

<div class="row">
    <div class="container">

        <ol class="breadcrumb">
            <li><a href="#">المخازن</a></li>
            <li><a href="mechandiseReturnRequest.php?do=show">  طلب مرتحع بضاعه </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">
                {literal}
                <form class="form-horizontal"  action="mechandiseReturnRequest.php?do=savedata"  id="submitformajax"  method="post"  enctype="multipart/form-data" data-dosave="?do=savedata" data-direction="?do=show" data-print="">
                    {/literal}

                    <div class="form-group">
                        <label class="col-lg-2 control-label">تالف او سليم    </label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input value="1" class="noradioR" name="damagedintact" type="radio" checked="checked">
                                    تالف </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input value="2" class="radioR" name="damagedintact" type="radio">
                                    سليم  </label>
                            </div>

                        </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="clientid" class=" wdt100" id="select2client" 
                             data-placeholder="اختر " />
                            
                        </div>
                    </div>



                     <div class="form-group">
                        <div class="col-md-12">
                              <div>
                                 <button type="button" class="btn green-meadow btn-sm pull-left addappend" data-itr=''  style="font-size: 10px;background: #ccc">اضافه  </button>
                                  <input type="hidden" id="productsitr" name="productsitr" value="1" />
                              </div>
                              <div class="clearfix"></div>
                              <ul class="products" id="products">
                                 <li  id="products01" style="list-style-type: none;">
                                   <div class="col-lg-4">
                                       <label for="txtName" class="control-label">المتجات  </label>
                                       <input type="text" name="productid_1" class=" wdt100 select2product" id="select2product1" data-placeholder="اختر " />
                                    </div>
                                   <div class="col-lg-7">
                                     <label for="txtName" class="control-label"> التعليق</label>
                                     <input      type="text" name="comment_1" class="form-control  " placeholder="التعليق  " data-table="" data-tablecol="" data-tableid="" data-parentid="" data-parentcol="" />
                                   </div>
                                </li>
                            </ul>  
                        </div>
                    </div>
                   
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="submit" class="btn btn-primary pull-left submitformajax" >حفظ الامر</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


{literal}
<script type="text/javascript">
$(document).ready(function () {
        var formatResult;
        formatResult = function (data) {return  data.text;}
        //    dssd();
        //   function dssd() {
        //     var start_date = $("#start_date").val();
        //      var end_date = $("#end_date").val();
        //      var clientid = $("#select2client").val();
        //       $.post('clientsexpensereport.php?do=getdata', {start_date: start_date, end_date: end_date, clientid: clientid}, function (result) {
        //         $("#getdata").html(result);
        //         $("#tspaids").html($("#gtspaids").text());
        //         $("#tepaids").html($("#gtepaids").text());
        //         $("#tcpaids").html($("#gtcpaids").text());
        //         $("#tcspaids").html($("#gtcspaids").text());
        //       });
        //   }

        //   $('body').on('change', '.searchdata', function () {
            // var start_date = $("#start_date").val();
            //  var end_date = $("#end_date").val();
            //  var clientid = $("#select2client").val();
            //   $.post('clientsexpensereport.php?do=getdata', {start_date: start_date, end_date: end_date, clientid: clientid}, function (result) {
            //     $("#getdata").html(result);

            //    $("#tspaids").html($("#gtspaids").text());
            //     $("#tepaids").html($("#gtepaids").text());
            //     $("#tcpaids").html($("#gtcpaids").text());
            //     $("#tcspaids").html($("#gtcspaids").text());

            //   });
            // });

            $('body').on('click', '.addappend', function () {
                var itr = Number($("#productsitr").val()) + 1;
                $("#productsitr").val(itr);
              $.post('mechandiseReturnRequest.php?do=appendproduct', {itr: itr}, function (result) {
                $("#products").append(result);
                products(itr);
                

              });
            });

            $('body').on('click', '.removeappend', function () {
                var id = Number($(this).attr('data-id'));
                var edit = Number($(this).attr('data-edit'));
                if(edit == 1){
                    $.post('mechandiseReturnRequest.php?do=removeappend', {id: id}, function (result) {
                        $("#products"+id).remove();
                    });
                }else{
                    $("#products"+edit+id).remove();

                }
                
            });
          products(1);
          function products($i){
            $("#select2product" + $i).select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "mechandiseReturnRequest.php?do=select2product",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    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);
            }
        });
          }


         $("#select2client").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "mechandiseReturnRequest.php?do=select2client",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    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);
            }
        });




    
});  
</script>
{/literal}
