<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <template id="report_contract_document">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="o">
                <t t-call="web.external_layout">
                    <t t-set="o" t-value="o.with_context(lang=o.partner_id.lang)" />
                    <t t-set="address">
                        <p id="partner_info">
                            <strong>Partner:</strong>
                        </p>
                        <div
                            t-field="o.partner_id"
                            t-options='{"widget": "contact", "fields": ["address", "name", "phone", "mobile", "fax", "email"], "no_marker": true, "phone_icons": true}'
                        />
                        <p t-if="o.partner_id.vat">VAT: <span
                                t-field="o.partner_id.vat"
                            /></p>
                    </t>
                    <div class="page">
                        <div class="oe_structure" />
                        <div class="row" id="header_info">
                            <div class="col-3">
                                <strong>Responsible: </strong>
                                <p t-field="o.user_id" />
                                <strong>Contract: </strong>
                                <p t-field="o.code" />
                            </div>
                        </div>
                        <div class="row" id="invoice_info">
                            <t t-set="total" t-value="0" />
                            <div class="col-12">
                                <p id="services_info">
                                    <strong>Recurring Items</strong>
                                </p>
                                <table class="table table-sm">
                                    <thead>
                                        <tr>
                                            <th>
                                                <strong>Description</strong>
                                            </th>
                                            <th class="text-right">
                                                <strong>Quantity</strong>
                                            </th>
                                            <th class="text-right">
                                                <strong>Unit Price</strong>
                                            </th>
                                            <th class="text-right">
                                                <strong>Price</strong>
                                            </th>
                                            <th class="text-right">
                                                <strong>Date Start</strong>
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <t t-set="current_subtotal" t-value="0" />
                                        <t t-foreach="o.contract_line_ids" t-as="l">
                                            <t
                                                t-set="current_subtotal"
                                                t-value="current_subtotal + l.price_subtotal"
                                            />
                                            <tr
                                                t-att-class="'bg-200 font-weight-bold o_line_section' if l.display_type == 'line_section' else 'font-italic o_line_note' if l.display_type == 'line_note' else ''"
                                            >
                                                <t t-if="not l.display_type">
                                                    <td>
                                                        <span t-field="l.name" />
                                                    </td>
                                                    <td class="text-right">
                                                        <span t-field="l.quantity" />
                                                    </td>
                                                    <td class="text-right">
                                                        <span
                                                            t-field="l.price_unit"
                                                            t-options='{"widget": "monetary", "display_currency": o.currency_id}'
                                                        />
                                                    </td>
                                                    <td class="text-right">
                                                        <span
                                                            t-field="l.price_subtotal"
                                                            t-options='{"widget": "monetary", "display_currency": o.currency_id}'
                                                        />
                                                    </td>
                                                    <td class="text-right">
                                                        <span t-field="l.date_start" />
                                                    </td>
                                                    <t
                                                        t-set="total"
                                                        t-value="total + l.price_subtotal"
                                                    />
                                                </t>
                                                <t
                                                    t-if="l.display_type == 'line_section'"
                                                >
                                                    <td colspan="99">
                                                        <span t-field="l.name" />
                                                    </td>
                                                    <t
                                                        t-set="current_section"
                                                        t-value="l"
                                                    />
                                                    <t
                                                        t-set="current_subtotal"
                                                        t-value="0"
                                                    />
                                                </t>
                                                <t t-if="l.display_type == 'line_note'">
                                                    <td colspan="99">
                                                        <span t-field="l.name" />
                                                    </td>
                                                </t>
                                            </tr>
                                            <t
                                                t-if="current_section and (l_last or o.contract_line_ids[l_index+1].display_type == 'line_section')"
                                            >
                                                <tr class="is-subtotal text-right">
                                                    <td colspan="99">
                                                        <strong
                                                            class="mr16"
                                                        >Subtotal</strong>
                                                        <span
                                                            t-esc="current_subtotal"
                                                            t-options='{"widget": "monetary", "display_currency": o.currency_id}'
                                                        />
                                                    </td>
                                                </tr>
                                            </t>
                                        </t>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div
                            class="row"
                            id="modification_info"
                            t-if="o.modification_ids"
                        >
                            <div class="col-12">
                                <p id="modification_info_p">
                                    <strong>Modifications</strong>
                                </p>
                                <table class="table table-sm">
                                    <thead>
                                        <tr>
                                            <th name="th_date">Date</th>
                                            <th
                                                name="th_description"
                                                class="text-right"
                                            >Description</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <t
                                            t-foreach="o.modification_ids"
                                            t-as="notification_id"
                                        >
                                            <tr>
                                                <td name="td_date">
                                                    <span
                                                        t-field="notification_id.date"
                                                    />
                                                </td>
                                                <td
                                                    name="td_description"
                                                    class="text-right"
                                                >
                                                    <div
                                                        t-field="notification_id.description"
                                                    />
                                                </td>
                                            </tr>
                                        </t>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div id="total" class="row" name="total">
                            <div class="col-4 ml-auto">
                                <table class="table table-sm">
                                    <tr class="border-black o_subtotal" style="">
                                        <td>
                                            <strong>Total</strong>
                                        </td>
                                        <td class="text-right">
                                            <span
                                                t-esc="total"
                                                t-options='{"widget": "monetary", "display_currency": o.currency_id}'
                                            />
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <div>
                            <div class="row mt-4" id="note">
                                <div>
                                    <strong>Notes: </strong>
                                </div>
                            </div>
                            <div class="row">
                                <p t-field="o.note" />
                            </div>
                        </div>
                    </div>
                </t>
            </t>
        </t>
    </template>
</odoo>
