<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">اداره الفولتير </a></li>
            <li><a href="userController.php?do=show">تقرير نسب {if $Programsettingdata->delegate_seller eq 0} البائعين
                    {elseif $Programsettingdata->delegate_seller == 1}المندوبين {elseif
                    $Programsettingdata->delegate_seller == 2}الاطباء {/if}</a></li>
            <li class="active"> تقرير نسب {if $Programsettingdata->delegate_seller eq 0} البائعين {elseif
                $Programsettingdata->delegate_seller == 1}المندوبين {elseif $Programsettingdata->delegate_seller ==
                2}الاطباء {/if}</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">تقرير نسب {if $Programsettingdata->delegate_seller eq 0} البائعين {elseif
                $Programsettingdata->delegate_seller == 1}المندوبين {elseif $Programsettingdata->delegate_seller ==
                2}الاطباء {/if}<br />
                {if $message != ""}
                {$message}
                {/if}
                <a href="{$youtubes[24]->url}" target="_blank" class="hidden-print"><img
                        src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube"
                        style="width: 2%;"></a>

            </div>
            <div class="panel-body">
                <form class="form-inline hidden-print" action="userratereportController.php?do=showWithPriceTypes" method="post">
                    <div class="form-group">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"
                            data-date-format="yyyy-mm-dd" name="startDate">
                    </div>
                    <div class="form-group">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"
                            data-date-format="yyyy-mm-dd" name="endDate">
                    </div>
                    <div class="form-group">
                        <label class="sr-only">المستخدم</label>
                        <select class="select2 wdt300" name="sellerid" id="sellerid">
                            <option value="-1">اختر المستخدم</option>
                            {foreach $allsellier as $myallsellier}
                            <option value="{$myallsellier->userid}">{$myallsellier->employeename}</option>
                            {/foreach}
                        </select>
                    </div>

                    <div class="form-group">
                        <label class="sr-only">بائعين فقط
                            <input type="checkbox" class="" name="sellersOnly" id="sellersOnly" checked="checked"
                                value="1"></label>
                    </div>
                    <button type="submit" class="btn btn-primary">بحث</button>

                </form>
            </div>
            <hr />

            {if !empty($dataArr)}
            <!-- Table -->
            <table class="table table-black dataTableClass">
                <thead>
                    <tr>
                        {if !$OneSeller}
                        <th rowspan="2">اسم المستخدم</th>
                        {/if}
                        <th colspan="2">فواتير البيع جملة</th>
                        <th colspan="2">فواتير البيع نصف جملة</th>
                        <th colspan="2">فواتير البيع تجزئة</th>
                        <th rowspan="2">إجمالي الفواتير</th>
                        <th rowspan="2">إجمالي نسبة</th>
                    </tr>
                    <tr>
                        <!-- جملة -->
                        <th>إجمالي</th>
                        <th>نسبة</th>
                        <!-- نصف جملة -->
                        <th>إجمالي</th>
                        <th>نسبة</th>
                        <!-- تجزئة -->
                        <th>إجمالي</th>
                        <th>نسبة</th>
                    </tr>
                </thead>
                <tbody>
                    {assign var="totalGomlaAmount" value=0}
                    {assign var="totalGomlaRate" value=0}
                    {assign var="totalHalfAmount" value=0}
                    {assign var="totalHalfRate" value=0}
                    {assign var="totalUnitAmount" value=0}
                    {assign var="totalUnitRate" value=0}
                    {assign var="totalAmount" value=0}
                    {assign var="totalRate" value=0}

                    {foreach $dataArr as $data}
                    {assign var="totalGomlaAmount" value=$totalGomlaAmount + {$data.totalGomla}}
                    {assign var="totalGomlaRate" value=$totalGomlaRate + {$data.rateGomla}}
                    {assign var="totalHalfAmount" value=$totalHalfAmount + {$data.totalhalf}}
                    {assign var="totalHalfRate" value=$totalHalfRate + {$data.ratehalf}}
                    {assign var="totalUnitAmount" value=$totalUnitAmount + {$data.totalUnit}}
                    {assign var="totalUnitRate" value=$totalUnitRate + {$data.rateUnit}}
                    {assign var="totalAmount" value=$totalAmount + {$data.totalBill}}
                    {assign var="totalRate" value=$totalRate + {$data.totalrate}}
                    <tr>
                        {if !$OneSeller}
                        <td>{$data.sellerName}</td>
                        {/if}
                        <td>{$data.totalGomla}</td>
                        <td>{$data.rateGomla}</td>

                        <td>{$data.totalhalf}</td>
                        <td>{$data.ratehalf}</td>

                        <td>{$data.totalUnit}</td>
                        <td>{$data.rateUnit}</td>

                        <td>{$data.totalBill}</td>
                        <td>{$data.totalrate}</td>
                        
                    </tr>
                    {/foreach}
                </tbody>
                <tfoot>
                    <tr>
                        <th>الإجمالي</th>
                        <th>{$totalGomlaAmount}</th>
                        <th>{$totalGomlaRate}</th>
                        <th>{$totalHalfAmount}</th>
                        <th>{$totalHalfRate}</th>
                        <th>{$totalUnitAmount}</th>
                        <th>{$totalUnitRate}</th>
                        <th>{$totalAmount}</th>
                        <th>{$totalRate}</th>
                    </tr>
                </tfoot>
            </table>
            {/if}

            <div class="row">

                <div class="well well-sm2">
                    <h4 class="text-center">إجمالي نسب البائعين {$totalRates}</h4>
                </div>
                <div class="well well-sm2">
                    <h4 class="text-center">إجمالي الفواتير {$totalsell}</h4>
                </div>
            </div>
        </div>
    </div>
</div>



<div class="hidden-print">
    <div class="col-lg-12">
        <div class="form-group">
            <div class="col-lg-4">
                <button type="button" onclick="print_Custom('mycustomheader');"
                    class="btn btn-success pull-right">طباعة</button>
            </div>
        </div>
    </div>
    <div class="clearfix"></div>
</div>


{literal}
<script>
    $(document).ready(function (e) {
        $('#sellersOnly').on('change', function () {
            let sellersOnly = 0;
            if($(this).is(':checked'))
                sellersOnly = 1;
            $.post('userratereportController.php?do=getUsers', { sellersOnly: sellersOnly }, function (res) {
                $('#sellerid').html(res);
            });
        });
    });
</script>
{/literal}