<?php
error_reporting(0);

include("../../include/db.php");
function get_jobcard_checkitem($jobcard_no)
{
	$Isql=mysql_query("select * from jobcard_main where jobcard_no='$jobcard_no'");
    $rscount=mysql_num_rows($Isql);
	return $rscount;
}
 
/***************************** Main Add***********************************************************/
if(($_POST['action']=="SUBMIT")) 
{
	
$jobcard_no=$_POST['jobcard_no'];
$entry_time=$_POST['entry_time'];
$customer_name=$_POST['customer_name'];
$style_no=$_POST['style_no'];
$created_by=$_POST['created_by'];
$style_name=$_POST['style_name'];
$cust_po_no=$_POST['cust_po_no'];
$combo=$_POST['combo'];
$jobtype=$_POST['jobtype'];
$fabric_type=$_POST['fabric_type'];
$overal_tot=$_POST['overal_tot'];
$order_by_quot=$_POST['order_by_quot'];
$payment_type=$_POST['payment_type'];

$tax=$_POST['tax'];
$tax_amt=$_POST['tax_amt'];
$net_amt=$_POST['net_amt'];
$create_date1=date('Y-m-d');
$acadamic_yr=explode("-",$create_date1);
$acdmc_yr_res=$acadamic_yr[0];
$check_item_jobcard = get_jobcard_checkitem($jobcard_no);

$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';
}
$Insql1=mysql_query("insert into jobcard_quotation(jobcard_quot_no,entry_date,created_by,cust_name,style_no,style_name,cust_po_no,job_type,fabric_type,combo,overall_value,tax,tax_amt,net_total,academic_yr,createdate,order_by,payment_terms)values('$jobcard_no','$entry_time','$created_by','$customer_name','$style_no','$style_name','$cust_po_no','$jobtype','$fabric_type','$combo','$overal_tot','$tax','$tax_amt','$net_amt','$acc_year','$create_date1','$order_by_quot','$payment_type')");


   $Upsql100="update jobcard_quotation_sub set entry_time='$entry_time',created_by='$created_by',customer_name='$customer_name',cust_po_no='$cust_po_no',jobtype='$jobtype',fabric_type='$fabric_type' where jobcard_quot_no='$_POST[jobcard_no]'";
   mysql_query($Upsql100);


}
/***************************** Main Update***********************************************************/
if($_POST['action']=="UPDATE")
{
$edit_ids=$_POST['main_edit_id'];
$jobcard_no=$_POST['jobcard_no'];
$entry_time=$_POST['entry_time'];
$customer_name=$_POST['customer_name'];
$style_no=$_POST['style_no'];
$created_by=$_POST['created_by'];
$style_name=$_POST['style_name'];
$cust_po_no=$_POST['cust_po_no'];
$combo=$_POST['combo'];
$jobtype=$_POST['jobtype'];
$fabric_type=$_POST['fabric_type'];
$overal_tot=$_POST['overal_tot'];
$tax=$_POST['tax'];
$tax_amt=$_POST['tax_amt'];
$net_amt=$_POST['net_amt'];
$order_by_quot=$_POST['order_by_quot'];
$payment_type=$_POST['payment_type'];

$create_date1=date('Y-m-d');
$acadamic_yr=explode("-",$create_date1);
$acdmc_yr_res=$acadamic_yr[0];


  $Upsq12="update jobcard_quotation set jobcard_quot_no='$jobcard_no',entry_date='$entry_time',created_by='$created_by',cust_name='$customer_name',style_no='$style_no',style_name='$style_name',cust_po_no='$cust_po_no',job_type='$jobtype',fabric_type='$fabric_type',combo='$combo',overall_value='$overal_tot',tax='$tax',tax_amt='$tax_amt',net_total='$net_amt',academic_yr='$acdmc_yr_res',createdate='$create_date1',order_by='$order_by_quot',payment_terms='$payment_type' where main_id='$_POST[main_edit_id]'";
 mysql_query($Upsq12) or die(error);
  
  
     $Upsql1002="update jobcard_quotation_sub set entry_time='$entry_time',created_by='$created_by',customer_name='$customer_name',cust_po_no='$cust_po_no',jobtype='$jobtype',fabric_type='$fabric_type' where jobcard_quot_no='$_POST[jobcard_no]'";
   mysql_query($Upsql1002);
}
 /**********************************SUB ADD  QUERY ***************************************/
 if($_POST['action']=="ADD")
	{
	  $edit_id=$_POST['edit_id'];
	 $jobcard_no=$_POST['jobcard_no'];
      $entry_time=$_POST['entry_time'];

      $created_by=$_POST['created_by'];
      $cust_po_no=$_POST['cust_po_no'];
      $customer_name=$_POST['customer_name'];
      $jobtype=$_POST['jobtype'];
      $fabric_type=$_POST['fabric_type'];
      $particulars=$_POST['particulars'];
      $width=$_POST['jobcard_width'];
	   $height=$_POST['jobcard_height'];
      $rate=$_POST['rate'];
      $amount=$_POST['amount'];
      $conformed_amt=$_POST['conformed_amt'];
      $qty=$_POST['qty'];
      $values=$_POST['values'];
      $create_date1=date('Y-m-d');
	  $acadamic_yr=explode("-",$create_date1);
      $acdmc_yr_res=$acadamic_yr[0];

$Insql1=mysql_query("insert into jobcard_quotation_sub(jobcard_quot_no,entry_time,created_by,cust_po_no,customer_name,jobtype,fabric_type,particulars,width,height,rate,amount,conformed_amt,qty,jobcard_values,academic_yr,createdate)values('$jobcard_no','$entry_time','$created_by','$cust_po_no','$customer_name','$jobtype','$fabric_type','$particulars','$width','$height','$rate','$amount','$conformed_amt','$qty','$values','$acdmc_yr_res','$create_date1')");
include("jobcard_quot_sublist.php");
}
 /**********************************SUB Edit  QUERY ***************************************/
	if($_POST['action']=="EDIT")
    {
      $edit_id=$_POST['edit_id'];
	  $jobcard_no=$_POST['jobcard_no'];
      $entry_time=$_POST['entry_time'];
      $created_by=$_POST['created_by'];
      $cust_po_no=$_POST['cust_po_no'];
      $customer_name=$_POST['customer_name'];
      $jobtype=$_POST['jobtype'];
      $fabric_type=$_POST['fabric_type'];
      $particulars=$_POST['particulars'];
      $width=$_POST['jobcard_width'];
	  $height=$_POST['jobcard_height'];
      $rate=$_POST['rate'];
      $amount=$_POST['amount'];
      $conformed_amt=$_POST['conformed_amt'];
      $qty=$_POST['qty'];
      $values=$_POST['values'];
      $create_date1=date('Y-m-d');
	  $acadamic_yr=explode("-",$create_date1);
      $acdmc_yr_res=$acadamic_yr[0];
	
   $Upsql1="update jobcard_quotation_sub set jobcard_quot_no='$jobcard_no',particulars='$particulars',
width='$width',height='$height',rate='$rate',	amount='$amount',conformed_amt='$conformed_amt',qty='$qty',jobcard_values='$values',academic_yr='$acdmc_yr_res',createdate='$create_date1' where 	job_id='$_POST[edit_id]'";
   mysql_query($Upsql1);
  
include("jobcard_quot_sublist.php");
}
/******************************************** SUB DELETE*****************************************************************/
if($_POST['action']=="delete_job_sub")
{ 		 
		      $delete1="delete from  jobcard_quotation_sub where job_id='$_POST[job_id]'";
			 mysql_query($delete1);
			 
			 include("jobcard_quot_sublist.php");
}
function get_jobcard_confirm_check($jobcard_no,$job_id)
{
	$Isql=mysql_query("select * from jobcard_sublist where quotation_no='$jobcard_no' and quotation_id='$job_id'");
    $rscount=mysql_num_rows($Isql);
	return $rscount;
}
function get_jobcard_confirm_check_file_upload($jobcard_quot_no,$file_id)
{
	$Isql=mysql_query("select * from file_upload_jobcard where quotation_no='$jobcard_quot_no' and quotation_id='$file_id'");
    $rscount=mysql_num_rows($Isql);
	return $rscount;
}

