<?php
include("../../include/db.php");
/**********************************Main  ADD ***************************************/
if($_POST['action']=='Save')
{
$return_no=$_POST['return_no'];
$date_time=$_POST['date_time'];
$job_no=$_POST['job_no'];
$created_by=$_POST['created_by'];
$customer_name=$_POST['customer_name'];
$style_no=$_POST['style_no'];
$style_name=$_POST['style_name'];
$combo=$_POST['combo'];
$cust_po_no=$_POST['cust_po_no'];
$job_type=$_POST['job_type'];
$fabric_type=$_POST['fabric_type'];
$remarks=$_POST['remarks'];
$overal_qty=$_POST['overal_qty'];
$deliv_status=$_POST['deliv_status'];
$cr_dates=date('Y-m-d');
$acadamic_yr=explode("-",$cr_dates);
$acdmc_yr_res=$acadamic_yr[0];

$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';
}

$Insql=mysql_query("insert into return_form_main(return_no,date_time,job_no,created_by,customer_name,style_no,style_name,combo,customer_po_no,job_type,fabric_type,remarks,total_qty,deliv_status,cr_date,acad_yr)values('$return_no','$date_time','$job_no','$created_by','$customer_name','$style_no','$style_name','$combo','$cust_po_no','$job_type','$fabric_type','$remarks','$overal_qty','$deliv_status','$cr_dates','$acc_year')");

if($deliv_status=='Completed')
{
$Insql=mysql_query("update jobcard_main SET deliv_status='1' where  jobcard_no='$job_no'");
$Insql=mysql_query("update jobcard_sublist SET deliv_status='1' where  jobcard_no='$job_no'");

$Insql=mysql_query("update inward_main SET deliv_status='1' where  jobcard_no='$job_no'");
$Insql=mysql_query("update inward_sub_list SET deliv_status='1' where  jobcard_no='$job_no'");

$Insql=mysql_query("update printer_production_main SET deliv_status='1' where  job_card_no='$job_no'");
$Insql=mysql_query("update printer_production_sublist SET deliv_status='1' where  job_card_no='$job_no'");

$Insql=mysql_query("update fusing_production_main SET deliv_status='1' where  job_card_no='$job_no'");
$Insql=mysql_query("update fusing_production_sublist SET deliv_status='1' where  job_card_no='$job_no'");
}

echo "Added Successfully";
}
/*********************************** Main Update  *********************************************/
if($_POST['action']=='Edit')
{
$edit_id=$_POST['edit_id'];
$return_no=$_POST['return_no'];
$date_time=$_POST['date_time'];
$job_no=$_POST['job_no'];
$created_by=$_POST['created_by'];
$customer_name=$_POST['customer_name'];
$style_no=$_POST['style_no'];
$style_name=$_POST['style_name'];
$combo=$_POST['combo'];
$cust_po_no=$_POST['cust_po_no'];
$job_type=$_POST['job_type'];
$fabric_type=$_POST['fabric_type'];
$remarks=$_POST['remarks'];
$overal_qty=$_POST['overal_qty'];
$deliv_status=$_POST['deliv_status'];
$cr_dates=date('Y-m-d');
$acadamic_yr=explode("-",$cr_dates);
$acdmc_yr_res=$acadamic_yr[0];

$Insql=mysql_query("update return_form_main SET return_no='$return_no',date_time='$date_time',job_no='$job_no',created_by='$created_by',customer_name='$customer_name',style_no='$style_no',style_name='$style_name',combo='$combo',customer_po_no='$cust_po_no',job_type='$job_type',fabric_type='$fabric_type',remarks='$remarks',total_qty='$overal_qty',deliv_status='$deliv_status' where id='$_POST[edit_id]'");

if($deliv_status=='Completed')
{
$Insql=mysql_query("update jobcard_main SET deliv_status='1' where  jobcard_no='$job_no'");
$Insql=mysql_query("update jobcard_sublist SET deliv_status='1' where  jobcard_no='$job_no'");

$Insql=mysql_query("update inward_main SET deliv_status='1' where  jobcard_no='$job_no'");
$Insql=mysql_query("update inward_sub_list SET deliv_status='1' where  jobcard_no='$job_no'");

$Insql=mysql_query("update printer_production_main SET deliv_status='1' where  job_card_no='$job_no'");
$Insql=mysql_query("update printer_production_sublist SET deliv_status='1' where  job_card_no='$job_no'");

$Insql=mysql_query("update fusing_production_main SET deliv_status='1' where  job_card_no='$job_no'");
$Insql=mysql_query("update fusing_production_sublist SET deliv_status='1' where  job_card_no='$job_no'");
}
echo "Updated Successfully";
}
/********************************** Sublist Add ***************************************/
if($_POST['action']=='ADD')
{
$return_no=$_POST['return_no'];
$date_time=$_POST['date_time'];
$job_no=$_POST['job_no'];
$customer_name=$_POST['customer_name'];
$job_type=$_POST['job_type'];
$fabric_type=$_POST['fabric_type'];
$return_dates=$_POST['return_dates'];
$deliv_particular=$_POST['deliv_particular'];
$roll_width=$_POST['roll_width'];
$kg_height=$_POST['kg_height'];
$inward_qty=$_POST['inward_qty'];
$cr_dates=date('Y-m-d');
$acadamic_yr=explode("-",$cr_dates);
$acdmc_yr_res=$acadamic_yr[0];


	 $Insql=mysql_query("insert into  return_sublist(return_no,date_time,job_no,cust_name,job_type,fabric_type,return_date,particulars,rollno_width,kg_meter_height,qty,cr_date,acad_yr)values('$return_no','$date_time','$job_no','$customer_name','$job_type','$fabric_type','$return_dates','$deliv_particular','$roll_width','$kg_height','$inward_qty','$cr_dates','$acdmc_yr_res')");
				 
include('return_sublist.php');
}
/********************************** Sublist Edit ***************************************/
if($_POST['action']=='EDIT')
{
$return_no=$_POST['return_no'];
$date_time=$_POST['date_time'];
$job_no=$_POST['job_no'];
$customer_name=$_POST['customer_name'];
$job_type=$_POST['job_type'];
$fabric_type=$_POST['fabric_type'];
$return_dates=$_POST['return_dates'];
$deliv_particular=$_POST['deliv_particular'];
$roll_width=$_POST['roll_width'];
$kg_height=$_POST['kg_height'];
$inward_qty=$_POST['inward_qty'];
$cr_dates=date('Y-m-d');
$acadamic_yr=explode("-",$cr_dates);
$acdmc_yr_res=$acadamic_yr[0];
	 
	  $Insql=mysql_query("update return_sublist SET return_no='$return_no',date_time='$date_time',job_no='$job_no',cust_name='$customer_name',job_type='$job_type',fabric_type='$fabric_type',return_date='$return_dates',particulars='$deliv_particular',rollno_width='$roll_width',kg_meter_height='$kg_height',qty='$inward_qty' where sub_id='$_POST[edit_id]' and job_no='$job_no'");
				 
include('return_sublist.php');
}
/****************************** Sub Delete ******************************************/
if($_POST['action']=='del_return_sublist')
{
$Insql=mysql_query("delete from  return_sublist where sub_id='$_POST[id]'");
include('return_sublist.php');
}
/******************************* Main Delete *************************************************/
if($_POST['action']=='delete_return_main')
{
$Insql=mysql_query("delete from return_form_main where id='$_POST[id]'");
$Insql=mysql_query("delete from  return_sublist where return_no='$_POST[return_no]' and job_no='$_POST[job_no]' ");

}
?>
