<?php
error_reporting(0);
include("../../include/db.php");

function get_jobtype($job_card_no)
{
	 	$sql_user="select *	from  jobcard_main where jobcard_no='$job_card_no'";
		$rs_user=mysql_query($sql_user);
			while($rsdata_user=mysql_fetch_object($rs_user))
			{ 
			$job_type=$rsdata_user->job_type;
			}
return $job_type;
	
}
function get_job_types($job_card_no)
{
	 	$sql_user="select *	from  jobcard_main where jobcard_no='$job_card_no'";
		$rs_user=mysql_query($sql_user);
			while($rsdata_user=mysql_fetch_object($rs_user))
			{ 
			$job_type=$rsdata_user->job_type;
			}
return $job_type;
}

function get_fabricstype($job_card_no)
{
	 	$sql_user="select *	from  jobcard_main where jobcard_no='$job_card_no'";
		$rs_user=mysql_query($sql_user);
			while($rsdata_user=mysql_fetch_object($rs_user))
			{ 
			$fabric_type=$rsdata_user->fabric_type;
			}
return $fabric_type;
}

if($_POST['action']=="delete_porforma_invoice")
{ 
 $sql="select * from fusing_production_main where invoice_no='$_POST[invoice_no]' and p_id='$_POST[p_id]' and billing_type='$_POST[billing_type]' ";
$rs=mysql_query($sql);
while($rsdata=mysql_fetch_array($rs))
{
$job_card_no=$rsdata['job_card_no'];
$print_date=$rsdata['print_date'];
$cust_name=$rsdata['cust_name'];
$job_created=$rsdata['job_created'];
$cust_po=$rsdata['cust_po'];
$style_no=$rsdata['style_no'];
$style_name=$rsdata['style_name'];
$combo=$rsdata['combo'];
$fabric_type=$rsdata['fabric_type'];
$printed_qty=$rsdata['printed_qty'];
$fusing_status=$rsdata['fusing_status'];
$job_type=get_job_types($job_card_no);
$create_date1=date('Y-m-d');
$billing_type=$rsdata['billing_type'];
$invoice_no=$rsdata['invoice_no'];
$bill_date=$rsdata['bill_date'];
$payment_terms=$rsdata['payment_terms'];


 $Insql1=mysql_query("insert into deleted_production_main(job_card_no,print_date,cust_name,job_created,cust_po,style_no,style_name,combo,printed_qty,printer_status,job_type,refer,cr_date,fabric_type,billing_type,invoice_no,bill_date,payment_terms)values('$job_card_no','$print_date','$cust_name','$job_created','$cust_po','$style_no','$style_name','$combo','$printed_qty','$fusing_status','$job_type','Fusing','$create_date1','$fabric_type','$billing_type','$invoice_no','$bill_date','$payment_terms')");
}



$sql="select * from printer_production_main where invoice_no='$_POST[invoice_no]' and p_id='$_POST[p_id]' and billing_type='$_POST[billing_type]' ";
$rs=mysql_query($sql);
while($rsdata=mysql_fetch_array($rs))
{
$job_card_no=$rsdata['job_card_no'];
$print_date=$rsdata['print_date'];
$cust_name=$rsdata['cust_name'];
$job_created=$rsdata['job_created'];
$cust_po=$rsdata['cust_po'];
$style_no=$rsdata['style_no'];
$style_name=$rsdata['style_name'];
$combo=$rsdata['combo'];
$printed_qty=$rsdata['printed_qty'];
$printer_status=$rsdata['printer_status'];
$job_type=get_jobtype($job_card_no);
$fabrics_type=get_fabricstype($job_card_no);
$create_date1=date('Y-m-d');
$billing_type=$rsdata['billing_type'];
$invoice_no=$rsdata['invoice_no'];
$bill_date=$rsdata['bill_date'];
$payment_terms=$rsdata['payment_terms'];

 $Insql1=mysql_query("insert into deleted_production_main(job_card_no,print_date,cust_name,job_created,cust_po,style_no,style_name,combo,printed_qty,refer,job_type,fabric_type,printer_status,cr_date,billing_type,invoice_no,bill_date,payment_terms)values('$job_card_no','$print_date','$cust_name','$job_created','$cust_po','$style_no','$style_name','$combo','$printed_qty','Printer','$job_type','$fabrics_type','$printer_status','$create_date1','$billing_type','$invoice_no','$bill_date','$payment_terms')");
}
	$create_date=date('Y-m-d');
$explodes=explode("-",$create_date);
$year1=$explodes[0];
$year2=$explodes[1];
$year=$year1."-".$year2;

if(($year=='2014-04')||($year=='2014-05')||($year=='2014-06')||($year=='2014-07')||($year=='2014-08')||($year=='2014-09')||($year=='2014-10')||($year=='2014-11')||($year=='2014-12')||($year=='2015-01')||($year=='2015-02')||($year=='2015-03'))
{
$acc_year='2015';
}

if(($year=='2015-04')||($year=='2015-05')||($year=='2015-06')||($year=='2015-07')||($year=='2015-08')||($year=='2015-09')||($year=='2015-10')||($year=='2015-11')||($year=='2015-12')||($year=='2016-01')||($year=='2016-02')||($year=='2016-03'))
{
$acc_year='2016';
}

if(($year=='2016-04')||($year=='2016-05')||($year=='2016-06')||($year=='2016-07')||($year=='2016-08')||($year=='2016-09')||($year=='2016-10')||($year=='2016-11')||($year=='2016-12')||($year=='2017-01')||($year=='2017-02')||($year=='2017-03'))
{
$acc_year='2017';
}

if(($year=='2017-04')||($year=='2017-05')||($year=='2017-06')||($year=='2017-07')||($year=='2017-08')||($year=='2017-09')||($year=='2017-10')||($year=='2017-11')||($year=='2017-12')||($year=='2018-01')||($year=='2018-02')||($year=='2018-03'))
{
$acc_year='2018';
}


if(($year=='2018-04')||($year=='2018-05')||($year=='2018-06')||($year=='2018-07')||($year=='2018-08')||($year=='2018-09')||($year=='2018-10')||($year=='2018-11')||($year=='2018-12')||($year=='2019-01')||($year=='2019-02')||($year=='2019-03'))
{
$acc_year='2019';
}



if(($year=='2019-04')||($year=='2019-05')||($year=='2019-06')||($year=='2019-07')||($year=='2019-08')||($year=='2019-09')||($year=='2019-10')||($year=='2019-11')||($year=='2019-12')||($year=='2020-01')||($year=='2020-02')||($year=='2020-03'))
{
$acc_year='2020';
}



if(($year=='2020-04')||($year=='2020-05')||($year=='2020-06')||($year=='2020-07')||($year=='2020-08')||($year=='2020-09')||($year=='2020-10')||($year=='2020-11')||($year=='2020-12')||($year=='2021-01')||($year=='2021-02')||($year=='2021-03'))
{
$acc_year='2021';
}



if(($year=='2021-04')||($year=='2021-05')||($year=='2021-06')||($year=='2021-07')||($year=='2021-08')||($year=='2021-09')||($year=='2021-10')||($year=='2021-11')||($year=='2021-12')||($year=='2022-01')||($year=='2022-02')||($year=='2022-03'))
{
$acc_year='2022';
}

if(($year=='2022-04')||($year=='2022-05')||($year=='2022-06')||($year=='2022-07')||($year=='2022-08')||($year=='2022-09')||($year=='2022-10')||($year=='2022-11')||($year=='2022-12')||($year=='2023-01')||($year=='2023-02')||($year=='2023-03'))
{
$acc_year='2023';
}

if(($year=='2023-04')||($year=='2023-05')||($year=='2023-06')||($year=='2023-07')||($year=='2023-08')||($year=='2023-09')||($year=='2023-10')||($year=='2023-11')||($year=='2023-12')||($year=='2024-01')||($year=='2024-02')||($year=='2024-03'))
{
$acc_year='2024';
}

if(($year=='2024-04')||($year=='2024-05')||($year=='2024-06')||($year=='2024-07')||($year=='2024-08')||($year=='2024-09')||($year=='2024-10')||($year=='2024-11')||($year=='2024-12')||($year=='2025-01')||($year=='2025-02')||($year=='2025-03'))
{
$acc_year='2025';
}
	$update12="update fusing_production_main set billed_status='0',`billing_type`='',`payment_terms`='',`tax_type`='',`frieght_charges`='',`invoice_no`='',`bill_date`='' where invoice_no='$_POST[invoice_no]' and academic_year='$acc_year' ";
	mysql_query($update12);

	$update1="update printer_production_main set billed_status='0',`billing_type`='',`payment_terms`='',`tax_type`='',`frieght_charges`='',`invoice_no`='',`bill_date`='' where invoice_no='$_POST[invoice_no]' and academic_year='$acc_year' ";
	mysql_query($update1);
	
$deletes="delete from fusing_jobcard_sub where invoice_no='$_POST[invoice_no]' and acc_year='$acc_year'";
mysql_query($deletes); 
		
include("proforma_billing_unbill_entry_list.php");
}

?>