<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 ">
                <div class=" hidden-print">كشف حساب عميل مفصل</div>
                {if $message != ""}
                {$message}
                {/if}
                <a href="{$youtubes[129]->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="clientReportsnewController.php?do=clientShowDetail"
                    method="post">
                    <div class="form-group">
                        <label class="sr-only">العميل</label>
                        <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>




                    <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 rowspan="2">م</th>
                        <th rowspan="2">التاريخ</th>
                        {if !$clientid}
                        <th rowspan="2">اسم العميل</th>
                        {/if}
                        <th rowspan="2">اسم العملية</th>
                        <th rowspan="2">رقم الفاتوره</th>
                        <th colspan="6">البيان</th>
                        <th rowspan="2">الدين قبل</th>
                        <th rowspan="2">اجمالي العملية</th>
                        <th colspan="2">القيمة المتغيرة

                        </th>
                        <th rowspan="2">الدين بعد </th>
                        <th rowspan="2" class="hidden-print">التفاصيل </th>
                    </tr>
                    <tr>
                        <th>الصنف</th>
                        <th>الكمية</th>
                        <th>السعر</th>
                        <th>الاجمالي</th>
                        <th>الخصم</th>
                        <th>الصافي</th>
                        <th> اضافة</th>
                        <th> خصم</th>
                    </tr>
                </thead>
                <tbody>
                    {foreach $shownData as $data}
                    {if {$data->clientdebtchangeid} > 0}   
                        {assign var="rowspan" value=2}
                        {assign var="products" value=0}
                        {if $data->tablename == "sellbillController.php"}
                            {assign var="products" value=count($productsArr[$data->clientdebtchangemodelid])}
                        {else if $data->tablename == "returnsellbillController.php"}
                            {assign var="products" value=count($productsReArr[$data->clientdebtchangemodelid])}
                        {elseif $data->tablename == "sellbillandruternController.php"}
                            {assign var="products" value=count($productssellAndReArr[$data->clientdebtchangemodelid])}
                        {/if}
                        {assign var="rowspan" value=$products+1}
                    <tr {if $data->clientdebtchangetype eq 0} class="danger" {else} {/if}>
                        <td rowspan="{$rowspan}">{$data@iteration}</td>
                        <td rowspan="{$rowspan}">{$data->clientdebtchangedate}</td>
                        {if !$clientid}
                        <td rowspan="{$rowspan}">{$data->clientname}</td>
                        {/if}
                        <td rowspan="{$rowspan}">{$data->processname}</td>
                        <td rowspan="{$rowspan}">{if $data->tablename eq "sellbillController.php" || $data->tablename eq
                            "returnsellbillController.php" || $data->tablename eq "sellbillandruternController.php"}
                            <a class="hidden-print" href="{$data->link}" target="_blank"
                                style="color: blue;"><u>{$data->clientdebtchangemodelid}</u></a>
                            {else} -
                            {/if}
                        </td>
                        <td colspan="6">
                            
                        </td>
                        <td rowspan="{$rowspan}">{$data->clientdebtchangebefore}</td>
                        <td rowspan="{$rowspan}">
                            {if $data->tablename eq "sellbillandruternController.php" ||  $data->tablename eq "sellbillController.php"  ||  $data->tablename eq "returnsellbillController.php" }
                            {$data->payedamount}
                            {else}
                            {$data->clientdebtchangeamount}
                            {/if}
                        </td>
                        {if {$data->clientdebtchangetype} eq 1}
                        <td rowspan="{$rowspan}"></td>
                        <td rowspan="{$rowspan}">{$data->clientdebtchangeamount}</td>
                        {else}
                        <td rowspan="{$rowspan}">{$data->clientdebtchangeamount}</td>
                        <td rowspan="{$rowspan}"></td>
                        {/if}
                        <td rowspan="{$rowspan}">{$data->clientdebtchangeafter}</td>
                        <td rowspan="{$rowspan}">
                            {if $data->link != "#" && $data->link != ""}
                            <a class="hidden-print" href="{$data->link}" target="_blank"
                                style="color: blue;"><u>التفاصيل</u></a>
                            {else}
                            -
                            {/if}
                        </td>
                    </tr>
                    {if $data->tablename == "sellbillController.php"}
                        {foreach $productsArr[$data->clientdebtchangemodelid] as $prod}
                            {if $prod@first}
                                <tr>
                                    <td>{$prod->productName}</td>
                                    <td>{$prod->sellbilldetailquantity*$prod->productnumber}</td>
                                    <td>{$prod->sellbilldetailprice}</td>
                                    <td>{$prod->sellbilldetailtotalprice}</td>
                                    <td>{$prod->discountvalue}</td>
                                    <td>{$prod->discountvalue + $prod->sellbilldetailtotalprice}</td>
                                </tr>
                            {else}
                                <tr>
                                    <td>{$prod->productName}</td>
                                    <td>{$prod->sellbilldetailquantity*$prod->productnumber}</td>
                                    <td>{$prod->sellbilldetailprice}</td>
                                    <td>{$prod->sellbilldetailtotalprice}</td>
                                    <td>{$prod->discountvalue}</td>
                                    <td>{$prod->discountvalue + $prod->sellbilldetailtotalprice}</td>
                                </tr>
                            {/if}
                        {/foreach}
                    {elseif $data->tablename == "returnsellbillController.php"}
                        {foreach $productsReArr[$data->clientdebtchangemodelid] as $prod}
                            {if $prod@first}
                                <tr>
                                    <td>{$prod->productName}</td>
                                    <td>{$prod->returnsellbilldetailquantity*$prod->productnumber}</td>
                                    <td>{$prod->returnsellbilldetailprice}</td>
                                    <td>{$prod->returnsellbilldetailtotalprice}</td>
                                    <td>{$prod->discountvalue}</td>
                                    <td>{$prod->discountvalue + $prod->returnsellbilldetailtotalprice}</td>
                                </tr>
                            {else}
                                <tr>
                                    <td>{$prod->productName}</td>
                                    <td>{$prod->returnsellbilldetailquantity*$prod->productnumber}</td>
                                    <td>{$prod->returnsellbilldetailprice}</td>
                                    <td>{$prod->returnsellbilldetailtotalprice}</td>
                                    <td>{$prod->discountvalue}</td>
                                    <td>{$prod->discountvalue + $prod->returnsellbilldetailtotalprice}</td>
                                </tr>
                            {/if}
                        {/foreach}
                    {elseif $data->tablename == "sellbillandruternController.php"}
                        {foreach $productssellAndReArr[$data->clientdebtchangemodelid] as $prod}
                                {if $prod@first}
                                    <tr>
                                        <td>{$prod->productName}</td>
                                        <td>{$prod->sellbilldetailquantity*$prod->productnumber}</td>
                                        <td>{$prod->sellbilldetailprice}</td>
                                        <td>{$prod->sellbilldetailtotalprice}</td>
                                        <td>{$prod->discountvalue}</td>
                                        <td>{$prod->discountvalue + $prod->sellbilldetailtotalprice}</td>
                                    </tr>
                                {else}
                                    <tr>
                                        <td>{$prod->productName}</td>
                                        <td>{$prod->sellbilldetailquantity*$prod->productnumber}</td>
                                        <td>{$prod->sellbilldetailprice}</td>
                                        <td>{$prod->sellbilldetailtotalprice}</td>
                                        <td>{$prod->discountvalue}</td>
                                        <td>{$prod->discountvalue + $prod->sellbilldetailtotalprice}</td>
                                    </tr>
                                {/if}
                            {/foreach}
                        {else}
                        {if $rowspan > 1}
                        <tr>
                            <td colspan="6"></td>
                        </tr>
                        {/if}
                    {/if}
                    {/if}

                    {/foreach}
                </tbody>
            </table>
            <hr />
            {if {count($shownData)} > 0}
            <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>
            {/if}
            <div class="clearfix"></div>
        </div>
    </div>
</div>