<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="sales_category_view">
        <t t-call="web.html_container">
            <t t-call="web.external_layout">
                <t class="page">
                    <div class="oe_structure"/>
                    <center>
                        <b>
                            <h3>Sales category Report</h3>

                        </b>
                    </center>
                    <t t-if="start_date and end_date">
                        <center>
                            <span t-esc="start_date"/>
                            To
                            <span t-esc="end_date"/>
                        </center>
                    </t>
                    <t t-if="categ_id">
                        <t t-foreach="categ_id" t-as="categ">
                            <center>
                                <b>
                                    <span t-esc="categ['name']"/>
                                </b>
                            </center>
                            <br/>
                            <t t-set="t_qty" t-value="0"/>
                            <t t-set="t_price" t-value="0"/>
                            <t t-set="t_total" t-value="0"/>
                            <t t-set="t_subtotal" t-value="0"/>
                            <table class="table table-condensed">
                                <thead>
                                    <tr>
                                        <th>Order</th>
                                        <th>Date</th>
                                        <th>Product</th>
                                        <th>Quantity</th>
                                        <th>UOM</th>
                                        <th>Price</th>
                                        <th>Tax(%)</th>
                                        <th>Subtotal</th>
                                        <th>Total</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr t-foreach="form" t-as="order">
                                        <t t-if="order['category_id'] == categ['id']">
                                            <td>
                                                <span t-esc="order['so']"/>
                                            </td>
                                            <td>
                                                <span t-esc="order['date']" t-options='{"widget": "date"}'/>
                                            </td>
                                            <td>
                                                <span t-esc="order['product_id']"/>
                                            </td>
                                            <td>
                                                <span t-esc="order['quantity']"/>
                                                <t t-set="t_qty" t-value="t_qty + order['quantity']"></t>
                                            </td>
                                            <td>
                                                <span t-esc="order['uom']"/>
                                            </td>
                                            <td>
                                                <span t-esc="order['price']"/>
                                                <t t-set="t_price" t-value="t_price + order['price']"></t>
                                            </td>
                                            <td>
                                                <span t-esc="order['tax']"/>
                                            </td>
                                            <td>
                                                <span t-esc="order['subtotal']"/>
                                                <t t-set="t_subtotal" t-value="t_subtotal + order['subtotal']"></t>

                                            </td>
                                            <td>
                                                <span t-esc="order['total']"/>
                                                <t t-set="t_total" t-value="t_total + order['total']"></t>

                                            </td>
                                        </t>
                                    </tr>
                                    <tr>
                                        <td colsapn="3">
                                            <span>Total Quantity</span>
                                            <t t-esc="t_qty"/>
                                        </td>
                                        <td>
                                            <span>Total Price:</span>
                                            <t t-esc="t_price"/>
                                        </td>
                                        <td>
                                            <span>Total Subtotal:</span>
                                            <t t-esc="t_subtotal"/>
                                        </td>
                                        <td>
                                            <span>Total:</span>
                                            <t t-esc="t_total"/>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </t>
                    </t>
                </t>
            </t>
        </t>
    </template>
</odoo>
