<?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_fabricstype($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))
			{ 
			$fabric_type=$rsdata_user->fabric_type;
			}
return $fabric_type;
}

function get_jobcard_checkitem22($job_card_no)
{
	$Isql=mysql_query("select * from printer_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'];
$printed_qty=$_POST['printed_qty'];
$printer_status=$_POST['printer_status'];
$job_type=get_jobtype($job_card_no);
$fabrics_type=get_fabricstype($job_card_no);
$create_date1=date('Y-m-d');
$check_item_jobcard22 = get_jobcard_checkitem22($job_card_no);
$acc_year = date('Y');
if($check_item_jobcard22==0)
{
 $Insql1=mysql_query("insert into printer_production_main(job_card_no,print_date,cust_name,job_created,cust_po,style_no,style_name,combo,printed_qty,refer,job_type,fabric_type,printer_status,cr_date,acc_year)values('$job_card_no','$print_date','$cust_name','$job_created','$cust_po','$style_no','$style_name','$combo','$printed_qty','Printer','$job_type','$fabrics_type','$printer_status','$create_date1','$acc_year')");
 
   $Upsq125="update printer_production_sublist set status='1' where job_card_no='$_POST[job_card_no]'";
 mysql_query($Upsq125);
 
 
 $Upsq123="update jobcard_main set printer_status='$printer_status' where jobcard_no='$_POST[edit_job_card_id]'";
 mysql_query($Upsq123) or die(error);
echo "<script>alert('Added Successfully');</script>";
}
}
/***************************** 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'];
$printer_status=$_POST['printer_status'];
$job_type=get_jobtype($job_card_no);
$fabrics_type=get_fabricstype($job_card_no);

$create_date1=date('Y-m-d');
$printer_status=$_POST['printer_status'];
 $Upsq12="update printer_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',job_type='$job_type',fabric_type='$fabrics_type',cr_date='$create_date1',printer_status='$printer_status' where p_id='$_POST[edit_id]'";
  
 mysql_query($Upsq12) or die(error);
 $Upsq122="update printer_production_sublist set job_card_no='$job_card_no' where job_card_no='$_POST[edit_job_card_id]'";
 mysql_query($Upsq122) or die(error);
 $Upsq123="update jobcard_main set printer_status='$printer_status' where jobcard_no='$_POST[edit_job_card_id]'";
 mysql_query($Upsq123) 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 printer_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("printer_production_sublist.php");
}
/******************************************** SUB DELETE*****************************************************************/
if($_POST['action']=="Del_sub")
{ 		 
	 $delete1="delete from printer_production_sublist where pr_id='$_POST[pr_id]'";
			 mysql_query($delete1);
			 
			 include("printer_production_sublist.php");
}
/******************************************** Main DELETE*****************************************************************/
if($_POST['action']=="delete_book_main")
{ 		 
  $delete2="delete from printer_production_main where p_id='$_POST[p_id]'";
   mysql_query($delete2);
	$delete1="delete from printer_production_sublist where job_card_no='$_POST[job_card_no]'";
			 mysql_query($delete1);
			 echo "<script>alert('Deleted Successfully');</script>";
}
if($_POST['action']=="viewjobcard")
{
	include("printer_production_sublist.php");
}
 /*******************************************************SUB Edit  QUERY ******************************************************/
/*	if($_POST['action']=="EDIT")
    {
      $id=$_POST['edit_id'];
      $book_no=$_POST['book_no'];
      $booking_date=$_POST['booking_date'];
      $booking_place=$_POST['booking_place'];
      $booking_branch=$_POST['booking_branch'];
      $pay_to_pay_val=$_POST['pay_to_pay_val'];
      $book_particulars=$_POST['book_particulars'];
      $weight=$_POST['weight_kg'];
      $rates=$_POST['rates'];
      $freight_rs=$_POST['freight_rs'];
      $create_date1=date('Y-m-d');
	  $acadamic_yr=explode("-",$create_date1);
      $acdmc_yr_res=$acadamic_yr[0];
	
   $Upsql1="update booking_sub_list set book_no='$book_no',book_date='$booking_date',
book_place='$booking_place',book_branch='$booking_branch',pay_type='$pay_to_pay_val',particulars='$book_particulars',weight_kg='$weight',kg_rate='$rates',frieght_charge='$freight_rs',acad_yr='$acdmc_yr_res',cr_date='$create_date1' where sub_id='$_POST[edit_id]'";
   mysql_query($Upsql1);
  
include("booking_sublist.php");
}
*/?>