<odoo>
<record id="action_case_diary_report" model="ir.actions.report">
    <field name="name">Case Diary Report</field>
    <field name="model">sos_case_diary_report</field>
    <field name="report_type">qweb-html</field>
    <field name="report_name">sos_sales.case_diary_report_template</field>
    <field name="report_file">sos_sales.case_diary_report_template</field>
    <field name="binding_model_id" ref="model_sos_case_diary_report"/>
</record>

<template id="case_diary_report_template">
    <t t-call="web.html_container">
            <link rel="stylesheet" href="/sos_inventory/static/src/css/style.css?v=8" />
            <div class="page">

                <br/>

<div class="col-md-4 offset-md-4 card_custom">
    <h4>Summary</h4>
<table class="table_custom">
    <thead>
        <tr style="background-color: lavender;font-size: 16px;
    font-weight: bold;">
            <th>Status</th>
            <th>No of Cases(Qty)</th>
            <th>Value(In Lakhs)</th>
        </tr>
    </thead>
    <tbody>
        <!-- Use the spenco_summary from the first record -->
        <t t-if="docs and docs[0].spenco_summary">
            <t t-foreach="docs[0].spenco_summary.split('\n')" t-as="summary_line">
                  <tr>
                    <td><t t-esc="summary_line.split(':')[0]"/></td> <!-- Status -->
                    <td>
                        <t t-esc="summary_line.split('=')[1].split(',')[0].strip()"/> <!-- Count -->
                    </td>
                    <td>
                    <t t-esc="'₹ {:.2f}'.format(float(summary_line.split('=')[2].strip()))"/>

                    </td>
                </tr>
            </t>
        </t>
        <t t-else="">
            <tr>
                <td colspan="2">No Summary Available</td>
            </tr>
        </t>
    </tbody>
</table>
</div>


<div class="col-lg-10 offset-lg-1">
        <h4>Detailed Report</h4>
        <table class="table_custom">
            <thead>
                <tr style="background-color: lavender;font-size: 16px;
    font-weight: bold;">
                    <th>Customer Name</th>
                    <th>Action Plan Date</th>
                    <th>Value</th>
                    <th>Action Plan</th>
                    <th>Notes</th>
                    <th>Status</th>
                    <th>Status Changed On</th>
                </tr>
            </thead>
           <tbody>
    <!-- Initialize current_sales_person -->
    <t t-set="current_sales_person" t-value="None"/>
    <t t-foreach="docs" t-as="doc">
        <!-- Check if the sales_person has changed -->
        <t t-if="doc.sales_person and doc.sales_person.name != current_sales_person">
            <tr>
                <th colspan="7" style="background-color: #d3d3f9; text-align: left; padding: 5px;">
                    Sales Executive: <t t-esc="doc.sales_person.name or 'N/A'"/>
                </th>
            </tr>
            <!-- Update current_sales_person -->
            <t t-set="current_sales_person" t-value="doc.sales_person.name"/>
        </t>
        <!-- Display the record under the grouped Sales Executive -->
        <tr>
            <td><t t-esc="doc.customer_name.customer_name.customer_name or 'N/A'"/></td>
            <td><t t-esc="doc.action_plan_date or 'N/A'"/></td>
            <td><t t-esc="doc.current_state_value or 'N/A'"/></td>
            <td><t t-esc="doc.action_plan or 'N/A'"/></td>
            <td><t t-esc="doc.notes or 'N/A'"/></td>
            <td><t t-esc="doc.spenco_status or 'N/A'"/></td>
            <td><t t-esc="doc.status_changed_on or 'N/A'"/></td>
        </tr>
    </t>
</tbody>

        </table>
        <br></br>
        </div>
        </div>
    </t>
</template>




</odoo>
