
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">المنتجات</a></li>
            <li><a href="#">المنتجات </a></li>
            <li class="active">تعديل منتج</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">
                <h3 class="panel-title">تعديل منتج</h3>
            </div>
            <div class="panel-body">
                <input type="hidden" id="searchvalue" value="0"/>
                <input type="hidden" id="changeBuyPriceChangeSellInProductCtrl" value="{$Programsettingdata->changeBuyPriceChangeSellInProductCtrl}"/>
                <input type="hidden" id="productBuyPrice1Old" value="{$productsData->productBuyPrice}" />
                {literal}
                <form class="nameToBeChecked form-horizontal" id="productEditForm" action="productController.php?do=update"  method="post" enctype="multipart/form-data"
                      onsubmit="
                              if ($('#productName1').val() == '') {
                                  return false;
                              }
                              //                        if (checkNameWithId(event, 'product', 'productName1', 'productId')) {
                              //                            return true;
                              //                        } else {
                              //                            return false;
                              //                        }
                      ">
                    <!--validate the form before checking name-->
                    {/literal}
                    <input type="hidden" id="ebillsetting" value="{$Programsettingdata->ebill}">
                    <input name="productId" id="productId" type="hidden" value="{$productsData->productId}" />
                    <input name="level" id="level" type="hidden" value="1" />
                    <input name="productCatId0" id="productCatId0" type="hidden" value="{$productsData->productCatId}" />

                    <div class="form-group">
                        <label class="col-lg-2 control-label">تصنيف المنتج</label>
                        <div class="col-lg-4"> <span id="spryselect1">
                                <select name="productCatId" data-placeholder="" class="select2 wdt100" tabindex="1">
                                    <option value="-1">اختر المنتج الرئيسي</option>
                                    {foreach $alldata as $data }
                                    <option value="{$data->productCatId}" {if $productsData->productCatId eq $data->productCatId}selected{/if}>{$data->productCatName}</option>
                                    {/foreach}
                                </select>
                                <span class="selectInvalidMsg">اختر تصنيف</span><span class="selectRequiredMsg">اختر تصنيف</span></span> </div>
                    </div>
                    <a class="btn pull-left btn-primary " id="reCalcUnitPrices"><u>تعديل اسعار الوحدات</u></a>
                    <input type="hidden" name="dailyentryid" value="{$productsData->dailyentryid}"/>

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

                    <table id="product_Table"  class="table table-black">
                        <tr>
                            <td colspan="2">الإسم</td>

                            <td >سعر الشراء</td>
                            <td >الخصم المرجح</td>
                            <td >سعر الشراء الفعلى</td>
                            <td>سعر الجمله</td>
                            <td >سعر  نصف الجمله </td>
                            <td>سعر التجزئة</td>
                        </tr>
                        <tr >

                            <td  colspan="2"><span id="sprytextfield7">


                                    <!--<input name="productName1" type="text" id="productName1" size="9" value="{$productsData->productName}" class="form-control" onchange="checkProductNameForEdit($('#productName1').val(), $('#productId').val(), $('#productCatId0').val())"/>-->
                                    <textarea name="productName1" id="productName1" class="form-control" onchange="checkProductNameForEdit($('#productName1').val(), $('#productId').val(), $('#productCatId0').val())" rows="2">{$productsData->productName}</textarea>
                                    <span class="textfieldRequiredMsg">*</span></span>
                                <div id="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>
                                    <p>هذا الاسم مستخدم من قبل</p>
                                    <div class="clearfix"></div>
                                </div>
                            </td>

                            <td><span id="sprytextfield1">
                                    <input name="productBuyPrice1" data-id="1" type="text" id="productBuyPrice1" class="form-control wd50 aw_m aw_mt aw_pp numberclic buy_price enteraction numberinput"  value="{$productsData->productBuyPrice}" />
                                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">أدخل رقم</span></span></td>
                            <td><span id="sprytextfield1">
                                    <input name="weightedDiscount1" disabled data-id="1" type="text" id="weightedDiscount1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput"  value="{$productsData->weightedDiscount}" />
                                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">أدخل رقم</span></span></td>
                            <td><span id="sprytextfield1">
                                    <input style="width: 50%;float: left;" name="productbuypricereal1" value="{$productsData->productbuypricereal}" type="text" id="buypricereal1"  data-type="pricereal"  class="form-control prices  aw_m aw_mt aw_pp numberclic enteraction  numberinput positivefloat buy_pricereal1" data-id="1" width="10"/></span>
                                <input style="  width: 50%;"  name="buypricereal_precentage1"  value="{$productsData->buypricereal_precentage|floatval}" type="text" id="productBuyPrice1" data-type="pricereal" tabindex="-1"  readonly class="form-control precentages success  aw_m aw_mt aw_pp numberclic enteraction  numberinput positivefloat buypricereal_precentage1" data-id="1" width="10" />

                                <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">أدخل رقم</span></span></td>
                            <td><span id="sprytextfield2">
                                    <input style="width: 50%;float: left;" name="productSellAllPrice1" type="text" id="productSellAllPrice" data-type="buytotal"  class="form-control prices aw_m aw_mt aw_pp numberclic positivefloat buy_total1 enteraction numberinput" value="{$productsData->productSellAllPrice}" data-id="1" width="10"/>
                                    <input style="  width: 50%;"  name="buytotal_precentage1" type="text"  value="{$productsData->buytotal_precentage|floatval}" id="productBuyPrice1"   data-type="buytotal" tabindex="-1"  readonly class="form-control  aw_m aw_mt aw_pp numberclic enteraction precentages success numberinput positivefloat buytotal_precentage1" data-id="1" width="10"/>
                                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">أدخل رقم</span></span></td>
                            <td><span id="sprytextfield3">
                                    <!--<input name="productSellHalfPrice1"   type="text" id="productSellHalfPrice1"  class="form-control wd50 aw_m aw_mt aw_pp numberclic buy_hafe1 enteraction numberinput"  value="{$productsData->productSellHalfPrice}" />-->
                                    <input  style="width: 50%;float: left;"  name="productSellHalfPrice1" type="text" data-type="buyhalf" id="productSellHalfPrice" value="{$productsData->productSellHalfPrice}"   class="form-control  aw_m aw_mt aw_pp numberclic prices enteraction numberinput positivefloat buy_hafe1" data-id="1" width="10"/>
                                    <input style="  width: 50%;"  name="buyhalf_precentage1" type="text" id="productBuyPrice1"  value="{$productsData->buyhalf_precentage|floatval}"   data-type="buyhalf" tabindex="-1"  readonly class="form-control  aw_m aw_mt aw_pp numberclic enteraction  precentages success numberinput positivefloat buyhafe_precentage1" data-id="1" width="10"/>

                                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">أدخل رقم</span></span></td>
                            <td><span id="sprytextfield4">
                                    <!--<input name="productSellUnitPrice1"   type="text" id="productSellUnitPrice1" class="form-control wd50 aw_m aw_mt aw_pp numberclic buy_part1 enteraction numberinput"   value="{$productsData->productSellUnitPrice}"/>-->
                                    <input  style="width: 50%;float: left;" name="productSellUnitPrice1" type="text" data-type="buypart"  id="productSellUnitPrice"  class="form-control  aw_m aw_mt aw_pp numberclic prices enteraction numberinput positivefloat buy_part1"   value="{$productsData->productSellUnitPrice}" data-id="1"  width="20"/>
                                    <input style="  width: 50%;"  name="buypart_precentage1" type="text" id="productBuyPrice1" data-type="buypart"   value="{$productsData->buypart_precentage|floatval}" tabindex="-1"  readonly class="form-control  aw_m aw_mt aw_pp numberclic enteraction precentages success numberinput positivefloat buypart_precentage1" data-id="1" width="10"/>
                                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">أدخل رقم</span></span></td>
                        </tr>
                        <tr>
                            <td class=" check_tr {if {$Programsettingdata->parcode} eq 1} hidden {/if}">الباركود</td>
                            <td {if {$Programsettingdata->expiredate} eq 1} hidden {/if}> مدة الصلاحية</td>
                            <td >الكمية</td>
                            <td class="{if {$Programsettingdata->date} eq 1} hidden {/if}">التاريخ</td>
                            <td  class=" {if {$Programsettingdata->limitamount} eq 1} hidden {/if}">الحد الأدنى للمنتج</td>
                            <td class="{if $Programsettingdata->isCaf != 1 && $Programsettingdata->isRestaurent != 1} hidden {/if}">فى المنيو</td>
                            <td>إخفاء</td>
                        </tr>
                        <tr>
                            <td class=" check_tr {if {$Programsettingdata->parcode} eq 1} hidden {/if}">
                                <input name="parcode1" type="text" required id="parcode1" size="9" value="{$productsData->parcode}" class="form-control" onblur="checkbarcodewithid(this.value, 1);"/>
                            </td>
                            <td {if {$Programsettingdata->expiredate} eq 1} hidden {/if}><input name="expireDate1" type="text" required  id="expireDate1" size="9" class="form-control" value="{$productsData->expireDate}" style="width: 71%;"> <span style="float: left;margin-top: -27px; color: white;font-size: 15px;font-weight: bold;">يوم</span></td>
                            <td><span id="sprytextfield5">
                                    <input name="productquantity1" readonly="readonly"  type="text" id="productquantity1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->sumProductQuantity}"/>
                                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">أدخل رقم</span></span></td>
                            <td  class="{if {$Programsettingdata->date} eq 1} hidden {/if}">
                                <input name="productDate1"  type="text" id="productDate1" size="9"  value="{$productsData->productDate}" required class="form-control awdatepicker" autocomplete="off"  data-date-format="yyyy-mm-dd"/>
                            </td>
                            <td class=" {if {$Programsettingdata->limitamount} eq 1} hidden {/if}"><span id="sprytextfield6">
                                    <input name="limitamount1"   type="text" id="limitamount1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->limitamount}"/>
                                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">أدخل رقم</span></span></td>
                            <td class="{if $Programsettingdata->isCaf != 1 && $Programsettingdata->isRestaurent != 1} hidden {/if}">
                                <div class="form-group">
                                    <div class="col-lg-12">
                                        <div class="radio-inline">
                                            <label>
                                                <input value="0"  class="radioR" name="inMenu1"   type="radio"  {if {$productsData->inMenu} eq 0} checked="checked"  {/if} />

                                                نعم </label>
                                        </div>
                                        <div class="radio-inline">
                                            <label>
                                                <input value="1"  class="noradioR" name="inMenu1"   type="radio" {if {$productsData->inMenu} eq 1} checked="checked"  {/if} />
                                                لا </label>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="form-group">
                                    <div class="col-lg-12">
                                        <div class="radio-inline">
                                            <input name="conditions" type="radio" value="1" {if {$productsData->
                                            conditions} eq 1} checked="checked" {/if} />
                                            نعم
                                            </label>
                                        </div>
                                        <div class="radio-inline">
                                            <label>
                                                <input name="conditions" type="radio" {if {$productsData->
                                                conditions} eq 0} checked="checked" {/if} value="0" />
                                                لا</label>
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>

                        <tr>
                            <td>متوسط سعر الشراء</td>
                            <td>متوسط سعر الشراء مع الخصم</td>
                            <td>متوسط سعر الشراء شامل القيمة المضافة</td>
                            <td>المتوسط العام</td>
                            <td>اخر سعر شراء</td>
                            <td>اخر سعر شراء مع الخصم</td>
                            <td>اخر سعر شراء شامل القيمة المضافة</td>
                        </tr>
                        <tr>
                            <td>
                                <input name="meanbuyprice1"  type="text" id="meanbuyprice1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->meanbuyprice}"/>
                            </td>
                            <td>
                                <input name="meanbuyprice_withDiscount1"  type="text" id="meanbuyprice_withDiscount1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->meanbuyprice_withDiscount}"/>
                            </td>
                            <td>
                                <input name="meanbuyprice_withTax1"  type="text" id="meanbuyprice_withTax1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->meanbuyprice_withTax}"/>
                            </td>
                            <td>
                                <input name="overAllAveragePrice1" type="text" id="overAllAveragePrice1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->overAllAveragePrice}"/>
                            </td>
                            <td>
                                <input name="lastbuyprice1" type="text" id="lastbuyprice1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->lastbuyprice}"/>
                            </td>
                            <td>
                                <input name="lastbuyprice_withDiscount1" type="text" id="lastbuyprice_withDiscount1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->lastbuyprice_withDiscount}"/>
                            </td>
                            <td>
                                <input name="lastbuyprice_withTax1" type="text" id="lastbuyprice_withTax1" class="form-control wd50 aw_m aw_mt aw_pp numberclic enteraction numberinput" value="{$productsData->lastbuyprice_withTax}"/>
                            </td>
                        </tr>
                        <tr>
                            <td   colspan="3" class="check_tr_description {if {$Programsettingdata->description} eq 1} hidden {/if}">التعليق</td>
                            <td>خدمة</td>
                            <td class=" check_tr_production {if {$Programsettingdata->production} eq 1} hidden {/if}">تصنيع</td>
                            <td class=" {if {$Programsettingdata->ebill} neq 1} hidden {/if}">نوع الباركود الضريبى</td>
                            <td class=" {if {$Programsettingdata->ebill} neq 1} hidden {/if}">الباركود الضريبى</td>
                        </tr>
                        <tr>
                            <td   colspan="3" class=" check_tr_description {if {$Programsettingdata->description} eq 1} hidden {/if}">
                                <textarea name="productDescription1" id="productDescription1" cols="20" rows="5" class="form-control">{$productsData->productDescription}</textarea>
                            </td>
                            <td>
                                <div class="form-group">
                                    <div class="col-lg-12">
                                        <div class="radio-inline">
                                            <label>
                                                <input value="1"  class="radioR" name="isService"   type="radio"  {if {$productsData->isService} eq 1} checked="checked"  {/if} />

                                                نعم </label>
                                        </div>
                                        <div class="radio-inline">
                                            <label>
                                                <input value="0"  class="noradioR" name="isService"   type="radio" {if {$productsData->isService} eq 0} checked="checked"  {/if} />
                                                لا </label>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class=" check_tr_production {if {$Programsettingdata->production} eq 1} hidden {/if}">
                                <div class="form-group">
                                    <div class="col-lg-12">
                                        <div class="radio-inline">
                                            <label>
                                                <input value="1"  class="radioR" name="type"   type="radio"  {if {$productsData->type} eq 1} checked="checked"  {/if} />

                                                نعم </label>
                                        </div>
                                        <div class="radio-inline">
                                            <label>
                                                <input value="0"  class="noradioR" name="type"   type="radio" {if {$productsData->type} eq 0} checked="checked"  {/if} />
                                                لا </label>
                                        </div>
                                    </div>
                                </div>
                            </td>

                            <td class=" {if {$Programsettingdata->ebill} neq 1} hidden {/if}">

                                <div class="form-group">
                                    <div class="col-lg-12">
                                        <div class="radio-inline">
                                            <label>
                                                <input value="GS1" class="noradioR" name="TypeOfBarcodeInTax" type="radio" {if {$productsData->TypeOfBarcodeInTax} eq 'GS1'} checked="checked"  {/if} />
                                                GS1 </label>
                                        </div>

                                        <div class="radio-inline">
                                            <label>
                                                <input value="EGS"  class="radioR" name="TypeOfBarcodeInTax"   type="radio"  {if {$productsData->TypeOfBarcodeInTax} eq 'EGS'} checked="checked"  {/if} />

                                                EGS </label>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td class=" {if {$Programsettingdata->ebill} neq 1} hidden {/if}">

                                <input name="barcodeInTax" type="text" id="barcodeInTax" class="form-control" autocomplete="off" value="{$productsData->barcodeInTax}">
                            </td>

                        </tr>
                        <tr>
                            <td   colspan="3">صورة</td>
                            <td  colspan="3">حساب الشجرة</td>
                        </tr>
                        <tr>
                            <td   colspan="3">
                                {if $productsData->logo !="" &&$productsData->logo!="."}<img src="../views/default/images/product_image/{$productsData->logo}" alt="" width="{$productsData->displayWidth}" height="{$productsData->displayHeight}" style="cursor: pointer;" onclick="window.open($(this).attr('src'))" / > {/if}
                                <input type="file" name="logo" id="logo" class="form-control" placeholder="صورة" />
                                <input type="hidden" name="oldlogo" id="oldlogo"  value="{$productsData->logo}" /></td>
                            <td  colspan="3">
                                <select class="select2" name="treeId" id="treeId">
                                    {$myhtml}
                                </select>
                            </td>
                        </tr>

                        {if $Programsettingdata->importproduct eq 1}
                        <tr >
                            <td colspan="1">E الإسم</td>
                            <td colspan="1">كود</td>
                            <td colspan="1">رقم القطعة</td>
                            <td colspan="1">نوع السياره</td>
                            <td colspan="2">الشركه المنتجه للصنف    </td>
                            <td colspan="1">وزن</td>
                            <td colspan="1">منشأ</td>
                            <td colspan="1">رمز النظام المنسق</td>
                            <td colspan="1">صلاحيه</td>
                            <td colspan="1" class="power1">تاريخ الانتاج</td>
                            <td colspan="1" class="power1">مدة الصلاحيه</td>


                        </tr>
                        <tr>

                            <td colspan="1">
                                <input name="productNameE1" type="text" id="productNameE1" width="100%"   class="form-control" data-itra="1" data-id="1"  value="{$productsData->partNumber}">
                            </td>
                            <td colspan="1">
                                <input name="procode1"  type="text" id="procode1" width="100%"   class="form-control" data-itra="1" data-id="1" value="{$productsData->procode}">
                            </td>
                            <td colspan="1">
                                <input name="partNumber1"  type="text" id="partNumber1" width="100%"   class="form-control positivefloat" data-itra="1" data-id="1"  value="{$productsData->partNumber}">
                            </td>
                            <td colspan="1">
                                <select name="vehicleType1" id="vehicleType1"  class="select2 wdt100 vehicleType" >
                                    <option value="-1">اختر</option>
                                    {foreach $vehicletypes as $vehicle}
                                    <option value="{$vehicle->id}" {if $productsData->vehicleType eq $vehicle->id}selected{/if}>{$vehicle->typename}</option>
                                    {/foreach}
                                </select>


                            </td>
                            <td colspan="2">
                                <select name="company1" id="company1"  class="select2 wdt100 vehicleType" data-id="1" data-itra="1" >
                                    <option value="-1">اختر</option>
                                    {foreach $companyproduces as $company}
                                    <option value="{$company->id}" {if $productsData->company eq $company->id}selected{/if}>{$company->companyname}</option>
                                    {/foreach}
                                </select>
                            </td>
                            <td colspan="1">
                                <input name="weight1" type="text" id="weight1" width="100%"   class="form-control positivefloat" data-itra="1" data-id="1"  value="{$productsData->weight}">
                            </td>
                            <td colspan="1">
                                <input name="origin1" type="text" id="origin1" width="100%"   class="form-control" data-itra="1" data-id="1"  value="{$productsData->origin}">
                            </td>
                            <td colspan="1">
                                <input name="hscode1" type="text" id="hscode1" width="100%"   class="form-control positivefloat" data-itra="1" data-id="1"  value="{$productsData->hscode}">
                            </td>
                            <td colspan="1">
                                <div class="form-group" style="font-size:13px">
                                    <label class='color-black'>
                                        <input value="0"  class="power" data-itra="1" name="power1" {if {$productsData->power} eq 0} checked="checked"  {/if}   type="radio"  data-id="1"/>
                                        نعم </label>

                                    <label class='color-black'>
                                        <input value="1"  class="power"  data-itra="1" name="power1" type="radio" data-id="1" {if {$productsData->power} eq 1} checked="checked"  {/if} />
                                        لا </label>
                                </div>
                            </td>
                            <td colspan="1" class="power1">
                                <input name="ProductionDate1" type="text" id="ProductionDate1" width="100%"   class="form-control awdatepicker" data-date-format="yyyy-mm-dd"  data-itra="1" data-id="1"  value="{$productsData->ProductionDate}">
                            </td>
                            <td colspan="1" class="power1">
                                <input name="expiry1"  type="text" id="expiry1" width="100%"   class="form-control positivefloat" data-itra="1" data-id="1"  value="{$productsData->expiry}">
                            </td>
                        </tr>
                        {/if}
                        <tr>
                            <td colspan="10"><!--------------------------------  adding units   ----------------------------->

                                <div id="addUnitsDiv1" class="{if {$Programsettingdata->measuringunit} eq 1} hidden {/if}">
                                    <div class="table-responsive">
                                        <table id="unitsTable1"  class="table table-black" >
                                            {assign var=j value=1}
                                            {foreach $productUnitsData as $proUnit}
                                            <tr>
                                                <td>
                                                    <div>
                                                        <label class="control-label">وحدة القياس</label>
                                                        <select name="productunit1_disabled{$j}" id="productunit1_disabled{$j}" disabled="disabled" data-placeholder="اختر" class="select2 wdt100 aw_m1 chosenproduct"  tabindex="12">
                                                            <option value="-1">اختر وحدة القياس</option>


                                                            {foreach $unitsData as $unit}
                                                            <option value="{$unit->unitId}" {if $proUnit->unitid eq $unit->unitId}selected{/if}>{$unit->unitName}</option>

                                                            {/foreach}


                                                        </select>
                                                        <input name="productunit1{$j}" id="productunit1{$j}" type="hidden" value="{$proUnit->unitid}" />
                                                        <input name="productunitid{$j}" id="productunitid{$j}" type="hidden" value="{$proUnit->productunitid}" />
                                                    </div>
                                                </td>
                                                <td>
                                                    <div>
                                                        <label class="control-label">عدد الوحدات</label>
                                                        <input name="productnumber1{$j}" readonly="readonly"  id="productnumber1{$j}" type="text" value="{$proUnit->productnumber}" class="form-control"/>
                                                    </div>
                                                </td>
                                                <td class=" {if {$Programsettingdata->ebill} neq 1} hidden {/if}">
                                                    <div>
                                                        <label class="control-label"> وحدة القياس الضريبية </label>
                                                        <input name="unitInTax1{$j}"  id="unitInTax1{$j}" class="unitInTaxClass" type="hidden" value="{$proUnit->unitInTax}" data-old="{$proUnit->unitInTax}"/>
                                                    </div>
                                                </td>
                                                <td>
                                                    <div>
                                                        <label class="control-label">الباركود</label>
                                                        <input name="proUnitParcode1{$j}" id="proUnitParcode1{$j}" type="text" class="form-control numberinput positiveNo" value="{$proUnit->proUnitParcode}" data-unit-itr="1{$j}" data-unitid-itr="{$j}" onblur="checkUnitbarcodewithid(this.value, $(this).data('unitid-itr'), $(this).data('unit-itr'));"/>
                                                    </div>
                                                </td>
                                                <td>
                                                    <div>
                                                        <label class="control-label">سعر الشراء</label>
                                                        <input name="proUnitBuyPrice1{$j}" id="proUnitBuyPrice1{$j}" type="text" class="form-control positivefloat" value="{$proUnit->proUnitBuyPrice}"/>
                                                    </div>
                                                </td>
                                                <td>
                                                    <div>
                                                        <label class="control-label">سعر الجملة</label>
                                                        <input name="proUnitSellAllPrice1{$j}" id="proUnitSellAllPrice1{$j}" type="text" class="form-control positivefloat" value="{$proUnit->proUnitSellAllPrice}"/>
                                                    </div>
                                                </td>
                                                <td>
                                                    <div>
                                                        <label class="control-label">سعر نص جملة</label>
                                                        <input name="proUnitSellHalfPrice1{$j}" id="proUnitSellHalfPrice1{$j}" type="text" class="form-control positivefloat" value="{$proUnit->proUnitSellHalfPrice}"/>
                                                    </div>
                                                </td>
                                                <td>
                                                    <div>
                                                        <label class="control-label">سعر قطاعى</label>
                                                        <input name="proUnitSellUnitPrice1{$j}" id="proUnitSellUnitPrice1{$j}" type="text" class="form-control positivefloat" value="{$proUnit->proUnitSellUnitPrice}"/>
                                                    </div>
                                                </td>
                                                <td><a id="remove1{$j}"  onclick="removeUnits(1, {$j});" class="removeUnits">X</a></td>
                                            </tr>
                                            {capture assign=j}{$j+1}{/capture}
                                            {/foreach}
                                        </table>
                                    </div>
                                    <!--end unitsTable-->
                                    </                            div>
                                    <input                            class="addUnits btn btn-warning  {if {$Programsettingdata->measuringunit} eq 1} hidden {/if}" onClick="addUnits(1);" type="button"  value="إضافة وحدة قياس"/>
                                    <input name="unitsItr1" id="unitsItr1" type="hidden" value="{$countProductUnits}" />

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

                                    <input name="productItr" id="productItr" type="hidden" value="1" />
                            </td>
                        </tr>
                        {if $isCollective == 1}
                        <tr>
                            <td colspan="10"><!--------------------------------  adding units   ----------------------------->
                                <input type="hidden" name="searchvalue" id="searchvalue" value="{$Programsettingdata->searchvalue}"/>
                                <div class="panel panel-default panel-m">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">المكونات</h3>
                                        <input type="hidden" name="isCollective" id="isCollective" value="1"/>
                                    </div>
                                    <div class="panel-body">
                                        <div class="row">
                                            <input type="hidden" name="rowitr" id="rowitr" value="{$noOfRows}" />
                                            <input type="hidden" name="notRawMaterialsOnly" id="notRawMaterialsOnly" value="1"/>
                                            <div class="col-lg-12">
                                                <button type="button" name="addrow" id="addrow" class="btn btn-primary pull-left ft-nor"> اضافة </button>
                                                <button type="button" style="display:none;" name="addrow" id="addrow" class="btn btn-primary pull-left ft-nor" onclick="addrow();"> اضافة جديد</button>
                                            </div>

                                        </div>
                                        <table class="table billtable table-bordered table-black col-lg-4" id="table">
                                            <thead>
                                                <tr>
                                                    <th class="wdt400">المنتجات الخام</th>
                                                    <th  class="wdt200"><span class="sr-only">وحدة القياس</span></th>
                                                    <!--<th  class="wdt200">نسبة المشاركة </th>-->
                                                    <th  class="wdt200" >عدد الوحدات</th>
                                                    <th class="wdt200">حذف</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                {assign var=i value=1}
                                                {assign var=y value=1}
                                                {foreach $Productionrateproduct as $x}
                                                <tr>
                                                    <td ><input type="hidden" name="productionRateProductId{$i}" id="productionRateProductId{$i}"  value="{$x->productionRateProductId}"/>

                                                        <!--  <input type="hidden"  class="select2RawMaterials wdt300" name="product{$i}" id="product{$i}" data-placeholder=" اختر منتج خام"  />-->

                                                        <!--               <input type="hidden"   name="oldproduct{$i}" id="oldproduct{$i}" value="{$x->productId}"  />
                                                                                          <input type="hidden"   name="oldproductname{$i}" id="oldproductname{$i}" value="{$x->productName}"  />-->

                                                        <select class="select2 wdt300" name="product{$i}" id="product{$i}" >


                                                            {foreach $rows as $material}
                                                            <option value="{$material->productId}"

                                                                    {if {$material->productId}=={$x->ingridientId}}selected="selected"{/if} >{$material->productName}</option>
                                                            {/foreach}


                                                        </select>
                                                    </td>
                                                    <td>
                                                        <div id="unitDiv{$i}">
                                                            <select name="unitId{$i}" id="unitId{$i}" class="select2 wdt300">
                                                                {foreach $productUnitData{$y} as $myUnit}
                                                                <option value="{$myUnit->productunitid}" data-pronum="{$myUnit->productnumber}"
                                                                        {if {$myUnit->productunitid}=={$x->unitId}}selected="selected"{/if}

                                                                    >{$myUnit->unitName}</option>

                                                                {/foreach}
                                                            </select>
                                                            <input type="hidden" name="productBuyPrice{$i}" id="productBuyPrice{$i}" value="{$x->productBuyPrice}"/>
                                                            <input type="hidden" name="lastbuyprice{$i}" id="lastbuyprice{$i}" value="{$x->lastbuyprice}"/>
                                                            <input type="hidden" name="lastbuyprice_withDiscount{$i}" id="lastbuyprice_withDiscount{$i}" value="{$x->lastbuyprice_withDiscount}"/>
                                                            <input type="hidden" name="meanbuyprice{$i}" id="meanbuyprice{$i}" value="{$x->meanbuyprice}"/>
                                                            <input type="hidden" name="meanbuyprice_withDiscount{$i}" id="meanbuyprice_withDiscount{$i}" value="{$x->meanbuyprice_withDiscount}"/>
                                                        </div>

                                                        <!--<input type="hidden"   name="oldUnit{$i}" id="oldUnit{$i}" value="{$x->unitId}"  />
                                                                            <input type="hidden"   name="oldUnitName{$i}" id="oldUnitName{$i}" value="{$x->unitName}"  /> -->
                                                    </td>
                                                    <!--                                    <td><div id="table">
                                                                                                <input type="text" name="input{$i}" id="input{$i}"  class="form-control check" value="{$x->rate}" tabindex=""  />
                                                                                            </div></td>-->
                                                    <td><div id="table">
                                                            <input  name="inputt{$i}" id="inputt{$i}"  class="form-control positive" value="{$x->quantity}" tabindex="" />
                                                        </div></td>
                                                    <td id="{$i}">
                                                        <button id="remove{$i}" name="remove{$i}" type="button" class="close flt-none removeicon removeproduct"  aria-hidden="true" onclick="removerow();">&times;</button>
                                                    </td>
                                                </tr>
                                                {capture assign=i}{$i+1}{/capture}
                                                {capture assign=y}{$y+1}{/capture}
                                                {/foreach}
                                            </tbody>
                                        </table>
                                        <p>&nbsp; </p>
                                        <div>
                                            <!--h4><u>حساب تكلفة المنتج من المكونات</u></h4-->
                                            <button type="button" class="btn btn-primary ft-nor"> التكلفة بسعر الشراء
                                                <span class="badge wht-clo"><div id="productBuyPrice">{$productsData->productBuyPrice}</div></span></button>
                                            &nbsp;
                                            <button type="button" class="btn btn-primary ft-nor"> التكلفة باخر سعر شراء
                                                <span class="badge wht-clo"><div id="lastbuyprice">{$productsData->lastbuyprice}</div></span></button>
                                            &nbsp;
                                            <button type="button" class="btn btn-primary ft-nor"> التكلفة باخر سعر شراء مع الخصم
                                                <span class="badge wht-clo"><div id="lastbuyprice_withDiscount">{$productsData->lastbuyprice_withDiscount}</div></span></button>
                                            &nbsp;
                                            <button type="button" class="btn btn-primary ft-nor"> التكلفة بمتوسط سعر الشراء
                                                <span class="badge wht-clo"><div id="meanbuyprice">{$productsData->meanbuyprice}</div></span></button>
                                            &nbsp;
                                            <button type="button" class="btn btn-primary ft-nor"> التكلفة بمتوسط سعر الشراء مع الخصم
                                                <span class="badge wht-clo"><div id="meanbuyprice_withDiscount">{$productsData->meanbuyprice_withDiscount}</div></span></button>

                                            <input type="hidden" name="productBuyPrice_h" id="productBuyPrice_h" value="{$productsData->productBuyPrice}"/>
                                            <input type="hidden" name="lastbuyprice_h" id="lastbuyprice_h" value="{$productsData->lastbuyprice}"/>
                                            <input type="hidden" name="lastbuyprice_withDiscount_h" id="lastbuyprice_withDiscount_h" value="{$productsData->lastbuyprice_withDiscount}"/>
                                            <input type="hidden" name="meanbuyprice_h" id="meanbuyprice_h" value="{$productsData->meanbuyprice}"/>
                                            <input type="hidden" name="meanbuyprice_withDiscount_h" id="meanbuyprice_withDiscount_h" value="{$productsData->meanbuyprice_withDiscount}"/>
                                        </div>
                                        <br/>
                                        <div class="clearfix"></div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        {/if}
                        {if $productsData->hasSizeAndColor == 1}
                        <input name="hasSizeAndColor" type="hidden" value="1">
                        <tr>
                            <td colspan="10"><!--------------------------------  adding units   ----------------------------->
                                <div class="panel panel-default panel-m">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">المقاسات والالوان</h3>
                                        <input type="hidden" name="isCollective" id="isCollective" value="1"/>
                                    </div>
                                    <div class="panel-body">
                                        <div class="row">
                                            <div class="col-lg-5" id="rightpart" style="display: inline">
                                                <label for="sizes" class="col-lg-4 control-label">المقاسات</label>
                                                <select class="select2" name="sizes[]" id="sizes" multiple="multiple">
                                                    <option value="-1">كل المقاسات</option>
                                                    {foreach $allSizeColor as $data}
                                                    {if $data->type == 0}
                                                    <option value="{$data->id}">{$data->name}</option>
                                                    {/if}
                                                    {/foreach}
                                                </select>
                                            </div>
                                            <div class="col-lg-5" id="leftpart" style="display: inline">
                                                <label for="colors" class="col-lg-4 control-label">الالوان</label>
                                                <select class="select2" name="colors[]" id="colors" multiple="multiple">
                                                    <option value="-1">كل الالوان</option>
                                                    {foreach $allSizeColor as $data}
                                                    {if $data->type == 1}
                                                    <option value="{$data->id}">{$data->name}</option>
                                                    {/if}
                                                    {/foreach}
                                                </select>
                                            </div>
                                            <div class="col-lg-2" id="leftpart" style="display: inline">
                                                <button type="button"  class="btn btn-success pull-left" style="margin-top: 3px;" id="SizeColorQuantity">ادخال الكميات للكل </button>
                                                <button type="button"  class="btn btn-success pull-left" style="margin-top: 5px;" id="SizeColorQuantity_onlyNew">اضافة للموجود </button>
                                            </div>


                                        </div>
                                        <div class="clearfix"></div>
                                        <br/>
                                        <div class="row" id="quantity_div">
                                            <table class="table">
                                                <thead>
                                                    <tr>
                                                        <th>الباركود</th>
                                                        <th>المقاس</th>
                                                        <th>اللون</th>
                                                        <th>حذف</th>
                                                    </tr>
                                                </thead>
                                                <tbody id="SizeColorTB">
                                                    {assign var=i value=1}
                                                    {foreach $sizeColorStoreDetail as $data}
                                                    <tr>
                                                        <td>
                                                            <input type="hidden" name="sizecolorstoredetail_id{$i}" id="sizecolorstoredetail_id{$i}" value="{$data->id}">
                                                            <input type="hidden" name="size_detail{$i}" id="size_detail{$i}" value="{$data->sizeid}">
                                                            <input type="hidden" name="color_detail{$i}" id="color_detail{$i}" value="{$data->colorid}">

                                                            <input type="text" class="form-control" name="parcode_detail{$i}" id="parcode_detail{$i}" value="{$data->parcode}"></td>
                                                        <td><input type="text" class="form-control" readonly="" value="{$data->sizeName}"></td>
                                                        <td><input type="text" class="form-control" readonly="" value="{$data->colorName}"></td>
                                                        <td><a class="btn btn-default btn-lg removeicon removethis"></a></td>
                                                    </tr>
                                                    {assign var=i value=$i+1}
                                                    {/foreach}
                                                </tbody>
                                            </table>
                                            <input type="hidden" id="sizeColorItr" name="sizeColorItr" value="{$i}"/>
                                        </div>
                                        <br/>
                                        <div class="clearfix"></div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        {/if}
                    </table>
                    <!--==============================-->

                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="submit"  id="submit" class="btn btn-primary pull-left">تعديل</button>
                        </div>
                    </div>
                </form>
            </div>
        </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>
