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

    <!-- ============================================================ -->
    <!-- PAYROLL CHEQUE VIEWS                                          -->
    <!-- ============================================================ -->

    <!-- Cheque List View -->
    <record id="payroll_cheque_view_list" model="ir.ui.view">
        <field name="name">payroll.cheque.list</field>
        <field name="model">payroll.cheque</field>
        <field name="arch" type="xml">
            <list string="Cheques" default_order="cheque_date desc, cheque_number desc">
                <field name="cheque_number"/>
                <field name="cheque_date"/>
                <field name="employee_id"/>
                <field name="amount" widget="monetary"/>
                <field name="payslip_id" optional="show"/>
                <field name="payslip_run_id" optional="show"/>
                <field name="state" widget="badge" 
                       decoration-info="state == 'draft'"
                       decoration-success="state == 'printed'"
                       decoration-warning="state == 'cashed'"
                       decoration-danger="state == 'voided'"/>
                <field name="currency_id" column_invisible="1"/>
            </list>
        </field>
    </record>

    <!-- Cheque Form View -->
    <record id="payroll_cheque_view_form" model="ir.ui.view">
        <field name="name">payroll.cheque.form</field>
        <field name="model">payroll.cheque</field>
        <field name="arch" type="xml">
            <form string="Cheque">
                <header>
                    <button name="action_print_cheque" type="object" string="Print Cheque" 
                            class="oe_highlight" invisible="state != 'draft'"/>
                    <button name="action_print_cheque" type="object" string="Reprint Cheque" 
                            invisible="state not in ['printed', 'cashed']"/>
                    <button name="action_void" type="object" string="Void" 
                            class="btn-secondary" invisible="state not in ['draft', 'printed']"/>
                    <button name="action_mark_cashed" type="object" string="Mark as Cashed" 
                            invisible="state != 'printed'"/>
                    <button name="action_reset_to_draft" type="object" string="Reset to Draft" 
                            invisible="state != 'voided'" groups="hr.group_hr_manager"/>
                    <field name="state" widget="statusbar" statusbar_visible="draft,printed,cashed"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="action_print_cheque" type="object" class="oe_stat_button" icon="fa-print">
                            <span>Print</span>
                        </button>
                        <button name="%(action_payroll_cheque)d" type="action" class="oe_stat_button" icon="fa-list">
                            <span>Cheques</span>
                        </button>
                    </div>
                    
                    <!-- Status badge in top right -->
                    <div class="float-end" style="position: absolute; top: 10px; right: 20px; z-index: 10;">
                        <field name="state" widget="badge" 
                               decoration-info="state == 'draft'"
                               decoration-success="state == 'printed'"
                               decoration-warning="state == 'cashed'"
                               decoration-danger="state == 'voided'"/>
                    </div>
                    
                    <!-- Compact header with smaller text and spacing -->
                    <div style="margin-bottom: 16px;">
                        <div style="margin-bottom: 8px;">
                            <label for="employee_id" string="Employee" class="o_form_label" style="font-size: 12px; color: #666;"/>
                            <div style="margin-top: 4px;">
                                <field name="employee_id" readonly="1" style="font-size: 14px; font-weight: 500;"/>
                            </div>
                        </div>
                        <div style="display: flex; gap: 24px; margin-top: 12px;">
                            <div style="flex: 1;">
                                <label for="cheque_number" string="Cheque Number" class="o_form_label" style="font-size: 12px; color: #666;"/>
                                <div style="margin-top: 4px;">
                                    <span invisible="not cheque_number" style="font-size: 12px; color: #999;">CHQ-</span>
                                    <field name="cheque_number" placeholder="Draft" style="font-size: 14px; font-weight: 500;"/>
                                </div>
                            </div>
                            <div style="flex: 1;">
                                <label for="payment_method_display" string="Payment Method" class="o_form_label" style="font-size: 12px; color: #666;"/>
                                <div style="margin-top: 4px;">
                                    <field name="payment_method_display" readonly="1" style="font-size: 14px; font-weight: 500;"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <group>
                        <group string="Cheque Details">
                            <field name="cheque_date"/>
                            <field name="employee_id"/>
                            <field name="amount" widget="monetary"/>
                            <field name="amount_in_words" readonly="1"/>
                            <field name="currency_id" invisible="1"/>
                        </group>
                        <group string="Payment Info">
                            <field name="payslip_id" readonly="1"/>
                            <field name="payslip_run_id" readonly="1"/>
                            <field name="bank_account_id"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                    </group>
                    
                    <group>
                        <group string="Payee Address">
                            <field name="payee_name"/>
                            <field name="payee_address"/>
                        </group>
                        <group string="Pay Period">
                            <field name="pay_period_start"/>
                            <field name="pay_period_end"/>
                            <field name="pay_period_display" readonly="1"/>
                        </group>
                    </group>
                    
                    <group string="Memo">
                        <field name="memo" nolabel="1" colspan="2"/>
                    </group>
                    
                    <group string="Void Information" invisible="state != 'voided'">
                        <field name="voided_date"/>
                        <field name="void_reason"/>
                    </group>
                    
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids"/>
                    <field name="activity_ids"/>
                    <field name="message_ids"/>
                </div>
            </form>
        </field>
    </record>

    <!-- Cheque Search View -->
    <record id="payroll_cheque_view_search" model="ir.ui.view">
        <field name="name">payroll.cheque.search</field>
        <field name="model">payroll.cheque</field>
        <field name="arch" type="xml">
            <search string="Search Cheques">
                <field name="cheque_number"/>
                <field name="employee_id"/>
                <field name="payslip_id"/>
                <field name="payslip_run_id"/>
                <filter name="draft" string="Draft" domain="[('state', '=', 'draft')]"/>
                <filter name="printed" string="Printed" domain="[('state', '=', 'printed')]"/>
                <filter name="cashed" string="Cashed" domain="[('state', '=', 'cashed')]"/>
                <filter name="voided" string="Voided" domain="[('state', '=', 'voided')]"/>
                <filter name="group_employee" string="Employee" context="{'group_by': 'employee_id'}"/>
                <filter name="group_batch" string="Payslip Batch" context="{'group_by': 'payslip_run_id'}"/>
                <filter name="group_state" string="Status" context="{'group_by': 'state'}"/>
                <filter name="group_date" string="Date" context="{'group_by': 'cheque_date:month'}"/>
            </search>
        </field>
    </record>

    <!-- Cheque Action -->
    <record id="action_payroll_cheque" model="ir.actions.act_window">
        <field name="name">Cheques</field>
        <field name="res_model">payroll.cheque</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="payroll_cheque_view_search"/>
        <field name="context">{'search_default_draft': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No cheques found
            </p>
            <p>
                Cheques are created when you process payroll for employees with payment method set to "Cheque".
            </p>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- CHEQUE VOID WIZARD VIEW                                       -->
    <!-- ============================================================ -->
    <record id="payroll_cheque_void_wizard_form" model="ir.ui.view">
        <field name="name">payroll.cheque.void.wizard.form</field>
        <field name="model">payroll.cheque.void.wizard</field>
        <field name="arch" type="xml">
            <form string="Void Cheque">
                <group>
                    <field name="cheque_id" readonly="1"/>
                    <field name="void_reason" placeholder="Enter reason for voiding this cheque..."/>
                </group>
                <footer>
                    <button name="action_void" type="object" string="Void Cheque" class="btn-primary"/>
                    <button string="Cancel" class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- CHEQUE LAYOUT VIEWS                                           -->
    <!-- ============================================================ -->
    <record id="payroll_cheque_layout_view_form" model="ir.ui.view">
        <field name="name">payroll.cheque.layout.form</field>
        <field name="model">payroll.cheque.layout</field>
        <field name="arch" type="xml">
            <form string="Cheque Layout">
                <sheet>
                    <group>
                        <group string="General">
                            <field name="name"/>
                            <field name="active"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                        <group string="Page Settings">
                            <field name="page_width"/>
                            <field name="page_height"/>
                            <field name="cheque_height"/>
                            <field name="stub_height"/>
                            <field name="show_employer_copy"/>
                        </group>
                    </group>
                    
                    <notebook>
                        <page string="Date Position">
                            <group>
                                <group>
                                    <field name="date_x"/>
                                    <field name="date_y"/>
                                </group>
                                <group>
                                    <field name="date_format"/>
                                </group>
                            </group>
                        </page>
                        <page string="Amount Positions">
                            <group>
                                <group string="Numeric Amount">
                                    <field name="amount_x"/>
                                    <field name="amount_y"/>
                                </group>
                                <group string="Amount in Words">
                                    <field name="amount_words_x"/>
                                    <field name="amount_words_y"/>
                                </group>
                            </group>
                        </page>
                        <page string="Payee &amp; Memo">
                            <group>
                                <group string="Payee">
                                    <field name="payee_x"/>
                                    <field name="payee_y"/>
                                </group>
                                <group string="Memo">
                                    <field name="memo_x"/>
                                    <field name="memo_y"/>
                                </group>
                            </group>
                            <group>
                                <group string="Pay Period">
                                    <field name="pay_period_x"/>
                                    <field name="pay_period_y"/>
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="payroll_cheque_layout_view_list" model="ir.ui.view">
        <field name="name">payroll.cheque.layout.list</field>
        <field name="model">payroll.cheque.layout</field>
        <field name="arch" type="xml">
            <list string="Cheque Layouts">
                <field name="name"/>
                <field name="company_id" groups="base.group_multi_company"/>
                <field name="active"/>
            </list>
        </field>
    </record>

    <record id="action_payroll_cheque_layout" model="ir.actions.act_window">
        <field name="name">Cheque Layouts</field>
        <field name="res_model">payroll.cheque.layout</field>
        <field name="view_mode">list,form</field>
    </record>

    <!-- ============================================================ -->
    <!-- CHEQUE SEQUENCE                                               -->
    <!-- ============================================================ -->
    <record id="seq_payroll_cheque" model="ir.sequence">
        <field name="name">Payroll Cheque</field>
        <field name="code">payroll.cheque</field>
        <field name="prefix"></field>
        <field name="padding">6</field>
        <field name="number_next">1</field>
        <field name="number_increment">1</field>
    </record>

</odoo>
