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

$truck = mysqli_query($conn, "SELECT * FROM `truck_mst` WHERE `own` ='O' ORDER BY truck_no ");
$truck_data = array();
while ($truck_row = mysqli_fetch_assoc($truck)) {
 $truck_data[] = $truck_row;
}

$contract = mysqli_query($conn, "SELECT * FROM `contract` ORDER BY code");
$contract_data = array();
while ($contract_row = mysqli_fetch_assoc($contract)) {
 $contract_data[] = $contract_row;
}

$trip =  mysqli_query($conn, "SELECT * FROM `trip` WHERE truck_no = '".$truck_data['truck_no']."' ");
$trip_row = mysqli_fetch_assoc($trip);

  // $start_km = isset($truck_data[0]['tr_kilometer']) ? $truck_data[0]['tr_kilometer'] : '';

$driver = mysqli_query($conn, "SELECT * FROM `driver_mst` WHERE status = '0' ORDER BY name ASC");
$driver_data = array();
while ($driver_row = mysqli_fetch_assoc($driver)) {
 $driver_data[] = $driver_row;
}

if (isset($_REQUEST['p1']) && !empty($_REQUEST['p1'])){

   $select = mysqli_query($conn, "SELECT * FROM `trip` WHERE `id` = '".$_REQUEST['p1']."'");
   $rows   = mysqli_fetch_assoc($select);
   $id             = $rows['id'];
   $code           = $rows['trip_no'];
   $date           = $rows['date'];
   $recharge_date  = $rows['recharge_date'];
   $fast_tag_opening   = $rows['fast_tag_opening'];
   $fast_tag_recharge  = $rows['fast_tag_recharge'];
   $fast_tag_used      = $rows['fast_tag_used'];
   $fast_tag_closing   = $rows['fast_tag_closing'];
   $truck_no       = $rows['truck_no'];
   $owner_name     = $rows['owner_name'];
   $owner_pan      = $rows['owner_pan'];
   $driver_id      = $rows['driver_id'];
   $driver_lic_no  = $rows['driver_lic_no'];
   $driver_address = $rows['driver_address'];
   $start_km       = $rows['start_km'];
   $end_km         = $rows['end_km'];
   $total_km       = $rows['total_km'];
   $total_freight  = $rows['total_freight'];
   $advance_amount = $rows['advance_amount'];
   $rate_per_km    = $rows['rate_per_km'];
   $total_amount   = $rows['total_amount'];
   $expense_1      = $rows['expense_1'];
   $expense_2      = $rows['expense_2'];
   $expense_3      = $rows['expense_3'];
   $expense_4      = $rows['expense_4'];
   $expense_5      = $rows['expense_5'];
   $expense_6      = $rows['expense_6'];
   $remark_1       = $rows['remark_1'];
   $remark_2       = $rows['remark_2'];
   $remark_3       = $rows['remark_3'];
   $remark_4       = $rows['remark_4'];
   $remark_5       = $rows['remark_5'];
   $remark_6       = $rows['remark_6'];

   $from_place_1     = $rows['from_place_1'];
   $to_place_1       = $rows['to_place_1'];
   $date_1           = $rows['date_1'];
   $total_freight_1  = $rows['total_freight_1'];
   $advance_1        = $rows['advance_1'];

   $from_place_2     = $rows['from_place_2'];
   $to_place_2       = $rows['to_place_2'];
   $date_2           = $rows['date_2'];
   $total_freight_2  = $rows['total_freight_2'];
   $advance_2        = $rows['advance_2'];

   $from_place_3     = $rows['from_place_3'];
   $to_place_3       = $rows['to_place_3'];
   $date_3           = $rows['date_3'];
   $total_freight_3  = $rows['total_freight_3'];
   $advance_3        = $rows['advance_3'];

   $from_place_4     = $rows['from_place_4'];
   $to_place_4       = $rows['to_place_4'];
   $date_4           = $rows['date_4'];
   $total_freight_4  = $rows['total_freight_4'];
   $advance_4        = $rows['advance_4'];

   $from_place_5     = $rows['from_place_5'];
   $to_place_5       = $rows['to_place_5'];
   $date_5           = $rows['date_5'];
   $total_freight_5  = $rows['total_freight_5'];
   $advance_5        = $rows['advance_5'];

   $from_place_6     = $rows['from_place_6'];
   $to_place_6       = $rows['to_place_6'];
   $date_6           = $rows['date_6'];
   $total_freight_6  = $rows['total_freight_6'];
   $advance_6        = $rows['advance_6'];
   $single_start_km        = $rows['single_start_km'];
   $single_start_km2        = $rows['single_start_km2'];
   $single_start_km3        = $rows['single_start_km3'];
   $single_start_km4        = $rows['single_start_km4'];
   $single_start_km5        = $rows['single_start_km5'];
   $single_start_km6        = $rows['single_start_km6'];
   $single_end_km        = $rows['single_end_km'];
   $single_end_km2        = $rows['single_end_km2'];
   $single_end_km3        = $rows['single_end_km3'];
   $single_end_km4        = $rows['single_end_km4'];
   $single_end_km5        = $rows['single_end_km5'];
   $single_end_km6        = $rows['single_end_km6'];
   $single_total_km        = $rows['single_total_km'];
   $single_total_km2        = $rows['single_total_km2'];
   $single_total_km3        = $rows['single_total_km3'];
   $single_total_km4        = $rows['single_total_km4'];
   $single_total_km5        = $rows['single_total_km5'];
   $single_total_km6        = $rows['single_total_km6'];


    $from_place_7     = $rows['from_place_7'];
   $to_place_7       = $rows['to_place_7'];
   $date_7           = $rows['date_7'];
   $total_freight_7  = $rows['total_freight_7'];
   $advance_7        = $rows['advance_7'];

   $from_place_8     = $rows['from_place_8'];
   $to_place_8       = $rows['to_place_8'];
   $date_8           = $rows['date_8'];
   $total_freight_8  = $rows['total_freight_8'];
   $advance_8        = $rows['advance_8'];

   $from_place_9     = $rows['from_place_9'];
   $to_place_9       = $rows['to_place_9'];
   $date_9           = $rows['date_9'];
   $total_freight_9  = $rows['total_freight_9'];
   $advance_9        = $rows['advance_9'];

   $from_place_10     = $rows['from_place_10'];
   $to_place_10       = $rows['to_place_10'];
   $date_10           = $rows['date_10'];
   $total_freight_10  = $rows['total_freight_10'];
   $advance_10        = $rows['advance_10'];

   $from_place_11     = $rows['from_place_11'];
   $to_place_11       = $rows['to_place_11'];
   $date_11           = $rows['date_11'];
   $total_freight_11  = $rows['total_freight_11'];
   $advance_11        = $rows['advance_11'];

   $from_place_12     = $rows['from_place_12'];
   $to_place_12       = $rows['to_place_12'];
   $date_12           = $rows['date_12'];
   $total_freight_12  = $rows['total_freight_12'];
   $advance_12        = $rows['advance_12'];
   $single_start_km7        = $rows['single_start_km7'];
   $single_start_km8        = $rows['single_start_km8'];
   $single_start_km9        = $rows['single_start_km9'];
   $single_start_km10        = $rows['single_start_km10'];
   $single_start_km11        = $rows['single_start_km11'];
   $single_start_km12        = $rows['single_start_km12'];
   $single_end_km7        = $rows['single_end_km7'];
   $single_end_km8        = $rows['single_end_km8'];
   $single_end_km9        = $rows['single_end_km9'];
   $single_end_km10        = $rows['single_end_km10'];
   $single_end_km11        = $rows['single_end_km11'];
   $single_end_km12        = $rows['single_end_km12'];
   $single_total_km7         = $rows['single_total_km7'];
   $single_total_km8        = $rows['single_total_km8'];
   $single_total_km9        = $rows['single_total_km9'];
   $single_total_km10        = $rows['single_total_km10'];
   $single_total_km11        = $rows['single_total_km11'];
   $single_total_km12        = $rows['single_total_km12'];
   $extra_paid_to_driver        = $rows['extra_paid_to_driver'];
   $driver_remark        = $rows['driver_remark'];

   $c_no_1            = $rows['c_no_1'];
   $rate_1            = $rows['rate_1'];
   $amount_1          = $rows['amount_1'];

   $c_no_2             = $rows['c_no_2'];
   $rate_2             = $rows['rate_2'];
   $amount_2           = $rows['amount_2'];

   $c_no_3             = $rows['c_no_3'];
   $rate_3             = $rows['rate_3'];
   $amount_3           = $rows['amount_3'];

   $c_no_4             = $rows['c_no_4'];
   $rate_4             = $rows['rate_4'];
   $amount_4           = $rows['amount_4'];

   $c_no_5             = $rows['c_no_5'];
   $rate_5             = $rows['rate_5'];
   $amount_5           = $rows['amount_5'];

   $c_no_6             = $rows['c_no_6'];
   $rate_6             = $rows['rate_6'];
   $amount_6           = $rows['amount_6'];

   $c_no_7             = $rows['c_no_7'];
   $rate_7             = $rows['rate_7'];
   $amount_7           = $rows['amount_7'];

   $c_no_8             = $rows['c_no_8'];
   $rate_8             = $rows['rate_8'];
   $amount_8           = $rows['amount_8'];

   $c_no_9             = $rows['c_no_9'];
   $rate_9             = $rows['rate_9'];
   $amount_9           = $rows['amount_9'];

   $c_no_10             = $rows['c_no_10'];
   $rate_10             = $rows['rate_10'];
   $amount_10           = $rows['amount_10'];

   $c_no_11             = $rows['c_no_11'];
   $rate_11             = $rows['rate_11'];
   $amount_11           = $rows['amount_11'];

   $c_no_12             = $rows['c_no_12'];
   $rate_12             = $rows['rate_12'];
   $amount_12           = $rows['amount_12'];



   

   $query = mysqli_query($conn, "SELECT * FROM `trip_detail` WHERE `master_id` = '".$_REQUEST['p1']."' ORDER BY id ASC");
   $detail = array();
   while ($row = mysqli_fetch_assoc($query)) {
      $detail[] = $row;
   }
}else{
 $code = tripCode($conn);
 $id   = '';
}

