<?php
   if( !hasPermission($_SESSION['user_detail']['role_id'], 'truck_add') ) {
      echo '<script>window.location.href="index.php?page=no_permission.php"</script>';die();
   }
   $voucher_no          = turckCode($conn);
   $g_act_codes         = accountCode($conn);
   
   if($_GET['type'] != 'truck' && $_GET['type'] != ''){
      $page       = 'truck';
      $truck_no   = '';
   }else{
      $page       = 'lr';
      $truck_no   = $_GET['no'];
   }
  
?>
<link rel="stylesheet" href="assets/plugins/toaster/jquery.toast.css">
<link rel="stylesheet" href="assets/plugins/toaster/jquery.toast.min.css">
<script src="assets/plugins/toaster/jquery.toast.js"></script>
 <style>
      .datepicker {
         z-index: 1051 !important;
      }

      /* Optional: for Bootstrap Datepicker dropdown */
      .datepicker-dropdown {
         z-index: 9999 !important;
      }

      /* Optional: for jQuery UI Datepicker */
      .ui-datepicker {
         z-index: 9999 !important;
      }
   </style>
<section class="content-header">
  <div class="row">
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 bottom20">
        <h3 class="capital font15 padding5 bold">ADD NEW TRUCK</h3>
      </div>
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 text-right bottom20">
        <h3>
          <?php if( hasPermission($_SESSION['user_detail']['role_id'], 'truck_list') ) { ?>
          <a href="index.php?page=truck_mst/list.php" class="btn btn-danger capital bottom10 custome-btn">VIEW TRUCK DETAILS</a>
          <?php } ?>
        </h3>
      </div>
  </div>