</div>
{literal}
<script type="text/javascript">
    var spryte                                   xtfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "real");
            var spry                                   textfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "real");
            var sp
    rytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "real");
    var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "real");
            va                                   r sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "integer");
    var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "integer");
    var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7");
    var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {invalidValue: "-1"});
    $(function () {
        $('#reCalcUnitPrices').on('click', function () {
            $('[id^="productnumber"]').each(function () {
                var itr = $(this).attr('id').slice(13);
                var unitNum = Number($(this).val());
                var proUnitBuyPrice = unitNum * Number($('#productBuyPrice1').val());
                var proUnitSellAllPrice = unitNum * Number($('#productSellAllPrice').val());
                var proUnitSellHalfPrice = unitNum * Number($('#productSellHalfPrice').val());
                var proUnitSellUnitPrice = unitNum * Number($('#productSellUnitPrice').val());
                $('#proUnitBuyPrice' + itr).val(Number(proUnitBuyPrice.toFixed(3)));
                $('#proUnitSellAllPrice' + itr).val(Number(proUnitSellAllPrice.toFixed(3)));
                $('#proUnitSellHalfPrice' + itr).val(Number(proUnitSellHalfPrice.toFixed(3)));
                $('#proUnitSellUnitPrice' + itr).val(Number(proUnitSellUnitPrice.toFixed(3)));
            })
        })
        $('.unitInTaxClass').each(function () {
            var unitInTaxSelectID = $(this).attr('id');
            var old = $(this).data('old');
            $('#' + unitInTaxSelectID).select2({
                placeholder: "اختر",
                minimumInputLength: 0, // document.getElementById("searchvalue").value,
                multiple: false,
                quietMillis: 100,
                ajax: {
                    url: "eBillRequests.php?do=unit-types",
                    dataType: 'json',
                    data: function (term, page) {
                        return {
                            term: term, //search term
                        };
                    },
                    results: function (data) {
                        return {results: data};
                    }
                },
                formatResult: function (data) {
                    return  data.text;
                },
                initSelection: function (element, callback) {
                    var item = element.val().split(':');
                    //  var data = {id: item[0], text: item[1]};
                    var data = {id: item[0], text: item[1]};
                    callback(data);
                },
                //dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
            });
            $('#' + unitInTaxSelectID).select2("data", {id: old, text: old});
        });
    });


</script>
{/literal}