?>
<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"><?php echo ($id == 0) ? 'ADD NEW TRIP' : 'EDIT TRIP'; ?></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'], 'trip_list') ) { ?>
          <a href="index.php?page=trip/list.php" class="btn btn-danger capital bottom10 custome-btn">VIEW TRIP 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="trip/insert.php" method="post" enctype="multipart/form-data" class="common-frm-validation" id="signupForm">
                  <div class="row">
                     <div class="col-md-12">
                        <div class="col-md-2">
                           <div class="form-group">
                              <label class="capital">TRIP NO</label><span class="error">*</span>
                              <input type="text" size="35" id="trip_no" name="trip_no" class="form-control" autocomplete="off" placeholder="VOUCHER NO" value="<?php echo $code;?>" readonly="" autofocus=""/>
                           </div>
                        </div>
                        <div class="col-md-2">
                           <div class="form-group">
                              <label class="capital">DATE</label><span class="error">*</span>
                              <div class="input-group">
                                 <input type="text" name="date" id="date" class="form-control date-picker required" autocomplete="off" value="<?php echo risFormatDate($date);?>"/>
                                 <div class="input-group-addon">
                                    <i class="fa fa-calendar date-icon-color"></i>
                                 </div>
                              </div>
                           </div>
                        </div>
                        <div class="col-sm-4">
                         <div class="form-group">
                           <label class="capital">VEHICLE NO</label><span class="error">*</span>
                           <select class="form-control select2 required truck_no" name="truck_no" id="truck_no">
                              <option></option>
                              <?php foreach ($truck_data as $key => $truck_datas) {
                               echo '<option value="'. $truck_datas['truck_no'] .'" '. ($truck_datas['truck_no'] == $truck_no ? 'selected' : '') .'>' . $truck_datas['truck_no'] . '</option>';
                            } ?>
                         </select>
                      </div>
                   </div>
                   <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">OWNER NAME</label><span class="error">*</span>
                        <input type="text" name="owner_name" id="owner_name" class="form-control" placeholder="OWNER NAME" value="<?php echo $owner_name ?>" readonly="readonly">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">OWNER PAN</label><span class="error">*</span>
                        <input type="text" name="owner_pan" id="owner_pan" class="form-control" placeholder="OWNER NAME" value="<?php echo $owner_pan ?>" readonly="readonly">
                     </div>
                  </div>
               </div>
            </div>
            <div class="row">
               <div class="col-md-12">
                  <div class="col-sm-4">
                     <div class="form-group">
                        <label class="capital">DRIVER</label><span class="error">*</span>
                        <select class="form-control select2 required" name="driver_id" id="driver_id">
                           <option></option>
                           <?php foreach ($driver_data as $key => $driver_datas) {
                              echo '<option value="'. $driver_datas['id'] .'" '. ($driver_datas['id'] == $driver_id ? 'selected' : '') .'>' . $driver_datas['name'] . '</option>';
                           } ?>
                        </select>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <div class="form-group">
                        <label class="capital">DRIVER ADDRESS</label><span class="error">*</span>
                        <textarea class="form-control" name="driver_address" id="driver_address" style="height: 49px !important" readonly="readonly"><?php echo $driver_address?></textarea>
                     </div>
                  </div>
                  <div class="col-md-4">
                     <div class="form-group">
                        <label class="capital">LIC NO</label><span class="error">*</span>
                        <input type="text" name="driver_lic_no" id="driver_lic_no" class="form-control" placeholder="LIC NO" value="<?php echo $driver_lic_no ?>" readonly="readonly">
                     </div>
                  </div>
               </div>
            </div>
            <div class="row">
               <div class="col-md-12">
                           
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">C.NO</label><span class="error">*</span>
                              <input type="text" name="c_no_1" id="c_no_1" class="form-control" value="<?php echo $c_no_1; ?>" onblur="fetchContractDetails('c_no_1')">
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">FROM PLACE</label><span class="error">*</span>
                              <input type="text" name="from_place_1" id="from_place_1" class="form-control" value="<?php echo $from_place_1; ?>">
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">TO PLACE</label><span class="error">*</span>
                              <input type="text" name="to_place_1" id="to_place_1" class="form-control" value="<?php echo $to_place_1; ?>">
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">start km</label><span class="error">*</span>
                              <input type="text" name="single_start_km" id="single_start_km" class="form-control"  value="<?php echo $single_start_km ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">END KM</label><span class="error">*</span>
                              <input type="text" name="single_end_km" id="single_end_km" class="form-control"  value="<?php echo $single_end_km; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">total km</label><span class="error">*</span>
                              <input type="text" name="single_total_km" id="single_total_km" class="form-control"  value="<?php echo $single_total_km; ?>" >
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">RATE</label><span class="error">*</span>
                              <input type="text" name="rate_1" id="rate_1" class="form-control" value="<?php echo $rate_1; ?>">
                           </div>
                        </div>
                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">AMOUNT</label><span class="error">*</span>
                              <input type="text" name="amount_1" id="amount_1" class="form-control" value="<?php echo $amount_1; ?>" >
                           </div>
                        </div>
                        <div class="col-md-2">
                           <div class="form-group">
                              <label class="capital">DATE</label><span class="error">*</span>
                              <div class="input-group">
                                 <input type="text" name="date_1" id="date_1" class="form-control date-picker required" autocomplete="off" value="<?php echo risFormatDate($date_1);?>"/>
                                 <div class="input-group-addon">
                                    <i class="fa fa-calendar date-icon-color"></i>
                                 </div>
                              </div>
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">TOTAL FREIGHT</label>
                              <input type="text" name="total_freight_1" id="total_freight_1" class="form-control"  value="<?php echo $total_freight_1; ?>">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital">ADVANCE</label>
                              <input type="text" name="advance_1" id="advance_1" class="form-control"  value="<?php echo $advance_1; ?>">
                           </div>
                        </div>


               </div>
            </div>


            <div class="row">
               <div class="col-md-12">

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_2" id="c_no_2" class="form-control" value="<?php echo $c_no_2; ?>" onblur="fetchContractDetails('c_no_2')" >
                     </div>
                  </div>
                  
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_2" id="from_place_2" class="form-control" value="<?php echo $from_place_2; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_2" id="to_place_2" class="form-control"  value="<?php echo $to_place_2 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km2" id="single_start_km2" class="form-control"  value="<?php echo $single_start_km2 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km2" id="single_end_km2" class="form-control"  value="<?php echo $single_end_km2; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km2" id="single_total_km2" class="form-control"  value="<?php echo $single_total_km2; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_2" id="rate_2" class="form-control"  value="<?php echo $rate_2; ?>">
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_2" id="amount_2" class="form-control" value="<?php echo $amount_2; ?>" >
                           </div>
                        </div>

                  <div class="col-md-2">  
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_2" id="date_2" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_2);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_2" id="total_freight_2" class="form-control"  value="<?php echo $total_freight_2; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_2" id="advance_2" class="form-control"  value="<?php echo $advance_2; ?>">
                     </div>
                  </div>

               </div>
            </div>


            <div class="row">
               <div class="col-md-12">

                   <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_3" id="c_no_3" class="form-control" value="<?php echo $c_no_3; ?>" onblur="fetchContractDetails('c_no_3')" >
                     </div>
                  </div>

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_3" id="from_place_3" class="form-control" value="<?php echo $from_place_3; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_3" id="to_place_3" class="form-control"  value="<?php echo $to_place_3; ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km3" id="single_start_km3" class="form-control"  value="<?php echo $single_start_km3 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km3" id="single_end_km3" class="form-control"  value="<?php echo $single_end_km3; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km3" id="single_total_km3" class="form-control"  value="<?php echo $single_total_km3; ?>"  >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_3" id="rate_3" class="form-control" value="<?php echo $rate_3; ?>">
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_3" id="amount_3" class="form-control" value="<?php echo $amount_3; ?>"  >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_3" id="date_3" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_3);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_3" id="total_freight_3" class="form-control"  value="<?php echo $total_freight_3; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_3" id="advance_3" class="form-control"  value="<?php echo $advance_3; ?>">
                     </div>
                  </div>
               </div>
            </div>

            
            <div class="row">
               <div class="col-md-12">
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_4" id="c_no_4" class="form-control" value="<?php echo $c_no_4; ?>" onblur="fetchContractDetails('c_no_4')" >
                     </div>
                  </div>
                   <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_4" id="from_place_4" class="form-control" value="<?php echo $from_place_4; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_4" id="to_place_4" class="form-control"  value="<?php echo $to_place_4 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km4" id="single_start_km4" class="form-control"  value="<?php echo $single_start_km4 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km4" id="single_end_km4" class="form-control"  value="<?php echo $single_end_km4; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km4" id="single_total_km4" class="form-control"  value="<?php echo $single_total_km4; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_4" id="rate_4" class="form-control" value="<?php echo $rate_4; ?>" >
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_4" id="amount_4" class="form-control"  value="<?php echo $amount_4; ?>" >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_4" id="date_4" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_4);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_4" id="total_freight_4" class="form-control"  value="<?php echo $total_freight_4; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_4" id="advance_4" class="form-control"  value="<?php echo $advance_4; ?>">
                     </div>
                  </div>

               </div>
            </div>


            <div class="row">
               <div class="col-md-12">

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_5" id="c_no_5" class="form-control" value="<?php echo $c_no_5; ?>" onblur="fetchContractDetails('c_no_5')" >
                     </div>
                  </div>

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_5" id="from_place_5" class="form-control" value="<?php echo $from_place_5; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_5" id="to_place_5" class="form-control"  value="<?php echo $to_place_5 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km5" id="single_start_km5" class="form-control"  value="<?php echo $single_start_km5 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km5" id="single_end_km5" class="form-control"  value="<?php echo $single_end_km5; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km5" id="single_total_km5" class="form-control"  value="<?php echo $single_total_km5; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_5" id="rate_5" class="form-control"  value="<?php echo $rate_5 ?>"  >
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_5" id="amount_5" class="form-control"  value="<?php echo $amount_5 ?>"  >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_5" id="date_5" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_5);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_5" id="total_freight_5" class="form-control"  value="<?php echo $total_freight_5; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_5" id="advance_5" class="form-control"  value="<?php echo $advance_5; ?>">
                     </div>
                  </div>
               </div>
            </div>

            
            <div class="row">
               <div class="col-md-12">

                   <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_6" id="c_no_6" class="form-control" value="<?php echo $c_no_6; ?>" onblur="fetchContractDetails('c_no_6')" >
                     </div>
                  </div>

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_6" id="from_place_6" class="form-control" value="<?php echo $from_place_6; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_6" id="to_place_6" class="form-control"  value="<?php echo $to_place_6 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km6" id="single_start_km6" class="form-control"  value="<?php echo $single_start_km6 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km6" id="single_end_km6" class="form-control"  value="<?php echo $single_end_km6; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km6" id="single_total_km6" class="form-control"  value="<?php echo $single_total_km6; ?>" >
                           </div>
                        </div>
                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_6" id="rate_6" class="form-control" value="<?php echo $rate_6; ?>" >
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_6" id="amount_6" class="form-control" value="<?php echo $amount_6; ?>"  >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_6" id="date_6" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_6);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_6" id="total_freight_6" class="form-control"  value="<?php echo $total_freight_6; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_6" id="advance_6" class="form-control"  value="<?php echo $advance_6; ?>">
                     </div>
                  </div>
               </div>
            </div>

             <div class="row">
               <div class="col-md-12">

                   <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_7" id="c_no_7" class="form-control" value="<?php echo $c_no_7; ?>" onblur="fetchContractDetails('c_no_7')" >
                     </div>
                  </div>

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_7" id="from_place_7" class="form-control" value="<?php echo $from_place_7; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_7" id="to_place_7" class="form-control"  value="<?php echo $to_place_7 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km7" id="single_start_km7" class="form-control"  value="<?php echo $single_start_km7 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km7" id="single_end_km7" class="form-control"  value="<?php echo $single_end_km7; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km7" id="single_total_km7" class="form-control"  value="<?php echo $single_total_km7; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_7" id="rate_7" class="form-control" value="<?php echo $rate_7; ?>" >
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_7" id="amount_7" class="form-control"  value="<?php echo $amount_7; ?>" >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_7" id="date_7" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_7);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_7" id="total_freight_7" class="form-control"  value="<?php echo $total_freight_7; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_7" id="advance_7" class="form-control"  value="<?php echo $advance_7; ?>">
                     </div>
                  </div>
               </div>
            </div>

             <div class="row">
               <div class="col-md-12">

                   <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_8" id="c_no_8" class="form-control" value="<?php echo $c_no_8; ?>" onblur="fetchContractDetails('c_no_8')" >
                     </div>
                  </div>

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_8" id="from_place_8" class="form-control" value="<?php echo $from_place_8; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_8" id="to_place_8" class="form-control"  value="<?php echo $to_place_8 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km8" id="single_start_km8" class="form-control"  value="<?php echo $single_start_km8 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km8" id="single_end_km8" class="form-control"  value="<?php echo $single_end_km8; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km8" id="single_total_km8" class="form-control"  value="<?php echo $single_total_km8; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_8" id="rate_8" class="form-control" value="<?php echo $rate_8; ?>" >
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_8" id="amount_8" class="form-control"  value="<?php echo $amount_8; ?>" >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_8" id="date_8" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_8);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_8" id="total_freight_8" class="form-control"  value="<?php echo $total_freight_8; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_8" id="advance_8" class="form-control"  value="<?php echo $advance_8; ?>">
                     </div>
                  </div>
               </div>
            </div>

             <div class="row">
               <div class="col-md-12">

                   <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_9" id="c_no_9" class="form-control" value="<?php echo $c_no_9; ?>" onblur="fetchContractDetails('c_no_9')" >
                     </div>
                  </div>

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_9" id="from_place_9" class="form-control" value="<?php echo $from_place_9; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_9" id="to_place_9" class="form-control"  value="<?php echo $to_place_9 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km9" id="single_start_km9" class="form-control"  value="<?php echo $single_start_km9 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km9" id="single_end_km9" class="form-control"  value="<?php echo $single_end_km9; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km9" id="single_total_km9" class="form-control"  value="<?php echo $single_total_km9; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_9" id="rate_9" class="form-control" value="<?php echo $rate_9; ?>" >
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_9" id="amount_9" class="form-control" value="<?php echo $amount_9; ?>" >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_9" id="date_9" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_9);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_9" id="total_freight_9" class="form-control"  value="<?php echo $total_freight_9; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_9" id="advance_9" class="form-control"  value="<?php echo $advance_9; ?>">
                     </div>
                  </div>
               </div>
            </div>

             <div class="row">
               <div class="col-md-12">

                   <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_10" id="c_no_10" class="form-control" value="<?php echo $c_no_10; ?>" onblur="fetchContractDetails('c_no_10')" >
                     </div>
                  </div>
                  
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_10" id="from_place_10" class="form-control" value="<?php echo $from_place_10; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_10" id="to_place_10" class="form-control"  value="<?php echo $to_place_10 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km10" id="single_start_km10" class="form-control"  value="<?php echo $single_start_km10 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km10" id="single_end_km10" class="form-control"  value="<?php echo $single_end_km10; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km10" id="single_total_km10" class="form-control"  value="<?php echo $single_total_km10; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_10" id="rate_10" class="form-control" value="<?php echo $rate_10; ?>" >
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_10" id="amount_10" class="form-control" value="<?php echo $amount_10; ?>"  >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_10" id="date_10" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_10);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_10" id="total_freight_10" class="form-control"  value="<?php echo $total_freight_10; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_10" id="advance_10" class="form-control"  value="<?php echo $advance_10; ?>">
                     </div>
                  </div>
               </div>
            </div>

             <div class="row">
               <div class="col-md-12">

                   <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_11" id="c_no_11" class="form-control" value="<?php echo $c_no_11; ?>" onblur="fetchContractDetails('c_no_11')" >
                     </div>
                  </div>

                       <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_11" id="from_place_11" class="form-control" value="<?php echo $from_place_11; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_11" id="to_place_11" class="form-control"  value="<?php echo $to_place_11 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km11" id="single_start_km11" class="form-control"  value="<?php echo $single_start_km11 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km11" id="single_end_km11" class="form-control"  value="<?php echo $single_end_km11; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km11" id="single_total_km11" class="form-control"  value="<?php echo $single_total_km11; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_11" id="rate_11" class="form-control" value="<?php echo $rate_11; ?>">
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_11" id="amount_11" class="form-control" value="<?php echo $amount_11; ?>" >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_11" id="date_11" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_11);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_11" id="total_freight_11" class="form-control"  value="<?php echo $total_freight_11; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_11" id="advance_11" class="form-control"  value="<?php echo $advance_11; ?>">
                     </div>
                  </div>
               </div>
            </div>

             <div class="row">
               <div class="col-md-12">

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="c_no_12" id="c_no_12" class="form-control " value="<?php echo $c_no_12; ?>" onblur="fetchContractDetails('c_no_12')" >
                     </div>
                  </div>
                  
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="from_place_12" id="from_place_12" class="form-control" value="<?php echo $from_place_12; ?>">
                     </div>
                  </div>

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="to_place_12" id="to_place_12" class="form-control"  value="<?php echo $to_place_12 ?>">
                     </div>
                  </div>
                   <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_start_km12" id="single_start_km12" class="form-control"  value="<?php echo $single_start_km12 ;?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_end_km12" id="single_end_km12" class="form-control"  value="<?php echo $single_end_km12; ?>" oninput="calculatesingleTotalKm()">
                           </div>
                        </div>
                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="single_total_km12" id="single_total_km12" class="form-control"  value="<?php echo $single_total_km12; ?>" >
                           </div>
                        </div>

                        <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="rate_12" id="rate_12" class="form-control" value="<?php echo $amount_12; ?>">
                           </div>
                        </div>

                         <div class="col-md-1">
                           <div class="form-group">
                              <label class="capital"></label>
                              <input type="text" name="amount_12" id="amount_12" class="form-control" value="<?php echo $amount_12; ?>" >
                           </div>
                        </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital"></label>
                        <div class="input-group">
                           <input type="text" name="date_12" id="date_12" class="form-control date-picker" autocomplete="off" value="<?php echo risFormatDate($date_12);?>"/>
                           <div class="input-group-addon">
                              <i class="fa fa-calendar date-icon-color"></i>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="total_freight_12" id="total_freight_12" class="form-control"  value="<?php echo $total_freight_12; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"></label>
                        <input type="text" name="advance_12" id="advance_12" class="form-control"  value="<?php echo $advance_12; ?>">
                     </div>
                  </div>
               </div>
            </div>






            <div class="row">
               <div class="col-md-12">
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital">START KM</label><span class="error">*</span>
                        <input type="text" name="start_km" id="start_km" class="form-control start_km" placeholder="START KM" value="<?php echo $start_km; ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital">END KM</label><span class="error">*</span>
                        <input type="text" name="end_km" id="end_km" class="form-control number" placeholder="END KM" value="<?php echo $end_km ?>">
                     </div>
                  </div>
                  <div class="col-md-3">
                     <div class="form-group">
                        <label class="capital">TOTAL KM</label><span class="error">*</span>
                        <input type="text" name="total_km" id="total_km" class="form-control number" readonly value="<?php echo $total_km ?>">
                     </div>
                  </div>

                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">rate/KM</label><span class="error">*</span>
                        <input type="text" name="rate_per_km" id="rate_per_km" class="form-control number" value="<?php echo $rate_per_km ?>">
                     </div>
                  </div>

                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital">total amount</label><span class="error">*</span>
                        <input type="text" name="total_amount" id="total_amount" class="form-control number" readonly value="<?php echo $total_amount ?>">
                     </div>
                  </div>

                  <div class="col-md-2">
                     <div class="form-group">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital">TOTAL FREIGHT</label>
                        <input type="text" name="total_freight" id="total_freight" class="form-control number" placeholder="TOTAL FREIGHT" value="<?php echo $total_freight ?>">
                     </div>
                  </div>
                  <div class="col-md-1">
                     <div class="form-group">
                        <label class="capital"> TOtal ADVANCE</label>
                        <input type="text" name="advance_amount" id="advance_amount" class="form-control number" placeholder="ADVANCE" value="<?php echo $advance_amount ?>">
                     </div>
                  </div>


               </div>
            </div>
            <div class="row">
               <div class="col-md-12">
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">FIX EXPENSE 1</label><span class="error">*</span>
                        <input type="text" name="expense_1" id="expense_1" class="form-control" value="<?php echo $expense_1;?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">FIX EXPENSE 2</label><span class="error">*</span>
                        <input type="text" name="expense_2" id="expense_2" class="form-control" value="<?php echo $expense_2 ?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">FIX EXPENSE 3</label><span class="error">*</span>
                        <input type="text" name="expense_3" id="expense_3" class="form-control"  value="<?php echo $expense_3 ?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">FIX EXPENSE 4</label><span class="error">*</span>
                        <input type="text" name="expense_4" id="expense_4" class="form-control" value="<?php echo $expense_4;?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">FIX EXPENSE 5</label><span class="error">*</span>
                        <input type="text" name="expense_5" id="expense_5" class="form-control" value="<?php echo $expense_5 ?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">FIX EXPENSE 6</label><span class="error">*</span>
                        <input type="text" name="expense_6" id="expense_6" class="form-control"  value="<?php echo $expense_6 ?>">
                     </div>
                  </div>
               </div>
            </div>
            <div class="row">
               <div class="col-md-12">
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">REMARK 1</label><span class="error">*</span>
                        <input type="text" name="remark_1" id="remark_1" class="form-control" value="<?php echo $remark_1;?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">REMARK 2</label><span class="error">*</span>
                        <input type="text" name="remark_2" id="remark_2" class="form-control"  value="<?php echo $remark_2 ?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">REMARK 3</label><span class="error">*</span>
                        <input type="text" name="remark_3" id="remark_3" class="form-control"  value="<?php echo $remark_3 ?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">REMARK 4</label><span class="error">*</span>
                        <input type="text" name="remark_4" id="remark_4" class="form-control" value="<?php echo $remark_4;?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">REMARK 5</label><span class="error">*</span>
                        <input type="text" name="remark_5" id="remark_5" class="form-control"  value="<?php echo $remark_5 ?>">
                     </div>
                  </div>
                  <div class="col-md-2">
                     <div class="form-group">
                        <label class="capital">REMARK 6</label><span class="error">*</span>
                        <input type="text" name="remark_6" id="remark_6" class="form-control"  value="<?php echo $remark_6 ?>">
                     </div>
                  </div>
               </div>
            </div>
            <div class="row">
               <div class="col-md-12">
                 <div class="col-md-2">
                   <div class="form-group">
                    <label class="capital">FAST TAG OPENING</label><span class="error">*</span>
                    <input type="text" name="fast_tag_opening" id="fast_tag_opening" class="form-control" placeholder="OPENING BALANCE" readonly value="<?php echo $fast_tag_opening;?>">
                    <span id="fast_tag_opening_element">0</span>
                 </div>
              </div>
              <div class="col-md-2">
               <div class="form-group">
                  <label class="capital">Fast tag Recharge</label><span class="error">*</span>
                  <input type="text" name="fast_tag_recharge" id="fast_tag_recharge" class="form-control" placeholder="END KM" value="<?php echo $fast_tag_recharge;?>">
               </div>
            </div>
            <div class="col-md-2">
               <div class="form-group">
                  <label class="capital">Fast tag used</label><span class="error">*</span>
                  <input type="text" name="fast_tag_used" id="fast_tag_used" class="form-control" value="<?php echo $fast_tag_used ;?>">
               </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 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="recharge_date" name="recharge_date" class="form-control date-picker required" placeholder="DATE" autocomplete="off" value="<?php echo risFormatDate($recharge_date);?>" />
             </div>
          </div>
       </div>
       <div class="col-md-2">
         <div class="form-group">
            <label class="capital">Fast tag Closing</label><span class="error">*</span>
            <input type="text" name="fast_tag_closing" id="fast_tag_closing" class="form-control" value="<?php echo $fast_tag_closing ;?>">
         </div>
      </div>
      <div class="col-md-1">
         <div class="form-group">
            <label class="capital">EXTRA PAyable TO DRIVER</label>
            <input type="text" name="extra_paid_to_driver" id="extra_paid_to_driver" class="form-control" value="<?php echo $extra_paid_to_driver ;?>">
         </div>
      </div>

      <div class="col-md-1">
         <div class="form-group">
            <label class="capital">REMARK</label>
            <input type="text" name="driver_remark" id="driver_remark" class="form-control" value="<?php echo $driver_remark ;?>">
         </div>
      </div>

   </div>
