<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;
    }

    .product-image-overlay {
        /*        position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(0, 0, 0, 0.9);
                z-index: 9999;
                display: none;*/

        position: fixed;
        top: 15%;
        left: 40%;
        /* text-align: center; */
        width: 30%;
        height: 50%;
        background: rgba(4, 0, 0, 0.38);
        z-index: 9999;
        border-radius: 45px;
        display: none;
    }

    .product-image-overlay .product-image-overlay-close {
        display: block;
        position: absolute;
        top: 20px;
        left: 20px;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: 1px solid #eee;
        line-height: 35px;
        font-size: 20px;
        color: #eee;
        text-align: center;
        cursor: pointer;
    }

    .product-image-overlay img {
        width: auto;
        max-width: 80%;
        position: absolute;
        top: 50%;
        left: 50%;
        -webkit-transform: translate(-50%, -50%);
        -moz-transform: translate(-50%, -50%);
        -o-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
    }
</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[143]->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="buyreport.php" method="post">

                    <div class="form-group">
                        <label class="sr-only">المورد</label>
                        <select class="select2" name="supplierid" id="supplierid">
                            <option value="-1">اختر مورد</option>
                            {foreach $suppliers as $data}
                            <option value="{$data->supplierid}" {if $data->supplierid eq
                                $supplierid}selected{/if}>{$data->suppliername}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="form-group" {if empty($debt)}style="display: none" {/if} id="supDebt">
                        <label class="sr-only">الدين</label>
                        <input type="text" class="form-control" style="width: 83%" disabled id="suppliercurrentDebt"
                            value="{$debt}">
                    </div>
                    <div style="clear: both"></div>

                    <!-- <div class="form-group">
                        <label class="sr-only">العميل</label>
                        <select class="select2" name="clientid" id="clientid">
                            <option value="-1">اختر عميل</option>
                            {foreach $clients as $data}
                            <option value="{$data->clientid}" {if $data->clientid eq
                                $clientid}selected{/if}>{$data->clientname}</option>
                            {/foreach}
                        </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>
                    <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>
                    <div style="clear: both"></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}
                    <!--                    <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;
                            }

                            /* .willprint th{
                                background: #aaa !important;
                            } */
                            .willprint tr:even-child td {
                                background: #333 !important;
                                color: #fff !important;
                            }
                        }
                    </style>
                    <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>
                                {if $loadUserGroupData->netprofit neq 1}
                                <th>عدد صافي المبيعات </th>
                                <th>قيمة صافي المبيعات </th>
                                <th>تكلفة المبيعات </th>
                                {/if}
                            </tr>
                        </thead>
                        <tbody>
                            {assign var=i value=1}
                            {assign var=noOfBills value=0}
                            {assign var=sell_quantity value=0}
                            {foreach $allDataArr as $dataArr}
                            {foreach $dataArr as $data}
                            <tr>

                                {assign var=noOfBills value=$noOfBills+$data->noOfBills}
                                {assign var=sell_quantity value=$sell_quantity + ($data->amount-$data->amount_ret) -
                                $data->productQuantity}
                                <td>{$data->productName}</td>
                                <td><img src="../views/default/images/product_image/{$data->logo}" class="moImg" alt=""
                                        width="50" height="30" /></td>
                                <td>{$data->unitName}</td>
                                <td>{$data->noOfBills}</td>
                                <td>{$data->amount}</td>
                                <td>{$data->price}</td>
                                <td>{$data->priceWithTax}</td>
                                <td>{$data->priceWithTax-$data->price}</td>
                                <td>{$data->amount_ret}</td>
                                <td>{$data->price_ret}</td>
                                <td>{$data->priceWithTax_ret}</td>
                                <td>{$data->priceWithTax_ret-$data->price_ret}</td>
                                <td>{$data->amount-$data->amount_ret}</td>
                                <td>
                                    {assign var=total value={($data->price - $data->price_ret) / ($data->amount -
                                    $data->amount_ret) }}
                                    {$total|string_format:"%.2f"}
                                </td>
                                <td>{$data->productQuantity}</td>
                                <td>{$data->storeQuantityPrice}{*$data->productLastPrice * $data->productQuantity*}</td>
                                <!-- <td>{($data->amount-$data->amount_ret) - $data->productQuantity}</td> -->
                                {if $loadUserGroupData->netprofit neq 1}
                                <td>{$data->netQuantity}</td>
                                <td>{$data->netPrice}</td>
                                <td>{$data->realCost}</td>
                                {/if}
                            </tr>
                            {/foreach}
                            {/foreach}

                        </tbody>

                    </table>
                    <div class="row"></div>
                    <hr />
                    <div class="row"></div>
                    <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>
                                {if $loadUserGroupData->netprofit neq 1}
                                <th>عدد صافي المبيعات </th>
                                <th>قيمة صافي المبيعات </th>
                                <th>تكلفة المبيعات </th>
                                {/if}
                            </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}
                            {assign var=total_net_quantity value=0}
                            {assign var=total_net_price value=0}
                            {assign var=total_real_cost 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}
                                {assign var=total_net_quantity value=$total_net_quantity+$data->netQuantity}
                                {assign var=total_net_price value=$total_net_price+$data->netPrice}
                                {assign var=total_real_cost value=$total_real_cost+$data->realCost}
                                <td>{$data->catName}</td>
                                <td>{$data->unitName}</td>
                                <td>{$data->amount}</td>
                                <td>{$data->price}</td>
                                <td>{$data->priceWithTax}</td>
                                <td>{$data->amount_ret}</td>
                                <td>{$data->price_ret}</td>
                                <td>{$data->priceWithTax_ret}</td>
                                <td>{$data->amount-$data->amount_ret}</td>
                                <td>
                                    {assign var=total value={($data->price - $data->price_ret) / ($data->amount -
                                    $data->amount_ret) }}
                                    {$total|string_format:"%.2f"}
                                </td>
                                <td>{$data->storeQuantity}</td>
                                <td>{$data->storeQuantityPrice}</td>
                                <!-- <td>{($data->amount-$data->amount_ret) - $data->storeQuantity}</td> -->
                                {if $loadUserGroupData->netprofit neq 1}
                                <td>{$data->netQuantity}</td>
                                <td>{$data->netPrice}</td>
                                <td>{$data->realCost}</td>
                                {/if}
                            </tr>
                            {/foreach}
                            {/foreach}

                        </tbody>

                    </table>

                    <!--                    <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 well-2sm">
                            <h4 class="text-center">عدد المشتريات {$amount}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">اجمالى المشتريات {$price} {$currency}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">عدد المردودات {$amount_ret}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">اجمالى المردودات {$price_ret} {$currency}</h4>
                        </div>
                    </div>
                    <!-- <div class="clearfix"></div>
                    <br/> -->
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">اجمالى الكمية {$totalStoreQuantity}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">اجمالى السعر {$totalStoreQuantityPrice} {$currency}</h4>
                        </div>
                    </div>

                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">دين المورد {$debt} {$currency}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">اجمالى الدفعات {$payed} {$currency}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <!-- <h4 class="text-center">اجمالى عدد الفواتير {$noOfBills}</h4> -->
                            <h4 class="text-center">اجمالى عدد الفواتير {$buyBillNo}</h4>
                        </div>
                    </div>
                    {if $loadUserGroupData->netprofit neq 1}
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">اجمالى عدد صافي المبيعات {$total_net_quantity}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">اجمالى قيمة صافي المبيعات {$total_net_price}</h4>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="well well-sm well-2sm">
                            <h4 class="text-center">اجمالى تكلفة المبيعات {$total_real_cost}</h4>
                        </div>
                    </div>
                    {/if}
                    <!--                    <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>
            $('#supplierid').live('change', function () {
                var supplierid = $(this).val();
                $.ajax({
                    type: 'GET',
                    url: 'getSupplierDept.php?do=getsuppliercurrentDebt&supplierid=' + supplierid,
                    success: function (data) {
                        $('#supDebt').show();
                        $("#suppliercurrentDebt").val(data);
                    }
                });
            })
            $('body').on('click', '.moImg', function () {

                $('body').append('<div class="product-image-overlay"><span class="product-image-overlay-close">x</span><img src="" /></div>');
                var productImage = $('img');
                var productOverlay = $('.product-image-overlay');
                var productOverlayImage = $('.product-image-overlay img');
                productImage.click(function () {
                    var productImageSource = $(this).attr('src');
                    productOverlayImage.attr('src', productImageSource);
                    productOverlay.fadeIn(100);
                    $('body').css('overflow', 'hidden');
                    $('.product-image-overlay-close').click(function () {
                        productOverlay.fadeOut(100);
                        $('body').css('overflow', 'auto');
                    });
                });
            });

        </script>
        {/literal}