<?php
include 'connection.php';

date_default_timezone_set('Asia/Calcutta');
$today = date("Y-m-d");
$time = date("h:i A"); 
$currentyear = date("Y");

?>
<? 		
$query2job = "select * from check_month";
$resultjob = mysql_query($query2job,$conn);
while($rowmonth=mysql_fetch_array($resultjob))

{
$check_month = $rowmonth['check_month'];
 }
								   
													   							  
$month1=date("m");
if($month1>$check_month)
  {
  $currentyear = date("Y");
 $curr_full_year=date("Y");
$curr_short_year=date("y");
$future=$curr_short_year+1;
} else {
$currentyear1 = date("Y");
$currentyear = $currentyear1-1;
$curr_full_year1=date("Y");
 $curr_full_year=$curr_full_year1-1;
 $curr_short_year1=date("y");

$curr_short_year=$curr_short_year1-1;
$future=$curr_short_year+1;
}
?>


<?   $curr_fy=$currentyear .'-'. $future;?>
<?  $short_year=$curr_short_year .'-'. $future; ?>

<?php
$currentmonth = date("m");

if($currentmonth>$check_month) { 
$cuyear = date("y");
$cuyear1 = date("y")+1;

} else { 
$cuyear = date("y")-1;
$cuyear1 =  date("y");
 } 
$fy_short_year = "$cuyear"."-"."$cuyear1";
?>



<?php

 
			$query2c = "select * from main_job_details where main_id='".$_REQUEST['main_id']."'";
		                 				$result2c = mysql_query($query2c,$conn);	
										while($row = mysql_fetch_array($result2c)){
													 $main_job_no = $row['main_job_no'];
													 $main_id = $row['main_id'];
													 $customer_id=$row['customer_id'];
													  $customer_name=$row['customer_name'];
													  $inv_type=$row['inv_type'];
												}
												
$customer_id = $_POST['customer_id'];
//$inv_type = $_POST['inv_type'];
$trans_inv_date = $_POST['trans_inv_date'];
$transport_name = $_POST['transport_name'];
$challan_id = $_POST['challan_id'];
$main_id=$_REQUEST['main_id'];
$query2tm = "select * from transport_master where transport_id = '$transport_name'";
$result2tm = mysql_query($query2tm,$conn);	
while($row = mysql_fetch_array($result2tm))
{
$short_form = $row['short_form'];
}


?>


<?php

$challan_id_p=$_POST['challan_id'];
    $challan_id=implode(',',$challan_id_p);
	
	$query2 = "select * from  challan_master where challan_id='$challan_id'";
			//echo $query2;
$result2 = mysql_query($query2,$conn);	
while($row=mysql_fetch_array($result2))
{

$challan_no_book= $row['challan_no_book'];
$delivery_date= $row['delivery_date'];
}
$gst_inv_type=$_POST['gst_inv_type'];
$query2 = "select * from customer_master where customer_id = '".$_REQUEST['customer_id']."'";
$result2 = mysql_query($query2,$conn);	
while($row = mysql_fetch_array($result2))
{
$billing_address = $row['billing_address'];
$bgst_no = $row['bgst_no'];
$customer_name = $row['customer_name'];
$bstate_code = $row['bstate_code'];

}
$queryls1 = "select * from transport_master where trans_auto_no!='' and short_form='$short_form' and f_year ='$fy_short_year'";
//echo $queryls1;
$resultls1 = mysql_query($queryls1,$conn);	
$num_rows3t = mysql_num_rows($resultls1);
if($num_rows3t =='0') { 
$trans_auto_no1 = 0;
$trans_auto_no_new=$trans_auto_no1+1;
$cont_seriesa= sprintf("%04d", $trans_auto_no_new);
} 
else 
{
$queryls1 = "select * from transport_master where trans_auto_no!='' and short_form='$short_form' and f_year ='$fy_short_year'";
//echo $queryls1;
$resultls1 = mysql_query($queryls1,$conn);	
while($row=mysql_fetch_array($resultls1))
{
$trans_auto_no = $row['trans_auto_no'];
}
$trans_auto_no_new=$trans_auto_no+1;
$cont_seriesa= sprintf("%04d", $trans_auto_no_new);
}
if($short_form=='DGK' or $short_form=='SPM'){
$trans_inv_no=$short_form.'/'.$cont_seriesa.'/'. $fy_short_year;
}
if($short_form=='HSC' or $short_form=='SE'){
$trans_inv_no=$cont_seriesa.'/'. $fy_short_year;
}         
if($short_form=='SMCL' or $short_form=='PSGR' or $short_form=='TCS'or $short_form=='SMPL'){
$trans_inv_no=$short_form.'/'.$inv_type.'/'.$cont_seriesa.'/'. $fy_short_year;
}
//echo $trans_inv_no;
//exit();
$query2b2 = "select * from transport_master where trans_auto_no = '$trans_auto_no_new' and f_year ='$fy_short_year' and short_form='$short_form'";

$result2b2 = mysql_query($query2b2,$conn);	
$num_rowsb2 = mysql_num_rows($result2b2); 
if($num_rowsb2=='0') { 
$query14T = "update transport_master set trans_auto_no='$trans_auto_no_new',trans_inv_no='$trans_inv_no',f_year='$fy_short_year' where short_form='$short_form'";
$r14T=mysql_query($query14T,$conn); 
}

$advance=$_POST['advance'];

$qrytrans = "insert into tax_transtax(trans_inv_no,trans_inv_date,customer_id,inv_type,customer_name,entry_date,entry_time,challan_id,main_id,main_job_no,gst_inv_type,bstate_code,bgst_no,advance,challan_no_book,delivery_date) values ('$trans_inv_no','$trans_inv_date','$customer_id','$inv_type','$customer_name','$today','$time','$challan_id','$main_id','$main_job_no','$gst_inv_type','$bstate_code','$bgst_no','$advance','$challan_no_book','$delivery_date')";
//echo $qrytrans;
$restrans=mysql_query($qrytrans,$conn);
 
$person_to_contact2 = explode(",", $challan_id);
foreach ($person_to_contact2 as $challan_id)
{
$query14T = "update challan_master set trans_inv_date='$trans_inv_date',trans_inv_no='$trans_inv_no' where challan_id='$challan_id'";
$r14T=mysql_query($query14T,$conn); 
}
?>

<script>
javascript:window.location.href="direct_transport_inv.php?customer_id=<?php echo $customer_id?>&&main_id=<?php echo $_REQUEST['main_id']?>&&trans_inv_date=<?php echo $trans_inv_date?>&&transport_name=<?php echo $transport_name?>&&trans_inv_no=<?php echo $trans_inv_no?>&&short_form=<?php echo $short_form?>";
</script>