<?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_jobcard_checkitem11($job_card_no)
{
	$Isql=mysql_query("select * from fusing_production_main where job_card_no='$job_card_no'");
    $rscount=mysql_num_rows($Isql);
	return $rscount;
}

/***************************** Main Add***********************************************************/
if(($_POST['action']=="SUBMIT")) 
{
$job_card_no=$_POST['job_card_no'];
$print_date=$_POST['print_date'];
$cust_name=$_POST['cust_name'];
$job_created=$_POST['job_created'];
$cust_po=$_POST['cust_po'];
$style_no=$_POST['style_no'];
$style_name=$_POST['style_name'];
$combo=$_POST['combo'];
$fabric_type=$_POST['fabric_type'];
$printed_qty=$_POST['printed_qty'];
$fusing_status=$_POST['fusing_status'];
$job_type=get_jobtype($job_card_no);
$create_date1=date('Y-m-d');
$check_item_jobcard11 = get_jobcard_checkitem11($job_card_no);
$acc_year = date('Y');
if($check_item_jobcard11==0)
{
 $Insql1=mysql_query("insert into fusing_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,acc_year)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','$acc_year')");

 $Upsq125="update fusing_production_sublist set status='1' where job_card_no='$_POST[job_card_no]'";
 mysql_query($Upsq125);
}
else
{
 $Upsq12="update fusing_production_main set print_date='$print_date',cust_name='$cust_name',job_created='$job_created',cust_po='$cust_po',style_no='$style_no',style_name='$style_name',combo='$combo',printed_qty='$printed_qty',printer_status='$fusing_status',fabric_type='$fabric_type',cr_date='$create_date1' where job_card_no='$_POST[job_card_no]'";
 mysql_query($Upsq12) or die(error);
 
 $Upsq125="update fusing_production_sublist set status='1' where job_card_no='$_POST[job_card_no]'";
 mysql_query($Upsq125);
}
}
/***************************** Main Update***********************************************************/
if($_POST['action']=="UPDATE")
{
$job_card_no=$_POST['job_card_no'];
$print_date=$_POST['print_date'];
$cust_name=$_POST['cust_name'];
$job_created=$_POST['job_created'];
$cust_po=$_POST['cust_po'];
$style_no=$_POST['style_no'];
$style_name=$_POST['style_name'];
$combo=$_POST['combo'];
$printed_qty=$_POST['printed_qty'];
$fusing_status=$_POST['fusing_status'];
$fabric_type=$_POST['fabric_type'];
$create_date1=date('Y-m-d');

  $Upsq12="update fusing_production_main set job_card_no='$job_card_no',print_date='$print_date',cust_name='$cust_name',job_created='$job_created',cust_po='$cust_po',style_no='$style_no',style_name='$style_name',combo='$combo',printed_qty='$printed_qty',printer_status='$fusing_status',fabric_type='$fabric_type',cr_date='$create_date1' where p_id='$_POST[edit_id]'";
 mysql_query($Upsq12) or die(error);
 $Upsq122="update fusing_production_sublist set job_card_no='$job_card_no' where job_card_no='$_POST[edit_job_card_id]'";
 mysql_query($Upsq122) or die(error);
echo "<script>alert('Updated Successfully');</script>";
}
 /**********************************SUB ADD  QUERY ***************************************/

 if($_POST['action']=="ADD")
	{
	  $job_card_no=$_POST['job_card_no'];
      $production_time=$_POST['production_time'];
      $shift_time=$_POST['shift_time'];
      $machine_no=$_POST['machine_no'];
      $operator_name=$_POST['operator_name'];
      $prod_size=$_POST['prod_size'];
	  $sizexpl=explode("@#@#",$prod_size);
	  $size=$sizexpl[0];
	  $width=$sizexpl[1];
	  $height=$sizexpl[2];
      $total_qty=$_POST['total_qty'];
      $prod_qty=$_POST['prod_qty'];
      $balance_qty=$_POST['balance_qty'];
      $create_date1=date('Y-m-d');
if($total_qty>=$prod_qty)
{
$Insql1=mysql_query("insert into fusing_production_sublist(job_card_no,production_time,shift_time,machine_no,operator_name,prod_size,width,height,total_qty,prod_qty,balance_qty,cr_date	 )values('$job_card_no','$production_time','$shift_time','$machine_no','$operator_name',
'$size','$width','$height','$total_qty','$prod_qty','$balance_qty','$create_date1')");
}
else
{
}
include("fusing_production_sublist.php");
}
/******************************************** SUB DELETE*****************************************************************/
if($_POST['action']=="Del_sub")
{ 		 
$delete1="delete from fusing_production_sublist where pr_id='$_POST[pr_id]'";
mysql_query($delete1);
include("fusing_production_sublist.php");
}
/******************************************** Main DELETE*****************************************************************/
if($_POST['action']=="delete_fusing_main")
{ 		 
  $delete2="delete from fusing_production_main where p_id='$_POST[p_id]'";
  mysql_query($delete2);
  $delete1="delete from fusing_production_sublist where job_card_no='$_POST[job_card_no]'";
  mysql_query($delete1);
  echo "<script>alert('Deleted Successfully');</script>";
}
if($_POST['action']=="viewjobcard")
{
	include("fusing_production_sublist.php");
}
?>