<style>
    .myresult {
        -webkit-print-color-adjust: exact;
    }
    .nodata{
        background-color: #72B4EC;
        color: white;
        border-radius: 13px;
        margin: 14px;
        font-size: 24px;
        text-align: center;
        padding: 5px;
    }
    table.dataTable tfoot th, table.dataTable tfoot td {
        padding: 10px 18px 6px 18px;
        border-top: 1px solid #111;
        text-align: center;
    }
</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[132]->url}" target="_blank" class="hidden-print"><img src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube" style="width: 2%;"></a>
            </div>
            {if $Programsetting->valueadded eq 0}
            <div class="panel-heading">تقرير مبيعات </div>
            {else}
            <div class="panel-heading">تقرير مبيعات    غير شاملة القيمة المضافه</div>
            {/if}
            <div class="panel-body">
                <input type="hidden" id="searchvalue" value="{$Programsetting->searchvalue}">
                <form class="form-inline hidden-print" action="salesreport.php" method="post">
                    <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 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" size="16" type="text" value="" name="datefrom" id="datefrom" 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" size="16" type="text" value="" name="dateto" id="dateto" 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" autocomplete="off"   data-date-format="yyyy-mm-dd" name="datefrom" >
                        </div>
                        <div class="form-group">
                            <label class="sr-only">إلى التاريخ</label>
                            <input type="text" class="form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" name="dateto" >
                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <div class="form-group col-lg-5">
                        <div class="col-md-2">
                            <label class="sr-only">العميل</label>
                        </div>
                        <input type="hidden" name="clientId" id="clientId" class="select2Supp"/>
                    </div>
                    <div class="form-group col-lg-2">
                        <label class="sr-only">نوع الفاتورة</label>
                        <div class="input-group">
                            <label>  <input value="1" name="obgyBillType" id="obgyBillType" type="radio">
                                مباشر</label>
                            <label>
                                <input value="2" name="obgyBillType" id="obgyBillType" type="radio">
                                مستهلك</label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only"> شامل الخدمات</label>
                        </div>
                        <div class="radio-inline">
                            <input value="1" name="servicesAreIncluded"  type="checkbox" checked="checked"  />
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only">نوع العميل</label>
                        </div>
                        <select class="select2 wdt300"  name="typeId" id="typeId" >
                            <option value="-1">اختر نوع العميل</option>
                            <option value="0">كل انواع العملاء</option>
                            {foreach $types as $data}
                            <option value="{$data->typeId}">{$data->typeName}</option>
                            {/foreach}
                        </select>
                    </div>


                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only">المحافظه</label>
                        </div>
                        <select class="select2 wdt300"  name="governmentid" id="governmentid" >
                            <option value="-1">اختر </option>
                            {foreach $allGovernment as $government}
                            <option value="{$government->governmetid}">{$government->governmentname}</option>
                            {/foreach}
                        </select>
                    </div>

                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only">المناطق</label>
                        </div>
                        <input type="hidden" name="clientareaid" id="getclientareaonly" class="getclientareaonly"/>
                    </div>

                    <!--    <div class="form-group">
                          <div class="col-md-4">
                              <label class="sr-only">التعليق</label>
                          </div>
                          <input type="text" name="comment" id="comment" class="form-control"/>
                      </div> -->



                    {if $user->userstoreid == 0}
                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only">المخزن</label>
                        </div>
                        <select class="select2 wdt300"  name="storeId" id="storeId" >
                            <option value="-1">اختر مخزن</option>
                            <option value="0">كل المخازن</option>
                            {foreach $storeData as $store}
                            <option value="{$store->storeId}">{$store->storeName}</option>
                            {/foreach}
                        </select>
                    </div>
                    {/if}
                    {if $user->branchId == 0}
                    <div class="form-group">
                        <div class="col-md-2">

                            <label class="sr-only">الفرع</label>
                        </div>
                        <select class="select2 wdt300"  name="branchId" id="branchId" >
                            <option value="-1">اختر الفرع</option>
                            <option value="0">كل الفروع</option>
                            {foreach $branchData as $branch}
                            <option value="{$branch->branchId}">{$branch->branchName}</option>
                            {/foreach}
                        </select>
                    </div>
                    {/if}
                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only">نوع السعر</label>
                        </div>
                        <select class="select2 wdt300" name="pricetype" id="pricetype">
                            <option value="-1">اختر نوع السعر</option>
                            <option value="0">جملة</option>
                            <option value="1">تجزئة</option>
                            <option value="2">نصف جملة</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <div class="col-md-2">

                            <label class="sr-only">{if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</label>
                        </div>
                        <select class="select2 wdt300"  name="sellerid" id="sellerid" >
                            <option value="-1">اختر {if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</option>
                            <option value="0">كل {if $Programsettingdata->delegate_seller eq 0} البائعين {elseif $Programsettingdata->delegate_seller == 1}المندوبين {elseif $Programsettingdata->delegate_seller == 2}الاطباء {/if}</option>
                            {foreach $sellerData as $user}
                            <option value="{$user->userid}">{$user->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <div class="col-md-2">

                            <label class="sr-only">المستخدم</label>
                        </div>
                        <select class="select2 wdt300"  name="userid" id="userid" >
                            <option value="-1">اختر المستخدم</option>
                            <option value="0">كل المستخدمين</option>
                            {foreach $userData as $user}
                            <option value="{$user->userid}">{$user->employeename}</option>
                            {/foreach}
                        </select>
                    </div>

                    <div class="form-group">
                        <div class="col-md-2">

                            <label class="sr-only">تصنيف المنتج</label>
                        </div>
                        <select class="select2 wdt300 productCat" data-level="0"  name="productCatId0" id="productCatId0" >
                            <option value="-1">اختر تصنيف</option>
                            {foreach $catDataReport as $data}
                            <option value="{$data->productCatId}">{$data->productCatName}</option>
                            {/foreach}
                        </select>
                        <input type="hidden" id="level" name="level" value="0">
                    </div>

                    <div class="form-group">
                        <div id="manyParents">

                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only">نوع السعر</label>
                        </div>
                        <select class="select2 wdt300" name="chosenProductPrice" id="chosenProductPrice">
                            <option value="-1">اختر الربح ب</option>
                            <option value="0" {if {$Programsetting->Profitevaluation} eq "first"}  selected {/if}>سعر الشراء</option>
                            <option value="1" {if {$Programsetting->Profitevaluation} eq "mean"}  selected {/if}>متوسط سعر الشراء</option>
                            <option value="2" {if {$Programsetting->Profitevaluation} eq "last"}  selected {/if}>اخر سعر شراء</option>
                            <option value="3" {if {$Programsetting->Profitevaluation} eq "last_discount"}  selected {/if}>اخر سعر شراء بعد الخصم</option>
                            <option value="4" {if {$Programsetting->Profitevaluation} eq "mean_discount"}  selected {/if}>متوسط سعر الشراء بعد الخصم</option>
                            <option value="5" {if {$Programsetting->Profitevaluation} eq "generalPrice"}  selected {/if}>المتوسط العام</option>
                            <option value="6" {if {$Programsetting->Profitevaluation} eq "tax"}  selected {/if}>اخر سعر شراء شامل القيمة المضافة</option>
                            <option value="7" {if {$Programsetting->Profitevaluation} eq "mean_tax"}  selected {/if}>متوسط سعر الشراء شامل القيمة المضافة</option>
                        </select>
                    </div>

                    <!--<div class="form-group" style="padding-top:10px">-->
                    <!--<div class="col-md-2">-->
                    <!--<label class="sr-only">الربح ب</label>-->
                    <!--</div>-->
                    <!--<div class="radio-inline">-->
                    <!--<label>-->
                    <!--<input value="0" name="chosenProductPrice"  type="radio" {if {$programsettingsdata->Profitevaluation} eq "first"}  checked {/if}  />-->
                    <!--سعر الشراء   </label>-->
                    <!--</div>-->
                    <!--<div class="radio-inline">-->
                    <!--<label>-->
                    <!--<input value="1" name="chosenProductPrice"   type="radio"   {if {$programsettingsdata->Profitevaluation} eq "mean"}  checked {/if} />-->
                    <!--متوسط سعر الشراء  </label>-->
                    <!--</div>-->
                    <!--<div class="radio-inline">-->
                    <!--<label>-->
                    <!--<input value="2" name="chosenProductPrice"   type="radio" {if {$programsettingsdata->Profitevaluation} eq "last"}  checked {/if}   />-->
                    <!--اخر سعر شراء   </label>-->
                    <!--</div>-->
                    <!--<div class="radio-inline">-->
                    <!--<label>-->
                    <!--<input type="radio" name="chosenProductPrice"  value="3" {if {$programsettingsdata->Profitevaluation} eq "last_discount"}  checked {/if}>-->
                    <!--اخر سعر شراء بعد الخصم </label>-->
                    <!--</div>-->
                    <!--<div class="radio-inline">-->
                    <!--<label>-->
                    <!--<input type="radio" name="buyPriceType"  value="4" {if {$programsettingsdata->Profitevaluation} eq "mean_discount"}  checked {/if}>-->
                    <!--متوسط سعر الشراء بعد الخصم</label>-->
                    <!--</div>-->
                    <!--<div class="radio-inline">-->
                    <!--<label>-->
                    <!--<input type="radio" name="buyPriceType"  value="5" {if {$programsettingsdata->Profitevaluation} eq "generalPrice"}  checked {/if}>-->
                    <!--المتوسط العام</label>-->
                    <!--</div>-->

                    <!--</div>-->
                    <div class="form-group" style="padding-top:10px;padding-right:30px;">
                        <div class="col-md-2">
                            <label class="sr-only">نوع البحث</label>
                        </div>
                        <div class="radio-inline">
                            <label>
                                <input value="0" name="searchtype"  type="radio" checked="checked"  />
                                منتج نهائى   </label>
                        </div>
                        <div class="radio-inline">
                            <label>
                                <input value="1" name="searchtype"   type="radio"    />
                                اخر تصنيف   </label>
                        </div>

                    </div>




                    <div style="clear: both"></div>
                    <br />
                    <button type="submit" class="btn btn-primary">بحث</button>
                    <input type="hidden" name="getTodayBills" id="getTodayBills" value="0">
                    <button type="submit" class="btn btn-primary" onclick="$('#getTodayBills').val(1);">نتائج اليوم</button>
                </form>

            </div>
            <div class="panel panel-default panel-m">
                <!-- Default panel contents -->
                <div class="panel-heading">{$message}</div>
                <div class="panel-body">
                    {if $resultsCount > 0}
                    <hr/>
                    {if $loadData->netprofit neq 1}
                    <div class="col-lg-offset-8 col-lg-4">
                        <div class="well well-sm hidden-print" >
                            <h4 class="text-center">صافى الربح {$totalsObj->netProfit} {$currency}</h4>
                        </div>
                    </div>
                    {/if}
                    <!--<div class=" col-lg-offset-8 col-lg-4 ">-->
                    <!--<div class="well well-sm">-->
                    <!--<h4 class="text-center">اجمالى المبيعات بدون خصومات  {$total_sell_without_discount}</h4>-->
                    <!--</div>-->


                </div>

                <style>
                    @media print {
                        @page {
                            size: landscape;
                            margin: 0;
                        }
                        .willprint ,.willprint td,.willprint th {
                            font-family: arial;
                            font-size: 14px;
                            border-collapse: collapse;
                            border: 1px solid #333 !important;
                        }
                        /* .willprint th{
                            background: #aaa !important;
                        } */
                        .willprint tr:even-child td{
                            background: #333 !important;
                            color: #fff !important;
                        }
                    }
                </style>
                <table class="dataTableClass willprint table-black" style="width: 100%">
                    <thead>
                        <tr>
                            <th rowspan="2">#</th>
                            <th rowspan="2">اسم المنتج</th>
                            <th colspan="2">المبيعات </th>
                            <th colspan="2">المرتجعات</th>
                            <th colspan="2">صافى المبيعات</th>
                            {if $loadData->netprofit neq 1}
                            <th rowspan="2">تكلفة المبيعات</th>
                            <th rowspan="2">صافى الربح</th>
                            {/if}
                            <th rowspan="2">الكمية الحالية</th>
                            <th rowspan="2">الخصومات</th>
                            <th rowspan="2">المبيعات بدون خصومات</th>

                        </tr>
                        <tr>
                            <th>عدد </th>
                            <th>قيمة </th>
                            <th>عدد </th>
                            <th>قيمة </th>
                            <th>عدد </th>
                            <th>قيمة </th>
                        </tr>
                    </thead>
                    <tbody>
                        {assign var=i value=1}
                        {foreach $allDataArr as $data}
                        <tr>
                            <td>{$i}</td>
                            <td>{$data->productName}/ {$data->productCatName}</td>
                            <td>{$data->soldNo}</td>
                            <td>{$data->soldVal}</td>
                            <td>{$data->returnNo}</td>
                            <td>{$data->returnVal}</td>
                            <td>{$data->netNo}</td>
                            <td>{$data->netVal}</td>
                            {if $loadData->netprofit neq 1}
                            <td>{$data->realCost}</td>
                            <td>{$data->netProfit}</td>
                            {/if}
                            <td>{$data->currentQuantity}</td>
                            <td>{$data->discount}</td>
                            <td>{$data->sellbilltotalprice}</td>
                        </tr>
                        {assign var=i value=$i+1}
                        {/foreach}
                    </tbody>
                    <tfoot>
                        <tr style="background-color: #ededed !important">
                            <td><span style="display: none">z</span></td>
                            <th style="text-align: center;">الاجمالى</th>
                            <td>{$totalsObj->soldNo}</td>
                            <td>{$totalsObj->soldVal}</td>
                            <td>{$totalsObj->returnNo}</td>
                            <td>{$totalsObj->returnVal}</td>
                            <td>{$totalsObj->netNo}</td>
                            <td>{$totalsObj->netVal}</td>
                            {if $loadData->netprofit neq 1}
                            <td>{$totalsObj->realCost}</td>
                            <td>{$totalsObj->netProfit}</td>
                            {/if}
                            <td>{$totalsObj->currentQuantity}</td>
                            <td>{$totalsObj->discount}</td>
                            <td>{$totalsObj->sellbilltotalprice}</td>
                        </tr>
                    </tfoot>
                </table>
                {if $loadData->netprofit neq 1}
                <div class="col-lg-offset-8 col-lg-4">
                    <div class="well well-sm">
                        <h4 class="text-center">صافى الربح {$totalsObj->netProfit} {$currency}</h4>
                    </div>
                </div>
                {/if}

                <div class="clearfix"></div>
                <hr />
                <div  class="noprint">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <div class="col-lg-4">
                                <button type="button" onclick="print_Custom('mycustomheader');" class="btn btn-success pull-right hidden-print">طباعة</button>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                {else}
                <div class="nodata">عفوا لا توجد نتائج</div>
                {/if}

                <div class="clearfix"></div>
            </div>
        </div>
    </div>
    {literal}
    <script>
        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();
        }


        $(function () {
            var formatResult = function (data) {
                return  data.text;
            }

            $('#getclientareaonly').select2({
                placeholder: "اختر الشركة  - المنطقة",
                width: '100%',
                ajax: {
                    url: 'clientControllerAjax.php?do=getclientareaonly',
                    dataType: 'json',
                    type: "POST",
                    data: function (term) {
                        var governmentid = $('#governmentid').val();
                        if (governmentid < 1) {
                            alert('يجب اختيار المحافظه اولا');
                        }
                        return {
                            searchTerms: term,
                            governmentid: $('#governmentid').val()
                        };
                    },
                    results: function (data) {
                        return {
                            results: data,
                        };
                    }
                },
                formatResult: formatResult,
            });

            $(".select2Supp").select2({
                placeholder: "العميل",
                minimumInputLength: document.getElementById("searchvalue").value,
                inimumInputLength: 0,
                multiple: false,
                quietMillis: 100,
                allowClear: true,
                width: '100%',
                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: '', text: ''});
        });
    </script>
    {/literal}