<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;
    }
</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[153]->url}" target="_blank" class="hidden-print"><img src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube" style="width: 2%;"></a>
            </div>
            <div class="panel-body">
                <form class="form-inline hidden-print" action="salesreportofclientsbyproduct.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">
                        <div class="col-md-2">
                            <label class="sr-only">العميل</label>
                        </div>
                        <select class="select2 wdt300"  name="clientId" id="clientId" >
                            <option value="-1">اختر عميل</option>
                            <option value="0">كل العملاء</option>
                            {foreach $clients as $data}
                            <option value="{$data->clientid}">{$data->clientname}</option>
                            {/foreach}
                        </select>
                    </div>
                    {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" checked="checked"  />-->
                    <!--سعر الشراء   </label>-->
                    <!--</div>-->
                    <!--<div class="radio-inline">-->
                    <!--<label>-->
                    <!--<input value="1" name="chosenProductPrice"   type="radio"    />-->
                    <!--متوسط سعر الشراء  </label>-->
                    <!--</div>-->
                    <!--<div class="radio-inline">-->
                    <!--<label>-->
                    <!--<input value="2" name="chosenProductPrice"   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="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>
                </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}
                    <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>
                                <th rowspan="2">تكلفة المبيعات</th>
                                {if $loadData->netprofit neq 1}<th rowspan="2">صافى الربح</th>{/if}
                                <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->clientName}</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>
                                <td>{$data->realCost}</td>
                                {if $loadData->netprofit neq 1}<td>{$data->netProfit}</td>{/if}
                                <td>{$data->currentQuantity}</td>
                            </tr>
                            {assign var=i value=$i+1}
                            {/foreach}
                            <tr style="background-color: #9e9e9e !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>
                                <td>{$totalsObj->realCost}</td>
                                {if $loadData->netprofit neq 1}<td>{$totalsObj->netProfit}</td>{/if}
                                <td>{$totalsObj->currentQuantity}</td>
                            </tr>
                        </tbody>

                    </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();
            }
        </script>
        {/literal}