</div>
<div class="row">
  <div class="col-md-2">
    <div id="validationMessage"></div>
 </div>
</div>
<div class="row">
   <div class="col-md-12">
      <div class="col-sm-12" id="product-wapper">
         <table class="table table-bordered table-responsive">
            <thead>
               <tr>
                 <th class="text-center" width="10">#</th>
                 <th class="text-center" width="100">DATE</th>
                 <th class="text-center">HAMALI</th>
                 <th class="text-center">LOADING/UN LOADING</th>
                 <th class="text-center"width="80">CASH DRIVER</th>
                 <th class="text-center"width="80">BANK DRIVER</th>
                 <th class="text-center">TOLL</th>
                 <th class="text-center">KATA</th>
                 <th class="text-center">BORDER</th>
                 <th class="text-center">BATTHA/KHANA</th>
                 <th class="text-center">SALARY</th>
                 <th class="text-center"width="80">DIESEL QTY</th>
                 <th class="text-center"width="80">DIESEL RATE</th>
                 <th class="text-center"width="80">DIESEL AMOUNT</th>
                 <th class="text-center">MAINTANANCE</th>
                 <th class="text-center">TYRE</th>
                 <th class="text-center">ELECTRIC</th>
                 <th class="text-center">MECHANIC</th>
                 <th class="text-center">POLICE / RTO</th>
                 <th class="text-center">FASTTAG</th>
                 <th class="text-center">EXTRA HEIGHT</th>
                 <th class="text-center">EXTRA WEIGHT</th>
              </tr>
           </thead>
           <tbody>
            <?php $tmp_cnt = 0; ?>
            <?php if(isset($detail) && count($detail) > 0) { ?>
               <?php foreach ($detail as $key => $detail_data) { ?>
                <tr>
                 <td>
                    <a href="javascript:;" class="btn red btn-block remove-me cutome-action-btn" style="display: <?php echo ($tmp_row_count == $last_med) ? 'block' : 'none'; ?>;"><i class="fa fa-minus"></i></a>
                 </td>

                 <td> <input type="text" name="product[<?php echo $key ?>][date]" class="add-more-table form-control date-picker top date" data-count="<?php echo $key;?>" value="<?php echo risFormatDate($detail_data['date'],'d-m-Y')?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][hamali]" class="form-control top add-more-table hamali number" value="<?php echo $detail_data['hamali']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][loading_unloading]" class="form-control top add-more-table loading_unloading number" value="<?php echo $detail_data['loading_unloading']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][cash_driver]" class="form-control top add-more-table cash_driver number" value="<?php echo $detail_data['cash_driver']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][bank_driver]" class="form-control top add-more-table bank_driver number" value="<?php echo $detail_data['bank_driver']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][toll]" class="form-control top add-more-table toll number" value="<?php echo $detail_data['toll']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][kata]" class="form-control top add-more-table kata number" value="<?php echo $detail_data['kata']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][border]" class="form-control top add-more-table border number" value="<?php echo $detail_data['border']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][battha]" class="form-control top add-more-table battha number" value="<?php echo $detail_data['battha']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][salary]" class="form-control top add-more-table salary number" value="<?php echo $detail_data['salary']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][diesel]" class="form-control top add-more-table diesel number" value="<?php echo $detail_data['diesel'];?>"></td>
                 <td><input type="text" name="product[<?php echo $key ?>][diesel_rate]" class="form-control top add-more-table diesel_rate number" value="<?php echo $detail_data['diesel_rate'];?>"></td>
                 <td><input type="text" name="product[<?php echo $key ?>][diesel_amount]" class="form-control top add-more-table diesel_amount number" value="<?php echo $detail_data['diesel_amount'];?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][maintance]" class="form-control top add-more-table maintance number" value="<?php echo $detail_data['maintance']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][tyre]" class="form-control top add-more-table tyre number" value="<?php echo $detail_data['tyre']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][electric]" class="form-control top add-more-table electric number" value="<?php echo $detail_data['electric']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][mechanic]" class="form-control top add-more-table mechanic number" value="<?php echo $detail_data['mechanic']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][police_rto]" class="form-control top add-more-table police_rto number" value="<?php echo $detail_data['police_rto']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][other]" class="form-control top add-more-table other number" value="<?php echo $detail_data['other']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][extra_height]" class="form-control top add-more-table extra_height number" value="<?php echo $detail_data['extra_height']?>"></td>

                 <td><input type="text" name="product[<?php echo $key ?>][extra_weight]" class="form-control top add-more-table extra_weight number" value="<?php echo $detail_data['extra_weight']?>"></td>
              </tr>
              <?php $tmp_cnt++; ?>
           <?php } ?>
        <?php } ?>
        <?php
        $tmp_for_loop = ( $tmp_cnt < 10 ) ? 10 : ($tmp_cnt + 1);
        $last_med = $tmp_for_loop - 1;
        ?>
        <?php for ($tmp_row_count = $tmp_cnt; $tmp_row_count < $tmp_for_loop; $tmp_row_count++) { ?>
         <tr>
            <td>
               <a href="javascript:;" class="btn green btn-block add-more cutome-action-btn" style="display: <?php echo ($tmp_row_count == $last_med) ? 'block' : 'none'; ?>"><i class="fa fa-plus"></i></a>
               <a href="javascript:;" class="btn red btn-block remove-me cutome-action-btn" style="display: <?php echo ($tmp_row_count == $last_med) ? 'none' : 'block'; ?>;"><i class="fa fa-minus"></i></a>
            </td>

            <td> <input type="text" name="product[<?php echo $tmp_row_count ?>][date]" class="add-more-table form-control date-picker top date" data-count="<?php echo $tmp_row_count;?>"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][hamali]" class="form-control top add-more-table hamali number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][loading_unloading]" class="form-control top add-more-table loading_unloading number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][cash_driver]" class="form-control top add-more-table cash_driver number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][bank_driver]" class="form-control top add-more-table bank_driver number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][toll]" class="form-control top add-more-table toll number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][kata]" class="form-control top add-more-table kata number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][border]" class="form-control top add-more-table border number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][battha]" class="form-control top add-more-table battha number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][salary]" class="form-control top add-more-table salary number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][diesel]" class="form-control top add-more-table diesel number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][diesel_rate]" class="form-control top add-more-table diesel_rate number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][diesel_amount]" class="form-control top add-more-table diesel_amount number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][maintance]" class="form-control top add-more-table maintance number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][tyre]" class="form-control top add-more-table tyre number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][electric]" class="form-control top add-more-table electric number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][mechanic]" class="form-control top add-more-table mechanic number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][police_rto]" class="form-control top add-more-table police_rto number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][other]" class="form-control top add-more-table other number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][extra_height]" class="form-control top add-more-table extra_height number"></td>

            <td><input type="text" name="product[<?php echo $tmp_row_count ?>][extra_weight]" class="form-control top add-more-table extra_weight number"></td>
         </tr>
      <?php }  ?>
   </tbody>
