<?php
include("../include/startup.php");
/*error_reporting(E_ALL);
if(!isset($_SESSION['login'])){
	die("Please login to admin panel first");
}*/

session_start();
//$orderDetails = $orders->getOrder($id);

require('fpdf.php');
class PDF extends FPDF
{
protected $id =1;
protected $fontName ="Times";
protected $fontSize =12;
protected $tableHeaderHeight = 8;
protected $tableDescriptionHeight = 6;
//protected $orderDetails = $orders->getOrder($id);

function Header()
{	
	if($this->page == 1){
		// Logo
		$this->Image('../admin/images/logo.png',160,7,40);
		$this->SetXY(170, 27);
		$this->SetFont('Arial','',10);
		$row = utility::getTableRowByField("sites","id",1);
		$company_address = $row["company_address"];
		$company_address = str_replace("&nbsp;"," ",$company_address);
		$company_address = str_replace("’","'",$company_address);
		$company_address = str_replace("&lsquo;"," ",$company_address);
		$company_address = str_replace("&rsquo;"," ",$company_address);
		$this->MultiCell(30,5,$company_address,0,"R");
		
		$company_phone = $row["company_phone"];
		$sales_email = $row["sales_email"];
		$company_website = $row["company_website"];
		$this->SetXY(174, 59);
		$this->Cell(30,5,$company_phone,0,"R");
		$this->Ln();
		$this->SetXY(155, 64);
		$this->Cell(30,5,$sales_email,0);
		$this->Ln();
		$this->SetXY(155, 69);
		$this->Cell(30,5,$company_website,0);
		// hr line
		//$this->SetFillColor(122,138,144);
		//$this->SetY($this->GetY() + 10);
		//$this->SetX(5);
		//$this->Cell(200,0,"",0,1,'L',true);
	}	
	// Line break
	$this->Ln(1);
	$this->Rect(5, 5, 200, 286);
}
function normalInvoice($job_id)
{
	global $config,$bebcrm;
	$row = utility::getTableRowByField("job","id",$job_id);
	$q_no = $row["quotation_no"];
	$quotation_date = utility::getFormatedDateReturn($row["quotation_date"]);
	$package_information_details = $row["package_information_details"];
	$first_name = $row["first_name1"];
	$last_name = $row["last_name1"];
	$company_name = $row["company_name"];
	if($row["enquiry_type"] == 1){
		$package_name = $gsi->getFixedPackagesById($row["fixed_packages"]);
		$package_month_support = "12 months";
		if($row["fixed_packages"] == 4){
			$package_month_support = "2 years";
		}
		$fixed_amount = number_format($row["fixed_amount"],2)." + VAT";
		$no_of_hours_to_be_worked = "Fixed price";
		$hourly_rate = "N/A";
	}else{
		$package_name = $gsi->getHourlyPackagesById($row["hourly_packages"])." months";
		$no_of_hours_to_be_worked = $gsi->getHourlyPackagesById($row["hourly_packages"])." months";
		$fixed_amount = "N/A";
		$total_hours = $row["total_hours"];
		$hourly_amount = $row["hourly_amount"];
		$hourly_rate = number_format(($hourly_amount/$total_hours),2);
	}
	
	$consultant_id = utility::getTableFieldById("job_admin_mapping","admin_id","job_id",$job_id);
	$consultant_name = utility::getTableFieldById("admin","name","id",$consultant_id);
	
	
	$this->AddPage();
	$this->SetLeftMargin(10);
	$height = 6;
	$this->SetFont('Arial','B',10);
	$this->Cell(191,$height,'INSTRUCTION TO PROCEED',0,0,'C');
	$this->SetY($this->GetY() + 6);
	$this->Cell(191,$height,$company_name,0,0,'C');
	$this->SetFont('Arial','',10);
	$this->SetY($this->GetY() + 10);
	$this->Cell(70,$height,'DATE : ',0,0,'L');
	$this->Cell(121,$height,$quotation_date,0,0,'L');
	
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'WORKS TO BE CARRIED OUT : ',0,0,'L');
	$this->MultiCell(121,$height,"PREPARATION OF CONTRACTUAL DOCUMENTATION AS PER MY QUOTATION NO. $q_no DATED $quotation_date",0,'L');
	$this->SetY($this->GetY() + 2);
	$this->Cell(70,$height,'INSTRUCTIONS RECEIVED FROM : ',0,0,'L');
	$this->Cell(121,$height,ucfirst($first_name)." ".ucfirst($last_name),0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'TRAVELLING TIME : ',0,0,'L');
	$this->Cell(121,$height,'2 hours travelling time included',0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'MILEAGE : ',0,0,'L');
	$this->Cell(121,$height,'45 pence per mile',0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'NO. OF HOURS TO BE WORKED : ',0,0,'L');
	$this->Cell(121,$height,$no_of_hours_to_be_worked,0,0,'L');
	
