<?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']))); 
	$key_det	=	base64_decode(base64_decode(base64_decode($_GET['key_det']))); 
	$nxt_det	=	base64_decode(base64_decode(base64_decode($_GET['nxt_det']))); 
	if(isset($_GET['lod_tim']) && $_GET['lod_tim']!='')
	{
		$ld_tim = base64_decode(base64_decode(base64_decode($_GET['lod_tim']))); 
	}
	else
	{
		$ld_tim = '';
	}
	$flg	=	2;
	if(isset($_GET['inflg'])){ $inflg = 1; }else{ $inflg = 2; }
	//echo $flg; 

		
	$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  `cam_loading` WHERE  `loading_date` LIKE  '$key_det'";
			//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_loading.* FROM `cam_loading`,design_det WHERE `loading_date` LIKE '$key_det' 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 = "CAM LOADING";
		}
		else if($dep_id==2)
		{
			$SLCT_t = "SELECT COUNT(design_det_id) AS tot_cnt FROM cam_finishing WHERE finishing_date  LIKE  '$key_det'";
			//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 finishing_date LIKE  '$key_det' 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 = "CAM RECEIVING";
		}
		else if($dep_id==3)
		{
			$SLCT_t = "SELECT COUNT(design_det_id) AS tot_cnt FROM rtv_loading WHERE `loading_date` LIKE  '$key_det'";
			//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  `loading_date` LIKE  '$key_det' 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 = "RTV LOADING";
		}
		else if($dep_id==4)
		{
			$SLCT_t = "SELECT COUNT(design_det_id) AS tot_cnt FROM wax_finishing WHERE finishing_date LIKE  '$key_det'";
			//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 wax_finishing.* FROM wax_finishing,design_det WHERE finishing_date LIKE  '$key_det' AND design_det.design_det_id = wax_finishing.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "WAX FINISHING";
		}
		else if($dep_id==5)
		{
			$SLCT_t = "SELECT COUNT(design_det_id) AS tot_cnt FROM casting_finishing WHERE finishing_date LIKE  '$key_det'";
			//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 casting_finishing.* FROM casting_finishing,design_det WHERE finishing_date LIKE  '$key_det' 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 FINISHING";
		}
		else if($dep_id==6)
		{
			$SLCT_t = "SELECT COUNT(sol_finishing_des_id) AS tot_cnt, IFNULL(SUM(master_pice),'0') AS master_pice FROM sol_finishing_des,sol_finishing  WHERE sol_finishing.emp_det_id  =  '$nxt_det' AND  sol_finishing.finishing_date LIKE  '$key_det' AND sol_finishing.sol_finishing_id = sol_finishing_des.sol_finishing_id";
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			$tot_pic = $FTCH_t->master_pice;
			
			$SLCT = "SELECT sol_finishing_des.*,sol_finishing.* FROM sol_finishing_des,sol_finishing,design_det WHERE sol_finishing.emp_det_id  =  '$nxt_det' AND  sol_finishing.finishing_date LIKE  '$key_det' AND sol_finishing.sol_finishing_id = sol_finishing_des.sol_finishing_id 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";
			$dpa_name = "SOLDERING FINISHING";
		}
		else if($dep_id==7)
		{
			$SLCT_t = "SELECT COUNT(buf_finishing_des_id) AS tot_cnt, IFNULL(SUM(master_pieces),0) AS master_pice FROM buf_finishing_des,buf_finishing,design_det WHERE buf_finishing.emp_det_id  =  '$nxt_det' AND  buf_finishing.finishing_date LIKE  '$key_det' AND buf_finishing.buf_finishing_id = buf_finishing_des.buf_finishing_id AND design_det.design_det_id=buf_finishing_des.design_det_id";
			//echo $SLCT_t
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			$tot_pic = $FTCH_t->master_pice;
			
			$SLCT = "SELECT buf_finishing_des.*,buf_finishing.* FROM buf_finishing_des,buf_finishing,design_det WHERE buf_finishing.emp_det_id  =  '$nxt_det' AND  buf_finishing.finishing_date LIKE  '$key_det' AND buf_finishing.buf_finishing_id = buf_finishing_des.buf_finishing_id 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 = "BUFFING FINISHING";
		}
		else if($dep_id==8)
		{
			$SLCT_t = "SELECT COUNT(design_det_id) AS tot_cnt FROM mas_finishing WHERE finishing_date LIKE  '$key_det'";
			//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 finishing_date LIKE  '$key_det' 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 = "Master Pieces";
		}
		else if($dep_id==9)
		{
			$SLCT_t = "SELECT  COUNT(design_det_id) AS tot_cnt FROM show_case WHERE show_date LIKE  '$key_det'";
			//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 show_date LIKE '$key_det' ORDER BY master_cat_id, design_det_id ASC";
			$dpa_name = "Show Case";
		}
		else if($dep_id==10)
		{
			$SLCT_t = "SELECT COUNT(sol_finishing_des_id) AS tot_cnt FROM sol_finishing_des,design_det WHERE sol_finishing_des.sol_fin_status = 'no' AND design_det.up_status='no'
			AND design_det.design_det_id = sol_finishing_des.design_det_id AND design_det.statu_s='active' AND sol_finishing_des.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 sol_finishing_des,design_det WHERE sol_finishing_des.sol_fin_status = 'no' AND design_det.up_status='no'
			AND design_det.design_det_id = sol_finishing_des.design_det_id AND design_det.statu_s='active' AND sol_finishing_des.up_status='no' ORDER BY design_det.master_cat_id, sol_finishing_des.design_det_id ASC";
			$dpa_name = "In Buffing";
		}
		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 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 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)
		{
			$st_va  = base64_decode(base64_decode(base64_decode($_GET['lim'])));//$_GET['st_val'];
			$ed_va  = 250;//$_GET['ed_val'];
			$SLCT_t = "SELECT  COUNT(show_case_id) AS tot_cnt FROM show_case";
			$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 ORDER BY `master_cat_id`,`design_no` ASC LIMIT $st_va,$ed_va";
			$dpa_name = "In Show Case";
		}
		if($dep_id==14)
		{
			$SLCT_t = "SELECT COUNT(design_det_id) AS tot_cnt FROM  `silver_loading` WHERE  `loading_date` LIKE  '$key_det'";
			//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  `loading_date` LIKE  '$key_det' 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 = "SILVER LOADING";
		}
		else if($dep_id==15)
		{
			$SLCT_t = "SELECT COUNT(design_det_id) AS tot_cnt FROM silver_finishing WHERE finishing_date  LIKE  '$key_det'";
			//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 finishing_date LIKE  '$key_det' 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 = "SILVER RECEIVING";
		}
		if($dep_id==16)
		{
			$kdm_id	=	base64_decode(base64_decode(base64_decode($_GET['kdm_id'])));
			
			$SLCT_t = "SELECT COUNT(soldering_loading.design_det_id) AS tot_cnt, GROUP_CONCAT(soldering_loading.design_det_id) AS desin_id, IFNULL(SUM(no_of_pieces),'0') AS no_pieces FROM `soldering_loading`,design_det WHERE design_det.design_det_id = soldering_loading.design_det_id AND soldering_loading.emp_det_id  =  '$nxt_det'  AND sol_loading_kdm_id = '$kdm_id' AND `loading_date` LIKE  '$key_det'";
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			$tot_pice = $FTCH_t->no_pieces;
			
			/*$SLCT_KDM= "SELECT sol_loading_kdm_id FROM soldering_loading WHERE design_det_id IN($FTCH_t->desin_id)";
			$QURY_KDM = mysqli_query($connect,$SLCT_KDM);
			$FTCH_KDM = mysqli_fetch_object($QURY_KDM);*/
			
			$SLCT_KDM1 = "SELECT SUM(kdm_loading_weight) AS kdm_loading_weight FROM sol_loading_kdm WHERE sol_loading_kdm_id = '$kdm_id'";
			$QURY_KDM1 = mysqli_query($connect,$SLCT_KDM1);
			if(mysqli_num_rows($QURY_KDM1)>0)
			{
				$FTCH_KDM1 = mysqli_fetch_object($QURY_KDM1);
				if($FTCH_KDM1->kdm_loading_weight!='')
				{
					$kdm_wght = $FTCH_KDM1->kdm_loading_weight;
				}
				else
				{
					$kdm_wght = "0.00";
				}
			}
			else
			{
				$kdm_wght = "0.00";
			}
			
			$SLCT = "SELECT soldering_loading.* FROM  `soldering_loading`,design_det WHERE soldering_loading.emp_det_id  =  '$nxt_det'  AND sol_loading_kdm_id = '$kdm_id' AND `loading_date` LIKE '$key_det' AND design_det.design_det_id = soldering_loading.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "SOLDERING LOADING";
		}	
		if($dep_id==17)
		{
			$SLCT_t = "SELECT COUNT(buf_loading.design_det_id) AS tot_cnt,IFNULL(SUM(master_pieces),'0') AS master_pice FROM `buf_loading`,design_det WHERE `loading_date` LIKE '$key_det' AND design_det.design_det_id=buf_loading.design_det_id";
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);
			$tot_cnt = $FTCH_t->tot_cnt;
			$tot_pic = $FTCH_t->master_pice;
			
			$SLCT = "SELECT buf_loading.* FROM `buf_loading`,design_det WHERE `loading_date` LIKE '$key_det' AND design_det.design_det_id = buf_loading.design_det_id ORDER BY design_det.master_cat_id,design_det.design_det_id ASC";
			$dpa_name = "BUFFING LOADING";
		}		
	}
	$QURY = mysqli_query($connect,$SLCT);
	
	$des_id = array();
	$des_det_id = array();
	$des_ext = array();
	$tot_wt = 0;
	$i=1;			
	$del_date = '';
	while($FTCH = mysqli_fetch_object($QURY))
	{
		$del_date = $FTCH->post_dt;
		$design_id	=	base64_encode(base64_encode(base64_encode($FTCH->design_det_id)));
		
		$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);
		
		$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);
		
		$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);
		
		$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 if($dep_id==16)
		{
			$SLCT_sl= "SELECT * FROM soldering_loading WHERE design_det_id = '$FTCH->design_det_id'";
			$QURY_sl = mysqli_query($connect,$SLCT_sl);
			$FTCH_sl = mysqli_fetch_object($QURY_sl);
			$weigh[$i] = number_format($FTCH_sl->solder_weight,2)." g"; 
			
			$tot_wt = $tot_wt + $FTCH_sl->solder_weight;
			
			$SLCT_emp= "SELECT * FROM emp_det WHERE emp_det_id = '$FTCH->emp_det_id'";
			$QURY_emp = mysqli_query($connect,$SLCT_emp);
			$FTCH_emp = mysqli_fetch_object($QURY_emp);
		}
		else if($dep_id==9)
		{
			$SLCT_sl= "SELECT * FROM  mas_finishing WHERE design_det_id = '$FTCH->design_det_id'";
			$QURY_sl = mysqli_query($connect,$SLCT_sl);
			$FTCH_sl = mysqli_fetch_object($QURY_sl);
			$weigh[$i] = number_format($FTCH_sl->mas_weight,2)." g"; 
		}
		else
		{
			$weigh[$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)){  $des_ext[$i] = "../cad_fin_images/L.".$FTCH_t->cad_fin_ext; }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');
	$pdf->AliasNbPages();		
	//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;  
		$pdf->Cell(296,6,'','',1,'C');//for empty space 
		$pdf->SetFont('Times','B',11);
		$pdf->Cell(0,6,$v1.' - '.$v2,0,0,'C');
		$pdf->Cell(296,6,'','',1,'C');//for empty space 
	}
	else
	{
		if($dep_id==16)
		{
			$pdf->SetFont('Times','',11);
			$pdf->Cell(8,2,'',0,0,'C');//for empty space 
			$pdf->Cell(70,10,'Name : '.$FTCH_emp->name." ");
			$pdf->Cell(70,10,'Date   : '.$key_det.' '.$ld_tim,$br,0);
			$pdf->Cell(45,10,'No. Of Designs : '.$tot_cnt.' ('.$tot_pice.' pcs)',$br,1);
			$pdf->Cell(8,2,'',0,0,'C');//for empty space
			$pdf->Cell(70,8,'Design Weight : '.number_format($tot_wt,2).' g',$br,0);
			$pdf->Cell(70,8,'KDM Loading Weight : '.number_format($kdm_wght,2).' g',$br,0);
			$pdf->Cell(45,8,'Total Weight : '.number_format($kdm_wght+$tot_wt,2).' g',$br,1);
			
			$pdf->SetFont('Times','',11);
			$pdf->Cell(296,6,'','T',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." ");
			
			$pdf->SetFont('Times','',11);
			$pdf->Cell(80,6,'Date : '.$key_det.' '.$ld_tim,$br,0,'C');
			//$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');
			if($dep_id==6 || $dep_id==7 || $dep_id==17)
			{				
				$pdf->Cell(45,6,'No. Of Designs : '.$tot_cnt.' ('.$tot_pic.' pcs)',$br,1);
			}
			else
			{
				$pdf->Cell(45,6,'No. Of Designs : '.$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
				 $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($l==25)
				{
					$pdf->SetY(-15);
					$pdf->SetFont('Arial','I',8);
					$pdf->Cell(0,10,'Page '.$pdf->PageNo()." / {nb}",0,0,'C');
					$pdf->SetFont('Times','',10);
				}
				 $tot_ro = $l % 25 ;
				if($tot_ro == 0)
				{ 
					$pdf->AddPage();
					$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','',10);
				}
			}
			$l++;
		}
		if($l<26)
		{			
			$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','',10);
		}
		if($tot_ro!=0){	$pdf->SetXY(0, $start_y+$image_height+13); }else if($tot_ro==0){ if($dep_id==13) { $v1 = $st_va + $l; $v2 = $v1 + 24;  $pdf->SetFont('Times','B',11); $pdf->Cell(0,10,$v1.' - '.$v2,0,0,'C'); $pdf->SetXY(0,10); $pdf->SetFont('Times','',10); } else { $pdf->SetXY(0,0);} }
		
	}
	$pdf->Output(); //THIS IS FOR OUTPUT OF THE P
?>