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

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

    <record id="action_hr_t4a_slip" model="ir.actions.act_window">
        <field name="name">T4A Slips</field>
        <field name="res_model">hr.t4a.slip</field>
        <field name="view_mode">list,form</field>
    </record>

    <!-- ============================================================ -->
    <!-- T4A SUMMARY FORM VIEW                                          -->
    <!-- ============================================================ -->
    <record id="hr_t4a_summary_view_form" model="ir.ui.view">
        <field name="name">hr.t4a.summary.form</field>
        <field name="model">hr.t4a.summary</field>
        <field name="arch" type="xml">
            <form string="T4A Summary">
                <header>
                    <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_t4a_slip)d"
                                icon="fa-file-text-o">
                            <field name="slip_count" widget="statinfo" string="T4A 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="filing_date"/>
                        </group>
                    </group>

                    <notebook>
                        <page string="Summary Totals" name="totals">
                            <group string="Income Totals">
                                <group>
                                    <field name="total_box_016" 
                                           string="Box 016: Pension"/>
                                    <field name="total_box_018"
                                           string="Box 018: Lump-Sum"/>
                                    <field name="total_box_020"
                                           string="Box 020: Commissions"/>
                                </group>
                                <group>
                                    <field name="total_box_024"
                                           string="Box 024: Annuities"/>
                                    <field name="total_box_048"
                                           string="Box 048: Fees"/>
                                </group>
                            </group>
                        </page>

                        <page string="T4A Slips" name="slips">
                            <field name="slip_ids">
                                <list>
                                    <field name="recipient_name"/>
                                    <field name="box_016_pension" sum="Total"/>
                                    <field name="box_018_lump_sum" sum="Total"/>
                                    <field name="box_020_commissions" sum="Total"/>
                                    <field name="box_024_annuities" sum="Total"/>
                                    <field name="box_048_fees" sum="Total"/>
                                </list>
                            </field>
                        </page>
                    </notebook>

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

    <!-- ============================================================ -->
    <!-- T4A SUMMARY LIST VIEW                                          -->
    <!-- ============================================================ -->
    <record id="hr_t4a_summary_view_list" model="ir.ui.view">
        <field name="name">hr.t4a.summary.list</field>
        <field name="model">hr.t4a.summary</field>
        <field name="arch" type="xml">
            <list string="T4A Summaries">
                <field name="tax_year"/>
                <field name="company_id"/>
                <field name="slip_count"/>
                <field name="total_box_016"/>
                <field name="state"/>
                <field name="currency_id" column_invisible="1"/>
            </list>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- T4A SLIP FORM VIEW                                             -->
    <!-- ============================================================ -->
    <record id="hr_t4a_slip_view_form" model="ir.ui.view">
        <field name="name">hr.t4a.slip.form</field>
        <field name="model">hr.t4a.slip</field>
        <field name="arch" type="xml">
            <form string="T4A 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="Recipient">
                            <field name="recipient_id" 
                                   options="{'no_create': True}"/>
                            <field name="recipient_name" required="1"/>
                            <field name="recipient_sin" 
                                   string="SIN (Box 12)"/>
                            <field name="recipient_account_number" 
                                   string="Account Number (Box 13)"/>
                        </group>
                        <group string="Reference">
                            <field name="summary_id"/>
                            <field name="tax_year"/>
                        </group>
                    </group>

                    <group string="Recipient Address">
                        <field name="recipient_address" 
                               widget="text" 
                               placeholder="Street address&#10;City, Province Postal Code"/>
                    </group>

                    <group string="Income Boxes">
                        <group>
                            <field name="box_016_pension"
                                   string="Box 016: Pension or Superannuation"/>
                            <field name="box_018_lump_sum"
                                   string="Box 018: Lump-Sum Payments"/>
                            <field name="box_020_commissions"
                                   string="Box 020: Self-Employed Commissions"/>
                        </group>
                        <group>
                            <field name="box_024_annuities"
                                   string="Box 024: Annuities"/>
                            <field name="box_048_fees"
                                   string="Box 048: Fees for Services"/>
                        </group>
                    </group>

                    <group string="Other Information (Boxes 028-197)">
                        <field name="other_info_ids">
                            <list>
                                <field name="box_number" required="1"/>
                                <field name="amount" required="1"/>
                                <field name="description"/>
                            </list>
                        </field>
                    </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>

    <!-- ============================================================ -->
    <!-- T4A SLIP LIST VIEW                                             -->
    <!-- ============================================================ -->
    <record id="hr_t4a_slip_view_list" model="ir.ui.view">
        <field name="name">hr.t4a.slip.list</field>
        <field name="model">hr.t4a.slip</field>
        <field name="arch" type="xml">
            <list string="T4A Slips">
                <field name="recipient_name"/>
                <field name="tax_year"/>
                <field name="box_016_pension" sum="Total"/>
                <field name="box_018_lump_sum" sum="Total"/>
                <field name="box_020_commissions" sum="Total"/>
                <field name="box_024_annuities" sum="Total"/>
                <field name="box_048_fees" sum="Total"/>
                <field name="filled_pdf_filename" optional="hide"/>
                <field name="currency_id" column_invisible="1"/>
            </list>
        </field>
    </record>

</odoo>
