
<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[163]->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="reportClientAndSupplier.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 data-placeholder="اختر مورد" class="select2 wdt300" name="supplierid" id="supplierid">
                            <option value="-1"> اختر مورد</option>
                            <option value="-2"> كل الموردين</option>
                            {foreach $supplierData as $supplier}
                            <option value="{$supplier->supplierid}">{$supplier->suppliername}</option>
                            {/foreach}
                        </select>
                    </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">التاريخ</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>
                    <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/>
            
             <div  class="col-sm-6" style="width: 50%;float: left;">
                <h2>عميل</h2>
            <table class="table billtable table-bordered table-black">
                <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->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>
                        <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>{$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}
                                style="float:right; margin: 10px 10px 10px 10px;"
                                {/if}
                                >
                                {$data->clientdebtchangeamount}
                            </div>

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


                    {/if}
                    {/foreach}
                    
                </tbody>

            </table>


            <div class="col-lg-offset-8 col-lg-4">
                <div class="well well-sm">
                    <h4 class="text-center"> اجمالى المبلغ    {$total}</h4>
                </div>
            </div>
        </div>
         <div  class="col-sm-6" style="width: 50%;float: left;">
                            <h2>مورد</h2>

                <table class="table billtable table-bordered table-black">
                    <thead>
                        <tr>
                            <th><strong>م</strong></th>
                            <th><strong>التاريخ</strong></th>
                            <th><strong>الاسم</strong></th>
                            {if $burex <> 1}      <th><strong>الدين  قبل </strong></th>{/if}
                            <th><strong>اجمالي العملية</strong></th>
                            <th>القيمة المتغيرة
                    <table class="table table-black billtable table-bordered">
                        <tr>
                            <td style="color:#000"> اضافة</td><!-- وارد-->
                            <td style="color:#000"> خصم</td><!-- صادر-->
                        </tr>
                    </table>
                    </th>
                    {if $burex <> 1}        <th><strong>الدين بعد</strong></th>{/if}
                    <th><strong>العملية </strong></th>
                    </tr>
                    </thead>
                    <tbody>
                        {assign var=j value=0}
                        {assign var=k value=0}
                        {foreach $shownData2 as $data}
                        {if $data->supplierdebtchangeid > 0}

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

                        <tr {if $data->supplierdebtchangetype eq 0} class="danger" {else}   {/if}>
                            <td>{$data@index+1}</td>
                            <td >{$data->supplierdebtchangedate}</td>
                            <td >{$data->suppliername}</td>
                            {if $burex <> 1}     <td >{$data->supplierdebtchangebefore}</td>{/if}
                            <td >{$data->totalbillvalue}</td>
                            <!--td >{$data->buybillpaid}</td-->
                            <td><div {if {$data->supplierdebtchangetype} eq 1} style="float:left;  margin: 10px 10px 10px 10px;"  {else} style="float:right; margin: 10px 10px 10px 10px;"  {/if} >
                                    {$data->supplierdebtchangeamount}
                                </div></td>
                            
                            {if $burex <> 1}       <td >{$data->supplierdebtchangeafter}</td>{/if}
                            <td >
                                <a class=" hidden-print"{if $data->link == ""} href="#" {else} href="{$data->link}" {/if}>{$data->processname}{if $data->processname == "دفع شيك"}({$data->bankname})/({$data->accountname}){/if}</a>
                                <div class="visible-print">{$data->processname}</div>
                            </td>
                        </tr>

                        {/if}
                        {/foreach}
                     
                    </tbody>

                </table>
                <div class="col-lg-offset-8 col-lg-4">
                    <div class="well well-sm">
                        <h4 class="text-center"> اجمالى المبلغ  {$k-$j} </h4>
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
            <div class="col-lg-offset-4 col-lg-4">
                    <div class="well well-sm">
                        {if $total >= 0}
                            {if {$k-$j} <= 0}
                                <h4 class="text-center">  عليه   {abs($k-$j) + {$total}} </h4>
                            {else}
                                <h4 class="text-center">  ليه   {{$k-$j} - {$total}} </h4>
                            {/if}
                        {else}
                            {if {$k-$j} >= 0}
                                <h4 class="text-center">  ليه   {{$k-$j} + {abs($total)}} </h4>
                            {else}
                                <h4 class="text-center">  عليه   {{$k-$j} - {$total}} </h4>
                            {/if}
                        {/if}
                    </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}