<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;
    }
    table.dataTable thead .sorting:after, table.dataTable thead .sorting_asc:after, table.dataTable thead .sorting_desc:after, table.dataTable thead .sorting_asc_disabled:after, table.dataTable thead .sorting_desc_disabled:after{
        display: none;
    }
    @media print {
        {
            width: 10px !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[133]->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">
                <input type="hidden" id="searchvalue" value="{$Programsettingdata->searchvalue}">
                <input type="hidden" name="withNakdi" id="withNakdi" value="{$Usergroupdata->showClientAndSupplierOne}"/>
                <form class="form-inline hidden-print" action="salesreportbills.php" method="post" id="salesreportbills-form">
                    <div class="form-group" style="width: 30%;">
                        <label class="sr-only">العملاء</label>
                        <input type="hidden" name="clientid" id="clientid" class="select2Supp"/>
                        <input type="hidden" name="oldsupplierid" id="oldsupplierid" value=""/>
                        <input type="hidden" name="oldsuppliername" id="oldsuppliername" value=""/>
                        <!--                        <select class="select2 "  name="clientid" id="clientid" >
                                                    <option value="-1">اختر عميل</option>
                                                    <option value="0">كل العملاء</option>
                                                    {foreach $clients as $data}
                                                    <option value="{$data->clientid}">{$data->clientname}</option>
                                                    {/foreach}
                                                </select>-->
                    </div>
                    <div class="form-group">
                        <label class="sr-only">التسلسل</label>
                        <input type="text" class="form-control" name="billid" >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">رقم الفاتورة</label>
                        <input type="text" class="form-control" name="billserial" >
                    </div>
                    <div style="clear: both"></div>
                    <br />
                    {if $user->userstoreid == 0}
                    <div class="form-group">
                        <label class="sr-only">المخزن</label>
                        <select class="select2 "  name="storeId" id="storeId" >
                            <option value="-1">اختر مخزن</option>
                            <option value="0">كل المخازن</option>
                            {foreach $storeData as $store}
                            <option value="{$store->storeId}">{$store->storeName}</option>
                            {/foreach}
                        </select>
                    </div>
                    {/if}
                    {if $user->branchId == 0}
                    <div class="form-group">
                        <label class="sr-only">الفرع</label>
                        <select class="select2 "  name="branchId" id="branchId" >
                            <option value="-1">اختر الفرع</option>
                            <option value="0">كل الفروع</option>
                            {foreach $branchData as $branch}
                            <option value="{$branch->branchId}">{$branch->branchName}</option>
                            {/foreach}
                        </select>
                    </div>
                    {/if}
                    <div class="form-group">
                        <label class="sr-only">{if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</label>
                        <select class="select2 "  name="sellerid" id="sellerid" >
                            <option value="-1">اختر {if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</option>
                            <option value="0">{if $Programsettingdata->delegate_seller eq 0} البائعين {elseif $Programsettingdata->delegate_seller == 1}المندوبين {elseif $Programsettingdata->delegate_seller == 2}الاطباء {/if}</option>
                            {foreach $sellerData as $user}
                            <option value="{$user->userid}">{$user->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">المستخدم</label>
                        <select class="select2 "  name="userid" id="userid" >
                            <option value="-1">اختر المستخدم</option>
                            <option value="0">كل المستخدمين</option>
                            {foreach $userData as $user}
                            <option value="{$user->userid}">{$user->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">نوع الفاتورة</label>
                        <select class="select2 "  name="billtype" id="billtype" >
                            <option value="-1">اختر النوع</option>
                            <option value="1">مبيعات فقط</option>
                            <option value="2">مرتجعات فقط</option>
                            <option value="3">مبيعات و مرتجعات</option>
                            <option value="4">مبيعات بصريات</option>
                            <option value="5">مرتجعات بصريات</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">نوع الفاتورة</label>
                        <div  class="input-group" style="display: block">
                            <label>  <input value="1" name="obgyBillType" id="obgyBillType" type="radio">
                                مباشر</label>
                            <label>
                                <input value="2" name="obgyBillType" id="obgyBillType" type="radio">
                                مستهلك</label>
                            <label>
                                <input value="3" name="obgyBillType" id="obgyBillType" type="radio">
                                استقبال</label>
                        </div>
                    </div>
                    <div style="clear: both"></div>
                    <br />
                    <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="datefrom" >
                    </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="dateto" >
                    </div>
                    <div class="form-group">
                        <div><label class="sr-only">مجمل يوم</label></div>
                        <div class="radio-inline">
                            <input value="1" name="searchtype"  type="checkbox"/>
                        </div>
                    </div>

                    <div style="clear: both"></div>
                    <br />
                    <button type="submit" class="btn btn-primary">بحث</button>

                    <input type="hidden" name="storeIdS" value="{$storeIdS}"/>
                    <input type="hidden" name="branchIdS" value="{$branchIdS}"/>
                    <input type="hidden" name="selleridS" value="{$selleridS}"/>
                    <input type="hidden" name="useridS" value="{$useridS}"/>
                    <input type="hidden" name="clientidS" value="{$clientidS}"/>
                    <input type="hidden" name="billidS" value="{$billidS}"/>
                    <input type="hidden" name="billserialS" value="{$billserialS}"/>
                    <input type="hidden" name="billtypeS" value="{$billtypeS}"/>
                    <input type="hidden" name="obgyBillTypeS" value="{$obgyBillTypeS}"/>
                    <input type="hidden" name="day" id="day" value=""/>
                </form>

            </div>
            <div class="panel panel-default panel-m">
                <!-- Default panel contents -->
                <div class="panel-heading">{$message}</div>
                <div class="panel-body" style="overflow-x: auto;">
                    {if count($allDataArr) > 0}
                    <hr/>
                    <div class="col-lg-offset-8 col-lg-4">
                        <div class="well well-sm">
                            <h4 class="text-center">صافى الربح {$totalsObj->billProfit} {$currency}</h4>
                        </div>
                    </div>
                    <style>
                        @media print {
                            @page {
                                size: landscape;
                                margin: 0;
                            }
                            .willprint ,.willprint td,.willprint th {
                                padding:  0px !important;
                                font-family: arial;
                                font-size: 10px;
                                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>
                    {if $searchtype == "0"}
                    <table class="dataTableClass willprint table-black" style="width: 100%">
                        <thead>
                            <tr>
                                <th>م</th>
                                <!--<th>  التسلسل</th>-->
                                {if {$Programsettingdata->billid} != 1}<th><center>رقم الفاتورة</center></th>{/if}
                        <th><center>  نوع الفاتورة</center></th>
                        <th><center>اجمالى الفاتورة</center></th>
                        <th><center>عدد القطع</center></th>
                        <th><center>تاريخ الفاتورة ووقتها</center></th>
                        <th><center>خصم الفاتورة</center></th>
                        <th><center>خصومات الشبكة</center></th>
                        <th><center>ربح الفاتورة</center></th>
                        <th><center>العميل</center></th>
                        <th><center>البائع</center></th>
                        <th><center>المستخدم</center></th>
                        <th class="hidden-print"><center>تفاصيل الفاتورة</center></th>
                        </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {foreach $allDataArr as $data}
                            <tr>
                                <td>{$i}</td>
                                <!--<td>{$data->billno}</td>-->
                                {if {$Programsettingdata->billid} != 1}<td><center>{$data->billserial}</center></td>{/if}
                        <td><center>{$data->billtype}</center></td>
                        <td><center>{$data->totalbill}</center></td>
                        <td><center>{$data->noOfpieces}</center></td>
                        <td><center>{$data->datetime}</center></td>
                        <td><center>{$data->billdiscount}</center></td>
                        <td><center>{$data->networkDiscount}</center></td>
                        <td><center>{$data->billProfit}</center></td>
                        <td><center>{$data->clientName}</center></td>
                        <td><center>{$data->sellerName}</center></td>
                        <td><center>{$data->userName}</center></td>
                        <td class="hidden-print"><center><a href="{$data->billURL}" target="_blank" type="button" class="btn btn-default btn-lg notesicon"></a></center></td>

                        </tr>
                        {assign var=i value=$i+1}
                        {/foreach}
                        <tr>
                            <td><span style="display: none">z</span></td>
                            <td></td>
                            <th style="text-align: center;">الاجمالى</th>
                            <td>{$totalsObj->totalbill}</td>
                            <td>{$totalsObj->noOfpieces}</td>
                            <td></td>
                            <td>{$totalsObj->billdiscount}</td>
                            <td>{$totalsObj->networkDiscount}</td>
                            <td>{$totalsObj->billProfit}</td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td class="hidden-print"></td>
                        </tr>


                        </tbody>

                    </table>
                    {else}
                    <table class="dataTableClass willprint table-black" style="width: 100%">
                        <thead>
                            <tr>
                                <th>م</th>
                                <th>تاريخ الفاتورة ووقتها</th>
                                <th>اجمالى الفاتورة</th>
                                <th>عدد القطع</th>
                                <th>خصم الفاتورة</th>
                                <th>خصومات الشبكة</th>
                                <th>ربح الفاتورة</th>

                                <th class="hidden-print">تفاصيل الفاتورة</th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {foreach $allDataArr as $data}
                            <tr>
                                <td>{$i}</td>
                                <td>{$data->datetime}</td>
                                <td>{$data->totalbill}</td>
                                <td>{$data->noOfpieces}</td>
                                <td>{$data->billdiscount}</td>
                                <td>{$data->networkDiscount}</td>
                                <td>{$data->billProfit}</td>

                                <td class="hidden-print"><a data-day="{$data->datetime}" style="color: blue;" class="daydetail">التفاصيل</a></td>
                                <!--td class="hidden-print">{$data->billURL}</td-->
                            </tr>
                            {assign var=i value=$i+1}
                            {/foreach}
                            <tr>
                                <td><span style="display: none">z</span></td>
                                <th style="text-align: center;">الاجمالى</th>
                                <td>{$totalsObj->totalbill}</td>
                                <td>{$totalsObj->noOfpieces}</td>
                                <td>{$totalsObj->billdiscount}</td>
                                <td>{$totalsObj->networkDiscount}</td>
                                <td>{$totalsObj->billProfit}</td>
                                <td class="hidden-print"></td>
                            </tr>


                        </tbody>

                    </table>
                    {/if}

                    <div class="col-lg-offset-8 col-lg-4">
                        <div class="well well-sm">
                            <h4 class="text-center">صافى الربح {$totalsObj->billProfit} {$currency}</h4>
                        </div>
                    </div>

                    <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-->
                    {else}
                    <div class="nodata">عفوا لا توجد نتائج</div>
                    {/if}

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


{literal}
<script>
    $(document).ready(function () {
        $('.daydetail').on('click', function () {
            var day = $(this).attr('data-day');
            $('#day').val(day);
            $('#salesreportbills-form').attr("target", "_blank");
            $('#salesreportbills-form').submit();
            $('#day').val("");
            $('#salesreportbills-form').removeAttr("target");
        });
    });
    $(function () {
        $(".select2Supp").select2({
            placeholder: "العميل",
            minimumInputLength: document.getElementById("searchvalue").value,
            inimumInputLength: 0,
            multiple: false,
            quietMillis: 100,
            //width: '80%',
            ajax: {
                url: "clientControllerAjax.php?do=select2ClientsAjax",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        term: term, //search term
                        page_limit: 7, // page size
                        withAddOption: 0,
                        withNakdi: function () {
                            return (Number($('#withNakdi').val()) == 1) ? 0 : 1;
                        },
                        //jsonRowRet: 1,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: function (data) {
                if (Number(data.id) == -2) {
                    return  '<span class="newoption">' + data.text + '</span >';
                } else {
                    return  '<span>' + data.text + '</span >';
                }
            },
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                //  var data = {id: item[0], text: item[1]};
                var data = {id: item[0], text: item[1], productquantity: item[2], price: item[3]};
                callback(data);
            },
            //dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
        })
        //this is needed for ajax =>to obtain id from it  and use in ajax
        $('#clientid').select2('data', {id: $('#oldsupplierid').val(), text: $('#oldsuppliername').val()});
    });
</script>
{/literal}
