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


function get_jobcard_check($jobcard_no)
{
	$Isql=mysql_query("select * from inward_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'];
$total_piece=$_POST['total_piece'];
$customer_dc_no=$_POST['customer_dc_no'];
$receipt=$_POST['receipt'];
$invoice_no=$_POST['invoice_no'];
$delivery_through=$_POST['delivery_through'];
$vehicle_no=$_POST['vehicle_no'];

$create_date1=date('Y-m-d');
$acadamic_yr=explode("-",$create_date1);
$acdmc_yr_res=$acadamic_yr[0];
$check_item=get_jobcard_check($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==0)
{
 $Insql1=mysql_query("insert into inward_main(jobcard_no,entry_date,created_by,cust_name,style_no,style_name,cust_po_no,job_type,fabric_type,combo,overall_value,academic_yr,createdate,total_piece,customer_dc_no,receipt,invoice_no,delivery_through,vehicle_no)values('$jobcard_no','$entry_time','$created_by','$customer_name','$style_no','$style_name','$cust_po_no','$jobtype','$fabric_type','$combo','$overal_tot','$acc_year','$create_date1','$total_piece','$customer_dc_no','$receipt','$invoice_no','$delivery_through','$vehicle_no')");
 echo "Added Successfully";
 $insert_id = mysql_insert_id();
 $Upsq1211="update inward_sub_list set insert_id='$insert_id' where jobcard_no='$jobcard_no'";
 $Upsq12112=mysql_query("update printer_production_main set deliv_status='1' where job_card_no='$jobcard_no'");
 $Upsq12113=mysql_query("update fusing_production_main set deliv_status='1' where job_card_no='$jobcard_no'");
 mysql_query($Upsq1211) or die(error);
}
else
{
	echo "Already Exists...";
}
}
/***************************** 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'];
$total_piece=$_POST['total_piece'];
$customer_dc_no=$_POST['customer_dc_no'];
$receipt=$_POST['receipt'];
$invoice_no=$_POST['invoice_no'];
$delivery_through=$_POST['delivery_through'];
$vehicle_no=$_POST['vehicle_no'];

$create_date1=date('Y-m-d');
$acadamic_yr=explode("-",$create_date1);
$acdmc_yr_res=$acadamic_yr[0];
  $Upsq12="update inward_main set jobcard_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',academic_yr='$acdmc_yr_res',
  createdate='$create_date1',total_piece='$total_piece',customer_dc_no='$customer_dc_no',receipt='$receipt',invoice_no='$invoice_no',delivery_through='$delivery_through',vehicle_no='$vehicle_no' where main_id='$_POST[main_edit_id]'";
 mysql_query($Upsq12) or die(error);
 echo "Updated Successfully";
}


 /**********************************SUB ADD  QUERY ***************************************/
function get_inward($jobcard_no,$inward_particular)
{
    $sql_user="select sum(inward_qty) as inward_qty from  inward_sub_list where jobcard_no='$jobcard_no' and inward_particular='$inward_particular'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$inward_qty=$rsdata_user->inward_qty;
	}
	return $inward_qty;
}


 if($_POST['action']=="ADD")
	{
	  $jobcard_no=$_POST['jobcard_no'];
      $in_cust_name=$_POST['in_cust_name'];
      $inward_date=$_POST['inward_date'];
      $inward_particular=$_POST['inward_particular'];
      $roll_width=$_POST['roll_width'];
      $kg_height=$_POST['kg_height'];
	  $fabric_type=$_POST['fabric_type'];
      $inward_qty=$_POST['inward_qty'];
	 $inward_qty1=$_POST['inward_qty1'];
	  $sum_inward=get_inward($jobcard_no,$inward_particular);
	  $created_by=$_POST['created_by'];
	  $job_types=$_POST['job_types'];
	  $entrydates=date('Y-m-d',strtotime($_POST['entrydates']));
      $create_date1=date('Y-m-d');
	  $acadamic_yr=explode("-",$create_date1);
      $acdmc_yr_res=$acadamic_yr[0];
	  $total_piece=$_POST['total_piece'];
	  $customer_dc_no=$_POST['customer_dc_no'];
       $receipt=$_POST['receipt'];
	   $invoice_no=$_POST['invoice_no'];
if($inward_qty!=0)
{
$Insql1=mysql_query("insert into inward_sub_list(jobcard_no,in_cust_name,inward_date,inward_particular,roll_width,kg_height,inward_qty,order_qty,acad_yr,cr_date	 ,fabric_type,created_by,job_types,entrydates,total_piece,customer_dc_no,receipt,invoice_no)values('$jobcard_no','$in_cust_name','$inward_date','$inward_particular','$roll_width','$kg_height','$inward_qty','$inward_qty1','$acdmc_yr_res','$create_date1','$fabric_type','$created_by','$job_types','$entrydates','$total_piece','$customer_dc_no','$receipt','$invoice_no')");
echo "Added Successfully";
}
else
{
	 echo "Check The Quantity...";
}
include("inward_sublist.php");
}
 /**********************************SUB Edit  QUERY ***************************************/
	if($_POST['action']=="EDIT")
    {
      $id=$_POST['edit_id'];
      $jobcard_no=$_POST['jobcard_no'];
      $in_cust_name=$_POST['in_cust_name'];
      $inward_date=$_POST['inward_date'];
      $inward_particular=$_POST['inward_particular'];
      $roll_width=$_POST['roll_width'];
      $kg_height=$_POST['kg_height'];
	  $fabric_type=$_POST['fabric_type'];
      $inward_qty=$_POST['inward_qty'];
	  $created_by=$_POST['created_by'];
	  $job_types=$_POST['job_types'];
	  $entrydates=date('Y-m-d',strtotime($_POST['entrydates']));
      $create_date1=date('Y-m-d');
	  $acadamic_yr=explode("-",$create_date1);
      $acdmc_yr_res=$acadamic_yr[0];
	  $total_piece=$_POST['total_piece'];
	  $customer_dc_no=$_POST['customer_dc_no'];
	  $invoice_no=$_POST['invoice_no'];
   $Upsql1="update inward_sub_list set jobcard_no='$jobcard_no',in_cust_name='$in_cust_name',
inward_date='$inward_date',inward_particular='$inward_particular',roll_width='$roll_width',kg_height='$kg_height',fabric_type='$fabric_type',inward_qty='$inward_qty',created_by='$created_by',job_types='$job_types',entrydates='$entrydates',total_piece='$total_piece',customer_dc_no='$customer_dc_no',invoice_no='$invoice_no' where id='$_POST[edit_id]'";
   mysql_query($Upsql1);
   echo "Edited Successfully";
include("inward_sublist.php");
}
/******************************************** SUB DELETE*****************************************************************/
if($_POST['action']=="del_inward_sublist")
{ 		 
		     $delete1="delete from inward_sub_list where id='$_POST[id]'";
			 mysql_query($delete1);
			 include("inward_sublist.php");
}
/******************************************** Main DELETE*****************************************************************/
if($_POST['action']=="delete_inward")
{ 		 
  $delete2="delete from inward_main where jobcard_no='$_POST[jobcard_no]'";
   mysql_query($delete2);
  $Delsql5="delete from inward_sub_list where  jobcard_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql5);
  include("inward_entry_list.php");
}
?>