</section>
<hr class="bottom35"> 
<section class="hitz-top-header">
   <div class="row bottom40">
      <div class="col-xs-12">
         <div class="box box-success">
            <div class="box-body">
              <form action="truck_mst/insert.php" method="post" enctype="multipart/form-data" class="common-frm-validation" id="signupForm">
                 <div class="col-md-12">
                    <div class="row">
                        
                     <div class="col-md-3">
                          <div class="form-group">
                             <label class="capital">code</label>
                             <input type="text" size="35" id="truck_code" name="truck_code" placeholder="CODE" class="form-control" autocomplete="off" readonly="" value="<?php echo $voucher_no;?>" />
                          </div>
                       <div class="col-md-12">
                           <legend class="capital hitz-legend">owner information</legend>
                              <div class="col-md-12">
                                <div class="form-group">
                                   <label class="capital">name</label><span style="color: red">*</span>
                                   <input type="text" size="35" id="o_name" name="o_name" value="" class="form-control required" placeholder="NAME" autocomplete="off" />
                                </div>
                              </div>
                          <div class="col-md-12">
                             <div class="form-group">
                                <label class="capital">address</label>
                                <textarea class="form-control " name="o_address" id="o_address" style="height: 10% "></textarea> 
                             </div>
                          </div>
                          <div class="col-md-12">
                             <div class="form-group">
                                <label class="capital">city</label>
                                <input type="text" size="35" id="t_name" name="t_name" class="form-control" placeholder="NAME" autocomplete="off" value=""/ !important;>
                             </div>
                          </div>
                          <div class="col-md-12">
                             <div class="form-group">
                                <label class="capital">contact</label>
                                <input type="text" name="o_contact" id="o_contact" class="form-control" placeholder="CONTACT" value=""/>  
                             </div>
                          </div>
                          <div class="col-md-12">
                             <div class="form-group">
                                <label class="capital">pan</label>
                                <input type="text" name="o_pan" id="o_pan" class="form-control" placeholder="PAN" value=""/>  
                             </div>
                          </div>                       
                    </div>
                    </div>
                 <div class="col-md-9">
                     <div class="row">
                            <div class="col-md-2">
                        <div class="form-group">
                          <label class="radio-inline fontradiobuttion">
                           <input class="type own" type="radio" name="own" value="O"> <span class="label-text">OWN</span>
                        </label>
                     </div>
                  </div>
                        <div class="col-md-3">
                          <div class="form-group">
                             <label class="capital">truck no</label><span style="color: red">*</span>
                             <input type="text" size="35" id="truck_no" name="truck_no" value="" class="form-control required" autocomplete="off" placeholder="TRUCK NO" autofocus onChange="CheckTruck(this.value);" />
                          </div>
                       </div>
                    </div>
                    <div class="row">
                        
                           <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">REFERENCE</label>
                                <input type="text" size="35" id="t_name" name="t_name" class="form-control" placeholder="REFERENCE" autocomplete="off" value=""/>
                             </div>
                          </div>
                           <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">lorry type</label>
                                <input type="text" size="35" id="lorry_type" name="lorry_type" class="form-control" placeholder="LORRY TYPE" autocomplete="off" value=""/>
                             </div>
                          </div>
                           <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">chasis no</label>
                                <input type="text" size="35" id="chasis_no" name="chasis_no" class="form-control" placeholder="CHASIS NO" autocomplete="off" value=""/>
                             </div>
                          </div>
                          <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">Engine no</label>
                                <input type="text" size="35" id="eng_no" name="eng_no" class="form-control" placeholder="ENGINE NO" autocomplete="off" value=""/>
                             </div>
                          </div>
                          <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">NATIONAL permit no</label>
                                <input type="text" size="35" id="per_no" name="per_no" class="form-control" placeholder="PERMIT NO" autocomplete="off" value=""/>
                             </div>
                          </div>
                          <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">from</label>
                                <div class="input-group date">
                                   <div class="input-group-addon">
                                      <i class="fa fa-calendar"></i>
                                   </div>
                                   <input type="text" size="35" id="from" name="from" class="form-control date-picker" placeholder="FROM" autocomplete="off" value=""/>
                                </div>
                             </div>
                          </div>
                          <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">up to</label>
                                <div class="input-group date">
                                   <div class="input-group-addon">
                                      <i class="fa fa-calendar"></i>
                                   </div>
                                   <input type="text" size="35" id="up_to" name="up_to" class="form-control date-picker" placeholder="UP TO" autocomplete="off" value=""/>
                                </div>
                             </div>
                          </div> 
                          </div>
                          <div class="row"> 
                          <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">State permit no</label>
                                <input type="text" size="35" id="state_per_no" name="state_per_no" class="form-control" placeholder="PERMIT NO" autocomplete="off" value=""/>
                             </div>
                          </div>
                          <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">from</label>
                                <div class="input-group date">
                                   <div class="input-group-addon">
                                      <i class="fa fa-calendar"></i>
                                   </div>
                                   <input type="text" size="35" id="state_from" name="state_from" class="form-control date-picker" placeholder="FROM" autocomplete="off" value=""/>
                                </div>
                             </div>
                          </div>
                          <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">up to</label>
                                <div class="input-group date">
                                   <div class="input-group-addon">
                                      <i class="fa fa-calendar"></i>
                                   </div>
                                   <input type="text" size="35" id="state_up_to" name="state_up_to" class="form-control date-picker" placeholder="UP TO" autocomplete="off" value=""/>
                                </div>
                             </div>
                          </div> 
                    </div> 
                     <div class="row">
                           <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">insurance co.</label>
                                <input type="text" size="35" id="insurance" name="insurance" class="form-control" placeholder="INSURANCE CO." autocomplete="off" value=""/>
                             </div>
                           </div>
                  
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">branch</label>
                          <input type="text" size="35" id="branch" name="branch" class="form-control" placeholder="BRANCH" autocomplete="off" value=""/>
                       </div>
                    </div>
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">policy no</label>
                          <input type="text" size="35" id="policy" name="policy" class="form-control" placeholder="POLICY NO" autocomplete="off" value=""/>
                       </div>
                    </div>
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">up to</label>
                          <div class="input-group date">
                             <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                             </div>
                             <input type="text" size="35" id="up_too" name="up_too" class="form-control date-picker" placeholder="UP TO" autocomplete="off" value=""/>
                          </div>
                       </div>
                    </div>
                     </div>
                     <div class="row">
                           <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">PUC NO.</label>
                                <input type="text" size="35" id="puc_no" name="puc_no" class="form-control" placeholder="PUC NO." autocomplete="off" value=""/>
                             </div>
                           </div>
                  
                   
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">VALID up to</label>
                          <div class="input-group date">
                             <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                             </div>
                             <input type="text" size="35" id="puc_up_to" name="puc_up_to" class="form-control date-picker" placeholder="UP TO" autocomplete="off" value=""/>
                          </div>
                       </div>
                    </div>
                     </div>

                     <div class="row">
                           <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">FITNESS NO.</label>
                                <input type="text" size="35" id="fitness" name="fitness" class="form-control" placeholder="FITNESS." autocomplete="off" value=""/>
                             </div>
                           </div>
                  
                   
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">VALID up to</label>
                          <div class="input-group date">
                             <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                             </div>
                             <input type="text" size="35" id="fitness_up_to" name="fitness_up_to" class="form-control date-picker" placeholder="UP TO" autocomplete="off" value=""/>
                          </div>
                       </div>
                    </div>
                     </div>

                     <div class="row">
                           <div class="col-md-3">
                             <div class="form-group">
                                <label class="capital">TAX NO.</label>
                                <input type="text" size="35" id="tax_no" name="tax_no" class="form-control" placeholder="TAX NO." autocomplete="off" value=""/>
                             </div>
                           </div>
                  
                   
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">VALID up to</label>
                          <div class="input-group date">
                             <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                             </div>
                             <input type="text" size="35" id="tax_up_to" name="tax_up_to" class="form-control date-picker" placeholder="UP TO" autocomplete="off" value=""/>
                          </div>
                       </div>
                    </div>
                     </div>
                 <div class="row">
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">height</label>
                          <input type="text" size="35" id="height" name="height" class="form-control" placeholder="HEIGHT" autocomplete="off" value=""/>
                       </div>
                    </div>
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">weight(mt)</label>
                          <input type="text" size="35" id="weight" name="weight" class="form-control" placeholder="WEIGHT(MT)" autocomplete="off" value=""/>
                       </div>
                    </div>
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">RC NO</label>
                          <input type="text" size="35" id="rc_no" name="rc_no" class="form-control" placeholder="RC NO" autocomplete="off" value=""/>
                       </div>
                    </div>
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">PAN NO</label>
                          <input type="text" size="35" id="pan_no" name="pan_no" class="form-control" placeholder="PAN NO" autocomplete="off" value=""/>
                       </div>
                    </div>
                  </div>  
                  <div class="row">  
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">RC FRONT</label>
                          <input type="file" size="35" id="rc_img" name="rc_img"/>
                          <input type="hidden" name="old_rc_img" value="">
                          <br/>
                          <?php
                          if($update_row['rc_img']==''){ ?>
                          <img src="assets/default.png" style="width: 100px;">
                          <?php }else{ ?>
                          <a href="assets/upload/rc/" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" title="VIEW IMAGE...!!" target="_blank"><em class="fa fa-file-image-o"></em></a>
                          <?php } ?>
                       </div>
                    </div>
                    <div class="col-md-3">
                      <div class="form-group">
                        <label class="capital">RC BACK</label>
                        <input type="file" size="35" id="rc_img_back" name="rc_img_back"/>
                        <input type="hidden" name="rc_back_img" id="rc_back_img" value=""><br/>
                        <?php
                        if($update_row['rc_img_back']==''){ ?>
                        <img src="assets/default.png" style="width: 100px;">
                        <?php }else{ ?>
                        <a href="assets/upload/rc/" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" title="VIEW IMAGE...!!" target="_blank"><em class="fa fa-file-image-o"></em></a>
                        <?php } ?>
                      </div>
                    </div>
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">PAN IMAGE</label>
                          <input type="file" size="35" id="pan_img" name="pan_img"/><br/>
                          <input type="hidden" size="35" id="old_pan_img" name="old_pan_img" value=""/>
                          <?php
                          if($update_row['pan_img']==''){ ?>
                            <img src="assets/default.png" style="width: 100px;">
                          <?php }else{ ?>
                            <a href="assets/upload/pan/" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" title="VIEW IMAGE...!!" target="_blank"><em class="fa fa-file-image-o"></em></a>
                          <?php } ?>
                       </div>
                    </div>
                    <div class="col-md-3">
                       <div class="form-group">
                          <label class="capital">DECLARATION</label>
                          <input type="file" size="35" id="dec_img" name="dec_img"/>
                          <input type="hidden" name="dec_imgs" id="dec_imgs" value=""><br/>
                          <?php
                          if($update_row['dec_img']==''){ ?>
                          <img src="assets/default.png" style="width: 100px;">
                          <?php }else{ ?>
                          <a href="assets/upload/declaration/" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" title="VIEW IMAGE...!!" target="_blank"><em class="fa fa-file-image-o"></em></a>
                          <?php } ?>
                       </div>
                       <div class="form-group">
                          <div class="progress_dec" style="display:none;height: 0.5rem;    margin-left: 1px;">
                             <div class="progress-bar progress-bar-success mydecprogress" role="progressbar" style="width:0%; display:none; background-color:#1bb99a">0%</div>
                          </div>
                          <p style="margin-bottom:0rem;">&nbsp;</p>
                          <span id="dec_img_uplode" style="position: relative;bottom: 28px;"></span>
                       </div>
                    </div>
                   </div> 
                    <div class="col-md-12">
                       <div class="form-group">
                          <label class="capital">remark</label>
                          <textarea class="form-control" name="remark" id="remark" style="height: 10% !important;"></textarea>
                       </div>
                    </div>          
              </div>
              </div>
                <input type="hidden" value="" name="id" id="id">
                <input type="hidden" value="truck" name="page_name" id="page_name">
                <hr>
                <div class="row" align="center">
                  <button id="btn" class="btn btn-primary ajax-submit capital" type="submit" onclick="CheckTruck();"> <?php echo ($id == 0) ? 'Save & List' : 'Update & save'; ?></button>
                  <a href="index.php?page=truck_mst/list.php" class="btn btn-danger capital"> Cancel</a>
                </div>
              </form>
              
            </div>
         </div>
      </div>
   </div>
