<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">تقرير عميل مفصل<br />
                {if $message != ""}
                {$message}
                {/if}
                <a href="{$youtubes[124]->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="clientReportsController.php?do=all" method="post">
                    <div class="form-group">
                        <label class="sr-only">العميل</label>
                        <div id="clientDiv">
                            <input type="hidden" name="clientid" id="clientid"
                                class="select2 select2Supp wdt300" />
                            <input type="hidden" id="oldclientid" />
                            <input type="hidden" id="oldclientname" />
                        </div>
                        <!-- <select class="select2 wdt300"  name="clientid" id="clientid" >
                            <option value="-1">اختر عميل</option>

                            {foreach $clientData as $client}


                            <option value="{$client->clientid}">{$client->clientname}</option>


                            {/foreach}


                        </select> -->
                    </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="from">
                    </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="to">
                    </div>

                    <div class="form-group">
                        <label class="sr-only">رصيد صافي</label>
                        <input type="checkbox" name="bure" checked="checked" id="bure" value="1" />
                        <label for="bure"></label>
                    </div>
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>
                <hr />
                <div id="tableWrap">

                    <table width="230" border="1" align="center" class="table-black">
                        <tr>
                            <th>رصيد العميل :</th>
                            <th>{$clinetdept->clientdebt} {$currency}</th>
                        </tr>
                        <tr>
                            <th> بداية مديونية العميل :</th>
                            <th>{$clientControllerVal} {$currency}</th>
                        </tr>
                    </table>

                    <div class="col-lg-4">
                        <div class="panel panel-default panel-m">
                            <!-- Default panel contents -->

                            <div class="panel-heading">فواتير المبيعات</div>
                            <div class="panel-body">
                                <table class="table table-black" style="width:100% !important; height:100% !important;">
                                    <thead>
                                        <tr>
                                            <th>م</th>
                                            <!--                  <th>رقم الفاتورة</th>
                                            -->
                                            <th>تاريخ الفاتورة</th>
                                            <th>عدد الوحدات</th>
                                            <th>إجمالي الفاتورة</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        {foreach $sellbillData as $data}
                                        <tr {if $data->conditions eq 1}class="danger"{/if}>
                                            <td>{$data->sellbillid}</td>
                                            <!--                <td>{$data->sellbillserial}</td>
                                            -->
                                            <td>{$data->sellbilldate}</td>
                                            <td>{$data->sellQuantity}</td>
                                            <td>
                                                {if {$data->userid} eq -1}

                                                {$data->sellbillprice}
                                                {else}
                                                {$data->sellbillaftertotalbill}
                                                {/if}</td>
                                        </tr>
                                        {/foreach}
                                        <tr class="success">
                                            <td colspan="2">الإجمالي</td>
                                            <td>{$selltotalQTY} قطعة</td>
                                            <td>{$selltotalBills} {$currency}</td>

                                        </tr>
                                    </tbody>

                                </table>
                            </div>
                            <!--panel-body-->
                        </div>
                        <!--panel panel-default-->
                    </div><!--col-lg-4-->
                    <!--**********************************************************************-->
                    <div class="col-lg-4">
                        <div class="panel panel-default panel-m">
                            <!-- Default panel contents -->
                            <div class="panel-heading">الدفعات</div>
                            <div class="panel-body">
                                <table class="table table-black">
                                    <thead>
                                        <tr>
                                            <th>التاريخ</th>
                                            <th>القيمة</th>
                                            <th>النوع</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        {foreach $clientShowData as $data}
                                        {if $data->clientdebtchangeamount neq "0" && $data->tablename neq
                                        'clientController.php'}
                                        <tr {if $data->clientdebtchangetype eq 1} style=" background-color: #ffb6b6;"
                                            {/if} >
                                            <td>{$data->clientdebtchangedate}</td>
                                            <td>{$data->clientdebtchangeamount}</td>
                                            <td>{$data->processname}{if $data->processname =="ايداع
                                                شيك"}({$data->bankname})/({$data->accountname}){/if}</td>
                                        </tr>
                                        {/if}
                                        {/foreach}
                                        {foreach $sellbillData as $data}
                                        {if $data->sellbilltotalpayed !=0}
                                        {*if $data->sellbilltotalpayed > $data->sellbillaftertotalbill*}
                                        <tr {if $data->conditions neq 1}class="danger"{/if}>
                                            <td>{$data->sellbilldate}</td>
                                            <!--td>{$data->sellbilltotalpayed - $data->sellbillaftertotalbill}</td-->
                                            <td>{$data->sellbilltotalpayed}</td>
                                            <td>دفعة فى فاتورة مبيعات</td>
                                        </tr>
                                        {*/if*}
                                        {/if}
                                        {/foreach}
                                        {foreach $sellBillAndReturnData as $data}
                                        {if $data->sellbilltotalpayed !=0}
                                        {*if $data->sellbilltotalpayed > $data->sellbillaftertotalbill*}
                                        <tr {if $data->conditions neq 1}class="danger"{/if}>
                                            <td>{$data->sellbilldate}</td>
                                            <!--td>{$data->sellbilltotalpayed - $data->sellbillaftertotalbill}</td-->
                                            <td>{$data->sellbilltotalpayed}</td>
                                            <td>دفعة فى فاتورة المبيعات والمرتجعات</td>
                                        </tr>
                                        {*/if*}
                                        {/if}
                                        {/foreach}
                                        <tr class="success">
                                            <td>الإجمالي</td>
                                            <td>{abs($totalPrice)} {$currency}</td>
                                            <td></td>
                                        </tr>
                                    </tbody>

                                </table>
                            </div>
                            <!--panel-body-->
                        </div>


                        <table width="200" border="1" align="center" class="table-black">
                            <tr>
                                <th> فرق اجمالى القطع :</th>
                                <th>{$selltotalQTY - $returntotalQTY} </th>
                            </tr>
                        </table>
                        <!--panel panel-default-->
                    </div><!--col-lg-4-->
                    <!--**********************************************************************-->
                    <div class="col-lg-4">
                        <div class="panel panel-default panel-m">
                            <!-- Default panel contents -->
                            <div class="panel-heading">فواتير مردودات المبيعات</div>
                            <div class="panel-body">
                                <table class="table table-black">
                                    <thead>
                                        <tr>
                                            <th>م</th>
                                            <!--                  <th>رقم الفاتورة</th>
                                            -->
                                            <th>تاريخ الفاتورة</th>
                                            <th>عدد الوحدات</th>
                                            <th>إجمالي الفاتورة</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        {foreach $returnsellbillData as $data}
                                        <tr {if $data->conditions eq 1}class="danger"{/if}>
                                            <td>{$data->returnsellbillid}</td>
                                            <!--                <td>{$data->returnsellbillserial}</td>
                                            -->
                                            <td>{$data->returnsellbilldate}</td>
                                            <td>{$data->returnsellQuantity}</td>
                                            <td>
                                                {if {$data->userid} eq -1}

                                                {$data->returnsellbillprice}
                                                {else}
                                                {$data->returnsellbillaftertotalbill}
                                                {/if}</td>
                                        </tr>
                                        {/foreach}

                                        <tr class="success">
                                            <td colspan="2">الإجمالي</td>
                                            <td>{$returntotalQTY} قطعة</td>
                                            <td>{$returntotalBills} {$currency}</td>

                                        </tr>
                                    </tbody>

                                </table>
                            </div>
                        </div>
                        <!--panel-body-->
                    </div>
                    <!--panel panel-default-->
                </div><!--col-lg-4-->
                <div class="clearfix"></div>
                <hr />
                <div class="hidden-print">
                    <div class="col-lg-12 hidden-print">
                        <span><button type="button" onClick="print_Custom('mycustomheader');"
                                class="btn btn-success pull-right">طباعة</button></span>
                        <span><button class="btn btn-success pull-right excelFile" data-tblId="tableWrap"
                                data-path="">ملف اكسل</button></span>
                        <span id="ExcelStatus"></span>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>


{literal}
<script type="text/javascript">
    jQuery(document).ready(function () {

        $(".select2Supp").select2({
            placeholder: "العميل",
            minimumInputLength: 2,//document.getElementById("clientsearchvalue").value,
            inimumInputLength: 0,
            multiple: false,
            quietMillis: 100,
            formatInputTooShort: function (input, min) {
                var n = min - input.length;
                $lenMsg = '<ul class="select2-results">';
                // if (supplierWithAddOption == 1)
                // $lenMsg += '<li class="select2-results-dept-0 select2-result select2-result-selectable" onclick="newOptionAtInputTooShort();"><div class="select2-result-label newoption"><span class="newoption">اضافة عميل جديد</span></div></li>';
                $lenMsg += '</ul><div class="select2-result-label"><span>من فضلك أدخل ' + n + ' حروف أكثر</span></div>';
                // Append it to the select
                return $lenMsg;
            },
            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: 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], mobile: item[6] };
                callback(data);
            },
            //dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
        }).on('select2-loaded', function (e) {// not "select2-open" nor "select2-opening" //http://mkurz.github.io/select2/index.html
            $('.newoption').parent().addClass('newoption');
        }).on("select2-selecting", function (e) {
            // the class to make diffrence of change from select2 itself "choose another option" ,it wont exist for triggering change
            $('#clientid').addClass('selectingClass');
        })
        //this is needed for ajax =>to obtain id from it  and use in ajax
        $('#clientid').select2('data', { id: $('#oldclientid').val(), text: $('#oldclientname').val() });
        setTimeout(function () {
            //this is needed as we need html to end drawing then put value => without it text will be undefined
            $('#clientid').select2('data', { id: $('#oldclientid').val(), text: $('#oldclientname').val() });
        }, 0)
    });
</script>
{/literal}