<?php
if( !hasPermission($_SESSION['user_detail']['role_id'], 'lr_edit') ) {
  echo '<script>window.location.href="index.php?page=no_permission.php"</script>';die();
}

$vendor     = "SELECT * FROM `vendor_master` WHERE `company_id` ='".$_SESSION['company_id']."' AND `status` = '0'";
$vendor_res = mysqli_query($conn,$vendor);

$vendors      = "SELECT * FROM `vendor_master` WHERE `company_id` ='".$_SESSION['company_id']."' AND `status` = '0'";
$vendor_resu  = mysqli_query($conn,$vendors);

$bill     = "SELECT * FROM `vendor_master` WHERE `company_id` ='".$_SESSION['company_id']."' AND `status` = '0'";
$bill_res = mysqli_query($conn,$bill);

if (isset($_REQUEST['eid']) && !empty($_REQUEST['eid'])){
  $select_update     = "SELECT * FROM lr_mst WHERE lr_no='".$_REQUEST['eid']."' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."'";
  $select_update_res = mysqli_query($conn,$select_update);
  $update_row         = mysqli_fetch_array($select_update_res,MYSQLI_BOTH);
  $delivery_type = $update_row['delivery']; 
}

$lr_cons     = "SELECT * FROM `lr_mst` WHERE `lr_no` = '".$_REQUEST['eid']."'";
$lr_cons_res = mysqli_query($conn,$lr_cons);
$lr_cons_row = mysqli_fetch_array($lr_cons_res);

$con     = "SELECT * FROM `vendor_master` WHERE `id` = '".$update_row['consignor_name']."'";
$con_res = mysqli_query($conn,$con);
$con_row = mysqli_fetch_array($con_res);

$cons     = "SELECT * FROM `vendor_master` WHERE `id` = '".$update_row['consignee_name']."'";
$cons_res = mysqli_query($conn,$cons);
$cons_row = mysqli_fetch_array($cons_res);

if($lr_cons_row['consignee_address'] == ''){
  $consignee_address = $cons_row['address'];
}else{
  $consignee_address = $lr_cons_row['consignee_address'];
}


if($lr_cons_row['consignee_city'] == ''){
  $consignee_city = $cons_row['city'];
}else{
  $consignee_city = $lr_cons_row['consignee_city'];
}

if($lr_cons_row['consignee_contact'] == ''){
  $consignee_contact = $cons_row['mobile'];
}else{
  $consignee_contact = $lr_cons_row['consignee_contact'];
}

if($lr_cons_row['consignee_pan'] == ''){
  $consignee_pan = $cons_row['pan'];
}else{
  $consignee_pan = $lr_cons_row['consignee_pan'];
}

if($lr_cons_row['consignee_gst'] == ''){
  $consignee_gst = $cons_row['gstin'];
}else{
  $consignee_gst = $lr_cons_row['consignee_gst'];
}

$bills      = "SELECT * FROM `vendor_master` WHERE `id` = '".$update_row['billing_to']."'";
$bills_res  = mysqli_query($conn,$bills);
$bill_rows  = mysqli_fetch_array($bills_res);

$agent = mysqli_query($conn, "SELECT * FROM `vendor_master` WHERE `type` = 'A' AND `status` = '0'");
$agent_data = array();
while ($agent_row = mysqli_fetch_assoc($agent)) {
  $agent_data[] = $agent_row;
}
$branch = "SELECT * FROM `branch_mst` WHERE `id` = '".$_SESSION['branch_id']."'";
$bra_res = mysqli_query($conn,$branch);
$bra_row = mysqli_fetch_array($bra_res);

