

  <div class="modal fade" id="md_add_gin_product" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  {{ Form::open(array('route' => 'commit.gin' , 'id' => 'form_add_gin', 'class' => 'cls_form' , 'method' => 'POST' , 'enctype'=>'multipart/form-data'
)) }}
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Create Product GIN</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true"></span>
        </button>
      </div>
      <div class="modal-body ">
        <div class ="card">
          <div class = "card-body form-fieldset">
          <div class="row">

            <div class="col-sm-12">
              <label>Project</label>
              @php($branch_label = EF::branchWhiteLabel())
              <select name="{{$branch_label['module']}}" class="form-control form-control-sm cls_selection branch" id="b_id1" onChange ="getItemList2(event,this)">
                 <option value="{{Crypt::encrypt(0)}}">Select {{ucwords(str_replace('_',' ',$branch_label['module']))}}</option>
                @foreach($branch as $rows)
                @if(Auth::user()->usertoprojectCheck($rows->id) == 1 || Auth::user()->type="Super Admin")
                  <option @if(isset($current_branch) && $rows->id === $current_branch) selected  @endif value="{{Crypt::encrypt($rows->id)}}">{{$rows->code}} {{$rows->name}}</option>
                  @endif
                @endforeach
              </select>
            </div>

            <div class="col-sm-12">
            <label class="label-color"> Floor: <i style = "color:red;">*</i></label>
            <div class="input-group mb-3">
              <select class="form-control" id="floor" required name="floor" >

                @foreach($floor_list as $floor_l)
                <option value="{{$floor_l->floor}}">{{$floor_l->floor}}</option>
                @endforeach
              </select>
            </div>
            </div>

            <div class="col-sm-12">
            <label class="label-color"> Select PR: <i style = "color:red;">*</i></label>
            <div class="input-group mb-3">
              <select class="form-control" id="p_number" required name="p_number" >

                @foreach($boq_list as $purchase_orde)
                <option value="RS/PR/000{{$purchase_orde->id}}">RS/PR/000{{$purchase_orde->id}}</option>
                @endforeach
              </select>
            </div>
            </div>

            <div class="col-sm-12">
            <label class="label-color"> Product: <i style = "color:red;">*</i></label>
            <div class="input-group mb-3">
              <select class="form-control" id="product_id" required name="product_id" onChange ="getItemList(event,this)">
                <option value="{{Crypt::encrypt(0)}}">Select Product</option>
                @foreach($product_list as $product)
                <option value="{{Crypt::encrypt($product->id)}}">{{$product->name}}</option>
                @endforeach
              </select>
            </div>
            </div>

            <div class="col-sm-12">
            <label class="label-color" id="qtylabel"> Quantity: <i style = "color:red;">*</i></label>
            <div class="input-group mb-3">
              <input type="number" name="quantity" class="form-control " min="0" required id="quantity" />
            </div>
            </div>
            <!-- <div class="col-sm-12">
            <label class="label-color"> Requested By: <i style = "color:red;">*</i></label>
            <div class="input-group mb-3">
              <input type="text" readonly class="form-control" value=""/>
            </div>
            </div> -->
            <div class="col-sm-12">
            <label class="label-color"> Issued to: <i style = "color:red;">*</i></label>
            <div class="input-group mb-3">
              <select class="form-control" name="receiver_id">
                @foreach($user as $user_row)
                <option value="{{Crypt::encrypt($user_row->id)}}">{{$user_row->name}}</option>
                @endforeach
              </select>
            </div>
            </div>

            <div class = "col-md-12">
               <label class="label-color">Issued By: <i style = "color:red;">*</i></label>
            <div class="input-group mb-3">
            <select name="au_user" class="form-control form-control-sm cls_selection branch" id="au_id" >
            @foreach($auser_list as $auser)
            <option  value="{{Crypt::encrypt($auser->id)}}">{{$auser->name}} | {{$auser->designation->name}}</option>
            @endforeach
            </select>
            </div>
            </div>

            <div class="col-sm-12">
            <label class="label-color"> Remarks: <i style = "color:red;">*</i></label>
            <div class="input-group mb-3">
              <input type="text" name="remarks" class="form-control " required id="remakrs" />
            </div>
            </div>


        </div>
          </div>
        </div>
      </div>

      <div class="modal-footer">

        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

        <button type="submit" onClick="storeInventoryUnit(event,this)" class="btn btn-primary"   content="add unit">Generate GIN</button>

      </div>
      {{ Form::close() }}
    </div>
  </div>

</div>

<script>

function getItemList(event,obj)
{
      event.preventDefault();
      var project_id = $("#b_id1").val();

    var route = "{{url('/getitemid')}}/"+$(obj).val()+'/'+project_id;

      showLoader();

  $.get(route,function(data)
  {

    if(data['msg'] == "success")
    {
      $("#qtylabel").html('Quantity: <i style = "color:red;">*</i>(max|'+data['item']+')')
      $("#quantity").attr({
       "max" : data['item'],
       "min" : 1
    });
    }
    else
    {
      $("#qtylabel").html('Quantity: <i style = "color:red;">*</i>(max|0')
      $("#quantity").attr({
       "max" : 0,
       "min" : 0
    });
    }


       removeLoader();

    });
}
</script>

<script>

function getItemList2(event,obj)
{
      event.preventDefault();
      var project_id = $(obj).val();
      var item_id = $("#product_id").val();

    var route = "{{url('/getitemid')}}/"+item_id+'/'+project_id;

      showLoader();

  $.get(route,function(data)
  {

    if(data['msg'] == "success")
    {
      $("#qtylabel").html('Quantity: <i style = "color:red;">*</i>(max|'+data['item']+')')
      $("#quantity").attr({
       "max" : data['item'],
       "min" : 1
    });
    }
    else
    {
      $("#qtylabel").html('Quantity: <i style = "color:red;">*</i>(max|0')
      $("#quantity").attr({
       "max" : 0,
       "min" : 0
    });
    }


       removeLoader();

    });
}
</script>
