<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	require('pdf/fpdf.php');
	//require('pdf/wordwrap.php');
	
	
	$dep_id	=	base64_decode(base64_decode(base64_decode($_GET['dep_id']))); 
	//$dep_id		=	$_GET['dep_id']; 
	
	$flg	=	2;
	if(isset($_GET['inflg'])){ $inflg = 1; }else{ $inflg = 2; }
	//echo $flg; 

	//echo $dep_id;	
	$tot_cnt = '';
	$h_br = '0'; //THIS IS FOR SETTING THE BORDER IN PDF PAGE FOR HEADER
	$h_br1 = '0'; //THIS IS FOR SETTING THE BORDER IN PDF PAGE FOR HEADER
	$dpa_name = '';
	if($flg==2)
	{
		$h_br='T';
		$h_br1='0';
		
		if($dep_id==1)
		{
			$SLCT_t = "SELECT  COUNT(design_det_id) AS tot_cnt FROM design_det WHERE design_status = 'New Design' AND master_cat_id!=0";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT * FROM design_det WHERE design_status = 'New Design' AND master_cat_id!=0 ORDER BY master_cat_id,design_det_id ASC";
			$dpa_name = "New Design";
		}
		else if($dep_id==2)
		{
			//$SLCT_t = "SELECT COUNT(cad_loading_id) AS tot_cnt FROM cad_loading WHERE cad_status = 'no'";
			$SLCT_t = "SELECT COUNT(cad_loading_id) AS tot_cnt FROM `cad_loading` WHERE `emp_det_id`=0 AND `cad_status`='no' AND `design_det_id` NOT IN(SELECT `design_det_id` FROM `emp_current_design`)";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT cad_loading.* FROM cad_loading,design_det WHERE cad_loading.`emp_det_id`=0 AND cad_loading.cad_status = 'no' AND design_det.design_det_id = cad_loading.design_det_id AND cad_loading.`design_det_id` NOT IN(SELECT `design_det_id` FROM `emp_current_design`) ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "In Cad Loading";
		}
		else if($dep_id==3)
		{
			$SLCT_t = "SELECT  COUNT(cad_finishing_des_id) AS tot_cnt FROM cad_finishing_des WHERE `design_det_id` NOT IN (SELECT `design_det_id` FROM cam_loading UNION ALL SELECT `design_det_id` FROM silver_loading) AND to_rtv_load = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT cad_finishing_des.* FROM cad_finishing_des,design_det WHERE cad_finishing_des.`design_det_id` NOT IN (SELECT `design_det_id` FROM cam_loading UNION ALL SELECT `design_det_id` FROM silver_loading) AND to_rtv_load = 'no' AND design_det.design_det_id = cad_finishing_des.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "In Cad Finishing";
		}
		else if($dep_id==4)
		{
			$SLCT_t = "SELECT  COUNT(cam_loading_id) AS tot_cnt FROM cam_loading WHERE cam_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT * FROM cam_loading,design_det WHERE cam_status = 'no' AND design_det.design_det_id = cam_loading.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id  ASC";
			$dpa_name = "In Cam Loading";
		}
		else if($dep_id==5)
		{
			$SLCT_t = "SELECT  COUNT(cam_finishing_id) AS tot_cnt FROM cam_finishing WHERE `design_det_id` NOT IN (SELECT `design_det_id` FROM rtv_loading)";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT cam_finishing.* FROM cam_finishing,design_det WHERE cam_finishing.`design_det_id` NOT IN (SELECT `design_det_id` FROM rtv_loading) AND design_det.design_det_id = cam_finishing.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "In Cam Receiving";
		}
		else if($dep_id==6)
		{
			$SLCT_t = "SELECT  COUNT(rtv_loading_id) AS tot_cnt FROM rtv_loading WHERE rtv_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT rtv_loading.* FROM rtv_loading,design_det WHERE rtv_status = 'no' AND design_det.design_det_id = rtv_loading.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC
";
			$dpa_name = "In Rtv Loading";
		}
		else if($dep_id==7)
		{
			$SLCT_t = "SELECT COUNT(rtv_finishing_des.rtv_finishing_des_id) AS tot_cnt FROM rtv_finishing_des,design_det WHERE rtv_finishing_des.rtv_fin_status = 'no' AND rtv_finishing_des.up_status = 'no' AND design_det.design_det_id = rtv_finishing_des.design_det_id AND design_det.statu_s='active' AND design_det.up_status='no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT * FROM rtv_finishing_des,design_det WHERE rtv_finishing_des.rtv_fin_status = 'no' AND rtv_finishing_des.up_status = 'no' AND design_det.design_det_id = rtv_finishing_des.design_det_id AND design_det.statu_s='active' AND design_det.up_status='no' ORDER BY design_det.master_cat_id,rtv_finishing_des.design_det_id ASC";
			$dpa_name = "In Wax";
		}
		else if($dep_id==8)
		{
			$SLCT_t = "SELECT COUNT(wax_finishing_id) AS tot_cnt FROM wax_finishing,design_det WHERE wax_finishing.wax_fin_status = 'no' AND  design_det.design_det_id=wax_finishing.design_det_id AND design_det.statu_s='active' AND design_det.up_status='no' AND wax_finishing.up_status='no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT * FROM wax_finishing,design_det WHERE wax_finishing.wax_fin_status = 'no' AND  design_det.design_det_id=wax_finishing.design_det_id AND design_det.statu_s='active' AND design_det.up_status='no' AND wax_finishing.up_status='no' ORDER BY design_det.master_cat_id,wax_finishing.design_det_id ASC";
			$dpa_name = "In Casting";
		}
		else if($dep_id==9)
		{
			//$SLCT_t = "SELECT  COUNT(casting_finishing_id) AS tot_cnt FROM casting_finishing,design_det WHERE casting_finishing.cas_fin_status = 'no' AND design_det.design_det_id = casting_finishing.design_det_id AND design_det.statu_s='active' AND design_det.up_status='no' AND casting_finishing.up_status='no'";
			$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//$SLCT_t = "SELECT COUNT(soldering_loading_id) AS tot_cnt FROM soldering_loading WHERE soldering_status = 'no'";			
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT sol_finishing_des.* FROM sol_finishing_des,design_det WHERE sol_fin_status = 'no' AND design_det.design_det_id = sol_finishing_des.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM soldering_loading WHERE soldering_status = 'no' ORDER BY design_det_id ASC";	
			//$SLCT = "SELECT * FROM casting_finishing,design_det WHERE casting_finishing.cas_fin_status = 'no' AND design_det.design_det_id = casting_finishing.design_det_id AND design_det.statu_s='active' AND design_det.up_status='no' AND casting_finishing.up_status='no' ORDER BY casting_finishing.design_det_id ASC";
			$dpa_name = "In Soldering Finishing";
		}
		else if($dep_id==10)
		{
			//$SLCT_t = "SELECT COUNT(buf_loading_id) AS tot_cnt FROM buf_loading WHERE buf_status = 'no'";
			$SLCT_t = "SELECT COUNT(buf_finishing_des_id) AS tot_cnt FROM buf_finishing_des WHERE buf_fin_status ='no' AND up_status='no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
						
			$SLCT = "SELECT buf_finishing_des.* FROM buf_finishing_des,design_det WHERE buf_fin_status ='no' AND up_status='no' AND design_det.design_det_id = buf_finishing_des.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM buf_loading WHERE buf_status = 'no' ORDER BY design_det_id ASC";
			$dpa_name = "In Buffing Finishing";
		}
		else if($dep_id==11)
		{
			$SLCT_t = "SELECT COUNT(buf_finishing_des_id) AS tot_cnt FROM buf_finishing_des WHERE buf_fin_status ='no' AND up_status='no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT buf_finishing_des.* FROM buf_finishing_des,design_det WHERE buf_fin_status ='no' AND buf_finishing_des.up_status='no' AND design_det.design_det_id = buf_finishing_des.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "In Master Pieces";
		}
		else if($dep_id==12)
		{
			$SLCT_t = "SELECT  COUNT(mas_finishing_id) AS tot_cnt FROM mas_finishing WHERE show_status ='no' AND up_status='no'";
			//echo $SLCT_t;
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT mas_finishing.* FROM mas_finishing,design_det WHERE show_status ='no' AND mas_finishing.up_status='no' AND design_det.design_det_id = mas_finishing.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "In Show Case";
		}
		else if($dep_id==13)
		{
			if(isset($_GET['lim']))
			{
				$st_va  = base64_decode(base64_decode(base64_decode($_GET['lim'])));//$_GET['st_val'];
			}
			else
			{
				$st_va  = 0;
			}
			$cat_id  = base64_decode(base64_decode(base64_decode(base64_decode($_GET['cat_id']))));//$_GET['st_val'];
			
			
			$ed_va  = 250;//$_GET['ed_val'];
			
			$SLCT_t = "SELECT COUNT(show_case_id) AS tot_cnt FROM show_case WHERE master_cat_id = '$cat_id'";
			//echo $SLCT_t;
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT * FROM show_case WHERE master_cat_id = '$cat_id' ORDER BY `master_cat_id`,`design_no` ASC LIMIT $st_va,$ed_va";
			$dpa_name = "In Show Case";
		}
		/*else if($dep_id==14)
		{
			$SLCT_t = "SELECT COUNT(cad_finishing_des_id) AS tot_cnt FROM cad_finishing_des WHERE design_det_id NOT IN(SELECT design_det_id FROM silver_loading) AND cad_finishing_des.to_silver_load = 'yes'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT_d14 = "SELECT * FROM cad_finishing_des WHERE design_det_id NOT IN(SELECT design_det_id FROM silver_loading) AND cad_finishing_des.to_silver_load = 'yes' ORDER BY design_det_id ASC";
			$dpa_name = "In Silver Loading";
		}*/
		else if($dep_id==14)
		{
			$SLCT_t = "SELECT COUNT(silver_loading_id) AS tot_cnt FROM silver_loading WHERE silver_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT silver_loading.* FROM silver_loading,design_det WHERE silver_status = 'no' AND design_det.design_det_id = silver_loading.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "In Silver Loading";
		}
		else if($dep_id==15)
		{
			$SLCT_t = "SELECT COUNT(silver_finishing_id) AS tot_cnt FROM silver_finishing WHERE to_solder_load = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT silver_finishing.* FROM silver_finishing, design_det WHERE to_solder_load = 'no' AND design_det.design_det_id = silver_finishing.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "In Silver Receiving";
		}
		else if($dep_id==16)
		{
			//$SLCT_t = "SELECT COUNT(*) AS tot_cnt FROM (SELECT CF.cast_weight, DD.design_det_id, DD.master_cat_id, DD.design_no, DD.mas_fin_ext, DD.cad_fin_ext, DD.imag_ext FROM casting_finishing AS CF,design_det AS DD WHERE CF.cas_fin_status = 'no' AND DD.design_det_id = CF.design_det_id AND DD.statu_s='active' AND DD.up_status='no' AND CF.up_status='no' UNION ALL SELECT SF.silver_weight, DD.design_det_id, DD.master_cat_id, DD.design_no, DD.mas_fin_ext, DD.cad_fin_ext, DD.imag_ext FROM silver_finishing AS SF,design_det DD WHERE SF.to_solder_load = 'no' AND DD.design_det_id = SF.design_det_id AND DD.statu_s='active' AND DD.up_status='no') AS TBL2";
			//echo $SLCT_t
			$SLCT_t = "SELECT COUNT(soldering_loading_id) AS tot_cnt FROM soldering_loading WHERE soldering_status = 'no'";
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
								
			$SLCT = "SELECT soldering_loading.*,emp_det.name AS emp_det_nm FROM soldering_loading,design_det,emp_det WHERE soldering_status = 'no' AND design_det.design_det_id = soldering_loading.design_det_id AND emp_det.emp_det_id = soldering_loading.emp_det_id ORDER BY emp_det.emp_det_id, design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM (SELECT CF.cast_weight, CF.post_dt, DD.design_det_id, DD.master_cat_id, DD.design_no, DD.mas_fin_ext, DD.cad_fin_ext, DD.imag_ext FROM casting_finishing AS CF,design_det AS DD WHERE CF.cas_fin_status = 'no' AND DD.design_det_id = CF.design_det_id AND DD.statu_s='active' AND DD.up_status='no' AND CF.up_status='no' UNION ALL SELECT SF.silver_weight, SF.post_dt, DD.design_det_id, DD.master_cat_id, DD.design_no, DD.mas_fin_ext, DD.cad_fin_ext, DD.imag_ext FROM silver_finishing AS SF,design_det DD WHERE SF.to_solder_load = 'no' AND DD.design_det_id = SF.design_det_id AND DD.statu_s='active' AND DD.up_status='no') AS TBL2 ORDER BY design_det_id ASC";
			$dpa_name = "In Soldering Loading";
		}
		else if($dep_id==17)
		{
			$SLCT_t = "SELECT COUNT(buf_loading_id) AS tot_cnt FROM buf_loading WHERE buf_status = 'no'";
			//$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT buf_loading.* FROM buf_loading,design_det WHERE buf_status = 'no' AND design_det.design_det_id = buf_loading.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM sol_finishing_des WHERE sol_fin_status = 'no' ORDER BY design_det_id ASC";
			$dpa_name = "In Buffing Loading";
		}	
		
		else if($dep_id==19)
		{
			$SLCT_t = "SELECT COUNT(emp_current_design_id) AS tot_cnt FROM emp_current_design WHERE curr_status = 'finished' AND `design_det_id` NOT IN (SELECT `design_det_id` FROM cad_finishing_des)";
			//$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT emp_current_design.* FROM emp_current_design,design_det WHERE curr_status = 'finished' AND emp_current_design.`design_det_id` NOT IN (SELECT `design_det_id` FROM cad_finishing_des) AND design_det.design_det_id = emp_current_design.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM sol_finishing_des WHERE sol_fin_status = 'no' ORDER BY design_det_id ASC";
			$dpa_name = "Waiting for Approval - Finished";
		}	
		
		else if($dep_id==20)
		{
			$SLCT_t = "SELECT COUNT(emp_current_design_id) AS tot_cnt FROM emp_current_design WHERE curr_status = 'waiting' AND `design_det_id` NOT IN (SELECT `design_det_id` FROM cad_finishing_des)";
			//$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT emp_current_design.* FROM emp_current_design, design_det WHERE curr_status = 'waiting' AND emp_current_design.`design_det_id` NOT IN (SELECT `design_det_id` FROM cad_finishing_des) AND design_det.design_det_id = emp_current_design.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM sol_finishing_des WHERE sol_fin_status = 'no' ORDER BY design_det_id ASC";
			$dpa_name = "Waiting for Approval - Waiting";
		}
		
		else if($dep_id==21)
		{
			$SLCT_t = "SELECT COUNT(emp_current_design_id) AS tot_cnt FROM emp_current_design WHERE curr_status = 'closed' AND `design_det_id` IN (SELECT `design_det_id` FROM cad_finishing_des WHERE cad_fin_status='no')";
			//$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//echo $SLCT_t;
			//echo "<br>";
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT emp_current_design.* FROM emp_current_design,design_det WHERE curr_status = 'closed' AND emp_current_design.`design_det_id` IN (SELECT `design_det_id` FROM cad_finishing_des WHERE cad_fin_status='no') AND design_det.design_det_id = emp_current_design.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//echo $SLCT;
			$dpa_name = "CAD Finish";
		}
		
		else if($dep_id==22)
		{
			$SLCT_t = "SELECT COUNT(*) AS tot_cnt FROM cad_finishing_des WHERE `to_rtv_load` = 'no' AND `to_silver_load` = 'no' AND `cad_fin_status` = 'no' AND design_det_id IN(SELECT design_det_id FROM cam_loading WHERE cam_status='no')";
			//$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT cad_finishing_des.* FROM cad_finishing_des, design_det WHERE `to_rtv_load` = 'no' AND `to_silver_load` = 'no' AND `cad_fin_status` = 'no' AND cad_finishing_des.design_det_id IN(SELECT design_det_id FROM cam_loading WHERE cam_status='no') AND design_det.design_det_id = cad_finishing_des.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM sol_finishing_des WHERE sol_fin_status = 'no' ORDER BY design_det_id ASC";
			$dpa_name = "CAD Finish - CAM Pending";
		}
		
		else if($dep_id==23)
		{
			$SLCT_t = "SELECT COUNT(*) AS tot_cnt FROM cad_finishing_des WHERE `to_rtv_load` = 'yes' AND `cad_fin_status` = 'no'";
			//$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT cad_finishing_des.* FROM cad_finishing_des,design_det WHERE `to_rtv_load` = 'yes' AND `cad_fin_status` = 'no' AND design_det.design_det_id = cad_finishing_des.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM sol_finishing_des WHERE sol_fin_status = 'no' ORDER BY design_det_id ASC";
			$dpa_name = "CAD Finish - RTV Pending";
		}
		
		else if($dep_id==24)
		{
			$SLCT_t = "SELECT COUNT(*) AS tot_cnt FROM cad_finishing_des WHERE `to_silver_load` = 'yes' AND design_det_id NOT IN (SELECT design_det_id FROM silver_loading)";
			//$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt - 1;
			
			$SLCT = "SELECT cad_finishing_des.* FROM cad_finishing_des,design_det WHERE `to_silver_load` = 'yes' AND cad_finishing_des.design_det_id NOT IN (SELECT design_det_id FROM silver_loading) AND design_det.design_det_id = cad_finishing_des.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM sol_finishing_des WHERE sol_fin_status = 'no' ORDER BY design_det_id ASC";
			$dpa_name = "CAD Finish - Silver Pending";
		}
		else if($dep_id==25)
		{
			//$SLCT_t = "SELECT COUNT(cad_loading_id) AS tot_cnt FROM cad_loading WHERE design_det_id NOT IN(SELECT design_det_id FROM emp_current_design) AND emp_det_id!=0";
			$SLCT_t = "SELECT COUNT(cad_loading_id) AS tot_cnt FROM cad_loading WHERE emp_det_id!=0 AND `cad_status`='no' AND `design_det_id` NOT IN(SELECT `design_det_id` FROM emp_current_design)";
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
//			$SLCT = "SELECT cad_loading.*,emp_det.name AS emp_det_nm FROM cad_loading,design_det,emp_det WHERE cad_loading.design_det_id NOT IN(SELECT design_det_id FROM emp_current_design) AND cad_loading.emp_det_id!=0 AND cad_loading.design_det_id NOT IN (SELECT design_det_id FROM emp_current_design) AND design_det.design_det_id = cad_loading.design_det_id AND emp_det.emp_det_id = cad_loading.emp_det_id ORDER BY emp_det.emp_det_id, design_det.master_cat_id, design_det.design_det_id ASC";

			$SLCT = "SELECT cad_loading.*,emp_det.name AS emp_det_nm FROM cad_loading,design_det,emp_det WHERE cad_loading.emp_det_id!=0 AND cad_loading.cad_status='no' AND cad_loading.design_det_id NOT IN(SELECT design_det_id FROM emp_current_design) AND design_det.design_det_id = cad_loading.design_det_id AND emp_det.emp_det_id = cad_loading.emp_det_id ORDER BY emp_det.emp_det_id, design_det.master_cat_id, design_det.design_det_id ASC";
			
			$dpa_name = "CAD Loading - Allort Design";
		}	
		else if($dep_id==26)
		{
			$SLCT_t = "SELECT COUNT(casting_finishing_id) AS tot_cnt FROM casting_finishing WHERE cas_fin_status = 'no' AND up_status='no'";
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT casting_finishing.* FROM casting_finishing, design_det WHERE cas_fin_status = 'no' AND casting_finishing.up_status='no' AND design_det.design_det_id = casting_finishing.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "Casting Pending";
		}	
		
		else if($dep_id==27)
		{
			$SLCT_t = "SELECT COUNT(emp_current_design_id) AS tot_cnt FROM emp_current_design WHERE curr_status = 'process' AND `design_det_id` NOT IN (SELECT `design_det_id` FROM cad_finishing_des)";
			//$SLCT_t = "SELECT COUNT(sol_finishing_id) AS tot_cnt FROM sol_finishing_des WHERE sol_fin_status = 'no'";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			
			$SLCT = "SELECT emp_current_design.* FROM emp_current_design,design_det WHERE curr_status = 'process' AND emp_current_design.`design_det_id` NOT IN (SELECT `design_det_id` FROM cad_finishing_des) AND design_det.design_det_id = emp_current_design.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			//$SLCT = "SELECT * FROM sol_finishing_des WHERE sol_fin_status = 'no' ORDER BY design_det_id ASC";
			$dpa_name = "Work in Process";
		}
	}
	
	//echo $dep_id."<br>".$SLCT;
	$QURY = mysqli_query($connect,$SLCT);
	
	$des_id = array();
	$des_det_id = array();
	$des_ext = array();
	$i=1;			
	$del_date = '';
	while($FTCH = mysqli_fetch_object($QURY))
	{
		//echo $i;
		$del_date = $FTCH->post_dt;
		$design_id	=	base64_encode(base64_encode(base64_encode($FTCH->design_det_id)));
		//echo "<br>";
		//echo
		$SLCT_t = "SELECT * FROM design_det WHERE design_det_id = '$FTCH->design_det_id'";
		$QURY_t = mysqli_query($connect,$SLCT_t);
		$FTCH_t = mysqli_fetch_object($QURY_t);
		//echo "<br>";
		//echo
		$SLCT_cat = "SELECT * FROM  master_cat WHERE  master_cat_id= '$FTCH_t->master_cat_id'";
		$QURY_cat = mysqli_query($connect,$SLCT_cat);
		$FTCH_cat = mysqli_fetch_object($QURY_cat);
		//echo "<br>";
		//echo
		$SLCT_or = "SELECT COUNT(design_det_id) AS or_cnt FROM po_entry_det WHERE cancelled = 'no' AND design_det_id = '$FTCH->design_det_id' AND fin_status = 'no'"; 
		$QURY_or = mysqli_query($connect,$SLCT_or);
		$FTCH_or = mysqli_fetch_object($QURY_or);
		//echo "<br>";
		//echo
		$SLCT_st = "SELECT COUNT(design_det_id) AS st_cnt FROM stock_det WHERE st_fin_status = 'no' AND design_det_id = '$FTCH->design_det_id'";
		$QURY_st = mysqli_query($connect,$SLCT_st);
		$FTCH_st = mysqli_fetch_object($QURY_st);
		
		$or_cnt[$i] = $FTCH_or->or_cnt;
		$st_cnt[$i] = $FTCH_st->st_cnt;
		
		$des_det_id[$i] = $FTCH_t->design_det_id;
		$des_id[$i] = $FTCH_cat->master_cat_name." ".$FTCH_t->design_no;
		if($dep_id==13)
		{
			$SLCT_mas = "SELECT * FROM mas_finishing WHERE design_det_id = '$FTCH->design_det_id'";
			$QURY_mas = mysqli_query($connect,$SLCT_mas);
			$FTCH_mas = mysqli_fetch_object($QURY_mas);
			$weigh[$i] = number_format($FTCH_mas->mas_weight,2)." g"; 
		}
		else
		{
			$weigh[$i] = '';
		}
		if($dep_id==25 || $dep_id==16)
		{
			$emp_det_nm[$i] = $FTCH->emp_det_nm;
		}
		else
		{
			$emp_det_nm[$i] = '';
		}
		/*$des_ext[$i] = $FTCH_t->imag_ext; */
		if($FTCH_t->mas_fin_ext!=''){ if(file_exists("../mas_fin_images/L.".$FTCH_t->mas_fin_ext)){ $des_ext[$i] = "../mas_fin_images/L.".$FTCH_t->mas_fin_ext; }else{ $des_ext[$i] = "../design_images/not_found/not-found.jpg"; } }

		else if($FTCH_t->cad_fin_ext!='')
		{ 
			if(file_exists("../cad_fin_images/L.".$FTCH_t->cad_fin_ext))
			{  
			//	echo "<br>";
			//	echo 
				$des_ext[$i] = "../cad_fin_images/L.".$FTCH_t->cad_fin_ext;
			//	echo "<br><br>";
			}
			else
			{ 
				$des_ext[$i] = "../design_images/not_found/not-found.jpg"; 
			} 
		}
		
		else if($FTCH_t->imag_ext!=''){ if(file_exists("../design_images/L.".$FTCH_t->imag_ext)){ $des_ext[$i] = "../design_images/L.".$FTCH_t->imag_ext; }else{ $des_ext[$i] = "../design_images/not_found/not-found.jpg"; } }
		$i++;
	}
	$ro_vl = 5; //this is important when u change the table column u should change this
	$arr_len = sizeof($des_ext);
	
	if($flg!=1){ $po_die_qty = $tot_cnt; $pen_qty = $po_die_qty-$arr_len;  } else{ $po_die_qty = $arr_len; $pen_qty = '0'; } //this is for po entry qty
	//echo $flg;
	//echo $arr_len."<br/>";
	//echo $po_die_qty;
	if($arr_len > $ro_vl)
	{ 
		$cnt = $arr_len/$ro_vl;
		$cnt = floor($cnt+1);
	}
	else
	{
		$cnt =1;
	}
	//echo $cnt;
	
	
		
	$pdf = new FPDF('P','mm','A4');		
	//THIS IS FOR CREATING THE OBJECTS	 
	$pdf->AddPage();	
	$pdf->SetAutoPageBreak(false); 	
	$pdf->SetMargins(0.5,0.5,0.5,0.5);
	$br=0; //this is for border value;
	$br_l='L'; //this is for border value for table data;
	$pdf->SetX(0);
	$pdf->SetY(0);
	if($dep_id==13)
	{
		$v1 = $st_va +1; 
		$v2 = $v1 + 24; 
		if($v2<$tot_cnt)
		{
			$v2_end = $v2;
		}
		else if($v2>=$tot_cnt)
		{
			$v2_end = $tot_cnt;
		}  	
		$pdf->Cell(296,6,'','',1,'C');//for empty space 
		$pdf->SetFont('Times','B',11);
		$pdf->Cell(0,6,$v1.' - '.$v2_end,0,0,'C');
		$pdf->Cell(296,6,'','',1,'C');//for empty space 
	}
	else
	{
		$pdf->SetFont('Times','',11);
		$pdf->Cell(296,2,'',0,1,'C');//for empty space 
		$pdf->Cell(75,6,'Departmet Name : '.$dpa_name,$br,0,'L');
		
		$pdf->SetFont('Times','',11);
		$pdf->Cell(80,6,'Date : '.date("d/m/Y",strtotime($cur_date)),$br,0,'C');
		
		/*$pdf->SetFont('Times','',11);
		$pdf->Cell(60,6,'',$br,0,'R');*/ 
		//$pdf->Cell(45,6,'Page '.$cnt,$br,1,'C');
		$pdf->Cell(45,6,'Pending Quantity : '.$tot_cnt,$br,1);
		
		$pdf->SetFont('Times','',11);
		$pdf->Cell(296,6,'','T',1,'C');//for empty space 
	}
	$l=1; 
	$tot_ro = '';
	$image_height = 40;
	$image_width = 40;
	$pdf->SetFont('Times','',10);
	for($i=1;$i<=$cnt;$i++) 
	{
		for($k=1;$k<=$ro_vl;$k++)
		{
			if(isset($des_ext[$l]))
			{
				$start_x = $pdf->GetX();
   				$start_y = $pdf->GetY();
   
				//$pdf->Cell(40,40,,1,0,'C');//for empty space 
				$pdf->Image($des_ext[$l],$start_x,$start_y,$image_height,$image_width);
				$pdf->SetXY($start_x,$start_y+40); // this is for design no cordinate positions
				$pdf->Cell(40,5,$des_id[$l],0,1,'C');//for design no  
				$pdf->SetXY($start_x,$start_y+45); // this is for design no cordinate positions
				if($dep_id==25 || $dep_id==16)
				{
				 	$pdf->Cell(40,5,$emp_det_nm[$l],0,0,'C');//for design weight
				}
				else
				{
					 $pdf->Cell(40,5,$weigh[$l],0,0,'C');//for design weight
				}
				 
				if($flg==1 && $inflg==1)
				{
				 	$pdf->SetXY($start_x,$start_y+46); // this is for design no cordinate positions
					$pdf->Cell(40,5,$or_cnt[$l]. " / " .$st_cnt[$l],0,0,'C');//for stock and pending
				}
				
				$pdf->SetXY($start_x + $image_width + 2, $start_y); //this is for image cordinate positions
				if($dep_id!=13)
				{
					if($l==25)
					{
						$pdf->SetY(-15);
						$pdf->SetFont('Arial','I',8);
						$pdf->Cell(0,10,'Page '.$pdf->PageNo()." / {nb}",0,0,'C');
						$pdf->SetFont('Times','',11);
					}
				}
				$tot_ro = $l % 25 ;
				if($dep_id==13)
				{
					$end_vl = 250;
				}
				else if($dep_id!=13)
				{
					$end_vl = 1600;
				}
				if($tot_ro == 0 && $l<$end_vl)
				{ 
					$pdf->AddPage();
					if($dep_id!=13)
					{
						$pdf->AliasNbPages();
						$pdf->SetY(-15);
					    // Select Arial italic 8
					    $pdf->SetFont('Arial','I',8);
					    // Print centered page number
					    $pdf->Cell(0,10,'Page '.$pdf->PageNo()." / {nb}",0,0,'C');
					    $pdf->SetFont('Times','',11);
					}
				}
			}
			$l++;
		}
		
		if($tot_ro!=0)
		{	
			$pdf->SetXY(0, $start_y+$image_height+13); 
		}
		else if($tot_ro==0)
		{ 
			if($dep_id==13 && $l<250) 
			{ 
				$v1 = $st_va + $l; 
				$v2 = $v1 + 24;
				if($v2<$tot_cnt)
				{
					$v2_end = $v2;
				}
				else if($v2>=$tot_cnt)
				{
					$v2_end = $tot_cnt;
				} 
				$pdf->Cell(296,6,'','',1,'C');//for empty space 
				$pdf->SetFont('Times','B',11);
				$pdf->Cell(0,6,$v1.' - '.$v2_end,0,0,'C');
				$pdf->Cell(296,6,'','',1,'C');//for empty space 
				$pdf->SetFont('Times','',11);
			} 
			else 
			{ 
				$pdf->SetXY(0,0);
				
			}
		}				
	}
	
	$pdf->Output(); //THIS IS FOR OUTPUT OF THE P
?>