$exp = mysqli_query($conn, "SELECT * FROM `lr_expense_details` WHERE `lr_no` = '".$_REQUEST['eid']."'");
$exp_data = array();
while ($exp_row = mysqli_fetch_assoc($exp)) {
   $exp_data[] = $exp_row;
}
?>
<style type="text/css">
 .ui-autocomplete {
  border: 1px solid #730215 !important;
  width: 20% !important;
}
.jq-icon-warning{
  background-color: #f39c12 !important;
}
</style>

 <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">UPDATE LR</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'], 'lr_list') ) { ?>
        <a href="index.php?page=lr/list.php" class="btn btn-danger capital bottom10 custome-btn">VIEW LR 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="lr/insert.php" method="post" enctype="multipart/form-data" class="common-frm-validation" id="signupForm">
                  <div class="row">
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">LR TYPE</label><span style="color: red">*</span><br>
                           <label class="radio-inline fontradiobuttion">
                              <input class="type lr_type" type="radio" name="lr_type" value="D" <?php if($update_row['lr_type'] == 'D'){echo "checked";}?>> <span class="label-text">Dummy</span>
                           </label>
                           <label class="radio-inline fontradiobuttion">
                              <input class="type lr_type" type="radio" name="lr_type" value="O" <?php if($update_row['lr_type']=='O'){echo "checked";}?>> <span class="label-text">Original</span>
                           </label>
                        </div>
                     </div>
                     <div class="col-md-2">
                        <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" class="form-control" autofocus="" autocomplete="off" placeholder="TRUCK NO" onchange="get_Truck_weight(this);CheckUplode(this);" value="<?php echo $update_row['truck_no'];?>" />
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">LR.NO</label><span style="color: red">*</span>
                           <?php 
                           if($codeType == 1){  ?>
                              <input type="text" size="35" id="lr_no" name="lr_no" class="form-control lr_number required" autocomplete="off" placeholder="LR.NO" onChange="CheckNumberSeries(this.value);CheckCode(this.value);" value="<?php echo $update_row['lr_no'];?>" readonly=""/>
                           <?php }else{ ?>
                              <input type="text" size="35" id="lr_no" name="lr_no" class="form-control lr_number required" autocomplete="off" placeholder="LR.NO" onChange="CheckCode(this.value);" autofocus="" value="<?php echo $update_row['lr_no'];?>" readonly=""/>
                           <?php } ?>
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">DATE</label><span style="color: red">*</span>
                           <div class="input-group date">
                              <div class="input-group-addon">
                                 <i class="fa fa-calendar"></i>
                              </div>
                              <input type="text" size="35" id="l_date" name="l_date" class="form-control date-picker required" placeholder="DATE" autocomplete="off" value="<?php echo date('d-m-Y', strtotime($update_row['l_date']));?>"onfocusout="CheckDate(this.value);" />
                           </div>
                        </div>
                     </div>

                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">FROM PLACE</label><span style="color: red">*</span>
                           <input type="text" size="35" id="from_place" name="from_place" class="form-control required" autocomplete="off" placeholder="FROM PLACE" value="<?php echo $update_row['from_place'];?>" />
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">TO PLACE</label><span style="color: red">*</span>
                           <input type="text" size="35" id="to_place" name="to_place" class="form-control required" autocomplete="off" placeholder="TO PLACE" value="<?php echo $update_row['to_place'];?>" />
                        </div>
                     </div>
                  </div>
                  <div class="row">
                     <div class="col-md-1">
                        <div class="form-group">
                           <label class="capital">INVOICE</label>
                           <input type="text" size="35" id="party_invoice" name="party_invoice" class="form-control" autocomplete="off" placeholder="INVOICE" value="<?php echo $update_row['party_invoice'];?>"/>
                        </div>
                     </div>
                     <div class="col-md-1">
                        <div class="form-group">
                           <label class="capital">INV.AMOUNT</label>
                           <input type="text" size="35" id="party_amount" name="party_amount" class="form-control number" autocomplete="off" placeholder="INVOICE AMOUNT" value="<?php echo $update_row['party_amount'];?>"/>
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">INVOICE DATE</label>
                           <div class="input-group date date-picker" data-date-format="dd-mm-yyyy">
                              <div class="input-group-addon">
                                 <i class="fa fa-calendar"></i>
                              </div>
                              <input type="text" size="35" id="invoice_date" name="invoice_date" class="form-control" placeholder="INVOICE DATE" autocomplete="off" value="<?php echo date('d-m-Y', strtotime($update_row['invoice_date']));?>"/>
                           </div>
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">EWAY BILL NO</label> 
                           <input type="text" name="eway_bill_no" id="eway_bill_no" class="form-control" value="<?php echo $update_row['eway_bill_no'];?>">
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">EWAY BILL DATE</label>
                           <div class="input-group date date-picker" data-date-format="dd-mm-yyyy">
                              <div class="input-group-addon">
                                 <i class="fa fa-calendar"></i>
                              </div>
                              <input type="text" size="35" id="eway_date" name="eway_date" class="form-control" placeholder="EWAY BILL DATE" autocomplete="off" value="<?php echo date('d-m-Y', strtotime($update_row['eway_date']));?>"/>
                           </div>
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">EWAY EX. DATE</label>
                           <div class="input-group date date-picker" data-date-format="dd-mm-yyyy">
                              <div class="input-group-addon">
                                 <i class="fa fa-calendar"></i>
                              </div>
                              <input type="text" size="35" id="eway_ex_date" name="eway_ex_date" class="form-control" placeholder="EWAY EX. DATE" autocomplete="off" value="<?php echo date('d-m-Y', strtotime($update_row['eway_ex_date']));?>"/>
                           </div>
                        </div>
                     </div>

                  </div>
                  <div class="row">
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">Challan No.</label> 
                           <input type="text" name="challan_no" id="challan_no" class="form-control" autocomplete="off" value="<?php echo $update_row['challan_no'];?>">
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">challan date</label>
                           <div class="input-group date date-picker" data-date-format="dd-mm-yyyy">
                              <div class="input-group-addon">
                                 <i class="fa fa-calendar"></i>
                              </div>
                              <input type="text" size="35" id="po_date" name="po_date" class="form-control" placeholder="PO DATE" autocomplete="off" value="<?php echo date('d-m-Y', strtotime($update_row['po_date']));?>"/>
                           </div>
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">METHOD OF PACKING</label> 
                           <input type="text" name="packing" id="packing" class="form-control" autocomplete="off" value="<?php echo $update_row['packing'];?>">
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">Vehicle TYPE</label> 
                           <input type="text" name="lorry_type" id="lorry_type" class="form-control"  autocomplete="off"  value="<?php echo $update_row['lorry_type']?>">
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">WEIGHT</label> 
                           <input type="text" name="weight" id="weight" class="form-control"  autocomplete="off"  value="<?php echo $update_row['weight']?>">
                        </div>
                     </div>
                  </div>
                  <div class="row">
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">insurance status</label> 
                           <input type="text" name="insurance_status" id="insurance_status" class="form-control" autocomplete="off" value="<?php echo $update_row['insurance_status'];?>">
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">INSURANCE date</label>
                           <div class="input-group date date-picker" data-date-format="dd-mm-yyyy">
                              <div class="input-group-addon">
                                 <i class="fa fa-calendar"></i>
                              </div>
                              <input type="text" size="35" id="insurance_date" name="insurance_date" class="form-control" placeholder=" DATE" autocomplete="off" value="<?php echo date('d-m-Y', strtotime($update_row['insurance_date']));?>"/>
                           </div>
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">insured by</label> 
                           <input type="text" name="insured_by" id="insured_by" class="form-control" autocomplete="off" value="<?php echo $update_row['insured_by'];?>">
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">policy no</label> 
                           <input type="text" name="policy_no" id="policy_no" class="form-control" value="<?php echo $update_row['policy_no'];?>">
                        </div>
                     </div>
                     <div class="col-md-2">
                        <div class="form-group">
                           <label class="capital">notes</label> 
                           <input type="text" name="notes" id="notes" class="form-control" value="<?php echo $update_row['notes'];?>">
                        </div>
                     </div>
                  </div>

                  <div class="row">
                    <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">LR MODE</label> 
                        <select class="form-control select2" name="lr_mode" id="lr_mode">
                           <option></option>
                           <option <?php if($update_row['lr_mode'] == 'NONE') { ?> selected="selected"<?php } ?> value="NONE">NONE</option>
                           <option <?php if($update_row['lr_mode'] == 'TO BE BILLED') { ?> selected="selected"<?php } ?> value="TO BE BILLED">TO BE BILLED</option>
                           <option <?php if($update_row['lr_mode'] == 'TO PAY') { ?> selected="selected"<?php } ?> value="TO PAY">TO PAY</option>
                           <option <?php if($update_row['lr_mode'] == 'PAID') { ?> selected="selected"<?php } ?> value="PAID">PAID</option>
                           <option <?php if($update_row['lr_mode'] == 'FOC') { ?> selected="selected"<?php } ?> value="FOC">FOC</option>
                        </select>
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">DELIVERY OPTION</label> 
                        <select class="form-control select2" name="delivery" id="delivery">
                           <option></option>
                           <option <?php if($update_row['delivery'] == 'DOOR') { ?> selected="selected"<?php } ?> value="DOOR">DOOR DELIVERY</option>
                           <option <?php if($update_row['delivery'] == 'GODOWN') { ?> selected="selected"<?php } ?> value="GODOWN">GODOWN DELIVERY</option>
                        </select>
                     </div>
                  </div>   
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"> Tranport Mode</label> 
                        <input type="text" name="mode" id="mode" class="form-control" value="<?php echo $update_row['mode'];?>">
                     </div>
                  </div>              
               </div>
               <div class="row">
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">Billing Party</label> 
                        <select class="form-control select2" name="billing_party" id="billing_party">
                           <option></option>
                           <option value="CONSIGNOR" <?php if($update_row['billing_party'] == 'CONSIGNOR') { ?> selected="selected"<?php } ?>>CONSIGNOR</option>
                           <option value="CONSIGNEE" <?php if($update_row['billing_party'] == 'CONSIGNEE') { ?> selected="selected"<?php } ?>>CONSIGNEE</option>
                           <option value="TRANSPORTER" <?php if($update_row['billing_party'] == 'TRANSPORTER') { ?> selected="selected"<?php } ?>>TRANSPORTER</option>
                           <option value="OTHER" <?php if($update_row['billing_party'] == 'OTHER') { ?> selected="selected"<?php } ?>>OTHER</option>
                           <option value="TO PAY" <?php if($update_row['billing_party'] == 'TO PAY') { ?> selected="selected"<?php } ?>>TO PAY</option>
                        </select>
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">GST PAID BY</label> 
                        <select class="form-control select2" name="gst_paid_by" id="gst_paid_by">
                           <option></option>
                           <option <?php if($update_row['gst_paid_by'] == 'CONSIGNOR') { ?> selected="selected"<?php } ?> value="CONSIGNOR">CONSIGNOR</option>
                           <option <?php if($update_row['gst_paid_by'] == 'CONSIGNEE') { ?> selected="selected"<?php } ?> value="CONSIGNEE">CONSIGNEE</option>
                           <option <?php if($update_row['gst_paid_by'] == 'TRANSPORTER') { ?> selected="selected"<?php } ?> value="TRANSPORTER">TRANSPORTER</option>
                           <option <?php if($update_row['gst_paid_by'] == 'OTHER') { ?> selected="selected"<?php } ?> value="OTHER">OTHER</option>
                           <option <?php if($update_row['gst_paid_by'] == 'NOT APPLICABLE') { ?> selected="selected"<?php } ?> value="NOT APPLICABLE">NOT APPLICABLE</option>
                        </select>
                     </div>
                  </div>
               </div>
               <div class="row">
                  <div class="col-md-4">
                     <legend class="capital hitz-legend">CONSIGNOR</legend>
                     <div class="col-md-12">
                        <div class="form-group">
                           <label class="capital">name</label>
                           <select class="form-control select2" name="consignor_name" id="consignor_name" onchange="get_consignor_data(this);">
                              <option></option>
                              <?php while ($vendor_row = mysqli_fetch_array($vendor_res)) { ?>
                                 <option <?php if($vendor_row['id'] == $update_row['consignor_name']) { echo "selected='selected'"; } ?> value="<?php echo $vendor_row['id'];?>"><?php echo $vendor_row['name'];?></option>
                              <?php } ?>
                           </select>
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <textarea class="form-control hitz-text-height" name="consignor_address" id="consignor_address" readonly="" style="height: 64px !important;"><?php echo $con_row['address'];?></textarea> 
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name="consignor_city" id="consignor_city" class="form-control get_city" placeholder="CITY" readonly="" value="<?php echo $con_row['city'];?>" />  
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name="consignor_contact" id="consignor_contact" class="form-control" placeholder="CONTACT" readonly="" value="<?php echo $con_row['mobile'];?>" />  
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name="consignor_pan" id="consignor_pan" class="form-control" placeholder="PAN" readonly="" value="<?php echo $con_row['pan'];?>"/>  
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name="consignor_gst" id="consignor_gst" class="form-control" placeholder="GST" readonly="" value="<?php echo $con_row['gstin'];?>"/>  
                        </div>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <legend class="capital hitz-legend">CONSIGNEE</legend>
                     <div class="col-md-12">
                        <div class="form-group">
                           <label class="capital">name</label>
                           <select class="form-control select2" name="consignee_name" id="consignee_name" onchange="get_consignee_data(this);">
                              <option></option>
                              <?php while ($vendor_rows = mysqli_fetch_array($vendor_resu)) { ?>
                                 <option <?php if($vendor_rows['id'] == $update_row['consignee_name']) { echo "selected='selected'"; } ?> value="<?php echo $vendor_rows['id'];?>"><?php echo $vendor_rows['name'];?></option>
                              <?php } ?>
                           </select>
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <textarea class="form-control hitz-text-height" name="consignee_address" id="consignee_address" style="height: 64px !important;"><?php echo $consignee_address;?></textarea> 
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name ="consignee_city" id="consignee_city" class="form-control" placeholder="CITY" value="<?php echo $consignee_city;?>" />  
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name ="consignee_contact" id="consignee_contact" class="form-control" placeholder="CONTACT" value="<?php echo $consignee_contact;?>"/>  
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name ="consignee_pan" id="consignee_pan" class="form-control" placeholder="PAN" value="<?php echo $consignee_pan;?>"/>
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name ="consignee_gst" id="consignee_gst" class="form-control" placeholder="GST"  value="<?php echo $consignee_gst;?>"/>  
                        </div>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <legend class="capital hitz-legend">BILLING TO</legend>
                     <div class="col-md-12">
                        <div class="form-group">
                           <label class="capital">name</label>
                           <select class="form-control select2" name="billing_to" id="billing_to" onchange="get_bill_data(this);">
                              <option></option>
                              <?php while ($bill_row = mysqli_fetch_array($bill_res)) { ?>
                                 <option <?php if($bill_row['id'] == $update_row['billing_to']) { echo "selected='selected'"; } ?> value="<?php echo $bill_row['id'];?>"><?php echo $bill_row['name'];?></option>
                              <?php } ?>
                           </select>
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <textarea class="form-control hitz-text-height" name="bill_address" id="bill_address" readonly="" style="height: 64px !important;"><?php echo $bill_rows['address'];?></textarea> 
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name="bill_city" id="bill_city" class="form-control get_city" placeholder="CITY" readonly="" value="<?php echo $bill_rows['city'];?>" />  
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name="bill_contact" id="bill_contact" class="form-control" placeholder="CONTACT" readonly="" value="<?php echo $bill_rows['mobile'];?>" />  
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name="bill_pan" id="bill_pan" class="form-control" placeholder="PAN" readonly="" value="<?php echo $bill_rows['pan'];?>" />  
                        </div>
                     </div>
                     <div class="col-md-12">
                        <div class="form-group">
                           <input type="text" name="bill_gst" id="bill_gst" class="form-control" placeholder="GST" readonly="" value="<?php echo $bill_rows['gstin'];?>" />  
                        </div>
                     </div>
                  </div>
               </div>
               <div class="row">
                  <div class="col-md-4">
                    <div class="form-group">
                     <label class="capital">Agent</label>
                     <select class="form-control" id="agent" name="agent">
                        <option value></option>
                        <?php 
                        foreach ($agent_data as $key => $agent_datas) { ?>
                           <option value="<?php echo $agent_datas['name'] ?>" <?php if($agent_datas['name'] == $update_row['agent']) { echo "selected='selected'"; } ?>><?php echo $agent_datas['name'] ?></option>
                        <?php } ?>
                     </select>
                  </div>
               </div>
               <div class="col-md-4">
                <div class="form-group">
                </div>
             </div>
             <div class="col-md-2">
                <div class="form-group">
                  <label class="capital">TO BE BILLED AT</label> 
                  <input type="text" size="35" id="to_be_billed_at" name="to_be_billed_at" class="form-control" autocomplete="off" value="<?php echo $update_row['to_be_billed_at'];?>" />
               </div>
            </div>
         </div>
         <div class="row">
            <div class="col-md-8">
               <div id="product-wapper" class="table-responsive">
                  <table class="table table-bordered">
                     <thead>
                       <tr>
                         <th class="text-center" width="2%">#</th>
                         <th class="text-center" width="7%">Description</th>
                         <th class="text-center" width="7%">pcs</th>
                         <th class="text-center" width="7%">Actual Weight</th>
                         <th class="text-center" width="7%">Charged weight</th>
                         <th class="text-center" width="7%">HSN CODE</th>
                         <th class="text-center" width="7%">FREIGHT RATE</th>
                      </tr>
                   </thead>
                   <tbody>
                    <?php
                                  // $pkgs_options = ["bag", "book", "bungdle", "c box", "loose", "MT","NOS","PALLET","W BOX"];
                    $lr_grid_query = "SELECT * FROM `lr_grid` WHERE `master_id` = '" . $update_row['id'] . "'";
                    $lr_grid_data = mysqli_query($conn, $lr_grid_query);
                    $i = 0;
                    while ($lr_grid_row = mysqli_fetch_array($lr_grid_data)) {
                    ?>charged_

                    <tr>
                     <td>
                      <a href="javascript:;" class="btn green btn-block add-more" style="display: none;"><i class="fa fa-plus"></i></a>
                      <a href="javascript:;" class="btn red btn-block remove-me" style="display: block;"><i class="fa fa-minus"></i></a>
                   </td>
                   <td>
                    <input type="text" name="product[<?php echo $i; ?>][description]" value="<?php echo $lr_grid_row['description']; ?>" class="add-more-table form-control top product-name description bill_cal" data-count="<?php echo $i; ?>">
                 </td>

                 <td><input type="text" name="product[<?php echo $i; ?>][pcs]" value="<?php echo $lr_grid_row['pcs']; ?>" class="add-more-table form-control top pcs bill_cal"></td>

                 <td><input type="text" name="product[<?php echo $i; ?>][weight]" value="<?php echo $lr_grid_row['weight']; ?>" class="add-more-table form-control top weight bill_cal"></td>

                 <td><input type="text" name="product[<?php echo $i; ?>][charged_weight]" value="<?php echo $lr_grid_row['charged_weight']; ?>" class="add-more-table form-control top charged_weight bill_cal"></td>

                 <td><input type="text" name="product[<?php echo $i; ?>][hsn_code]" value="<?php echo $lr_grid_row['hsn_code']; ?>" class="add-more-table form-control top hsn_code bill_cal"></td>

                 <td><input type="text" name="product[<?php echo $i; ?>][freight_rate]" value="<?php echo $lr_grid_row['freight_rate']; ?>" class="add-more-table form-control top freight_rate  bill_cal"></td>
              </tr>
              <?php
              $i++;
           }
           ?>
           <tr>
            <td>
             <a href="javascript:;" class="btn green btn-block add-more" style="display: block;"><i class="fa fa-plus"></i></a>
             <a href="javascript:;" class="btn red btn-block remove-me" style="display: none;"><i class="fa fa-minus"></i></a>
          </td>
          <td>
           <input type="text" name="product[<?php echo $i; ?>][description]" value="<?php echo $lr_grid_row['description']; ?>" class="add-more-table form-control top product-name description bill_cal" data-count="<?php echo $i; ?>">
        </td>

        <td><input type="text" name="product[<?php echo $i; ?>][pcs]" value="<?php echo $lr_grid_row['pcs']; ?>" class="add-more-table form-control top pcs bill_cal"></td>

        <td><input type="text" name="product[<?php echo $i; ?>][weight]" value="<?php echo $lr_grid_row['weight']; ?>" class="add-more-table form-control top weight bill_cal"></td>

        <td><input type="text" name="product[<?php echo $i; ?>][charged_weight]" value="<?php echo $lr_grid_row['charged_weight']; ?>" class="add-more-table form-control top charged_weight bill_cal"></td>
        <td><input type="text" name="product[<?php echo $i; ?>][hsn_code]" value="<?php echo $lr_grid_row['hsn_code']; ?>" class="add-more-table form-control top hsn_code bill_cal"></td>
        <td><input type="text" name="product[<?php echo $i; ?>][freight_rate]" value="<?php echo $lr_grid_row['freight_rate']; ?>" class="add-more-table form-control top freight_rate bill_cal"></td>
     </tr>
  </tbody>
