<style>
    .newQtyClass{
        width: 100px;
    }
</style>
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">المخازن </a></li>
            <li class="active">تالف مواد تشغيل</li>
        </ol>
        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">تالف مواد تشغيل</h3>
            </div>
            <div class="panel-body">
                <form class="form-horizontal" role="form" action="restaurantRawDestruction.php?do=add" method="post" >
                   <!--  <div class="form-group">
                        <label for="storesData" class="col-lg-2 control-label">المخزن</label>
                        <div class="col-lg-4">
                            <select class="select2 wdt100" name="storeId" id="storeId">
                                <option value="-1">اختر مخزن</option>
                                {foreach $storesData as $store}
                                <option value="{$store->storeId}">{$store->storeName}</option>
                                {/foreach}
                            </select>
                            <input type="hidden" name="storeId_hidden" id="storeId_hidden" value=""/>
                        </div>
                    </div> -->


                    {if $searchinonestore neq 0}

               

                 <div class="form-group">
                        <label for="storesData" class="col-lg-2 control-label">المخزن</label>
                        <div class="col-lg-4">
                             <input type="hidden" name="storeId" id="storeId"  value="{$storeid}"  >
                            <input type="hidden"  id="searchstoreName" value="{$storedef->storeName}">
                            <input type="hidden"  id="searchstorid" value="{$storeid}">
                            {$storedef->storeName}
                            <input type="hidden" name="storeId_hidden" id="storeId_hidden" value="{$storeid}"/>

                        </div>
                    </div>


                {else}

                    <div class="form-group">
                        <label for="storesData" class="col-lg-2 control-label">المخزن</label>
                        <div class="col-lg-4">
                            <select class="select2 wdt100" name="storeId" id="storeId">
                                <option value="-1">اختر مخزن</option>
                                {foreach $stores as $store}
                                <option value="{$store->storeId}">{$store->storeName}</option>
                                {/foreach}
                            </select>
                            <input type="hidden" name="storeId_hidden" id="storeId_hidden" value=""/>
                        </div>
                    </div>


             
                {/if}

                    {if $Programsetting->realestateunits eq 1}
                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">العقارات</label>
                        <div class="col-lg-4">
                            <input type="text" name="realestateid" class="wdt100" id="select2realestates" data-placeholder="اختر " />
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">الوحدات </label>
                        <div class="col-lg-4">
                            <input type="text" name="realestateunitid" class="wdt100" id="select2realestatesunits" data-placeholder="اختر " />
                        </div>
                    </div>
                    {/if}

                    <input type="hidden" name="searchvalue" id="searchvalue" value="{$Programsetting->searchvalue}"/>
                    <!-- ================================================= -->
                    <input type="hidden" name="catId" id="catId" value="-1"/>
                    <!-- ================================================= -->
                    <div id="productsDiv">
                        <button type="button" name="addpro" id="addpro" class="btn btn-primary pull-left ft-nor">اضافة </button>
                        <table class="table table-black">
                            <thead>
                                <tr>
                                    <th style="width:30%">إسم المنتج</th>
                                    <th>الكمية الحالية</th>
                                    <th>كمية الاهلاك</th>
                                    <th>الكمية بعد</th>
                                    <th class="priceClass {if $Usergroupdata->hideBillPrices == 1}hidden{/if}">السعر</th>
                                    <th class="priceClass {if $Usergroupdata->hideBillPrices == 1}hidden{/if}">الاجمالى</th>
                                    <th>تاريخ اخر اهلاك</th>
                                    <th>تعليق</th>
                                    <th>حذف</th>
                                </tr>
                            </thead>
                            <tbody id="productsTBody">

                            </tbody>
                        </table>
                        <button type="button" class="btn btn-primary pull-left ft-nor {if $Usergroupdata->hideBillPrices == 1}hidden{/if}">
                            الاجمالى <span class="badge wht-clo">
                                <div id="totalPrice">0</div>
                            </span>
                            <input type="hidden" name="sellbillprice" id="sellbillprice" value="0">
                        </button>
                        <input name="itr" id="itr" type="hidden" value="0" />
                    </div>
                    <input name="storenegative" type="hidden" value="{$storenegative}" id="storenegative" />

                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="submit"  class="btn btn-primary pull-left">حفظ</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


{literal}

<script type="text/javascript">

    $(document).ready(function () {


        var formatResult;
        formatResult = function (data) {
            return  data.text;
        }


        $("#select2realestates").select2({
            placeholder: "العقار",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "realestateunits.php?do=select2realestates",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    $('#select2realestatesunits').val("").trigger("change");
                    return {
                        searchTerm: term,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });



        $("#select2realestatesunits").select2({
            placeholder: "الوحده",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "realestateunits.php?do=select2realestatesunits",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    var select2realestates = Number($('#select2realestates').val());
                    if (!select2realestates) {
                        alert('يجب اختيار العقار اولا');
                        return false;
                    }
                    return {
                        searchTerm: term,
                        realestateid: select2realestates,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });

    });
</script>
{/literal}