<?php
error_reporting(0);

include("../../include/db.php");
function get_jobcard_checkitem_sample($jobcard_no)
{
	$Isql=mysql_query("select * from sample_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'];
$designer=$_POST['designer'];
$designer_name=$_POST['designer_name'];
$color_profile=$_POST['color_profile'];
$order_by=$_POST['order_by'];
$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_sample($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';
}

if($check_item_jobcard==0)
{ 
$Insql1=mysql_query("insert into sample_jobcard_main(jobcard_no,entry_date,created_by,cust_name,designer_name,design,color_profile,job_type,fabric_type,combo,overall_value,tax,tax_amt,net_total,academic_yr,createdate,order_by)values('$jobcard_no','$entry_time','$created_by','$customer_name','$designer_name','$designer','$color_profile','$jobtype','$fabric_type','$combo','$overal_tot','$tax','$tax_amt','$net_amt','$acc_year','$create_date1','$order_by')");


   $Upsql100="update jobcard_sublist 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_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'];
$designer=$_POST['designer'];
$designer_name=$_POST['designer_name'];
$color_profile=$_POST['color_profile'];
$order_by=$_POST['order_by'];


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

  $Upsq12="update sample_jobcard_main set jobcard_no='$jobcard_no',entry_date='$entry_time',created_by='$created_by',cust_name='$customer_name',designer_name='$designer_name',design='$designer',color_profile='$color_profile',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',order_by='$order_by',createdate='$create_date1' where main_id='$_POST[main_edit_id]'";
 mysql_query($Upsq12) or die(error);
  
  
     $Upsql1002="update jobcard_sublist 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_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'];

    
      $customer_name=$_POST['customer_name'];
      
      $particulars=$_POST['particulars'];
      $width=$_POST['jobcard_width'];
	        $height=$_POST['jobcard_height'];
      $rate=$_POST['inch'];
      $amount=$_POST['qty'];
      $conformed_amt=$_POST['total'];
   
      $create_date1=date('Y-m-d');
	  $acadamic_yr=explode("-",$create_date1);
      $acdmc_yr_res=$acadamic_yr[0];
$Insql1=mysql_query("insert into sample_jobcard_sublist(jobcard_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("sample_jobcard_sublist.php");
}
 /**********************************SUB Edit  QUERY ***************************************/
	if($_POST['action']=="EDIT")
    {
      $edit_id=$_POST['edit_id'];
	  $jobcard_no=$_POST['jobcard_no'];
      $entry_time=$_POST['entry_time'];
   
      $customer_name=$_POST['customer_name'];
    
      $particulars=$_POST['particulars'];
      $width=$_POST['jobcard_width'];
	  $height=$_POST['jobcard_height'];
      $rate=$_POST['inch'];
      $amount=$_POST['qty'];
      $conformed_amt=$_POST['total'];
    
      $create_date1=date('Y-m-d');
	  $acadamic_yr=explode("-",$create_date1);
      $acdmc_yr_res=$acadamic_yr[0];
	
   $Upsql1="update sample_jobcard_sublist set jobcard_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("sample_jobcard_sublist.php");
}
/******************************************** SUB DELETE*****************************************************************/
if($_POST['action']=="delete_job_sub")
{ 		 
		      $delete1="delete from  sample_jobcard_sublist where 	job_id='$_POST[job_id]'";
			 mysql_query($delete1);
			 
			 include("sample_jobcard_sublist.php");
}
/******************************************** Main DELETE*****************************************************************/
if($_POST['action']=="delete_job_main")
{ 		 
  $delete2="delete from sample_jobcard_main where main_id='$_POST[job_id]' and jobcard_no='$_POST[jobcard_no]'";
   mysql_query($delete2);

  $Delsql5="delete from sample_jobcard_sublist where  jobcard_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql5);
  
    $delete21="delete from inward_main where  jobcard_no='$_POST[jobcard_no]'";
   mysql_query($delete21);

  $Delsql51="delete from inward_sub_list where  jobcard_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql51);
  
     $delete22="delete from delivery_challan_main where  job_no='$_POST[jobcard_no]'";
   mysql_query($delete22);

  $Delsql52="delete from delivery_challan_sub where  job_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql52);
  
   $delete25="delete from printer_production_main where job_card_no='$_POST[jobcard_no]'";
   mysql_query($delete25);

  $Delsql55="delete from fusing_production_main where  job_card_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql55);
  
    $delete23="delete from fusing_production_sublist where job_card_no='$_POST[jobcard_no]'";
   mysql_query($delete23);

  $Delsql54="delete from printer_production_sublist where  job_card_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql54);
    $delete21="delete from file_upload_sample_jobcard where job_card_no='$_POST[job_card_no]'";
   mysql_query($delete21);
  include("sample_jobcard_entry_list.php");
  echo $msg;
}
if($_POST['action']=="del_file_upld")
{ 		 
  $delete21="delete from file_upload_sample_jobcard where file_id='$_POST[id]' and job_card_no='$_POST[job_card_no]'";
   mysql_query($delete21);
  include("file_upload_subllist.php");

}
?>