<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;
    }
    .productborder{
        border-top:4px solid  #ddd !important;
    }
    .solidgraytop{
        border-top-style:solid;
        border-top-color:#ddd;
    }
    .solidgrayleft{
        border-left:solid;
        border-left-width:3px;
        border-color: #ddd;
    }
    .solidgrayright{
        border-right-style:solid;
        border-right-color:#ddd;
    }
    .solidgraybottom{
        border-top-style:solid;
        border-top-color:#ddd;
    }
    .hidetop{
        border-top:hidden !important;
    }
    .mytotal{
        background-color:#ddd;
        font-weight:bold;
    }
</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[144]->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="sellreportpricetype.php" method="post">
                    <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="">كل العملاء</option>
                            {foreach $allClients as $data}
                            <option value="{$data->clientid}">{$data->clientname}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group" style="display: none" id="clientDebtDiv">
                        <label class="sr-only">الدين</label>
                        <input type="text" class="form-control" style="width: 83%" disabled id="clientDebt">
                    </div>
                    <div style="clear: both"></div>
                    <div class="form-group">
                        <label class="sr-only">نوع السعر</label>
                        <select class="select2 wdt100" name="pricetype" id="pricetype">
                            <option selected="selected" 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">تصنيف المنتج</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 style="clear: both"></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="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>
                    {if $userGroup->sellreportpricetype == "0"}
                    <div style="clear: both"></div>
                    <div class="form-group">
                        <label class="sr-only">ترتيب الاجمالى</label>
                        <div>
                            <div class="radio-inline">
                                <label>
                                    <input name="order" type="radio" checked="checked" value="no">بلا ترتيب
                                </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input name="order" type="radio" value="asc">تصاعدى
                                </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input name="order" type="radio" value="desc">تنازلى
                                </label>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <div style="clear: both"></div>
                           <div class="form-group">
                        <label class="sr-only">المخزن</label>
                        <select class="select2 wdt300"  name="storeId" id="storeId" >
                            <option value="-1">اختر مخزن</option>



                            {foreach $storeData as $store}




                            <option value="{$store->storeId}">{$store->storeName}</option>


                            {/foreach}



                        </select>
                    </div>
                    <br />
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>

            </div>
            <hr/>
            <div class="panel panel-default panel-m">
                <!-- Default panel contents -->
                <div class="panel-heading">{$message}</div>
                <div class="panel-body">
                    {if count($allDataArr) > 0}

                    {if $userGroup->sellreportpricetype == "0"}
                    <div class="col-lg-offset-8 col-lg-4">
                        <div class="well well-sm hidden-print">
                            <h4 class="text-center">اجمالى المبيعات {$totalOfTotals} {$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="table willprint table-black dataTableClass22" style="width: 100%">
                        <thead>
                            <tr class="solidgraytop solidgrayleft solidgrayright mytotal">
                                <th>#</th>
                                <th class="solidgrayright">اسم المنتج</th>
                                <th class="solidgrayright">العدد</th>
                                <th {if $userGroup->sellreportpricetype == "1"}class="solidgrayleft"{/if}>الوحدة</th>
                                {if $userGroup->sellreportpricetype == "0"}<th>السعر من الفاتورة</th>{/if}
                                {if $userGroup->sellreportpricetype == "0"}<th class="solidgrayright">الاجمالى</th>{/if}
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {foreach $allDataArr as $dataArr}
                            {foreach $dataArr as $data}
                            <tr {if $data->productName != ""} class="productborder" {/if}>
                                <td class="solidgrayright {if $data->productName == ''} hidetop {/if}">
                                    {if $data->productName != ""}{$i} {assign var=i value=$i+1} {/if}
                                </td>
                                <td  class="solidgrayright {if $data->productName == ''} hidetop {/if}">{$data->productName}</td>
                                <td class="solidgrayright">{$data->amount}</td>
                                <td {if $userGroup->sellreportpricetype == "1"}class="solidgrayleft"{/if}>{$data->unitName}</td>
                                {if $userGroup->sellreportpricetype == "0"}<td class="solidgrayleft">{$data->price}</td>{/if}
                                {if $userGroup->sellreportpricetype == "0"}<td class="solidgrayleft {if $data->productName == ''}hidetop{/if}">
                                    {if $data->productId != ""}
                                    {$productTotalArr[$data->productId]}
                                    {/if}
                                </td>{/if}
                            </tr>
                            {/foreach}
                            {/foreach}
                            <tr class="mytotal">
                                <td class="solidgrayright"></td>
                                <td class="solidgrayright"></td>
                                <td></td>
                                {if $userGroup->sellreportpricetype == "0"}
                                <td></td>
                                <td></td>
                                {/if}
                                <td class="solidgrayleft" style="text-align:center;"></td>

                            </tr>
                        </tbody>

                    </table>
                    {if $userGroup->sellreportpricetype == "0"}
                    <div class="col-lg-offset-8 col-lg-4">
                        <div class="well well-sm">
                            <h4 class="text-center">اجمالى المبيعات {$totalOfTotals} {$currency}</h4>
                        </div>
                    </div>
                    {/if}
                    <div class="clearfix"></div>
                    <br/>
                    <table class="table table-black" style="width: 50%;margin-left:25%;margin-right:25%;;text-align: center;">
                        <thead style="font-weight: bold">
                            <tr>
                                <th colspan="2">اجمالى الوحدات</th>
                            </tr>
                            <tr>
                                <td>الوحدة </td>
                                <td> العدد</td>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach from=$unitTotal item=value key=key }
                            <tr>
                                <td class="color-white">{$key} </td>
                                <td class="color-white"> {$value}</td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>

                    <div class="clearfix"></div>
                    <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>
            $('.dataTableClass22').dataTable({
                "order"
                        : [
                            [4, "desc"]       // order by drug cat
                        ]
            });
            $("#clientid").live('change', function () {
                var clientid = $(this).val();
                if (clientid == "" || clientid == "-1")
                {
                    $('#clientDebtDiv').hide();
                    $("#clientDebt").val("");
                }
                else
                {
                    $.ajax({
                        url: "clientDeficitControllerAjax.php?id=" + clientid,
                        type: "get",
                        success: function (data) {
                            //alert(data);
                            $('#clientDebtDiv').show();
                            $("#clientDebt").val(data);
                        },
                        error: function () {
                            alert("لقد حدث خطأ أثناء إجراء العملية");
                        }
                    });
                }
            });
        </script>
        {/literal}