<!DOCTYPE html>
<html>
<head>
  @include('title')
  

  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="{{asset('lte/bower_components/bootstrap/dist/css/bootstrap.min.css')}}">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="{{asset('lte/bower_components/font-awesome/css/font-awesome.min.css')}}">
  <!-- Ionicons -->
  <link rel="stylesheet" href="{{asset('lte/bower_components/Ionicons/css/ionicons.min.css')}}">
  <!-- Theme style -->
  <link rel="stylesheet" href="{{asset('lte/dist/css/AdminLTE.min.css')}}">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="{{asset('lte/dist/css/skins/_all-skins.min.css')}}">
  
  <!-- bootstrap wysihtml5 - text editor -->
  <link rel="stylesheet" href="{{asset('lte/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css')}}">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
  
</head>
<body class="hold-transition skin-blue fixed sidebar-mini">
<div class="wrapper">
  
  @include('headertag')
  <!-- Left side column. contains the logo and sidebar -->
  @include('leftside')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          <small><a href="{{route('products.index')}}"><i class="fa fa-fw fa-backward"> </i>Back to List</a></small>
        </h1>
        <ol class="breadcrumb">
          <li><a href="{{route('products.index')}}"><i class="fa fa-dashboard"></i> Product</a></li>
          <li class="active">edit</li>
        </ol>
      </section>
      @if(Session('success'))
      <div class="alert alert-success alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        {{Session('success')}}
      </div>
      @endif

      <!-- Main content -->
       <div class="modal modal-default fade" id="modal-place">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">New HSN Code</h4>
              </div>
            
              <div class="form-group">
                <div class="col-sm-3"></div>
                <div class="modal-body">
                  <div class="col-sm-1"></div>
                  <label class="col-sm-3 control-label">HSN Code<font color="red">*</font></label>
                  <div class="col-sm-5">
                    <input type="text" name="hsn" class="form-control" id="hsn" placeholder="Enter" required="">
                  </div>
                  <br>
                </div>
              </div>
              
              <div class="modal-footer">
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary save" data-dismiss="modal">Save</button>
              </div>
            </div>
            <!-- /.modal-content -->
          </div>
          <!-- /.modal-dialog -->
        </div>
      <!-- Main content -->
      <section class="content">
        
        <!-- Main row -->
        <div class="row">
          <!-- Left col -->
          <section class="col-lg-12 connectedSortable">
            <!-- Custom tabs (Charts with tabs)-->
            <div class="nav-tabs-custom">
              <!-- Tabs within a box -->
              <ul class="nav nav-tabs pull-right">
                <li class="active"><a href="#grade_manager" data-toggle="tab">Product Spec</a></li>
                <li><a href="#product_detail" data-toggle="tab">Product Detail</a></li>
                <li class="pull-left header"><i class="fa fa-inbox"></i> Product</li>
              </ul>
              <div class="tab-content no-padding">
                <div class="tab-pane" id="product_detail"  style="position: relative; height: 300px;">
                  <div class="box box-info">
                    <div class="box-header with-border">
                      <h3 class="box-title">Product Details</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                      <form role="form" id="product_detail_form" action="{{route('products.update',$product->id)}}" method="POST">
                        
                        <div class="form-group col-sm-6">
                          <label>Category <span class="reqstar">*</span></label>
                          <select name="product_category" id="inputError" class="form-control" required>
                            <option value="">-- select --</option>
                            @foreach($categories as $category)
                            <option value="{{$category->id}}" @if($category->id == $product->category_id) selected @endif
                            >{{$category->category}}</option>
                            @endforeach
                          </select>
                        </div>
                        <div class="form-group col-sm-6">
                          <label>Group <span class="reqstar">*</span></label>
                          <select name="product_group" id="inputError" class="form-control product_group" required>
                            <option value="">-- select --</option>
                            @foreach($group_masters as $group)
                            <option value="{{$group->id}}" @if($group->id == $product->group_master_id) selected="selected" @endif>{{$group->name}}</option>
                            @endforeach
                          </select>
                        </div>
                        <div class="form-group col-sm-6">
                          <label>Sub Group <span class="reqstar">*</span></label>
                          <select name="product_subgroup" id="inputError" class="form-control sub_group" required>
                            <option value="">-- select --</option>
                            @foreach($sub_groups as $sub)
                            <option value="{{$sub->id}}" @if($sub->id == $product->sub_group_id) selected="selected" @endif>{{$sub->sub_group}}</option>
                            @endforeach
                          </select>
                        </div>
                        <div class="form-group col-md-6">
                          <label>Name <span class="reqstar">*</span></label>
                          <input type="text" value="{{$product->name}}" name="product_name" class="form-control" placeholder="Enter ..." required>
                        </div>
                        <div class="form-group col-md-6">
                          <label>Code <span class="reqstar">*</span></label>
                          <input type="text" value="{{$product->code}}"  name="product_code" class="form-control" placeholder="Enter ..." required>
                        </div>
                        <div class="form-group col-md-6">
                          <label>Alias Name <span class="reqstar">*</span></label>
                          <input type="text" name="alias_name" value="{{$product->alias}}" class="form-control" placeholder="Enter ...">
                        </div>
                        
                        <div class="form-group col-md-6">
                          <label>Base Unit <span class="reqstar">*</span></label>
                          <select name="base_unit" id="base_unit" class="form-control" required>
                            <option value="">-- select --</option>
                            @foreach($units as $data)
                            @if($data->id == $product->base_unit_id)
                            <option value="{{$data->id}}" selected="">{{$data->unit}}</option>
                            @else
                            <option value="{{$data->id}}">{{$data->unit}}</option>
                            @endif
                            @endforeach
                          </select>
                          
                        </div>
                        <div class="form-group col-md-6">
                          <label>Secondary Name </label>
                          <input type="text" name="secondry_name" value="{{$product->secondry_name}}" style="border-top-width: 32.997;width: 470.99306px;height: 34.99306px;"  placeholder="Enter ...">
                        </div>

                         <div class="form-group col-md-5">
                          <label>HSN Code <span class="reqstar">*</span></label>
                          <select name="hsn_code" id="hsn_code" class="form-control" required>
                            <option value="">-- select --</option>
                            @foreach($hsn_code as $hsn)
                            @if($hsn->id == $product->hsn_code_id)
                            <option value="{{$hsn->id}}" selected="">{{$hsn->hsncode}}</option>
                            @else
                            <option value="{{$hsn->id}}">{{$hsn->hsncode}}</option>
                            @endif
                            @endforeach
                          </select>
                          
                        </div>

                            <div class="col-md-1">
                              <div>
                              <br>
                              <i class="fa fa-plus-circle" aria-hidden="true" id="add" style="color:#3c8dbc;font-size:30px;position:relative;margin-top: 9px;" data-toggle="modal" data-target="#modal-place"></i>
                              </div>
                            </div>

                        <div class="form-group col-md-6" >
                          <label>Tax <span></span></label>
                          <input type="number" name="tax"  class="form-control"  value="{{$product->tax}}" step=".01">
                        </div>

                            
                        <div class="form-group col-md-6 " style="padding-top: 5px;">
                          <label>Remarks <span></span></label>
                          <textarea name="remarks" class="form-control">{{$product->remarks}}</textarea>
                        </div>
                        <div class="form-group col-md-6" style="padding-top: 10px;margin-right: 525px;margin-left: 18px;">
                          
                            <input type="checkbox" name="is_active" value="Y" @if($product->is_active == 'Y') checked="checked" @endif> <label>is Active</label> 
                          
                        </div>
                        <div class="form-group col-sm-6 ">
                        <button type="button" id="product_save" class="btn btn-primary">Save</button>
                        </div>
                      </form>
                    </div>
                    <!-- /.box-body -->    
                  </div>
                  <!-- /.box -->  
                </div>




                <input type="hidden" id="product_id" value="{{$product->id}}" class="form-control" readonly>





                <div class="tab-pane active" id="grade_manager" style="position: relative; height: 300px;">
                  <div class="box box-info">
                    <div class="box-header with-border">
                      <h3 class="box-title">Unit Mapping</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                      <div class="callout callout-danger" style="display: none">
                        <h4>Enter Product Details First!</h4>
                      </div>  
                      <form role="form" id="p_unit_f" action="" method="POST">
                        <!-- text input -->
                        <div class="col-sm-6">
                          <div class="form-group">
                            <label>Product :</label>
                            <label >{{$product->name}}</label>
                          </div>
                          <div class="form-group">
                            <label>Unit <span class="reqstar">*</span></label>
                            <select name="p_unit" class="form-control" required>
                              <option value="">-- select --</option>
                              @foreach($units as $unit)
                              <option value="{{$unit->id}}">{{$unit->unit}}</option>
                              @endforeach
                            </select>
                          </div>
                          
                          <div class="form-group col-sm-9 col-sm-push-9">
                          <button type="button" id="unt_save" class="btn btn-primary">Save</button>
                          </div>
                        </div>
                      </form>  
                        <div class="col-sm-6">
                          <div class="form-group">
                              <!-- /.box-header -->
                              
                                <table id="unit_tbl" class="table table-bordered">
                                  <tr>
                                    <th style="width: 10px">#</th>
                                    <th>Unit</th>
                                    <th style="width: 40px">Label</th>
                                  </tr>
                                  <?php $c = 1; ?>
                                  @foreach($product_units as $unit)
                                  <tr>
                                    <td>{{$c}}</td>
                                    <td>{{$unit->unitMaster->unit}}</td>
                                    <td><button class="btn-danger u_delete" id="{{$unit->id}}"><i class="fa fa-fw fa-trash"></i></button></td>
                                  </tr>
                                  <?php $c++; ?>
                                  @endforeach
                                </table>
                              
                              <!-- /.box-body -->
                              
                            
                          </div>
                        </div>
                        
                      
                    </div>
                    <!-- /.box-body -->  
                    <hr class="box box-info">

                    <div class="box-header with-border">
                      <h3 class="box-title">Packing Mapping</h3>
                    </div> 
                    <div class="box-body">
                        <!-- text input -->
                        <div class="col-sm-6">
                        <form role="form" id="p_grade_f">
                      
                          <div class="form-group">
                            <label>Product: </label>
                            <label >{{$product->name}}</label>
                          </div>
                          <div class="form-group">
                            <label>Packing <span class="reqstar">*</span></label>
                            <select name="product_grade" id="grd" class="form-control" required>
                              <option value="">-- select --</option>
                              @foreach($grades as $grade)
                              <option value="{{$grade->id}}">{{$grade->grade}}</option>
                              @endforeach
                            </select>
                          </div>
                          <div class="form-group col-sm-9 col-sm-push-9">
                          <button type="button" id="grade_save" class="btn btn-primary">Save</button>
                          </div>
                        </form>  
                        </div>
                        
                        <div class="col-sm-6">
                          <div class="form-group">
                              <!-- /.box-header -->
                              
                                <table id="grade_tbl" class="table table-bordered">
                                  <tr>
                                    <th style="width: 10px">#</th>
                                    <th>Packing</th>
                                    <th style="width: 40px">Label</th>
                                  </tr>
                                  <?php $c = 1; ?>
                                  @foreach($product_grades as $grade)
                                  <tr>
                                    <td>{{$c}}</td>
                                    <td>
                                      {{!is_null($grade->grade_id) ? $grade->grade->grade : ''}}
                                    </td>
                                    <td>
                                    <button class='btn-danger g_delete' onclick='gradeDelete({{$grade->id}})' id='{{$grade->id}}'><i class='fa fa-fw fa-trash'></i></button>
                                    </td>
                                  </tr>
                                  <?php $c++; ?>
                                  @endforeach
                                </table>
                              
                              <!-- /.box-body -->
                              
                            
                          </div>
                        </div>
                        
                      
                    </div>
                    <!-- /.box-body --> 
                     <!-- /.box-body -->  
                    <hr class="box box-info">

                    <div class="box-header with-border">
                      <h3 class="box-title">Grade Mapping</h3>
                    </div> 
                    <div class="box-body">
                      <form role="form" id="p_std_f" method="GET">
                        <!-- text input -->
                        <div class="col-sm-6">
                          <div class="form-group">
                            <label>Product: </label>
                            <label >{{$product->name}}</label>
                          </div>
                          <div class="form-group">
                            <label>Grade <span class="reqstar">*</span></label>
                            <select name="product_std" class="form-control" required>
                              <option value="">-- select --</option>
                              @foreach($standards as $std)
                              <option value="{{$std->id}}">{{$std->standard}}</option>
                              @endforeach
                            </select>
                          </div>
                          <div class="form-group">
                            <label>Packing <span class="reqstar">*</span></label>
                            <select name="product_grd" id="product_std" class="form-control" required>
                              <option value="">-- select --</option>
                              @foreach($std_grade as $grd)
                              <option value="{{$grd->id}}">{{$grd->grade}}</option>
                              @endforeach
                            </select>
                          </div>
                          <div class="form-group col-sm-9 col-sm-push-9">
                          <button type="button" id="std_save" class="btn btn-primary">Save</button>
                          </div>
                        </div>
                        
                        <div class="col-sm-6">
                          <div class="form-group">
                              <!-- /.box-header -->
                              
                                <table id="std_tbl" class="table table-bordered">
                                  <tr>
                                    <th style="width: 10px">#</th>
                                    <th>Grade</th>
                                    <th>Packing</th>
                                    <th style="width: 40px">Label</th>
                                  </tr>
                                
                                  <?php $c = 1; ?>
                                  @foreach($pdt_stds as $stds)
                                  <tr>
                                    <td>{{$c}}</td>
                                    <td>
                                      {{!is_null($stds->standard_id) ? $stds->standard->standard : ''}}
                                    </td>
                                    <td>
                                      {{!is_null($stds->grade_id) ? $stds->grade->grade : ''}}
                                    </td>
                                    <td>
                                    <button class='btn-danger g_delete' onclick='standardDelete({{$stds->id}})' id='{{$stds->id}}'><i class='fa fa-fw fa-trash'></i></button>
                                    </td>
                                  </tr>
                                  <?php $c++; ?>
                                  @endforeach

                                </table>
                              
                              <!-- /.box-body -->
                              
                            
                          </div>
                        </div>
                        
                      </form>
                    </div>
                    <!-- /.box-body --> 
                  </div>
                  <!-- /.box -->  
                </div>
              </div>
            </div>
            <!-- /.nav-tabs-custom -->

            <!-- Chat box -->
            
            <!-- /.box (chat box) -->

            
            <!-- quick email widget -->
          </section>
          <!-- /.Left col -->
          
        </div>
        <!-- /.row (main row) -->

      </section>
      <!-- /.content -->
    </div>
  <!-- /.content-wrapper -->
  
  @include('footertag')

  <!-- Control Sidebar -->
  
  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

  <!-- jQuery 3 -->
  <script src="{{asset('lte/bower_components/jquery/dist/jquery.min.js')}}"></script>
  <!-- jQuery UI 1.11.4 -->
  <script src="{{asset('lte/bower_components/jquery-ui/jquery-ui.min.js')}}"></script>
  <!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
  <script>
    $.widget.bridge('uibutton', $.ui.button);
  </script>
  <!-- Bootstrap 3.3.7 -->
  <script src="{{asset('lte/bower_components/bootstrap/dist/js/bootstrap.min.js')}}"></script>
  
  <!-- Sparkline -->
  <script src="{{asset('lte/bower_components/jquery-sparkline/dist/jquery.sparkline.min.js')}}"></script>
  
  <!-- Bootstrap WYSIHTML5 -->
  <script src="{{asset('lte/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js')}}"></script>
  <!-- Slimscroll -->
  <script src="{{asset('lte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js')}}"></script>
  <!-- FastClick -->
  <script src="{{asset('lte/bower_components/fastclick/lib/fastclick.js')}}"></script>
  <!-- AdminLTE App -->
  <script src="{{asset('lte/dist/js/adminlte.min.js')}}"></script>
  
  <!-- AdminLTE for demo purposes -->
  <script src="{{asset('lte/dist/js/demo.js')}}"></script>
  
