<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <!-- ROE Form View -->
    <record id="hr_roe_view_form" model="ir.ui.view">
        <field name="name">hr.roe.form</field>
        <field name="model">hr.roe</field>
        <field name="arch" type="xml">
            <form string="Record of Employment">
                <header>
                    <button name="action_calculate_earnings" 
                            string="Calculate Earnings" 
                            type="object" 
                            class="btn-secondary"
                            invisible="state in ['submitted', 'archived']"/>
                    <button name="action_generate_blk" 
                            string="Generate BLK File" 
                            type="object" 
                            class="btn-primary"
                            invisible="state in ['submitted', 'archived']"/>
                    <button name="action_mark_submitted" 
                            string="Mark as Submitted" 
                            type="object" 
                            class="btn-success"
                            invisible="state in ['draft', 'submitted', 'archived']"/>
                    <button name="action_print_roe"
                            string="Print ROE"
                            type="object"
                            class="btn-secondary"
                            icon="fa-print"/>
                    <field name="state" widget="statusbar" statusbar_visible="draft,ready,submitted,archived"/>
                </header>
                <sheet>
                    <!-- Deadline Warning Ribbon -->
                    <widget name="web_ribbon" title="Deadline Approaching" bg_color="text-bg-warning" 
                            invisible="state != 'ready'"/>
                    <widget name="web_ribbon" title="Submitted" bg_color="text-bg-success" 
                            invisible="state != 'submitted'"/>
                    
                    <div class="oe_title">
                        <h1>
                            <field name="name" readonly="1"/>
                        </h1>
                    </div>

                    <group>
                        <group string="Employee Information">
                            <field name="employee_id"/>
                            <field name="sin_number"/>
                            <field name="occupation"/>
                            <field name="pay_period_type"/>
                        </group>
                        <group string="Employer Information">
                            <field name="company_id"/>
                            <field name="cra_business_number"/>
                        </group>
                    </group>

                    <group>
                        <group string="Employment Dates">
                            <field name="first_day_worked"/>
                            <field name="last_day_paid"/>
                            <field name="final_pay_period_end"/>
                            <field name="expected_recall_date"/>
                        </group>
                        <group string="Reason">
                            <field name="reason_code"/>
                            <field name="communication_language"/>
                        </group>
                    </group>

                    <notebook>
                        <page string="Insurable Earnings" name="earnings">
                            <group>
                                <group>
                                    <field name="total_insurable_hours"/>
                                </group>
                                <group>
                                    <field name="total_insurable_earnings"/>
                                </group>
                            </group>
                            
                            <field name="pay_period_earnings_ids">
                                <list editable="bottom">
                                    <field name="sequence"/>
                                    <field name="amount"/>
                                    <field name="payslip_id"/>
                                </list>
                            </field>
                        </page>

                        <page string="Additional Information" name="additional">
                            <group>
                                <group string="Other Payments">
                                    <field name="other_payments"/>
                                </group>
                                <group string="Comments">
                                    <field name="comments"/>
                                </group>
                            </group>
                        </page>

                        <page string="Contact" name="contact">
                            <group>
                                <group string="Contact Person">
                                    <field name="contact_name"/>
                                    <field name="contact_phone"/>
                                </group>
                                <group string="Submission Status">
                                    <field name="submission_date"/>
                                    <field name="submission_deadline"/>
                                    <field name="service_canada_serial"/>
                                </group>
                            </group>
                            
                            <group string="Files">
                                <group>
                                    <field name="blk_file" filename="blk_filename"/>
                                    <field name="blk_filename" invisible="1"/>
                                </group>
                                <group>
                                    <field name="pdf_file" filename="pdf_filename"/>
                                    <field name="pdf_filename" invisible="1"/>
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <!-- ROE List View -->
    <record id="hr_roe_view_tree" model="ir.ui.view">
        <field name="name">hr.roe.list</field>
        <field name="model">hr.roe</field>
        <field name="arch" type="xml">
            <list string="Records of Employment">
                <field name="name"/>
                <field name="employee_id"/>
                <field name="reason_code"/>
                <field name="last_day_paid"/>
                <field name="submission_deadline"/>
                <field name="total_insurable_earnings"/>
                <field name="state"/>
            </list>
        </field>
    </record>

    <!-- ROE Search View -->
    <record id="hr_roe_view_search" model="ir.ui.view">
        <field name="name">hr.roe.search</field>
        <field name="model">hr.roe</field>
        <field name="arch" type="xml">
            <search string="Search ROE">
                <field name="name"/>
                <field name="employee_id"/>
            </search>
        </field>
    </record>

    <!-- ROE Sequence (menus moved to fusion_payroll_menus.xml) -->
    <record id="sequence_hr_roe" model="ir.sequence">
        <field name="name">ROE Sequence</field>
        <field name="code">hr.roe</field>
        <field name="prefix">ROE-</field>
        <field name="padding">5</field>
        <field name="company_id" eval="False"/>
    </record>

</odoo>