</table>
</div>
</div>
</div>
<hr>
<div class="row text-center">
   <input type="hidden" name="id" class="form-control top add-more-table" value="<?php echo $id?>">
   <button id="btn" class="btn btn-primary ajax-submit capital" type="submit"> <?php echo ($id == 0) ? 'Save & List' : 'Update & save'; ?></button>
   <a href="index.php?page=trip/list.php" class="btn btn-danger capital"> Cancel</a>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<div id="product-template" style="display:none;">
  <table>
    <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[%i%][date]" class="add-more-table form-control date-picker top date" data-count="%i%"></td>

     <td><input type="text" name="product[%i%][hamali]" class="form-control top add-more-table hamali number"></td>

     <td><input type="text" name="product[%i%][loading_unloading]" class="form-control top add-more-table loading_unloading number"></td>

     <td><input type="text" name="product[%i%][cash_driver]" class="form-control top add-more-table cash_driver number"></td>
     
     <td><input type="text" name="product[%i%][bank_driver]" class="form-control top add-more-table bank_driver number"></td>

     <td><input type="text" name="product[%i%][toll]" class="form-control top add-more-table toll number"></td>

     <td><input type="text" name="product[%i%][kata]" class="form-control top add-more-table kata number"></td>

     <td><input type="text" name="product[%i%][border]" class="form-control top add-more-table border number"></td>

     <td><input type="text" name="product[%i%][battha]" class="form-control top add-more-table battha number"></td>

     <td><input type="text" name="product[%i%][salary]" class="form-control top add-more-table salary number"></td>

     <td><input type="text" name="product[%i%][diesel]" class="form-control top add-more-table diesel number"></td>
     <td><input type="text" name="product[%i%][diesel_rate]" class="form-control top add-more-table diesel_rate number"></td>
     <td><input type="text" name="product[%i%][diesel_amount]" class="form-control top add-more-table diesel_amount number"></td>

     <td><input type="text" name="product[%i%][maintance]" class="form-control top add-more-table maintance number"></td>

     <td><input type="text" name="product[%i%][tyre]" class="form-control top add-more-table tyre number"></td>

     <td><input type="text" name="product[%i%][electric]" class="form-control top add-more-table electric number"></td>

     <td><input type="text" name="product[%i%][mechanic]" class="form-control top add-more-table mechanic number"></td>

     <td><input type="text" name="product[%i%][police_rto]" class="form-control top add-more-table police_rto number"></td>

     <td><input type="text" name="product[%i%][other]" class="form-control top add-more-table other number"></td>

     <td><input type="text" name="product[%i%][extra_height]" class="form-control top add-more-table extra_height number"></td>

     <td><input type="text" name="product[%i%][extra_weight]" class="form-control top add-more-table extra_weight number"></td>
  </tr>