</table>
</div>
<div class="col-md-5">
   <div class="form-group">
   </div>
</div>
<div class="col-md-2">
   <div class="form-group">
      <label class="col-md-6 capital">A WEIGHT</label> 
      <input type="text" name="total_actual_weight" id="total_actual_weight" class="form-control" value="<?php echo $update_row['total_actual_weight']?>" >
   </div>
</div>
<div class="col-md-2">
   <div class="form-group">
      <label class="col-md-6 capital">C WEIGHT</label> 
      <input type="text" name="total_charged_weight" id="total_charged_weight" class="form-control" value="<?php echo $update_row['total_charged_weight']?>" >
   </div>
</div>
<div class="col-md-4">
   <div class="form-group">
   </div>
</div>
</div>
<div class="col-md-4">
   <div class="col-md-12">
      <div class="form-group">
         <label class="capital">REMARK</label>
         <textarea class="form-control hitz-text-height" id="remark" name="remark" style="height: 64px !important;"><?php echo $update_row['remark'];?></textarea>
      </div>
   </div>
</div>
<div class="col-md-4">
   <div class="col-md-6">
      <div class="form-group">
         <label class="capital">EMPLOYEE</label> 
         <select class="form-control select2 width100" name="emp_id" id="emp_id">
            <option value></option>
            <?php 
            $emp     = "SELECT * FROM `emp_mst` WHERE status = '0'";
            $emp_res = mysqli_query($conn,$emp);
            while ($emp_row = mysqli_fetch_assoc($emp_res)) { ?>
               <option <?php if($emp_row['id'] == $update_row['emp_id']) { echo "selected='selected'"; } ?> value="<?php echo $emp_row['id'];?>"><?php echo $emp_row['code'];?> - <?php echo $emp_row['name'];?> </option>
            <?php } ?>
         </select>
      </div>
   </div>
   <div class="col-md-6">
      <div class="form-group">
         <label class="capital">TRUCK DRIVER NO</label> 
         <input type="text" name="truck_driver_no" id="truck_driver_no" class="form-control" value="<?php echo $update_row['truck_driver_no'];?>">
      </div>
   </div>


   <div class="col-md-6">
      <div class="form-group">
        <label class="capital">FREIGHT </label>
     </div>
  </div>

  <div class="col-md-6" >
   <div class="form-group">
      <input type="text" class="form-control" id="freight" name="freight" value="<?php echo $update_row['freight']?>" placeholder="CHARGE" />
   </div>
