<script type="text/javascript">
    $(document).ready(function (e) {
        $(".numberinput").forceNumeric();
        $(".positivefloat").forcepositivefloat();

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

    #manyParents .form-group label{
        margin-left: 11px;
        margin-right: 16px;
    }

    #manyParents .form-group div{
        width: 155px;
    }
</style>
<div class="modal-body ">
    <form id="productInfo" action="#" method="post" class="form-horizontal">
        <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="productCatId0"  required ="required"  data-level="0"  data-placeholder="اختر" class="select2_customj wdt100 productCat" tabindex="12">
                        <option   value="">اختر تصنيف</option>
                        {foreach $catDataReport as $data}
                        <option value="{$data->productCatId}">{$data->productCatName}</option>
                        {/foreach}

                    </select>
                    <input type="hidden" id="level" name="level" value="0">
                    <span class="selectInvalidMsg">*</span></span></div>
            <div id="manyParents" class="col-lg-12">  </div>
            <span class="selectInvalidMsg">*</span>
        </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 ="required"  />
            </div>
        </div>
        <!---------------------------->

        <div class="form-group  check_tr " {if {$Programsettingdata->parcode} eq 1}  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"    value="{$generatedParcode}" onblur="checkbarcode(this.value);"/>
            </div>
        </div>
        <div class="form-group">
            <label for="productBuyPrice" class="col-lg-2 control-label">سعر الشراء</label>
            <div class="col-lg-4"> <span id="sprytextfield5">
                    <input name="new_productBuyPrice" type="text" id="new_productBuyPrice" class="numberinput positivefloat buy_price form-control"  required ="required" data-id="1"  size="50"   />
                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">ادخل السعر صحيح</span></span></div>
        </div>
        <!---------------------------->


        <div class="form-group"  style="{if {$Programsettingdata->realprice} eq 1} display: none; {/if}">
            <label for="productBuyPrice" class="col-lg-2 control-label">سعر الشراء الفعلى</label>
            <div class="col-lg-4"> <span id="sprytextfield5">
                    <input style="width: 50%;float: left;" name="new_productbuypricereal" type="text" id="buypricereal1"  data-type="pricereal"  required ="required" 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="new_buypricereal_precentage1" type="text" id="productBuyPrice1" data-type="pricereal"   class="form-control precentages  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></div>
        </div>
        <!---------------------------->
        <div class="form-group">
            <label for="productSellAllPrice" class="col-lg-2 control-label">سعر بيع الجمله</label>
            <div class="col-lg-4"> <span id="sprytextfield6">
                    <!--<input name="productSellAllPrice" type="text" id="productSellAllPrice" class="numberinput form-control" onkeyup="populateSellPrice();"  size="50"   />-->
                    <input style=" {if {$Programsettingdata->precentages} eq 1} width: 100%; {else} width: 50%; {/if} float: left;" name="new_productSellAllPrice" required ="required" type="text" id="productSellAllPrice" data-type="buytotal"  class="form-control prices aw_m aw_mt aw_pp numberclic positivefloat buy_total1 enteraction numberinput" data-id="1" width="10"/>
                    <input style=" {if {$Programsettingdata->precentages} eq 1} display: none; {/if} width: 50%;"  name="new_buytotal_precentage1" type="text" id="productBuyPrice1"   data-type="buytotal" class="form-control  aw_m aw_mt aw_pp numberclic enteraction precentages numberinput positivefloat buytotal_precentage1" data-id="1" width="10"/>
                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">ادخل السعر صحيح</span></span></div>
        </div>
        <!---------------------------->

        <div class="form-group">
            <!--<label for="productSellHalfPrice" class="col-lg-2 control-label">سعر بيع الجمله التجزئة</label>-->
            <label for="productSellHalfPrice" class="col-lg-2 control-label">سعر بيع نصف الجملة </label>
            <div class="col-lg-4"> <span id="sprytextfield7">
                    <!--<input name="productSellHalfPrice" type="text" id="productSellHalfPrice" class=" form-control numberinput"   size="50"   />-->
                    <input  style="{if {$Programsettingdata->precentages} eq 1} width: 100%; {else} width: 50%; {/if} float: left;"  required ="required" name="new_productSellHalfPrice" type="text" data-type="buyhalf" id="productSellHalfPrice"  class="form-control  aw_m aw_mt aw_pp numberclic prices enteraction numberinput positivefloat buy_hafe1" data-id="1" width="10"/>
                    <input style=" {if {$Programsettingdata->precentages} eq 1} display: none; {/if} width: 50%;"  name="new_buyhalf_precentage1" type="text" id="productBuyPrice1"  data-type="buyhalf" class="form-control  aw_m aw_mt aw_pp numberclic enteraction  precentages numberinput positivefloat buyhafe_precentage1" data-id="1" width="10"/>
                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">ادخل السعر صحيح</span></span></div>
        </div>
        <!---------------------------->

        <div class="form-group">
            <!--<label for="productSellUnitPrice" class="col-lg-2 control-label">سعر بيع الوحده</label>-->
            <label for="productSellUnitPrice" class="col-lg-2 control-label">سعر بيع التجزئة  </label>
            <div class="col-lg-4"> <span id="sprytextfield8">
                    <!--<input name="productSellUnitPrice" type="text" id="productSellUnitPrice" class=" form-control numberinput"  size="50"   />-->
                    <input  style=" {if {$Programsettingdata->precentages} eq 1} width: 100%; {else} width: 50%; {/if} float: left;"  required ="required" name="new_productSellUnitPrice" type="text" data-type="buypart"  id="productSellUnitPrice"  class="form-control  aw_m aw_mt aw_pp numberclic prices enteraction numberinput positivefloat buy_part1" data-id="1"  width="20"/>
                    <input style=" {if {$Programsettingdata->precentages} eq 1} display: none; {/if} width: 50%;"  name="new_buypart_precentage1" type="text" id="productBuyPrice1" data-type="buypart"    class="form-control  aw_m aw_mt aw_pp numberclic enteraction precentages numberinput positivefloat buypart_precentage1" data-id="1" width="10"/>
                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">ادخل السعر صحيح</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_productquantity" type="text" id="new_productquantity" class=" form-control numberinput"  required="required"   value="0" size="50"/>
            </div>
        </div>
        <!---------------------------->

        <div class="form-group check_tr_service " {if {$Programsettingdata->service} eq 1} style="display:none;" {/if}>
            <label for="inputEmail1" class="col-lg-2 control-label">خدمة</label>
            <div class="col-lg-4">

                <label class='color-black'>
                    <input value="1"  class="radioR isservice" name="new_isservice1"   type="radio" />
                    نعم </label>

                <label class='color-black'>
                    <input value="0"  class="noradioR isservice" name="new_isservice1"   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">
                <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  check_tr_production " {if {$Programsettingdata->production} eq 1}  style="display:none;" {/if}>
            <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 check_tr_date " {if {$Programsettingdata->date} eq 1} style="display:none;" {/if}>
            <label for="inputEmail1" class="col-lg-2 control-label">التاريخ</label>
            <div class="col-lg-4">
                <input name="new_productDate" type="text" id="new_productDate" value="{$today}" class=" form-control awdatepicker" autocomplete="off"   data-date-format="yyyy-mm-dd" size="50" required   />
            </div>
        </div>
        <!---------------------------->

        <div class="form-group check_tr_period " {if {$Programsettingdata->expiredate} eq 1} style="display:none;" {/if}>
            <label for="inputEmail1" class="col-lg-2 control-label">مده انتهاء الصلاحيه</label>
            <div class="col-lg-4">
                <input name="expireDate" style="width: 83%;" type="text" id="expireDate" class=" form-control numberinput"  required="required"   value="0" size="50"/>
                <span style="float: left;margin-top: -27px; color: white;font-size: 15px;font-weight: bold;">يوم</span>

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

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

        <div id="addUnitsDiv" class = "check_tr_mesurunit " {if {$Programsettingdata->measuringunit} eq 1} style="display:none;" {/if}>
            <table id="unitsTable" class="table">
                <tr id="unit_row1">
                    <td>
                        <div>
                            <label for="inputEmail1" class="control-label">وحدة القياس</label>
                            <select name="productunit1" id="productunit1" data-placeholder="اختر" class="select2_customj wdt100  chosenproduct"  tabindex="12">
                                <!-- <option value="-1">اختر وحدة القياس</option>-->
                                {foreach $unitsData as $unit}
                                <option value="{$unit->unitId}">{$unit->unitName}</option>
                                {/foreach}
                            </select>
                        </div>
                        <!---------------------------->
                    </td>
                    <td>
                        <div>
                            <label for="inputEmail1" class="control-label">عدد الوحدات</label>
                            <input name="productnumber1" id="productnumber1" class="numberinput form-control"  value="1" type="text" />
                        </div>
                        <!---------------------------->
                    </td>
                    <td>
                        <div>
                            <label class="control-label">الباركود</label>
                            <input name="proUnitParcode1" id="proUnitParcode1" type="text" class="form-control numberinput positiveNo" onblur="checkUnitbarcode(this.value, 1);"/>
                        </div>
                    </td>
                    <td>
                        <div>
                            <label class="control-label">سعر الشراء</label>
                            <input name="proUnitBuyPrice1" id="proUnitBuyPrice1" type="text" class="form-control positivefloat" />
                        </div>
                    </td>
                    <td>
                        <div>
                            <label class="control-label">سعر الجملة</label>
                            <input name="proUnitSellAllPrice1" id="proUnitSellAllPrice1" type="text" class="form-control positivefloat" />
                        </div>
                    </td>
                    <td>
                        <div>
                            <label class="control-label">سعر نص جملة</label>
                            <input name="proUnitSellHalfPrice1" id="proUnitSellHalfPrice1" type="text" class="form-control positivefloat" />
                        </div>
                    </td>
                    <td>
                        <div>
                            <label class="control-label">سعر قطاعى</label>
                            <input name="proUnitSellUnitPrice1" id="proUnitSellUnitPrice1" type="text" class="form-control positivefloat" />
                        </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 check_tr_mesurunit " {if {$Programsettingdata->measuringunit} eq 1} style="display:none;" {/if} onClick="addUnits();" type="button" value="إضافة وحدة قياس"/>
        <input name="unitsItr" id="unitsItr" type="hidden" value="1" />


        <!---------------------------->
        <div class="clearfix"></div>
        <br/>
        <div class="form-group " style="padding: 8px; line-height: 1.428571429; vertical-align: top; border-top: 1px solid #ddd;">
            <label for="inputEmail1" class="col-lg-2 control-label">بمقاسات و الوان</label>
            <div class="col-lg-4">
                <label>
                    <input value="1"  class="radioR hasSizeAndColor" name="hasSizeAndColor"  type="radio" />
                    نعم </label>
                <label>
                    <input value="0"  class="noradioR hasSizeAndColor" name="hasSizeAndColor" type="radio" checked="checked"/>
                    لا </label>
            </div>
        </div>
        <!---------------------------->
        <!-- size color ------------------------------->
        <div class="panel panel-default panel-m" id="sizeColorDiv" style="display:none">
            <div class="panel-heading">
                <h3 class="panel-title">المقاسات و الالوان</h3>
            </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" id="SizeColorQuantity">ادخال الكميات </button>
                    </div>


                </div>
                <div class="clearfix"></div>
                <br/>
                <div class="row" id="quantity_div" style="display:none">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>الباركود</th>
                                <th>المقاس</th>
                                <th>اللون</th>
                                <th>الكمية</th>
                                <th>حذف</th>
                            </tr>
                        </thead>
                        <tbody id="SizeColorTB">

                        </tbody>
                    </table>
                    <input type="hidden" id="sizeColorItr" name="sizeColorItr" value="0"/>
                </div>

            </div>
        </div>
        <!-- END  size color ---------------------->
        <!-------------------------------- end adding units   -------------------------->

        <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 class="modal-footer">
            <button type="button" class="btn btn-default" id="cancel" onClick="closeProductForm();">إلغاء</button>
            <button type="button" class="btn btn-primary" id="insert" onClick="insertIntoTemp();">حفظ</button>
        </div>
    </form>
    {literal}
    <script>
        function checkbarcode(barcod)
        {
            if (barcod != "") {
                //alert("productControllerAjax.php?do=checkbarcode&barcod="+barcod);
                $.ajax({
                    url: "productControllerAjax.php?do=checkbarcode&barcod=" + barcod,
                    type: "get",
                    success: function (data) {
                        //alert(data)
                        if (data == 1)
                        {
                            // alert('oldbarcod'+oldbarcod);
                            alert('هذا الباركود موجود من قبل');
                            $("#new_parcode").val('');

                            $('#new_parcode').focus();

                        } else if (data == 2)
                        {


                        }

                    }
                });
            }
        }
        function checkUnitbarcode(barcod, itr)
        {
            $.ajax({
                url: "productControllerAjax.php?do=checkUnitbarcode&barcod=" + barcod,
                type: "get",
                success: function (data) {
                    //alert(data)
                    if (data == 1)
                    {
                        // alert('oldbarcod'+oldbarcod);
                        alert('هذا الباركود موجود من قبل');
                        $("#proUnitParcode" + itr).val('');
                    }

                }
            });
        }
        $('#sizes').select2();
        $('#colors').select2();
    </script>
    {/literal}