</section>
<script type="text/javascript">
  $( function() {
    $( ".get_city" ).autocomplete({
        source: function( request, response ) {
          $.ajax({
              url: "truck_mst/get_city.php",
              type: 'post',
              dataType: "json",
              data: {
                  search: request.term
              },
              success: function( data ) {
                  response( data );
              }
          });
        },
        select: function (event, ui) {
            $('#get_city').val(ui.item.label);
            return false;
        }
    });
    $( "#t_city" ).autocomplete({
        source: function( request, response ) {
          $.ajax({
              url: "truck_mst/get_t_city.php",
              type: 'post',
              dataType: "json",
              data: {
                  search: request.term
              },
              success: function( data ) {
                  response( data );
              }
          });
        },
        select: function (event, ui) {
            $('#t_city').val(ui.item.label);
            return false;
        }
    });
    $( "#d_city" ).autocomplete({
        source: function( request, response ) {
          $.ajax({
              url: "truck_mst/get_d_city.php",
              type: 'post',
              dataType: "json",
              data: {
                  search: request.term
              },
              success: function( data ) {
                  response( data );
              }
          });
        },
        select: function (event, ui) {
            $('#d_city').val(ui.item.label);
            return false;
        }
    });
    $( "#tr_city" ).autocomplete({
        source: function( request, response ) {
          $.ajax({
              url: "truck_mst/get_tr_city.php",
              type: 'post',
              dataType: "json",
              data: {
                  search: request.term
              },
              success: function( data ) {
                  response( data );
              }
          });
        },
        select: function (event, ui) {
            $('#tr_city').val(ui.item.label);
            return false;
        }
    });

   $( "#o_name" ).autocomplete({
      source: function( request, response ) {
         $.ajax({
            url: "truck_mst/get_owner_data.php",
            type: 'post',
            dataType: "json",
            data: {
               search: request.term
            },
            success: function( data ) {
               response( data );
            }
         });
      },
      select: function (event, ui) {
         $('#o_name').val(ui.item.o_name);
         $('#o_address').val(ui.item.o_address);
         $('#o_city').val(ui.item.o_city);
         $('#o_contact').val(ui.item.o_contact);
         $('#o_pan').val(ui.item.o_pan);
         return false;
      }
   }).each(function() {
      $(this).autocomplete( 'instance' )._renderItem = function( ul, item ) {
        return $( "<li>" )
        .append( "<a><span>" + item.o_name + '</span></a>' )
        .appendTo( ul );
      };
   });

   /*TRANSPORT*/
   $( "#t_name" ).autocomplete({
      source: function( request, response ) {
         $.ajax({
            url: "truck_mst/get_transport_data.php",
            type: 'post',
            dataType: "json",
            data: {
               search: request.term
            },
            success: function( data ) {
               response( data );
            }
         });
      },
      select: function (event, ui) {
         $('#t_name').val(ui.item.t_name);
         $('#t_address').val(ui.item.t_address);
         $('#t_city').val(ui.item.t_city);
         $('#t_contact').val(ui.item.t_contact);
         $('#t_pan').val(ui.item.t_pan);
         return false;
      }
   }).each(function() {
      $(this).autocomplete( 'instance' )._renderItem = function( ul, item ) {
        return $( "<li>" )
        .append( "<a><span>" + item.t_name + '</span></a>' )
        .appendTo( ul );
      };
   });

   /*DRIVER*/
   $( "#d_name" ).autocomplete({
      source: function( request, response ) {
         $.ajax({
            url: "truck_mst/get_driver_data.php",
            type: 'post',
            dataType: "json",
            data: {
               search: request.term
            },
            success: function( data ) {
               response( data );
            }
         });
      },
      select: function (event, ui) {
         $('#d_name').val(ui.item.d_name);
         $('#d_address').val(ui.item.d_address);
         $('#d_city').val(ui.item.d_city);
         $('#d_contact').val(ui.item.d_contact);
         $('#d_pan').val(ui.item.d_pan);
         $('#lic_no').val(ui.item.lic_no);
         $('#rto').val(ui.item.rto);
         return false;
      }
   }).each(function() {
      $(this).autocomplete( 'instance' )._renderItem = function( ul, item ) {
        return $( "<li>" )
        .append( "<a><span>" + item.d_name + '</span></a>' )
        .appendTo( ul );
      };
   });

   /*TRUCK*/
   $( "#tr_name" ).autocomplete({
      source: function( request, response ) {
         $.ajax({
            url: "truck_mst/get_truck_hire_data.php",
            type: 'post',
            dataType: "json",
            data: {
               search: request.term
            },
            success: function( data ) {
               response( data );
            }
         });
      },
      select: function (event, ui) {
         $('#tr_name').val(ui.item.tr_name);
         $('#tr_address').val(ui.item.tr_address);
         $('#tr_city').val(ui.item.tr_city);
         $('#tr_contact').val(ui.item.tr_contact);
      }
   }).each(function() {
      $(this).autocomplete( 'instance' )._renderItem = function( ul, item ) {
        return $( "<li>" )
        .append( "<a><span>" + item.tr_name + '</span></a>' )
        .appendTo( ul );
      };
   });

  });
  
   function CheckTruck() {
      var truck_no      = $("#truck_no").val();
      $.ajax({
      'type': 'POST',
      'url': 'truck_mst/check_truck_no.php',
      'data': {
        'truck_no': truck_no
      },
      dataType: 'JSON',
      success: function (result) {
         if(result.status == 1) {
            swal("Opps !!", "ALREADY CODE EXIST...!!!", "info")  
            $('#truck_no').val('').trigger('focus');   
         }else{
          jQuery('.ajax-submit').attr('enable', true);
         }
      }
    });
  };
  
</script>