<!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')}}">
  <!-- Select2 -->
  <link rel="stylesheet" href="{{asset('lte/bower_components/select2/dist/css/select2.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">

  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="{{asset('lte/plugins/iCheck/all.css')}}">
  
</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>
          Customer Management
        </h1>
        <ol class="breadcrumb">
          <li><a href="{{route('customer.list')}}"><i class="fa fa-dashboard"></i> Customer</a></li>
          <li class="active">update</li>
        </ol>
      </section>

      <div class="modal fade" id="modal-default">
        <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">Mode</h4>
            </div>
            
            <div class="modal-body">
                <span>
                <input type="text" class="form-control" id="new_mode" name="new_mode">
                <i id="mode_name_req" style="color: red;"></i>
                </span>
            </div>
            
            <div class="modal-footer">
                <button type="button" id="close_mode" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
                <button type="button" id="add_mode" class="btn btn-primary">Save</button>
            </div>
          </div>
            <!-- /.modal-content -->
        </div>
          <!-- /.modal-dialog -->
      </div>
      <!-- /.modal -->

       <div class="modal fade" id="modal-default-parent">
        <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">Parent</h4>
            </div>
            <div class="form-group">
                <label for="inputcategory" class="col-sm-3 control-label">Name<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <input type="text" class="form-control" name="parent_name" placeholder="Enter" required="" autofocus="" id="parent_name_req">
                  </div>
            </div>
            <br><br>
            <div class="form-group">
                <label for="inputcategory" class="col-sm-3 control-label">Code<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <input type="text" class="form-control" name="parent_code" placeholder="Enter" required="" autofocus="" id="parent_code_req">
                  </div>
            </div>
            
            <br>
            <div class="modal-footer">
                <button type="button" id="close_parent" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
                <button type="button" id="add_parent" class="btn btn-primary">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="#revenue-chart" data-toggle="tab">Area</a></li>
                <li><a href="#sales-chart" data-toggle="tab">Donut</a></li>
                <li class="pull-left header"><i class="fa fa-inbox"></i> Unit</li>
              </ul> -->
              <div class="tab-content no-padding">
               <!-- right column -->
        
       <!-- Horizontal Form -->
             <div class="box box-info">
            
            <!-- /.box-header -->
            <!-- form start -->
             <form class="form-horizontal" action="{{route('customer.update')}}" method="POST">
              <input type="hidden" name="_token" value="{{{ csrf_token() }}}">
              <input type="hidden" name="id" value="{{$customer->id}}">
              <div class="box-body">
                <div class="col-sm-6">
                <div class="form-group">
                  <label for="inputcategory" class="col-sm-3 control-label">Customer<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <input type="text" class="form-control" name="name" value="{{$customer->name}}" required>
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-3 control-label">Customer Type<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <select class="form-control" name="type" required>
                      <option value="">Select</option>
                    @foreach($type as $ty)
                    @if($ty->id == $customer->customer_type_id)
                    <option value="{{$ty->id}}" selected>{{$ty->name}}</option>
                    @else
                    <option value="{{$ty->id}}">{{$ty->name}}</option>
                    @endif
                    @endforeach
                  </select>
                  </div>      
                </div>

                <div class="form-group">
                  <label class="col-sm-3 control-label">Industry Type </label>
                  <div class="col-sm-7">
                    <select class="form-control" name="industry">
                    <option value="">Select</option>
                    @foreach($industry as $ind)
                    @if($ind->id == $customer->industry_type)
                    <option value="{{$ind->id}}" selected>{{$ind->name}}</option>
                    @else
                    <option value="{{$ind->id}}">{{$ind->name}}</option>
                    @endif
                    @endforeach
                  </select>
                  </div>      
                </div>

                <div class="form-group">
                  <label for="inputcategory" class="col-sm-3 control-label">Contact Person<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <input type="text" class="form-control" name="cont_person" value="{{$customer->contact_person}}" required>
                  </div>
                </div>
                
              </div>

              <div class="col-sm-6">

                <div class="form-group">
                  <label class="col-sm-3 control-label">Code<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <input class="form-control" type="text" name="code" placeholder="Enter" value="{{$customer->customercode}}" required="true">
                  </div>      
                </div>

                <div class="form-group">
                  <label class="col-sm-3 control-label">Cost Center<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <select class="form-control select2" name="location[]" required="true" multiple='multiple' style="width: 100%;">
                      <option value="">Select</option>
                      @foreach($location as $loc)
                        @if(in_array($loc->id,$customer_loc))
                          <option value="{{$loc->id}}" selected>{{$loc->location}}</option>
                        @else
                          <option value="{{$loc->id}}">{{$loc->location}}</option>
                        @endif
                      @endforeach
                    </select>
                  </div>      
                </div>

                <div class="form-group">
                  <label for="inputcategory" class="col-sm-3 control-label">Place<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <input type="text" class="form-control" name="place" value="{{$customer->location}}" required>
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputcategory" class="col-sm-3 control-label">Address<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <textarea rows="4" cols="46" name="address" required>{{$customer->address}}</textarea>
                  </div>
                </div>

              </div>
            </div>

            <div>
              <div class="col-sm-6">

                <div class="form-group">
                  <br>
                  <label for="inputcategory" class="col-sm-3 control-label">Contact Number<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <input type="text" class="form-control" name="mob" value="{{$customer->mobileno}}" pattern="^\d*" maxlength="15" required>
                  </div>
                </div>
                
                <div class="form-group">
                  <label for="inputcategory" class="col-sm-3 control-label">Email ID </label>
                  <div class="col-sm-7">
                    <input type="email" class="form-control" name="email" value="{{$customer->email_id}}">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-3 control-label">Delivery Type</label>
                  <div class="col-sm-7">
                    <select class="form-control" name="d_type">
                      <option value="">Select</option>
                      @foreach($delivery as $del)
                        @if($del->id == $customer->delivery_type_id)
                          <option value="{{$del->id}}" selected>{{$del->name}}</option>
                        @else
                          <option value="{{$del->id}}">{{$del->name}}</option>
                        @endif
                      @endforeach
                    </select>
                  </div>      
                </div>

                <div class="form-group">
                  <label for="inputcategory" class="col-sm-3 control-label">Location<i style="color: red">*</i></label>
                  <span>
                  <div class="col-sm-7">
                     <select class="form-control select2" name="parent[]" id="parent" required="true" multiple='multiple' style="width: 100%;">
                      <option value="">Select</option>
                      @foreach($par_dtls as $par)
                      @if(in_array($par->id,$customer_parent))
                      <option value="{{$par->id}}" selected >{{$par->name}}</option>
                      @else
                          <option value="{{$par->id}}">{{$par->name}}</option>
                        @endif
                      @endforeach
                    </select>

                  </div>
                  <button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-default-parent">
                    +
                  </button>
                  </span>
                </div>

              </div>

              <div class="col-sm-6">

                <div class="form-group">
                  <br>
                  <label for="inputcategory" class="col-sm-3 control-label">Credit Limit </label>
                  <div class="col-sm-7">
                    <input type="text" class="form-control" name="limit" value="{{$customer->credit_limit}}">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputcategory" class="col-sm-3 control-label">Credit Period </label>
                  <div class="col-sm-7">
                    <input type="text" class="form-control" name="period" value="{{$customer->credit_period}}">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-3 control-label">Status<i style="color: red">*</i></label>
                  <div class="col-sm-7">
                    <select class="form-control" name="status" required>
                      <option value="">Select</option>
                      @foreach($status as $st)
                      @if($st->id == $customer->status)
                      <option value="{{$st->id}}" selected>{{$st->name}}</option>
                      @else
                      <option value="{{$st->id}}">{{$st->name}}</option>
                      @endif
                    @endforeach
                    </select>
                  </div>      
                </div>
              </div>
              <div class="col-sm-6">
                <div class="form-group">
                  <label for="inputcategory" class="col-sm-3 control-label">Mode<i style="color: red">*</i></label>
                  <span>
                  <div class="col-sm-7">
                    <select class="form-control" id="mode" name="mode" required>
                      <option value="">Select</option>
                      @foreach($mode_dtls as $mod)
                      <option value="{{$mod->id}}" @if($mod->id == $customer->mode_detail_id) selected @endif>{{$mod->mode_name}}</option>
                      @endforeach
                    </select>
                  </div>
                  <button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-default">
                    +
                  </button>
                  </span>
                </div>
              </div>
              </div>

              <!-- /.box-body -->
              <div class="box-footer">
                <div class="pull-right" style="margin-right: 95px;">
                <button type="reset" class="btn btn-default">Refresh</button>
                <button type="submit" class="btn btn-info">Save</button>
              </div>
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
          <!-- /.box --> 
                
          </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 -->
  @include('rightside')
  <!-- /.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>
  <!-- Select2 -->
  <script src="{{asset('lte/bower_components/select2/dist/js/select2.full.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>

  <!-- iCheck 1.0.1 -->
