<odoo>
<record id="action_week_summary_report" model="ir.actions.report">
        <field name="name">Spenco Summary Reports</field>
        <field name="model">sos_spenco_summary_week_wise</field>
        <field name="report_type">qweb-html</field>
        <field name="report_name">sos_sales.report_week_summary</field>
        <field name="print_report_name">Spenco_Week_Summary</field>
    </record>
    <template id="report_week_summary">
        
            <t t-call="web.basic_layout">

<t t-call="web.html_container">
                <link rel="stylesheet" href="/sos_inventory/static/src/css/style.css?v=7" />
                <div class="page">
                    <div style="padding: 2px;">
                 <style>
    .summary_table th, .summary_table td {
        border: 1px solid #ccc;
        padding: 4px;
        text-align: center;
        font-size: 15px;
    }
    .weekly-col,.quartely-col {
        background-color: #e8f1ff;
    }
    .mtd-col,.yearly-col {
        background-color: #fff3d1;
    }
</style>
<div style="font-weight: bold;padding: 10px;border: solid 1px #ccc;">Sales Executive : <t t-esc="sales_person_name"/></div>

<table class="summary_table" style="width: 100%; border-collapse: collapse;">
    <thead>
        <tr>
            <th rowspan="2"></th>
            <!-- Weekly Header -->
            <th class="weekly-col" colspan="10">Weekly (<t t-esc="week_number"/>)</th>
            <!-- MTD Header -->
            <th class="mtd-col" colspan="10">Monthly Till Date (<t t-esc="month_number"/>)</th>
        </tr>
        <tr>
            <!-- Weekly -->
            <th class="weekly-col" colspan="2">P</th>
            <th class="weekly-col" colspan="2">E</th>
            <th class="weekly-col" colspan="2">N</th>
            <th class="weekly-col" colspan="2">CO</th>
            <th class="weekly-col" colspan="2">Total</th>
            <!-- MTD -->
            <th class="mtd-col" colspan="2">P</th>
            <th class="mtd-col" colspan="2">E</th>
            <th class="mtd-col" colspan="2">N</th>
            <th class="mtd-col" colspan="2">CO</th>
            <th class="mtd-col" colspan="2">Total</th>
        </tr>
        <tr>
            <th></th>
            <!-- Weekly labels -->
            <t t-foreach="[1,2,3,4,5]" t-as="i">
                <th class="weekly-col">#Cases</th>
                <th class="weekly-col">Value</th>
            </t>
            <!-- MTD labels -->
            <t t-foreach="[1,2,3,4,5]" t-as="i">
                <th class="mtd-col">#Cases</th>
                <th class="mtd-col">Value</th>
            </t>
        </tr>
    </thead>

    <tbody>
        <tr t-foreach="['Opening', 'Downgrade', 'Upgrade', 'New', 'Closing']" t-as="stage">
            <td><t t-esc="stage"/></td>

            <!-- Weekly Data -->
            <td><t t-esc="aggregated_data.get(stage, {}).get('P', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data.get(stage, {}).get('P', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data.get(stage, {}).get('E', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data.get(stage, {}).get('E', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data.get(stage, {}).get('N', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data.get(stage, {}).get('N', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data.get(stage, {}).get('CO', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data.get(stage, {}).get('CO', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data.get(stage, {}).get('EOV', {}).get('count', 0.0)"/></td>
            <td><t t-esc="'{:.1f}'.format(aggregated_data.get(stage, {}).get('EOV', {}).get('value', 0.0))"/></td>

            <!-- MTD Data -->
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('P', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('P', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('E', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('E', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('N', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('N', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('CO', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('CO', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_month.get(stage, {}).get('EOV', {}).get('count', 0.0)"/></td>
            <td><t t-esc="'{:.1f}'.format(aggregated_data_month.get(stage, {}).get('EOV', {}).get('value', 0.0))"/></td>

        </tr>
<t t-set="val_p" t-value="0.1 * sum(aggregated_data.get(stage, {}).get('P', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_e" t-value="0.3 * sum(aggregated_data.get(stage, {}).get('E', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_n" t-value="0.5 * sum(aggregated_data.get(stage, {}).get('N', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_co" t-value="sum(aggregated_data.get(stage, {}).get('CO', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="final_sum" t-value="val_p + val_e + val_n + val_co"/>

<t t-set="val_p_month" t-value="0.1 * sum(aggregated_data_month.get(stage, {}).get('P', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_e_month" t-value="0.3 * sum(aggregated_data_month.get(stage, {}).get('E', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_n_month" t-value="0.5 * sum(aggregated_data_month.get(stage, {}).get('N', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_co_month" t-value="sum(aggregated_data_month.get(stage, {}).get('CO', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="final_sum_month" t-value="val_p_month + val_e_month + val_n_month + val_co_month"/>

<t t-set="val_p_quarter" t-value="0.1 * sum(aggregated_data_quarter.get(stage, {}).get('P', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_e_quarter" t-value="0.3 * sum(aggregated_data_quarter.get(stage, {}).get('E', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_n_quarter" t-value="0.5 * sum(aggregated_data_quarter.get(stage, {}).get('N', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_co_quarter" t-value="sum(aggregated_data_quarter.get(stage, {}).get('CO', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="final_sum_quarter" t-value="val_p_quarter + val_e_quarter + val_n_quarter + val_co_quarter"/>

<t t-set="val_p_year" t-value="0.1 * sum(aggregated_data_year.get(stage, {}).get('P', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_e_year" t-value="0.3 * sum(aggregated_data_year.get(stage, {}).get('E', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_n_year" t-value="0.5 * sum(aggregated_data_year.get(stage, {}).get('N', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="val_co_year" t-value="sum(aggregated_data_year.get(stage, {}).get('CO', {}).get('value', 0.0) for stage in ['Closing'])"/>
<t t-set="final_sum_year" t-value="val_p_year + val_e_year + val_n_year + val_co_year"/>
        <tr class="final-row">
    <td><strong>EOV</strong></td>

    <!-- Weekly Totals -->
    <td></td>
    <td><t t-esc="'{:.2f}'.format(val_p)"/></td>

    <td></td>
    <td><t t-esc="'{:.2f}'.format(val_e)"/></td>

    <td></td>
    <td><t t-esc="'{:.2f}'.format(val_n)"/></td>

    <td></td>
    <td><t t-esc="'{:.2f}'.format(val_co)"/></td>

    <td></td>
    <td><t t-esc="'{:.2f}'.format(final_sum)"/></td>
    <!-- MTD Totals -->
   <td></td>
<td><t t-esc="'{:.2f}'.format(val_p_month)"/></td>

<td></td>
<td><t t-esc="'{:.2f}'.format(val_e_month)"/></td>

<td></td>
<td><t t-esc="'{:.2f}'.format(val_n_month)"/></td>

<td></td>
<td><t t-esc="'{:.2f}'.format(val_co_month)"/></td>

<td></td>
<td><t t-esc="'{:.2f}'.format(final_sum_month)"/></td>
</tr>
        
    </tbody>
</table>
<table class="summary_table" style="width: 100%; border-collapse: collapse;">
    <thead>
        <tr>
            <th rowspan="2"></th>
            <!-- quartely Header -->
            <th class="quartely-col" colspan="10">Quartely Till Date (<t t-esc="quarter_number"/>)</th>

            <!-- yearly Header -->
            <th class="yearly-col" colspan="10">Yearly Till Date (<t t-esc="year_number"/>)</th>
        </tr>
        <tr>
            <!-- quartely -->
            <th class="quartely-col" colspan="2">P</th>
            <th class="quartely-col" colspan="2">E</th>
            <th class="quartely-col" colspan="2">N</th>
            <th class="quartely-col" colspan="2">CO</th>
            <th class="quartely-col" colspan="2">Total</th>
            <!-- yearly -->
            <th class="yearly-col" colspan="2">P</th>
            <th class="yearly-col" colspan="2">E</th>
            <th class="yearly-col" colspan="2">N</th>
            <th class="yearly-col" colspan="2">CO</th>
            <th class="yearly-col" colspan="2">Total</th>
        </tr>
        <tr>
            <th></th>
            <!-- quartely labels -->
            <t t-foreach="[1,2,3,4,5]" t-as="i">
                <th class="quartely-col">#Cases</th>
                <th class="quartely-col">Value</th>
            </t>
            <!-- yearly labels -->
            <t t-foreach="[1,2,3,4,5]" t-as="i">
                <th class="yearly-col">#Cases</th>
                <th class="yearly-col">Value</th>
            </t>
        </tr>
    </thead>

    <tbody>
        <tr t-foreach="['Opening', 'Downgrade', 'Upgrade', 'New', 'Closing']" t-as="stage">
            <td><t t-esc="stage"/></td>

            <!-- quartely Data -->
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('P', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('P', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('E', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('E', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('N', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('N', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('CO', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('CO', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_quarter.get(stage, {}).get('EOV', {}).get('count', 0.0)"/></td>
            <td><t t-esc="'{:.1f}'.format(aggregated_data_quarter.get(stage, {}).get('EOV', {}).get('value', 0.0))"/></td>
            <!-- yearly Data -->
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('P', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('P', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('E', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('E', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('N', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('N', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('CO', {}).get('count', 0)"/></td>
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('CO', {}).get('value', 0.0)"/></td>
            <td><t t-esc="aggregated_data_year.get(stage, {}).get('EOV', {}).get('count', 0.0)"/></td>
            <td><t t-esc="'{:.1f}'.format(aggregated_data_year.get(stage, {}).get('EOV', {}).get('value', 0.0))"/></td>

        </tr>
                <tr class="final-row">
    <td><strong>EOV</strong></td>

    <!-- Quartely Totals -->
    <td></td>
    <td><t t-esc="'{:.2f}'.format(val_p_quarter)"/></td>

    <td></td>
    <td><t t-esc="'{:.2f}'.format(val_e_quarter)"/></td>

    <td></td>
    <td><t t-esc="'{:.2f}'.format(val_n_quarter)"/></td>

    <td></td>
    <td><t t-esc="'{:.2f}'.format(val_co_quarter)"/></td>

    <td></td>
    <td><t t-esc="'{:.2f}'.format(final_sum_quarter)"/></td>
    <!-- Yearly Totals -->
   <td></td>
<td><t t-esc="'{:.2f}'.format(val_p_year)"/></td>

<td></td>
<td><t t-esc="'{:.2f}'.format(val_e_year)"/></td>

<td></td>
<td><t t-esc="'{:.2f}'.format(val_n_year)"/></td>

<td></td>
<td><t t-esc="'{:.2f}'.format(val_co_year)"/></td>

<td></td>
<td><t t-esc="'{:.2f}'.format(final_sum_year)"/></td>
</tr>
    </tbody>
</table>

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