<script>
    $(document).ready(function (e) {

        var printingpapersize = document.getElementById("printingpapersize").value;
        var id = document.getElementById("id").value;
        if (printingpapersize == 1)
        {

            window.open("buyBillprintController.php?do=buyandreturneditprint&id=" + id);
        } else
        {
            window.open("buyBillprintController.php?do=buyandreturneditprint1&id=" + id);
        }
    });

</script>
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">إدارة الفواتير</a></li>
            <li><a href="#">فاتورة الشراء</a></li>
            <li class="active">عرض فاتورة</li>
        </ol>

        <h3>{$billnameAddData->name}</h3>
        <hr/>
        <form class="form-horizontal" role="form" action="buyAndReturnBillController.php?do=show" method="post" id="billform">

            <!-- =========================== START BUY BILL SETTINGS ================================== -->
            <input name="printingpapersize" id="printingpapersize" type="hidden" value="{$Programsettingdata->printingpapersize}" />

            <input type="hidden" name="billnameid" id="billnameid" value="{$billnameid}"/>
            <input type="hidden" name="returnBillSetting" id="returnBillSetting" value="{$billsettingsData[0]->billsettingsvalue}"/>
            <input type="hidden" name="storeSetting" id="storeSetting" value="{$billsettingsData[2]->billsettingsvalue}"/>
            <input type="hidden" name="parcodeSetting" id="parcodeSetting" value="{$billsettingsData[4]->billsettingsvalue}"/>
            <input type="hidden" name="dateSetting" id="dateSetting" value="{$billsettingsData[5]->billsettingsvalue}"/>
            <input type="hidden" name="newProductSetting" id="newProductSetting" value="{$billsettingsData[6]->billsettingsvalue}"/>
            <input type="hidden" name="noteSetting" id="noteSetting" value="{$billsettingsData[7]->billsettingsvalue}"/>
            <input type="hidden" name="productDiscountSetting" id="productDiscountSetting" value="{$billsettingsData[8]->billsettingsvalue}"/>
            <!-- ==========================  END BUY BILL SETTINGS ============================ -->

            <!-- =========================== START GENERAL INFO PANEL =====================-->
            <div class="row">
                <div class="col-lg-8">
                    {if $Programsettingdata->clientserial eq 1}
                    <div class="form-group">
                        <label class="col-lg-2 control-label">رقم تسلسل الفاتورة</label>
                        <div class="col-lg-4">
                            <p class="form-control-static">
                                {$buyBillData->buybillid}
                            </p>
                        </div>
                    </div>
                    {/if}
                    <!--------------------------->

                    <div class="form-group mg-bt5" {if {$billsettingsData[45]->billsettingsvalue} eq 0}  {else} style="display:none" {/if}>
                        <label class="col-lg-4 control-label">مركز التكلفة </label>
                        <div class="col-lg-8">

                            {foreach $allCostcenter as $myallCostcenter}

                            {if {$buyBillData->costcenterid} eq {$myallCostcenter->id}}   {$myallCostcenter->name} {/if}
                            {/foreach}


                        </div>
                    </div>

                    <!----------------------------->
                    <!-- end of form-group-->
                    <div class="form-group" {if {$billsettingsData[61]->billsettingsvalue} eq 0}  {else} style="display:none !important" {/if}>
                        <label class="col-lg-2 control-label">رقم الفاتورة</label>
                        <div class="col-lg-4">
                            <p class="form-control-static">
                                {$buyBillData->buybillSerial}
                            </p>
                        </div>
                    </div>
                    <!-- end of form-group-->

                    <div class="form-group" {if $billsettingsData[5]->billsettingsvalue eq 0} {else} style="display:none !important;" {/if}>
                        <label class="col-lg-2 control-label">تاريخ الفاتورة</label>
                        <div class="col-lg-4">
                            <p class="form-control-static">
                                {$buyBillData->buybilldate}
                            </p>
                        </div>
                    </div>
                    <!-- end of form-group-->
                </div>
                <!-- end of bill no-->
                <div class="col-lg-4">
                    <div class="form-group mg-bt5">
                        <label class="col-lg-4 control-label">اسم المورد</label>
                        <div class="col-lg-8">
                            <div id="supplierIdDiv">
                                <p class="form-control-static">
                                    {$buyBillData->suppliername}
                                </p>
                            </div>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5 {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[56]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-4 control-label">رصيد الدين</label>
                        <div class="col-lg-8">
                            <div id="debt" class="form-control-static"> {$buyBillData->buybilltotaldeptbefor} </div>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <hr class="mg-bt5 mg-tp5"/>
                    <div class="form-group mg-bt5" {if $billsettingsData[2]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                        <label class="col-lg-4 control-label">المخزن</label>
                        <div class="col-lg-8">
                            <p class="form-control-static">
                                {$buyBillData->storeName}
                            </p>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5">
                        <label class="col-lg-4 control-label">التعليق</label>
                        <div class="col-lg-8">
                            <p class="form-control-static">
                                {$buyBillData->comment}
                            </p>
                        </div>
                    </div>
                    <!-- end of form-group-->
                </div>
                <!-- end of client info-->

            </div>
            <!-- =========================== END GENERAL INFO PANEL ====================== -->

            <!-- =========================== START BUY BILL PANEL ======================= -->
            <div class="row">
                <div class="row">
                    <hr/>
                    <div class="col-lg-6">
                        <h4>المشتريات</h4>
                    </div>
                    <div class="col-lg-6">
                    </div>
                </div>
                <!-- end of title row-->
                <div class="table-responsive">
                    <table class="table billtable table-bordered table-black" id="containerpros">
                        <thead>
                            <tr>
                                <th class="wdt120" {if {$billSettingsData[59]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>الباركود</th>
                                <th class="wdt120">اسم المنتج</th>
                                <th class="wdt240" {if $billsettingsData[7]->billsettingsvalue eq 0} {else} style="display:none !important;" {/if}>ملاحظات</th>
                                <th class="wdt100n" {if {$billSettingsData[53]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>الوحدة</th>
                                <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[64]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>السعر</th>
                                <th class="wdt100n">العدد</th>
                                <th class="wdt100n "  {if {$Programsettingdata->scunitname} eq '0'}  hidden {/if} >{$Programsettingdata->scunitname}</th>

                                <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[57]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>الخصم</th>
                                <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[96]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>ضريبة</th>
                                <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}">الاجمالى
                                    <input name="hidden_itr" id="hidden_itr" type="hidden" value="0" />
                                </th>

                            </tr>
                        </thead>
                        <tbody>
                            {foreach $buyBillDetails as $detail}
                            {if $detail->billtype eq 0}
                            <tr class="aw_td" id="newProduct1">

                                <td {if $billSettingsData[59]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                    <div id="parcodeDiv1"> <p class="form-control-static"> {$detail->parcode} </p></div></td>


                                <td><div id="productdiv1" class="aw_width aw_mt5">
                                        <p class="form-control-static"> {$detail->productName} / {$detail->productCatName}
                                            {if {$billSettingsData[79]->billsettingsvalue} eq 0}
                                            {if isset($detail->sizeName) && $detail->sizeName !=""}/{$detail->sizeName}{/if}
                                            {if isset($detail->colorName) && $detail->colorName !=""}/{$detail->colorName}{/if}
                                            {/if}
                                        </p>
                                    </div></td>


                                <td {if $billsettingsData[7]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                    <p class="form-control-static">
                                        {$detail->note}
                                    </p></td>

                                <td><div id="unitDiv1" {if {$billSettingsData[53]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                                        <p class="form-control-static">{$detail->unitName} </p>
                                    </div></td>


                                <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}"><div id="propricechange1">
                                        <p class="form-control-static">{$detail->buybilldetailprice} </p>
                                    </div></td>

                                <td> <p class="form-control-static" {if {$billSettingsData[64]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                                        {$detail->buybilldetailquantity}</p></td>


                                <td class="" {if {$Programsettingdata->scunitname} eq '0'}  hidden {/if}>
                                    <p class="form-control-static"> {$detail->otherdetailquantity}</p>
                                </td>

                                <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billsettingsData[57]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                    <p class="form-control-static">
                                        {$detail->discountvalue}</p></td>
                                <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billsettingsData[96]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                    <p class="form-control-static">
                                        {$detail->rowtaxper}%</p></td>


                                <td class="aw_totalprice {if $usergroup->hideBillPrices == 1}hidden{/if}"><div id="prototal1" class="aw_mt">
                                        <p class="form-control-static">{$detail->buybilldetailtotalprice}</p>
                                    </div></td>
                            </tr>
                            {/if}
                            {/foreach}
                        </tbody>
                    </table>
                </div>
                <button type="button" class="btn btn-primary pull-left ft-nor {if $usergroup->hideBillPrices == 1}hidden{/if}"> إجمالي المشتريات <span class="badge wht-clo"><div id="buyBillTotal">{$totalBuyPrice}</div></span></button>
            </div>
            <!-- end of second row-->
            <!-- =========================== END BUY BILL PANEL ==================== -->

            <!-- =========================== START RETURN BUY BILL PANEL ====================== -->
            <div class="row" {if $billsettingsData[0]->billsettingsvalue eq 0} {else} style="display:none !important;" {/if}>
                <div class="row">
                    <hr/>
                    <div class="col-lg-6">
                        <h4>مردودات المشتريات</h4>
                    </div>
                    <div class="col-lg-6">
                    </div>
                </div>
                <!-- end of title row-->
                <div class="table-responsive">
                    <table class="table billtable table-bordered table-black" id="containerpros_re">
                        <thead>
                            <tr>
                                <th {if {$billSettingsData[59]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>الباركود</th>

                                <th class="wdt120">اسم المنتج</th>

                                <th class="wdt240" {if $billsettingsData[7]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>ملاحظات</th>

                                <th class="wdt100n" {if {$billSettingsData[53]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>الوحدة</th>
                                <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[64]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>السعر</th>
                                <th class="wdt100n" >العدد</th>
                                <th class="wdt100n "  {if {$Programsettingdata->scunitname} eq '0'}  hidden {/if} >{$Programsettingdata->scunitname}</th>

                                <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billSettingsData[57]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>الخصم</th>
                                <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billSettingsData[96]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>ضريبة</th>
                                <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}">الاجمالى
                                    <input name="hidden_itr_re" id="hidden_itr_re" type="hidden" value="0" />
                                </th>

                            </tr>
                        </thead>
                        <tbody>
                            {foreach $buyBillDetails as $detail}
                            {if $detail->billtype eq 1}
                            <tr class="aw_td" id="newProduct1">
                                <td {if $billSettingsData[59]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                    <div id="parcodeDiv1">
                                        <p class="form-control-static">{$detail->parcode} </p>
                                    </div></td>

                                <td><div id="productdiv1" class="aw_width aw_mt5">
                                        <p class="form-control-static"> {$detail->productName} / {$detail->productCatName}
                                            {if {$billSettingsData[79]->billsettingsvalue} eq 0}
                                            {if isset($detail->sizeName) && $detail->sizeName !=""}/{$detail->sizeName}{/if}
                                            {if isset($detail->colorName) && $detail->colorName !=""}/{$detail->colorName}{/if}
                                            {/if}
                                        </p>
                                    </div></td>

                                <td {if $billsettingsData[7]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                    <p class="form-control-static"> {$detail->note}</p></td>


                                <td><div id="unitDiv1" {if {$billSettingsData[53]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                                        <p class="form-control-static">
                                            {$detail->unitName} </p></div>
                                </td>

                                <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}"><div id="propricechange1">
                                        <p class="form-control-static">{$detail->buybilldetailprice} </p>
                                    </div></td>


                                <td {if {$billSettingsData[64]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                                    <p class="form-control-static"> {$detail->buybilldetailquantity}</p>
                                </td>
                                <td class="myblack" {if {$Programsettingdata->scunitname} eq '0'}  hidden {/if}>
                                    <p class="form-control-static"> {$detail->otherdetailquantity}</p>
                                </td>

                                <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billSettingsData[57]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                    <p class="form-control-static"> {$detail->discountvalue}</p></td>
                                <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billSettingsData[96]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                    <p class="form-control-static"> {$detail->rowtaxper}%</p></td>


                                <td class="aw_totalprice {if $usergroup->hideBillPrices == 1}hidden{/if}"><div id="prototal1" class="aw_mt">
                                        <p class="form-control-static">
                                            {$detail->buybilldetailtotalprice}
                                        </p>
                                    </div></td>
                            </tr>
                            {/if}
                            {/foreach}
                        </tbody>
                    </table>
                </div>
                <button type="button" class="btn btn-primary pull-left ft-nor {if $usergroup->hideBillPrices == 1}hidden{/if}"> إجمالي مردودات المشتريات <span class="badge wht-clo"><div id="buyBillTotal_re">{$totalReturnBuyPrice}</div></span></button>
            </div>
            <!-- =========================== END RETURN BUY BILL PANEL ======================== -->

            <!-- =========================== START TOTAL VALUES PANEL ======================= -->
            <div class="row">
                <div class="col-lg-9">
                </div><!-- end of calucation center-->

                <div class="col-lg-3">
                    <hr/>
                    <div class="form-group mg-bt5" {if {$billSettingsData[58]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">عدد القطع</label>
                        <div class="col-lg-7">
                            <p class="form-control-static" id="totalQty">{$countBillDetails_buy}</p>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5" {if $billsettingsData[0]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                        <label class="col-lg-5 control-label">عدد القطع المرتجعة</label>
                        <div class="col-lg-7">
                            <p class="form-control-static" id="returnTotalQty">{$countBillDetails_return}</p>
                        </div>
                    </div><!-- end of form-group-->
                    <div class="form-group mg-bt5 {if $usergroup->hideBillPrices == 1}hidden{/if}">
                        <label class="col-lg-5 control-label">الاجمالى العام</label>
                        <div class="col-lg-7">
                            <p class="form-control-static" id="gentotal">{$buyBillData->buybilltotalbill}</p>
                        </div>
                    </div><!-- end of form-group-->
                    <div class="form-group mg-bt5 {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[57]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">نوع الخصم</label>
                        <div class="col-lg-7">

                            <p class="form-control-static">
                                {if $buyBillData->buybilldiscountrype eq 0}
                                خصم مباشر
                                {else}
                                خصم بنسبه مئويه
                                {/if}
                            </p>
                        </div>
                    </div><!-- end of form-group-->

                    <div class="form-group mg-bt5 {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[57]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}
                        >
                        <label class="col-lg-5 control-label">قيمة الخصم</label>
                        <div class="col-lg-7">
                            <p class="form-control-static">
                                {$buyBillData->buybilldiscount}
                            </p>

                        </div>
                    </div><!-- end of form-group-->

                    <!------------------------------------------------------>
                    <div {if {$billsettingsData[36]->billsettingsvalue} eq "0"} {else}  style="display:none"    {/if}>
                        <hr class="mg-tp5 mg-bt5"/>
                        <div class="form-group mg-bt5 {if $usergroup->hideBillPrices == 1}hidden{/if}">
                            <label class="col-lg-5 control-label">ضريبه القيمة المضافة</label>
                            <div class="col-lg-7">

                                <div class="input-group">
                                    {$buyBillData->payedtax} %
                                </div>
                                <div class="input-group" style="padding-top: 1px;">
                                    {$taxvalue}
                                    {$Programsettingdata->currancy}
                                </div>
                            </div>
                        </div>


                    </div>
                    <hr class="mg-tp5 mg-bt5"/>
                    <div class="form-group mg-bt5 {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[51]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">الصافى</label>
                        <div class="col-lg-7">
                            <p class="form-control-static" id="gen2total">{$buyBillData->buybillaftertotalbill}</p>

                        </div>
                    </div><!-- end of form-group-->
                    <div class="form-group mg-bt5 {if $usergroup->hideBillPrices == 1}hidden{/if}" {if {$billSettingsData[54]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">المدفوع</label>
                        <div class="col-lg-7">
                            <p class="form-control-static">
                                {$buyBillData->buybilltotalpayed}
                            </p>
                        </div>
                    </div><!-- end of form-group-->
                    <hr class="mg-tp5 mg-bt5"/ {if {$billSettingsData[55]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                    <div class="form-group mg-bt5 bg-yel {if $usergroup->hideBillPrices == 1}hidden{/if}">
                        <label class="col-lg-5 control-label">المتبقى</label>
                        <div class="col-lg-7">
                            <p class="form-control-static" id="gen3total">{$buyBillData->buybillfinalbill}</p>
                        </div>
                    </div><!-- end of form-group-->
                    <div class="form-group mg-bt5 {if $usergroup->hideBillPrices == 1}hidden{/if}">
                        <label class="col-lg-5 control-label">باقى الدين</label>
                        <div class="col-lg-7">
                            <p class="form-control-static" id="gen4total">{$buyBillData->buybilltotaldeptafter}</p>

                        </div>
                    </div><!-- end of form-group-->
                </div><!-- end of totals center-->
            </div><!-- end of fourth row-->

            <input name="id" id="id" type="hidden" value="{$buyBillData->buybillid}" />
            <div class="row hidden-print">
                <!--                <button type="submit"  class="btn btn-primary">رجوع</button>-->
                {if {$buyBillData->deletedbuyid} > 0 && {$buyBillData->deletedbuyid} <> NULL && {$buyBillData->deletedbuyid} <> ''}
                <a target="_new" href="{$buyBillData->controlname}?do=editprint&id={$buyBillData->deletedbuyid}">
                    <button type="button" class="btn btn-primary">الايصال القديم</button></a>
                {/if}
                {if {$Programsettingdata->printingpapersize} eq 0}
                <a target="_new" href="buyBillprintController.php?do=buyandreturneditprint1&id={$buyBillData->buybillid}">
                    <button type="button" class="btn btn-info">طباعه ايصال كبير</button></a>
                {/if}
                {if {$Programsettingdata->printingpapersize} eq 1}
                <a target="_new" href="buyBillprintController.php?do=buyandreturneditprint&id={$buyBillData->buybillid}">
                    <button type="button" class="btn btn-info">طباعه ايصال</button></a>
                {/if}

                <a href="buyAndReturnBillController.php?do=addoneserial&id={$buyBillData->buybillid}&type=3" >  <button type="button" class="btn btn-info">تكويد المنتجات</button></a>

                <a href="buyAndReturnBillController.php?do=addserial&id={$buyBillData->buybillid}&type=3" >  <button type="button" class="btn btn-info">تكويد منتجات متعدد</button></a>
            </div><!-- end of fifth row-->

            <!-- =========================== END TOTAL VALUESPANEL ====================== -->
        </form>



    </div>
</div>
