<!--<style>
    .tab-pane{
        min-height: 500px;
        max-height: 500px;
        overflow-y: scroll;
    }
</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[32]->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="sellbillController.php?do=show" method="post">
                    <div class="form-group">
                        <label class="sr-only">العميل</label>
                        <input type="hidden" name="clientid" id="clientid" class="select2Supp search_bill"/>
                        <input type="hidden" name="oldsupplierid" id="oldsupplierid" value=""/>
                        <input type="hidden" name="oldsuppliername" id="oldsuppliername" value=""/>
                        <!--                        <select class="select2 wdt100 search_bill"  name="clientid" id="clientid" >
                                                    <option value="-1">اختر عميل</option>
                                                    {foreach $clientData as $clihent}
                                                    <option value="{$clihent->clientid}">{$clihent->clientname}</option>
                                                    {/foreach}
                                                </select>-->
                    </div>
                    <div class="form-group">
                        <label class="sr-only">نوع العميل</label>
                        <select class="select2 wdt100 search_bill"  name="typeClient" id="typeClient" >
                            <option value="-1">اختر نوع عميل</option>
                            {foreach $typeClient as $data}
                            <option value="{$data->typeId}">{$data->typeName}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">اسم العميل المؤقت</label>
                        <input type="text" class="form-control search_bill" placeholder="اسم العميل المؤقت" name="tempclientName" id="tempclientName">
                    </div>





                    <div class="form-group">
                        <label class="sr-only">رقم الفاتورة</label>
                        <input type="text" class="form-control search_bill" placeholder="رقم الفاتورة" name="sellbillserial" id="sellbillserial">
                    </div>
                    <div class="form-group">
                        <label class="sr-only">الرقم تسلسل الفاتورة</label>
                        <input type="text" class="form-control search_bill" placeholder="رقم تسلسل الفاتورة" name="sellbillid" id="sellbillid">
                    </div>
                    <br/>
                    <div class="form-group">
                        <label class="sr-only">المخزن</label>
                        <select class="select2 wdt100 search_bill"  name="storeid" id="storeid" >
                            <option value="-1">اختر المخزن</option>
                            {foreach $stores as $data}
                            <option value="{$data->storeId}">{$data->storeName}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">الخزنة</label>
                        <select class="select2 wdt100 search_bill"  name="saveid" id="saveid" >
                            {if $user->searchinonesave == 0}<option value="-1">اختر الخزنة</option>{/if}
                            {foreach $saves as $data}
                            <option value="{$data->saveid}">{$data->savename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group" >
                        <label class="sr-only">مندوب / طبيب / بائع</label>
                        <select class="select2 wdt100 search_bill"  name="sellerid" id="sellerid" >
                            <option value="-1">اختر </option>
                            {foreach $sellerData as $mysellerData}
                            <option value="{$mysellerData->userid}">{$mysellerData->employeename}</option>
                            {/foreach}
                        </select>
                    </div>

                    <div class="form-group">
                        <label class="sr-only">اسم المستخدم</label>
                        <select class="select2 wdt100 search_bill"  name="selleruserid" id="selleruserid" >
                            <option value="-1">اختر المستخدم</option>
                            {foreach $sellerinsertData as $mysellerinsertData}
                            <option value="{$mysellerinsertData->userid}">{$mysellerinsertData->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <!--                    <div class="form-group">
                                            <label class="sr-only">نوع السعر</label>
                                            <select class="select2 search_bill wdt100" name="pricetype" id="pricetype">
                                                <option value="-1"></option>
                                                <option value="0">جملة</option>
                                                <option value="1">تجزئة</option>
                                                <option value="2">نصف جملة</option>
                                            </select>
                                        </div>-->
                    <div id="dateTimeDiv">
                        <div class="form-group">
                            <label class="sr-only">من التاريخ</label>
                            <div  class="input-group date form_datetime col-md-5" data-date="" data-date-format="yyyy-mm-dd  h:i:s" data-link-field="dtp_input1">
                                <input class="form-control search_bill" size="16" type="text" value="{$startDateTime}" name="from" id="from" readonly="">
                                <span class="input-group-addon " style="width: 0%;"><span class=" glyphicon glyphicon-remove col-lg-4"></span></span>
                                <span class="input-group-addon"  style="width: 0%;"><span class="glyphicon glyphicon-th col-lg-4"></span></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="sr-only">إلى التاريخ</label>
                            <div  class="input-group date form_datetime col-md-5" data-date="" data-date-format="yyyy-mm-dd  h:i:s" data-link-field="dtp_input1">
                                <input class="form-control search_bill" size="16" type="text" value="{$endDateTime}" name="to" id="to" readonly="" >
                                <span class="input-group-addon " style="width: 0%;"><span class=" glyphicon glyphicon-remove col-lg-4"></span></span>
                                <span class="input-group-addon" style="width: 0%;"><span class="glyphicon glyphicon-th col-lg-4"></span></span>
                            </div>
                        </div>
                    </div>

                    <div id="dateOnlyDiv">
                        <div class="form-group">
                            <label class="sr-only">من التاريخ</label>
                            <input type="text" class="form-control awdatepicker search_bill" autocomplete="off"   data-date-format="yyyy-mm-dd" name="from" id="from" value="{$startDate}">
                        </div>
                        <div class="form-group">
                            <label class="sr-only">إلى التاريخ</label>
                            <input type="text" class="form-control awdatepicker search_bill" autocomplete="off"   data-date-format="yyyy-mm-dd" name="to" id="to" value="{$endDate}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="sr-only">بحث بـ</label>
                        <div  class="input-group">
                            <label>  <input value="dateOnly" name="search" id="searchdateOnly" type="radio" checked onclick='localStorage.setItem("search", "dateOnly");
                                    window.location.reload();'>
                                تاريخ</label>
                            <label>
                                <input value="dateTime" name="search" id="searchdateTime" type="radio" onclick='localStorage.setItem("search", "dateTime");
                                        window.location.reload();'>
                                تاريخ ووقت</label>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <!--<button type="submit" class="btn btn-primary">بحث</button>-->
                </form>
                <input type="hidden" id="unReviewBillsPrivilage" value="{$Programsettingdata->unReviewBills}"/>

                <div class="row">
                    <div style="margin: 0px 37%">
                        <button type="button" class="btn btn-primary" id="refreshResultsBtn">تحديث النتائج</button>
                        <button type="button" id="reviewBillsBtn" class="btn btn-info execute" data-review="0" data-class-sell="choosedItemSellNotReviewd" data-class-ret="choosedItemRetNotReviewd" style="margin: 0px 3px;">مراجعة</button>
                        <button type="button" id="cancelReviewBillsBtn" class="btn btn-info execute" data-review="1" data-class-sell="choosedItemSellReviewd" data-class-ret="choosedItemRetReviewd" style="margin: 0px 3px;">الغاء المراجعة</button>
                    </div>

                </div>

                <br/>

                <div class="row">
                    <div class="col-lg-6">
                        <div class="panel panel-default panel-m">
                            <!-- Default panel contents -->
                            <div class="panel-heading">مبيعات</div>
                            <div class="panel-body">


                                <!-- ================================================   -->
                                <!-- Nav tabs -->
                                <ul class="nav nav-tabs sell_tabs">
                                    {if 1|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#notReviewedSell" data-toggle="tab">جديد نقدى</a></li>{/if}
                                    <!-- {if 2|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#notReviewedSellClients" data-toggle="tab">جديد عملاء</a></li>{/if} -->
                                    {if 2|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#notReviewedSellClientsCash" data-toggle="tab">عملاء كاش</a></li>{/if}
                                    {if 2|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#notReviewedSellClientsBook" data-toggle="tab">عملاء حجز</a></li>{/if}
                                    {if 3|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#reviwedSell" data-toggle="tab">تمت مراجعتها</a></li>{/if}
                                    {if 4|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#notReviewedPendingSell" data-toggle="tab">معلقة</a></li>{/if}
                                    {if 5|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#reviwedArchivedSell" data-toggle="tab">ارشيف</a></li>{/if}
                                </ul>
                                <!-- =================================================   -->
                                <!-- Tab panes -->
                                <div class="tab-content sell_tabs_content">
                                    {if 1|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="notReviewedSell">


                                        <table class="table table-black" id="billTablesellNotReviewed">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th class="hidden-print">مراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">
                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalsellNotReviewed">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    {/if}
                                    {if 2|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="notReviewedSellClientsCash">
                                        <table class="table table-black" id="billTablesellNotReviewedClientsCash">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th class="hidden-print">مراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">
                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalsellNotReviewedClientsCash">0</span></h4>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="tab-pane" id="notReviewedSellClientsBook">
                                        <table class="table table-black" id="billTablesellNotReviewedClientsBook">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th class="hidden-print">مراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">
                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalsellNotReviewedClientsBook">0</span></h4>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    {/if}
                                    {if 3|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="reviwedSell" style="overflow-x: scroll">


                                        <table class="table table-black" id="billTablesellReviewed">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th>تاريخ المراجعة</th>
                                                    <th>المراجع</th>
                                                    <th class="hidden-print">الغاء المراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">
                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalsellReviewed">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    {/if}
                                    {if 4|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="notReviewedPendingSell">


                                        <table class="table table-black" id="billTablesellNotReviewedPending">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th class="hidden-print">مراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">
                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalsellNotReviewedPending">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    {/if}
                                    {if 5|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="reviwedArchivedSell" style="overflow-x: scroll">


                                        <table class="table table-black" id="billTablesellReviewedArchived">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th>تاريخ المراجعة</th>
                                                    <th>المراجع</th>
                                                    <th class="hidden-print">الغاء المراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">
                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalsellReviewedArchived">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    {/if}
                                </div>
                                <!-- =================================================   -->


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


                    <div class="col-lg-6">
                        <div class="panel panel-default panel-m">
                            <!-- Default panel contents -->
                            <div class="panel-heading">مرتجعات</div>
                            <div class="panel-body">


                                <!-- ================================================   -->
                                <!-- Nav tabs -->
                                <ul class="nav nav-tabs ret_sell_tabs">
                                    {if 1|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#notReviewedRet" data-toggle="tab">جديد نقدى</a></li>{/if}
                                    {if 2|in_array:$usergroup->reviewBillsAllowedTables}
                                    <li class="contolTabs"><a href="#notReviewedRetClientsCash" data-toggle="tab">عملاء كاش</a></li>
                                    <li class="contolTabs"><a href="#notReviewedRetClientsBook" data-toggle="tab">عملاء حجز</a></li>
                                    {/if}
                                    {if 3|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#reviwedRet" data-toggle="tab">تمت مراجعتها</a></li>{/if}
                                    {if 4|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#notReviewedPendingRet" data-toggle="tab">معلقة</a></li>{/if}
                                    {if 5|in_array:$usergroup->reviewBillsAllowedTables}<li class="contolTabs"><a href="#reviwedArchivedaRet" data-toggle="tab">ارشيف</a></li>{/if}
                                </ul>
                                <!-- =================================================   -->
                                <!-- Tab panes -->
                                <div class="tab-content ret_sell_tabs_content">
                                    {if 1|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="notReviewedRet">

                                        <table class="table table-black" id="billTableretSellNotReviewed">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th class="hidden-print">مراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">

                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalretSellNotReviewed">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    {/if}
                                    {if 2|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="notReviewedRetClientsCash">

                                        <table class="table table-black" id="billTableretSellNotReviewedClientsCash">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th class="hidden-print">مراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">

                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalretSellNotReviewedClientsCash">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    <div class="tab-pane" id="notReviewedRetClientsBook">

                                        <table class="table table-black" id="billTableretSellNotReviewedClientsBook">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th class="hidden-print">مراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">

                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalretSellNotReviewedClientsBook">0</span></h4>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    {/if}
                                    {if 3|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="reviwedRet" style="overflow-x: scroll">

                                        <table class="table table-black" id="billTableretSellReviewed">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th>تاريخ المراجعة</th>
                                                    <th>المراجع</th>
                                                    <th class="hidden-print">الغاء المراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">

                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalretSellReviewed">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    {/if}
                                    {if 4|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="notReviewedPendingRet">

                                        <table class="table table-black" id="billTableretSellNotReviewedPending">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th class="hidden-print">مراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">

                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalretSellNotReviewedPending">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    {/if}
                                    {if 5|in_array:$usergroup->reviewBillsAllowedTables}
                                    <div class="tab-pane" id="reviwedArchivedaRet" style="overflow-x: scroll">

                                        <table class="table table-black" id="billTableretSellReviewedArchived">
                                            <thead>
                                                <tr>
                                                    <!--<th>م</th>-->
                                                    <th>رقم الفاتورة</th>
                                                    <th>العميل</th>
                                                    <th>اجمالى الفاتورة</th>
                                                    <th>المدفوع</th>
                                                    <th>تاريخ الفاتورة</th>
                                                    <th>اسم المستخدم</th>
                                                    <th>تاريخ المراجعة</th>
                                                    <th>المراجع</th>
                                                    <th class="hidden-print">الغاء المراجعة</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            </tbody>
                                        </table>
                                        <br/>
                                        <div class="row">

                                            <div class="col-lg-offset-6 col-lg-6 ">
                                                <div class="well well-sm">
                                                    <h4 class="text-center">إجمالي الفواتير  <span id="totalretSellReviewedArchived">0</span></h4>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                    {/if}
                                </div>
                                <!-- =================================================   -->


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


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


<!------------------------Client Model----------------------------->
<!-- Modal -->
<div class="modal fade" id="reviewModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content bg-modal">
            <div class="modal-header">
                <button type="button" class="close pull-left savemodel2 caneclReviewModalButton" data-dismiss="modal" aria-hidden="true" data-execbtn="">&times;</button>
                <h4 class="modal-title" id="reviewTitle"></h4>
            </div>
            <div class="modal-body" style="padding-bottom: 0">
                <form id="clientInfo" action="#" method="post" class="form-horizontal" autocomplete="off">


                    <div class="row" id="sellDiv">
                        <div class="row">
                            <div class="col-lg-6">
                                <h4>المبيعات</h4>
                            </div>
                        </div>
                        <!-- end of title row-->
                        <div class="table-responsive">
                            <table class="table billtable table-bordered table-black">
                                <thead>
                                    <tr>
                                        <th class="wdt60 myblack"> رقم الفاتورة</th>
                                        <th class="wdt60 myblack">العميل </th>
                                        <th class="wdt60 myblack">الاجمالى </th>
                                    </tr>
                                </thead>
                                <tbody id="sellTbody">

                                </tbody>
                            </table>
                        </div>
                        <button type="button" class="btn btn-primary pull-left ft-nor"> اجمالى المبيعات <span class="badge wht-clo">
                                <div id="sellTotal">25</div>
                            </span> </button>
                    </div>
                    <div class="row" id="retDiv">
                        <div class="row">
                            <div class="col-lg-6">
                                <h4>المردودات</h4>
                            </div>
                        </div>
                        <!-- end of title row-->
                        <div class="table-responsive">
                            <table class="table billtable table-bordered table-black">
                                <thead>
                                    <tr>
                                        <th class="wdt60 myblack"> رقم الفاتورة</th>
                                        <th class="wdt60 myblack">العميل </th>
                                        <th class="wdt60 myblack">الاجمالى </th>
                                    </tr>
                                </thead>
                                <tbody id="retTbody">

                                </tbody>
                            </table>
                        </div>
                        <button type="button" class="btn btn-primary pull-left ft-nor"> اجمالى المردودات <span class="badge wht-clo">
                                <div id="retTotal">25</div>
                            </span> </button>
                    </div>
                    <div class="row" style="margin-top:15px;" id="commentDiv">
                        <label class="col-lg-1 control-label">تعليق</label>
                        <div class="col-lg-11">
                            <textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
                        </div>
                    </div>

                    <br/>
                    <div class="row" id="netDiv" style="padding-left: 0;">
                        <div class="col-lg-offset-6 col-lg-6 ">
                            <div class="well well-sm">
                                <h4 class="text-center">الصافى  <span id="netTotal">0</span></h4>
                            </div>
                        </div>
                    </div>
                    <!-- =================================================   -->
                    <input type="hidden" id="currentReviewHidden" value=""/>
                </form>
            </div>
            <div class="modal-footer" id="unReviewBills_div">
                <button type="button" class="btn btn-default caneclReviewModalButton" data-dismiss="modal" data-execbtn="">الغاء</button>
                <button type="button" class="btn btn-primary confirmReview" id="confirmReviewNoPrint" data-print="0" data-payDebt="0" data-review="" style="margin-left: 0px;"></button>
                <button type="button" class="btn btn-primary confirmReview" id="confirmReviewPrint" data-print="1" data-payDebt="0" data-review="" style="margin-left: 0px;"></button>
                <button type="button" class="btn btn-primary payBefore_confirmReview" id="confirmReviewPrintPayDept" data-class-sell="choosedItemSellNotReviewd" data-class-ret="choosedItemRetReviewd" data-print="1" data-payDebt="1" data-review="" style="margin-left: 0px;"></button>
                <div style="width: 35%;display: inline;">
                    <input type="password" id="unReviewBillsPassCheck" style="display:none;" placeholder="باسورد الغاء مراجعة الفواتير" autocomplete="cc-unReviewBillsPassCheck" />
                </div>
            </div>
            <div class="modal-footer" id="unReviewBills_notAllowed_div" style="display:none">
                <span class="note note-warning"> عفوا ليس لديك الصلاحية لالغاء المراجعة</span>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<!------------------------Client Model----------------------------->
<!-- Modal -->
<div class="modal fade" id="payDebtModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content bg-modal">
            <div class="modal-header">
                <button type="button" class="close pull-left" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">تحصيل من عميل</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 0">
                <form id="clientInfo" action="#" method="post" class="form-horizontal" autocomplete="off">
                    <div id="forOneClient">
                        <div class="form-group">
                            <input type="hidden" id="oneClientId" name="oneClientId" value=""/>
                            <label class="col-lg-2 control-label">العميل</label>
                            <div class="col-lg-4">
                                <input class="form-control" id="cl_name" name="cl_name" value="" type="text" readonly/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الدين</label>
                            <div class="col-lg-4">
                                <input class="form-control" placeholder="المديونية" id="dept" name="dept" value="" type="text" readonly/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الخزنة</label>
                            <div class="col-lg-4">
                                <select class="form-control" name="paysaveid" id="paysaveid">
                                    {foreach $saves as $data}
                                    <option value="{$data->saveid}" {if $data->saveid == $user->saveid}selected{/if}>{$data->savename}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">المدفوع كاش</label>
                            <div class="col-lg-4">
                                <input class="form-control positivefloat" placeholder="كاش" id="payed" name="payed" value="" type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">حساب الدفع الالكتروني</label>
                            <div class="col-lg-4">
                                <select class="form-control" name="payaccountid" id="payaccountid">
                                    {foreach $visaAccounts as $data}
                                    <option value="{$data.accountid}">{$data.accountname}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">دفع الكتروني</label>
                            <div class="col-lg-4">
                                <input class="form-control positivefloat" placeholder="دفع الكتروني" id="visapayed" name="visapayed" value="" type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">المتبقى</label>
                            <div class="col-lg-4">
                                <input class="form-control positivefloat" id="remain" name="remain" value="" type="text" disabled/>
                            </div>
                        </div>
                    </div>
                    <div id="forMultiClient">
                        <span class="note note-warning">عفوا لقد اخترت فواتير لاكثر من عميل</span>
                    </div>

                    <!-- =================================================   -->
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">الغاء</button>
                <button type="button" class="btn btn-primary confirmReview" id="confirmReviewPrintPayDept_modal2" data-print="1" data-payDebt="1" data-review="" style="margin-left: 0px;">تنفيذ</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<!------------------------Client Model----------------------------->
<!-- Modal -->
<div class="modal fade" id="reviewHistoryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content bg-modal">
            <div class="modal-header">
                <button type="button" class="close pull-left" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="reviewHistoryTitle">التفاصيل</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 0">
                <form id="reviewHistoryInfo" action="#" method="post" class="form-horizontal" autocomplete="off">

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">غلق</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->


{literal}
<script>

    $('#payed').on('keyup', function () {
        var payed = Number($('#payed').val());
        var visapayed = Number($('#visapayed').val());
        var dept = Number($('#dept').val());
        var remain = dept - (payed + visapayed);
        $('#remain').val(remain);
    });
    $('#visapayed').on('keyup', function () {
        var payed = Number($('#payed').val());
        var visapayed = Number($('#visapayed').val());
        var dept = Number($('#dept').val());
        var remain = dept - (payed + visapayed);
        $('#remain').val(remain);
    });
    $(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()});
    });
    $(function () {
//        //select first tab as active tab
//        $('.sell_tabs li:first').addClass('active');
//        $('.sell_tabs_content div:first').addClass('active');
//        $('.ret_sell_tabs li:first').addClass('active');
//        $('.ret_sell_tabs_content div:first').addClass('active');


        //#####
        var otablesellnotreviewed;
        var otablesellnotreviewedClientsCash;
        var otablesellnotreviewedClientsBook;
        var otablesellreviewed;
        var otablesellnotreviewedPending;
        var otablesellreviewedArchived;
        function draw_billTablesellNotReviewed() {
            if ($('#billTablesellNotReviewed').length > 0) {
                var tablesellnotreviewed = $('#billTablesellNotReviewed');
                if ($.fn.dataTable.isDataTable('#billTablesellNotReviewed')) {
                    otablesellnotreviewed.ajax.reload();
                } else {
                    otablesellnotreviewed = tablesellnotreviewed.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxsell', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 0;
                                },
                                "cashOnlyNotClient": function () {
                                    return 1;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "today";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                //                    "pricetype": function () {
                                //                        return $('#pricetype').val()
                                //                    },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [//            {// set default column settings //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [lstone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [belastone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false, //                "targets": [thrdone],
                            //                "className": 'hide-print'
                            //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });
                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otablesellnotreviewed.on('draw', function (e, ajaxdata) {
                        //var sum = otablesell.column(3).data().sum();
                        $('#totalsellNotReviewed').html(ajaxdata.json.totals.totalBills);
                    });
                }

            }
        }
        function draw_billTablesellNotReviewedClientsCash() {
            if ($('#billTablesellNotReviewedClientsCash').length > 0) {
                var tablesellnotreviewedClientsCash = $('#billTablesellNotReviewedClientsCash');
                if ($.fn.dataTable.isDataTable('#billTablesellNotReviewedClientsCash')) {
                    otablesellnotreviewedClientsCash.ajax.reload();
                } else {
                    otablesellnotreviewedClientsCash = tablesellnotreviewedClientsCash.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxsellCash', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 0;
                                },
                                "cashOnlyNotClient": function () {
                                    return 0;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "today";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                //                    "pricetype": function () {
                                //                        return $('#pricetype').val()
                                //                    },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [
                            {
                                "targets": [3],
                                //"searchable": false,
                                //className: "never"//hide
                            },
                                    ////            {// set default column settings //                "orderable": false,
                                    //                "searchable": false,
                                    //                "targets": [lstone],
                                    //                "className": 'hide-print'
                                    //            },
                                    //            {// set default column settings
                                    //                "orderable": false,
                                    //                "searchable": false,
                                    //                "targets": [belastone],
                                    //                "className": 'hide-print'
                                    //            },
                                    //            {// set default column settings
                                    //                "orderable": false,
                                    //                "searchable": false, //                "targets": [thrdone],
                                    //                "className": 'hide-print'
                                    //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otablesellnotreviewedClientsCash.on('draw', function (e, ajaxdata) {
                        //var sum = otablesell.column(3).data().sum();
                        $('#totalsellNotReviewedClientsCash').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }
        function draw_billTablesellNotReviewedClientsBook() {
            if ($('#billTablesellNotReviewedClientsBook').length > 0) {
                var tablesellnotreviewedClientsBook = $('#billTablesellNotReviewedClientsBook');
                if ($.fn.dataTable.isDataTable('#billTablesellNotReviewedClientsBook')) {
                    otablesellnotreviewedClientsBook.ajax.reload();
                } else {
                    otablesellnotreviewedClientsBook = tablesellnotreviewedClientsBook.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxsellBook', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 0;
                                },
                                "cashOnlyNotClient": function () {
                                    return 0;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "today";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                //                    "pricetype": function () {
                                //                        return $('#pricetype').val()
                                //                    },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [
                            {
                                "targets": [3],
                                //"searchable": false,
                                //className: "never"//hide
                            },
                                    ////            {// set default column settings //                "orderable": false,
                                    //                "searchable": false,
                                    //                "targets": [lstone],
                                    //                "className": 'hide-print'
                                    //            },
                                    //            {// set default column settings
                                    //                "orderable": false,
                                    //                "searchable": false,
                                    //                "targets": [belastone],
                                    //                "className": 'hide-print'
                                    //            },
                                    //            {// set default column settings
                                    //                "orderable": false,
                                    //                "searchable": false, //                "targets": [thrdone],
                                    //                "className": 'hide-print'
                                    //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otablesellnotreviewedClientsBook.on('draw', function (e, ajaxdata) {
                        //var sum = otablesell.column(3).data().sum();
                        $('#totalsellNotReviewedClientsBook').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }

        function draw_billTablesellReviewed() {
            if ($('#billTablesellReviewed').length > 0) {
                var tablesellreviewed = $('#billTablesellReviewed');
                if ($.fn.dataTable.isDataTable('#billTablesellReviewed')) {
                    otablesellreviewed.ajax.reload();
                } else {
                    otablesellreviewed = tablesellreviewed.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxsell', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 1;
                                },
                                "cashOnlyNotClient": function () {
                                    return -1;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "today";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                //                    "pricetype": function () {
                                //                        return $('#pricetype').val()
                                //                    },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [//            {// set default column settings //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [lstone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [belastone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false, //                "targets": [thrdone],
                            //                "className": 'hide-print'
                            //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otablesellreviewed.on('draw', function (e, ajaxdata) {
                        //var sum = otablesell.column(3).data().sum();
                        $('#totalsellReviewed').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }
        function draw_billTablesellNotReviewedPending() {
            if ($('#billTablesellNotReviewedPending').length > 0) {
                var tablesellnotreviewedPending = $('#billTablesellNotReviewedPending');
                if ($.fn.dataTable.isDataTable('#billTablesellNotReviewedPending')) {
                    otablesellnotreviewedPending.ajax.reload();
                } else {
                    otablesellnotreviewedPending = tablesellnotreviewedPending.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxsell', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 0;
                                },
                                "cashOnlyNotClient": function () {
                                    return -1;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "beforeToday";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                //                    "pricetype": function () {
                                //                        return $('#pricetype').val()
                                //                    },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [//            {// set default column settings //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [lstone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [belastone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false, //                "targets": [thrdone],
                            //                "className": 'hide-print'
                            //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otablesellnotreviewedPending.on('draw', function (e, ajaxdata) {
                        //var sum = otablesell.column(3).data().sum();
                        $('#totalsellNotReviewedPending').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }
        function draw_billTablesellReviewedArchived() {
            if ($('#billTablesellReviewedArchived').length > 0) {
                var tablesellreviewedArchived = $('#billTablesellReviewedArchived');
                if ($.fn.dataTable.isDataTable('#billTablesellReviewedArchived')) {
                    otablesellreviewedArchived.ajax.reload();
                } else {
                    otablesellreviewedArchived = tablesellreviewedArchived.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxsell', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 1;
                                },
                                "cashOnlyNotClient": function () {
                                    return -1;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "beforeToday";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                //                    "pricetype": function () {
                                //                        return $('#pricetype').val()
                                //                    },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [//            {// set default column settings //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [lstone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [belastone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false, //                "targets": [thrdone],
                            //                "className": 'hide-print'
                            //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otablesellreviewedArchived.on('draw', function (e, ajaxdata) {
                        //var sum = otablesell.column(3).data().sum();
                        $('#totalsellReviewedArchived').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }


        //#####
        var otableretSellnotreviewed;
        var otableretSellnotreviewedClientsCash;
        var otableretSellnotreviewedClientsBook;
        var otableretSellreviewed;
        var otableretSellnotreviewedPending;
        var otableretSellreviewedArchived;
        function draw_billTableretSellNotReviewed() {
            if ($('#billTableretSellNotReviewed').length > 0) {
                var tableretSellnotreviewed = $('#billTableretSellNotReviewed');
                if ($.fn.dataTable.isDataTable('#billTableretSellNotReviewed')) {
                    otableretSellnotreviewed.ajax.reload();
                } else {
                    otableretSellnotreviewed = tableretSellnotreviewed.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxret', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 0;
                                },
                                "cashOnlyNotClient": function () {
                                    return 1;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "today";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                "pricetype": function () {
                                    return $('#pricetype').val()
                                },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            //console.log(aData[0]);
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [//            {// set default column settings //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [lstone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [belastone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false, //                "targets": [thrdone],
                            //                "className": 'hide-print'
                            //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otableretSellnotreviewed.on('draw', function (e, ajaxdata) {
                        //var sum = otableretSellnotreviewed.column(2).data().sum();
                        $('#totalretSellNotReviewed').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }
        function draw_billTableretSellNotReviewedClientsCash() {
            if ($('#billTableretSellNotReviewedClientsCash').length > 0) {
                var tableretSellnotreviewedClientsCash = $('#billTableretSellNotReviewedClientsCash');
                if ($.fn.dataTable.isDataTable('#billTableretSellNotReviewedClientsCash')) {
                    otableretSellnotreviewedClientsCash.ajax.reload();
                } else {
                    otableretSellnotreviewedClientsCash = tableretSellnotreviewedClientsCash.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxretCash', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 0;
                                },
                                "cashOnlyNotClient": function () {
                                    return 0;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "today";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                "pricetype": function () {
                                    return $('#pricetype').val()
                                },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            //console.log(aData[0]);
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [
                            {
                                "targets": [3],
                                //"searchable": false,
                                //className: "never"//hide
                            },
                                    //            {// set default column settings //                "orderable": false,
                                    //                "searchable": false,
                                    //                "targets": [lstone],
                                    //                "className": 'hide-print'
                                    //            },
                                    //            {// set default column settings
                                    //                "orderable": false,
                                    //                "searchable": false,
                                    //                "targets": [belastone],
                                    //                "className": 'hide-print'
                                    //            },
                                    //            {// set default column settings
                                    //                "orderable": false,
                                    //                "searchable": false, //                "targets": [thrdone],
                                    //                "className": 'hide-print'
                                    //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otableretSellnotreviewedClientsCash.on('draw', function (e, ajaxdata) {
                        //var sum = otableretSellnotreviewed.column(2).data().sum();
                        $('#totalretSellNotReviewedClientsCash').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }
        function draw_billTableretSellNotReviewedClientsBook() {
            if ($('#billTableretSellNotReviewedClientsBook').length > 0) {
                var tableretSellnotreviewedClientsBook = $('#billTableretSellNotReviewedClientsBook');
                if ($.fn.dataTable.isDataTable('#billTableretSellNotReviewedClientsBook')) {
                    otableretSellnotreviewedClientsBook.ajax.reload();
                } else {
                    otableretSellnotreviewedClientsBook = tableretSellnotreviewedClientsBook.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxretBook', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 0;
                                },
                                "cashOnlyNotClient": function () {
                                    return 0;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "today";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                "pricetype": function () {
                                    return $('#pricetype').val()
                                },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            //console.log(aData[0]);
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [
                            {
                                "targets": [3],
                                //"searchable": false,
                                //className: "never"//hide
                            },
                                    //            {// set default column settings //                "orderable": false,
                                    //                "searchable": false,
                                    //                "targets": [lstone],
                                    //                "className": 'hide-print'
                                    //            },
                                    //            {// set default column settings
                                    //                "orderable": false,
                                    //                "searchable": false,
                                    //                "targets": [belastone],
                                    //                "className": 'hide-print'
                                    //            },
                                    //            {// set default column settings
                                    //                "orderable": false,
                                    //                "searchable": false, //                "targets": [thrdone],
                                    //                "className": 'hide-print'
                                    //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otableretSellnotreviewedClientsBook.on('draw', function (e, ajaxdata) {
                        //var sum = otableretSellnotreviewed.column(2).data().sum();
                        $('#totalretSellNotReviewedClientsBook').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }

        function draw_billTableretSellReviewed() {
            if ($('#billTableretSellReviewed').length > 0) {
                var tableretSellreviewed = $('#billTableretSellReviewed');
                if ($.fn.dataTable.isDataTable('#billTableretSellReviewed')) {
                    otableretSellreviewed.ajax.reload();
                } else {
                    otableretSellreviewed = tableretSellreviewed.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxret', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 1;
                                },
                                "cashOnlyNotClient": function () {
                                    return -1;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "today";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                "pricetype": function () {
                                    return $('#pricetype').val()
                                },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            //console.log(aData[0]);
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [//            {// set default column settings //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [lstone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [belastone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false, //                "targets": [thrdone],
                            //                "className": 'hide-print'
                            //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otableretSellreviewed.on('draw', function (e, ajaxdata) {
                        //var sum = otableretSellnotreviewed.column(2).data().sum();
                        $('#totalretSellReviewed').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }
        function draw_billTableretSellNotReviewedPending() {
            if ($('#billTableretSellNotReviewedPending').length > 0) {
                var tableretSellnotreviewedPending = $('#billTableretSellNotReviewedPending');
                if ($.fn.dataTable.isDataTable('#billTableretSellNotReviewedPending')) {
                    otableretSellnotreviewedPending.ajax.reload();
                } else {
                    otableretSellnotreviewedPending = tableretSellnotreviewedPending.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxret', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 0;
                                },
                                "cashOnlyNotClient": function () {
                                    return -1;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "beforeToday";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                "pricetype": function () {
                                    return $('#pricetype').val()
                                },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            //console.log(aData[0]);
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [//            {// set default column settings //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [lstone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [belastone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false, //                "targets": [thrdone],
                            //                "className": 'hide-print'
                            //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otableretSellnotreviewedPending.on('draw', function (e, ajaxdata) {
                        //var sum = otableretSellnotreviewed.column(2).data().sum();
                        $('#totalretSellNotReviewedPending').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }
        function draw_billTableretSellReviewedArchived() {
            if ($('#billTableretSellReviewedArchived').length > 0) {
                var tableretSellreviewedArchived = $('#billTableretSellReviewedArchived');
                if ($.fn.dataTable.isDataTable('#billTableretSellReviewedArchived')) {
                    otableretSellreviewedArchived.ajax.reload();
                } else {
                    otableretSellreviewedArchived = tableretSellreviewedArchived.DataTable({
                        "processing": true,
                        "stateSave": true,
                        "serverSide": true,
                        "ajax": {url: 'salesreportbills.php?do=showallajaxret', type: 'POST',
                            "data": {
                                "reviewType": function () {
                                    return 1;
                                },
                                "cashOnlyNotClient": function () {
                                    return -1;
                                },
                                "from": function () {
                                    return $('#from').val()
                                },
                                "to": function () {
                                    return $('#to').val()
                                },
                                "tabDateGuide": function () {
                                    return "beforeToday";
                                },
                                "sellbillserial": function () {
                                    return $('#sellbillserial').val()
                                },
                                "sellbillid": function () {
                                    return $('#sellbillid').val()
                                },
                                "clientid": function () {
                                    return $('#clientid').val()
                                },
                                "typeClient": function () {
                                    return $('#typeClient').val()
                                },
                                "sellerid": function () {
                                    return $('#sellerid').val()
                                },
                                "selleruserid": function () {
                                    return $('#selleruserid').val()
                                },
                                "storeid": function () {
                                    return $('#storeid').val()
                                },
                                "saveid": function () {
                                    return $('#saveid').val()
                                },
                                "tempclientName": function () {
                                    return $('#tempclientName').val()
                                },
                                "pricetype": function () {
                                    return $('#pricetype').val()
                                },
                                "searchDate": function () {
                                    return localStorage.getItem("search")
                                },
                                // etc..
                            }}, //  server side processing
                        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                            //console.log(aData[0]);
                            if (aData[0].includes("danger")) {//not deleted
                                $('td', nRow).css('background-color', '#F2DEDE');
                            } else if (aData[0].includes("dark")) {
                                $('td', nRow).css('background-color', '#9E9E9E');
                            } else {
                                //$('td', nRow).css('background-color', 'white');
                            }
                        },
                        dom: 'Bfrtip',
                        buttons: [//'csv', 'pdf'
                            {
                                extend: "print",
                                className: "btn dark btn-outline",
                                text: "طباعه<i class='fa fa-print'></i>",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                },
                                customize: function (win) {
                                    $(win.document.body).find('table')
                                            //.addClass('compact')
                                            .css('direction', 'rtl');
                                }
                            }, {
                                extend: "copy",
                                className: "btn red btn-outline",
                                text: "نسخ",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "excel",
                                className: "btn yellow btn-outline ",
                                text: "اكسل",
                                exportOptions: {
                                    //columns: '.show-print'
                                    columns: ':visible'
                                }
                            }, {
                                extend: "colvis",
                                className: "btn dark btn-outline",
                                text: "المكونات"
                            }
                        ], "bStateSave": true,
                        "language": {
                            "aria": {
                                "sortAscending": ": Used to order Ascending",
                                "sortDescending": ": Used to order Descending"
                            },
                            "emptyTable": "لا يوجد بيانات",
                            "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                            "infoEmpty": "لا يوجد بيانات",
                            "infoFiltered": "", //"(تنقيه  من عدد فواتير كلى _MAX_)",
                            "lengthMenu": " _MENU_ عنصر",
                            "search": "البحث:",
                            "zeroRecords": "لا يوجد بيانات تشابه البحث"
                        },
                        responsive: !0,
                        "columnDefs": [//            {// set default column settings //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [lstone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false,
                            //                "targets": [belastone],
                            //                "className": 'hide-print'
                            //            },
                            //            {// set default column settings
                            //                "orderable": false,
                            //                "searchable": false, //                "targets": [thrdone],
                            //                "className": 'hide-print'
                            //            },
//                {targets: '_all', "className": 'show-print'}
                        ],
                        order: [
                            [0, "asc"]
                        ],
                        paging: true,
                        lengthMenu: [
                            [5, 10, 15, 20, 50, -1],
                            [5, 10, 15, 20, 50, "All"]
                        ],
                        pageLength: 10,
                        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
                    });

                    //when draw is comlete cal total of column using datatable api sum func //we may need settimeout
                    otableretSellreviewedArchived.on('draw', function (e, ajaxdata) {
                        //var sum = otableretSellnotreviewed.column(2).data().sum();
                        $('#totalretSellReviewedArchived').html(ajaxdata.json.totals.totalBills);
                    });
                }
            }
        }



        //select first tab as active tab
        $('[href="#notReviewedSell"]').first().parent('li').addClass('active');
        $('#notReviewedSell').addClass('active');//.sell_tabs_content
        draw_billTablesellNotReviewed();
        $('[href="#notReviewedRet"]').first().parent('li').addClass('active');
        $('#notReviewedRet').addClass('active');//.ret_sell_tabs_content
        draw_billTableretSellNotReviewed();

        $('body').on('click', '.contolTabs', function () {
            var href = $(this).children('a')[0].getAttribute('href');
            switch (href) {
                case "#notReviewedSell":
                    draw_billTablesellNotReviewed();
                    break;
                case "#notReviewedSellClientsCash":
                    draw_billTablesellNotReviewedClientsCash();
                    break;
                case "#notReviewedSellClientsBook":
                    draw_billTablesellNotReviewedClientsBook();
                    break;
                case "#reviwedSell":
                    draw_billTablesellReviewed();
                    break;
                case "#notReviewedPendingSell":
                    draw_billTablesellNotReviewedPending();
                    break;
                case "#reviwedArchivedSell":
                    draw_billTablesellReviewedArchived();
                    break;


                    //######

                case "#notReviewedRet":
                    draw_billTableretSellNotReviewed();
                    break;
                case "#notReviewedRetClientsCash":
                    draw_billTableretSellNotReviewedClientsCash();
                    break;
                case "#notReviewedRetClientsBook":
                    draw_billTableretSellNotReviewedClientsBook();
                    break;
                case "#reviwedRet":
                    draw_billTableretSellReviewed();
                    break;
                case "#notReviewedPendingRet":
                    draw_billTableretSellNotReviewedPending();
                    break;
                case "#reviwedArchivedaRet":
                    draw_billTableretSellReviewedArchived();
                    break;
            }
        })



        $('body').on('change', '.search_bill', function (e, checkToUnlockButtons) {
            var flagArr = new Array();
            for (var i = 1; i <= 10; i++) {
                flagArr[i] = 0;
            }
            if ($('#billTablesellNotReviewed').length > 0 && $('#billTablesellNotReviewed').is(':visible')) {
                otablesellnotreviewed.ajax.reload(function () {
                    flagArr[1] = 1;
                });
            } else {
                flagArr[1] = 1;
            }
            if ($('#billTablesellNotReviewedClientsCash').length > 0 && $('#billTablesellNotReviewedClientsCash').is(':visible')) {
                otablesellnotreviewedClientsCash.ajax.reload(function () {
                    flagArr[2] = 1;
                });
            } else {
                flagArr[2] = 1;
            }
            if ($('#billTablesellNotReviewedClientsBook').length > 0 && $('#billTablesellNotReviewedClientsBook').is(':visible')) {
                otablesellnotreviewedClientsBook.ajax.reload(function () {
                    flagArr[2] = 1;
                });
            } else {
                flagArr[2] = 1;
            }
            if ($('#billTablesellReviewed').length > 0 && $('#billTablesellReviewed').is(':visible')) {
                otablesellreviewed.ajax.reload(function () {
                    flagArr[3] = 1;
                });
            } else {
                flagArr[3] = 1;
            }
            if ($('#billTablesellNotReviewedPending').length > 0 && $('#billTablesellNotReviewedPending').is(':visible')) {
                otablesellnotreviewedPending.ajax.reload(function () {
                    flagArr[4] = 1;
                });
            } else {
                flagArr[4] = 1;
            }
            if ($('#billTablesellReviewedArchived').length > 0 && $('#billTablesellReviewedArchived').is(':visible')) {
                otablesellreviewedArchived.ajax.reload(function () {
                    flagArr[5] = 1;
                });
            } else {
                flagArr[5] = 1;
            }

            //
            if ($('#billTableretSellNotReviewed').length > 0 && $('#billTableretSellNotReviewed').is(':visible')) {
                otableretSellnotreviewed.ajax.reload(function () {
                    flagArr[6] = 1;
                });
            } else {
                flagArr[6] = 1;
            }
            if ($('#billTableretSellNotReviewedClientsCash').length > 0 && $('#billTableretSellNotReviewedClientsCash').is(':visible')) {
                otableretSellnotreviewedClientsCash.ajax.reload(function () {
                    flagArr[7] = 1;
                });
            } else {
                flagArr[7] = 1;
            }
            if ($('#billTableretSellNotReviewedClientsBook').length > 0 && $('#billTableretSellNotReviewedClientsBook').is(':visible')) {
                otableretSellnotreviewedClientsBook.ajax.reload(function () {
                    flagArr[7] = 1;
                });
            } else {
                flagArr[7] = 1;
            }
            if ($('#billTableretSellReviewed').length > 0 && $('#billTableretSellReviewed').is(':visible')) {
                otableretSellreviewed.ajax.reload(function () {
                    flagArr[8] = 1;
                });
            } else {
                flagArr[8] = 1;
            }
            if ($('#billTableretSellNotReviewedPending').length > 0 && $('#billTableretSellNotReviewedPending').is(':visible')) {
                otableretSellnotreviewedPending.ajax.reload(function () {
                    flagArr[9] = 1;
                });
            } else {
                flagArr[9] = 1;
            }
            if ($('#billTableretSellReviewedArchived').length > 0 && $('#billTableretSellReviewedArchived').is(':visible')) {
                otableretSellreviewedArchived.ajax.reload(function () {
                    flagArr[10] = 1;
                });
            } else {
                flagArr[10] = 1;
            }
            //otablesell.draw();//both work fine
            if (checkToUnlockButtons == 1) {
                checkToUnlockButtonsFunc(flagArr);

            }
        });
        function checkToUnlockButtonsFunc(flagArr) {
            var flag = 1;
            for (var i = 1; i <= 10; i++) {
                if (flagArr[i] == 0) {
                    flag = 0;
                }
            }
            if (flag == 1) {//all is ok ubblock buttons
                thisis.removeClass('processing...');
                $('.confirmReview').removeClass('processing...');
            } else {
                console.log('a');
                setTimeout(function () {
                    checkToUnlockButtonsFunc(flagArr);
                }, 500);
            }
        }
        $('body').on('click', '#refreshResultsBtn', function () {
            $('.search_bill:first').trigger('change');
        });

        //when draw is comlete cal total of column using datatable api sum func
        //####
        //        //when draw is comlete cal total of column using datatable api sum func
        //        otablesell.on('draw', function (e, ajaxdata) {
        //            var sum = otablesell.column(3).data().sum();
        //            $("#piecesCount").html(ajaxdata.json.totals.piecesCount);
        //            $("#payedTotal").html(ajaxdata.json.totals.payedTotal);
        //            $("#remainTotal").html(ajaxdata.json.totals.remainTotal);
        //            $("#totalBills").html(ajaxdata.json.totals.totalBills);
        //            $("#totalBills2").html(ajaxdata.json.totals.totalBills);
        //
        //            //$('#total_txt').html("- مجموع " + $("#typeshow option:selected").text() + " <u>المعروضة</u> : ");
        //            //$('#total').html(sum);
        //        });


        var idsSell;
        var idsRet;
        var sellDataArr;
        var retDataArr;
        var thisis;
        $('body').on('click', '.execute', function () {
            thisis = $(this);
            if (!thisis.hasClass('processing...')) {
                thisis.addClass('processing...');
                var classSell = thisis.data('class-sell');
                var classRet = thisis.data('class-ret');
                var review = thisis.data('review');
                $('.caneclReviewModalButton').data('execbtn', thisis.attr('id'))

                idsSell = '';
                var sellTotal = 0;
                sellDataArr = [];
                $('.' + classSell + ':checked').each(function () {
                    idsSell += $(this).val() + ',';
                    sellTotal += Number($(this).data('total'));
                    sellDataArr.push({id: $(this).val(), client: $(this).data('client'), total: $(this).data('total')});
                });
                idsRet = '';
                var retTotal = 0;
                retDataArr = [];
                $('.' + classRet + ':checked').each(function () {
                    idsRet += $(this).val() + ',';
                    retTotal += Number($(this).data('total'));
                    retDataArr.push({id: $(this).val(), client: $(this).data('client'), total: $(this).data('total')});
                });
                if (sellDataArr.length > 0 || retDataArr.length > 0) {
                    if (review == '0') {
                        $('#reviewTitle').html('مراجعة فواتير');
                        $('#confirmReviewNoPrint').html('حفظ');
                        $('#confirmReviewPrint').html('حفظ وطباعة').show();
                        $('#confirmReviewPrintPayDept').html('تحصيل ومراجعه').show();

                        $('#unReviewBillsPassCheck').hide();
                        //
                        $('#unReviewBills_notAllowed_div').hide();
                        $('#unReviewBills_div').show();

                        $('#comment').val("");
                        $('#commentDiv').show();


                        $('#currentReviewHidden').val(0);//represet current review
                    } else if (review == '1') {
                        $('#reviewTitle').html('الغاء مراجعة فواتير');
                        $('#confirmReviewNoPrint').html('تأكيد');
                        $('#confirmReviewPrint').hide();
                        $('#confirmReviewPrintPayDept').hide();

                        $('#unReviewBillsPassCheck').show();
                        //
                        if ($('#unReviewBillsPrivilage').val() == "0") {
                            $('#unReviewBills_notAllowed_div').hide();
                            $('#unReviewBills_div').show();
                        } else {
                            $('#unReviewBills_notAllowed_div').show();
                            $('#unReviewBills_div').hide();
                        }
                        $('#commentDiv').hide();

                        $('#currentReviewHidden').val(1);//represet current review
                    }
                    $('.caneclReviewModalButton').attr('data-execBtn', thisis.attr('id'));

                    $('#sellTotal').html(sellTotal);
                    $('#retTotal').html(retTotal);
                    $('#netTotal').html(sellTotal - retTotal);

                    var html = '';
                    sellDataArr.forEach(function (val) {
                        html += '<tr>' +
                                '    <td class=" myblack">' + val.id + '</td>' +
                                '    <td class=" myblack">' + val.client + '</td>' +
                                '    <td class=" myblack">' + val.total + '</td>' +
                                '</tr>';
                    });
                    $('#sellTbody').html(html);
                    var html = '';
                    retDataArr.forEach(function (val) {
                        html += '<tr>' +
                                '    <td class=" myblack">' + val.id + '</td>' +
                                '    <td class=" myblack">' + val.client + '</td>' +
                                '    <td class=" myblack">' + val.total + '</td>' +
                                '</tr>';
                    });
                    $('#retTbody').html(html);

                    if (sellDataArr.length > 0) {
                        $('#sellDiv').show();
                    } else {
                        $('#sellDiv').hide();
                    }
                    if (retDataArr.length > 0) {
                        $('#retDiv').show();
                    } else {
                        $('#retDiv').hide();
                    }

                    if (sellDataArr.length > 0 && retDataArr.length > 0) {
                        $('#netDiv').show();
                    } else {
                        $('#netDiv').hide();
                    }


                    $('#reviewModal').modal('show');
                } else {
                    thisis.removeClass('processing...');
                }
            }


        });
        $('body').on('click', '.caneclReviewModalButton', function () {
            var execBtnId = $(this).data('execbtn');
            $('#' + execBtnId).removeClass('processing...');
        });
        $('body').on('click', '.confirmReview', function () {
            if (!$('.confirmReview').hasClass('processing...')) {
                $('.confirmReview').addClass('processing...');
                var print = $(this).data('print');
                var review = $('#currentReviewHidden').val();
                var pass = $('#unReviewBillsPassCheck').val();
                var paydebt = $(this).data('paydebt');
                var paysaveid = $('#paysaveid').val();
                var payed = $('#payed').val();
                var payaccountid = $('#payaccountid').val();
                var visapayed = $('#visapayed').val();
                var oneClientId = $('#oneClientId').val();
                var comment = $('#comment').val();
                $.ajax({
                    type: 'POST',
                    url: 'salesreportbills.php?do=reviewUnReview',
                    data: {idsSell: idsSell, idsRet: idsRet, review: review, pass: pass, paydebt: paydebt, payed: payed, oneClientId: oneClientId, comment: comment, visapayed: visapayed, paysaveid: paysaveid, payaccountid: payaccountid},
                    success: function (data) {
                        $('#payDebtModal').modal('hide');
                        $('#payed').val("");
                        $('#visapayed').val("");
                        $('#oneClientId').val(0);
                        //
                        $('#reviewModal').modal('hide');
                        if (Number(data) == -1) {
                            alert('عفوا حدث خطا, حاول مرة اخرى');

                            setTimeout(function () {//this allow html changes to happen "modal hide"
                                thisis.removeClass('processing...');
                                $('.confirmReview').removeClass('processing...');
                            }, 0);
                        } else if (Number(data) == -2) {
                            $('#unReviewBillsPassCheck').val("");
                            alert('الباسورد خطأ');

                            setTimeout(function () {//this allow html changes to happen "modal hide"
                                thisis.removeClass('processing...');
                                $('.confirmReview').removeClass('processing...');
                            }, 0);
                        } else if (Number(data.split(',')[0]) == 1) {

                            if (review == '0' && print == '1') {
                                localStorage.setItem('sellDataArr', JSON.stringify(sellDataArr));
                                localStorage.setItem('retDataArr', JSON.stringify(retDataArr));
                                localStorage.setItem('theComment', comment);
                                if (Number(data.split(',')[1] > 0)) {
                                    window.open('salesreportbills.php?do=print', '_blank');
                                    window.open('salesreportbills.php?do=print&payment=' + Number(data.split(',')[1]), '_blank');
                                } else {
                                    window.open('salesreportbills.php?do=print', '_blank');
                                }
                            }
                            setTimeout(function () {//this allow print page to open first then load tabs
                                $('.search_bill:first').trigger('change', [1]);
                            }, 500);

                            /* ## this part will be  done at this event $('.search_bill:first').trigger('change'); to make sure that data has been reloaded first "no double reviews"
                             setTimeout(function () {//this allow html changes to happen "modal hide"
                             thisis.removeClass('processing...');
                             $('.confirmReview').removeClass('processing...');
                             }, 0);*/

                        }


                    }
                });
            }
        });

        var sameClientIdsChoosenFlag = 1;
        var thisisPayDebt;
        $('body').on('click', '.payBefore_confirmReview', function () {
            thisisPayDebt = $(this);
            if (!thisisPayDebt.hasClass('processing...')) {
                thisisPayDebt.addClass('processing...');

                var classSell = thisisPayDebt.data('class-sell');
                var classRet = thisisPayDebt.data('class-ret');

                sameClientIdsChoosenFlag = 1;//1 means onf client only ,you can pay bebt,0 multi clients you cant pay debt
                var last_cid = 0;
                var last_cname = 0;
                $('.' + classSell + ':checked').each(function () {
                    var cid = Number($(this).data('cid'));
                    last_cname = $(this).data('client');
                    if (sameClientIdsChoosenFlag == 1 && last_cid > 0 && last_cid != cid) {
                        sameClientIdsChoosenFlag = 0;
                    }
                    last_cid = cid;
                });
                $('.' + classRet + ':checked').each(function () {
                    var cid = Number($(this).data('cid'));
                    last_cname = $(this).data('client');
                    if (sameClientIdsChoosenFlag == 1 && last_cid > 0 && last_cid != cid) {
                        sameClientIdsChoosenFlag = 0;
                    }
                    last_cid = cid;
                });

                //
                $("#dept").val("loading...");
                if (sameClientIdsChoosenFlag == 1) {//really one client in all bills choosen to bereviewed
                    $('#confirmReviewPrintPayDept_modal2').show();
                    $('#forOneClient').show();
                    $('#forMultiClient').hide();
                    $('#cl_name').val(last_cname);

                    $.ajax({
                        url: "clientPayedDeptControllerAjax.php?id=" + last_cid,
                        type: "get",
                        async: false,
                        success: function (data) {
                            var response = $.parseJSON(data);
                            $("#dept").val(response.clientdebt);
                            $('#oneClientId').val(last_cid);
                        },
                        error: function () {
                            alert("لقد حدث خطأ أثناء إجراء العملية");
                        }
                    });

                } else {
                    $('#confirmReviewPrintPayDept_modal2').hide();
                    $('#forMultiClient').show();
                    $('#forOneClient').hide();
                }

                $('#payDebtModal').modal('show');
                thisisPayDebt.removeClass('processing...');
            }
        });

        $('body').on('click', '.reviewInfo', function () {
            thisis = $(this);
            if (!thisis.hasClass('processing...')) {
                thisis.addClass('processing...');

                var id = thisis.data('id');
                var type = thisis.data('type');
                $.ajax({
                    url: "salesreportbills.php?do=reviewhistory",
                    type: "post",
                    data: {id: id, type: type},
                    async: false,
                    success: function (data) {
                        thisis.removeClass('processing...');
                        if (type == "sell") {
                            $('#reviewHistoryTitle').html('مراجعات فاتورة بيع رقم ' + id + '');
                        } else if (type == "ret") {
                            $('#reviewHistoryTitle').html('مراجعات فاتورة مردودات رقم ' + id + '');
                        }

                        $('#reviewHistoryInfo').html(data);
                        $('#reviewHistoryModal').modal('show');
                    },
                    error: function () {
                        alert("لقد حدث خطأ أثناء إجراء العملية");
                    }
                });

            }
        });
    });
    //
    var search = localStorage.getItem("search");
    if (search == "dateTime") {
        $('#searchdateTime').attr('checked', 'checked');
        $('#searchdateOnly').removeAttr('checked');
        //
        $('#dateTimeDiv').show();
        $('#dateOnlyDiv').remove();
    } else {
        $('#searchdateOnly').attr('checked', 'checked');
        $('#searchdateTime').removeAttr('checked');
        //
        $('#dateOnlyDiv').show();
        $('#dateTimeDiv').remove();
    }

</script>
{/literal}
