<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">
                <form class="form-inline hidden-print" action="salesreportcatstore.php" method="post">
                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only">{if $Programsetting->delegate_seller eq 0} بائع {elseif
                                $Programsetting->delegate_seller == 1}مندوب {elseif $Programsetting->delegate_seller
                                == 2}طبيب {/if}</label>
                        </div>
                        <select class="select2" name="sellerid" id="sellerid">
                            <option value="-1">اختر {if $Programsetting->delegate_seller eq 0} بائع {elseif
                                $Programsetting->delegate_seller == 1}مندوب {elseif
                                $Programsetting->delegate_seller == 2}طبيب {/if}</option>
                            {foreach $sellerData as $mysellerData}
                            <option value="{$mysellerData->userid}">{$mysellerData->employeename}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group">
                        <div class="col-md-2">
                            <label class="sr-only">نوع البحث</label>
                        </div>
                        <div class="radio-inline">
                            <label>
                                <input value="0" name="searchtype" id="searchtype0" type="radio" checked="checked"  />
                                التصنيفات  </label>
                        </div>
                        <div class="radio-inline">
                            <label>
                                <input value="1" name="searchtype" id="searchtype1"  type="radio"    />
                                المخازن  </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="dateOnly" name="search" id="searchdateOnly" type="radio" checked onclick='localStorage.setItem("search", "dateOnly");
                                    window.location.reload();'>
                                تاريخ</label>
                        </div>
                        <div class="radio-inline">
                            <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" id="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" id="dateto">
                        </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="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>-->




                    <input type="hidden" name="storeId" id="storeId" value="">
                    <input type="hidden" name="productCatId" id="productCatId" value="">
                    <button type="submit" class="btn btn-primary" id="searchBtn">بحث</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>

                <input type="hidden" name="searchtypeold" id="searchtypeold" value="{$searchtype}">
                <input type="hidden" name="datefromold" id="datefromold" value="{$datefrom}">
                <input type="hidden" name="datetoold" id="datetoold" value="{$dateto}">
                <input type="hidden" name="storeidold" id="storeidold" value="{$storeid}">
                <input type="hidden" name="selleridold" id="selleridold" value="{$sellerid}">
                <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>
                                {if $data->id != "sum"}
                                <a class="doSearch" data-id="{$data->id}" data-namedisplayed="{$data->nameDisplayed}">{$data->productName}{if isset($data->productCatName)}/{/if} {$data->productCatName}</a>
                                {else}
                                {$data->productName}
                                {/if}
                            </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();
        }


        $('.doSearch').live('click', function () {
            var datefrom = $('#datefromold').val();
            var dateto = $('#datetoold').val();
            var searchtype = $('#searchtypeold').val();
            //#
            var namedisplayed = $(this).data('namedisplayed');
            var storeid;
            var catid;
            if (namedisplayed == 'store') {
                storeid = $(this).data('id');
                catid = 0;
            } else if (namedisplayed == 'cat') {
                storeid = $('#storeidold').val();
                catid = $(this).data('id');
            }

            //to allow open data in new tab stop this
//            $('#storeId').val(storeid);
//            $('#productCatId').val(catid);
//            $('#searchtype' + searchtype).prop('checked', true);
//            $('#datefrom').val(datefrom);
//            $('#dateto').val(dateto);
//            $('#searchBtn').click();
            //& use that
            document.cookie = "formData=" + encodeURIComponent(JSON.stringify({
                storeId: storeid,
                productCatId: catid,
                searchtype: searchtype,
                datefrom: datefrom,
                dateto: dateto,
                search: $('input[name="search"]:checked').val()
            }));
            var newTab = window.open(window.location.href, "_blank");
            //newTab.location.href = "https://example.com/new-url";

        });
    </script>
    {/literal}