</body>
<script>
  $(document).ready(function(){
    
    $(".reqstar").css("color","red");
    $(".reqstar").css("font-size",14);
    
    //check the product details is entered first
    $("a").click(function(){
      $("div.alert").remove();
      if($(this).attr('href') == "#grade_manager"){
        if($("#product_id").val() == 0){
          $(".callout-danger").show();
        }
      }
    });

    
    //product detail save 
    $("#product_save").on('keydown click',function(e){
      
      var ept = 0;
      
      $("#product_detail_form .form-control").filter(function(){
        if($(this).val().length == 0 && (!$(this).is("textarea"))) {
          ept = ept + 1;
          $(this).parent('div').addClass('has-error');
        }
      });
      
      if(ept == 0)
      {
        $("#product_detail_form").submit();
      }
      
    });
    // end

    //product unit grade
    $("#unt_save").on('keydown click',function(e){
      
    if(e.type == 'click' || e.which == 13){
      if(e.which == 13){
        e.preventDefault();
      }
      var ept = 0;
      $("#p_unit_f .form-control").filter(function(){
        if($(this).val().length == 0){
          ept = ept + 1;
          $(this).parent('div').addClass('has-error');
        }
      });

      if(ept == 0){
        var unt = [];
        var unt_n = [];
        $("#p_unit_f .form-control").filter(function(){
          $(this).parent('div').removeClass('has-error');
          unt[$(this).attr('name')] = $(this).val();
          unt_n[$(this).attr('name')] = $(this).find("option:selected").text();
        });
        
        $.post("{{url('product_unit_create')}}",{pid: $("#product_id").val(), p_unit: unt['p_unit']},function(data){
          if(data == 0){
            $("#p_unit_f").prepend("<div class='alert alert-danger alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>Already Exist!</div>");
          }
          else
          {
            var c = $("#unit_tbl tr:last td:first").text();
            
            if(c == '#' || c == '') {
              c = 1;
            } else {
              c = parseInt(c) + 1;
            }
            
            $("#unit_tbl tr:last").after("<tr><td>"+c+"</td><td>"+unt_n['p_unit']+"</td><td><button class='btn-danger u_delete' onclick='unitDelete("+data+")' id='"+data+"'><i class='fa fa-fw fa-trash'></i></button></td></tr>");

          }
          $("div.alert").delay(500).fadeOut();
        });//post
      }
      // p_unit_f
    }//if
    }); 
    // end unit grade
    // delete the unit 
    $(".u_delete").on("click",function(){
      var id = $(this).attr('id');
      $.post("{{url('product_delete_unit')}}", {option: id}, function(data){
          
          if(data == "deleted") {
            $("#"+id).closest('tr').remove();
            $("#p_unit_f").prepend("<div class='alert alert-success alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>Deleted !</div>");
            
          }
          else {
            $("#p_unit_f").prepend("<div class='alert alert-danger alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>It is Base Unit !</div>");
          }
          
      });
      $("div.alert").delay(500).fadeOut();
      
      var i = 1;
      $('#unit_tbl td:first-child').each(function() {
          $(this).text(i); 
          i++;
      });
    });


    // product grade
    $("#grade_save").on('keydown click',function(e){
      
	    if(e.type == 'click' || e.which == 13){
	      if(e.which == 13){
	        e.preventDefault();
	      }
	      var ept = 0;
	      $("#p_grade_f .form-control").filter(function(){
	        if($(this).val().length == 0){
	          ept = ept + 1;
	          $(this).parent('div').addClass('has-error');
	        }
	      });
	      if(ept == 0){
	      	var prd_grade = [];
	      	var prd_grade_n = [];
	      	$("#p_grade_f .form-control").filter(function(){
	      	  $(this).parent('div').removeClass('has-error');
	      	  prd_grade[$(this).attr('name')] = $(this).val();
	      	  prd_grade_n[$(this).attr('name')] = $(this).find("option:selected").text();
	      	});
           $('#product_std').append("<option value='"+prd_grade['product_grade']+"'>"+prd_grade_n['product_grade']+"</option>");
	      	$.post("{{url('product_grade_store')}}",
	      		{pid: $("#product_id").val(),
	      		 product_grade: prd_grade['product_grade']
	      		},
	      		function(success){
	      		if(success == 0){
	      		  $("#p_grade_f").prepend("<div class='alert alert-danger alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>Already Exist!</div>");
	      		} else {
	      			var c = $("#grade_tbl tr:last td:first").text();
	      			
	      			if(c == '#' || c == '') {
	      			  c = 1;
	      			} else {
	      			  c = parseInt(c) + 1;
	      			}
	      			
	      			$("#grade_tbl tr:last").after("<tr><td>"+c+"</td><td>"+prd_grade_n['product_grade']+"</td><td><button class='btn-danger g_delete' onclick='gradeDelete("+success+")' id='"+success+"'><i class='fa fa-fw fa-trash'></i></button></td></tr>");
	      		}
            $("div.alert").delay(500).fadeOut();
      		});
	      }
	    }
    });  
    // end tag

     // product grade
    $("#std_save").on('keydown click',function(e){
      
      if(e.type == 'click' || e.which == 13){
        if(e.which == 13){
          e.preventDefault();
        }
        var ept = 0;
        $("#p_std_f .form-control").filter(function(){
          if($(this).val().length == 0){
            ept = ept + 1;
            $(this).parent('div').addClass('has-error');
          }
        });
        if(ept == 0){
          var prd_grade = [];
          var prd_grade_n = [];
          var prd_std = [];
          var prd_std_n = [];
          $("#p_std_f .form-control").filter(function(){
            $(this).parent('div').removeClass('has-error');
            prd_grade[$(this).attr('name')] = $(this).val();
            prd_grade_n[$(this).attr('name')] = $(this).find("option:selected").text();
            prd_std[$(this).attr('name')] = $(this).val();
            prd_std_n[$(this).attr('name')] = $(this).find("option:selected").text();
          });
          $.get("{{url('product_standard_store')}}",
            {pid: $("#product_id").val(),
             product_grade: prd_grade['product_grd'],
             product_standard : prd_std['product_std']
            },
            function(success){
            if(success == 0){
              $("#p_std_f").prepend("<div class='alert alert-danger alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>Already Exist!</div>");
            } else {
              var c = $("#std_tbl tr:last td:first").text();
              
              if(c == '#' || c == '') {
                c = 1;
              } else {
                var c = parseInt(c) + 1;
              }
              
              $("#std_tbl tr:last").after("<tr><td>"+c+"</td><td>"+prd_std_n['product_std']+"</td><td>"+prd_grade_n['product_grd']+"</td><td><button class='btn-danger g_delete' onclick='standardDelete("+success+")' id='"+success+"'><i class='fa fa-fw fa-trash'></i></button></td></tr>");
            }
            $("div.alert").delay(500).fadeOut();
          });
        }
      }
    });  
    // end tag

    $(".product_group").change(function(){
      
      var grp = $(this).val();
      $(".sub_group").empty();
      $.post("{{url('get_sub_group')}}",{group: grp}, function(data){
        $(".sub_group").append(data);
      });
    });

  });
