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


class PDF_result extends FPDF {

	function __construct ($orientation = 'P', $unit = 'pt', $format = 'A4', $margin = 10) {
		$this->FPDF($orientation, $unit, $format);
		$this->SetTopMargin($margin);
		$this->SetLeftMargin($margin);
		$this->SetRightMargin($margin);
		$this->SetAutoPageBreak(true, $margin);

	}
	
	function Header () {

				if($_POST['PrePrint']=='false')
		{
        		if($_POST['Logo']=='true')

	    $this->Image('comlogo/cmplogo.gif',180,8,250,55);
		$this->SetFont('Arial', 'B', 20);
		//$this->Cell(0, 30, $_SESSION['SESS_CMP'], 0, 1, 'C', false);
		$this->SetFont('Arial', 'B', 10);
		 $this->SetX(150);
		 $this->SetY(70);
		//$this->Cell(300, 15, 'Your Apple Repair Specialist', 1, 1, 'C', false);

		$this->SetFont('Arial', '', 10);
		$this->Cell(0, 15, $_SESSION['SESS_CMPADD1'], 0, 1, 'C', false);
		$this->Cell(0, 15,$_SESSION['SESS_CMPADD1_1'], 0, 1, 'C', false);
		$this->SetFont('Arial', 'B', 15);
		$this->Cell(0, 15,"JOB CARD", 0, 1, 'C', false);
		//$this->Cell(0, 15,$_SESSION['SESS_CMPADD1_2'], 0, 1, 'C', false);

		}
				$this->Line(10,97,580,97);
		      $this->Line(10,99,580,99);
}

 function Footer()

{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',8);
    //Page number
}

function Generate_Table($con) {

	$billno=$_POST['jobid'];
	//to select the company's table in current session
	$bill_res=mysqli_query($con,"SELECT * FROM  jobregdet WHERE jobid =  '$billno' ORDER BY entryid");

	

	$w=array(30,460,0,0,0,0,75);
	$this->SetFont('Arial', 'B', 12);
	$this->SetTextColor(0);



	$this->SetFillColor(255,255,255);
	$this->Cell($w[0], 25, "SNo", '1', 0, 'L', true);
	$this->Cell($w[1], 25, "DESCRIPTION", '1', 0, 'C', true);
	//$this->Cell($w[5], 25, "PARTS", '1', 0, 'R', true);
	$this->Cell($w[6], 25, "PRICE", '1', 1, 'C', true);
	$this->SetFont('Arial', '',10);

	$fill = false;
		$x = $this->GetX();
		$y = $this->GetY();
		$i=1;
	while($row=mysqli_fetch_array($bill_res)) {
		$this->SetY($this->GetY()+10);

		if($c>550)

		{
			$this->Line(10,$this->GetY(),590,$this->GetY());
			$this->AddPage();

			$c=0;

		$this->Line(10,40,590,86);
		$this->Line(10,40,590,88);
		$this->SetFont('Arial', 'B', 12);
		$this->SetTextColor(0);
		$this->SetFillColor(255,255,255);
	   $this->Cell($w[0], 25, "SNo", '1', 0, 'L', true);
	//$this->Cell($w[1], 25, "CODE", '1', 0, 'L', true);
	$this->Cell($w[1], 25, "DESCRIPTION", '1', 0, 'c', true);
	$this->Cell($w[2], 25, "QTY", '1', 0, 'R', true);
//	$this->Cell($w[3], 25, "UNIT", '1', 0, 'R', true);
	$this->Cell($w[4], 25, "RATE", '1', 0, 'R', true);
	//$this->Cell($w[5], 25, "PARTS", '1', 0, 'R', true);
	$this->Cell($w[6], 25, "PRICE", '1', 1, 'C', true);
	$this->SetFont('Arial', '');
	$fill = false;

		}


		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[0], 10,  $i, 0, 'C', $fill);
		$y2=$this->GetY();

		$yH=$y2-$y1;
		$this->SetXY($x + $w[0], $this->GetY() - $yH);
		$y_check=$y2;


		

		$x = $this->GetX();
		$y1 = $this->GetY();
		$this->MultiCell($w[1], 10, $row['descrip'], 0, 'L', $fill);
		$y2=$this->GetY();
		$yH=$y2-$y1;
		$this->SetXY($x + $w[1], $this->GetY() - $yH);

		if($y2>$y_check)

		$y_check=$y2;



		

		$x = $this->GetX();

		$y1 = $this->GetY();

		$this->MultiCell($w[6], 10,$row['scost'], 0, 'R', $fill);

		$y2=$this->GetY();

		$yH=$y2-$y1;

		$this->SetXY($x + $w[6], $this->GetY() - $yH);

		if($y2>$y_check)

		$y_check=$y2;
		$this->SetY($y_check-18);

		$this->Ln(20);

		$fill = $fill;
		$i++;

	}

