<style>
    .myresult {
        -webkit-print-color-adjust: exact;
    }
</style>

<style>

    .mytd a {
        cursor: pointer;
        color: blue;
    }

    @media print {
        table, tbody, thead, th, tr, td {
            font-size: 12px !important;
        }
        .mytd {
            max-width:20px; !important
        }
        a::after {
            display: none; /* Hide the anchor tag */
        }

    }
</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[126]->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="clientbuysController.php" method="post">


                    <div class="form-group col-md-3">
                        <label class="sr-only">العميل</label>
                        <input type="hidden" name="client" id="client" class="select2client wdth300"/>
                    </div>
                    <div class="form-group">
                        <label class="sr-only"  style="display: block">عرض </label>
                        <div class="radio-inline">
                            <label>
                                <input value="0" class="radioR" name="showWhat" type="radio" checked>
                                التحصيلات فقط </label>
                        </div>
                        <div class="radio-inline">
                            <label>
                                <input value="1" class="radioR" name="showWhat" type="radio">
                                كل حركات العميل </label>
                        </div>

                    </div>

                    <br/>
                    <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>
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>
            </div>
            <div class="panel panel-default panel-m">
                <!-- Default panel contents -->
                <div class="panel-heading">{$message}</div>
                <div class="panel-body">
                    <hr/>
                    <table style="width:100% !important;" class="table table-black" border="1">
                        <thead>

                            <!--=================================================-->

                            <tr>
                                <!-- </div>
                                     <div class="col-lg-offset-8 col-lg-4">
                                   <div class="well well-sm">
                                     <h4 class="text-center">  اجمالى راس المال {$totalcapitalmoney} {$currency}</h4>
                                   </div>
                                 </div>-->
                            </tr>
                            <tr class="active">
                                <th colspan="4" style="text-align: center">
                                    تقرير مشتريات عميل
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td colspan="2">
                                    <table style="width:100% !important;vertical-align:top;"  class="table-black" >
                                        <tr>
                                            <td colspan="3"> <span style="text-decoration: underline; font-weight:bold;">مشتريات</span></td>
                                        </tr>


                                        <tr>
                                            <td >رقم الفاتورة</td>
                                            <td >التاريخ</td>
                                            <td >قيمة الفاتورة</td>
                                        </tr>
                                        {assign var=sumBuy value=0}
                                        {foreach $buyBillData as $data}
                                        <tr>
                                            <td class="mytd"><a target="_blank" href="buyBillController.php?do=details&id={$data['buybillid']}">{$data['buybillid']}</a></td>
                                            <td >{$data['buybilldate']}</td>
                                            <td >{$data['buybillaftertotalbill']}</td>
                                        </tr>
                                        {assign var=sumBuy value=$sumBuy+$data['buybillaftertotalbill']}
                                        {/foreach}
                                        <td colspan="2"><div ><span >{$sumBuy} </span></div></td>
                                        <td > <span style="font-weight:bold;"> اجمالى المشتريات  </span></td>




                                        <tr>
                                            <td colspan="3"> <span style="text-decoration: underline; font-weight:bold;">مردود مشتريات</span></td>
                                        </tr>

                                        <tr>
                                            <td >رقم الفاتورة</td>
                                            <td >التاريخ</td>
                                            <td >قيمة الفاتورة</td>
                                        </tr>
                                        {assign var=sumRetBuy value=0}
                                        {foreach $retBuyBillData as $data}
                                        <tr>
                                            <td class="mytd"><a target="_blank" href="returnBuyBillController.php?do=details&id={$data['returnbuybillid']}">{$data['returnbuybillid']}</a></td>
                                            <td >{$data['returnbuybilldate']}</td>
                                            <td >{$data['returnbuybillaftertotalbill']}</td>
                                        </tr>
                                        {assign var=sumRetBuy value=$sumRetBuy+$data['returnbuybillaftertotalbill']}
                                        {/foreach}

                                        <td colspan="2"><div ><span >  {$sumRetBuy} </span></div></td>
                                        <td > <span style="font-weight:bold;"> اجمالى مردود المشتريات  </span></td>

                            </tr>
                    </table>
                    </td>
                    <td colspan="2" style="vertical-align:top;">
                        {if $showWhat == 0}
                        <table  style="width:100% !important; " class="table-black" >
                            <tr>
                                <td colspan="5"> <span style="text-decoration: underline; font-weight:bold;"> التحصيلات </span></td>
                            </tr>

                            <tr>
                                <td>رقم الايصال</td>
                                <td >التاريخ</td>
                                <td >الدين قبل</td>
                                <td >الدفعه</td>
                                <td >الدين بعد</td>
                            </tr>
                            {assign var=sumPayments value=0}
                            {foreach $paymentData as $data}
                            <tr>
                                <td  class="mytd"><a target="_balnk" href="clientPayedDeptController.php?do=show&id={$data['clientdebtchangeid']}">{$data['clientdebtchangeid']}</a></td>
                                <td >{$data['clientdebtchangedate']}</td>
                                <td >{$data['clientdebtchangebefore']}</td>
                                <td >{$data['clientdebtchangeamount']}</td>
                                <td >{$data['clientdebtchangeafter']}</td>
                            </tr>

                            {if $data['clientdebtchangetype'] == 0}
                            {assign var=sumPayments value=$sumPayments+$data['clientdebtchangeamount']}
                            {else if $data['clientdebtchangetype'] == 1}
                            {assign var=sumPayments value=$sumPayments-$data['clientdebtchangeamount']}
                            {/if}
                            {/foreach}
                            <tr>
                                <td colspan="4"><div ><span>  {$sumPayments} </span></div></td>
                                <td > <span style="font-weight:bold;">  اجمالى التحصيلات </span></td>
                            </tr>
                        </table>
                        {/if}
                        {if $showWhat == 1}
                        <table  style="width:100% !important; " class="table-black" >
                            <tr>
                                <td colspan="5"> <span style="text-decoration: underline; font-weight:bold;"> تقرير عميل </span></td>
                            </tr>

                            <tr>
                                <td>وصف العمليه</td>
                                <td>تاريخ العملية</td>
                                <td >الدين قبل</td>
                                <td >القيمه</td>
                                <td >الدين بعد</td>
                            </tr>
                            {assign var=sumPayments value=0}
                            {foreach $clientDebtChangeData as $data}
                            <tr>
                                <td  class="mytd">
                                    {if $data['tablename'] eq "rb_kashf.php" || $data['tablename'] eq
                                    "sellbillandruternController.php" || $data['tablename'] eq "sellbillController.php" ||
                                    $data['tablename'] eq "bills.php" || $data['tablename'] eq "billsreturn.php" || $data['tablename']
                                    eq "returnsellbillController.php" || $data['tablename'] eq "clientPayedDeptController.php"}
                                    ( {$data['clientdebtchangemodelid']})
                                    {/if}

                                    <a class=" hidden-print" href="{$data['link']}">{$data['processname']}
                                        {if $data['processname'] == "ايداع شيك"}({$data['bankname']})/({$data['accountname']}){/if}
                                        {if $data['processname'] == "التحويل من حساب عميل إلى عميل
                                        آخر"}({$data['suppliername']}){/if}






                                        {if $data['clientdebtchangetype'] eq 1 && $data['tablename'] eq "datedCheckedController.php"
                                        && $data['datedCheckeddone'] eq 1 }
                                        شيك محصل

                                        {elseif $data['datedCheckeddone'] eq 3 && $data['tablename'] eq
                                        "datedCheckedController.php"}
                                        تم تظهير الشيك ({$data['suppliername']})
                                        {elseif $data['clientdebtchangetype'] eq 1 && $data['tablename'] eq
                                        "datedCheckedController.php"}

                                        شيك غير محصل

                                        {/if}

                                    </a>
                                    <div class="visible-print">
                                        {$data['processname']}
                                    </div>
                                </td>
                                <td >{$data['clientdebtchangedate']}</td>
                                <td >{$data['clientdebtchangebefore']}</td>
                                <td >{$data['clientdebtchangeamount']}</td>
                                <td >{$data['clientdebtchangeafter']}</td>
                            </tr>
                            {assign var=sumPayments value=$sumPayments+$data['clientdebtchangeamount']}
                            {/foreach}
                            <!--                            <tr>
                                                            <td colspan="4"><div ><span>  {$sumPayments} </span></div></td>
                                                            <td > <span style="font-weight:bold;">  اجمالى التحصيلات </span></td>
                                                        </tr>-->
                        </table>
                        {/if}
                    </td>
                    </tr>

                    <!--                    <tr class="foot">
                                            <td colspan="2"  style="text-align:center !important" class="black-color">

                                                صافى الرصيد
                                            </td>
                                            <td colspan="2" style="text-align:center !important" class="black-color">

                                                {math equation=" y  - x " x={$changeAmountminse} y={$changeAmountSumpluse}}
                                            </td>

                                        </tr>-->
                    <!--<tr class="active">
                      <th>
                        <center>
                          مجموع
                        </center>
                      </th>
                      <th>{$forYou}</th>
                      <th>
                        <center>
                          مجموع
                        </center>
                      </th>
                      <th>{$forTox}</th>
                    </tr>-->

                    </tbody>
                    </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>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
        <input type="hidden" name="searchvalue" id="searchvalue" value="{$Programsettingdata->searchvalue}" />
        {literal}
        <script>
            $(function () {
                $(".select2client").select2({
                    placeholder: "العميل",
                    minimumInputLength: document.getElementById("searchvalue").value,
                    inimumInputLength: 0,
                    multiple: false,
                    quietMillis: 100,
                    width: '100%',
                    formatInputTooShort: function (input, min) {
                        var n = min - input.length;
                        $lenMsg = '<ul class="select2-results">';
                        $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, //supplierWithAddOption,
                                withNakdi: 0, //withNakdi,
                                //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
                });

            });
        </script>
        {/literal}