<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright 2024-2025 Nexa Systems Inc.
    License OPL-1 (Odoo Proprietary License v1.0)
    Part of the Fusion Claim Assistant product family.
    Approved Items Report - Landscape
-->
<odoo>
    <template id="report_approved_items">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="doc">
                <t t-call="web.external_layout">
                    <t t-set="doc" t-value="doc.with_context(lang=doc.partner_id.lang)"/>
                    <t t-set="company" t-value="doc.company_id"/>
                    <t t-set="is_deduction" t-value="doc.x_fc_adp_application_status == 'approved_deduction'"/>
                    <t t-set="lines" t-value="doc.order_line.filtered(lambda l: l.product_id and l.display_type not in ('line_section', 'line_note'))"/>
                    <t t-set="has_deduction" t-value="any(l.x_fc_deduction_type and l.x_fc_deduction_type != 'none' for l in lines)"/>

                    <style>
                        .fc-ai { font-family: Arial, sans-serif; font-size: 10pt; }
                        .fc-ai h2 { color: #0066a1; font-size: 16pt; text-align: center; margin: 25px 0 20px 0; }
                        .fc-ai table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
                        .fc-ai table.bordered, .fc-ai table.bordered th, .fc-ai table.bordered td { border: 1px solid #000; }
                        .fc-ai th { background-color: #0066a1; color: white; padding: 6px 8px; font-weight: bold; font-size: 9pt; }
                        .fc-ai td { padding: 5px 6px; vertical-align: top; font-size: 9pt; }
                        .fc-ai .text-center { text-align: center; }
                        .fc-ai .text-end { text-align: right; }
                        .fc-ai .info-label { font-weight: bold; background-color: #f5f5f5; width: 18%; }
                        .fc-ai .alt-row { background-color: #f7fafc; }
                        .fc-ai .total-row { background-color: #edf2f7; font-weight: bold; }
                        .fc-ai .status-approved { color: #38a169; font-weight: bold; }
                        .fc-ai .status-deduction { color: #d69e2e; font-weight: bold; }
                    </style>

                    <div class="fc-ai">
                        <div class="page">

                            <div style="height: 30px;"></div>
                            <h2>APPROVED ITEMS REPORT</h2>

                            <!-- Case Info -->
                            <table class="bordered" style="margin-bottom: 15px;">
                                <thead>
                                    <tr>
                                        <th colspan="4">CASE DETAILS</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="info-label">Case</td>
                                        <td><t t-esc="doc.name"/></td>
                                        <td class="info-label">Client</td>
                                        <td><t t-esc="doc.partner_id.name"/></td>
                                    </tr>
                                    <tr>
                                        <td class="info-label">Claim Number</td>
                                        <td><t t-esc="doc.x_fc_claim_number or 'N/A'"/></td>
                                        <td class="info-label">Status</td>
                                        <td>
                                            <t t-if="is_deduction">
                                                <span class="status-deduction">Approved with Deduction</span>
                                            </t>
                                            <t t-else="">
                                                <span class="status-approved">Approved</span>
                                            </t>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="info-label">Assessment Date</td>
                                        <td>
                                            <t t-if="doc.x_fc_assessment_end_date"><span t-field="doc.x_fc_assessment_end_date" t-options="{'widget': 'date'}"/></t>
                                            <t t-else="">N/A</t>
                                        </td>
                                        <td class="info-label">Approval Date</td>
                                        <td>
                                            <t t-if="doc.x_fc_claim_approval_date"><span t-field="doc.x_fc_claim_approval_date" t-options="{'widget': 'date'}"/></t>
                                            <t t-else="">N/A</t>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="info-label">Client Ref 1</td>
                                        <td><t t-esc="doc.x_fc_client_ref_1 or 'N/A'"/></td>
                                        <td class="info-label">Client Ref 2</td>
                                        <td><t t-esc="doc.x_fc_client_ref_2 or 'N/A'"/></td>
                                    </tr>
                                </tbody>
                            </table>

                            <!-- Items Table -->
                            <table class="bordered">
                                <thead>
                                    <tr>
                                        <th class="text-center" style="width: 5%;">S/N</th>
                                        <th style="width: 12%;">ADP CODE</th>
                                        <th style="width: 15%;">DEVICE TYPE</th>
                                        <th style="width: 28%;">PRODUCT NAME</th>
                                        <th class="text-end" style="width: 5%;">QTY</th>
                                        <th class="text-end" style="width: 12%;">ADP PORTION</th>
                                        <th class="text-end" style="width: 13%;">CLIENT PORTION</th>
                                        <t t-if="has_deduction">
                                            <th class="text-end" style="width: 10%;">DEDUCTION</th>
                                        </t>
                                    </tr>
                                </thead>
                                <tbody>
                                    <t t-set="total_adp" t-value="0"/>
                                    <t t-set="total_client" t-value="0"/>
                                    <t t-set="idx" t-value="0"/>
                                    <t t-foreach="lines" t-as="line">
                                        <t t-set="idx" t-value="idx + 1"/>
                                        <t t-set="total_adp" t-value="total_adp + (line.x_fc_adp_portion or 0)"/>
                                        <t t-set="total_client" t-value="total_client + (line.x_fc_client_portion or 0)"/>
                                        <tr t-attf-class="#{ 'alt-row' if idx % 2 == 0 else '' }">
                                            <td class="text-center"><t t-esc="idx"/></td>
                                            <td><t t-esc="line._get_adp_code_for_report()"/></td>
                                            <td><t t-esc="line._get_adp_device_type()"/></td>
                                            <td><t t-esc="line.product_id.name or '-'"/></td>
                                            <td class="text-end">
                                                <t t-esc="int(line.product_uom_qty) if line.product_uom_qty == int(line.product_uom_qty) else line.product_uom_qty"/>
                                            </td>
                                            <td class="text-end">
                                                $<t t-esc="'%.2f' % (line.x_fc_adp_portion or 0)"/>
                                            </td>
                                            <td class="text-end">
                                                $<t t-esc="'%.2f' % (line.x_fc_client_portion or 0)"/>
                                            </td>
                                            <t t-if="has_deduction">
                                                <td class="text-end">
                                                    <t t-if="line.x_fc_deduction_type == 'pct' and line.x_fc_deduction_value">
                                                        <t t-esc="'%.0f' % line.x_fc_deduction_value"/>%
                                                    </t>
                                                    <t t-elif="line.x_fc_deduction_type == 'amt' and line.x_fc_deduction_value">
                                                        $<t t-esc="'%.2f' % line.x_fc_deduction_value"/>
                                                    </t>
                                                    <t t-else="">-</t>
                                                </td>
                                            </t>
                                        </tr>
                                    </t>
                                    <!-- Totals -->
                                    <tr class="total-row">
                                        <td colspan="5" class="text-end" style="border-top: 2px solid #000;">TOTAL</td>
                                        <td class="text-end" style="border-top: 2px solid #000;">
                                            $<t t-esc="'%.2f' % total_adp"/>
                                        </td>
                                        <td class="text-end" style="border-top: 2px solid #000;">
                                            $<t t-esc="'%.2f' % total_client"/>
                                        </td>
                                        <t t-if="has_deduction">
                                            <td style="border-top: 2px solid #000;"></td>
                                        </t>
                                    </tr>
                                </tbody>
                            </table>

                        </div>
                    </div>
                </t>
            </t>
        </t>
    </template>
</odoo>