	$this->SetY($this->GetY() + 10);
	$this->SetFont('Arial','B',10);
	$this->Cell(191,$height,'SCHEDULE OF RATES',0,0,'C');
	
	$this->SetFont('Arial','',10);
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'Fixed Price : ',0,0,'L');
	$this->Cell(121,$height,$fixed_amount,0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'Hourly Rate : ',0,0,'L');
	$this->Cell(121,$height,$hourly_rate,0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'Daily Rate : ',0,0,'L');
	$this->Cell(121,$height,'N/A',0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'Travelling Rate : ',0,0,'L');
	$this->Cell(121,$height,'2 hours travelling included',0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'Special Conditions : ',0,0,'L');
	$this->Cell(121,$height,'As per quotation ref '.$q_no,0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'Payment terms : ',0,0,'L');
	$this->Cell(121,$height,'Deposit with order and further payments strictly 30 days from invoice date',0,0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'Bank Details : ',0,0,'L');
	$this->MultiCell(50,$height,"Lloyds Bank\nSort Code: 30 96 09\nAccount No: 00313717",0,'L');
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'SIGNED BY CLIENT : ',0,0,'L');
	$y = $this->GetY()+5;
	$this->Line(48,$y,120,$y);
	$this->SetX($this->GetX() + 45);
	$this->Cell(70,$height,'DATE : ',0,0,'L');
	$this->Line(140,$y,190,$y);
	$this->SetY($this->GetY() + 7);
	$this->Cell(70,$height,'NAME : ',0,0,'L');
	$y = $this->GetY()+5;
	$this->Line(25,$y,190,$y);
	
	$this->SetY($this->GetY() + 10);
	$this->Cell(70,$height,'SIGNED BY BEB CONSULTANCY : ',0,0,'L');
	$y = $this->GetY();
	$consultant_id = utility::getTableFieldById("job_admin_mapping","admin_id","job_id",$job_id);
	$signature = utility::getTableFieldById("admin","signature","id",$consultant_id);
	if(isset($signature) && $signature !=""){
		$this->Image('../signature/'.$signature,70,$y,25);
	}
	
	$this->Ln();
	$this->Ln();
	$this->Cell(30,$height,'NAME : ',0,0,'L');
	$this->Cell(70,$height,$consultant_name,0,0,'L');
	$y = $this->GetY()+5;
	$this->Line(25,$y,100,$y);
}
function Footer(){
	global $config;
	$vat_reg_number = utility::getTableFieldById("sites","vat_reg_number","id",1);
	$height = 10;
	$this->SetTextColor(0,0,0);
	$this->SetY(260);
	$this->SetX($this->GetX() + 2);
	$this->SetFont('Arial','',10);
	
	$this->SetY($this->GetY() + 6);
	$this->SetX(5);
	$this->Cell(200,0,"",0,1,'L',true);
	$this->SetY($this->GetY() + 2);
	$this->SetFont('Arial','',10);
	$this->Cell(191,$height,'BEB Consultancy (UK) Ltd    Registered in England & Wales no 6663021   VAT No. '.$vat_reg_number,0,0,'C');
	$this->SetY($this->GetY() + 10);
	$this->SetX($this->GetX() + 10);
	$this->SetFillColor(152,251,152);
	$this->Cell(170,$height,'Subject to our terms and conditions, available upon request.',0,0,'C',true);
}
}
$pdf = new PDF();
$title = 'Instruction to proceed';
$pdf->SetTitle($title);
$pdf->SetAuthor('BEBCRM');
$job_id = base64_decode(base64_decode(base64_decode(base64_decode(base64_decode(base64_decode($_REQUEST['id']))))));
$pdf->normalInvoice($job_id);
$pdf->Output("instruction_to_proceed","I");
/*if($_SERVER['HTTP_HOST'] == "localhost"){
	$filename="../quotation_template/instruction_to_proceed_".$job_id;
}else{
	$filename="/home4/easysolu/public_html/{$other_fields["project_folder_name"]}quotation_template/instruction_to_proceed_".$job_id;
}
$pdf->Output($filename.'.pdf','F');*/
?>