<style>
    .newoption
    {
        background-color:#CCCCCC !important;
        font-weight:bold !important;
    }

</style>

<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">إدارة الفواتير</a></li>
            <li><a href="#">{$billnameAddData->name}</a></li>
            <li class="active">تعديل {$billnameAddData->name}</li>
        </ol>
        <!-- === start addrowcreated === -->
        <div id="addrowcreated" style="display:none">
            <option value="-1">اختر</option>
            {assign var=j value=0}
            {foreach $productsData as $product}
            <option value="{$product->productId}">{$names{$j}} {$product->productName} </option>
            {capture assign=j}{$j+1}{/capture}
            {/foreach} </div>

        <!-- === end addrowcreated === -->
        <h3>{$billnameAddData->name}</h3>
        <hr/>
        <input type="hidden" name="searchWithCatAndProductNameOnly" id="searchWithCatAndProductNameOnly" value="{$billsettingsData[97]->billsettingsvalue}"/>
        <input type="hidden" id="stopStoreSearch" value="1"/>
        <input type="hidden" id="supplierWithAddOption" value="{$usergroup->addsupplierInBill}"/>
        {literal}
        <form class="form-horizontal" role="form" action="buyBillController.php?do=update" method="post" enctype="multipart/form-data" id="billform" onsubmit="if (Spry.Widget.Form.validate(this)) {
                    $('#saveAndNew').css('display', 'none');
                    $('#saveBill').css('display', 'none');
                    return true;
                } else {
                    return false;
                }">
            {/literal}
            <!-- =========================== START BUY BILL SETTINGS ================================== -->
            <input type="hidden" name="billnameid" id="billnameid" value="{$billnameid}"/>
            <input type="hidden" name="ordertype" id="ordertype" value="{$billnameAddData->ordertype}"/>
            <input type="hidden" name="billidnor" id="billidnor" value="{$billidnor}"/>
            <input type="hidden" name="controlname" id="controlname" value="{$controlname}"/>
            <input type="hidden" name="scunitnamevalue" id="scunitnamevalue" value="{$Programsettingdata->scunitname}"/>
            <input type="hidden" name="usedParcode" id="usedParcode" value="{$Programsettingdata->usedParcode}"/>
            <input type="hidden" name="valueaddedbuy" id="valueaddedbuy" value="{$Programsettingdata->valueaddedbuy}"/>

            <input type="hidden" name="productAndQuantityOnly" id="productAndQuantityOnly" value="{$billnameAddData->productAndQuantityOnly}"/>
            <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}"/>
            <input type="hidden" name="productTaxSetting" id="productTaxSetting" value="{$billsettingsData[96]->billsettingsvalue}"/>
            <input type="hidden" name="quantityOrParcodeSetting" id="quantityOrParcodeSetting" value="{$billsettingsData[9]->billsettingsvalue}"/>
            <input type="hidden" name="payNumSetting" id="payNumSetting" value="{$billsettingsData[11]->billsettingsvalue}"/>
            <input type="hidden" name="unitSetting" id="unitSetting" value="{$billsettingsData[10]->billsettingsvalue}"/>
            <input type="hidden" name="commentSetting" id="commentSetting" value="{$billsettingsData[12]->billsettingsvalue}"/>
            <input type="hidden" name="searchvalue" id="searchvalue" value="{$Programsettingdata->searchvalue}"/>
            <input type="hidden" name="settingQuantitiyFocus" id="settingQuantitiyFocus" value="{$billsettingsData[9]->billsettingsvalue}"/>
            <input type="hidden" name="discountrowtype" id="discountrowtype" value="{$billsettingsData[34]->billsettingsvalue}"/>
            <input type="hidden" name="payedSetting" id="payedSetting" value="{$billsettingsData[71]->billsettingsvalue}"/>
            <input type="hidden" name="userSaveCurrencyName" id="userSaveCurrencyName" value="{$userSaveData->currencyName}"/>
            <input type="hidden" name="userSaveconversionFactor" id="userSaveconversionFactor" value="{$userSaveData->conversionFactor}"/>
            <input type="hidden" name="oldCFactor" id="oldCFactor" value="1"/>
            <input type="hidden" name="oldCFactorVal" id="oldCFactorVal" value="{if !empty($billCurrData->conversionFactor)}{$billCurrData->conversionFactor}{else}1{/if}"/>
            <input type="hidden" name="hideBillPrices" id="hideBillPrices" value="{$usergroup->hideBillPrices}"/>
            <input type="hidden" name="withNakdi" id="withNakdi" value="{$usergroup->showClientAndSupplierOne}"/>

            <input type="hidden" name="shownumber" id="shownumber" value="{$billsettingsData[40]->billsettingsvalue}"/>
            <input type="hidden" id="checkRedundantProducts" value="{$billsettingsData[107]->billsettingsvalue}"/>
            <!-- ==========================  END BUY BILL SETTINGS ============================ -->

            <!-- =========================== START GENERAL INFO PANEL =====================-->
            <div class="row">
                <div class="col-lg-8">


                    <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-4">
                            <select class="select2 wdt100" name="Costcenter" id="Costcenter" >


                                <option value="-1">اختر مركز التكلفه</option>
                                {foreach $allCostcenter as $myallCostcenter}



                                <option   {if {$buyBillData->costcenterid} eq {$myallCostcenter->id}  or {$returnbuybillData->costcenterid} eq {$myallCostcenter->id} }selected="selected"  {/if} value="{$myallCostcenter->id}">{$myallCostcenter->name}</option>

                                {/foreach}


                            </select>

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

                    </div>
                    {if $Programsettingdata->clientserial eq 1}
                    <div class="form-group">
                        <label class="col-lg-4 control-label">الرقم التسلسلي</label>
                        <div class="col-lg-4">
                            <input type="text" value="{$billId}"  class="form-control" disabled readonly/>


                        </div>
                    </div>
                    {/if}

                    <div class="form-group" {if $billsettingsData[61]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                        <label class="col-lg-4 control-label">رقم  الفاتورة</label>
                        <div class="col-lg-4">
                            <input name="pay_num" id="pay_num" type="text" value="{$buyBillData->buybillSerial}{$returnbuybillData->returnbuybillSerial}"  class="form-control"/>


                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group"  {if $billsettingsData[48]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                        <label class="col-lg-4 control-label">رقم عملية السداد - اختياري</label>
                        <div class="col-lg-4">
                            <input name="pay_num_optional" id="pay_num_optional"  class="form-control" type="text"  tabindex="1"  value="{$buyBillData->buybillSerial}{$returnbuybillData->returnbuybillSerial}" />
                        </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-4 control-label">تاريخ الفاتورة</label>
                        <div class="col-lg-4">
                            <!--input name="bn" type="text" class=" form-control awdatepicker" autocomplete="off"  data-date-format="yyyy-mm-dd" id="bn" value="{$buyBillData->buybillsysdate}{$returnbuybillData->returnbuybilldate}" placeholder="تاريخ الفاتورة" {if $Programsettingdata->allowdateedit == 1}disabled="disabled"{/if} tabindex="2"/-->
                            {if $Programsettingdata->allowdateedit == 1}
                            <input type="text" class="form-control" placeholder="تاريخ الفاتورة" readonly value="{$buyBillData->buybillsysdate}{$returnbuybillData->returnbuybilldate}" name="bn" id="bn">
                            {else}
                            <div  class="input-group date form_datetime col-md-5" data-date="" data-date-format="yyyy-mm-dd  h:i:s" data-link-field="dtp_input1">
                                <input class="form-control" size="16" type="text" value="{$buyBillData->buybilldate}{$returnbuybillData->returnbuybilldate}" name="bn" id="bn readonly="" >
                                <span class="input-group-addon "><span class=" glyphicon glyphicon-remove col-lg-4"></span></span>
                                <span class="input-group-addon"><span class="glyphicon glyphicon-th col-lg-4"></span></span>
                            </div>{/if}
                        </div>
                    </div>
                    <!-- end of form-group-->
                </div>
                <!-- end of bill no-->
                <div class="col-lg-4">
                    <div class="form-group mg-bt5" {if $billsettingsData[1]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                        <label class="col-lg-4 control-label">اسم المورد</label>
                        <div class="col-lg-8">
                            <span id="spryselect1">
                                <div id="supplierIdDiv">
                                    <!--                                    <select id="supplier" name="supplier" onChange="supplierDebt(this.value);" data-placeholder="اختر المورد" class="select2 wdt100"  tabindex="3">
                                                                            <option value="-1">اختر مورد</option>
                                                                            {if $usergroup->addsupplierInBill == 0}
                                                                            <option value="-2" class="newoption"><a class="conformdel_supplier">إضافة مورد جديد</a></option>
                                                                            {/if}

                                                                            {foreach $suppliersData as $supplier}



                                                                            <option {if {$buyBillData->buybillsupplierid} eq {$supplier->supplierid} or {$returnbuybillData->returnbuybillsupplierid} eq {$supplier->supplierid}}  selected="selected"  {/if} value="{$supplier->supplierid}">{$supplier->suppliername}</option>



                                                                            {/foreach}


                                                                        </select>-->

                                    <input type="hidden" name="supplier" id="supplier" class="select2Supp"/>
                                    <input type="hidden" name="oldsupplierid" id="oldsupplierid" value="{$mysupplierdata->supplierid}"/>
                                    <input type="hidden" name="oldsuppliername" id="oldsuppliername" value="{$mysupplierdata->suppliername}"/>

                                </div>

                                <input type="hidden" value="{$returnbuybillData->dailyentryid}" name="returndailyEntryId"/>
                                <input type="hidden" value="{$buyBillData->dailyentryid}" name="dailyentryid"/>
                                <input type="hidden" value="{$buyBillData->buybillsupplierid}" name="buybillsupplierid"/>


                                <span class="selectInvalidMsg">اختر المورد</span></span>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5" {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"> {$mysupplierdata->suppliercurrentDebtInCurrency}</div>
                            <input name="hidden_debt" id="hidden_debt" type="hidden" value="{$mysupplierdata->suppliercurrentDebtInCurrency}"/>
                            <input id="suppCurr" type="hidden" value="{$mysupplierdata->sullpierCurrencyid}"/>
                            <span class="aw_ras"><a id="editdebt" style="display:none;" href="#">تعديل</a></span> </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}>
                        {if $userdata->userstoreid  eq 0}


                        <label class="col-lg-4 control-label">المخزن</label>
                        <div class="col-lg-8">
                            <select name="storeId" id="storeId" data-placeholder="اختر" class="select2 wdt100 aw_m1"  tabindex="5">
                                <!--<option value="-1"></option>-->
                                {foreach $storesData as $store}



                                <option   {if {$buyBillData->buybillstoreid} eq {$store->storeId} or {$returnbuybillData->returnbuybillstoreid} eq  {$store->storeId}}  selected="selected"  {/if} value="{$store->storeId}">{$store->storeName}</option>



                                {/foreach}



                            </select>
                        </div>
                        {else}

                        <input name="storeId" id="storeId"  type="hidden" value="{$buyBillData->buybillstoreid}{$returnbuybillData->returnbuybillstoreid}" />
                        <label class="col-lg-4 control-label">المخزن</label>
                        {foreach $storesData as $store}


                        <div class="col-lg-8">  {if {$store->storeId} eq {$buyBillData->buybillstoreid} or {$returnbuybillData->returnbuybillstoreid} eq  {$store->storeId}}{$store->storeName} {/if}
                        </div>

                        {/foreach}
                        {/if}
                    </div>
                    <!-- end of form-group-->
                    <div {if {$billsettingsData[87]->billsettingsvalue} eq 1}  {else} style="display:none" {/if} >
                        <div class="form-group mg-bt5">
                            <label class="col-lg-4 control-label">الخزنة</label>
                            <div class="col-lg-8">
                                <select class="select2 wdt100" name="saveid" id="saveid">
                                    {foreach $allSaves as $data}
                                    <option value="{$data->saveid}" data-curr={$data->currencyId}  {if $buyBillData->buybillsaveid eq $data->saveid || $returnbuybillData->returnbuybillsaveid eq $data->saveid} selected="selected" {/if}>{$data->savename}</option>

                                    {/foreach}
                                </select>
                            </div>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <!--only currency allowed now is supplier currency ,,, till we manage it in php-->
                    <div class="form-group mg-bt5 hidden" {if $Programsettingdata->showCurrency != 1}style="display:none;"{/if}>
                        <label class="col-lg-4 control-label">{$smarty.const.BUY_BILL_CURRENCY}</label>
                        <div class="col-lg-8">
                            <select class="select2" name="currencyId" id="currencyId">
                                {foreach $allCurrency as $data}
                                <option value="{$data->id}" data-cfactor="{$data->conversionFactor}" data-othercfactor="{$data->otherconversionFactor}" {if $buyBillData->currencyId == $data->id||$returnbuybillData->currencyId == $data->id}selected{/if}>{$data->name}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="clear"></div>
                        <label class="col-lg-4 control-label">{$smarty.const.BUY_BILL_CONVERSION_FACTOR}</label>
                        <div class="col-lg-8">
                            <input type="text" name="cFactor" id="cFactor" class="form-control positivefloat calcOther" onkeyup="populateDebtAfter();" style="display: inline-block;width: 34%"/>
                            =
                            <div class="input-group" style="display: inline;">
                                <input type="text" name="otherCFactor" id="otherCFactor" class="form-control positivefloat calcOther" style="display: inline-block;width: 34%"/>
                                <span class="input-group-addon" style="display: inline-block;width: 23%">{$currency}</span>
                            </div>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5" {if $billsettingsData[12]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                        <label class="col-lg-4 control-label">التعليق</label>
                        <div class="col-lg-8">
                            <textarea name="comment" id="comment" cols="" rows="" class="form-control" tabindex="6">{$buyBillData->comment}{$buyBillData->returnbuybillData}</textarea>
                        </div>
                    </div>
                    <!-- end of form-group-->
                </div>
                <!-- end of client info-->

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

            <!-- =========================== START BUY BILL PANEL ======================= -->

            <input name="hidden_itr" id="hidden_itr" type="hidden" value="{$countBillDetails}" />


            <div  {if $controlname  eq "buyBillController.php"   or $controlname  eq "buyAndReturnBillController.php"} {else} style="display:none !important;" {/if}>

                <div class="row"  {if $billsettingsData[14]->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">
                            <button type="button" name="addpro2" id="addpro2" class="btn btn-primary pull-left ft-nor"> اضافة جديد</button>
                            <!--button type="button" style="display:none;" name="addpro2" id="addpro2" class="btn btn-primary pull-left ft-nor"> اضافة جديد</button-->
                        </div>
                    </div>
                    <!-- end of title row-->
                    <div class="table-responsive bd-gr">
                        <table class="table billtable table-bordered table-black" id="containerpros">
                            <thead>
                                <tr>
                                    <th class="wdt60" {if $billsettingsData[6]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>جديد</th>
                                    <th class="wdt20" {if {$billsettingsData[40]->billsettingsvalue} eq 0}  {else} style="display:none !important;" {/if}>رقم</th>
                                    <th class="wdt120 check_tr_parcode {if {$billsettingsData[59]->billsettingsvalue} eq 1}  hidden {/if}">الباركود</th>
                                    <th class="wdt400">اسم المنتج</th>
                                    <th class="wdt240" {if $billsettingsData[7]->billsettingsvalue eq 0} {else} style="display:none !important;" {/if}>ملاحظات</th>
                                    <th class="wdt100n check_tr_unit {if {$billsettingsData[53]->billsettingsvalue} eq 1}  hidden {/if}">الوحدة</th>
                                    <th class="wdt100n check_tr_quantity {if {$billsettingsData[64]->billsettingsvalue} eq 1}  hidden {/if}">العدد</th>
                                    <th class="wdt100n   {if {$Programsettingdata->scunitname} eq '0'}  hidden {/if}" >{$Programsettingdata->scunitname}</th>

                                    <th class="wdt80" {if $usergroup->hideBillPrices == 1}hidden{/if} {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>السعر</th>
                                    <th class="wdt80 check_tr_discount {if $usergroup->hideBillPrices == 1}hidden{/if} {if {$billsettingsData[8]->billsettingsvalue} eq 1}  hidden {/if}" {if $billsettingsData[8]->billsettingsvalue eq 0&& $billnameAddData->productAndQuantityOnly eq 0}  {else} style="display:none !important;" {/if}>الخصم</th>
                                    <th class="wdt80 check_tr_tax {if $usergroup->hideBillPrices == 1}hidden{/if} {if {$billsettingsData[96]->billsettingsvalue} eq 1}  hidden {/if}" >ضريبه</th>
                                    <th class="wdt100n {if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>الاجمالى

                                    </th>
                                    <th>حذف</th>
                                </tr>
                            </thead>
                            <tbody>
                                {assign var=x value=1}
                                {assign var=piecesCount value=0}
                                {foreach $buyBillDetails as $mybuyBillDetails}
                                <tr id="newProduct{$x}">
                                    <td {if $billsettingsData[6]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}><a onClick="javascript:showModalBox(this.name);" class="newLink btn btn-primary  btn-xs conformdel"   id="new1" name="1">جديد</a></td>
                                    <td {if {$billsettingsData[40]->billsettingsvalue} eq 0}  {else} style="display:none !important;" {/if}>{$mybuyBillDetails@iteration}</td>
                                    <td {if {$billsettingsData[59]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                                        <input type="text" class="form-control txt-nonraduis" placeholder="الباركود" name="parcode{$x}" id="parcode{$x}"  value="{$mybuyBillDetails->parcode}" onKeyPress="getproductbyParcode(event, this.value, {$x});" autocomplete="off" tabindex="7">
                                    </td>
                                    <td>
                                        <div id="productdiv{$x}">
                                            <input type="hidden" id="product{$x}" name="product{$x}" data-placeholder="اختر" class="select2product wdt100"  tabindex="7"/>
                                            <input type="hidden" id="oldproduct{$x}" name="oldproduct{$x}"  value="{if $mybuyBillDetails->sizeid > 0 && $mybuyBillDetails->colorid > 0}hasSizeColor{$mybuyBillDetails->buybilldetailproductid}-{$mybuyBillDetails->sizeid}-{$mybuyBillDetails->colorid}{else}{$mybuyBillDetails->buybilldetailproductid}{/if}"  />
                                            <input type="hidden" id="oldname{$x}" name="oldname{$x}"  value="{$mybuyBillDetails->productName}
                                                   {if $mybuyBillDetails->sizeName != ''}/ {$mybuyBillDetails->sizeName}{/if}
                                                   {if $mybuyBillDetails->colorName != ''}/ {$mybuyBillDetails->colorName}{/if}"  />
                                        </div>


                                    </td>
                                    <td {if $billsettingsData[7]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                        <textarea class="form-control txt-nonraduis" rows="1" name="note{$x}" id="note{$x}"  tabindex="7">{$mybuyBillDetails->note}</textarea>
                                    </td>
                                    <td class=" check_tr_unit {if {$billsettingsData[53]->billsettingsvalue} eq 0}  {else} hidden {/if}" >
                                        <div id="unitDiv{$x}">
                                            <select name="unitId{$x}" id="unitId{$x}"  size="3"  onchange="getUnitPrice({$x});"  data-placeholder="اختر" class="select2 aw_m1 wdt100 chosenproduct"  tabindex="7">
                                                <option value="-1"></option>
                                                {foreach $myunitdata{$x} as $mymyunitdata}
                                                <option   {if {$mybuyBillDetails->productunitid} eq {$mymyunitdata->productunitid} } selected="selected"  {/if}   value="{$mymyunitdata->productunitid}" >{$mymyunitdata->unitName}</option>
                                                {/foreach}

                                            </select>
                                        </div>
                                    </td>
                                    <td class="check_tr_quantity {if {$billsettingsData[64]->billsettingsvalue} eq 0} {else}  hidden   {/if}" >
                                        <input name="pronum{$x}" id="pronum{$x}"   class="form-control getprototal numberclic enteraction numberinput txt-nonraduis positivefloat" placeholder="العدد" type="text" tabindex="7" value="{$mybuyBillDetails->buybilldetailquantity}" />
                                        {assign var=piecesCount value=$piecesCount+$mybuyBillDetails->buybilldetailquantity}
                                    </td>

                                    <td class="  {if {$Programsettingdata->scunitname} eq '0'}  hidden {/if}">
                                        <input name="scunitname{$x}" id="scunitname{$x}" value="{$mybuyBillDetails->otherdetailquantity}"  class="form-control txt-nonraduis positiveNo" placeholder="العدد" type="text" tabindex="7" />
                                    </td>
                                    <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>
                                        <div id="propricechange{$x}">
                                            <input name="proprice{$x}" id="proprice{$x}" placeholder="السعر" class="form-control txt-nonraduis getprototal numberclic enteraction numberinput positivefloat" type="text"   value="{$mybuyBillDetails->buybilldetailprice}" tabindex="7"/>
                                        </div>
                                    </td>
                                    <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billsettingsData[8]->billsettingsvalue eq 0&& $billnameAddData->productAndQuantityOnly eq 0}  {else} style="display:none !important;" {/if}>
                                        <input name="prodis{$x}" id="prodis{$x}" value="{$mybuyBillDetails->discountvalue}" class="form-control getprototal numberonly enteraction numberinput txt-nonraduis positiveNo" placeholder="الخصم"  tabindex="7" {if {$billsettingsData[34]->billsettingsvalue} eq 0} type="text" {else}  type="hidden" {/if}/>
                                        <input name="discounttype{$x}" id="discounttype{$x}"  value="{$mybuyBillDetails->discounttype}" class="form-control getprototal numberonly enteraction numberinput txt-nonraduis positivefloat" tabindex="7"   {if {$billsettingsData[34]->billsettingsvalue} eq 1} type="text" {else}  type="hidden" {/if}/>
                                    </td>
                                    <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billsettingsData[96]->billsettingsvalue eq 0&& $billnameAddData->productAndQuantityOnly eq 0}  {else} style="display:none !important;" {/if}>
                                        <input name="rowtaxval{$x}" id="rowtaxval{$x}" value="{$mybuyBillDetails->rowtaxval}" class="form-control getprototal numberonly enteraction numberinput txt-nonraduis positiveNo" placeholder="ضريبة" type="hidden"/>
                                        <input name="rowtaxper{$x}" id="rowtaxper{$x}"  value="{$mybuyBillDetails->rowtaxper}" class="form-control getprototal numberonly enteraction numberinput txt-nonraduis positiveNo" tabindex="7"  type="text" />
                                    </td>
                                    <td class="aw_totalprice {if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>
                                        <!--                                        <div id="prototal{$x}" class="aw_mt form-control-static"> {$mybuyBillDetails->buybilldetailtotalprice} {$currency}</div>
                                                                                <input name="hidden_prototal{$x}" id="hidden_prototal{$x}" type="hidden" value="{$mybuyBillDetails->buybilldetailtotalprice}"  tabindex="7"/>-->

                                        <input  name="hidden_prototal{$x}" id="hidden_prototal{$x}" class="editTotal form-control txt-nonraduis enteraction numberinput positiveNo" value="{$mybuyBillDetails->buybilldetailtotalprice}" type="text"/>
                                    </td>
                                    <td>
                                        <button type="button" id="remove{$x}" class="removeproduct close flt-none" aria-hidden="true" onclick="removeproduct({$x});">&times;</button>
                                    </td>
                                </tr>

                                {capture assign=x}{$x+1}{/capture}
                                {/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">
                            <input name="norbuyBillTotal"  id="norbuyBillTotal"  type="hidden"  value="" />
                            <div id="buyBillTotal">0</div>
                            <input type="hidden" value="0" name="totalBuyBill" id="totalBuyBill"/>
                        </span></button>
                </div>
            </div>
            <!-- end of second row-->
            <!-- =========================== END BUY BILL PANEL ==================== -->

            <!-- =========================== START RETURN BUY BILL PANEL ====================== -->
            <input name="hidden_itr_re" id="hidden_itr_re" type="hidden" value="{$countreturnBillDetails}" />


            <div  {if $controlname  eq "returnBuyBillController.php"  or $controlname  eq "buyAndReturnBillController.php"} {else} style="display:none !important;" {/if}>



                <br />
                <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">
                            <button type="button" name="addpro_re" id="addpro_re" class="btn btn-primary  pull-left ft-nor"> اضافة جديد</button>
                            <button type="button" style="display:none !important;" name="addpro_re" id="addpro_re" class="btn btn-primary pull-left ft-nor"> اضافة جديد</button>
                        </div>
                    </div>
                    <!-- end of title row-->
                    <div class="table-responsive bd-rd">
                        <table class="table billtable table-bordered table-black" id="containerpros_re">
                            <thead>

                                <tr>
                                    <th class="wdt120 check_tr_parcode {if {$billsettingsData[59]->billsettingsvalue} eq 1}  hidden {/if}">الباركود</th>
                                    <th class="wdt400">اسم المنتج</th>
                                    <th class="wdt240" {if $billsettingsData[7]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>ملاحظات</th>
                                    <th class="wdt100n check_tr_unit {if {$billsettingsData[53]->billsettingsvalue} eq 1}  hidden {/if}">الوحدة</th>
                                    <th class="wdt100n check_tr_quantity {if {$billsettingsData[64]->billsettingsvalue} eq 1}  hidden {/if}" >العدد</th>
                                    <th class="wdt100n   {if {$Programsettingdata->scunitname} eq '0'}  hidden {/if}" >{$Programsettingdata->scunitname}</th>

                                    <th class="wdt80" {if $usergroup->hideBillPrices == 1}hidden{/if} {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>السعر</th>
                                    <th class="wdt80 check_tr_discount {if $usergroup->hideBillPrices == 1}hidden{/if} {if {$billsettingsData[8]->billsettingsvalue} eq 1}  hidden {/if}">الخصم</th>
                                    <th class="wdt80 check_tr_tax {if $usergroup->hideBillPrices == 1}hidden{/if} {if {$billsettingsData[96]->billsettingsvalue} eq 1}  hidden {/if}" >ضريبة</th>
                                    <th class="wdt100n" {if $usergroup->hideBillPrices == 1}hidden{/if} {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>الاجمالى

                                    </th>
                                    <th>حذف</th>
                                </tr>
                            </thead>
                            <tbody>

                                {assign var=y value=1}
                                {assign var=returnPiecesCount value=0}
                                {foreach $returnbuybilldetailData as $myreturnbuybillData}
                                <tr>
                                    <td class=" check_tr_parcode {if {$billsettingsData[59]->billsettingsvalue} eq 1}  hidden {/if}">
                                        <input name="parcode_re{$y}" type="text" id="parcode_re{$y}" class="form-control  txt-nonraduis"  placeholder="الباركود" value="{$myreturnbuybillData->parcode}" onkeypress="getreturnproductbyParcode(event, this.value, {$y});" autocomplete="off"  tabindex="301"/>

                                    </td>

                                    <td><!-- اسم المنتج -->
                                        <div id="productdiv_re{$y}">
                                            <input type="hidden" id="product_re{$y}" name="product_re{$y}" data-placeholder="اختر" class="select2product_re wdt100"  tabindex="301"/>

                                            <input type="hidden" id="reoldproduct{$y}" name="reoldproduct{$y}"  value="{if $myreturnbuybillData->sizeid > 0 && $myreturnbuybillData->colorid > 0}hasSizeColor{$myreturnbuybillData->buybilldetailproductid}{$myreturnbuybillData->returnbuybilldetailproductid}-{$myreturnbuybillData->sizeid}-{$myreturnbuybillData->colorid}{else}{$myreturnbuybillData->buybilldetailproductid}{$myreturnbuybillData->returnbuybilldetailproductid}{/if}"  />
                                            <!--{*$myreturnbuybillData->returnbuybilldetailproductid*}{*$myreturnbuybillData->buybilldetailproductid*}-->
                                            <input type="hidden" id="reoldname{$y}" name="reoldname{$y}"  value="{$myreturnbuybillData->productName}
                                                   {if $myreturnbuybillData->sizeName != ''}/ {$myreturnbuybillData->sizeName}{/if}
                                                   {if $myreturnbuybillData->colorName != ''}/ {$myreturnbuybillData->colorName}{/if}"  />
                                        </div>
                                    </td>

                                    <td {if $billsettingsData[7]->billsettingsvalue eq 0}  {else} style="display:none !important;" {/if}>
                                        <input name="note_re{$y}" id="note_re{$y}" type="text"  class="form-control  txt-nonraduis" tabindex="301"/ value="{$myreturnbuybillData->note}">
                                    </td>

                                    <!-- الوحدة -->
                                    <td class="check_tr_unit {if {$billsettingsData[53]->billsettingsvalue} eq 1}  hidden {/if}">

                                        <div id="unitDiv_re{$y}">
                                            <select name="unitId_re{$y}" id="unitId_re{$y}" onchange="return_getUnitPrice({$y});"  data-placeholder="اختر" class="select2 aw_m1 wdt100 chosenproduct"  tabindex="301">
                                                <option value="-1"></option>
                                                {foreach $myreunitdata{$y} as $mymyreunitdata}
                                                <option    value="{$mymyreunitdata->productunitid}"   {if {$myreturnbuybillData->productunitid} eq {$mymyreunitdata->productunitid}} selected="selected"{/if}>{$mymyreunitdata->unitName}
                                                </option>
                                                {/foreach}
                                            </select>



                                        </div>
                                    </td>

                                    <td class=" check_tr_quantity {if {$billsettingsData[64]->billsettingsvalue} eq 1}  hidden {/if}">
                                        <input name="pronum_re{$y}" id="pronum_re{$y}" value="{$myreturnbuybillData->returnbuybilldetailquantity}{$myreturnbuybillData->buybilldetailquantity}" class="form-control return_getprototal numberclic txt-nonraduis enteraction numberinput positiveNo" placeholder="العدد"  type="text"  tabindex="301"/>
                                        {assign var=returnPiecesCount value=$returnPiecesCount+$myreturnbuybillData->returnbuybilldetailquantity+$myreturnbuybillData->buybilldetailquantity}
                                    </td>
                                    <td class="  {if {$Programsettingdata->scunitname} eq '0'}  hidden {/if}">
                                        <input name="scunitname_re{$y}" id="scunitname_re{$y}" value="{$myreturnbuybillData->otherdetailquantity}"  class="form-control txt-nonraduis positiveNo" placeholder="العدد" type="text" tabindex="7" />
                                    </td>
                                    <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>
                                        <div id="propricechange_re{$y}">
                                            <input name="proprice_re{$y}" id="proprice_re{$y}" placeholder="السعر" value="{$myreturnbuybillData->returnbuybilldetailprice}{$myreturnbuybillData->buybilldetailprice}" class="form-control txt-nonraduis return_getprototal numberclic enteraction numberinput positivefloat" type="text"  tabindex="301"/>
                                        </div>
                                    </td>
                                    <td class="check_tr_discount {if $usergroup->hideBillPrices == 1}hidden{/if} {if {$billsettingsData[8]->billsettingsvalue} eq 1}  hidden {/if}">
                                        <input name="prodis_re{$y}" id="prodis_re{$y}" value="{$myreturnbuybillData->discountvalue}" class="form-control return_getprototal txt-nonraduis numberonly enteraction numberinput positiveNo" placeholder="الخصم"   tabindex="301" {if {$billsettingsData[34]->billsettingsvalue} eq 0} type="text" {else}  type="hidden" {/if}/>
                                        <input name="discounttype_re{$y}" id="discounttype_re{$y}"  value="{$myreturnbuybillData->discounttype}" class="form-control getprototal numberonly enteraction numberinput txt-nonraduis positivefloat" tabindex="301"   {if {$billsettingsData[34]->billsettingsvalue} eq 1} type="text" {else}  type="hidden" {/if}/>
                                    </td>
                                    <td class="{if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billsettingsData[96]->billsettingsvalue eq 0&& $billnameAddData->productAndQuantityOnly eq 0}  {else} style="display:none !important;" {/if}>
                                        <input name="rowtaxval_re{$y}" id="rowtaxval_re{$y}" value="{$myreturnbuybillData->rowtaxval}" class="form-control return_getprototal numberonly enteraction numberinput txt-nonraduis positiveNo" placeholder="ضريبة" type="hidden"/>
                                        <input name="rowtaxper_re{$y}" id="rowtaxper_re{$y}"  value="{$myreturnbuybillData->rowtaxper}" class="form-control return_getprototal numberonly enteraction numberinput txt-nonraduis positiveNo" tabindex="7"  type="text" />
                                    </td>
                                    <td class="aw_totalprice_re {if $usergroup->hideBillPrices == 1}hidden{/if}" {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>
                                        <!--                                        <div id="prototal_re{$y}" class="aw_mt form-control-static">{$myreturnbuybillData->returnbuybilldetailtotalprice}{$myreturnbuybillData->buybilldetailtotalprice}{$currency}</div>
                                                                                <input name="hidden_prototal_re{$y}" id="hidden_prototal_re{$y}" type="hidden" value="{$myreturnbuybillData->returnbuybilldetailtotalprice}{$myreturnbuybillData->buybilldetailtotalprice}"  tabindex="301"/>-->

                                        <input  name="hidden_prototal_re{$y}" id="hidden_prototal_re{$y}" class="returnEditTotal form-control txt-nonraduis enteraction numberinput positiveNo" value="{$myreturnbuybillData->returnbuybilldetailtotalprice}{$myreturnbuybillData->buybilldetailtotalprice}" type="text"/>
                                    </td>
                                    <td>
                                        <button type="button" id="remove_re{$y}" class="removeproduct_re close flt-none" aria-hidden="true"  onclick="removeproduct_re({$y});">&times;</button>
                                    </td>
                                </tr>
                                {capture assign=y}{$y+1}{/capture}
                                {/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">0</div>
                            <input name="norbuyBillTotal_re"  id="norbuyBillTotal_re"  type="hidden"  value="" />
                        </span></button>
                </div>
            </div>


            <!-- =========================== END RETURN BUY BILL PANEL ======================== -->

            <!-- =========================== START TOTAL VALUES PANEL ======================= -->
            <div class="row {if $usergroup->hideBillPrices == 1}hidden{/if}">
                <div class="col-lg-7">
                    <div class="form-group mg-bt5" >
                        <label class="col-lg-1 control-label">المدفوع</label>
                        <div class="col-lg-3">
                            <input type="text" class="form-control positivefloat"  value="0" placeholder="المدفوع" name="genpay2" id="genpay2">
                        </div>
                    </div>
                    <!-- end of form-group-->

                    <div class="form-group mg-bt5">
                        <label class="col-lg-1 control-label">الباقى</label>
                        <div class="col-lg-3">
                            <p class="form-control-static" id="gen3total2">0 {$currency}</p>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5 {if {$billsettingsData[91]->billsettingsvalue} eq 1}  hidden {/if}">
                        <label class="col-lg-1 control-label">الاجمالي شامل ضريبة القيمة المضافة لمنتج واحد</label>
                        <div class="col-lg-3">
                            <input type="text" class="form-control positivefloat" id="vatIncludedTotalIfRow" value=""/>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5 "><!-- {if {$billsettingsData[91]->billsettingsvalue} eq 1}  hidden {/if} -->
                        <label class="col-lg-1 control-label">المرفقات</label>
                        <div class="col-lg-3">
                            <input type="file" id="multiupload" name="files[]" style="display: inline-block" multiple >
                            {assign var=i value=1}
                            {foreach $buyBillData->filesArr as $file}
                            {if $file != "" && $file !="." && $file !="no image"}
                            <a href="../upload/buyBillFiles/{$file}" target="_blank" style="color: blue;"> ({$i}) </a>
                            {assign var=i value=$i+1}
                            {/if}
                            {/foreach}
                            <input type="hidden" name="oldFiles" id="oldFiles" value="{$buyBillData->files}">
                        </div>
                    </div>
                </div>
                <!-- end of calucation center-->

                <div class="col-lg-5">
                    <hr/>
                    {if $controlname  eq "buyBillController.php"   or $controlname  eq "buyAndReturnBillController.php"}
                    <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">{$piecesCount}</p>
                        </div>
                    </div>
                    {/if}

                    {if $controlname  eq "returnBuyBillController.php"  or $controlname  eq "buyAndReturnBillController.php"}
                    <!-- 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">{$returnPiecesCount}</p>
                        </div>
                    </div>
                    {/if}
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5">
                        <label class="col-lg-5 control-label">الاجمالى العام</label>
                        <div class="col-lg-7">
                            <input type="hidden" name="totalbeforediscount" id="totalbeforediscount" value="{$buyBillData->buybilltotalbill}"/>
                            <p class="form-control-static" id="gentotal">0</p>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    {if $billsettingsData[44]->billsettingsvalue eq "0"}
                    <input type="hidden" name="discount_type" id="discount_type" value="0"/>
                    <div class="form-group mg-bt5" {if {$billsettingsData[57]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">نوع الخصم</label>
                        <div class="col-lg-7">
                            خصم مباشر
                        </div>
                    </div>
                    {elseif $billsettingsData[44]->billsettingsvalue eq 1}
                    <input type="hidden" name="discount_type" id="discount_type" value="1"/>
                    <div class="form-group mg-bt5" {if {$billsettingsData[57]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">نوع الخصم</label>
                        <div class="col-lg-7">
                            خصم بنسبه مئويه
                        </div>
                    </div>
                    {elseif $billsettingsData[44]->billsettingsvalue eq 2}
                    <div class="form-group mg-bt5" {if {$billsettingsData[57]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">نوع الخصم</label>
                        <div class="col-lg-7">
                            <select name="discount_type" id="discount_type" class="select2 wdt100" dir="rtl">
                                <option  {if {$buyBillData->buybilldiscountrype}   eq 0 or {$returnbuybillData->returnbuybilldiscountrype} eq 0} selected="selected" {/if} value="0">خصم مباشر</option>
                                <option {if {$buyBillData->buybilldiscountrype}   eq 1 or {$returnbuybillData->returnbuybilldiscountrype} eq 1} selected="selected" {/if}  value="1">خصم بنسبه مئويه</option>
                            </select>
                        </div>
                    </div>
                    {/if}

                    <!-- end of form-group-->
                    {assign var=buybilldiscount value=$buyBillData->buybilldiscount}
                    {assign var=returnbuybilldiscount value=$returnbuybillData->returnbuybilldiscount}
                    {if isset($billCurrData)}
                    {if isset($buyBillData)}{assign var=buybilldiscount value={$billCurrData->conversionFactor * $buybilldiscount}}{/if}
                    {if isset($returnbuybillData)}{assign var=returnbuybilldiscount value={$billCurrData->conversionFactor * $returnbuybilldiscount}}{/if}
                    {/if}
                    <div class="form-group mg-bt5"{if {$billsettingsData[57]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">قيمة الخصم</label>
                        <div class="col-lg-7"><span id="sprytextfield3">
                                <input name="gendis" id="gendis" class="form-control numberclic numberinput positivefloat"  value="{$buybilldiscount}{$returnbuybilldiscount}" type="text" placeholder="قيمة الخصم" />
                                <span class="textfieldRequiredMsg">*</span></span></div>
                    </div>
                    <!-- end of form-group-->

                    <!-- end of form-group-->
                    <div {if {$billsettingsData[89]->billsettingsvalue} eq 0} style="display:none"    {/if}>
                        <hr class="mg-tp5 mg-bt5"/>
                        <div class="form-group mg-bt5">
                            <label class="col-lg-5 control-label">ضريبه خصم  ({$buyBillData->taxOfDiscountPer}{$returnbuybillData->taxOfDiscountPer}%)</label>
                            <div class="col-lg-7">
                                <div class="input-group">
                                    <input type="hidden" name="taxOfDiscountPercentage" id="taxOfDiscountPercentage" value="{$buyBillData->taxOfDiscountPer}{$returnbuybillData->taxOfDiscountPer}"/>
                                    <input type="hidden" name="taxOfDiscountVal_h" id="taxOfDiscountVal_h" value="{$buyBillData->taxOfDiscountVal}{$returnbuybillData->taxOfDiscountVal}"/>
                                    <input type="text" name="taxOfDiscountVal" class="form-control numberinput positiveNo"  id="taxOfDiscountVal" value="{$buyBillData->taxOfDiscountVal}{$returnbuybillData->taxOfDiscountVal}" readonly/>
                                    <span class="input-group-addon">{$Programsettingdata->currancy}</span>
                                </div>
                            </div>
                        </div>
                    </div>

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

                                <div class="input-group">
                                    <input type="text" name="payedtax" id="payedtax" class="form-control numberinput"  value="{$buyBillData->payedtax}{$returnbuybillData->payedtax}" onkeyup="checkdisValue();"/>
                                    <span class="input-group-addon">%</span>
                                </div>
                                <div class="input-group" style="padding-top: 1px;">
                                    <input type="text" name="taxVal" class="form-control numberinput positiveNo"  id="taxVal" value="0" readonly/><!-- value is calculated in js no need to write it -->
                                    <span class="input-group-addon">{$Programsettingdata->currancy}</span>
                                </div>
                            </div>
                        </div>


                    </div>
                    <!------------------------------------------------------->



                    <hr class="mg-tp5 mg-bt5"/>
                    <div class="form-group mg-bt5" {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}{$returnbuybillData->returnbuybillaftertotalbill}</p>
                            <input type="hidden" name="totalafterdiscount" id="totalafterdiscount" value="{$buyBillData->buybillaftertotalbill}{$returnbuybillData->returnbuybillaftertotalbill}"/>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5" {if {$billsettingsData[54]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                        <label class="col-lg-5 control-label">المدفوع</label>
                        <div class="col-lg-7">
                            <input name="genpay" id="genpay"  class="form-control numberclic numberinput positivefloat" type="text"  value="{if isset($billCurrData->buybilltotalpayedC)||isset($billCurrData->returnbuybilltotalpayedC)}{$billCurrData->buybilltotalpayedC}{$billCurrData->returnbuybilltotalpayedC}{else}{$buyBillData->buybilltotalpayed}{$returnbuybillData->returnbuybilltotalpayed}{/if}"/>

                            <!--input name="oldpayed" id="oldpayed" type="text" value="{$buyBillData->buybilltotalpayed}{$returnbuybillData->returnbuybilltotalpayed}" /-->
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <hr class="mg-tp5 mg-bt5"/>
                    <div class="form-group mg-bt5 bg-yel" {if {$billsettingsData[55]->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="gen3total">{$buyBillData->buybillfinalbill}{$returnbuybillData->returnbuybillfinalbill}</p>
                        </div>
                    </div>
                    <!-- end of form-group-->
                    <div class="form-group mg-bt5" {if $billnameAddData->productAndQuantityOnly eq 1} style="display:none !important;" {/if}>
                        <label class="col-lg-5 control-label">باقى الدين</label>
                        <div class="col-lg-7">
                            <p class="form-control-static" id="gen4total">0</p>
                            <input type="hidden" name="supplierdebtafter" id="supplierdebtafter" value="0"/>
                        </div>
                    </div>
                    <!-- end of form-group-->
                </div>
                <!-- end of totals center-->
            </div>
            <!-- end of fourth row-->

            <input type="hidden" value="{$roundNumbersStatus}" id="round_numbers" name="round_numbers"/>
            <input type="hidden" value="{$noOfDecimalPlaces}" id="noOfDecimalPlaces" name="noOfDecimalPlaces"/>
            <div class="row">
                <button type="submit" id="saveBill" class="btn btn-primary">تعديل</button>
            </div>
            <br/>
            <div class="row">
                <style>
                    .unsufficient{
                        background-color: #f59a99 !important;
                    }
                    .note-warning{
                        background-color: #faeaa9;
                        border-color: #f3cc31;
                        color: #000;
                        border-right: 5px solid #f3cc31;
                        border-radius: 4px 0 0 4px;
                        margin: 0 0 20px;
                        padding: 15px 15px 15px 30px;
                    }
                </style>
                <input type="hidden" name="storenegative" id="storenegative" value="{$storenegative}"/>
                <div class="note-warning" style="display: none" id="check_store_div">
                    <h4 class="block" id="check_store_msg"></h4>
                </div>
            </div>
            <!-- end of fifth row-->

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

        <!-- Modal -->
        <input type="hidden" name="productAddMultiCatLevel" id="productAddMultiCatLevel" value="1"/>
        <div class="modal fade in" id="productModal2"  role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog"style="width: 910px;">
                <div class="modal-content bg-modal">
                    <div class="modal-header">
                        <button type="button" class="close pull-left" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title"> إضافة منتج</h4>
                    </div>
                    <div class="productForm">
                        <div class="modal-body ">{literal}
                            <form id="productInfo" action="#" method="post" class="nameToBeChecked form-horizontal" onsubmit="if (Spry.Widget.Form.validate(this)) {
                                        checkName(event, 'product', 'new_productName');
                                        insertIntoTemp(event);
                                    } else {
                                        return false;
                                    }">
                                {/literal}  <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">المنتج الرئيسي</label>
                                    <div class="col-lg-4"> <span id="spryselect4">
                                            <select name="new_cat_id" id="new_cat_id" data-placeholder="اختر" class="select2 aw_m1 productCat" tabindex="12">
                                                <option>-- اختر المنتج الرئيسي</option>

                                                {foreach $categoriesData as $cat}

                                                <option value="{$cat->productCatId}">{$cat->productCatName}</option>

                                                {/foreach}

                                            </select>
                                            <span class="selectRequiredMsg">*</span></span> </div>
                                </div>
                                <!---------------------------->

                                <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">الإسم </label>
                                    <div class="col-lg-4">
                                        <input name="new_productName" type="text" id="new_productName" size="50" class=" form-control " required   />
                                        <!----------- start nameError alert -------------->
                                        <div id="new_nameError" class="alert alert-block alert-danger fade in" style="display:none">
                                            <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">&times;</button>
                                            <h4>رسالة خطأ</h4>
                                            <p>هذا الإسم مستخدم من قبل</p>
                                            <div class="clearfix"></div>
                                        </div>
                                        <!----------- end nameError alert ------------->
                                    </div>


                                </div>



                                <!---------------------------->

                                <div class="form-group" {if {$billsettingsData[59]->billsettingsvalue} eq 0} {else}  style="display:none"    {/if}>
                                    <label for="inputEmail1" class="col-lg-2 control-label">الباركود</label>
                                    <div class="col-lg-4">
                                        <input name="new_parcode" type="text" id="new_parcode"  class=" form-control" size="50"   />
                                    </div>
                                </div>
                                <!---------------------------->

                                <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">سعر الشراء</label>
                                    <div class="col-lg-4">
                                        <input name="new_productBuyPrice" type="text" id="new_productBuyPrice" class="numberinput form-control" required size="50"   />
                                    </div>
                                </div>
                                <!---------------------------->

                                <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">سعر بيع الجمله</label>
                                    <div class="col-lg-4">
                                        <input name="new_productSellAllPrice" type="text" id="new_productSellAllPrice" class="numberinput form-control" onKeyUp="populateSellPrice();" required size="50"   />
                                    </div>
                                </div>
                                <!---------------------------->

                                <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">سعر بيع الجمله التجزئة</label>
                                    <div class="col-lg-4">
                                        <input name="new_productSellHalfPrice" type="text" id="new_productSellHalfPrice" class=" form-control numberinput" required size="50"   />
                                    </div>
                                </div>
                                <!---------------------------->

                                <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">سعر بيع الوحده</label>
                                    <div class="col-lg-4">
                                        <input name="new_productSellUnitPrice" type="text" id="new_productSellUnitPrice" class=" form-control numberinput" required size="50"   />
                                    </div>
                                </div>
                                <!---------------------------->

                                <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">الكمية</label>
                                    <div class="col-lg-4">
                                        <input name="new_productquantity" type="text" id="new_productquantity" class=" form-control numberinput"  required="required"   value="0" size="50"/>
                                    </div>
                                </div>
                                <!---------------------------->
                                <div class="form-group ">
                                    <label for="inputEmail1" class="col-lg-2 control-label">فى المنيو</label>
                                    <div class="col-lg-4">
                                        <label>
                                            <input value="0"  class="radioR" name="inMenu1"  checked="checked"  type="radio" />
                                            نعم </label>
                                        <label>
                                            <input value="1"  class="noradioR" name="inMenu1"     type="radio" />
                                            لا </label>
                                    </div>
                                </div>
                                <!---------------------------->

                                <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">س</label>
                                    <div class="col-lg-4">



                                        <label>
                                            <input value="1"  class="radioR" name="type1"   type="radio" />

                                            نعم </label>

                                        <label>
                                            <input value="0"  class="noradioR" name="type1"   checked="checked"  type="radio" />
                                            لا </label>



                                    </div>
                                </div>
                                <!---------------------------->






                                <div class="form-group">
                                    <label for="inputEmail1" class="col-lg-2 control-label">التاريخ</label>
                                    <div class="col-lg-4">
                                        <input name="new_productDate" type="text" id="new_productDate" class=" form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" size="50"  value="{$today}" required   />
                                    </div>
                                </div>
                                <!---------------------------->

                                <!--------------------------------  adding units   ----------------------------->

                                <div id="addUnitsDiv">
                                    <table id="unitsTable" class="table table-black">
                                        <tr id="unit_row1">
                                            <td>
                                                <div class="form-group">
                                                    <label for="inputEmail1" class="col-lg-4 control-label">اسم وحدة القياس</label>
                                                    <div class="col-lg-8">
                                                        <select name="productunit1" id="productunit1" data-placeholder="اختر" class="select2 aw_m1 chosenproduct"  tabindex="12">
                                                            <option value="-1">اختر وحدة القياس</option>







                                                            {foreach $unitsData as $unit}







                                                            <option value="{$unit->unitId}">{$unit->unitName}</option>







                                                            {/foreach}







                                                        </select>
                                                    </div>
                                                </div>
                                                <!---------------------------->
                                            </td>
                                            <td>
                                                <div class="form-group">
                                                    <label for="inputEmail1" class="col-lg-4 control-label">عدد الوحدات</label>
                                                    <div class="col-lg-8">
                                                        <input name="productnumber1" id="productnumber1" class="numberinput form-control" type="text" />
                                                    </div>
                                                </div>
                                                <!---------------------------->
                                            </td>
                                            <td><a id="remove1" onClick="removeUnits(1);" class="removeUnits">X</a></td>
                                        </tr>
                                    </table>
                                    <!--end unitsTable-->
                                </div>
                                <input class="addUnits btn btn-primary" onClick="addUnits();" type="button" value="إضافة وحدة قياس"/>
                                <input name="unitsItr" id="unitsItr" type="hidden" value="1" />

                                <!-------------------------------- end adding units   -------------------------->
                                </td>
                                <input name="newLinkCurrentId" id="newLinkCurrentId" type="hidden" value="" />
                                <!--        <input type="button" id="cancel" onClick="closeProductForm();" value="إلغاء" />
                          <input type="button" id="insert" onClick="insertIntoTemp();" value="إضافة" />
                                -->

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" id="cancel" onClick="closeProductForm();">إلغاء</button>
                            <button type="submit" class="btn btn-primary" id="insert" >حفظ</button>
                        </div>
                        </form>
                    </div>
                    <!-- /.productForm -->
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->

        <div id="productSelect" style="display:none;"> {foreach $categoriesData as $cat}
            <option value="{$cat->productCatId}">{$cat->productCatName}</option>
            {/foreach} </div>
        <div id="productUnitsDiv" style="display:none;">
            <option value="-1">اختر وحدة القياس</option>
            {foreach $unitsData as $unit}
            <option value="{$unit->unitId}">{$unit->unitName}</option>
            {/foreach} </div>
        <div id="productUnitsDiv_new" style="display:none;">
            <option value="-1">اختر وحدة القياس</option>
            {foreach $unitsData as $unit}
            <option value="{$unit->unitId}">{$unit->unitName}</option>
            {/foreach} </div>

        <!---================== END ADD PRODUCT MODAL BOX ==================--->

        <!---================== START NEW UNIT ROW  ==================--->
        <div id="unitsTableHidden" style="display:none !important;">
            <tr>
                <td>
                    <div class="form-group">
                        <label for="inputEmail1" class="col-lg-2 control-label">اسم وحدة القياس</label>
                        <div class="col-lg-4">
                            <select name="productunit1" id="productunit1" data-placeholder="اختر" class="select2 aw_m1 chosenproduct"  tabindex="12">
                                <option value="-1">اختر وحدة القياس</option>







                                {foreach $unitsData as $unit}







                                <option value="{$unit->unitId}">{$unit->unitName}</option>







                                {/foreach}







                            </select>
                        </div>
                    </div>
                    <!---------------------------->
                </td>
                <td>
                    <div class="form-group">
                        <label for="inputEmail1" class="col-lg-2 control-label">عدد الوحدات</label>
                        <div class="col-lg-4">
                            <input name="productnumber1" id="productnumber1" class="numberinput form-control" type="text" />
                        </div>
                    </div>
                    <!---------------------------->
                </td>
                <td><a id="remove1" onClick="removeUnits(1);" class="removeUnits">X</a></td>
            </tr>
        </div>
        <!---================== END NEW UNIT ROW  ==================--->

        <!-- ======================= Supplier Modal Box =========== -->
        <!-- Modal -->
        <div class="modal fade" id="supplierModal" tabindex="-1" role="dialog" aria-labelledby="supplierModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content bg-modal">
                    <div class="modal-header">
                        <button type="button" class="close pull-left" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">عنوان الرسالة</h4>
                    </div>
                    <div class="modal-body">
                        <form id="supplierInfo" action="#" method="post" class="form-horizontal">
                            <div class="form-group">
                                <label class="col-lg-2 control-label">اسم المورد</label>
                                <div class="col-lg-4"> <span id="sprytextfield1">
                                        <input name="txtName" type="text" id="sup_txtName"  class="form-control"/>
                                        <span class="textfieldRequiredMsg">*</span></span> </div>
                            </div>
                            <!------------------------------>

                            <div class="form-group">
                                <label class="col-lg-2 control-label">العنوان</label>
                                <div class="col-lg-4">
                                    <input name="txtAddress" type="text" id="sup_txtAddress"  class="form-control"/>
                                </div>
                            </div>
                            <!------------------------------>
                            <div class="form-group">
                                <label class="col-lg-2 control-label">رقم التليفون</label>
                                <div class="col-lg-4">
                                    <input name="txtPhone" type="text" id="sup_txtPhone"  class="numberinput form-control"/>
                                </div>
                            </div>
                            <!------------------------------>

                            <div class="form-group">
                                <label class="col-lg-2 control-label">قيمة المديونية</label>
                                <div class="col-lg-4"> <span id="sprytextfield2">
                                        <input type="text" name="txtDebt" id="sup_txtDebt" class="numberinput  form-control" />
                                        <span class="textfieldRequiredMsg">يرجى إدخال رقم صحيح</span><span class="textfieldInvalidFormatMsg">*</span></span> </div>
                            </div>
                            <!------------------------------>
                            <div class="form-group">
                                <label class="col-lg-2 control-label">تفاصيل أخرى</label>
                                <div class="col-lg-4">
                                    <textarea name="textDetails" cols="" rows="" id="sup_textDetails"  class="form-control"></textarea>
                                </div>
                            </div>
                            <!------------------------------>

                            <!--  <div class="form-group">
                                <div class="col-lg-offset-2 col-lg-4">
                                  <input type="button" id="cancel" onClick="closeSupplierForm();" class="btn btn-error pull-left" value="إلغاء" />
                                  <input type="button" id="insert" onClick="insertSupplier();" class="btn btn-primary pull-left" value="إضافة" />
                                </div>
                              </div>-->
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" id="cancel" onClick="closeSupplierForm();">اغلاق</button>
                        <button type="button" id="insert" class="btn btn-primary savemodel_supplier"  onClick="insertSupplier();" >حفظ</button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->
        <!-- ============================================= -->
        <!-- ======================= Supplier Modal Box =========== -->
        <!-- Modal -->
        <div class="modal fade" id="proPriceUpdateModal" tabindex="-1" role="dialog" aria-labelledby="proPriceUpdateModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content bg-modal">
                    <div class="modal-header">
                        <button type="button" class="close pull-left" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">تم تعديل سعر شراء المنتج تحديث الاسعار؟</h4>
                    </div>
                    <div class="modal-body">
                        <form id="proPriceInfo" action="#" method="post" class="form-horizontal">

                        </form>
                        <input type="hidden" id="showProPriceUpdateModalIfBuyPriceChange" value="{$billsettingsData[95]->billsettingsvalue}"/>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">اغلاق</button>
                        <button type="button" class="btn btn-primary" data-rowItr="" id="saveProPricesBtn" >حفظ</button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->
        <!-- ============================================= -->

    </div>
</div>
{literal}
<script type="text/javascript">
    var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {isRequired: false, invalidValue: "-1"});
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    //var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2", {isRequired:false, invalidValue:"-1"});
    //var spryselect3 = new Spry.Widget.ValidationSelect("spryselect3");
    var spryselect4 = new Spry.Widget.ValidationSelect("spryselect4");</script>
<script type="text/javascript">
    var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
</script>
{/literal}