<?xml version="1.0"?>
<t t-name="mrp.mo_overview_content">
        <t t-set="currency" t-value="data['summary']['currency']"/>
        <div class="container bg-view">
            <h2><t t-out="data['name']"/> - Overview</h2>
            <table name="overview" class="table table-borderless">
                <thead>
                    <tr>
                        <th/>
                        <th t-if="data['show_replenishments']" class="text-center">Status</th>
                        <th t-attf-class="{{ 'text-center' if data['show_uom'] else 'text-end' }}" t-attf-colspan="{{ 2 if data['show_uom'] else 1 }}">Quantity</th>
                        <th t-if="data['show_availabilities']" class="text-end">Free to use / On Hand</th>
                        <th t-if="data['show_availabilities']" class="text-end">Reserved</th>
                        <th t-if="data['show_receipts']" class="text-end">Receipt</th>
                        <th class="text-end" t-if="data['show_unit_costs']">Unit Cost</th>
                        <th t-if="data['show_mo_costs']" class="text-end">MO Cost</th>
                        <th t-if="data['show_bom_costs']" class="text-end">BoM Cost</th>
                        <th t-if="data['show_real_costs']" class="text-end">Real Cost</th>
                    </tr>
                </thead>
                <tbody>
                    <t t-call="mrp.mo_overview_line">
                        <t t-set="line" t-value="data['summary']"/>
                    </t>
                    <t t-call="mrp.mo_overview_components">
                        <t t-set="components" t-value="data['components']"/>
                        <t t-set="operations" t-value="data['operations']"/>
                        <t t-set="byproducts" t-value="data['byproducts']"/>
                    </t>
                </tbody>
                <t t-if="data['show_mo_costs'] or data['show_real_costs']">
                    <tr name="unit_cost" class="border-top border-dark">
                        <td class="text-end" t-att-colspan="data['footer_colspan']">Unit Cost</td>
                        <td t-if="data['show_mo_costs']" t-attf-class="text-end" t-out="data['extras']['unit_mo_cost']" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        <td t-if="data['show_bom_costs']" class="text-end" t-out="data['extras']['unit_bom_cost']" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        <td t-if="data['show_real_costs']" t-attf-class="text-end" t-out="data['extras']['unit_real_cost']" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                    </tr>
                </t>
                <t t-if="data['summary'].get('state') == 'done' and data.get('extras')">
                    <tr>
                        <td class="text-end" t-att-colspan="data['footer_colspan']">Total Cost of Components</td>
                        <td t-attf-class="text-end" t-if="data['show_mo_costs']">
                            <t t-out="data['extras'].get('total_mo_cost_components')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_bom_costs']">
                            <t t-out="data['extras'].get('total_bom_cost_components')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_real_costs']">
                            <t t-out="data['extras'].get('total_real_cost_components')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                    </tr>
                    <tr t-if="data['summary'].get('quantity') != 1">
                        <td class="text-end" t-att-colspan="data['footer_colspan']">
                            Cost of Components per unit
                            <t t-if="data['show_uom']">(in <t t-out="data['summary'].get('uom_name')"/>)</t>
                        </td>
                        <td t-attf-class="text-end {{ data['get_color'](data['extras'].get('unit_mo_cost_components_decorator')) }}" t-if="data['show_mo_costs']">
                            <t t-out="data['extras'].get('unit_mo_cost_components')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_bom_costs']">
                            <t t-out="data['extras'].get('unit_bom_cost_components')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_real_costs']">
                            <t t-out="data['extras'].get('unit_real_cost_components')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                    </tr>
                    <tr t-if="len(data.get('operations', {}).get('details', []))">
                        <td class="text-end" t-att-colspan="data['footer_colspan']">Total Cost of Operations</td>
                        <td t-attf-class="text-end {{ data['get_color'](data['extras'].get('total_mo_cost_operations_decorator')) }}" t-if="data['show_mo_costs']">
                            <t t-out="data['extras'].get('total_mo_cost_operations')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_bom_costs']">
                            <t t-out="data['extras'].get('total_bom_cost_operations')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_real_costs']"> <!-- AJOC TODO add decorator here? more below -->
                            <t t-out="data['extras'].get('total_real_cost_operations')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                    </tr>
                    <tr t-if="len(data.get('operations', {}).get('details', [])) and data['summary'].get('quantity') != 1">
                        <td class="text-end" t-att-colspan="data['footer_colspan']">
                            Cost of Operations per unit
                            <t t-if="data['show_uom']">(in <t t-out="data['summary'].get('uom_name')"/>)</t>
                        </td>
                        <td t-attf-class="text-end {{ data['get_color'](data['extras'].get('unit_mo_cost_operations_decorator')) }}" t-if="data['show_mo_costs']">
                            <t t-out="data['extras'].get('unit_mo_cost_operations')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_bom_costs']">
                            <t t-out="data['extras'].get('unit_bom_cost_operations')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_real_costs']">
                            <t t-out="data['extras'].get('unit_real_cost_operations')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                    </tr>
                    <tr t-if="len(data.get('cost_breakdown', [])) and len(data.get('operations', {}).get('details', []))">
                        <td class="text-end" t-att-colspan="data['footer_colspan']">Total Cost of Production</td>
                        <td t-attf-class="text-end" t-if="data['show_mo_costs']">
                            <t t-out="data['extras'].get('total_mo_cost')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_bom_costs']">
                            <t t-out="data['extras'].get('total_bom_cost')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                        <td class="text-end" t-if="data['show_real_costs']">
                            <t t-out="data['extras'].get('total_real_cost')" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                        </td>
                    </tr>
                </t>
            </table>
            <t t-if="len(data.get('cost_breakdown', []))">
                <h3>Cost Breakdown of Products</h3>
                <table name="breakdown" class="table table-borderless">
                    <thead>
                        <tr>
                            <th class="text-start">Product</th>
                            <th class="text-end">Avg Cost of Components per Unit</th>
                            <th t-if="len(data.get('operations', {}).get('details', []))" class="text-end">Avg Cost of Operations per Unit</th>
                            <th class="text-end">Avg Total Cost per Unit</th>
                            <th t-if="data['show_uom']" class="text-end">Unit of Measure</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr t-foreach="data['cost_breakdown']" t-as="line">
                            <td class="text-start" t-out="line['name']"/>
                            <td class="text-end" t-out="line['unit_avg_cost_component']" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                            <td t-if="len(data.get('operations', {}).get('details', []))" class="text-end" t-out="line['unit_avg_cost_operation']" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                            <td class="text-end" t-out="line['unit_avg_total_cost']" t-options="{'widget': 'monetary', 'display_currency': currency}"/>
                            <td t-if="data['show_uom']" class="text-end" t-out="line['uom_name']"/>
                        </tr>
                    </tbody>
                </table>
            </t>
        </div>
    </t>

    