<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[128]->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="supplierReportsnewController.php?do=supplierShowDetail"
                    method="post">
                    <div class="form-group">
                        <label class="sr-only">المورد</label>
                        <select class="select2 wdt300" name="supplierId" id="supplierId">
                            <option value="-1">اختر المورد</option>


                            {foreach $supplierData as $mysupplierData}


                            <option value="{$mysupplierData->supplierid}">{$mysupplierData->suppliername}</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 !$supplierId}
                        <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->supplierdebtchangeid} > 0}   
                        {assign var="rowspan" value=2}
                        {assign var="products" value=0}
                        {if $data->tablename == "buyBillController.php"}
                            {assign var="products" value=count($productsArr[$data->supplierdebtchangemodelid])}
                        {else if $data->tablename == "returnBuyBillController.php"}
                            {assign var="products" value=count($productsReArr[$data->supplierdebtchangemodelid])}
                        {elseif $data->tablename == "buyAndReturnBillController.php"}
                            {assign var="products" value=count($productsBuyAndReArr[$data->supplierdebtchangemodelid])}
                        {/if}
                        {assign var="rowspan" value=$products+1}
                    <tr {if $data->supplierdebtchangetype eq 0} class="danger" {else} {/if}>
                        <td rowspan="{$rowspan}">{$data@iteration}</td>
                        <td rowspan="{$rowspan}">{$data->supplierdebtchangedate}</td>
                        {if !$supplierId}
                        <td rowspan="{$rowspan}">{$data->suppliername}</td>
                        {/if}
                        <td rowspan="{$rowspan}">{$data->processname}</td>
                        <td rowspan="{$rowspan}">{if $data->tablename eq "buyBillController.php" || $data->tablename eq
                            "returnBuyBillController.php" || $data->tablename eq "buyAndReturnBillController.php"}
                            <a class="hidden-print" href="{$data->link}" target="_blank"
                                style="color: blue;"><u>{$data->supplierdebtchangemodelid}</u></a>
                            {else} -
                            {/if}
                        </td>
                        <td colspan="6">
                            
                        </td>
                        <td rowspan="{$rowspan}">{$data->supplierdebtchangebefore}</td>
                        <td rowspan="{$rowspan}">{$data->supplierdebtchangeamount}</td>
                        {if {$data->supplierdebtchangetype} eq 1}
                        <td rowspan="{$rowspan}"></td>
                        <td rowspan="{$rowspan}">{$data->supplierdebtchangeamount}</td>
                        {else}
                        <td rowspan="{$rowspan}">{$data->supplierdebtchangeamount}</td>
                        <td rowspan="{$rowspan}"></td>
                        {/if}
                        <td rowspan="{$rowspan}">{$data->supplierdebtchangeafter}</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 == "buyBillController.php"}
                        {foreach $productsArr[$data->supplierdebtchangemodelid] as $prod}
                            {if $prod@first}
                                <tr>
                                    <td>{$prod->productName}</td>
                                    <td>{$prod->buybilldetailquantity*$prod->productnumber}</td>
                                    <td>{$prod->buybilldetailprice}</td>
                                    <td>{$prod->buybilldetailtotalprice}</td>
                                    <td>{$prod->discountvalue}</td>
                                    <td>{$prod->discountvalue + $prod->buybilldetailtotalprice}</td>
                                </tr>
                            {else}
                                <tr>
                                    <td>{$prod->productName}</td>
                                    <td>{$prod->buybilldetailquantity*$prod->productnumber}</td>
                                    <td>{$prod->buybilldetailprice}</td>
                                    <td>{$prod->buybilldetailtotalprice}</td>
                                    <td>{$prod->discountvalue}</td>
                                    <td>{$prod->discountvalue + $prod->buybilldetailtotalprice}</td>
                                </tr>
                            {/if}
                        {/foreach}
                    {elseif $data->tablename == "returnBuyBillController.php"}
                        {foreach $productsReArr[$data->supplierdebtchangemodelid] as $prod}
                            {if $prod@first}
                                <tr>
                                    <td>{$prod->productName}</td>
                                    <td>{$prod->returnbuybilldetailquantity*$prod->productnumber}</td>
                                    <td>{$prod->returnbuybilldetailprice}</td>
                                    <td>{$prod->returnbuybilldetailtotalprice}</td>
                                    <td>{$prod->discountvalue}</td>
                                    <td>{$prod->discountvalue + $prod->returnbuybilldetailtotalprice}</td>
                                </tr>
                            {else}
                                <tr>
                                    <td>{$prod->productName}</td>
                                    <td>{$prod->returnbuybilldetailquantity*$prod->productnumber}</td>
                                    <td>{$prod->returnbuybilldetailprice}</td>
                                    <td>{$prod->returnbuybilldetailtotalprice}</td>
                                    <td>{$prod->discountvalue}</td>
                                    <td>{$prod->discountvalue + $prod->returnbuybilldetailtotalprice}</td>
                                </tr>
                            {/if}
                        {/foreach}
                    {elseif $data->tablename == "buyAndReturnBillController.php"}
                        {foreach $productsBuyAndReArr[$data->supplierdebtchangemodelid] as $prod}
                                {if $prod@first}
                                    <tr>
                                        <td>{$prod->productName}</td>
                                        <td>{$prod->buybilldetailquantity*$prod->productnumber}</td>
                                        <td>{$prod->buybilldetailprice}</td>
                                        <td>{$prod->buybilldetailtotalprice}</td>
                                        <td>{$prod->discountvalue}</td>
                                        <td>{$prod->discountvalue + $prod->buybilldetailtotalprice}</td>
                                    </tr>
                                {else}
                                    <tr>
                                        <td>{$prod->productName}</td>
                                        <td>{$prod->buybilldetailquantity*$prod->productnumber}</td>
                                        <td>{$prod->buybilldetailprice}</td>
                                        <td>{$prod->buybilldetailtotalprice}</td>
                                        <td>{$prod->discountvalue}</td>
                                        <td>{$prod->discountvalue + $prod->buybilldetailtotalprice}</td>
                                    </tr>
                                {/if}
                            {/foreach}
                        {else}
                        {if $rowspan > 1}
                        <tr>
                            <td colspan="6"></td>
                        </tr>
                        {/if}
                    {/if}
                    {/if}

                    {/foreach}
                </tbody>
            </table>
            {if {$supplierDebt}}
            <div class="col-lg-offset-8 col-lg-4">
                <div class="well well-sm">
                    <h4 class="text-center"> الدين الحالي للمورد {$supplierDebt}</h4>
                </div>
            </div>
            {/if}
            <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>