</table>
</div>
<script type="text/javascript">
   jQuery(document).ready(function() {
     var $length = 0;
     jQuery(document).on('click', '.add-more', function(e) {
       $length = jQuery('#product-wapper').find('table tbody tr').length;
       var $clone = jQuery('#product-template table tr').clone();
       $clone.find('input').each(function() {
         this.name = this.name.replace('[%i%]', '[' + $length + ']');
      });
       $clone.find('.date').attr('data-count', $length);
       jQuery('#product-wapper table tbody').append($clone);
       jQuery('#product-wapper table tbody').find('.remove-me').show();
       jQuery('#product-wapper table tbody').find('.add-more').hide();
       jQuery('#product-wapper table tbody').find('.remove-me:last').hide();
       jQuery('#product-wapper table tbody').find('.add-more:last').show();

       if (jQuery().datepicker) {
        $('.date-picker').datepicker({
         orientation     : "center",
         todayHighlight  : true,
         todayBtn        :  1,
         autoclose       : true,
         format: 'dd-mm-yyyy',
      });
     }
     attachEventListenersToRow($clone[0]);
  });
     jQuery('#truck_no').select2();
     jQuery('#driver_id').select2();
     jQuery(document).on('click', '.remove-me', function(e) {
       e.preventDefault();
       jQuery(this).closest('tr').remove();
    });

     jQuery(document).on('change', '#truck_no', function(e) {
       GetTruckData();
    });

     jQuery(document).on('change', '#driver_id', function(e) {
       GetDriverData();
    });

     jQuery(document).on('keyup', '#start_km', function(e) {
       CheckNumber();
    });

     jQuery(document).on('keyup', '#end_km', function(e) {
       CheckNumber();
    });   
  });

   function GetTruckData(ele) {
     var truck_no = jQuery("#truck_no").val();
     $.ajax({
       'type': 'POST',
       'url': 'trip/get_truck.php',
       'data': 'truck_no=' + truck_no,
       dataType: 'JSON',
       success: function (result) {
         if (result != '') {
           jQuery('#owner_name').val(result[0].owner_name);
           jQuery('#owner_pan').val(result[0].owner_pan);
        }
     }
  });
  }

  function GetDriverData(ele) {
     var driver_id = jQuery("#driver_id").val();
     $.ajax({
       'type': 'POST',
       'url': 'trip/get_driver.php',
       'data': 'driver_id=' + driver_id,
       dataType: 'JSON',
       success: function (result) {
         if (result != '') {
           jQuery('#driver_lic_no').val(result[0].driver_lic_no);
           jQuery('#driver_address').val(result[0].driver_address);
        }
     }
  });
  }

  function CheckNumber(argument) {
     var startNumber = parseInt(jQuery("#start_km").val(), 10);
     var endNumber = parseInt(jQuery("#end_km").val(), 10);

     if (!isNaN(startNumber) && !isNaN(endNumber)) {
       if (startNumber <= endNumber) {
         jQuery("#validationMessage").text("Valid: End number is greater than or equal to start number.");
         jQuery("#validationMessage").css("color", "green");
         jQuery('.ajax-submit').attr('disabled', false);
      } else {
         jQuery("#validationMessage").text("Invalid: End number must be greater than or equal to start number.");
         jQuery("#validationMessage").css("color", "red");
         jQuery('.ajax-submit').attr('disabled', true);
      }
   } else {
    jQuery("#validationMessage").text("Please enter valid numbers in both fields.");
    jQuery("#validationMessage").css("color", "red");
    jQuery('.ajax-submit').attr('disabled', true);
 }
}

