<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">
                <input type="hidden" id="searchvalue" value="{$Programsetting->searchvalue}">
                <form class="form-inline hidden-print" action="supplierSalesReportController.php?do=show" 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">
                        <label class="sr-only">المورد</label>
                        <select class="select2 wdt300" name="supplierid" id="supplierid">
                            <option value="-1">اختر مورد</option>
                            {foreach $suppliers as $sup}
                            <option value="{$sup->supplierid}">{$sup->suppliername} </option>
                            {/foreach}
                        </select>
                    </div>

                    <div class="form-group col-lg-5">
                        <div class="col-md-2">
                            <label class="sr-only">العميل</label>
                        </div>
                        <input type="hidden" name="clientId" id="clientId" class="select2Supp" />
                    </div>

                    <div class="clearfix"></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">
                        <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>
                    <br />
                    <button type="submit" class="btn btn-primary">بحث</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 />
                </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="dataTableClass willprint table-black" style="width: 100%">
                    <thead>
                        <tr>
                            <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->productName}/ {$data->productCatName}</td>
                            <td>{$data->netVal}</td>
                            <td>{$data->netProfit}</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 style="text-align: center;">{$totalsObj->netVal}</td>
                            <td style="text-align: center;">{$totalsObj->netProfit}</td>
                        </tr>
                    </tfoot>
                </table>

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


        $(function () {
            var formatResult = function (data) {
                return data.text;
            }

            $(".select2Supp").select2({
                placeholder: "العميل",
                minimumInputLength: document.getElementById("searchvalue").value,
                inimumInputLength: 0,
                multiple: false,
                quietMillis: 100,
                allowClear: true,
                width: '100%',
                ajax: {
                    url: "clientControllerAjax.php?do=select2ClientsAjax",
                    dataType: 'json',
                    data: function (term, page) {
                        return {
                            term: term, //search term
                            page_limit: 7, // page size
                            withAddOption: 0,
                            withNakdi: function () {
                                return (Number($('#withNakdi').val()) == 1) ? 0 : 1;
                            },
                            //jsonRowRet: 1,
                        };
                    },
                    results: function (data) {
                        return { results: data };
                    }
                },
                formatResult: function (data) {
                    if (Number(data.id) == -2) {
                        return '<span class="newoption">' + data.text + '</span >';
                    } else {
                        return '<span>' + data.text + '</span >';
                    }
                },
                initSelection: function (element, callback) {
                    var item = element.val().split(':');
                    //  var data = {id: item[0], text: item[1]};
                    var data = { id: item[0], text: item[1], productquantity: item[2], price: item[3] };
                    callback(data);
                },
                //dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
            })
            //this is needed for ajax =>to obtain id from it  and use in ajax
            $('#clientId').select2('data', { id: '', text: '' });
        });
    </script>
    {/literal}