
<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}</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>
                        <input name="bure" type="checkbox" id="bure"  value="1" />
                        <label for="bure"></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>
                    <button type="submit" class="btn btn-primary">بحث</button>
                </form>
            </div>
            <hr/>
            <table class="table billtable table-bordered table-black">
                <thead>
                    <tr>
                        <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 0}
                    {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  $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}</a>
                            <div class="visible-print">
                                {$data->processname}
                            </div>

                        </td>
                        <td>{$data->clientdebtchangedate}</td>


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


                        <td>{$data->totalOperationCost}</td>

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


                        </td>


                        {if $burex <> 1}
                        <td>{$data->clientdebtchangebefore}</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} >
                                {$data->clientdebtchangeamount}
                            </div>
                        </td>

                        {else}



                        <td>{$data->totalOperationCost}</td>
                        <td>
                            {if $data->totalOperationCost eq 0}
                            0
                            {else}
                            {{$data->totalOperationCost} - {$data->clientdebtchangeamount}}
                            {/if}


                        </td>


                        {if $burex <> 1}
                        <td>
                            {$data->clientdebtchangebefore}
                        </td>
                        {/if}



                        <td>

                            <div {if {$data->clientdebtchangetype} eq 1} style="float:left;  margin: 10px 10px 10px 10px;"  {else}

                                {if $data->tablename neq "clientController.php" }
                                style="float:left !important; margin: 10px 10px 10px 10px;"
                                {else}
                                style="float:right; margin: 10px 10px 10px 10px;"
                                {/if}
                                {/if}
                                >


                                {$data->clientdebtchangeamount}

                            </div>

                        </td>
                        {/if}
                        {if $burex <> 1}      	 <td>{$data->clientdebtchangeafter}</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%">  {$j}</td><td width="50%">{$k}</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 () {

        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}