<?php 
include "config.php";
include "financial_year_calculation.php";
include "current_date_time.php";
session_start();
$user=$_SESSION['log'];
$ticket = $_POST['ticket'];
$vehicleno = $_POST['vehicleno'];
$chakka = $_POST['chakka'];
$limit = $_POST['limitvalue'];
$customer = $_POST['customer'];
$product = $_POST['product'];
$load_type = $_POST['weight'];
$emptyweight = $_POST['emptyweight'];
$vehicle_capacity = $_POST['vehiclecapacity'];
$remark = $_POST['remark'];
$date = (empty($_POST['datetkt'])?$cur_date:$_POST['datetkt']);
$time =(empty($_POST['timetkt'])?$cur_time:$_POST['timetkt']);
$delivery = $_POST['delivery'];
$block_date=$_POST['blockdate'];
$ori_capacity=$_POST['oricapacity'];
$trip_no=$_POST['tripno'];
$modetrans=$_POST['modetrans'];
$upi_number=$_POST['upi_number'];
echo $date;
echo $time;
$accountyear    = $financialYearStart."-".$financialYearEnd;
echo $vehicleno;

              error_reporting(0);
              $code = mysqli_query($connect,"select count(id) as count from ticket where status !='deleted'&& financialyear ='$accountyear'");
              while($row=mysqli_fetch_array($code))
              {
                $codsin = mysqli_query($connect,"select count(id) as count from single_transaction where status !='deleted'&& financialyear ='$accountyear' ");
              while($roww=mysqli_fetch_array($codsin))
              {
                $code = $row['count'];
                $codsin = $roww['count'];
                  $codee = $code + $codsin;
                  $year_code=substr($financialYearEnd,2);
                  $codeco = $year_code."-". ($codee+1);
              }}
              $code_validate = mysqli_query($connect,"select count(ticket) as code from ticket where ticket='T$codeco' && status!='deleted'");
              $code_count=mysqli_fetch_assoc($code_validate);
              $code_val = $code_count['code'];
              if($code_val==0)
              {
//foreach ($productcode as $id => $value ){
$sql = "INSERT INTO ticket(ticket, vehicleno, customer, limitvalue, product, loadtype,emptyweight,cft,ori_cft,tripno,chakka,remarks, date, time, delivery,modetrans,upi_number,blockdate,editby, editdate, edittime, status, financialyear, process,syncdata) VALUES ('T$codeco','$vehicleno','$customer','$limit','$product','$load_type','$emptyweight','$vehicle_capacity','$ori_capacity','$trip_no','$chakka','$remark','$date','$time','$delivery','-','-','$block_date','$user','','','','$accountyear','','0')";
echo $sql;
 $go = mysqli_query($connect,$sql);
 }
 //header('Location:ticket.php');

?>
<html>
  <script>
     let folderName = '<?php echo $folder_name ?>';
     window.open("billslipticket.php?print=<?php echo $ticket ?>","OriginalWindowa40",'width=722,height=950,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,left=25,top=25');
	let srcVariable=`${window.location.origin}/${folderName}/ticket.php`;
	 window.location.href = srcVariable;
  </script>
</html>
