<?php 
session_start();
require('../../fpdf/fpdf.php');

class PDF_result extends FPDF {
	function __construct ($orientation = 'L', $unit = 'pt', $format = 'Letter', $margin = 20) {
		$this->FPDF($orientation, $unit, $format);
		$this->SetTopMargin($margin);
		$this->SetLeftMargin($margin);
		$this->SetRightMargin($margin);
		
		$this->SetAutoPageBreak(true, $margin);
	}
	
	function Header () {
	   //  $this->Image('youhack.png',100,15,250);

		$this->SetFont('times', 'B', 20);
		//$this->SetFillColor(36, 96, 84);
		//$this->SetTextColor(225);
		$this->Cell(0, 30, $_SESSION['SESS_CMP'], 0, 1, 'C', false);
		$this->SetFont('times', 'B', 9);
		$this->MultiCell(0, 12, $_SESSION['SESS_CMPADD1'].$_SESSION['SESS_CMPADD1_1'], 0,  'C');
	}
	
 function Footer()
{
   //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //times italic 8
    $this->SetFont('times','I',8);
    //Page number
	$this->Cell(40,10,'Printed On:'.date('d/m/Y  @  H:i'),0,0,'L');
    $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}

	
//function Generate_Table($b_id, $b_dutydate,$b_sttime,  $b_city, $b_billedto, $b_usedby, $b_repadd, $b_package,$b_vehicle,$b_status) {
	function Generate_Table($orderid,$packingdate,$buyercode,$agentcode,$dlvdate,$shipto,$shipvia,$status) {
		
	$this->SetFont('times', 'B', 6);
	$this->SetTextColor(0);
	$w=array(30,40,50,80,90,160,60,100);
//	$this->SetFillColor(94, 188, z);
//$this->SetFillColor(94, 188, 225);
	//$this->SetLineWidth(1);
	$y = $this->GetY();
	$this->SetY($y);
	$this->Cell($w[2], 20, "$orderid[0]", '1', 0, 'C', false);
	$this->Cell($w[2], 20, "$packingdate[0]	", '1', 0, 'C', false);
	//if(!empty($b_sttime[0]))
	$this->Cell($w[4], 20, "$buyercode[0]	", '1', 0, 'L', false);
	$this->Cell($w[7], 20, "$agentcode[0]	", '1', 0, 'L', false);
	$this->Cell($w[3], 20, "$dlvdate[0]", '1', 0, 'C', false);
	$this->Cell($w[5], 20, "$shipto[0]", '1', 0, 'L', false);
	$this->Cell($w[4], 20, "$shipvia[0]", '1', 0, 'C', false);
	//$this->Cell($w[5], 20, "$status[0]", '1', 0, 'C', false);
	//$this->Cell($w[8], 20, "$attendby[0]", '1', 1, 'C', false);
	//$this->Cell($w[3], 20, "$attendby[0]	", '1', 0, 'C', false);
	//$this->Cell($w[3], 20, "$attendmob[0]	", '1', 0, 'C', false);
	$this->Cell($w[3], 20, "$status[0]", '1', 1, 'C', false);
 
	
	//$this->SetLineWidth(0);
	$fill = false;


		$x = $this->GetX();
		$y = $this->GetY();
	
	
	
	/*for ($i = 1; $i < count($b_id); $i++) {
			if($y2>500)
		{
		$this->AddPage();
			$this->SetFont('times', '', 6);
	$this->SetTextColor(0);
//	$this->SetFillColor(94, 188, z);
//$this->SetFillColor(94, 188, 225);
	$this->SetLineWidth(1);
	$this->Cell($w[0], 20, "$b_id[0]", '1', 0, 'L', false);
	$this->Cell($w[1], 20, "$b_dutydate[0]	", '1', 0, 'L', false);
	if(!empty($b_sttime[0]))
	$this->Cell($w[9], 20, "$b_sttime[0]	", '1', 0, 'C', false);
	$this->Cell($w[2], 20, "$b_city[0]", '1', 0, 'L', false);
	$this->Cell($w[3], 20, "$b_billedto[0]", '1', 0, 'C', false);
	$this->Cell($w[4], 20, "$b_usedby[0]", '1', 0, 'L', false);
	$this->Cell($w[5], 20, "$b_repadd[0]", '1', 0, 'C', false);
	
	$this->Cell($w[6], 20, "$b_package[0]	", '1', 0, 'L', false);
	$this->Cell($w[7], 20, "$b_vehicle[0]	", '1', 0, 'L', false);
	$this->Cell($w[8], 20, "$b_status[0]", '1', 1, 'C', false);
 
	$this->SetFont('times', '');*/
	
	for ($i = 1; $i < count($orderid); $i++) {
			if($y2>500)
		{
		$this->AddPage();
		$this->SetFont('times', '', 6);
	$this->SetTextColor(0);
//	$this->SetFillColor(94, 188, z);
//$this->SetFillColor(94, 188, 225);
	$this->SetLineWidth(1);
	$this->Cell($w[2], 20, "$orderid[0]", '1', 0, 'C', false);
	$this->Cell($w[2], 20, "$packingdate[0]	", '1', 0, 'C', false);
	//if(!empty($b_sttime[0]))
	$this->Cell($w[4], 20, "$buyercode[0]	", '1', 0, 'L', false);
	$this->Cell($w[7], 20, "$agentcode[0]	", '1', 0, 'L', false);
	$this->Cell($w[3], 20, "$dlvdate[0]", '1', 0, 'C', false);
	$this->Cell($w[5], 20, "$shipto[0]", '1', 0, 'L', false);
	$this->Cell($w[4], 20, "$shipvia[0]", '1', 0, 'C', false);
	/*$this->Cell($w[5], 20, "$status[0]", '1', 0, 'C', false);
	$this->Cell($w[3], 20, "$attendby[0]", '1', 1, 'C', false);
 	$this->Cell($w[7], 20, "$attendmob[0]	", '1', 0, 'C', false);*/
	$this->Cell($w[3], 20, "$status[0]", '1', 1, 'C', false);
	$this->SetFont('times', '');
	
	//$this->SetLineWidth(0.2);
	$fill = false;
		$y = $this->GetY();
	$this->SetY($y);
		
		}
		$this->SetFont('times', '',8);
		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[2], 10, $orderid[$i], 0,  'C', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x+$w[2], $this->GetY() - $yH);
		
		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[2], 10, $packingdate[$i], 0, 'C', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[2], $this->GetY() - $yH);
		$y_check=$y2;
		
