<!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">

  <!-- 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>
          Supplier Management
        </h1>
        <ol class="breadcrumb">
          <li><a href="{{route('supplier.list')}}"><i class="fa fa-dashboard"></i> Supplier</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">Add Country</h4>
              </div>
              <div class="modal-body">

               <div class="form-group">
                  <div class="col-sm-10">
                    <label for="newcountry" class="col-sm-4 control-label">Country Name<i style="color: red">*</i></label>
                    <div class="col-sm-6">
                      <input type="text" class="form-control" name="newcountry" id="newcountry" placeholder="Enter" required="" autofocus="">
                    </div>
                  </div>
               </div>
               <br>

              </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" data-dismiss="modal" aria-hidden="true" id="save">Save</button>
              </div>
            </div>
            <!-- /.modal-content -->
          </div>
          <!-- /.modal-dialog -->
      </div>
        <!-- /.modal -->

      <!-- 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">
            <div class="box-header">
                <h3 class="box-title"></h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
             <form class="form-horizontal" action="{{route('supplier.update')}}" method="POST">
              <input type="hidden" name="_token" value="{{{ csrf_token() }}}">
              <input type="hidden" name="id" value="{{$sup->id}}">
              <div class="box-body">
                <div class="form-group">
                  <div class="col-md-6">
                    <label for="inputcategory" class="col-md-4 control-label">Supplier Name<i style="color: red">*</i></label>
                    <div class="col-md-6">
                      <input type="text" class="form-control" name="name" value="{{$sup->name}}" required="" autofocus="">
                    </div>
                  </div>

                  <div class="col-md-6">
                    <label for="inputcategory" class="col-md-2 control-label">Address<i style="color: red">*</i></label>
                    <div class="col-md-3">
                      <textarea rows="5" cols="39" name="address">{{$sup->address}}</textarea>
                    </div>
                  </div>

                  <div class="col-md-6">
                    <label for="country" class="col-md-4 control-label">Country<i style="color: red">*</i></label>
                    <div class="col-md-6">
                      <select class="form-control" name="country" id="country" required="">
                        <option value="">Select</option>
                        @foreach($country as $cntry)
                        <option value="{{$cntry->id}}" @if($sup->country_id == $cntry->id) selected @endif>{{$cntry->country}}</option>
                        @endforeach
                      </select>
                    </div>
                    <div class="col-md-1">
                     <a class="btn btn-primary glyphicon-plus pull-right" id="addcountry" data-toggle="modal" data-target="#modal-default"></a>
                    </div>
                  </div>

                </div>

              </div>
              <!-- /.box-body -->
              <div class="box-body">
                <div>
                  <label><i>Contact 1</i></label>
                  <div class="form-group">
                    <div class="col-md-4">
                      <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" name="contact_p1" class="form-control" value="{{$sup->contact_p1}}" required="">
                      </div>
                    </div>

                    <div class="col-md-4">
                      <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="mobile1" value="{{$sup->contact_no1}}"  pattern="^\d*" maxlength="15" required>
                      </div>
                    </div>

                    <div class="col-md-4">
                      <label for="inputcategory" class="col-sm-3 control-label">Email ID<i style="color: red">*</i></label>
                      <div class="col-sm-8">
                        <input type="email" name="email1" class="form-control" value="{{$sup->email1}}" required="">
                      </div>
                    </div>

                  </div>
                </div>

                <div>
                  <label><i>Contact 2</i></label>
                  <div class="form-group">
                    <div class="col-md-4">
                      <label for="inputcategory" class="col-sm-3 control-label">Contact Person</label>
                      <div class="col-sm-7">
                        <input type="text" name="contact_p2" class="form-control" value="{{$sup->contact_p2}}">
                      </div>
                    </div>

                    <div class="col-md-4">
                      <label for="inputcategory" class="col-sm-3 control-label">Contact Number</label>
                      <div class="col-sm-7">
                        <input type="text" class="form-control" name="mobile2" value="{{$sup->contact_no2}}"pattern="^\d*" maxlength="15">
                      </div>
                    </div>

                    <div class="col-md-4">
                      <label for="inputcategory" class="col-sm-3 control-label">Email ID</label>
                      <div class="col-sm-8">
                        <input type="email" name="email2" class="form-control" value="{{$sup->email2}}">
                      </div>
                    </div>

                  </div>
                </div>
                
              </div>
              <!-- /.box-body -->
              <div class="box-footer"></div>
              <!-- /.box-footer -->

              <div class="box-body">

                <div class="col-md-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 type="text" name="supCode" value="{{$sup->sup_code}}" class="form-control" required="">
                    </div>      
                  </div>

                  <div class="form-group">
                    <label class="col-sm-3 control-label">Preferred Company Code <i style="color: red">*</i></label>
                    <div class="col-sm-7">
                      <select class="form-control" name="office" required="">
                        <option value="">Select</option>
                        @foreach($office as $off)
                        @if($sup->office_id == $off->id)
                        <option value="{{$off->id}}" selected="">{{$off->office}}</option>
                        @else
                        <option value="{{$off->id}}">{{$off->office}}</option>
                        @endif
                        @endforeach
                      </select>
                    </div>      
                  </div>

                  <div class="form-group">
                    <label class="col-sm-3 control-label">Supplier Type </label>
                    <div class="col-sm-7">
                      <select class="form-control" name="s_type">
                        <option value="">Select</option>
                        @foreach($supplier as $ty)
                        @if($ty->id == $sup->supplier_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">Preferred Currency<i style="color: red">*</i></label>
                    <div class="col-sm-7">
                      <select class="form-control" name="currency" id="currency" required>
                        @foreach($currency as $cur)
                        @if($sup->currency_type_id == $cur->id)
                        <option value="{{$cur->id}}" selected>{{$cur->currency}}</option>
                        @else
                        <option value="{{$cur->id}}">{{$cur->currency}}</option>
                        @endif
                        @endforeach
                      </select>
                    </div>      
                  </div>

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

                  <div class="form-group">
                    <label for="inputcategory" class="col-sm-3 control-label">Credit Period </label>
                    <div class="col-sm-6">
                      <input type="text" class="form-control" name="period" value="{{$sup->credit_period}}">
                    </div>
                    <label class="control-label">/day(s)</label>
                  </div>

                </div>

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

                  <div class="form-group">
                    <label class="col-sm-3 control-label">Delivery Type<i style="color: red">*</i></label>
                    <div class="col-sm-7">
                      <select class="form-control" name="d_type" required>
                        <option value="">Select</option>
                        @foreach($delivery as $del)
                        @if($del->id == $sup->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 class="col-sm-3 control-label">Mode of Payment<i style="color: red">*</i></label>
                    <div class="col-sm-8">
                      @foreach($pay as $mode)
                      @if($mode->id == $sup->payment_type_id)
                        <input type="radio" name="pay" value="{{$mode->id}}" class="minimal" checked required>
                        {{$mode->name}} &nbsp; &nbsp;
                      @else
                         <input type="radio" name="pay" value="{{$mode->id}}" class="minimal" required>
                        {{$mode->name}} &nbsp; &nbsp;
                      @endif
                      @endforeach
                    </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 == $sup->status_id)
                        <option value="{{$st->id}}" selected>{{$st->name}}</option>
                        @else
                        <option value="{{$st->id}}">{{$st->name}}</option>
                        @endif
                        @endforeach
                      </select>
                    </div>      
                  </div>

                  <div class="form-group">
                    <label for="inputcategory" class="col-sm-3 control-label">Shipping Terms<i style="color: red">*</i></label>
                    <div class="col-sm-7">
                      <textarea rows="5" cols="43" name="shipping" class="form-control">{{$sup->shipping_terms}}</textarea>
                    </div>
                  </div>

                </div>

              </div>
              <!-- /.box-body -->

<div class="box-body">
  <div class="box-header">
                <h3 class="box-title">Bank Details</h3>
  </div>
</br></hr>
        <div class="col-md-6">

                  <div class="form-group">
                    <label class="col-sm-3 control-label">Beneficiary name</label>
                    <div class="col-sm-7">
                       <input type="text" class="form-control" name="ben_name" value="{{$sup->ben_name}}"placeholder="Enter">
                    </div>      
                  </div>

                  <div class="form-group">
                    <label class="col-sm-3 control-label">Bank name</label>
                    <div class="col-sm-7">
                       <input type="text" class="form-control" name="bank_name" value="{{$sup->bank_name}}" placeholder="Enter">
                    </div>      
                  </div>
                  <div class="form-group">
                    <label class="col-sm-3 control-label">Swift code</label>
                    <div class="col-sm-7">
                       <input type="text" class="form-control" name="swift_code" value="{{$sup->swift_code}}" placeholder="Enter">
                    </div>      
                  </div>
                  <div class="form-group">
                    <label class="col-sm-3 control-label">Bank Address</label>
                    <div class="col-sm-7">
                        <textarea rows="5" cols="39" name="bank_address">{{$sup->bank_addrs}}</textarea>
                    </div>      
                  </div>
      </div>
       <div class="col-md-6">

                  <div class="form-group">
                    <label class="col-sm-3 control-label">Account Number</label>
                    <div class="col-sm-7">
                       <input type="text" class="form-control" name="acc_number" value="{{$sup->account_number}}" placeholder="Enter">
                    </div>      
                  </div>

                  <div class="form-group">
                    <label class="col-sm-3 control-label">Branch name</label>
                    <div class="col-sm-7">
                       <input type="text" class="form-control" name="branch_name" value="{{$sup->branch_name}}" placeholder="Enter">
                    </div>      
                  </div>
                  <div class="form-group">
                    <label class="col-sm-3 control-label">IBAN Code</label>
                    <div class="col-sm-7">
                       <input type="text" class="form-control" name="iban" value="{{$sup->iban}}" placeholder="Enter">
                    </div>      
                  </div>
      </div>
 </div>
              <div class="box-footer">
                <div class="pull-right" style="margin-right: 49px;">
                  <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>
  
  <!-- 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>
</body>
</html>

<script type="text/javascript">
  $(document).ready(function() {
    var curr = $("#currency option:selected").text();
    $("#label_curr").text('/'+curr);
  });

  $(document).on("change","#currency", function() {
     var curr = $("#currency option:selected").text();
    $("#label_curr").text('/'+curr);
  });

  $('#save').on('click', function(e){  
      var name = $.trim($('#newcountry').val()); 
      if (name  === '') {
          alert('Enter a country name.');
          return false;
      }

      $.get("{{url('country/add')}}", {country: name}, function(data){  
        if(data == 1){
          alert('Country already exist.'); 
        }
        else{
          $('#country').append('<option value="'+data.id+'">'+data.country+'</option>'); 
        }
                
      });
      $('#newcountry').val("").text();
  });
</script>