<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- ============================================================ -->
    <!-- Payslip — Tree View                                          -->
    <!-- ============================================================ -->
    <record id="view_payslip_tree" model="ir.ui.view">
        <field name="name">c2c.payslip.tree</field>
        <field name="model">c2c.payslip</field>
        <field name="arch" type="xml">
            <tree string="Payslips" decoration-info="state == 'draft'"
                  decoration-success="state == 'confirmed'"
                  decoration-muted="state == 'paid'">
                <field name="employee_id"/>
                <field name="date_from"/>
                <field name="date_to"/>
                <field name="gross_salary"/>
                <field name="total_deductions"/>
                <field name="net_salary"/>
                <field name="state" widget="badge"
                       decoration-info="state == 'draft'"
                       decoration-success="state == 'confirmed'"
                       decoration-warning="state == 'paid'"/>
                <field name="company_id" groups="base.group_multi_company"/>
            </tree>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Payslip — Form View                                          -->
    <!-- ============================================================ -->
    <record id="view_payslip_form" model="ir.ui.view">
        <field name="name">c2c.payslip.form</field>
        <field name="model">c2c.payslip</field>
        <field name="arch" type="xml">
            <form string="Payslip">
                <header>
                    <button name="action_confirm" string="Confirm"
                            type="object" class="oe_highlight"
                            invisible="state != 'draft'"
                            confirm="Are you sure you want to confirm this payslip and create a journal entry?"/>
                    <button name="action_mark_paid" string="Mark as Paid"
                            type="object" class="oe_highlight"
                            invisible="state != 'confirmed'"/>
                    <button name="action_reset_to_draft" string="Reset to Draft"
                            type="object"
                            invisible="state != 'confirmed'"/>
                    <field name="state" widget="statusbar"
                           statusbar_visible="draft,confirmed,paid"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="action_open_journal_entry"
                                type="object"
                                class="oe_stat_button"
                                icon="fa-book"
                                invisible="journal_entry_count == 0">
                            <field name="journal_entry_count" widget="statinfo"
                                   string="Journal Entry"/>
                        </button>
                    </div>
                    <div class="oe_title">
                        <h1>
                            <field name="display_name" readonly="1"/>
                        </h1>
                    </div>
                    <group>
                        <group string="Employee Details">
                            <field name="employee_id"/>
                            <field name="contract_id"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                        <group string="Period">
                            <field name="date_from"/>
                            <field name="date_to"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Earnings" name="earnings">
                            <group>
                                <group>
                                    <field name="gross_salary"/>
                                    <field name="basic"/>
                                    <field name="hra"/>
                                    <field name="allowances"/>
                                </group>
                            </group>
                        </page>
                        <page string="Deductions" name="deductions">
                            <group>
                                <group>
                                    <field name="pf_deduction"/>
                                    <field name="esi_deduction"/>
                                    <field name="professional_tax"/>
                                    <separator/>
                                    <field name="total_deductions"/>
                                </group>
                            </group>
                        </page>
                        <page string="Summary" name="summary">
                            <group>
                                <group>
                                    <field name="gross_salary" string="Gross Salary"/>
                                    <field name="total_deductions" string="Total Deductions"/>
                                    <separator/>
                                    <field name="net_salary" class="oe_subtotal_footer_separator"/>
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids"/>
                    <field name="activity_ids"/>
                    <field name="message_ids"/>
                </div>
            </form>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Payslip — Search View                                        -->
    <!-- ============================================================ -->
    <record id="view_payslip_search" model="ir.ui.view">
        <field name="name">c2c.payslip.search</field>
        <field name="model">c2c.payslip</field>
        <field name="arch" type="xml">
            <search string="Payslips">
                <field name="employee_id"/>
                <field name="state"/>
                <filter name="filter_draft" string="Draft"
                        domain="[('state', '=', 'draft')]"/>
                <filter name="filter_confirmed" string="Confirmed"
                        domain="[('state', '=', 'confirmed')]"/>
                <filter name="filter_paid" string="Paid"
                        domain="[('state', '=', 'paid')]"/>
                <separator/>
                <filter name="group_employee" string="Employee"
                        context="{'group_by': 'employee_id'}"/>
                <filter name="group_state" string="Status"
                        context="{'group_by': 'state'}"/>
            </search>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Payslip — Action                                             -->
    <!-- ============================================================ -->
    <record id="action_payslip" model="ir.actions.act_window">
        <field name="name">Payslips</field>
        <field name="res_model">c2c.payslip</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No payslips yet
            </p>
            <p>
                Create payslips individually or use the "Generate Payslips" wizard
                to create them in bulk for all employees with active contracts.
            </p>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- Generate Payslip Wizard — Form + Action                      -->
    <!-- ============================================================ -->
    <record id="view_payslip_generate_wizard_form" model="ir.ui.view">
        <field name="name">c2c.payslip.generate.wizard.form</field>
        <field name="model">c2c.payslip.generate.wizard</field>
        <field name="arch" type="xml">
            <form string="Generate Payslips">
                <group>
                    <field name="date_from"/>
                    <field name="date_to"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                </group>
                <footer>
                    <button name="action_generate_payslips" string="Generate"
                            type="object" class="oe_highlight"/>
                    <button string="Cancel" class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <record id="action_payslip_generate_wizard" model="ir.actions.act_window">
        <field name="name">Generate Payslips</field>
        <field name="res_model">c2c.payslip.generate.wizard</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>
</odoo>