</div>
<div class="col-md-6">
   <div class="form-group">
      <label class="capital">ST CHARGE </label>
  </div>
</div>

<div class="col-md-6" >
   <div class="form-group">
      <input type="text" class="form-control" id="st_charges" name="st_charges" value="<?php echo $update_row['st_charges']?>" placeholder="CHARGE" />
   </div>
</div>

</div>
</div>
<input type="hidden" value="LR" name="module" id="module">
<input type="hidden" value="<?php echo $_SESSION['branch_id'];?>" name="branch_id" id="branch_id">
<input type="hidden" value="<?php echo $_GET['eid'];?>" name="id" id="id">
<hr>
<div class="row" align="center">
   <button id="btn" class="btn btn-primary ajax-submit capital" type="submit"> UPDATE & SAVE</button>
   <a href="index.php?page=lr/list.php" class="btn btn-danger capital"> Cancel</a>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</section>
<div id="expense-template" style="display:none;">
   <table>
      <tr>
         <td>
            <a href="javascript:;" class="btn green btn-block add-more-expense" style="display: block;"><i class="fa fa-plus"></i></a>
            <a href="javascript:;" class="btn red btn-block remove-me-expense" style="display: none;"><i class="fa fa-minus"></i></a>
         </td>

         <td>
            <input type="text" name="expense[%i%][account_name]" class="add-more-table form-control account_name top account_name lr_cal" data-count="%i%">

            <input type="hidden" name="expense[%i%][account_id]" class="add-more-table form-control account_id top account_id lr_cal" data-count="%i%">

            <input type="hidden" name="expense[%i%][account_code]" class="add-more-table form-control account_code top lr_cal">
         </td>
         
         <td><input type="text" name="expense[%i%][amount]" class="form-control top add-more-table lr_cal amount" autocomplete="off"></td>
         <td><input type="text" name="expense[%i%][remarks]" class="form-control top add-more-table lr_cal remarks" autocomplete="off"></td>
      </tr>
   </table>
