<style>
    .myresult {
        -webkit-print-color-adjust: exact;
    }
    .nodata{
        background-color: #72B4EC;
        color: white;
        border-radius: 13px;
        margin: 14px;
        font-size: 24px;
        text-align: center;
        padding: 5px;
    }

    @media print {
        @page {
            size: landscape;
            margin: 0;
        }
        .willprint ,.willprint td,.willprint th {
            font-family: arial;
            font-size: 14px;
            border-collapse: collapse;
            border: 1px solid #333 !important;
        }
        /* .willprint th{
            background: #aaa !important;
        } */
        .willprint tr:even-child td{
            background: #333 !important;
            color: #fff !important;
        }
    }

</style>



<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">التقارير</a></li>
            <li class="active">تقرير ترتيب العملاء بصافى المبيعات</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">تقرير ترتيب العملاء بصافى المبيعات
                <a href="{$youtubes[137]->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="orderClientsWithSelles.php" method="post">
                    <div class="form-group col-lg-3">
                        <label class="sr-only">نوع العميل</label>
                        <select class="select2 wdt300" name="clientType" id="clientType" >
                            <option value="-1"></option>
                            {foreach $typeClient as $data}
                            <option value="{$data['typeId']}">{$data['typeName']}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group col-lg-3">
                        <label class="sr-only">المخزن</label>
                        <select class="select2 wdt300" name="storeid" id="storeid" >
                            <option value="-1"></option>
                            {foreach $storeData as $store}
                            <option value="{$store->storeId}">{$store->storeName}</option>
                            {/foreach}
                        </select>
                    </div>
                    <!--                    <div class="form-group col-lg-3">
                                            <label class="sr-only">الخزنة</label>
                                            <select class="select2 wdt300" name="saveid" id="saveid" >
                                                <option value="-1"></option>
                                                {foreach $saveData as $data}
                                                <option value="{$data->saveid}">{$data->savename}</option>
                                                {/foreach}
                                            </select>
                                        </div>-->
                    <div class="form-group col-lg-3">
                        <label class="sr-only">تصنيف المنتج</label>
                        <select class="select2 wdt300 productCat" data-level="0"  name="productCatId0" id="productCatId0" >
                            <option value="-1">اختر تصنيف</option>
                            {foreach $catDataReport as $data}
                            <option value="{$data->productCatId}">{$data->productCatName}</option>
                            {/foreach}
                        </select>
                        <input type="hidden" id="level" name="level" value="0">
                    </div>

                    <div id="manyParents">

                    </div>
                    <div style="clear: both"></div>

                    <div class="form-group">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"  value="{$datefrom}" data-date-format="yyyy-mm-dd" name="datefrom" id="datefrom" >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker" autocomplete="off"  value="{$dateto}" data-date-format="yyyy-mm-dd" name="dateto" id="dateto" >
                    </div>
                    <br />
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>

            </div>
            <div class="panel panel-default panel-m">
                <!-- Default panel contents -->
                <div class="panel-heading">{$message}</div>


                {if $resultsCount > 0 }
                <table class="stable dataTableClass22 willprint table-black" style="width: 100%">
                    <thead>
                        <tr>
                            <th >#</th>
                            <th > اسم العميل</th>
                            <th > التليفون</th>
                            <th > الموبايل</th>
                            <th > نوع العميل</th>
                            <th >المبيعات </th>
                            <th >المرتجعات</th>
                            <th > المبيعات بدون الخصومات</th>
                            <th >   الخصومات</th>
                            <th >   صافى المبيعات</th>
                            <th >مديونيه العميل </th>
                            <th >مدفوعات عميل </th>
                        </tr>

                    </thead>
                    <tbody>
                        {assign var=i value=1}
                        {assign var=totalsell value=0}
                        {assign var=totalreturn value=0}
                        {assign var=dis value=0}
                        {assign var=bure value=0}
                        {assign var=clientdebt value=0}
                        {assign var=totalPrice value=0}
                        {assign var=totalSum value=0}

                        {foreach $sellbillDataArr as $data}

                        {assign var=sum value=0}


                        <tr>
                            <td >{$i}</td>
                            <td >
                                <a href="javascript:;"  data-id="{$data->clientid}" class="getSellersData">{$data->clientname}</a></td>
                            <td >{$data->phone}</td>
                            <td >{$data->mobile}</td>
                            <td >
                                {$data->typeclient}
                            </td>
                            <td >{$data->totalsell}</td>
                            <td >{$data->totalreturn}</td>
                            <td >{if $data->totalreturn <= 0 }
                                {$sum = {$data->totalsell  +   $data->totalreturn} }
                                {$sum}
                                {else}
                                {$sum = {$data->totalsell  -   $data->totalreturn}}
                                {$sum}
                                {/if}
                            </td>
                            <td >{$data->t_dis}</td>
                            <td >{$data->t_bure}</td>
                            <td >{$data->clientdebt}</td>
                            <td >{$data->totalPrice}</td>

                        </tr>

                        {assign var=totalsell value=$totalsell+$data->totalsell}
                        {assign var=totalreturn value=$totalreturn+$data->totalreturn}
                        {assign var=dis value=$dis+$data->t_dis}
                        {assign var=bure value=$bure+$data->t_bure}
                        {assign var=clientdebt value=$clientdebt+$data->clientdebt}
                        {assign var=totalPrice value=$totalPrice+$data->totalPrice}
                        {assign var=totalSum value=$totalSum+$sum}
                        {assign var=i value=$i+1}
                        {/foreach}
                    </tbody>

                    <tfoot style="background-color: #ccc">
                        <tr>
                            <td colspan="5">الاجمالي</td>
                            <td>{$totalsell}</td>
                            <td>{$totalreturn}</td>
                            <td>{$totalSum}</td>
                            <td>{$dis}</td>
                            <td>{$bure}</td>
                            <td>{$clientdebt}</td>
                            <td>{$totalPrice}</td>
                        </tr>
                    </tfoot>

                </table>
                <div class="col-lg-4 col-lg-offset-8">
                    <div class="well well-sm ">
                        <h4 class="text-center">اجمالى الخصومات  {$t_discount}</h4>
                    </div>
                </div>




                {else}
                <div class="nodata">عفوا لا توجد نتائج</div>
                {/if}

                <div class="clearfix"></div>
                <hr />
                <div  class="noprint">
                    <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 hidden-print">طباعة</button>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>


                <div class="clearfix"></div>
            </div>
        </div>
    </div>

    <div  class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog"  style="width:600px;">
            <div class="modal-content">
                <div class="modal-header text-center">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true" class="text-left">&times;</span><span class="sr-only"></span></button>
                    <h3 class="modal-title" id="myModalLabel">تفاصيل البائعين</h3>
                </div>
                <div class="modal-body">
                    <div class="card" id="sellerDataDiv">


                    </div>
                    <!-- end of title row-->


                    <div class="row  hidden-print m10" >
                        <div class="col-lg-12 text-center">
                            <button type="button"  data-dismiss="modal"   class="btn btn-primary">
                                <i class="glyphicon glyphicon-ok "></i>  رجوع</button>
                        </div>



                    </div>
                    <!-- end of fifth row-->

                </div>

            </div>
        </div>
    </div>

    {literal}
    <script>
        $(document).ready(function () {
            $('.getSellersData').on('click', function () {
                var clientid = $(this).data('id');
                var datefrom = $('#datefrom').val();
                var dateto = $('#dateto').val();
                $.post('orderClientsWithSelles.php?do=showsellersajax', {clientid: clientid, datefrom: datefrom, dateto: dateto}, function (res) {
                    $('#myModal').modal('show');
                    $('#sellerDataDiv').html(res);
                });
            });

            $('.productCat').live('change', function () {
                var id = $(this).val();
                var level = Number($(this).attr('data-level'));
                level = level + 1;
                $('#level').val(level);
                $.post('salesreportajax.php?do=getsubcat', {id: id, level: level}, function (data) {
                    $('.productCat').each(function () {
                        var thisLevel = Number($(this).attr('data-level'));
                        if (thisLevel >= level) {
                            $(this).parent('div').remove();
                        }
                    });
                    $('#productIdDiv').remove();
                    if (data != "-1") {
                        $('#manyParents').append(data);
                    } else
                    {
                        $('#level').val((level - 1));
                    }
                });

            });

            $('.dataTableClass22').dataTable({
                "order"
                        : [
                            [9, "desc"]       // order by drug cat
                        ]
            });
        });

    </script>
    {/literal}
