<?php 
include("../config.php");
if(!empty($_POST))
{
  $trip_no            = mysqli_real_escape_string($conn, $_POST['trip_no']);
  $trip_data            =  $_POST['product'];
  $date               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date'])));

  $from_place_1         = mysqli_real_escape_string($conn, $_POST['from_place_1']);
  $to_place_1         = mysqli_real_escape_string($conn, $_POST['to_place_1']);
  $date_1               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_1'])));
  $total_freight_1      = mysqli_real_escape_string($conn, $_POST['total_freight_1']);
  $advance_1     = mysqli_real_escape_string($conn, $_POST['advance_1']);

  $from_place_2         = mysqli_real_escape_string($conn, $_POST['from_place_2']);
  $to_place_2         = mysqli_real_escape_string($conn, $_POST['to_place_2']);
  $date_2               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_2'])));
  $total_freight_2      = mysqli_real_escape_string($conn, $_POST['total_freight_2']);
  $advance_2     = mysqli_real_escape_string($conn, $_POST['advance_2']);


  $from_place_3         = mysqli_real_escape_string($conn, $_POST['from_place_3']);
  $to_place_3         = mysqli_real_escape_string($conn, $_POST['to_place_3']);
  $date_3               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_3'])));
  $total_freight_3      = mysqli_real_escape_string($conn, $_POST['total_freight_3']);
  $advance_3     = mysqli_real_escape_string($conn, $_POST['advance_3']);


  $from_place_4         = mysqli_real_escape_string($conn, $_POST['from_place_4']);
  $to_place_4         = mysqli_real_escape_string($conn, $_POST['to_place_4']);
  $date_4               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_4'])));
  $total_freight_4      = mysqli_real_escape_string($conn, $_POST['total_freight_4']);
  $advance_4     = mysqli_real_escape_string($conn, $_POST['advance_4']);

  $from_place_5         = mysqli_real_escape_string($conn, $_POST['from_place_5']);
  $to_place_5         = mysqli_real_escape_string($conn, $_POST['to_place_5']);
  $date_5               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_5'])));
  $total_freight_5      = mysqli_real_escape_string($conn, $_POST['total_freight_5']);
  $advance_5     = mysqli_real_escape_string($conn, $_POST['advance_5']);

  $from_place_6         = mysqli_real_escape_string($conn, $_POST['from_place_6']);
  $to_place_6         = mysqli_real_escape_string($conn, $_POST['to_place_6']);
  $date_6               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_6'])));
  $total_freight_6      = mysqli_real_escape_string($conn, $_POST['total_freight_6']);
  $advance_6     = mysqli_real_escape_string($conn, $_POST['advance_6']);

  $single_start_km        = mysqli_real_escape_string($conn, $_POST['single_start_km']);
  $single_start_km2        = mysqli_real_escape_string($conn, $_POST['single_start_km2']);
  $single_start_km3        = mysqli_real_escape_string($conn, $_POST['single_start_km3']);
  $single_start_km4        = mysqli_real_escape_string($conn, $_POST['single_start_km4']);
  $single_start_km5        = mysqli_real_escape_string($conn, $_POST['single_start_km5']);
  $single_start_km6        = mysqli_real_escape_string($conn, $_POST['single_start_km6']);
  $single_end_km        = mysqli_real_escape_string($conn, $_POST['single_end_km']);
  $single_end_km2        = mysqli_real_escape_string($conn, $_POST['single_end_km2']);
  $single_end_km3        = mysqli_real_escape_string($conn, $_POST['single_end_km3']);
  $single_end_km4        = mysqli_real_escape_string($conn, $_POST['single_end_km4']);
  $single_end_km5        = mysqli_real_escape_string($conn, $_POST['single_end_km5']);
  $single_end_km6        = mysqli_real_escape_string($conn, $_POST['single_end_km6']);
  $single_total_km        = mysqli_real_escape_string($conn, $_POST['single_total_km']);
  $single_total_km2        = mysqli_real_escape_string($conn, $_POST['single_total_km2']);
  $single_total_km3        = mysqli_real_escape_string($conn, $_POST['single_total_km3']);
  $single_total_km4        = mysqli_real_escape_string($conn, $_POST['single_total_km4']);
  $single_total_km5        = mysqli_real_escape_string($conn, $_POST['single_total_km5']);
  $single_total_km6        = mysqli_real_escape_string($conn, $_POST['single_total_km6']);


  $from_place_7         = mysqli_real_escape_string($conn, $_POST['from_place_7']);
  $to_place_7         = mysqli_real_escape_string($conn, $_POST['to_place_7']);
  $date_7               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_7'])));
  $total_freight_7      = mysqli_real_escape_string($conn, $_POST['total_freight_7']);
  $advance_7     = mysqli_real_escape_string($conn, $_POST['advance_7']);

  $from_place_8         = mysqli_real_escape_string($conn, $_POST['from_place_8']);
  $to_place_8         = mysqli_real_escape_string($conn, $_POST['to_place_8']);
  $date_8               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_8'])));
  $total_freight_8      = mysqli_real_escape_string($conn, $_POST['total_freight_8']);
  $advance_8     = mysqli_real_escape_string($conn, $_POST['advance_8']);


  $from_place_9         = mysqli_real_escape_string($conn, $_POST['from_place_9']);
  $to_place_9           = mysqli_real_escape_string($conn, $_POST['to_place_9']);
  $date_9               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_9'])));
  $total_freight_9      = mysqli_real_escape_string($conn, $_POST['total_freight_9']);
  $advance_9            = mysqli_real_escape_string($conn, $_POST['advance_9']);


  $from_place_10         = mysqli_real_escape_string($conn, $_POST['from_place_10']);
  $to_place_10           = mysqli_real_escape_string($conn, $_POST['to_place_10']);
  $date_10               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_10'])));
  $total_freight_10      = mysqli_real_escape_string($conn, $_POST['total_freight_10']);
  $advance_10            = mysqli_real_escape_string($conn, $_POST['advance_10']);

  $from_place_11         = mysqli_real_escape_string($conn, $_POST['from_place_11']);
  $to_place_11         = mysqli_real_escape_string($conn, $_POST['to_place_11']);
  $date_11               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_11'])));
  $total_freight_11      = mysqli_real_escape_string($conn, $_POST['total_freight_11']);
  $advance_11     = mysqli_real_escape_string($conn, $_POST['advance_11']);

  $from_place_12         = mysqli_real_escape_string($conn, $_POST['from_place_12']);
  $to_place_12         = mysqli_real_escape_string($conn, $_POST['to_place_12']);
  $date_12               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['date_12'])));
  $total_freight_12      = mysqli_real_escape_string($conn, $_POST['total_freight_12']);
  $advance_12     = mysqli_real_escape_string($conn, $_POST['advance_12']);

  $c_no_1         = mysqli_real_escape_string($conn, $_POST['c_no_1']);
  $rate_1         = mysqli_real_escape_string($conn, $_POST['rate_1']);
  $amount_1      = mysqli_real_escape_string($conn, $_POST['amount_1']);

  $c_no_2         = mysqli_real_escape_string($conn, $_POST['c_no_2']);
  $rate_2         = mysqli_real_escape_string($conn, $_POST['rate_2']);
  $amount_2      = mysqli_real_escape_string($conn, $_POST['amount_2']);

  $c_no_3         = mysqli_real_escape_string($conn, $_POST['c_no_3']);
  $rate_3         = mysqli_real_escape_string($conn, $_POST['rate_3']);
  $amount_3      = mysqli_real_escape_string($conn, $_POST['amount_3']);

  $c_no_4         = mysqli_real_escape_string($conn, $_POST['c_no_4']);
  $rate_4         = mysqli_real_escape_string($conn, $_POST['rate_4']);
  $amount_4      = mysqli_real_escape_string($conn, $_POST['amount_4']);

  $c_no_5         = mysqli_real_escape_string($conn, $_POST['c_no_5']);
  $rate_5         = mysqli_real_escape_string($conn, $_POST['rate_5']);
  $amount_5      = mysqli_real_escape_string($conn, $_POST['amount_5']);

  $c_no_6         = mysqli_real_escape_string($conn, $_POST['c_no_6']);
  $rate_6         = mysqli_real_escape_string($conn, $_POST['rate_6']);
  $amount_6      = mysqli_real_escape_string($conn, $_POST['amount_6']);

  $c_no_7         = mysqli_real_escape_string($conn, $_POST['c_no_7']);
  $rate_7         = mysqli_real_escape_string($conn, $_POST['rate_7']);
  $amount_7      = mysqli_real_escape_string($conn, $_POST['amount_7']);

  $c_no_8         = mysqli_real_escape_string($conn, $_POST['c_no_8']);
  $rate_8         = mysqli_real_escape_string($conn, $_POST['rate_8']);
  $amount_8      = mysqli_real_escape_string($conn, $_POST['amount_8']);

  $c_no_9         = mysqli_real_escape_string($conn, $_POST['c_no_9']);
  $rate_9         = mysqli_real_escape_string($conn, $_POST['rate_9']);
  $amount_9      = mysqli_real_escape_string($conn, $_POST['amount_9']);

  $c_no_10         = mysqli_real_escape_string($conn, $_POST['c_no_10']);
  $rate_10         = mysqli_real_escape_string($conn, $_POST['rate_10']);
  $amount_10      = mysqli_real_escape_string($conn, $_POST['amount_10']);

  $c_no_11         = mysqli_real_escape_string($conn, $_POST['c_no_11']);
  $rate_11         = mysqli_real_escape_string($conn, $_POST['rate_11']);
  $amount_11      = mysqli_real_escape_string($conn, $_POST['amount_11']);

  $c_no_12         = mysqli_real_escape_string($conn, $_POST['c_no_12']);
  $rate_12         = mysqli_real_escape_string($conn, $_POST['rate_12']);
  $amount_12      = mysqli_real_escape_string($conn, $_POST['amount_12']);



  $single_start_km7        = mysqli_real_escape_string($conn, $_POST['single_start_km7']);
  $single_start_km8        = mysqli_real_escape_string($conn, $_POST['single_start_km8']);
  $single_start_km9        = mysqli_real_escape_string($conn, $_POST['single_start_km9']);
  $single_start_km10        = mysqli_real_escape_string($conn, $_POST['single_start_km10']);
  $single_start_km11        = mysqli_real_escape_string($conn, $_POST['single_start_km11']);
  $single_start_km12        = mysqli_real_escape_string($conn, $_POST['single_start_km12']);
  $single_end_km7         = mysqli_real_escape_string($conn, $_POST['single_end_km7']);
  $single_end_km8        = mysqli_real_escape_string($conn, $_POST['single_end_km8']);
  $single_end_km9        = mysqli_real_escape_string($conn, $_POST['single_end_km9']);
  $single_end_km10        = mysqli_real_escape_string($conn, $_POST['single_end_km10']);
  $single_end_km11        = mysqli_real_escape_string($conn, $_POST['single_end_km11']);
  $single_end_km12        = mysqli_real_escape_string($conn, $_POST['single_end_km12']);
  $single_total_km7        = mysqli_real_escape_string($conn, $_POST['single_total_km7']);
  $single_total_km8        = mysqli_real_escape_string($conn, $_POST['single_total_km8']);
  $single_total_km9        = mysqli_real_escape_string($conn, $_POST['single_total_km9']);
  $single_total_km10        = mysqli_real_escape_string($conn, $_POST['single_total_km10']);
  $single_total_km11        = mysqli_real_escape_string($conn, $_POST['single_total_km11']);
  $single_total_km12        = mysqli_real_escape_string($conn, $_POST['single_total_km12']);


  $truck_no           = mysqli_real_escape_string($conn, $_POST['truck_no']);
  $owner_name         = mysqli_real_escape_string($conn, $_POST['owner_name']);
  $owner_pan          = mysqli_real_escape_string($conn, $_POST['owner_pan']);
  $driver_id          = mysqli_real_escape_string($conn, $_POST['driver_id']);  
  $driver_lic_no      = mysqli_real_escape_string($conn, $_POST['driver_lic_no']);
  $driver_address     = mysqli_real_escape_string($conn, $_POST['driver_address']);
  $start_km           = mysqli_real_escape_string($conn, $_POST['start_km']);
  $end_km             = mysqli_real_escape_string($conn, $_POST['end_km']);
  $total_freight      = mysqli_real_escape_string($conn, $_POST['total_freight']);
  $advance_amount     = mysqli_real_escape_string($conn, $_POST['advance_amount']);
  $rate_per_km        = mysqli_real_escape_string($conn, $_POST['rate_per_km']);
  $total_km           = mysqli_real_escape_string($conn, $_POST['total_km']);
  $total_amount       = mysqli_real_escape_string($conn, $_POST['total_amount']);
  $expense_1          = mysqli_real_escape_string($conn, $_POST['expense_1']);
  $expense_2          = mysqli_real_escape_string($conn, $_POST['expense_2']);
  $expense_3          = mysqli_real_escape_string($conn, $_POST['expense_3']);
  $expense_4          = mysqli_real_escape_string($conn, $_POST['expense_4']);
  $expense_5          = mysqli_real_escape_string($conn, $_POST['expense_5']);
  $expense_6          = mysqli_real_escape_string($conn, $_POST['expense_6']);
  $remark_1           = mysqli_real_escape_string($conn, $_POST['remark_1']);
  $remark_2           = mysqli_real_escape_string($conn, $_POST['remark_2']);
  $remark_3           = mysqli_real_escape_string($conn, $_POST['remark_3']);
  $remark_4           = mysqli_real_escape_string($conn, $_POST['remark_4']);
  $remark_5           = mysqli_real_escape_string($conn, $_POST['remark_5']);
  $remark_6           = mysqli_real_escape_string($conn, $_POST['remark_6']);
  $fast_tag_opening           = mysqli_real_escape_string($conn, $_POST['fast_tag_opening']);
  $fast_tag_recharge           = mysqli_real_escape_string($conn, $_POST['fast_tag_recharge']);
  $fast_tag_used           = mysqli_real_escape_string($conn, $_POST['fast_tag_used']);
  $fast_tag_closing           = mysqli_real_escape_string($conn, $_POST['fast_tag_closing']);
  $recharge_date               = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['recharge_date'])));
  $extra_paid_to_driver           = mysqli_real_escape_string($conn, $_POST['extra_paid_to_driver']);
  $driver_remark           = mysqli_real_escape_string($conn, $_POST['driver_remark']);



  $product 		    = $_POST['product'];
  $company_id         = $_SESSION['company_id'];
  $branch_id          = $_SESSION['branch_id'];
  $created_id         = $_SESSION['user_detail']['id'];
  $created_datetime   = date('Y-m-d H:i:s');
  $updated_id         = $_SESSION['user_detail']['id'];
  $updated_datetime   = date('Y-m-d H:i:s');

  if($_POST["id"] == '')
  {
    $type      = 'trip_created';
    $user_id   = $_SESSION['user_detail']['id'];
    $data      = serialize($_POST);

    $insert = mysqli_query($conn, "INSERT INTO `trip`(
      `trip_no`, `date`, `from_place_1`, `to_place_1`, `date_1`, `total_freight_1`, `advance_1`, `truck_no`, 
      `from_place_2`, `to_place_2`, `date_2`, `total_freight_2`, `advance_2`, `owner_name`, `owner_pan`, 
      `from_place_3`, `to_place_3`, `date_3`, `total_freight_3`, `advance_3`, `driver_id`, `from_place_4`, 
      `to_place_4`, `date_4`, `total_freight_4`, `advance_4`, `driver_address`, `from_place_5`, `to_place_5`, 
      `date_5`, `total_freight_5`, `advance_5`, `driver_lic_no`, `from_place_6`, `to_place_6`, `date_6`, 
      `total_freight_6`, `advance_6`, `start_km`, `end_km`, `total_km`, `total_freight`, `advance_amount`, 
      `rate_per_km`, `total_amount`, `expense_1`, `expense_2`, `expense_3`, `expense_4`, `expense_5`, 
      `expense_6`, `remark_1`, `remark_2`, `remark_3`, `remark_4`, `remark_5`, `remark_6`, `company_id`, 
      `branch_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`, `fast_tag_opening`, 
      `fast_tag_recharge`, `fast_tag_used`, `fast_tag_closing`, `recharge_date`, `single_start_km`, 
      `single_start_km2`, `single_start_km3`, `single_start_km4`, `single_start_km5`, `single_start_km6`, 
      `single_end_km`, `single_end_km2`, `single_end_km3`, `single_end_km4`, `single_end_km5`, `single_end_km6`, 
      `single_total_km`, `single_total_km2`, `single_total_km3`, `single_total_km4`, `single_total_km5`, 
      `single_total_km6`, `extra_paid_to_driver`, `driver_remark`,`from_place_7`, `to_place_7`, `date_7`,
      `total_freight_7`, `advance_7`,`single_start_km7`,`single_end_km7`,`single_total_km7`,
      `from_place_8`, `to_place_8`, `date_8`,`total_freight_8`, `advance_8`,`single_start_km8`,
      `single_end_km8`,`single_total_km8`,`from_place_9`, `to_place_9`, `date_9`,
      `total_freight_9`, `advance_9`,`single_start_km9`,`single_end_km9`,`single_total_km9`,`from_place_10`, `to_place_10`, `date_10`,
      `total_freight_10`, `advance_10`,`single_start_km10`,`single_end_km10`,`single_total_km10`,`from_place_11`, `to_place_11`, `date_11`,
      `total_freight_11`, `advance_11`,`single_start_km11`,`single_end_km11`,`single_total_km11`,`from_place_12`, `to_place_12`, `date_12`,
      `total_freight_12`, `advance_12`,`single_start_km12`,`single_end_km12`,`single_total_km12`,`c_no_1`, `rate_1`, `amount_1`, `c_no_2`, `rate_2`, `amount_2`, `c_no_3`, `rate_3`, `amount_3`, `c_no_4`, `rate_4`, `amount_4`, `c_no_5`, `rate_5`, `amount_5`, `c_no_6`, `rate_6`, `amount_6`, `c_no_7`, `rate_7`, `amount_7`, `c_no_8`, `rate_8`, `amount_8`,`c_no_9`, `rate_9`, `amount_9`, `c_no_10`, `rate_10`, `amount_10`, `c_no_11`, `rate_11`, `amount_11`, `c_no_12`, `rate_12`, `amount_12`)
    VALUES (
      '".$trip_no."', '".$date."', '".$from_place_1."', '".$to_place_1."', '".$date_1."', '".$total_freight_1."', 
      '".$advance_1."', '".$truck_no."', '".$from_place_2."', '".$to_place_2."', '".$date_2."', '".$total_freight_2."', 
      '".$advance_2."', '".$owner_name."', '".$owner_pan."', '".$from_place_3."', '".$to_place_3."', '".$date_3."', 
      '".$total_freight_3."', '".$advance_3."', '".$driver_id."', '".$from_place_4."', '".$to_place_4."', '".$date_4."', 
      '".$total_freight_4."', '".$advance_4."', '".$driver_address."', '".$from_place_5."', '".$to_place_5."', '".$date_5."', 
      '".$total_freight_5."', '".$advance_5."', '".$driver_lic_no."', '".$from_place_6."', '".$to_place_6."', '".$date_6."', 
      '".$total_freight_6."', '".$advance_6."', '".$start_km."', '".$end_km."', '".$total_km."', '".$total_freight."', 
      '".$advance_amount."', '".$rate_per_km."', '".$total_amount."', '".$expense_1."', '".$expense_2."', '".$expense_3."', 
      '".$expense_4."', '".$expense_5."', '".$expense_6."', '".$remark_1."', '".$remark_2."', '".$remark_3."', '".$remark_4."', 
      '".$remark_5."', '".$remark_6."', '".$company_id."', '".$branch_id."', '".$created_id."', '".$created_datetime."', 
      '".$updated_id."', '".$updated_datetime."', '".$fast_tag_opening."', '".$fast_tag_recharge."', '".$fast_tag_used."', 
      '".$fast_tag_closing."', '".$recharge_date."', '".$single_start_km."', '".$single_start_km2."', '".$single_start_km3."', 
      '".$single_start_km4."', '".$single_start_km5."', '".$single_start_km6."', '".$single_end_km."', '".$single_end_km2."', 
      '".$single_end_km3."', '".$single_end_km4."', '".$single_end_km5."', '".$single_end_km6."', '".$single_total_km."', 
      '".$single_total_km2."', '".$single_total_km3."', '".$single_total_km4."', '".$single_total_km5."', '".$single_total_km6."', 
      '".$extra_paid_to_driver."', '".$driver_remark."','".$from_place_7."', '".$to_place_7."', '".$date_7."', '".$total_freight_7."', 
      '".$advance_7."','".$single_start_km7."','".$single_end_km7."','".$single_total_km7."','".$from_place_8."', '".$to_place_8."', '".$date_8."', '".$total_freight_8."', 
      '".$advance_8."','".$single_start_km8."','".$single_end_km8."','".$single_total_km8."','".$from_place_9."', '".$to_place_9."', '".$date_9."', '".$total_freight_9."', '".$advance_9."','".$single_start_km9."','".$single_end_km9."','".$single_total_km9."','".$from_place_10."', '".$to_place_10."', '".$date_10."', '".$total_freight_10."', '".$advance_10."','".$single_start_km10."','".$single_end_km10."','".$single_total_km10."','".$from_place_10."', '".$to_place_11."', '".$date_11."', '".$total_freight_11."', '".$advance_11."','".$single_start_km11."','".$single_end_km11."','".$single_total_km11."','".$from_place_12."', '".$to_place_12."', '".$date_12."', '".$total_freight_12."', '".$advance_12."','".$single_start_km12."','".$single_end_km12."','".$single_total_km12."', '".$c_no_1."', '".$rate_1."', '".$amount_1."', '".$c_no_2."', '".$rate_2."', '".$amount_2."', '".$c_no_3."', '".$rate_3."', '".$amount_3."', '".$c_no_4."', '".$rate_4."', '".$amount_4."', '".$c_no_5."', '".$rate_5."', '".$amount_5."', '".$c_no_6."', '".$rate_6."', '".$amount_6."', '".$c_no_7."', '".$rate_7."', '".$amount_7."', '".$c_no_8."', '".$rate_8."', '".$amount_8."', '".$c_no_9."', '".$rate_9."', '".$amount_9."', '".$c_no_10."', '".$rate_10."', '".$amount_10."', '".$c_no_11."', '".$rate_11."', '".$amount_11."', '".$c_no_12."', '".$rate_12."', '".$amount_12."')");

    $last_id = mysqli_insert_id($conn);
    if(count($product) > 0){

     foreach ($product as $key => $products) {
      if( isset($products['date']) && !empty($products['date'])) {
       $grid = mysqli_query($conn, "INSERT INTO `trip_detail`(`master_id`, `date`, `hamali`, `loading_unloading`, `cash_driver`,`bank_driver`, `toll`, `kata`, `border`, `battha`, `salary`, `diesel`,`diesel_rate`,`diesel_amount`, `maintance`, `tyre`, `electric`, `mechanic`, `police_rto`, `other`, `extra_height`, `extra_weight`) VALUES ('".$last_id."','".date('Y-m-d', strtotime($products['date']))."','".$products['hamali']."','".$products['loading_unloading']."','".$products['cash_driver']."','".$products['bank_driver']."','".$products['toll']."','".$products['kata']."','".$products['border']."','".$products['battha']."','".$products['salary']."','".$products['diesel']."','".$products['diesel_rate']."','".$products['diesel_amount']."','".$products['maintance']."','".$products['tyre']."','".$products['electric']."','".$products['mechanic']."','".$products['police_rto']."','".$products['other']."','".$products['extra_height']."','".$products['extra_weight']."')");
     }
   }
 }
 $gl_delete_bank = mysqli_query($conn, "DELETE FROM `bank_master` WHERE `trip_code` = '".$trip_no."' ");
 $gl_delete_bank_details = mysqli_query($conn, "DELETE FROM `bank_details` WHERE `trip_code` = '".$trip_no."' ");   

    $gl_delete_cash = mysqli_query($conn, "DELETE FROM `cash_master` WHERE `trip_code` = '".$trip_no."' ");   


    $gl_delete_cash_details = mysqli_query($conn, "DELETE FROM `cash_details` WHERE `trip_code` = '".$trip_no."' ");   
   
 $gl_delete = mysqli_query($conn, "DELETE FROM `general_ledger` WHERE `trip_code` = '".$trip_no."' ");   

if (count($trip_data)> 0) {
  foreach ($trip_data as $key => $trip_data) {
     $trip_date = date('Y-m-d',strtotime($trip_data['date']));
   if( isset($trip_data['cash_driver']) && !empty($trip_date) && !empty($trip_data['cash_driver']))
   {
    
    // $master_bank = combine(getAllRecords('act_master'), 'id', 'ac_name');
    $bank_remark = 'TRIP CASH';
    $voucher_no   = cpCode($conn);

    $get_cash = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = 'CASH IN HAND'");
    $get_cash_row = mysqli_fetch_assoc($get_cash);

    $driver = mysqli_query($conn, "SELECT * FROM `driver_mst` WHERE `id` = '".$driver_id."'");
    $driver_row = mysqli_fetch_assoc($driver);

    $get_driver = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = '".$driver_row['name']."'");
    $get_driver_row = mysqli_fetch_assoc($get_driver);

    $insert = mysqli_query($conn, "INSERT INTO `cash_master`(`voucher`, `date`, `cash_book`, `amount`, `status`, `remark`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`,`trip_code`) VALUES ('".$voucher_no."','".$trip_date."','".$get_cash_row['id']."','".$trip_data['cash_driver']."','PAYMENT','".$bank_remark."','".$branch_id."','".$company_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$update_datetime."','".$trip_no."')");

      $last_id = mysqli_insert_id($conn);

      $grid_insert = mysqli_query($conn, "INSERT INTO `cash_details`(`master_id`, `account_id`, `account_code`, `account_name`, `amount`,`trip_code`) VALUES ('".$last_id."','".$get_driver_row['id']."','".$get_driver_row['act_code']."','".$get_driver_row['ac_name']."','".$trip_data['cash_driver']."','".$trip_no."')");


    $gl = mysqli_query($conn, "INSERT INTO `general_ledger`(`voucher_no`, `trip_code`,`voucher_date`, `flag`, `credit_account`, `debit_account`, `amount`, `remark`, `checked`, `mark`, `net_amount`, `company_id`, `branch_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$voucher_no."','".$trip_no."','".$trip_date."','C','".$get_cash_row['act_code']."','".$get_driver_row['act_code']."','".$trip_data['cash_driver']."','".$bank_remark."','','TRIP CASH','".$trip_data['cash_driver']."','".$company_id."','".$branch_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')");
  }

  if( isset($trip_data['bank_driver']) && !empty($trip_date) && !empty($trip_data['bank_driver']))
  {
    // $master_bank = combine(getAllRecords('act_master'), 'id', 'ac_name');
    $bank_remark = 'TRIP BANK';
    $voucher_no   = bpCode($conn);

    $get_bank = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = 'AXIS BANK LTD'");
    $get_bank_row = mysqli_fetch_assoc($get_bank);

    $driver = mysqli_query($conn, "SELECT * FROM `driver_mst` WHERE `id` = '".$driver_id."'");
    $driver_row = mysqli_fetch_assoc($driver);

    $get_driver = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = '".$driver_row['name']."'");
    $get_driver_row = mysqli_fetch_assoc($get_driver);

    $insert_bank = mysqli_query($conn, "INSERT INTO `bank_master`(`voucher`, `date`, `bank_book`, `transaction_type`, `transaction_ref`, `amount`, `status`, `remark`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`,`trip_code`) VALUES ('".$voucher_no."','".$trip_date."','".$get_bank_row['id']."','NEFT','','".$trip_data['bank_driver']."','PAYMENT','".$bank_remark."','".$branch_id."','".$company_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$update_datetime."','".$trip_no."')");

      $last_id = mysqli_insert_id($conn);

      $grid_insert = mysqli_query($conn, "INSERT INTO `bank_details`(`master_id`, `account_id`, `account_code`, `account_name`, `amount`,`trip_code`) VALUES ('".$last_id."','".$get_driver_row['id']."','".$get_driver_row['act_code']."','".$get_driver_row['ac_name']."','".$trip_data['bank_driver']."','".$trip_no."')");

    $gl = mysqli_query($conn, "INSERT INTO `general_ledger`(`voucher_no`, `trip_code`,`voucher_date`, `flag`, `credit_account`, `debit_account`, `amount`, `remark`, `checked`, `mark`, `net_amount`, `company_id`, `branch_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$voucher_no."','".$trip_no."','".$trip_date."','B','".$get_bank_row['act_code']."','".$get_driver_row['act_code']."','".$trip_data['bank_driver']."','".$bank_remark."','','TRIP BANK','".$trip_data['bank_driver']."','".$company_id."','".$branch_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')");
  }

  if( isset($trip_data['other']) && !empty($trip_date) && !empty($trip_data['other']))
  {
    // $master_bank = combine(getAllRecords('act_master'), 'id', 'ac_name');
    $bank_remark = 'FAST TAG RECHARGE';
    $voucher_no   = bpCode($conn);

    $get_bank = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = 'AXIS BANK LTD'");
    $get_bank_row = mysqli_fetch_assoc($get_bank);

    $get_truck = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = '$truck_no'");
    $get_truck_row = mysqli_fetch_assoc($get_truck);

    $insert_bank = mysqli_query($conn, "INSERT INTO `bank_master`(`voucher`, `date`, `bank_book`, `transaction_type`, `transaction_ref`, `amount`, `status`, `remark`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`,`trip_code`) VALUES ('".$voucher_no."','".$trip_date."','".$get_bank_row['id']."','NEFT','','".$trip_data['other']."','PAYMENT','".$bank_remark."','".$branch_id."','".$company_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$update_datetime."','".$trip_no."')");

      $last_id = mysqli_insert_id($conn);

      $grid_insert = mysqli_query($conn, "INSERT INTO `bank_details`(`master_id`, `account_id`, `account_code`, `account_name`, `amount`,`trip_code`) VALUES ('".$last_id."','".$get_driver_row['id']."','".$get_driver_row['act_code']."','".$get_driver_row['ac_name']."','".$trip_data['other']."','".$trip_no."')");

    $gl = mysqli_query($conn, "INSERT INTO `general_ledger`(`voucher_no`, `trip_code`,`voucher_date`, `flag`, `credit_account`, `debit_account`, `amount`, `remark`, `checked`, `mark`, `net_amount`, `company_id`, `branch_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$voucher_no."','".$trip_no."','".$trip_date."','B','".$get_bank_row['act_code']."','".$get_truck_row['act_code']."','".$trip_data['other']."','".$bank_remark."','','FAST TAG RECHARGE','".$trip_data['other']."','".$company_id."','".$branch_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')");
  }

}
}
 $activity = mysqli_query($conn, "INSERT INTO `activities`(`type`, `user_id`, `data`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$type."','".$user_id."','".$data."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')");
}else{
  $type      = 'trip_updated';
  $user_id   = $_SESSION['user_detail']['id'];
  $data      = serialize($_POST);

  $delete = mysqli_query($conn, "DELETE FROM `trip_detail` WHERE `master_id` = '".$_POST['id']."'");

  $update = mysqli_query($conn, "UPDATE `trip` SET `date`='".$date."',`from_place_1`='".$from_place_1."',`to_place_1`='".$to_place_1."',`date_1`='".$date_1."',`total_freight_1`='".$total_freight_1."',`advance_1`='".$advance_1."',`truck_no`='".$truck_no."',`from_place_2`='".$from_place_2."',`to_place_2`='".$to_place_2."',`date_2`='".$date_2."',`total_freight_2`='".$total_freight_2."',`advance_2`='".$advance_2."',`owner_name`='".$owner_name."',`owner_pan`='".$owner_pan."',`from_place_3`='".$from_place_3."',`to_place_3`='".$to_place_3."',`date_3`='".$date_3."',`total_freight_3`='".$total_freight_3."',`advance_3`='".$advance_3."',`driver_id`='".$driver_id."',`from_place_4`='".$from_place_4."',`to_place_4`='".$to_place_4."',`date_4`='".$date_4."',`total_freight_4`='".$total_freight_4."',`advance_4`='".$advance_4."',`driver_address`='".$driver_address."',`from_place_5`='".$from_place_5."',`to_place_5`='".$to_place_5."',`date_5`='".$date_5."',`total_freight_5`='".$total_freight_5."',`advance_5`='".$advance_5."',`driver_lic_no`='".$driver_lic_no."',`from_place_6`='".$from_place_6."',`to_place_6`='".$to_place_6."',`date_6`='".$date_6."',`total_freight_6`='".$total_freight_6."',`advance_6`='".$advance_6."',`start_km`='".$start_km."',`end_km`='".$end_km."',`total_km`='".$total_km."',`total_freight`='".$total_freight."',`advance_amount`='".$advance_amount."',`rate_per_km`='".$rate_per_km."',`total_amount`='".$total_amount."',`expense_1`='".$expense_1."',`expense_2`='".$expense_2."',`expense_3`='".$expense_3."',`expense_4`='".$expense_4."',`expense_5`='".$expense_5."',`expense_6`='".$expense_6."',`remark_1`='".$remark_1."',`remark_2`='".$remark_2."',`remark_3`='".$remark_3."',`remark_4`='".$remark_4."',`remark_5`='".$remark_5."',`remark_6`='".$remark_6."',`updated_id`='".$updated_id."',`updated_datetime`='".$updated_datetime."',`fast_tag_opening`='".$fast_tag_opening."',`fast_tag_recharge`='".$fast_tag_recharge."',`fast_tag_used`='".$fast_tag_used."',`fast_tag_closing`='".$fast_tag_closing."',`recharge_date`='".$recharge_date."',`single_start_km`='".$single_start_km."',`single_start_km2`='".$single_start_km2."',`single_start_km3`='".$single_start_km3."',`single_start_km4`='".$single_start_km4."',`single_start_km5`='".$single_start_km5."',`single_start_km6`='".$single_start_km6."',`single_end_km`='".$single_end_km."',`single_end_km2`='".$single_end_km2."',`single_end_km3`='".$single_end_km3."',`single_end_km4`='".$single_end_km4."',`single_end_km5`='".$single_end_km5."',`single_end_km6`='".$single_end_km6."',`single_total_km`='".$single_total_km."',`single_total_km2`='".$single_total_km2."',`single_total_km3`='".$single_total_km3."',`single_total_km4`='".$single_total_km4."',`single_total_km5`='".$single_total_km5."',`single_total_km6`='".$single_total_km6."',`extra_paid_to_driver`='".$extra_paid_to_driver."',`driver_remark`='".$driver_remark."'
    ,`from_place_7`='".$from_place_7."',`to_place_7`='".$to_place_7."',`date_7`='".$date_7."',`total_freight_7`='".$total_freight_7."',`advance_7`='".$advance_7."',`single_start_km7`='".$single_start_km7."',`single_end_km7`='".$single_end_km7."',`single_total_km7`='".$single_total_km7."'
    ,`from_place_8`='".$from_place_8."',`to_place_8`='".$to_place_8."',`date_8`='".$date_8."',`total_freight_8`='".$total_freight_8."',`advance_8`='".$advance_8."',`single_start_km8`='".$single_start_km8."',`single_end_km8`='".$single_end_km8."',`single_total_km8`='".$single_total_km8."'
    ,`from_place_9`='".$from_place_9."',`to_place_9`='".$to_place_9."',`date_9`='".$date_9."',`total_freight_9`='".$total_freight_9."',`advance_7`='".$advance_9."',`single_start_km9`='".$single_start_km9."',`single_end_km9`='".$single_end_km9."',`single_total_km9`='".$single_total_km9."'
    ,`from_place_10`='".$from_place_10."',`to_place_10`='".$to_place_10."',`date_10`='".$date_10."',`total_freight_10`='".$total_freight_10."',`advance_7`='".$advance_10."',`single_start_km10`='".$single_start_km10."',`single_end_km10`='".$single_end_km10."',`single_total_km10`='".$single_total_km10."'
    ,`from_place_11`='".$from_place_11."',`to_place_11`='".$to_place_11."',`date_11`='".$date_11."',`total_freight_11`='".$total_freight_11."',`advance_11`='".$advance_11."',`single_start_km11`='".$single_start_km11."',`single_end_km11`='".$single_end_km11."',`single_total_km11`='".$single_total_km11."'
    ,`from_place_12`='".$from_place_12."',`to_place_12`='".$to_place_12."',`date_12`='".$date_12."',`total_freight_12`='".$total_freight_12."',`advance_12`='".$advance_12."',`single_start_km12`='".$single_start_km12."',`single_end_km12`='".$single_end_km12."',`single_total_km12`='".$single_total_km12."',`c_no_1`='".$c_no_1."',`rate_1`='".$rate_1."',`amount_1`='".$amount_1."',`c_no_2`='".$c_no_2."',`rate_2`='".$rate_2."',`amount_2`='".$amount_2."',`c_no_3`='".$c_no_3."',`rate_3`='".$rate_3."',`amount_3`='".$amount_3."',`c_no_4`='".$c_no_4."',`rate_4`='".$rate_4."',`amount_4`='".$amount_4."',`c_no_5`='".$c_no_5."',`rate_5`='".$rate_5."',`amount_5`='".$amount_5."',`c_no_6`='".$c_no_6."',`rate_6`='".$rate_6."',`amount_6`='".$amount_6."',`c_no_7`='".$c_no_7."',`rate_7`='".$rate_7."',`amount_7`='".$amount_7."',`c_no_8`='".$c_no_8."',`rate_8`='".$rate_8."',`amount_8`='".$amount_8."',`c_no_9`='".$c_no_9."',`rate_9`='".$rate_9."',`amount_9`='".$amount_9."',`c_no_10`='".$c_no_10."',`rate_10`='".$rate_10."',`amount_10`='".$amount_10."',`c_no_11`='".$c_no_11."',`rate_11`='".$rate_11."',`amount_11`='".$amount_11."',`c_no_12`='".$c_no_12."',`rate_12`='".$rate_12."',`amount_12`='".$amount_12."' WHERE id = '".$_POST['id']."'");

  $last_id = $_POST['id'];

  if(count($product) > 0){
   foreach ($product as $key => $products) {
    if( isset($products['date']) && !empty($products['date'])) {
     $grid = mysqli_query($conn, "INSERT INTO `trip_detail`(`master_id`, `date`, `hamali`, `loading_unloading`, `cash_driver`,`bank_driver`, `toll`, `kata`, `border`, `battha`, `salary`, `diesel`,`diesel_rate`,`diesel_amount`, `maintance`, `tyre`, `electric`, `mechanic`, `police_rto`, `other`, `extra_height`, `extra_weight`) VALUES ('".$last_id."','".date('Y-m-d', strtotime($products['date']))."','".$products['hamali']."','".$products['loading_unloading']."','".$products['cash_driver']."','".$products['bank_driver']."','".$products['toll']."','".$products['kata']."','".$products['border']."','".$products['battha']."','".$products['salary']."','".$products['diesel']."','".$products['diesel_rate']."','".$products['diesel_amount']."','".$products['maintance']."','".$products['tyre']."','".$products['electric']."','".$products['mechanic']."','".$products['police_rto']."','".$products['other']."','".$products['extra_height']."','".$products['extra_weight']."')");
   }
 }
}

$gl_delete_bank = mysqli_query($conn, "DELETE FROM `bank_master` WHERE `trip_code` = '".$trip_no."' ");
 $gl_delete_bank_details = mysqli_query($conn, "DELETE FROM `bank_details` WHERE `trip_code` = '".$trip_no."' ");   

    $gl_delete_cash = mysqli_query($conn, "DELETE FROM `cash_master` WHERE `trip_code` = '".$trip_no."' ");   


    $gl_delete_cash_details = mysqli_query($conn, "DELETE FROM `cash_details` WHERE `trip_code` = '".$trip_no."' ");   
    
$gl_delete = mysqli_query($conn, "DELETE FROM `general_ledger` WHERE `trip_code` = '".$trip_no."' ");   

if (count($trip_data)> 0) {
  foreach ($trip_data as $key => $trip_data) {
   $trip_date = date('Y-m-d',strtotime($trip_data['date']));
   if( isset($trip_data['cash_driver']) && !empty($trip_date) && !empty($trip_data['cash_driver']))
   {

    // $master_bank = combine(getAllRecords('act_master'), 'id', 'ac_name');
    $bank_remark = 'TRIP CASH';
    $voucher_no   = cpCode($conn);

    $get_cash = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = 'CASH IN HAND'");
    $get_cash_row = mysqli_fetch_assoc($get_cash);

    $driver = mysqli_query($conn, "SELECT * FROM `driver_mst` WHERE `id` = '".$driver_id."'");
    $driver_row = mysqli_fetch_assoc($driver);

    $get_driver = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = '".$driver_row['name']."'");
    $get_driver_row = mysqli_fetch_assoc($get_driver);

    $insert = mysqli_query($conn, "INSERT INTO `cash_master`(`voucher`, `date`, `cash_book`, `amount`, `status`, `remark`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`,`trip_code`) VALUES ('".$voucher_no."','".$trip_date."','".$get_cash_row['id']."','".$trip_data['cash_driver']."','PAYMENT','".$bank_remark."','".$branch_id."','".$company_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$update_datetime."','".$trip_no."')");

      $last_id = mysqli_insert_id($conn);

      $grid_insert = mysqli_query($conn, "INSERT INTO `cash_details`(`master_id`, `account_id`, `account_code`, `account_name`, `amount`,`trip_code`) VALUES ('".$last_id."','".$get_driver_row['id']."','".$get_driver_row['act_code']."','".$get_driver_row['ac_name']."','".$trip_data['cash_driver']."','".$trip_no."')");


        $gl = mysqli_query($conn, "INSERT INTO `general_ledger`(`voucher_no`, `trip_code`,`voucher_date`, `flag`, `credit_account`, `debit_account`, `amount`, `remark`, `checked`, `mark`, `net_amount`, `company_id`, `branch_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$voucher_no."','".$trip_no."','".$trip_date."','C','".$get_cash_row['act_code']."','".$get_driver_row['act_code']."','".$trip_data['cash_driver']."','".$bank_remark."','','TRIP CASH','".$trip_data['cash_driver']."','".$company_id."','".$branch_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')");
      }

      if( isset($trip_data['bank_driver']) && !empty($trip_date) && !empty($trip_data['bank_driver']))
      {
    // $master_bank = combine(getAllRecords('act_master'), 'id', 'ac_name');
        $bank_remark = 'TRIP BANK';
        $voucher_no   = bpCode($conn);

        $get_bank = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = 'AXIS BANK LTD'");
        $get_bank_row = mysqli_fetch_assoc($get_bank);

        $driver = mysqli_query($conn, "SELECT * FROM `driver_mst` WHERE `id` = '".$driver_id."'");
        $driver_row = mysqli_fetch_assoc($driver);

        $get_driver = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = '".$driver_row['name']."'");
        $get_driver_row = mysqli_fetch_assoc($get_driver);

        $insert_bank = mysqli_query($conn, "INSERT INTO `bank_master`(`voucher`, `date`, `bank_book`, `transaction_type`, `transaction_ref`, `amount`, `status`, `remark`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`,`trip_code`) VALUES ('".$voucher_no."','".$trip_date."','".$get_bank_row['id']."','NEFT','','".$trip_data['bank_driver']."','PAYMENT','".$bank_remark."','".$branch_id."','".$company_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$update_datetime."','".$trip_no."')");

          $last_id = mysqli_insert_id($conn);

          $grid_insert = mysqli_query($conn, "INSERT INTO `bank_details`(`master_id`, `account_id`, `account_code`, `account_name`, `amount`,`trip_code`) VALUES ('".$last_id."','".$get_driver_row['id']."','".$get_driver_row['act_code']."','".$get_driver_row['ac_name']."','".$trip_data['bank_driver']."','".$trip_no."')");

            $gl = mysqli_query($conn, "INSERT INTO `general_ledger`(`voucher_no`, `trip_code`,`voucher_date`, `flag`, `credit_account`, `debit_account`, `amount`, `remark`, `checked`, `mark`, `net_amount`, `company_id`, `branch_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$voucher_no."','".$trip_no."','".$trip_date."','B','".$get_bank_row['act_code']."','".$get_driver_row['act_code']."','".$trip_data['bank_driver']."','".$bank_remark."','','TRIP BANK','".$trip_data['bank_driver']."','".$company_id."','".$branch_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')");
          }

          if( isset($trip_data['other']) && !empty($trip_date) && !empty($trip_data['other']))
          {
            // $master_bank = combine(getAllRecords('act_master'), 'id', 'ac_name');
            $bank_remark = 'FAST TAG RECHARGE';
            $voucher_no   = bpCode($conn);

            $get_bank = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = 'AXIS BANK LTD'");
            $get_bank_row = mysqli_fetch_assoc($get_bank);

            $get_truck = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `ac_name` = '$truck_no'");
            $get_truck_row = mysqli_fetch_assoc($get_truck);

            $insert_bank = mysqli_query($conn, "INSERT INTO `bank_master`(`voucher`, `date`, `bank_book`, `transaction_type`, `transaction_ref`, `amount`, `status`, `remark`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`,`trip_code`) VALUES ('".$voucher_no."','".$trip_date."','".$get_bank_row['id']."','NEFT','','".$trip_data['other']."','PAYMENT','".$bank_remark."','".$branch_id."','".$company_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$update_datetime."','".$trip_no."')");

              $last_id = mysqli_insert_id($conn);

              $grid_insert = mysqli_query($conn, "INSERT INTO `bank_details`(`master_id`, `account_id`, `account_code`, `account_name`, `amount`,`trip_code`) VALUES ('".$last_id."','".$get_driver_row['id']."','".$get_driver_row['act_code']."','".$get_driver_row['ac_name']."','".$trip_data['other']."','".$trip_no."')");

                $gl = mysqli_query($conn, "INSERT INTO `general_ledger`(`voucher_no`, `trip_code`,`voucher_date`, `flag`, `credit_account`, `debit_account`, `amount`, `remark`, `checked`, `mark`, `net_amount`, `company_id`, `branch_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$voucher_no."','".$trip_no."','".$trip_date."','B','".$get_bank_row['act_code']."','".$get_truck_row['act_code']."','".$trip_data['other']."','".$bank_remark."','','FAST TAG RECHARGE','".$trip_data['other']."','".$company_id."','".$branch_id."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')");
              }
            }
          }


          $activity = mysqli_query($conn, "INSERT INTO `activities`(`type`, `user_id`, `data`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$type."','".$user_id."','".$data."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')");
        }
        echo json_encode( array('response' => 1, 'msg' => 'DATA SAVED SUCCESSFULLY....!!!', 'alert' => 1, 'redirect' => 'index.php?page=trip/list.php') );die();
      }else{
       echo json_encode( array('response' => 2, 'msg' => 'Opps', 'alert' => 1, 'redirect' => 'index.php?page=trip/manage.php') );die();
     }
   ?>