function calculateTotals() {
      // Get values of total_freight_1 and total_freight_2
   let totalFreight1 = parseFloat(document.getElementById('total_freight_1').value) || 0;
   let totalFreight2 = parseFloat(document.getElementById('total_freight_2').value) || 0;
   let totalFreight3 = parseFloat(document.getElementById('total_freight_3').value) || 0;
   let totalFreight4 = parseFloat(document.getElementById('total_freight_4').value) || 0;
   let totalFreight5 = parseFloat(document.getElementById('total_freight_5').value) || 0;
   let totalFreight6 = parseFloat(document.getElementById('total_freight_6').value) || 0;
   let totalFreight7 = parseFloat(document.getElementById('total_freight_7').value) || 0;
   let totalFreight8 = parseFloat(document.getElementById('total_freight_8').value) || 0;
   let totalFreight9 = parseFloat(document.getElementById('total_freight_9').value) || 0;
   let totalFreight10 = parseFloat(document.getElementById('total_freight_10').value) || 0;
   let totalFreight11 = parseFloat(document.getElementById('total_freight_11').value) || 0;
   let totalFreight12 = parseFloat(document.getElementById('total_freight_12').value) || 0;

      // Sum total_freight_1 and total_freight_2
   let totalFreight = totalFreight1 + totalFreight2 + totalFreight3 + totalFreight4 + totalFreight5 + totalFreight6 +  totalFreight7 + totalFreight8 + totalFreight9 + totalFreight10 + totalFreight11 + totalFreight12;

      // Update total_freight field
   document.getElementById('total_freight').value = totalFreight;

      // Get values of advance_1 and advance_2
   let advance1 = parseFloat(document.getElementById('advance_1').value) || 0;
   let advance2 = parseFloat(document.getElementById('advance_2').value) || 0;
   let advance3 = parseFloat(document.getElementById('advance_3').value) || 0;
   let advance4 = parseFloat(document.getElementById('advance_4').value) || 0;
   let advance5 = parseFloat(document.getElementById('advance_5').value) || 0;
   let advance6 = parseFloat(document.getElementById('advance_6').value) || 0;
   let advance7 = parseFloat(document.getElementById('advance_7').value) || 0;
   let advance8 = parseFloat(document.getElementById('advance_8').value) || 0;
   let advance9 = parseFloat(document.getElementById('advance_9').value) || 0;
   let advance10 = parseFloat(document.getElementById('advance_10').value) || 0;
   let advance11 = parseFloat(document.getElementById('advance_11').value) || 0;
   let advance12 = parseFloat(document.getElementById('advance_12').value) || 0;

      // Sum advance_1 and advance_2
   let advanceTotal = advance1 + advance2 + advance3 + advance4 + advance5 + advance6 + advance7 + advance8 + advance9 + advance10 + advance11 + advance12 ;

      // Update advance_amount field
   document.getElementById('advance_amount').value = advanceTotal;
}

   // Add event listeners to input fields
document.getElementById('total_freight_1').oninput = calculateTotals;
document.getElementById('total_freight_2').oninput = calculateTotals;
document.getElementById('total_freight_3').oninput = calculateTotals;
document.getElementById('total_freight_4').oninput = calculateTotals;
document.getElementById('total_freight_5').oninput = calculateTotals;
document.getElementById('total_freight_6').oninput = calculateTotals;
document.getElementById('total_freight_7').oninput = calculateTotals;
document.getElementById('total_freight_8').oninput = calculateTotals;
document.getElementById('total_freight_9').oninput = calculateTotals;
document.getElementById('total_freight_10').oninput = calculateTotals;
document.getElementById('total_freight_11').oninput = calculateTotals;
document.getElementById('total_freight_12').oninput = calculateTotals;
document.getElementById('advance_1').oninput = calculateTotals;
document.getElementById('advance_2').oninput = calculateTotals;
document.getElementById('advance_3').oninput = calculateTotals;
document.getElementById('advance_4').oninput = calculateTotals;
document.getElementById('advance_5').oninput = calculateTotals;
document.getElementById('advance_6').oninput = calculateTotals;
document.getElementById('advance_7').oninput = calculateTotals;
document.getElementById('advance_8').oninput = calculateTotals;
document.getElementById('advance_9').oninput = calculateTotals;
document.getElementById('advance_10').oninput = calculateTotals;
document.getElementById('advance_11').oninput = calculateTotals;
document.getElementById('advance_12').oninput = calculateTotals;