</script>
<script type="text/javascript">
	function unitDelete(value){
		
		$.post("{{url('product_delete_unit')}}", {option: value}, function(data){

        if(data == "deleted") {
          $("#"+value).closest("tr").remove();
          $("#p_unit_f").prepend("<div class='alert alert-success alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>Deleted !</div>");
          
        }
        else {
          $("#p_unit_f").prepend("<div class='alert alert-danger alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>It is Base Unit !</div>");
        } 
          
  	});
        $("div.alert").delay(500).fadeOut();
      	
        var i = 1;
        $('#unit_tbl td:first-child').each(function() {
            $(this).text(i); 
            i++;
        });
	}

	function gradeDelete(value){
    var grd = $('#grd').val();
		$.post("{{url('product_delete_grade')}}", {option: value},
			function(data){
        if(data == 0) {
          $("#p_grade_f").prepend("<div class='alert alert-success alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>Packing have grade !</div>"); 
        }
        else {
          $("#p_grade_f").prepend("<div class='alert alert-success alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>Deleted !</div>"); 
          $("#product_std option[value='"+grd+"']").remove();
          $("#"+value).closest("tr").remove();
        }
			
		});
    $("div.alert").delay(500).fadeOut();
		
    var i = 1;
    $('#grade_tbl td:first-child').each(function() {
        $(this).text(i); 
        i++;
    });
	}

  function standardDelete(value){
    
    $.get("{{url('product_delete_standard')}}", {option: value},
      function(data){
      $("#p_std_f").prepend("<div class='alert alert-success alert-dismissible'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>Deleted !</div>");
    });
    $("div.alert").delay(500).fadeOut();
    $("#"+value).closest("tr").remove();
    var i = 1;
    $('#std_tbl td:first-child').each(function() {
        $(this).text(i); 
        i++;
    });
  }


  $(".save").click(function(){
    var hsn = $('#hsn').val();
    if(hsn == ''){
      alert("Enter a valid hsn code.");
    }
    else{
        var eurl = "{{url('add/hsn/code')}}";
            $.get(eurl,{option1: hsn}, function(data){ 
              console.log(data);
            if(data == 0){
              alert("HSN Code allready added.")
            }
            else{
              $('#hsn_code').append('<option value="'+data.id+'">'+data.hsncode+'</option>');
              $('#hsn_code').val(data.id);}
            }); 
    }

  });
  $("#add").click(function(){
    $('#hsn').val('');
  });
</script>
</html>
