<odoo>
  <record id="action_report_fir" model="ir.actions.report">
        <field name="name">FIR Form</field>
        <field name="model">sos_fir</field>
        <field name="report_type">qweb-pdf</field>
        <field name="report_name">sos_inventory.report_fir</field>
        <field name="report_file">sos_inventory.report_fir</field>
        <field name="print_report_name">"Report _ %s" % object.fir_no</field>
        <field name="binding_model_id" eval="False"/>
        <field name="binding_type">report</field>
    </record>

<template id="report_fir">
    <t t-call="web.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="web.external_layout">
             <link rel="stylesheet" href="/sos_inventory/static/src/css/style.css" />
                <div class="page">

                    <h2 style="text-align:center">Final Inspection Report</h2>
                    <br></br>
                    <!-- HTML Table -->
                    <table class="table table-bordered">
                        <tbody>
                            <tr>
                    
                                <td class="column">FIR No</td><td><t t-esc="o.fir_no"/></td>
                            
                                <td class="column">FIR Date</td><td><t t-esc="o.fir_date"/></td>
                            </tr>
                            <tr>
                            <td class="column">Product Name</td><td><t t-esc="o.product_type"/></td>

                                <td class="column">Batch No</td><td><t t-esc="o.batch_No"/></td>
                           
                            </tr>
                            <tr>
                                <td class="column">Customer Name</td><td><t t-esc="o.customer_name.customer_name"/></td>
                                <td class="column">Manufacturing Date</td><td><t t-esc="o.mfg_date"/></td>
                           
                            </tr>
                            <t t-if="o.approved_qty &lt; o.sampling_size">
                        <tr>
                                <td class="column">Batch Size</td><td><t t-esc="o.approved_qty"/></td>
                                <td class="column">Sampling Size</td><td><t t-esc="o.approved_qty"/></td>
                           
                            </tr>
                      
</t>
                             <t t-else="">
                        <tr>
                                <td class="column">Batch Size</td><td><t t-esc="o.approved_qty"/></td>
                                <td class="column">Sampling Size</td><td><t t-esc="o.sampling_size"/></td>
                           
                            </tr>
         

                            </t>  
                                                        <tr>
                            <td class="column">FG Name</td>
<td colspan="3">
    <t t-foreach="o.fg_name" t-as="fg">
        <t t-esc="fg.name"/>
        <br/>
    </t>
</td>

                            </tr>
                        </tbody>
                    </table>
                  <table class="table table-bordered" style="width:100%;">
    <tbody>
    <tr style="background-color:#ccc"><td colspan="7" class="column"><h5>Serial No's</h5></td></tr>


    <t t-set="lines" t-value="o.serial_no_line_ids"/>
    <t t-foreach="range(0, len(lines), 2)" t-as="i">
      <tr>
        <td><t t-esc="lines[i].serial_no or ''"/></td>
        <td><t t-esc="(lines[i+1].serial_no if i+1 &lt; len(lines) else '')"/></td>
      </tr>
    </t>
  </tbody>
</table>

<!-- <table class="table table-bordered">
    <tbody>
<tr style="background-color:#ccc"><td colspan="7" class="column"><h5>Summary Report</h5></td></tr>

      <tr class="column">
                <td>Sampled Quantity</td>
                <td>Approved Quantity</td>
                <td>Rejected Quantity</td>
                <td>Rejection Percentage</td>
            </tr>
  
<tr>
<td><t t-esc="o.sampling_size"/></td>
<td><t t-esc="o.approved_qty"/></td>
<td><t t-esc="o.rejected_qty"/></td>
<td><t t-esc="o.rejection_percentage_display"/></td>
</tr>

        </tbody>
    </table>
    <br></br> -->

<table class="table table-bordered">
    <tbody>
<tr style="background-color:#ccc"><td colspan="7" class="column"><h5>Monitoring &amp; Measuring Equipment Details</h5></td></tr>

      <tr class="column">
      <td>S.No</td>
                <td>Equipment Name</td>
                <td>Identification No</td>
                <td>Certification No</td>
                <td>Calibrated On</td>
                <td>Calibrated Due</td>
          
            </tr>
  
<t t-foreach="o.calibration_line_ids" t-as="line_items">
<tr>
<td><t t-esc="line_items_index + 1"/></td>
<td><t t-esc="line_items.calibration_device.name"/></td>
<td><t t-esc="line_items.identification_No"/></td>
<td><t t-esc="line_items.certification_No"/></td>
<td><t t-esc="line_items.calibrated_date"/></td>
<td><t t-esc="line_items.due_date"/></td>
</tr>
</t>

        </tbody>
    </table>
<br></br>

<table class="table table-bordered">
    <tbody>
<tr style="background-color:#ccc"><td colspan="8" class="column"><h5>Inspection Details</h5></td></tr>

      <tr class="column">
                <td>S.No</td>
                <td>Testing parameter</td>
                <td>Specification</td>
                <td>Results</td>
                <td>Inspection Remarks</td>
            
            </tr>
  
<t t-foreach="o.testing_parameter_line_ids" t-as="line_items">
    <tr>
        <td><t t-esc="line_items_index + 1"/></td>
        <td><t t-esc="line_items.testing_parameter.name"/></td>
        <td><t t-esc="line_items.specification"/></td>
        <td>
            <t t-if="line_items.results and isinstance(line_items.results, str)">
                <t t-foreach="line_items.results.split('\n')" t-as="part">
                    <t t-esc="part"/><br/>
                </t>
            </t>
        </td>
        <td>PASS</td>
    </tr>
</t>


        </tbody>
    </table>
                        <div style="page-break-after: always;">
</div>

  <div style="width: 100%; display: flex; justify-content: space-between; margin-top: 50px;">

<table class="table table-bordered">

        <tr style="background-color:#ccc">
        <td style="padding: 8px;" class="column"><b>Department </b></td>
            <td style="padding: 8px;" class="column"><b>Authorized Signatory </b></td>
            <td style="padding: 8px;" class="column"><b>Authorized On</b></td>
            <td style="padding: 8px;" class="column"><b>Authorized By</b></td>
        </tr>
        <tr>
        <td>QC</td>
            <td><img style="height:80px;width:100px" t-if="o.qc_by_image" t-att-src="'data:image/png;base64,%s' % (o.qc_by_image.decode())" alt="Tested By"/></td>

            <td><t t-esc="o.qc_tested_on"/></td>
             <td><t t-esc="o.qc_by_name.name"/></td>
        </tr>
        <tr>
        <td>QA</td>
            <td><img style="height:80px;width:100px" t-if="o.qa_by_image" t-att-src="'data:image/png;base64,%s' % (o.qa_by_image.decode())" alt="Tested By"/></td>

            <td><t t-esc="o.qa_tested_on"/></td>
             <td><t t-esc="o.qa_by_name.name"/></td>
        </tr>
      
    </table>

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

</odoo>
