<style type="text/css">
    @media print {

        #div1,
        #div2,
        #div3 {
            width: 33% !important;
            float: left !important;
        }

        #div1 {
            text-align: left !important;
        }

        #div2 {
            text-align: center !important;
        }

        #div1 {
            text-align: right !important;
        }

        thead {
            font-size: 10px !important;
            background-color: #ccc !important;
        }

        thead tr {
            font-size: 10px !important;
            background-color: #ccc !important;
        }

        tbody {
            font-size: 10px !important;
        }

        .well {
            width: 154px !important;

        }

        .well h4 {
            width: 154px !important;
            padding: 3px !important;
            margin: 3px !important;
            font-size: 13px !important;
        }

    }
</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">
                {if $message != ""}
                {$message}
                {else}
                تقرير العملاء<br />
                {/if}
                <a href="{$youtubes[266]->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=show" method="post">
                    <div class="form-group">
                        <label class="sr-only">العميل</label>
                        <input type="hidden" id="clientid" name="clientid" class="wdt100 select2-offscreen"
                               data-placeholder="اختر عميل " tabindex="-1" style="display: inline-block;" value="1" />
                    </div>

                    <div class="form-group">
                        <label class="sr-only"> الترتيب بـ</label>
                        <select class="select2 wdt100" name="order" id="order">
                            <option value="0">id تنازلي </option>
                            <option value="1"> id تصاعدي</option>
                            <option value="2">التاريخ تنازلي </option>
                            <option value="3"> التاريخ تصاعدي</option>
                        </select>
                    </div>


                    <div class="form-group">
                        <label class="sr-only">رصيد صافي</label>
                        <input name="bure" type="checkbox" id="bure" value="1" />
                        <label for="bure"></label>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">عرض المطابقات فقط</label>
                        <input name="matchOnly" type="checkbox" id="matchOnly" value="1" />
                        <label for="matchOnly"></label>
                    </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>
                    <div class="form-group">
                        <label class="sr-only">تقرير مختصر</label>
                        <input type="checkbox" class="form-control" id="summaryreport" value="1">
                    </div>


                    <!--                    <div class="form-group" style="padding-right: 20px;">
                                            <label class="sr-only">تاريخ البحث</label><br>
                                            <label>  <input value="sysDate" name="searchDate" type="radio" checked>
                                                تاريخ السيستم</label>
                                            <label>  <input value="userSelectedDate" name="searchDate" type="radio" >
                                                تاريخ المستخدم</label>
                                        </div>-->
                    <button type="submit" class="btn btn-primary">بحث</button>

                </form>
            </div>
            <hr />

            <!--            <div class=" container  visible-print" style="width: 100% !important;">
                            <div id="div1">
                                <br>
                                {$programsettingsdata->companyname}
                            </div>
                            <div id="div2">
                                <img src="{$path}/images/upload/{$programsettingsdata->logo}" width="80px" height="80px">
                            </div>

                            <div id="div3">
                                <br>
                                {$programsettingsdata->phone}
                            </div>
                        </div>-->
            <div class="col-lg-offset-8 col-lg-4 hidden-print">
                <div class="well well-sm">
                    <h4 class="text-center"> مديونية العميل {$clientDebt}</h4>
                </div>
            </div>
            <table class="table billtable table-bordered table-black summaryreporthide">
                <thead>
                    <tr>
                        <th>وصف العمليه</th>
                        <th>تاريخ العملية</th>
                        <th>اسم العميل</th>

                        <th>إجمالي مبلغ العملية</th>
                        <th>المدفوع</th>
                        {*if $burex <> 1*}
                        <th>المديونيه قبل</th>
                        {*/if*}
                        <!--<th><table   class="table" border="1" width="100%"  style="text-align:center" >
                    <tr ><td colspan="2" > متغير المديونية</td></tr>
                       <tr><td>اضافه</td><td>خصم</td></tr>

                    </table>  </th>-->
                        <th>متغير المديونية
                            <table class="table billtable table-bordered">
                                <tr>
                                    <td style="color:black!important;" class="color-black"> إضافة</td>
                                    <td style="color:black!important;" class="color-black"> خصم</td>
                                </tr>
                            </table>
                        </th>
                        {*if $burex <> 1*}
                        <th>المديونيه بعد</th>
                        {*/if*}
                    </tr>
                </thead>
                <tbody>
                    {assign var=j value=0}
                    {assign var=k value=0}
                    {foreach $shownData as $data}

                    {if {$data->clientdebtchangeid} > 0}


                    {if $data->clientdebtchangetype eq 1}
                    {capture assign=j}{$j+{$data->clientdebtchangeamount}}{/capture}
                    {else}
                    {capture assign=k}{$k+{$data->clientdebtchangeamount}}{/capture}
                    {/if}

                    {if $data->tablename == "customerqccountmatching"}
                    <tr class="success">
                        {elseif {$data->clientdebtchangetype} eq 1}
                    <tr class="danger">
                        {elseif {$data->clientdebtchangetype} eq 0}
                    <tr>
                        {/if}

                        <td>

                            {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>
                            {if $searchDate == "sysDate"}
                            {$data->clientdebtchangedate}
                            {else if $searchDate == "userSelectedDate"}
                            {$data->userSelectedDate}
                            {/if}
                        </td>
                        <td>{$data->clientname}</td>


                        {if $data->tablename eq "rb_kashf.php" || $data->tablename eq "sellbillandruternController.php"
                        || $data->tablename eq "sellbillController.php" || $data->tablename eq
                        "returnsellbillController.php" }


                        <td>
                            {if $data->totalOperationCost|strpos:'.' eq true}
                            {$data->totalOperationCost|rtrim:'0'|rtrim:'.'}<br />
                            {else}
                            {$data->totalOperationCost}
                            {/if}
                        </td>

                        <td>
                            {if $data->totalOperationCost eq 0}
                            0
                            {else}
                            {if $data->tablename eq "sellbillController.php"}
                            {{abs($data->totalOperationCost)} - {$data->clientdebtchangeamount}}
                            {else}
                            {{abs($data->totalOperationCost)} - {abs($data->clientdebtchangeamount)}}
                            {/if}
                            <!-- old one -->
                            {*{$data->totalOperationCost} - {$data->clientdebtchangeamount}*}
                            {/if}


                        </td>


                        {*if $burex <> 1*}
                        <td>
                            {if $data->clientdebtchangebefore|strpos:'.' eq true}
                            {$data->clientdebtchangebefore|rtrim:'0'|rtrim:'.'}
                            {else}
                            {$data->clientdebtchangebefore}
                            {/if}
                        </td>
                        {*/if*}
                        <td>
                            <div {if {$data->clientdebtchangetype} eq 1} style="float:left; margin: 10px 10px 10px
                                10px;" {else} style="float:right; margin: 10px 10px 10px 10px;" {/if} >
                                {if $data->clientdebtchangeamount|strpos:'.' eq true}
                                {$data->clientdebtchangeamount|rtrim:'0'|rtrim:'.'}<br />
                                {else}
                                {$data->clientdebtchangeamount}
                                {/if}
                            </div>
                        </td>

                        {else}



                        <td>
                            {if $data->totalOperationCost|strpos:'.' eq true}
                            {$data->totalOperationCost|rtrim:'0'|rtrim:'.'}
                            {else}
                            {$data->totalOperationCost}
                            {/if}
                        </td>
                        <td>
                            {if $data->totalOperationCost eq 0}
                            0
                            {else}


                            {if $data->tablename eq "clientPayedDeptSellBillsController.php" || $data->tablename eq
                            "clientPayedDeptReturnSellBillsController.php" }
                            {$data->clientdebtchangeamount}
                            {else}
                            {{$data->totalOperationCost} - {$data->clientdebtchangeamount}}
                            {/if}



                            {/if}


                        </td>


                        {*if $burex <> 1*}
                        <td>
                            {if $data->clientdebtchangebefore|strpos:'.' eq true}
                            {$data->clientdebtchangebefore|rtrim:'0'|rtrim:'.'}
                            {else}
                            {$data->clientdebtchangebefore}
                            {/if}
                        </td>
                        {*/if*}



                        <td>

                            <div {if {$data->clientdebtchangetype} eq 1}
                                style="float:left; margin: 10px 10px 10px 10px;"
                                {else}
                                style="float:right; margin: 10px 10px 10px 10px;"
                                {/if}
                                >
                                {if $data->clientdebtchangeamount|strpos:'.' eq true}
                                {$data->clientdebtchangeamount|rtrim:'0'|rtrim:'.'}
                                {else}
                                {$data->clientdebtchangeamount}
                                {/if}
                            </div>

                        </td>
                        {/if}
                        {*if $burex <> 1*}
                        <td>
                            {if $data->clientdebtchangeafter|strpos:'.' eq true}
                            {$data->clientdebtchangeafter|rtrim:'0'|rtrim:'.'}
                            {else}
                            {$data->clientdebtchangeafter}
                            {/if}
                        </td>
                        {*/if*}
                    </tr>


                    {/if}
                    {/foreach}
                    <!--<tr>
                   {if $burex <> 1}
                     <td></td>
                  <td></td>
                     <td></td>
                  <td></td>
                  <td></td>
                  {else}
                     <td></td>
                       <td></td>
                     <td></td>
                  <td></td>
                  {/if}
                  <td> <table border="1" width="100%"  style="text-align:center" >
                         <tr><td width="50%">  {$k}</td><td width="50%">{$j}</td></tr>

                      </table>
                    </td>


                  </tr>-->
                </tbody>

            </table>

            <table class="table billtable table-bordered table-black summaryreportshow" style="display:none">
                <thead>
                    <tr>
                        <th>التاريخ</th>
                        <th>التفاصيل</th>
                        {if $clientid < 1} <th> العميل</th>
                        {/if}
                        <th>دائن
                        </th>
                        <th>مدين
                        </th>
                        <th>الرصيد
                        </th>
                    </tr>
                </thead>
                <tbody>
                    {assign var=j value=0}
                    {assign var=k value=0}
                    {foreach $shownData as $data}

                    {if {$data->clientdebtchangeid} > 0}


                    {if $data->clientdebtchangetype eq 1}
                    {capture assign=j}{$j+{$data->clientdebtchangeamount}}{/capture}
                    {else}
                    {capture assign=k}{$k+{$data->clientdebtchangeamount}}{/capture}
                    {/if}


                    {if {$data->clientdebtchangetype} eq 1}
                    <tr class="danger"> {elseif {$data->clientdebtchangetype} eq 0}
                    <tr>
                        {/if}
                        <td>
                            {if $searchDate == "sysDate"}
                            {$data->clientdebtchangedate|date_format:'%Y-%m-%d'}
                            {else if $searchDate == "userSelectedDate"}
                            {$data->userSelectedDate|date_format:'%Y-%m-%d'}
                            {/if}


                        </td>

                        <td>

                            {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->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>
                        {if $clientid < 1} <td>{$data->clientname}</td>
                        {/if}






                        {if {$data->clientdebtchangetype} eq 1}
                        <td>

                            {$data->clientdebtchangeamount}
                        </td>
                        <td>
                        </td>
                        {else}
                        <td>
                        </td>
                        <td>

                            {$data->clientdebtchangeamount}

                        </td>
                        {/if}
                        <td>{$data->clientdebtchangeafter}</td>
                    </tr>


                    {/if}
                    {/foreach}
                    <!--<tr>
                   {if $burex <> 1}
                     <td></td>
                  <td></td>
                     <td></td>
                  <td></td>
                  <td></td>
                  {else}
                     <td></td>
                       <td></td>
                     <td></td>
                  <td></td>
                  {/if}
                  <td> <table border="1" width="100%"  style="text-align:center" >
                         <tr><td width="50%">  {$k}</td><td width="50%">{$j}</td></tr>

                      </table>
                    </td>


                  </tr>-->
                </tbody>

            </table>
            <div class="col-lg-offset-8 col-lg-4">
                <div class="well well-sm">
                    {if {$k} eq 0}
                    <h4 class="text-center"> اجمالى المبلغ {$total}</h4>
                    {else}

                    <h4 class="text-center"> اجمالى المبلغ {$total}</h4>
                    {/if}
                </div>
            </div>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />
            <div class="hidden-print">
                <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">طباعة</button>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{literal}
<script>
    $(document).ready(function () {

        $('#summaryreport').click(function () {
            var summaryreport = $('#summaryreport').prop("checked") ? 1 : 0;
            if (summaryreport == 1) {
                $(".summaryreportshow").show();
                $(".summaryreporthide").hide();
            } else {
                $(".summaryreporthide").show();
                $(".summaryreportshow").hide();
            }

        });




        var searchvalue = $('#searchvalue').val();

        $("#clientid").select2({
            placeholder: "اختر عميل ",
            minimumInputLength: 0,
            //  minimumInputLength: 3,
            multiple: false,
            quietMillis: 100,
            //width: '120%',
            ajax: {
                url: "billsajax.php?do=getclients&noadd=1",
                dataType: 'json',
                data: function (term, page) {
                    //  alert(term);
                    return {
                        term: term, //search term
                        page_limit: 10, // page size
                    };
                },
                results: function (data) {

                    // alert(term);
                    return {results: data};
                }
            },
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });
        $("#clientid").select2("data", {id: "-1", text: "اختر عميل"});
    });

</script>
{/literal}