</div>
<script type="text/javascript">
   $(document).ready(function(){
      jQuery('#signupForm').delegate('.lr_type', 'ifChecked', function(event){
         $value = jQuery(this).val();
         if($value == 'D') {
          jQuery('#from_place').removeClass('required');
          jQuery('#to_place').removeClass('required');
          jQuery('#consignor_name').removeClass('required');
          jQuery('#consignee_name').removeClass('required');
          jQuery('#billing_party').removeClass('required');
       }
    });
    $('#rate_on').select2();
    $('#lr_mode').select2();
    // $('#delivery').select2();
    $('#emp_id').select2();
    $('#gst_paid_by').select2();
    $('#billing_party').select2();
    $('#location_id').select2();
    $('#billing_branch').select2();
    $('#billing_to').select2();
    $( "#from_place" ).autocomplete({
       source: function( request, response ) {
          $.ajax({
             url: "lr/get_from_place.php",
             type: 'post',
             dataType: "json",
             data: {
               search: request.term
             },
             success: function( data ) {
             response( data ); 
             }
          });
       },
       select: function (event, ui) {
          $('#from_place').val(ui.item.label);
          return false;
       }
   });

   $( "#method_pack" ).autocomplete({
      source: function( request, response ) {
      $.ajax({
         url: "lr/get_method_pack.php",
         type: 'post',
         dataType: "json",
         data: {
            search: request.term
         },
         success: function( data ) {
            response( data );
         }
      });
      },
      select: function (event, ui) {
         $('#method_pack').val(ui.item.label);
       return false;
       }
    });



    jQuery(document).ready(function($) {
    var $length = 0;

    // Add a new row
    $(document).on('click', '.add-more', function(e) {
        $length = $('#product-wapper').find('table tbody tr').length;
        var $clone = $('#product-wapper table tbody tr:first').clone();

        $clone.find('input').each(function() {
            this.name = this.name.replace('[0]', '[' + $length + ']');
            this.value = ''; // Clear input values if needed
        });

        $clone.find('.product-name').attr('data-count', $length);
        $('#product-wapper table tbody').append($clone);
        $('#product-wapper table tbody').find('.remove-me').show();
        $('#product-wapper table tbody').find('.add-more').hide();
        $('#product-wapper table tbody').find('.remove-me:last').hide();
        $('#product-wapper table tbody').find('.add-more:last').show();

        calculateTotalWeight(); // Recalculate total weight
        calculateCTotalWeight(); // Recalculate total weight
    });

   jQuery(document).on('click', '.add-more-expense', function(e) {
         $length = jQuery('#expense-wapper').find('table tbody tr').length;
         var $clone = jQuery('#expense-template table tr').clone();
         $clone.find('input').each(function() {
            this.name = this.name.replace('[%i%]', '[' + $length + ']');
         });
         $clone.find('.account_name').attr('data-count', $length);
         $clone.find('.account_id').attr('data-count', $length);
         jQuery('#expense-wapper table tbody').append($clone);
         jQuery('#expense-wapper table tbody').find('.remove-me-expense').show();
         jQuery('#expense-wapper table tbody').find('.add-more-expense').hide();
         jQuery('#expense-wapper table tbody').find('.remove-me-expense:last').hide();
         jQuery('#expense-wapper table tbody').find('.add-more-expense:last').show();
      });


    // Remove a row
    $(document).on('click', '.remove-me', function(e) {
        e.preventDefault();
        $(this).closest('tr').remove();
        calculateTotalWeight(); // Recalculate total weight
        calculateCTotalWeight(); // Recalculate total weight
    });

      jQuery(document).on('click', '.remove-me-expense', function(e) {
         e.preventDefault();
         jQuery(this).closest('tr').remove();
      });


    // Calculate total actual weight on input change
    $(document).on('input', '.weight', function() {
        calculateTotalWeight();
    });
     $(document).on('input', '.charged_weight', function() {
        calculateCTotalWeight();
    });
     

    // Function to calculate total weight
    function calculateTotalWeight() {
        var totalWeight = 0;
        $('.weight').each(function() {
            var weight = parseFloat($(this).val()) || 0; // Parse value or default to 0
            totalWeight += weight;
        });
        $('#total_actual_weight').val(totalWeight.toFixed(2)); // Display total with 2 decimal places
    }

     function calculateCTotalWeight() {
        var totalCWeight = 0;
        $('.charged_weight').each(function() {
            var chargedweight = parseFloat($(this).val()) || 0; // Parse value or default to 0
            totalCWeight += chargedweight;
        });
        $('#total_charged_weight').val(totalCWeight.toFixed(2)); // Display total with 2 decimal places
    }
});



   //TRUCK NO
   $( "#truck_no" ).autocomplete({
      source: function( request, response ) {
         $.ajax({
            url: "lr/get_truck_data.php",
            type: 'post',
            dataType: "json",
            data: {
            search: request.term
            },
            success: function( data ) {
               response( data );
            }
        });
      },
      select: function (event, ui) {
         if(ui.item.value != 0) {
            $('#truck_no').val(ui.item.label);
            get_Truck_weight();
            return false;
         }
      }
   });



   $( "#to_place" ).autocomplete({
      source: function( request, response ) {
         $.ajax({
            url: "lr/get_to_place.php",
            type: 'post',
            dataType: "json",
            data: {
              search: request.term
            },
            success: function( data ) {
              response( data );
            }
         });
      },
      select: function (event, ui) {
         $('#to_place').val(ui.item.label);
         return false;
      }
   });

   $( "#agent" ).autocomplete({
      source: function( request, response ) {
         $.ajax({
            url: "lr/get_agent.php",
            type: 'post',
            dataType: "json",
            data: {
              search: request.term
            },
            success: function( data ) {
              response( data );
            }
         });
      },
      select: function (event, ui) {
         $('#agent').val(ui.item.label);
            return false;
         }
    });

    $( "#packing" ).autocomplete({
       source: function( request, response ) {
          $.ajax({
             url: "lr/get_packing.php",
             type: 'post',
             dataType: "json",
             data: {
                search: request.term
             },
             success: function( data ) {
                response( data );
             }
          });
       },
       select: function (event, ui) {
          $('#packing').val(ui.item.label);
          return false;
       }
    });

    $( "#address_delivery" ).autocomplete({
       source: function( request, response ) {
          $.ajax({
             url: "lr/get_address_delivery.php",
             type: 'post',
             dataType: "json",
             data: {
                search: request.term
             },
             success: function( data ) {
                response( data );
             }
          });
       },
       select: function (event, ui) {
          $('#address_delivery').val(ui.item.label);
          return false;
       }
    });

    $( "#lorry_type" ).autocomplete({
      source: function( request, response ) {
         $.ajax({
           url: "lr/get_lorry_type.php",
           type: 'post',
           dataType: "json",
           data: {
              search: request.term
           },
           success: function( data ) {
              response( data );
           }
        });
      },
      select: function (event, ui) {
         $('#lorry_type').val(ui.item.label);
         return false;
      }
    });

    $( "#nature_of_goods" ).autocomplete({
       source: function( request, response ) {
          $.ajax({
             url: "lr/get_nature_of_goods.php",
             type: 'post',
             dataType: "json",
             data: {
               search: request.term
             },
             success: function( data ) {
             response( data );
             }
          });
       },
       select: function (event, ui) {
          $('#nature_of_goods').val(ui.item.label);
          return false;
       }
    });

   /* $('#rate_on').on('change', function() {
       calculateFinalAmount(this);
    });

    $('#billing_party').on('change', function() {
       if ($(this).val()  == 'CONSIGNOR') {
          var $consi = parseFloat(jQuery('#consignor_name').val());
          if($consi == $consi){
             var $consis = parseFloat(jQuery('#billing_to').val($consi).change());
          }
          }else if($(this).val()  == 'CONSIGNEE'){
          var $consignee = parseFloat(jQuery('#consignee_name').val());
          if($consignee == $consignee){
             var $consignee = parseFloat(jQuery('#billing_to').val($consignee).change());
          }
       }else{
          var $consignee = parseFloat(jQuery('#billing_to').change());
       }
    });*/
    
    $("#consignor_name").autocomplete({
       source: function( request, response ) {
          $.ajax({
             url: "lr/get_consignor_search_data.php",
             type: 'post',
             dataType: "json",
             data: {
                search: request.term
             },
             success: function( data ){
                response( data );
                $('#consignor_address').prop('readonly',false);
                $('#consignor_city').prop('readonly',false);
                $('#consignor_contact').prop('readonly',false);
                $('#consignor_pan').prop('readonly',false);
                $('#consignor_gst').prop('readonly',false);
             }
          });
       },
       select: function (event, ui) {
          if(ui.item.value != 0) {
               $('#consignor_name').val(ui.item.label);
               $('#consignor_address').prop('readonly',true);
               $('#consignor_city').prop('readonly',true);
               $('#consignor_contact').prop('readonly',true);
               $('#consignor_pan').prop('readonly',true);
               $('#consignor_gst').prop('readonly',true);
          return false;
          }
       }
    });

    $("#consignee_name").autocomplete({
       source: function( request, response ) {
          $.ajax({
             url: "lr/get_consignor_search_data.php",
             type: 'post',
             dataType: "json",
             data: {
               search: request.term
             },
             success: function( data ) {
                response( data );
                $('#consignee_name').prop('readonly',false);
                $('#consignee_address').prop('',false);
                $('#consignee_city').prop('',false);
                $('#consignee_contact').prop('',false);
                $('#consignee_pan').prop('',false);
                $('#consignee_gst').prop('',false);
             }
          });
       },
       select: function (event, ui) {
          if(ui.item.value != 0) {
               $('#consignee_name').val(ui.item.label);
               $('#consignee_address').prop('',true);
               $('#consignee_city').prop('',true);
               $('#consignee_contact').prop('',true);
               $('#consignee_pan').prop('',true);
               $('#consignee_gst').prop('',true);
             return false;
          }
       }
    });
    });