document.addEventListener('DOMContentLoaded', (event) => {
    const startKmInput = document.getElementById('start_km');
    const endKmInput = document.getElementById('end_km');
    const totalKmInput = document.getElementById('total_km');
    const ratePerKmInput = document.getElementById('rate_per_km');
    const totalAmountInput = document.getElementById('total_amount');
    const rate1Input = document.getElementById('rate_1');
    const amount1Input = document.getElementById('amount_1');
    const rate2Input = document.getElementById('rate_2');
    const amount2Input = document.getElementById('amount_2');
    const rate3Input = document.getElementById('rate_3');
    const amount3Input = document.getElementById('amount_3');
    const rate4Input = document.getElementById('rate_4');
    const amount4Input = document.getElementById('amount_4');
    const rate5Input = document.getElementById('rate_5');
    const amount5Input = document.getElementById('amount_5');
    const rate6Input = document.getElementById('rate_6');
    const amount6Input = document.getElementById('amount_6');
    const rate7Input = document.getElementById('rate_7');
    const amount7Input = document.getElementById('amount_7');
    const rate8Input = document.getElementById('rate_8');
    const amount8Input = document.getElementById('amount_8');
    const rate9Input = document.getElementById('rate_9');
    const amount9Input = document.getElementById('amount_9');
    const rate10Input = document.getElementById('rate_10');
    const amount10Input = document.getElementById('amount_10');
    const rate11Input = document.getElementById('rate_11');
    const amount11Input = document.getElementById('amount_11');
    const rate12Input = document.getElementById('rate_12');
    const amount12Input = document.getElementById('amount_12');

 const manuallySetAmounts = new Set();

// Add event listeners for manual amount inputs
document.getElementById('amount_1').addEventListener('input', function() {
    manuallySetAmounts.add('amount_1');
});
document.getElementById('amount_2').addEventListener('input', function() {
    manuallySetAmounts.add('amount_2');
});

document.getElementById('amount_3').addEventListener('input', function() {
    manuallySetAmounts.add('amount_3');
});
document.getElementById('amount_4').addEventListener('input', function() {
    manuallySetAmounts.add('amount_4');
});
document.getElementById('amount_5').addEventListener('input', function() {
    manuallySetAmounts.add('amount_5');
});
document.getElementById('amount_6').addEventListener('input', function() {
    manuallySetAmounts.add('amount_6');
});
document.getElementById('amount_7').addEventListener('input', function() {
    manuallySetAmounts.add('amount_7');
});
document.getElementById('amount_8').addEventListener('input', function() {
    manuallySetAmounts.add('amount_8');
});
document.getElementById('amount_9').addEventListener('input', function() {
    manuallySetAmounts.add('amount_9');
});
document.getElementById('amount_10').addEventListener('input', function() {
    manuallySetAmounts.add('amount_10');
});
document.getElementById('amount_11').addEventListener('input', function() {
    manuallySetAmounts.add('amount_11');
});
document.getElementById('amount_12').addEventListener('input', function() {
    manuallySetAmounts.add('amount_12');
});



 function calculateAmount() {
    // Calculate amount_1 only if not manually set
    if (!manuallySetAmounts.has('amount_1')) {
        var single_total_km = parseFloat(document.getElementById('single_total_km').value) || 0;
        var rate_1 = parseFloat(document.getElementById('rate_1').value) || 0;
        var amount_1 = single_total_km * rate_1;
        document.getElementById('amount_1').value = amount_1.toFixed(2);
    }

    // Calculate amount_2 only if not manually set
    if (!manuallySetAmounts.has('amount_2')) {
        var single_total_km2 = parseFloat(document.getElementById('single_total_km2').value) || 0;
        var rate_2 = parseFloat(document.getElementById('rate_2').value) || 0;
        var amount_2 = single_total_km2 * rate_2;
        document.getElementById('amount_2').value = amount_2.toFixed(2);
    }

    // Continue with amount_3 to amount_12 in the same pattern...
    // Calculate amount_3 only if not manually set
    if (!manuallySetAmounts.has('amount_3')) {
        var single_total_km3 = parseFloat(document.getElementById('single_total_km3').value) || 0;
        var rate_3 = parseFloat(document.getElementById('rate_3').value) || 0;
        var amount_3 = single_total_km3 * rate_3;
        document.getElementById('amount_3').value = amount_3.toFixed(2);
    }

    if (!manuallySetAmounts.has('amount_4')) {
        var single_total_km4 = parseFloat(document.getElementById('single_total_km4').value) || 0;
        var rate_4 = parseFloat(document.getElementById('rate_4').value) || 0;
        var amount_4 = single_total_km4 * rate_4;
        document.getElementById('amount_4').value = amount_4.toFixed(2);
    }
    if (!manuallySetAmounts.has('amount_5')) {
        var single_total_km5 = parseFloat(document.getElementById('single_total_km5').value) || 0;
        var rate_5 = parseFloat(document.getElementById('rate_5').value) || 0;
        var amount_5 = single_total_km5 * rate_5;
        document.getElementById('amount_5').value = amount_5.toFixed(2);
    }
    if (!manuallySetAmounts.has('amount_6')) {
        var single_total_km6 = parseFloat(document.getElementById('single_total_km6').value) || 0;
        var rate_6 = parseFloat(document.getElementById('rate_6').value) || 0;
        var amount_6 = single_total_km6 * rate_6;
        document.getElementById('amount_6').value = amount_6.toFixed(2);
    }
    if (!manuallySetAmounts.has('amount_7')) {
        var single_total_km7 = parseFloat(document.getElementById('single_total_km7').value) || 0;
        var rate_7 = parseFloat(document.getElementById('rate_7').value) || 0;
        var amount_7 = single_total_km7 * rate_7;
        document.getElementById('amount_7').value = amount_7.toFixed(2);
    }
    if (!manuallySetAmounts.has('amount_8')) {
        var single_total_km8 = parseFloat(document.getElementById('single_total_km8').value) || 0;
        var rate_8 = parseFloat(document.getElementById('rate_8').value) || 0;
        var amount_8 = single_total_km8 * rate_8;
        document.getElementById('amount_8').value = amount_8.toFixed(2);
    }
    if (!manuallySetAmounts.has('amount_9')) {
        var single_total_km9 = parseFloat(document.getElementById('single_total_km9').value) || 0;
        var rate_9 = parseFloat(document.getElementById('rate_9').value) || 0;
        var amount_9 = single_total_km9 * rate_9;
        document.getElementById('amount_9').value = amount_9.toFixed(2);
    }
    if (!manuallySetAmounts.has('amount_10')) {
        var single_total_km10 = parseFloat(document.getElementById('single_total_km10').value) || 0;
        var rate_10 = parseFloat(document.getElementById('rate_10').value) || 0;
        var amount_10 = single_total_km10 * rate_10;
        document.getElementById('amount_10').value = amount_10.toFixed(2);
    }
    if (!manuallySetAmounts.has('amount_11')) {
        var single_total_km11 = parseFloat(document.getElementById('single_total_km11').value) || 0;
        var rate_11 = parseFloat(document.getElementById('rate_11').value) || 0;
        var amount_11 = single_total_km11 * rate_11;
        document.getElementById('amount_11').value = amount_11.toFixed(2);
    }
    if (!manuallySetAmounts.has('amount_12')) {
        var single_total_km12 = parseFloat(document.getElementById('single_total_km12').value) || 0;
        var rate_12 = parseFloat(document.getElementById('rate_12').value) || 0;
        var amount_12 = single_total_km12 * rate_12;
        document.getElementById('amount_12').value = amount_12.toFixed(2);
    }
    
    // ... and so on for all other amounts

    // Recalculate total amount
    calculateTotalAmount();
}

// Optional: Add a reset function if you need to clear manual overrides
function resetManualAmounts() {
    manuallySetAmounts.clear();
    calculateAmount(); // This will recalculate all amounts now
}


    function calculateTotalKm() {
        const startKm = parseFloat(startKmInput.value) || 0;
        const endKm = parseFloat(endKmInput.value) || 0;
        const totalKm = endKm - startKm;
        totalKmInput.value = totalKm > 0 ? totalKm : 0;
        calculateTotalAmount();
    }

    function calculateTotalAmount() {
        const totalKm = parseFloat(totalKmInput.value) || 0;
        const ratePerKm = parseFloat(ratePerKmInput.value) || 0;
        const amount1 = parseFloat(amount1Input.value) || 0;
        const amount2 = parseFloat(amount2Input.value) || 0;
        const amount3 = parseFloat(amount3Input.value) || 0;
        const amount4 = parseFloat(amount4Input.value) || 0;
        const amount5 = parseFloat(amount5Input.value) || 0;
        const amount6 = parseFloat(amount6Input.value) || 0;
        const amount7 = parseFloat(amount7Input.value) || 0;
        const amount8 = parseFloat(amount8Input.value) || 0;
        const amount9 = parseFloat(amount9Input.value) || 0;
        const amount10 = parseFloat(amount10Input.value) || 0;
        const amount11 = parseFloat(amount11Input.value) || 0;
        const amount12 = parseFloat(amount12Input.value) || 0;

        if (ratePerKm > 0) {
            // Use rate_per_km for calculation
            const totalAmount = totalKm * ratePerKm;
            totalAmountInput.value = totalAmount.toFixed(2);
        } else {
            // Fallback to amount_1 + amount_2 + ... + amount_12
            const totalAmount = amount1 + amount2 + amount3 + amount4 + amount5 + amount6 + amount7 + amount8 + amount9 + amount10 + amount11 + amount12;
            totalAmountInput.value = totalAmount.toFixed(2);
        }
    }

    // Event listeners for inputs
    startKmInput.addEventListener('input', calculateTotalKm);
    endKmInput.addEventListener('input', calculateTotalKm);
    ratePerKmInput.addEventListener('input', calculateTotalAmount);
    rate1Input.addEventListener('input', calculateAmount);
    rate2Input.addEventListener('input', calculateAmount);
    rate3Input.addEventListener('input', calculateAmount);
    rate4Input.addEventListener('input', calculateAmount);
    rate5Input.addEventListener('input', calculateAmount);
    rate6Input.addEventListener('input', calculateAmount);
    rate7Input.addEventListener('input', calculateAmount);
    rate8Input.addEventListener('input', calculateAmount);
    rate9Input.addEventListener('input', calculateAmount);
    rate10Input.addEventListener('input', calculateAmount);
    rate11Input.addEventListener('input', calculateAmount);
    rate12Input.addEventListener('input', calculateAmount);

    // Add event listeners for amount fields
    amount1Input.addEventListener('input', calculateTotalAmount);
    amount2Input.addEventListener('input', calculateTotalAmount);
    amount3Input.addEventListener('input', calculateTotalAmount);
    amount4Input.addEventListener('input', calculateTotalAmount);
    amount5Input.addEventListener('input', calculateTotalAmount);
    amount6Input.addEventListener('input', calculateTotalAmount);
    amount7Input.addEventListener('input', calculateTotalAmount);
    amount8Input.addEventListener('input', calculateTotalAmount);
    amount9Input.addEventListener('input', calculateTotalAmount);
    amount10Input.addEventListener('input', calculateTotalAmount);
    amount11Input.addEventListener('input', calculateTotalAmount);
    amount12Input.addEventListener('input', calculateTotalAmount);
});
function attachEventListenersToRow(row) {
  const dieselInput = row.querySelector('input.diesel');
  const dieselRateInput = row.querySelector('input.diesel_rate');
  const dieselAmountInput = row.querySelector('input.diesel_amount');
  
  if (dieselInput && dieselRateInput) {
    dieselInput.addEventListener('input', calculateDieselAmount);
    dieselRateInput.addEventListener('input', calculateDieselAmount);
  }

  if (dieselAmountInput) {
    dieselAmountInput.addEventListener('input', function() {
      // If the user manually enters an amount, set the manual flag
      if (dieselAmountInput.value !== '') {
        dieselAmountInput.dataset.manual = true; // Mark as manually edited
      } else {
        delete dieselAmountInput.dataset.manual; // Clear the manual flag if field is emptied
      }
    });
  }
}

