<style>
    @media print{
        body,th,td,span,p{
            color:#000!important
        }
    }
    .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[151]->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="fullCategoryReport.php?do=show" method="post">
                    <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>
                            <option value="0">الكل</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">
                        <label class="sr-only">المخزن</label>
                        <select class="select2" 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">
                        <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 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>
                    <div style="clear: both"></div>
                    <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}
                    <!--                    <div class="col-lg-offset-8 col-lg-4">
                                            <div class="well well-sm">
                                                <h4 class="text-center">اجمالى المشتريات {$totalOfTotals} {$currency}</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;
                                color:#000!important
                            }
                            p,h4,h3,h2,h1,span,label,td,th,div.dataTables_info,a,.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
                            div.dataTables_wrapper div.dataTables_info,.panel-heading, tr.odd td.sorting_1{
                                color:#000!important
                            }
                            .willprint th{
                                background: #aaa !important;
                                color:#000!important
                            }
                            .willprint tr:even-child td{
                                background: #333 !important;
                                color: #fff !important;
                                color:#000!important
                            }
                        }
                    </style>
                    {if $isLastLevelCatFlag == 1}
                    <table class="table willprint table-black dataTableClass" style="width: 100%">
                        <thead>
                            <tr>
                                <th>اسم المنتج</th>
                                <th>الوحدة</th>
                                <th>عدد المشتربات</th>
                                <th>اجمالى المشتريات</th>
                                <th>عدد المردودات</th>
                                <th>اجمالى المردودات</th>
                                <th>صافى المشتريات</th>
                                <th>متوسط سعر الشراء</th>

                                <th>عدد المبيعات</th>
                                <th>اجمالى المبيعات</th>
                                <th>عدد المردودات</th>
                                <th>اجمالى المردودات</th>
                                <th>صافى المبيعات</th>
                                <th>متوسط سعر البيع</th>
                                <th>الكمية فى المخازن</th>
                                <th>سعر المخزن باخر سعر شراء</th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=price value=0}
                            {assign var=amount value=0}
                            {assign var=price_ret value=0}
                            {assign var=amount_ret value=0}
                            {foreach $allDataArr as $dataArr}
                            {foreach $dataArr as $data}
                            <tr>
                                {assign var=price value=$price+$data->price}
                                {assign var=amount value=$amount+$data->amount}
                                {assign var=price_ret value=$price_ret+$data->price_ret}
                                {assign var=amount_ret value=$amount_ret+$data->amount_ret}
                                <td>{$data->productName}</td>
                                <td>{$data->unitName}</td>
                                <td>{$data->amount}</td>
                                <td>{$data->price}</td>
                                <td>{$data->amount_ret}</td>
                                <td>{$data->price_ret}</td>
                                <td>{$data->amount-$data->amount_ret}</td>
                                <td>
                                    {assign var=buyAverage value={($data->price - $data->price_ret) / ($data->amount - $data->amount_ret) }}
                                    {$buyAverage|string_format:"%.2f"}
                                </td>
                                <td>{$data->amount_sell}</td>
                                <td>{$data->price_sell}</td>
                                <td>{$data->amount_ret_sell}</td>
                                <td>{$data->price_ret_sell}</td>
                                <td>{$data->amount_sell-$data->amount_ret_sell}</td>
                                <td>
                                    {assign var=sellAverage value={($data->price_sell - $data->price_ret_sell) / ($data->amount_sell - $data->amount_ret_sell) }}
                                    {$sellAverage|string_format:"%.2f"}
                                </td>
                                <td>{$data->productQuantity}</td>
                                <td>{$data->storeQuantityPrice}{*$data->productLastPrice * $data->productQuantity*}</td>

                            </tr>
                            {/foreach}
                            {/foreach}

                        </tbody>

                    </table>
                    {/if}
                    <!--                    <div class="row"></div>
                                        <hr/>
                                        <hr/>
                                        <div class="row"></div>-->
                    {if $isLastLevelCatFlag == 0}
                    <h3> اجمالى التصنيفات</h3>
                    <table class="table willprint table-black dataTableClass" style="width: 100%">
                        <thead>
                            <tr>
                                <th>اسم التصنيف</th>
                                <th>الوحدة</th>
                                <th>عدد المشتربات</th>
                                <th>اجمالى المشتريات</th>
                                <th>عدد المردودات</th>
                                <th>اجمالى المردودات</th>
                                <th>صافى المشتريات</th>
                                <th>متوسط سعر الشراء</th>

                                <th>عدد المبيعات</th>
                                <th>اجمالى المبيعات</th>
                                <th>عدد المردودات</th>
                                <th>اجمالى المردودات</th>
                                <th>صافى المبيعات</th>
                                <th>متوسط سعر البيع</th>
                                <th>الكمية فى المخازن</th>
                                <th>سعر المخزن باخر سعر شراء</th>
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=price value=0}
                            {assign var=amount value=0}
                            {assign var=price_ret value=0}
                            {assign var=amount_ret value=0}
                            {foreach $allCatArr as $dataArr}
                            {foreach $dataArr as $data}
                            <tr>
                                {assign var=price value=$price+$data->price}
                                {assign var=amount value=$amount+$data->amount}
                                {assign var=price_ret value=$price_ret+$data->price_ret}
                                {assign var=amount_ret value=$amount_ret+$data->amount_ret}
                                <td>{$data->catName}</td>
                                <td>{$data->unitName}</td>
                                <td>{$data->amount}</td>
                                <td>{$data->price}</td>
                                <td>{$data->amount_ret}</td>
                                <td>{$data->price_ret}</td>
                                <td>{$data->amount-$data->amount_ret}</td>
                                <td>
                                    {assign var=buyAverage value={($data->price - $data->price_ret) / ($data->amount - $data->amount_ret) }}
                                    {$buyAverage|string_format:"%.2f"}
                                </td>
                                <td>{$data->amount_sell}</td>
                                <td>{$data->price_sell}</td>
                                <td>{$data->amount_ret_sell}</td>
                                <td>{$data->price_ret_sell}</td>
                                <td>{$data->amount_sell-$data->amount_ret_sell}</td>
                                <td>
                                    {assign var=sellAverage value={($data->price_sell - $data->price_ret_sell) / ($data->amount_sell - $data->amount_ret_sell) }}
                                    {$sellAverage|string_format:"%.2f"}
                                </td>
                                <td>{$data->storeQuantity}</td>
                                <td>{$data->storeQuantityPrice}</td>
                            </tr>
                            {/foreach}
                            {/foreach}

                        </tbody>

                    </table>
                    {/if}

                    <!--                    <table class="table willprint table-black" style="width: 100%">
                                            <thead>
                                                <tr class="solidgraytop solidgrayleft solidgrayright mytotal">
                                                    <th>#</th>
                                                    <th class="solidgrayright">اسم المنتج</th>
                                                    <th class="solidgrayright">العدد</th>
                                                    <th>الوحدة</th>
                                                    <th>السعر من الفاتورة</th>
                                                    <th class="solidgrayright">الاجمالى</th>
                                                </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>{$data->unitName}</td>
                                                    <td class="solidgrayleft">{$data->price}</td>
                                                    <td class="solidgrayleft {if $data->productName == ''}hidetop{/if}">
                                                        {if $data->productId != ""}
                                                        {$productTotalArr[$data->productId]}
                                                        {/if}
                                                    </td>
                                                </tr>
                                                {/foreach}
                                                {/foreach}
                                                <tr class="mytotal">
                                                    <td class="solidgrayright"></td>
                                                    <td class="solidgrayright"></td>
                                                    <td></td>
                                                    <td></td>
                                                    <td></td>
                                                    <td class="solidgrayleft" style="text-align:center;"></td>

                                                </tr>
                                            </tbody>

                                        </table>-->

                    <div class="col-lg-3">
                        <div class="well well-sm">
                            <h4 class="text-center">عدد المشتريات {$amount}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm">
                            <h4 class="text-center">اجمالى المشتريات {$price} {$currency}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm">
                            <h4 class="text-center">عدد المردودات {$amount_ret}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm">
                            <h4 class="text-center">اجمالى المردودات {$price_ret} {$currency}</h4>
                        </div>
                    </div>
                    <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>
                                                    <th>الوحدة </th>
                                                    <th> العدد</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                {foreach from=$unitTotal item=value key=key }
                                                <tr>
                                                    <td>{$key} </td>
                                                    <td> {$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>
            $('.productCat').live('change', function () {
                var id = $(this).val();
                var level = Number($(this).attr('data-level'));
                level = level + 1;
                $('#level').val(level);
                $.post('salesreportajax.php?do=getsubcat', {id: id, level: level}, function (data) {
                    $('.productCat').each(function () {
                        var thisLevel = Number($(this).attr('data-level'));
                        if (thisLevel >= level) {
                            $(this).parent('div').remove();
                        }
                    });
                    $('#productIdDiv').remove();
                    if (data != "-1") {
                        $('#manyParents').append(data);
                    }
                });

            });

        </script>
        {/literal}