		$this->SetY($this->GetY()+15);
}

}

$billno=$_POST['jobid'];
$vehno=$_POST['vehno'];

	include '../../db_connect.php';

$billdet_res=mysqli_query($con,"SELECT   loginname, DATE_FORMAT(date,'%d/%m/%Y') as jobdate, name, client, address, contactno,telephone, email, jobreg.location, jobreg.vehno, make, vehreg.model as model, remarks, 
STATUS , compid_key, chassisno, engineno, mfgyear, regdate, vehtype, color, vin, variant, enginetype, inscmp, policyno, insexp, puc, runkms, nextservkms, supervisor
FROM jobreg LEFT  JOIN vehreg ON jobreg.vehno = vehreg.vehno  LEFT  JOIN commst ON jobreg.client = commst.compid  WHERE jobreg.jobid  ='$billno'");
//LEFT OUTER JOIN commst ON client=compid
$billdet_res_row=mysqli_fetch_assoc($billdet_res);


$pdf = new PDF_result();
$pdf->AddPage();
$pdf->Line(10,118,575,118);
//$pdf->Line(10,178,270,178);
//$pdf->Line(10,190,270,190);
$pdf->line(10,118,10,270);
$pdf->line(270,118,270,281);
$pdf->line(420,118,420,242);
$pdf->line(575,118,575,270);
$pdf->SetY(118);
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "Job Order",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billno,0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53,13, "Date",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13, ' : '.$billdet_res_row['jobdate'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "Make",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billdet_res_row['make'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "Model",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billdet_res_row['model'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "Color",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billdet_res_row['color'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "VIN",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billdet_res_row['vin'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "Variant",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(30, 13,  ' : '.$billdet_res_row['variant'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "Veh Type",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billdet_res_row['vehtype'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "Engine No",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billdet_res_row['engineno'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(53, 13, "Mfg Year",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billdet_res_row['mfgyear'],0,1,'L');
$pdf->SetX(275);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(52, 13, "Engine Type",0,0);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(0, 13,  ' : '.$billdet_res_row['enginetype'],0,1,'L');
$pdf->SetX(270);
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(50, 13, "Remarks",'T',0);
$pdf->SetFont('Arial', '', 10);
$pdf->MultiCell(255, 13,' : '.$billdet_res_row['remarks'],'T');
$y=$pdf->GetY();
$y_ini=$pdf->GetY();





$pdf->SetY(118);

$pdf->SetX(425);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(65, 13, "Insrn Comp.",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(0, 13,  ' : '.$billdet_res_row['inscmp'],0,1,'L');

$pdf->SetX(425);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(65,13, "Policy No",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(50, 13, ' : '.$billdet_res_row['policyno'],0,1,'L');

$pdf->SetX(425);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(65, 13, "Insrn Expiry",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(0, 13,  ' : '.$billdet_res_row['insexp'],0,1,'L');

$pdf->SetX(425);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(65, 13, "PUC",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(0, 13,  ' : '.$billdet_res_row['puc'],0,1,'L');

$pdf->SetX(425);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(65, 13, "Running Kms",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(0, 13,  ' : '.$billdet_res_row['runkms'],0,1,'L');

$pdf->SetX(425);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(65, 13, "Next Serv Kms",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(0, 13,  ' : '.$billdet_res_row['nextservkms'],0,1,'L');

$pdf->SetX(425);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(65, 13, "Accessories",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(0, 13,  ' : '.$billdet_res_row['accessories'],0,1,'L');

$pdf->SetX(425);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(65, 13, "SUPERVISOR",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(0, 13,  ' : '.$billdet_res_row['supervisor'],0,1,'L');


$pdf->Cell(0, 13,  ' ',0,1,'L');







if ($pdf->GetY()>$y){

$y=$pdf->GetY();

$y_ini=$pdf->GetY();}



$pdf->SetFont('Arial', 'B', 10);

$pdf->SetY(118);



$pdf->Cell(35, 13, "Client",0,0 );

$pdf->SetFont('Arial', '', 10);

$pdf->Cell(300, 13, ' : '.$billdet_res_row['name'],0,1,'L');

$pdf->Cell(1, 13, "",0,0);

$pdf->MultiCell(250, 13, $billdet_res_row['address']."\n".$billdet_res_row['bcity']);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(73, 13, "Contact Name",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->MultiCell(300, 13,': '.$billdet_res_row['client']);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(30, 13, "Tel",0,0);

$pdf->SetFont('Arial', '', 10);

$pdf->MultiCell(300, 13,': '.$billdet_res_row['telephone']);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(30, 13, "Email",0,0);

$pdf->SetFont('Arial', '', 8);

$pdf->MultiCell(300, 13,': '.$billdet_res_row['email']);

$pdf->SetFont('Arial', 'B', 10);

$pdf->Cell(50, 13, "Symptoms",'T',0);

$pdf->SetFont('Arial', '', 8);

$pdf->MultiCell(210, 13,' : '.$billdet_res_row['descp'],'T');







if ($pdf->GetY()>$y){

$y=$pdf->GetY();

$y_ini=$pdf->GetY();}









$pdf->SetY($y_ini);

$pdf->Generate_Table($con);





$y=450;



$pdf->SetY($y);

	$y=$pdf->GetY();

	$w=array(30,460,0,0,0,0,75);

	

	//prints vertical lines

	$pdf->Line(10,$y_ini,10,$y);

	$pdf->Line(10+$w[0],$y_ini,10+$w[0],$y);

	//$pdf->Line(10+$w[0]+$w[1],$y_ini,10+$w[0]+$w[1],$y+55);

	//$pdf->Line(10+$w[0]+$w[1]+$w[2],$y_ini,10+$w[0]+$w[1]+$w[2],$y);

	//$pdf->Line(10+$w[0]+$w[1]+$w[2]+$w[3],$y_ini,10+$w[0]+$w[1]+$w[2]+$w[3],$y);

	//$pdf->Line(8+$w[0]+$w[1]+$w[2]+$w[3]+$w[4],$y_ini,8+$w[0]+$w[1]+$w[2]+$w[3]+$w[4],$y);

	$pdf->Line(10+$w[0]+$w[1]+$w[2]+$w[3]+$w[4]+$w[5],$y_ini,10+$w[0]+$w[1]+$w[2]+$w[3]+$w[4]+$w[5],$y+85);

	$pdf->Line(10+$w[0]+$w[1]+$w[2]+$w[3]+$w[4]+$w[5]+$w[6],$y_ini,10+$w[0]+$w[1]+$w[2]+$w[3]+$w[4]+$w[5]+$w[6],$y+55);

	

	

	$pdf->Line(10,$y,575,$y);

	$pdf->SetFont('Arial', '',10);

     $pdf->Line(430,475,575,475);

	 $pdf->Line(430,489,575,489);

	  $pdf->Line(430,520,575,520);

	// $pdf->line(346,450,346,505);

	 $pdf->line(430,450,430,520);

	 

	

	$pdf->SetXY(10,$y+10);

	$pdf->SetFont('Arial', 'B',10);

	$pdf->Cell(42, 10, "NOTES : ",0, 0);

	$pdf->SetFont('Arial', '',7);

	$pdf->MultiCell(350, 10, $billdet_res_row['notes']);





	

	

	$pdf->SetY($y+10);

	$pdf->SetX(430);

	$pdf->SetFont('Arial', 'B',10);

	$pdf->Cell(52, 15, "Total:",0, 0);

	$pdf->Cell(33, 15, "",0, 0);

	//$pdf->Cell(50, 15, $billdet_res_row['ptotal'], 0, 0, 'L');



	$pdf->Cell(60, 15,  $billdet_res_row['stotal'], 0, 1, 'R');

	

	//if($billdet_res_row['discount']>0)

//	{

//	$pdf->SetX(430);

//	$pdf->Cell(135, 15, "Discount", 0);

//	$pdf->Cell(33, 15, $billdet_res_row['discountr']."%", 0);

//	$pdf->Cell(60, 15,  $billdet_res_row['discount'], 0, 1, 'R');

//	}



	if($billdet_res_row['vattr']>0)

	{

	$pdf->SetX(430);

	$pdf->Cell(135, 15, "Vat on Product Cost", 0);

	$pdf->Cell(33, 15, $billdet_res_row['vattr']."%",'TBLR', 0);

	$pdf->Cell(60, 15,  $billdet_res_row['vatta'], 'TBLR', 1, 'R');

	}

	

	if($billdet_res_row['sevtr']>0)

	{

	$pdf->SetX(430);

	$pdf->Cell(135, 15, "ST on Service Cost", 0);

	$pdf->Cell(33, 15, $billdet_res_row['sevtr']."%", 0);

	$pdf->Cell(60, 15,  $billdet_res_row['sevta'], 0, 1, 'R');

	

	

	if(!empty($billdet_res_row['extra'])){

	$pdf->SetX(430);

	$pdf->Cell(135, 15, $billdet_res_row['extra'], 0);

	$pdf->Cell(33, 15, $billdet_res_row['extrar']."%", 0);

	$pdf->Cell(60, 15, $billdet_res_row['extraa'], 0, 1, 'R');

	}

	

	

	$pdf->SetX(430);

	$pdf->Cell(52, 15, "Grand Total:",'TB', 0);

	$pdf->Cell(33, 15, "",'TB', 0);

	$pdf->Cell(60, 15, $billdet_res_row['gtotal'], 'TB', 1, 'R');

	}

	else

	{

		

	$pdf->SetX(430);

	$pdf->Cell(52, 15, "Discount:",0, 0);

	$pdf->Cell(33, 15, $billdet_res_row['discountr']." ", 0);

	$pdf->Cell(60, 15,  $billdet_res_row['discount'],0, 1, 'R');
	
	$pdf->SetX(430);
	$pdf->Cell(52, 15, "Net Amount:",0, 0);
	$pdf->Cell(33, 15,"",0,0, 0);
	$pdf->Cell(60, 15,  $billdet_res_row['namount'],0, 1, 'R');

	$pdf->SetX(430);

	$pdf->Cell(52, 15, "Vat/ST:",'T', 0);

	$pdf->Cell(33, 15,"",'T',0, 0);

	$pdf->Cell(60, 15, $billdet_res_row['servicetax'],'TR', 1, 'R');

	$pdf->SetX(430);

	$pdf->Cell(52, 15, "Grand Total:",'LB', 0);

	$pdf->Cell(33, 15, "",'B', 0);

	$pdf->Cell(60, 15, $billdet_res_row['grtotal'], 'BR', 1, 'R');

	

	

	$pdf->Ln(29);



		//$message = "
//		1)Subject to Navi Mumbai Jurisdiction. 
//		2)Repaired or Unrepaired Goods to be picked up within 7 Days of Drop off, After 7 Days its not eServe's Responsibility of any kind for the goods. 
//		3)eServe is not responsible for any kind of damage caused to device & also data loss in the  product during the repair process and customer is well aware of risk involved
//		\tduring the repair process. There is no cable cut warranty & eServe is not responsible for any damage caused to device by Customer Mishandling the product or Normal Wear
//		\tand Tear during the daily use of the product. 
//		4)Diagnosis fees to be paid on decline of the quotation and jobs returns back unrepaired. 
//		5)All Workmanship comes with three months warranty Unless Specified in Notes except software warranty, Misheld devices and repair done on liquid damage devices. There  
//		\tis no Refund for software and any repair performed on liquid damage devices unless specified, eServe in not responsible for damage caused to the device by software restore
//		\tand upgrade or, device misheld by customer.";



        $y=$pdf->GetY();







		$pdf->SetY(540);
         $pdf->Image('images/acess.gif',10,490,380,120);
		 $pdf->Image('images/carplan.gif',10,640,260,120);
		 $pdf->Image('images/fuelmeter.gif',320,630,250,120);

	}

		$pdf->SetFont('Arial', '', 10);

		$pdf->SetY(710);

		$pdf->SetX(450);

		

		

		/* section for signature*/

		$pdf->SetY($pdf->GetY()+40);

		

		

		$pdf->SetFont('Arial','BI',10);

		$pdf->Cell(560,20,'','0',1,'C');

		$pdf->SetFont('Arial','',10);

		$pdf->Cell(212,20,'Staff member','TLBR',0,'C');

		$pdf->Cell(355,20,'Client Signature On Leaving Goods for Repair','TLBR',1,'C');

		$pdf->Cell(212,40,'','LBR',0,'C');

		$pdf->Cell(355,40,' ','LBR',1,'C');





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







?>