function get_consignor_name_data2(input) {
  var consignorName = input.value;
  $.ajax({
     type: "POST",
     url: "lr/get_consignor_details.php", // Replace with your PHP script URL
     data: { consignor_name: consignorName },
     success: function(response) {
        // Parse the response and update other form fields
        var data = JSON.parse(response);
        $('#consignor_address').val(data.address);
        $('#consignor_city').val(data.city);
        $('#consignor_contact').val(data.contact);
        $('#consignor_pan').val(data.pan);
        $('#consignor_gst').val(data.gst);
     },
        error: function(xhr, status, error) {
        // Handle errors
     }
  });
}

function get_consignee_name_data2(input) {
  var consigneeName = input.value;
  $.ajax({
     type: "POST",
     url: "lr/get_consignee_details.php", // Replace with your PHP script URL
     data: { consignee_name: consigneeName },
     success: function(response) {
        // Parse the response and update other form fields
        var data = JSON.parse(response);
        $('#consignee_address').val(data.address);
        $('#consignee_city').val(data.city);
        $('#consignee_contact').val(data.contact);
        $('#consignee_pan').val(data.pan);
        $('#consignee_gst').val(data.gst);
     },
        error: function(xhr, status, error) {
        // Handle errors
     }
  });
}


// Attach event listener to gst_per for dynamic GST and net_amount calculation




