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

    <!-- ============================================================ -->
    <!-- T4 ACTIONS - Must be defined before views that reference them -->
    <!-- ============================================================ -->
    <record id="action_hr_t4_summary" model="ir.actions.act_window">
        <field name="name">T4 Summary</field>
        <field name="res_model">hr.t4.summary</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create your T4 Summary
            </p>
            <p>
                Generate T4 slips for all employees for the tax year.
            </p>
        </field>
    </record>

    <record id="action_hr_t4_slip" model="ir.actions.act_window">
        <field name="name">T4 Slips</field>
        <field name="res_model">hr.t4.slip</field>
        <field name="view_mode">list,form</field>
    </record>

    <!-- ============================================================ -->
    <!-- T4 SUMMARY FORM VIEW                                          -->
    <!-- ============================================================ -->
    <record id="hr_t4_summary_view_form" model="ir.ui.view">
        <field name="name">hr.t4.summary.form</field>
        <field name="model">hr.t4.summary</field>
        <field name="arch" type="xml">
            <form string="T4 Summary">
                <header>
                    <button name="action_generate_slips" 
                            string="Generate T4 Slips" 
                            type="object" 
                            class="btn-primary"/>
                    <button name="action_fill_pdf" 
                            string="Fill PDF" 
                            type="object" 
                            class="btn-primary"/>
                    <button name="action_download_pdf" 
                            string="Download PDF" 
                            type="object"
                            class="btn-secondary"
                            invisible="not filled_pdf"/>
                    <button name="action_extract_pdf_fields" 
                            string="Extract PDF Fields" 
                            type="object"
                            class="btn-info"
                            help="Extract and display PDF form field names (for debugging)"/>
                    <button name="action_mark_filed" 
                            string="Mark as Filed" 
                            type="object" 
                            class="btn-success"/>
                    <field name="state" widget="statusbar"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button type="action" class="oe_stat_button" 
                                name="%(fusion_payroll.action_hr_t4_slip)d"
                                icon="fa-file-text-o">
                            <field name="slip_count" widget="statinfo" string="T4 Slips"/>
                        </button>
                    </div>

                    <div class="oe_title">
                        <h1>
                            <field name="name" readonly="1"/>
                        </h1>
                    </div>

                    <group>
                        <group string="Tax Year">
                            <field name="company_id"/>
                            <field name="tax_year"/>
                            <field name="cra_business_number"/>
                        </group>
                        <group string="Contact">
                            <field name="contact_name"/>
                            <field name="contact_phone"/>
                            <field name="proprietor_sin"/>
                            <field name="filing_date"/>
                        </group>
                    </group>

                    <group string="PDF" invisible="not filled_pdf">
                        <field name="filled_pdf_filename" readonly="1"/>
                    </group>

                    <notebook>
                        <page string="Summary Totals" name="totals">

                            <group string="Employee Contributions">
                                <group>
                                    <field name="total_employment_income" 
                                           string="Box 14: Employment Income"/>
                                    <field name="total_cpp_employee"
                                           string="Box 16: Employees' CPP"/>
                                    <field name="total_cpp2_employee"
                                           string="Box 16A: Employees' CPP2"/>
                                </group>
                                <group>
                                    <field name="total_ei_employee"
                                           string="Box 18: Employees' EI"/>
                                    <field name="total_income_tax"
                                           string="Box 22: Income Tax"/>
                                </group>
                            </group>

                            <group string="Employer Contributions">
                                <group>
                                    <field name="total_cpp_employer"
                                           string="Box 27: Employer's CPP"/>
                                    <field name="total_cpp2_employer"
                                           string="Box 27A: Employer's CPP2"/>
                                </group>
                                <group>
                                    <field name="total_ei_employer"
                                           string="Box 19: Employer's EI"/>
                                </group>
                            </group>

                            <group string="Remittance Summary">
                                <group>
                                    <field name="total_deductions"
                                           string="Box 80: Total Deductions"/>
                                    <field name="total_remittances"
                                           string="Box 82: Remittances"/>
                                </group>
                                <group>
                                    <field name="balance_due"
                                           string="Box 86: Balance Due"/>
                                    <field name="overpayment"
                                           string="Box 84: Overpayment"/>
                                </group>
                            </group>

                        </page>

                        <page string="T4 Slips" name="slips">
                            <field name="slip_ids">
                                <list>
                                    <field name="employee_id"/>
                                    <field name="employment_income" sum="Total"/>
                                    <field name="cpp_employee" sum="Total"/>
                                    <field name="ei_employee" sum="Total"/>
                                    <field name="income_tax" sum="Total"/>
                                    <field name="t4_dental_code"/>
                                </list>
                            </field>
                        </page>
                    </notebook>

                    <field name="currency_id" invisible="1"/>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- T4 SUMMARY LIST VIEW                                          -->
    <!-- ============================================================ -->
    <record id="hr_t4_summary_view_list" model="ir.ui.view">
        <field name="name">hr.t4.summary.list</field>
        <field name="model">hr.t4.summary</field>
        <field name="arch" type="xml">
            <list string="T4 Summaries">
                <field name="tax_year"/>
                <field name="company_id"/>
                <field name="slip_count"/>
                <field name="total_employment_income"/>
                <field name="total_deductions"/>
                <field name="state"/>
                <field name="currency_id" column_invisible="1"/>
            </list>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- T4 SLIP FORM VIEW                                             -->
    <!-- ============================================================ -->
    <record id="hr_t4_slip_view_form" model="ir.ui.view">
        <field name="name">hr.t4.slip.form</field>
        <field name="model">hr.t4.slip</field>
        <field name="arch" type="xml">
            <form string="T4 Slip">
                <header>
                    <button name="action_fill_pdf" 
                            string="Fill PDF" 
                            type="object" 
                            class="btn-primary"/>
                    <button name="action_download_pdf" 
                            string="Download PDF" 
                            type="object"
                            class="btn-secondary"
                            invisible="not filled_pdf"/>
                    <button name="action_extract_pdf_fields" 
                            string="Extract PDF Fields" 
                            type="object"
                            class="btn-info"
                            help="Extract and display PDF form field names (for debugging)"/>
                </header>
                <sheet>
                    <group>
                        <group string="Employee">
                            <field name="employee_id"/>
                            <field name="sin_number"/>
                            <field name="tax_year"/>
                        </group>
                        <group string="Reference">
                            <field name="summary_id"/>
                            <field name="t4_dental_code"/>
                        </group>
                    </group>

                    <group string="Amounts">
                        <group>
                            <field name="employment_income"
                                   string="Box 14: Employment Income"/>
                            <field name="cpp_employee"
                                   string="Box 16: CPP"/>
                            <field name="cpp2_employee"
                                   string="Box 16A: CPP2"/>
                        </group>
                        <group>
                            <field name="ei_employee"
                                   string="Box 18: EI"/>
                            <field name="income_tax"
                                   string="Box 22: Income Tax"/>
                        </group>
                    </group>

                    <group string="Earnings and Deductions">
                        <group>
                            <field name="ei_insurable_earnings"
                                   string="Box 24: EI Insurable Earnings"/>
                            <field name="cpp_pensionable_earnings"
                                   string="Box 26: CPP Pensionable Earnings"/>
                        </group>
                        <group>
                            <field name="box_40_taxable_benefits"
                                   string="Box 40: Other Taxable Allowances/Benefits"/>
                            <field name="box_42_commissions"
                                   string="Box 42: Employment Commissions"/>
                            <field name="box_44_union_dues"
                                   string="Box 44: Union Dues"/>
                        </group>
                    </group>

                    <group string="PDF" invisible="not filled_pdf">
                        <field name="filled_pdf_filename" readonly="1"/>
                    </group>

                    <field name="currency_id" invisible="1"/>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- T4 SLIP LIST VIEW                                             -->
    <!-- ============================================================ -->
    <record id="hr_t4_slip_view_list" model="ir.ui.view">
        <field name="name">hr.t4.slip.list</field>
        <field name="model">hr.t4.slip</field>
        <field name="arch" type="xml">
            <list string="T4 Slips">
                <field name="employee_id"/>
                <field name="tax_year"/>
                <field name="employment_income" sum="Total"/>
                <field name="ei_insurable_earnings" sum="Total" optional="hide"/>
                <field name="cpp_pensionable_earnings" sum="Total" optional="hide"/>
                <field name="cpp_employee" sum="Total"/>
                <field name="cpp2_employee" sum="Total"/>
                <field name="ei_employee" sum="Total"/>
                <field name="income_tax" sum="Total"/>
                <field name="box_40_taxable_benefits" sum="Total" optional="hide"/>
                <field name="box_42_commissions" sum="Total" optional="hide"/>
                <field name="box_44_union_dues" sum="Total" optional="hide"/>
                <field name="t4_dental_code"/>
                <field name="currency_id" column_invisible="1"/>
            </list>
        </field>
    </record>

    <!-- Menus moved to fusion_payroll_menus.xml -->

</odoo>