if($_POST['action']=="conformed")
{
 $jobcard_no_quot=$_POST['jobcard_no_quot'];
 $customer_name_quot=$_POST['customer_name_quot'];
$entry_time_quot=$_POST['entry_time_quot'];
$overal_tot_quot=$_POST['overal_tot_quot'];
$net_amt_quot=$_POST['net_amt_quot'];
 $sql2=mysql_query("Select * from jobcard_quotation_sub where jobcard_quot_no='$jobcard_no_quot'");
while($rsdata1=mysql_fetch_array($sql2))
{
	
   				 $job_id=$rsdata1['job_id'];
     			$jobcard_no=$rsdata1['jobcard_quot_no'];
				$particulars=$rsdata1['particulars'];
   				$width=$rsdata1['width'];
				$height=$rsdata1['height'];
				$rate=$rsdata1['rate'];
				$amount=$rsdata1['amount'];
				$conformed_amt=$rsdata1['conformed_amt'];
				 $qty=$rsdata1['qty'];
				$jobcard_values=$rsdata1['jobcard_values'];
				$created_by=$rsdata1['created_by'];
				$jobtype=$rsdata1['jobtype'];
				$cust_po_no=$rsdata1['cust_po_no'];
				$jobtype=$rsdata1['jobtype'];
				$fabric_type=$rsdata1['fabric_type'];
				$checks=get_jobcard_confirm_check($jobcard_no,$job_id);

	if($checks==0)
	{
 $Insql1=mysql_query("insert into jobcard_sublist(quotation_no,entry_time,created_by,cust_po_no,customer_name,jobtype,fabric_type,particulars,width,height,rate,amount,conformed_amt,qty,jobcard_values,academic_yr,createdate,quotation_id)values('$jobcard_no_quot','$entry_time_quot','$created_by','$cust_po_no','$customer_name_quot','$jobtype','$fabric_type','$particulars','$width','$height','$rate','$amount','$conformed_amt','$qty','$jobcard_values','$acdmc_yr_res','$create_date1','$job_id')");	
	}
}
 $sql2=mysql_query("Select * from file_upload_jobcard_quotation where jobcard_quot_no='$jobcard_no_quot'");
while($rsdata1=mysql_fetch_array($sql2))
{
	
   				 $file_id=$rsdata1['file_id'];
     			$jobcard_quot_no=$rsdata1['jobcard_quot_no'];
				$customer_name=$rsdata1['customer_name'];
   				$file_name=$rsdata1['file_name'];
				$create_date=$rsdata1['create_date'];
				
				$checks11=get_jobcard_confirm_check_file_upload($jobcard_quot_no,$file_id);

	if($checks11==0)
	{
 $Insql1=mysql_query("insert into file_upload_jobcard(quotation_no,file_name,customer_name,create_date,quotation_id)values('$jobcard_quot_no','$file_name','$customer_name','$create_date','$file_id')");	
	}
}
}

/******************************************** Main DELETE*****************************************************************/
if($_POST['action']=="delete_job_quotation_main")
{ 		 
  $delete2="delete from jobcard_quotation where main_id='$_POST[job_id]' and jobcard_quot_no='$_POST[jobcard_no]'";
   mysql_query($delete2);
  $Delsql5="delete from jobcard_quotation_sub where  jobcard_quot_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql5);
  $Delsql51="delete from jobcard_sublist where  quotation_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql51);
}

if($_POST['action']=="del_file_upld")
{ 		 
   $delete21="delete from file_upload_jobcard_quotation where file_id='$_POST[id]' and jobcard_quot_no='$_POST[jobcard_no]'";
   mysql_query($delete21);
   include("file_upload_subllist.php");
}

?>