// The diesel amount calculation function
function calculateDieselAmount() {
  document.querySelectorAll('input.diesel, input.diesel_rate').forEach(function(inputField) {
    const row = inputField.closest('tr');
    const dieselQty = parseFloat(row.querySelector('input.diesel').value) || 0;
    const dieselRate = parseFloat(row.querySelector('input.diesel_rate').value) || 0;
    const dieselAmountField = row.querySelector('input.diesel_amount');
    
    // Only calculate diesel amount if it's not manually entered
    if (!dieselAmountField.dataset.manual && dieselQty > 0 && dieselRate > 0) {
      const dieselAmount = dieselQty * dieselRate;
      dieselAmountField.value = dieselAmount.toFixed(2);
    }
  });
}

// Attach initial event listeners for already loaded rows
document.addEventListener('DOMContentLoaded', function() {
  document.querySelectorAll('tr').forEach(function(row) {
    attachEventListenersToRow(row);
  });

  // Trigger initial calculation
  calculateDieselAmount();
});


$(document).ready(function() {
 function calculatekilometerClosing() {
        // Get values from the input fields
  // var fastTagOpening = parseFloat($('#fast_tag_opening').val()) || 0;
  // var fastTagRecharge = parseFloat($('#fast_tag_recharge').val()) || 0;
  // var fastTagUsed = parseFloat($('#fast_tag_used').val()) || 0;

        // Perform the calculation: fast_tag_closing = fast_tag_opening + fast_tag_recharge - fast_tag_used
  // var fastTagClosing = fastTagOpening + fastTagRecharge - fastTagUsed;

        // Update the closing balance field
  // $('#fast_tag_closing').val(fastTagClosing.toFixed(2));
}

    // Trigger calculation on input change
// $('#fast_tag_recharge, #fast_tag_used').on('input', calculatekilometerClosing);

    // If fast_tag_opening is updated dynamically via AJAX
$('#truck_no').change(function() {
  var truck_no = $(this).val();

  $.ajax({
   type: 'POST',
   url: 'trip/get_kilometer.php',
   data: { truck_no: truck_no },
   dataType: 'json',
   success: function(response) {
    if (response.start_km) {
     $('#start_km').val(response.start_km);
                    // calculatekilometerClosing();  // Trigger calculation after updating opening balance
                 } else {
                    $('#start_km').val('0');
                    // calculatekilometerClosing();
                 }
              },
              error: function(jqXHR, textStatus, errorThrown) {
                console.error('AJAX error: ', textStatus, errorThrown);
                $('#start_km').val('Error loading data');
             }
          });
});
});
$(document).ready(function() {
    function calculateFastTagClosing() {
        // Get values from the input fields
        var fastTagOpening = parseFloat($('#fast_tag_opening').val()) || 0;
        var fastTagRecharge = parseFloat($('#fast_tag_recharge').val()) || 0;
        var fastTagUsed = parseFloat($('#fast_tag_used').val()) || 0;

        // Perform the calculation: fast_tag_closing = fast_tag_opening + fast_tag_recharge - fast_tag_used
        var fastTagClosing = fastTagOpening + fastTagRecharge - fastTagUsed;

        // Update the closing balance field
        $('#fast_tag_closing').val(fastTagClosing.toFixed(2));
    }

    function calculateFastTagUsed() {
        // Get values from the input fields
        var fastTagOpening = parseFloat($('#fast_tag_opening').val()) || 0;
        var fastTagRecharge = parseFloat($('#fast_tag_recharge').val()) || 0;
        var fastTagClosing = parseFloat($('#fast_tag_closing').val()) || 0;

        // Perform the calculation: fast_tag_used = fast_tag_opening + fast_tag_recharge - fast_tag_closing
        var fastTagUsed = fastTagOpening + fastTagRecharge - fastTagClosing;

        // Update the used balance field
        $('#fast_tag_used').val(fastTagUsed.toFixed(2));
    }

    // Trigger calculation on input change
    $('#fast_tag_recharge, #fast_tag_used').on('input', calculateFastTagClosing);
    $('#fast_tag_closing').on('input', calculateFastTagUsed);

    // If fast_tag_opening is updated dynamically via AJAX
    $('#truck_no').change(function() {
        var truck_no = $(this).val();

        $.ajax({
            type: 'POST',
            url: 'trip/get_last_fasttag_closing.php',
            data: { truck_no: truck_no },
            dataType: 'json',
            success: function(response) {
                if (response.fast_tag_opening) {
                    $('#fast_tag_opening').val(response.fast_tag_opening);
                    calculateFastTagClosing();  // Trigger calculation after updating opening balance
                } else {
                    $('#fast_tag_opening').val('0');
                    calculateFastTagClosing();
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.error('AJAX error: ', textStatus, errorThrown);
                $('#fast_tag_opening').val('Error loading data');
            }
        });
    });
});


function calculatesingleTotalKm() {
      var singlestartKm = parseFloat(document.getElementById('single_start_km').value) || 0;
      var singleendKm = parseFloat(document.getElementById('single_end_km').value) || 0;
      var singletotalKm = singleendKm - singlestartKm; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km').value = singletotalKm;

      var singlestartKm2 = parseFloat(document.getElementById('single_start_km2').value) || 0;
      var singleendKm2 = parseFloat(document.getElementById('single_end_km2').value) || 0;
      var singletotalKm2 = singleendKm2 - singlestartKm2; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km2').value = singletotalKm2;

      var singlestartKm3 = parseFloat(document.getElementById('single_start_km3').value) || 0;
      var singleendKm3 = parseFloat(document.getElementById('single_end_km3').value) || 0;
      var singletotalKm3 = singleendKm3 - singlestartKm3; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km3').value = singletotalKm3;

      var singlestartKm4 = parseFloat(document.getElementById('single_start_km4').value) || 0;
      var singleendKm4 = parseFloat(document.getElementById('single_end_km4').value) || 0;
      var singletotalKm4 = singleendKm4 - singlestartKm4; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km4').value = singletotalKm4;

      var singlestartKm5 = parseFloat(document.getElementById('single_start_km5').value) || 0;
      var singleendKm5 = parseFloat(document.getElementById('single_end_km5').value) || 0;
      var singletotalKm5 = singleendKm5 - singlestartKm5; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km5').value = singletotalKm5;

      var singlestartKm6 = parseFloat(document.getElementById('single_start_km6').value) || 0;
      var singleendKm6 = parseFloat(document.getElementById('single_end_km6').value) || 0;
      var singletotalKm6 = singleendKm6 - singlestartKm6; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km6').value = singletotalKm6;

      var singlestartKm7 = parseFloat(document.getElementById('single_start_km7').value) || 0;
      var singleendKm7 = parseFloat(document.getElementById('single_end_km7').value) || 0;
      var singletotalKm7 = singleendKm7 - singlestartKm7; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km7').value = singletotalKm7;

      var singlestartKm8 = parseFloat(document.getElementById('single_start_km8').value) || 0;
      var singleendKm8 = parseFloat(document.getElementById('single_end_km8').value) || 0;
      var singletotalKm8 = singleendKm8 - singlestartKm8; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km8').value = singletotalKm8;

      var singlestartKm9 = parseFloat(document.getElementById('single_start_km9').value) || 0;
      var singleendKm9 = parseFloat(document.getElementById('single_end_km9').value) || 0;
      var singletotalKm9 = singleendKm9 - singlestartKm9; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km9').value = singletotalKm9;

      var singlestartKm10 = parseFloat(document.getElementById('single_start_km10').value) || 0;
      var singleendKm10 = parseFloat(document.getElementById('single_end_km10').value) || 0;
      var singletotalKm10 = singleendKm10 - singlestartKm10; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km10').value = singletotalKm10;

      var singlestartKm11 = parseFloat(document.getElementById('single_start_km11').value) || 0;
      var singleendKm11 = parseFloat(document.getElementById('single_end_km11').value) || 0;
      var singletotalKm11 = singleendKm11 - singlestartKm11; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km11').value = singletotalKm11;

      var singlestartKm12 = parseFloat(document.getElementById('single_start_km12').value) || 0;
      var singleendKm12 = parseFloat(document.getElementById('single_end_km12').value) || 0;
      var singletotalKm12 = singleendKm12 - singlestartKm12; // Adjust this logic if 'total km' means the distance traveled
      document.getElementById('single_total_km12').value = singletotalKm12;

   }

function calculate_amount() {

     


   }

function fetchContractDetails(id) {
   const cNo = document.getElementById(id).value.trim();

   if (cNo) {
      $.ajax({
         type: 'POST',
         url: 'trip/get_contract.php',
         data: { c_no: cNo },
         dataType: 'json',
         success: function(data) {
            const index = id.split('_')[2];

            if (data.success) {
               document.getElementById(`from_place_${index}`).value = data.from_place;
               document.getElementById(`to_place_${index}`).value = data.to_place;
            } else {
               alert(data.message);
               document.getElementById(`from_place_${index}`).value = '';
               document.getElementById(`to_place_${index}`).value = '';
            }
         },
         error: function(jqXHR, textStatus, errorThrown) {
            console.error('Error:', textStatus, errorThrown);
         }
      });
   } else {
      alert('Ivalid Contract Number.');
   }
}




</script>