function calculateFinalAmount(ele) {
   var lr_no = $(ele).val();
   var $weight = parseFloat(jQuery('#weight').val());
   if ($weight == '' || $weight == undefined || isNaN($weight)) {
      $weight = 0;
   }
   $rate       = parseFloat(jQuery('#rate').val());
   if ($rate == '' || $rate == undefined || isNaN($rate)) {
      $rate = 0;
   }
   $pcs  = parseFloat(jQuery('#pcs').val());
   if ($pcs == '' || $pcs == undefined || isNaN($pcs)) {
     $pcs = 0;
   }

   var $freight = parseFloat(jQuery('#freight').val());
   if ($freight == '' || $freight == undefined || isNaN($freight)) {
      $freight = 0;
   }

   var $advance = parseInt(jQuery('#advance').val());
   if ($advance == '' || $advance == undefined || isNaN($advance)) {
     $advance = 0;
   }

   var $extra_height_amnt = parseInt(jQuery('#extra_height_amnt').val());
   if ($extra_height_amnt == '' || $extra_height_amnt == undefined || isNaN($extra_height_amnt)) {
      $extra_height_amnt = 0;
   }
   if(lr_no == 'WEIGHT'){
      if($weight !=''){
         $amnt  = $weight * $rate;
      }
      if($weight !='' && $pcs !=''){
         $amnt  = $weight * $rate;
      }
   }else if(lr_no == 'PCS'){
      if($pcs !=''){
         $amnt  = $pcs * $rate;
      }
      if($weight !='' && $pcs !=''){
         $amnt  = $pcs * $rate;
      }
   }else{}

   if(lr_no != 'WEIGHT' && lr_no != 'PCS'){
      $net   = $freight - $advance;
      jQuery('#total_amnt').val($net.toFixed(2));  
   }else{
   $net   = $amnt - $advance;
   jQuery('#freight').val($amnt.toFixed(2));
   jQuery('#total_amnt').val($net.toFixed(2));  
   }

   if($extra_height_amnt !=''){
      $final_am = $freight + $extra_height_amnt - $advance;  
      jQuery('#total_amnt').val($final_am.toFixed(2));
   }
   document.getElementById('advance').setAttribute('max', $freight);
}

function get_Truck_weight(ele) {
   var truck_no = $("#truck_no").val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/get_truck.php',
      'data': 'truck_no=' + truck_no,
      dataType: 'JSON',
      success: function (result) {
         if (result != '') {
            jQuery('#lorry_type').val(result.lorry_type);
         }
      }
   });
}

function get_consignor_data(ele) {
   var consignor_name = $(ele).val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/get_consignor_data.php',
      'data': 'consignor_name=' + consignor_name,
      dataType: 'JSON',
      success: function (result) {
         if (result != '') {
            $('#consignor_address').val(result.address);
            $('#consignor_city').val(result.city);
            $('#consignor_contact').val(result.mobile);
            $('#consignor_pan').val(result.pan);
            $('#consignor_gst').val(result.gstin);
         }
      }
   });
}