	//	if(!empty($b_sttime[0]))
		
		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[4], 10, $buyercode[$i], 0, 'L', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[4], $this->GetY() - $yH);
		$y_check=$y2;
		
		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[4],10, $agentcode[$i], 0, 'L', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[4], $this->GetY() - $yH);
		if($y2>$y_check)
		$y_check=$y2;
		
		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[4], 10, $dlvdate[$i], 0, 'C', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[4], $this->GetY() - $yH);
		if($y2>$y_check)
		$y_check=$y2;

		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[5], 10, $shipto[$i], 0, 'L', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[5], $this->GetY() - $yH);
		if($y2>$y_check)
		$y_check=$y2;
	
		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[4], 10, iconv('UTF-8', 'windows-1252', $shipvia[$i]), 0, 'L', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[4], $this->GetY() - $yH);
		if($y2>$y_check)
		$y_check=$y2;
		
		
		
		/*$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[5], 10,  iconv('UTF-8', 'windows-1252',$transport[$i]), 0, 'L', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[5], $this->GetY() - $yH);
		if($y2>$y_check)
		$y_check=$y2;
		
		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[3], 10,  iconv('UTF-8', 'windows-1252',$attendby[$i]), 0, 'L', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[3], $this->GetY() - $yH);
		if($y2>$y_check)
		$y_check=$y2;
		
		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[3], 10,  iconv('UTF-8', 'windows-1252',$attendmob[$i]), 0, 'L', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[3], $this->GetY() - $yH);
		if($y2>$y_check)
		$y_check=$y2;*/
		
		
	
		$this->MultiCell($w[3], 10, $status[$i], 0,  'L', $fill);
		$this->SetY($y_check-18);
		$this->Ln(20);
		$fill = $fill;
		}
	$this->SetX(367);

}
	
	
	
	
	
	
}

$pdf = new PDF_result();
$pdf->AddPage();


$pdf->Ln(5);

$pdf->Generate_Table($_POST['orderid'], $_POST['packingdate'],$_POST['buyercode'], $_POST['agentcode'], $_POST['dlvdate'], $_POST['shipto'], $_POST['shipvia'], $_POST['status']);



$pdf->Output('preceivingdet_export_pdf.pdf', 'F');


?>