<script src="{{asset('lte/plugins/iCheck/icheck.min.js')}}"></script>
<script>
  $(function () {
    $('.select2').select2()
  })
  $(document).ready(function(){
    $("#add_mode").click(function(){
      $("#mode").val('');
      var new_mode = $.trim($("#new_mode").val()).toUpperCase();
      if(new_mode != '') {
        
        $.get("{{url('new/mode/update')}}", {new_mode: new_mode}, function(mode_data){
          if(mode_data != 0) {
            $("#mode").append("<option value='"+mode_data+"' selected>"+new_mode+"</option>");
            $("#close_mode").trigger("click");
          } else {
            $("#mode_name_req").text("Already Exist!");
          }
        });
        $("#mode option").each(function(){
          if($(this).text() == new_mode) {
            $("#mode_name_req").text("Already Exist!");
          } else {
            $("#mode_name_req").text("");
          }
        });
        
      } else {
        $("#mode_name_req").text("required!");
      }

    });

    $("#close_mode, .close").click(function(){
      $("#new_mode").val('');
      $("#mode_name_req").text("");
    });

    $("#add_parent").click(function(){
      
      var new_name = $.trim($("#parent_name_req").val()).toUpperCase();
      var new_code = $.trim($("#parent_code_req").val()).toUpperCase();
      if(new_name != '' || new_code != '' ) {
        
        $.get("{{url('new/parent/update')}}", {new_name: new_name,new_code: new_code}, function(parent_data){
          if(parent_data != 0) {           console.log(parent_data);
           $("#parent").append("<option value='"+parent_data+"' selected>"+new_name+"</option>");
            $("#close_parent").trigger("click");
          } else {
            $("#parent_name_req").text("Already Exist!");
            alert("Name or Code Already Exist!")
          }
        });
        $("#parent option").each(function(){
          if($(this).text() == new_name) {
            $("#parent_name_req").text("Already Exist!");
          } else {
            $("#parent_name_req").text("");
          }
        });
        
      } else {

        $("#parent_name_req").text("required!");
      }

    });

    $("#close_parent, .close").click(function(){
      $("#parent_name_req").val('');
      $("#parent_name_req").text("");
      $("#parent_code_req").val('');
      $("#parent_code_req").text("");
    });

  });
</script>
</body>


</html>