function get_bill_data(ele) {
    var billing_to = $(ele).val();
    $.ajax({
        type: 'POST',
        url: 'lr/get_bill_data.php',
        data: 'billing_to=' + billing_to,
        dataType: 'JSON',
        success: function (result) {
            if (result) {
                $('#bill_address').val(result.address);
                $('#bill_city').val(result.city);
                $('#bill_contact').val(result.mobile);
                $('#bill_pan').val(result.pan);
                $('#bill_gst').val(result.gstin);
                $('#rate').val(result.rate); // Populate the rate field

                updateGSTPercentages();
            } else {
                // Clear fields if no result
                $('#bill_address, #bill_city, #bill_contact, #bill_pan, #bill_gst, #rate').val('');
            }
        }
    });
}

function updateGSTPercentages() {
    const billGst = $('#bill_gst').val();
    const gstSlab = parseFloat($('#gst_slab').val());

    if (billGst.startsWith('24') || billGst === '' || billGst === null) {
        // If bill_gst starts with '24' or is null/blank, divide gst_slab by 2 for CGST and SGST
        const gstPercentage = gstSlab / 2;
        $('#cgst_per').val(gstPercentage);
        $('#sgst_per').val(gstPercentage);
        $('#igst_per').val(0); // Reset IGST
    } else {
        // If bill_gst does not start with '24', set gst_slab to IGST
        $('#igst_per').val(gstSlab);
        $('#cgst_per').val(0); // Reset CGST
        $('#sgst_per').val(0); // Reset SGST
    }

    // Recalculate GST and Net Amount
    calculateGST();
}

function get_consignee_data(ele) {
   var consignee_name = $(ele).val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/get_consignee_data.php',
      'data': 'consignee_name=' + consignee_name,
      dataType: 'JSON',
      success: function (result) {
         if (result != '') {
            $('#consignee_address').val(result.address);
            $('#consignee_city').val(result.city);
            $('#consignee_contact').val(result.mobile);
            $('#consignee_pan').val(result.pan);
            $('#consignee_gst').val(result.gstin);
         }
      }
   });
}

function get_consignor_name_data(ele) {
   var consignor_name = $(ele).val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/get_consignor_name_data.php',
      'data': 'consignor_name=' + consignor_name,
      dataType: 'JSON',
      success: function (result) {
         if (result != '') {
            $('#consignor_address').val(result.address);
            $('#consignor_city').val(result.city);
            $('#consignor_contact').val(result.mobile);
            $('#consignor_pan').val(result.pan);
            $('#consignor_gst').val(result.gstin);
         }
      }
   });
} 

function get_consignee_name_data(ele) {
   var consignor_name = $(ele).val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/get_consignee_name_data.php',
      'data': 'consignee_name=' + consignee_name,
      dataType: 'JSON',
      success: function (result) {
         if (result != '') {
            $('#consignee_address').val(result.address);
            $('#consignee_city').val(result.city);
            $('#consignee_contact').val(result.mobile);
            $('#consignee_pan').val(result.pan);
            $('#consignee_gst').val(result.gstin);
         }
      }
   });
}

function CheckLr() {
   var lr_no      = $("#lr_no").val();
   var branch_id  = $("#branch_id").val();
   var module     = $("#module").val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/check-lr-no.php',
      'data': {
         'lr_no': lr_no,
         'branch_id': branch_id,
         'module': module
      },
      dataType: 'JSON',
      success: function (result) {
         if(result.status == 1) {
            jQuery('.submit').attr('disabled', false);
         }else{
            jQuery('.submit').attr('disabled', true);
            swal("Opps !!", "Not A Valid LR Number", "info")  
         }
      }
   });
}

function CheckCode() {
   var lr_no      = $("#lr_no").val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/check-code.php',
      'data': {
         'lr_no': lr_no
      },
      dataType: 'JSON',
      success: function (result) {
         if(result.status == 1) {
            swal("Opps !!", "ALREADY CODE EXIST...!!!", "info");
            setTimeout("location.reload(true);",2000);
            $('#lr_no').val('').trigger('focus');   
         }else{
            jQuery('.ajax-submit').attr('enable', true);
         }
      }
   });
}

function CheckNumberSeries() {
   var lr_no      = $("#lr_no").val();
   var branch_id  = $("#branch_id").val();
   var module     = $("#module").val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/check_number_series.php',
      'data': {
         'lr_no': lr_no,
         'branch_id': branch_id,
         'module': module
      },
      dataType: 'JSON',
      success: function (result) {
         if(result.status == 1) {
            jQuery('.ajax-submit').attr('disabled', false);
         }else{
            jQuery('.ajax-submit').attr('disabled', true);
            swal("Opps !!", "Not A Valid LR Number", "info");
            setTimeout("location.reload(true);",2000);  
         }
      }
   });
}

function CheckTruck() {
   var truck_no = $("#truck_no").val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/check-truck-no.php',
      'data': {
         'truck_no': truck_no
      },
      dataType: 'JSON',
      success: function (result) {
         if(result.status != 1) {
            var $truck      = $("#truck_no").val('').trigger('focus');
            var url = "index.php?page=truck_mst/add.php" + '&type=' + 'truck' + '&no=' + jQuery('#truck_no').val();
            window.open(url);
         }else{
            get_Truck_weight();
         }
     }
   });
}

function CheckUplode() {
   var truck_no      = $("#truck_no").val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/check_truck_doc.php',
      'data': {
         'truck_no': truck_no
      },
      dataType: 'JSON',
      success: function (result) {
         if(result.status == 1) {
            $.toast({
               heading: 'OPPS....',
               text: 'RC AND IMAGE NOT UPLODED',
               icon: 'warning',
               position: 'top-right'
            });  
         }else{
            jQuery('.submit').attr('enable', true);
         }
      }
   });
}

function CheckDate() {
   var l_date      = $("#l_date").val();
   $.ajax({
      'type': 'POST',
      'url': 'lr/check-date.php',
      'data': {
         'l_date': l_date
      },
      dataType: 'JSON',
      success: function (result) {
         if(result.status == 0) {
            swal("Opps !!", "Date should be between Financial Year...!!!", "info");
            setTimeout("location.reload(true);",2000);
            $('#l_date').val('').trigger('focus');   
         }else{
            jQuery('.ajax-submit').attr('enable', true);
         }
      }
   });
}

function CopyData(ele) {
   var $billing_party = ele;
   jQuery('#gst_paid_by').val($billing_party).trigger('change');
}
</script>