<?xml version="1.0" encoding="UTF-8"?>
<!--
    Fusion Claims - March of Dimes Quotation Report
    Portrait format with estimated completion time
-->
<odoo>
    <template id="report_mod_quotation">
        <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)"/>

                    <style>
                        .fc-mod { font-family: Arial, sans-serif; font-size: 10pt; }
                        .fc-mod table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
                        .fc-mod table.bordered, .fc-mod table.bordered th, .fc-mod table.bordered td { border: 1px solid #000; }
                        .fc-mod th { background-color: #1a5276; color: white; padding: 6px 8px; font-weight: bold; text-align: center; }
                        .fc-mod td { padding: 6px 8px; vertical-align: top; }
                        .fc-mod .text-center { text-align: center; }
                        .fc-mod .text-end { text-align: right; }
                        .fc-mod .text-start { text-align: left; }
                        .fc-mod .section-row { background-color: #f0f0f0; font-weight: bold; }
                        .fc-mod h4 { color: #1a5276; margin: 0 0 15px 0; font-size: 16pt; }
                        .fc-mod .info-header { background-color: #eaf2f8; color: #333; }
                        .fc-mod .mod-accent { color: #1a5276; font-weight: bold; }
                        .fc-mod .highlight-box { border: 2px solid #1a5276; padding: 10px; margin: 10px 0; background-color: #eaf2f8; }
                    </style>

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

                            <!-- Document Title -->
                            <h4>
                                March of Dimes Quotation
                                <span t-field="doc.name"/>
                            </h4>

                            <!-- Address Table -->
                            <table class="bordered">
                                <thead>
                                    <tr>
                                        <th style="width: 50%;">CLIENT</th>
                                        <th style="width: 50%;">SERVICE ADDRESS</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td style="height: 70px; font-size: 11pt;">
                                            <div t-field="doc.partner_id"
                                                 t-options="{'widget': 'contact', 'fields': ['name', 'address', 'phone'], 'no_marker': True}"/>
                                        </td>
                                        <td style="height: 70px; font-size: 11pt;">
                                            <div t-if="doc.partner_shipping_id"
                                                 t-field="doc.partner_shipping_id"
                                                 t-options="{'widget': 'contact', 'fields': ['name', 'address'], 'no_marker': True}"/>
                                            <div t-else=""
                                                 t-field="doc.partner_id"
                                                 t-options="{'widget': 'contact', 'fields': ['name', 'address'], 'no_marker': True}"/>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>

                            <!-- Order Info -->
                            <table class="bordered">
                                <thead>
                                    <tr>
                                        <th class="info-header" style="width: 20%;">DATE</th>
                                        <th class="info-header" style="width: 20%;">SALESPERSON</th>
                                        <th class="info-header" style="width: 20%;">AUTHORIZER/OT</th>
                                        <th class="info-header" style="width: 20%;">PRODUCT TYPE</th>
                                        <th class="info-header" style="width: 20%;">EXPIRATION</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="text-center">
                                            <span t-field="doc.date_order" t-options="{'widget': 'date'}"/>
                                        </td>
                                        <td class="text-center">
                                            <span t-field="doc.user_id"/>
                                        </td>
                                        <td class="text-center">
                                            <span t-if="doc.x_fc_authorizer_id" t-field="doc.x_fc_authorizer_id"/>
                                            <span t-else="">-</span>
                                        </td>
                                        <td class="text-center">
                                            <t t-set="prod_type_label" t-value="dict(doc._fields['x_fc_mod_product_type'].selection or []).get(doc.x_fc_mod_product_type, '-')"/>
                                            <span t-esc="prod_type_label"/>
                                        </td>
                                        <td class="text-center">
                                            <span t-field="doc.validity_date"/>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>

                            <!-- Estimated Completion -->
                            <table class="bordered">
                                <thead>
                                    <tr>
                                        <th class="info-header" style="width: 50%;">EST. COMPLETION TIME</th>
                                        <th class="info-header" style="width: 50%;">EST. COMPLETION DATE</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="text-center">
                                            <span t-if="doc.x_fc_mod_estimated_weeks">
                                                <t t-esc="doc.x_fc_mod_estimated_weeks"/> weeks
                                            </span>
                                            <span t-else="">To be confirmed</span>
                                        </td>
                                        <td class="text-center">
                                            <span t-if="doc.x_fc_estimated_completion_date"
                                                  t-field="doc.x_fc_estimated_completion_date"
                                                  t-options="{'widget': 'date'}"/>
                                            <span t-else="">To be confirmed</span>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>

                            <!-- Order Lines -->
                            <table class="bordered">
                                <thead>
                                    <tr>
                                        <th style="width: 10%;">SKU</th>
                                        <th style="width: 35%;">DESCRIPTION</th>
                                        <th style="width: 8%;">QTY</th>
                                        <th style="width: 15%;">UNIT PRICE</th>
                                        <th style="width: 12%;">TAX</th>
                                        <th style="width: 20%;">AMOUNT</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <t t-foreach="doc.order_line" t-as="line">
                                        <t t-if="not line.display_type">
                                            <tr>
                                                <td class="text-center" style="font-size: 9pt;">
                                                    <t t-esc="line.product_id.default_code or '-'"/>
                                                </td>
                                                <td>
                                                    <strong t-field="line.product_id.name"/>
                                                    <t t-if="line.name and line.name != line.product_id.name">
                                                        <t t-set="clean_desc" t-value="line.name"/>
                                                        <t t-if="'] ' in (line.name or '')">
                                                            <t t-set="clean_desc" t-value="line.name.split('] ', 1)[1]"/>
                                                        </t>
                                                        <t t-if="clean_desc != line.product_id.name">
                                                            <br/>
                                                            <span t-esc="clean_desc" style="font-size: 9pt; color: #555;"/>
                                                        </t>
                                                    </t>
                                                </td>
                                                <td class="text-center">
                                                    <span t-field="line.product_uom_qty"/>
                                                </td>
                                                <td class="text-end">
                                                    <span t-field="line.price_unit"/>
                                                </td>
                                                <td class="text-center" style="font-size: 9pt;">
                                                    <t t-if="line.tax_ids">
                                                        <t t-esc="', '.join(t.invoice_label or t.name for t in line.tax_ids)"/>
                                                    </t>
                                                    <span t-else="">-</span>
                                                </td>
                                                <td class="text-end">
                                                    <span t-field="line.price_subtotal"/>
                                                </td>
                                            </tr>
                                        </t>
                                        <t t-if="line.display_type == 'line_section'">
                                            <tr class="section-row">
                                                <td colspan="6"><span t-field="line.name"/></td>
                                            </tr>
                                        </t>
                                        <t t-if="line.display_type == 'line_note'">
                                            <tr>
                                                <td colspan="6" style="font-style: italic;">
                                                    <span t-field="line.name"/>
                                                </td>
                                            </tr>
                                        </t>
                                    </t>
                                </tbody>
                            </table>

                            <!-- Totals -->
                            <div class="row">
                                <div class="col-6"/>
                                <div class="col-6">
                                    <table class="bordered">
                                        <tr>
                                            <td class="text-end" style="width: 60%;"><strong>Subtotal</strong></td>
                                            <td class="text-end" style="width: 40%;"><span t-field="doc.amount_untaxed"/></td>
                                        </tr>
                                        <tr>
                                            <td class="text-end">Taxes</td>
                                            <td class="text-end"><span t-field="doc.amount_tax"/></td>
                                        </tr>
                                        <tr style="font-size: 12pt;">
                                            <td class="text-end" style="background-color: #eaf2f8;">
                                                <strong>Total</strong>
                                            </td>
                                            <td class="text-end" style="background-color: #eaf2f8;">
                                                <strong><span t-field="doc.amount_total"/></strong>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>

                            <!-- Notes -->
                            <div t-if="doc.note" class="mt-3">
                                <strong>Notes:</strong>
                                <div t-field="doc.note"/>
                            </div>

                            <!-- Terms and Conditions -->
                            <div class="mt-4" style="font-size: 9pt; color: #555;">
                                <strong>Terms &amp; Conditions:</strong>
                                <ul style="margin-top: 4px;">
                                    <li>This quotation is valid for 30 days from the date above unless otherwise specified.</li>
                                    <li>All drawings must be signed and accepted by the client before production begins.</li>
                                    <li>Estimated completion time is subject to manufacturer lead times and weather conditions.</li>
                                </ul>
                            </div>

                            <!-- Signature Block -->
                            <div class="row mt-5">
                                <div class="col-6">
                                    <div style="border-top: 1px solid #000; padding-top: 4px; width: 80%;">
                                        Client Signature / Date
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div style="border-top: 1px solid #000; padding-top: 4px; width: 80%;">
                                        Authorized Representative / Date
                                    </div>
                                </div>
                            </div>

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