<?php

/* $Id: PDFTransPageHeaderPortrait.inc 4644 2011-07-30 06:58:14Z daintree $ */


if (!$FirstPage){ /* only initiate a new page if its not the first */
	$pdf->newPage();
}

$YPos = $Page_Height - $Top_Margin;

//20140714 YS Chin: Reformat invoice layout
//$pdf->addJpegFromFile($_SESSION['LogoFile'],$Page_Width/2 -118,$YPos-60,0,35);
$pdf->addJpegFromFile($_SESSION['LogoFile'],40,$YPos-20,0,35);

$YPos-=30;

$FontSize =15;

//20140714 YS Chin: Reformat invoice layout
//$pdf->addText($Page_Width/2 - 60, $YPos, $FontSize, _('TAX INVOICE') . ' ');
$pdf->addText(40, $YPos, $FontSize, _('DELIVERY ORDER ') . ' ');

$FontSize = 10;
$pdf->addText($Page_Width-128, $YPos, $FontSize, _('Page'));
$pdf->addText($Page_Width-60, $YPos, $FontSize, $PageNumber);


$XPos = $Page_Width - 265;
//20140714 YS Chin: Reformat invoice layout
//$YPos -= 95;
$YPos -= 90;
//20140912 YS Chin: Redraw box to allow additional line of Invoice# - lower $YPos-20 from $YPos-10 for ellipse and $YPos-30 from $YPos-20 for bottom line
/*draw a nice curved corner box around the billing details */
/*from the top right */
$pdf->partEllipse($XPos+225,$YPos+67,0,90,10,10);
/*line to the top left */
$pdf->line($XPos+225, $YPos+77,$XPos, $YPos+77);
/*Do top left corner */
$pdf->partEllipse($XPos, $YPos+67,90,180,10,10);
/*Do a line to the bottom left corner */
$pdf->line($XPos-10, $YPos+67,$XPos-10, $YPos-20);
/*Now do the bottom left corner 180 - 270 coming back west*/
$pdf->partEllipse($XPos, $YPos-20,180,270,10,10);
/*Now a line to the bottom right */
$pdf->line($XPos, $YPos-30,$XPos+225, $YPos-30);
/*Now do the bottom right corner */
$pdf->partEllipse($XPos+225, $YPos-20,270,360,10,10);
/*Finally join up to the top right corner where started */
$pdf->line($XPos+235, $YPos-20,$XPos+235, $YPos+67);

//20140714 YS Chin: Reformat invoice layout
//$YPos = $Page_Height - $Top_Margin - 10;
$YPos = $Page_Height - $Top_Margin - 32;

$FontSize = 10;
$LineHeight = 13;
$LineCount = 1;
$pdf->addText($Page_Width-268, $YPos-$LineCount*$LineHeight, $FontSize, _('Number'));
$pdf->addText($Page_Width-180, $YPos-$LineCount*$LineHeight, $FontSize, $FromTransNo);

$LineCount += 1;
$pdf->addText($Page_Width-268, $YPos-$LineCount*$LineHeight, $FontSize, _('Customer Code'));
$pdf->addText($Page_Width-180, $YPos-$LineCount*$LineHeight, $FontSize, $myrow['debtorno'] . ' ' . _('Branch') . ' ' . $myrow['branchcode']);
$LineCount += 1;
$pdf->addText($Page_Width-268, $YPos-$LineCount*$LineHeight, $FontSize, _('Date'));
$pdf->addText($Page_Width-180, $YPos-$LineCount*$LineHeight, $FontSize, ConvertSQLDate($myrow['trandate']));

//20140912 YS Chin: Add reference to invoice#
$LineCount += 1;
$pdf->addText($Page_Width-268, $YPos-$LineCount*$LineHeight, $FontSize, _('Invoice No'));
$pdf->addText($Page_Width-180, $YPos-$LineCount*$LineHeight, $FontSize, $FromTransNo . _(' (Dated ') . ConvertSQLDate($myrow['trandate']) . ')');
//20140912 YS Chin: Add reference to invoice#

$LineCount += 1;
$pdf->addText($Page_Width-268, $YPos-$LineCount*$LineHeight, $FontSize, _('Order No'));
$pdf->addText($Page_Width-180, $YPos-$LineCount*$LineHeight, $FontSize, $myrow['orderno']);
$LineCount += 1;
$pdf->addText($Page_Width-268, $YPos-$LineCount*$LineHeight, $FontSize, _('Order Date'));
$pdf->addText($Page_Width-180, $YPos-$LineCount*$LineHeight, $FontSize, ConvertSQLDate($myrow['orddate']));
$LineCount += 1;
$pdf->addText($Page_Width-268, $YPos-$LineCount*$LineHeight, $FontSize, _('Dispatch Detail'));
$pdf->addText($Page_Width-180, $YPos-$LineCount*$LineHeight, $FontSize, $myrow['shippername'] . '-' . $myrow['consignment']);
$LineCount += 1;
$pdf->addText($Page_Width-268, $YPos-$LineCount*$LineHeight, $FontSize, _('Dispatched From'));
$pdf->addText($Page_Width-180, $YPos-$LineCount*$LineHeight, $FontSize, $myrow['locationname']);

/*End of the text in the right side box */

/*Now print out company info at the top left */

$XPos = $Left_Margin;
$YPos = $Page_Height - $Top_Margin - 20;

$FontSize = 10;
$LineHeight = 13;
$LineCount = 0;

//20140714 YS Chin: Reformat invoice layout
//$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $_SESSION['CompanyRecord']['coyname']);

$FontSize = 8;
$LineHeight = 10;

//20140714 YS Chin: Reformat invoice layout
/*
if ($_SESSION['CompanyRecord']['regoffice1'] <> '') {
  $LineCount += 1;
  $pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice1']);
}
if ($_SESSION['CompanyRecord']['regoffice2'] <> '') {
  $LineCount += 1;
  $pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice2']);
}
if (($_SESSION['CompanyRecord']['regoffice3'] <> '') OR ($_SESSION['CompanyRecord']['regoffice4'] <> '') OR ($_SESSION['CompanyRecord']['regoffice5'] <> '')) {
  $LineCount += 1;
  $pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice3'] . ' ' . $_SESSION['CompanyRecord']['regoffice4'] . ' ' . $_SESSION['CompanyRecord']['regoffice5']);  // country in 6 not printed
}
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Phone') . ':' . $_SESSION['CompanyRecord']['telephone']);
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, _('Fax') . ': ' . $_SESSION['CompanyRecord']['fax']);
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Email') . ': ' . $_SESSION['CompanyRecord']['email']);
*/
//20140714 YS Chin: Reformat invoice layout
//$LineCount += 1;
$LineCount += 3;
if($_SESSION['CompanyRecord']['gstno'] != "")
{
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $_SESSION['TaxAuthorityReferenceName'] . ': ' . $_SESSION['CompanyRecord']['gstno']);
}

/*Now the customer company info */

$XPos = $Left_Margin;
//20140714 YS Chin: Reformat invoice layout
//$YPos = $Page_Height - $Top_Margin - 10;
$YPos = $Page_Height - $Top_Margin - 70;

$FontSize = 8;
$LineHeight = 10;
$LineCount = 0;

$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Sold To') . ':');

$XPos += 20;
$FontSize = 10;
$LineHeight = 13;

if ($myrow['invaddrbranch']==0){
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight+3, $FontSize, html_entity_decode($myrow['name']));
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['address1']));
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['address2']));
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['address3']) . ' ' . html_entity_decode($myrow['address4'])  . ' ' . html_entity_decode($myrow['address5'])  . ' ' . html_entity_decode($myrow['address6']));
} else {
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight-3, $FontSize, html_entity_decode($myrow['name']));
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['brpostaddr1']));
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['brpostaddr2']));
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['brpostaddr3']) . ' ' . html_entity_decode($myrow['brpostaddr4']) . ' ' . html_entity_decode($myrow['brpostaddr5']) . ' ' . html_entity_decode($myrow['brpostaddr6']));
}

//20140714 YS Chin: Reformat invoice layout
//$XPos = $Page_Width/2;
//$XPos = $Page_Width - 265;
$XPos -= 20;
$YPos = $Page_Height - $Top_Margin - 140;

$FontSize = 8;
$LineHeight = 10;
$LineCount = 0;

	
  $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Delivered To (check Dispatch Detail)') . ':');
  $FontSize = 10;
  $LineHeight = 13;
	$XPos +=20;
	$LineCount += 1;
	// Before trying to call htmlspecialchars_decode, check that its supported, if not substitute a compatible version
	if (!function_exists('htmlspecialchars_decode')) {
		function htmlspecialchars_decode($str) {
			$trans = get_html_translation_table(HTML_SPECIALCHARS);
	
			$decode = ARRAY();
			foreach ($trans AS $char=>$entity) {
				$decode[$entity] = $char;
			}
	
			$str = strtr($str, $decode);
	
			return $str;
		}
	}

	//20140714 YS Chin: Reformat invoice layout
	//$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['deliverto']));
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight+3, $FontSize, html_entity_decode($myrow['deliverto']));
	
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['deladd1']));
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['deladd2']));
	$LineCount += 1;
	$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, html_entity_decode($myrow['deladd3']) . ' ' . html_entity_decode($myrow['deladd4']) . ' ' . html_entity_decode($myrow['deladd5']) . ' ' . html_entity_decode($myrow['deladd6']));
	//$XPos -=80;

$XPos = $Left_Margin;

//20140714 YS Chin: Reformat invoice layout
//$YPos = $Page_Height - $Top_Margin - 190;
$YPos = $Page_Height - $Top_Margin - 192;
$XPos = $Left_Margin;
$FontSize = 9;

//20140714 YS Chin: Reformat invoice layout
//$pdf->addText($XPos, $YPos-8, $FontSize, _('All amounts stated in') . ' - ' . $myrow['currcode']);
//$pdf->addText($Right_Margin-180, $YPos-8, $FontSize, _('All amounts stated in') . ' - ' . $myrow['currcode']);

//20140714 YS Chin: Reformat invoice layout
//$BoxHeight = $Page_Height-282;
$BoxHeight = $Page_Height-372;

/*draw a box with nice round corner for entering line items */
/*90 degree arc at top right of box 0 degrees starts a bottom */
$pdf->partEllipse($Page_Width-$Right_Margin-10, $Bottom_Margin+$BoxHeight,0,90,10,10);
/*line to the top left */
$pdf->line($Page_Width-$Right_Margin-10, $Bottom_Margin+$BoxHeight+10,$Left_Margin+10, $Bottom_Margin+$BoxHeight+10);
/*Dow top left corner */
$pdf->partEllipse($Left_Margin+10, $Bottom_Margin+$BoxHeight,90,180,10,10);
/*Do a line to the bottom left corner */
$pdf->line($Left_Margin, $Bottom_Margin+$BoxHeight,$Left_Margin, $Bottom_Margin+10);
/*Now do the bottom left corner 180 - 270 coming back west*/
$pdf->partEllipse($Left_Margin+10, $Bottom_Margin+10,180,270,10,10);
/*Now a line to the bottom right */
$pdf->line($Left_Margin+10, $Bottom_Margin,$Page_Width-$Right_Margin-10, $Bottom_Margin);
/*Now do the bottom right corner */
$pdf->partEllipse($Page_Width-$Right_Margin-10, $Bottom_Margin+10,270,360,10,10);
/*Finally join up to the top right corner where started */
$pdf->line($Page_Width-$Right_Margin, $Bottom_Margin+10,$Page_Width-$Right_Margin, $Bottom_Margin+$BoxHeight);


$YPos -= 35;
/*Set up headings */
$FontSize=10;
$LineHeight = 12;
$LineCount = 0;

$pdf->addText($Left_Margin+2, ($YPos+$LineHeight)-$LineCount*$LineHeight, $FontSize, _('Cust. Tax Ref') . ':');
/*Print a vertical line */
//20140912 YS Chin: repositioned tax ref number text
$LineCount += 1;
$pdf->addText($Left_Margin+12, ($YPos+$LineHeight)-$LineCount*$LineHeight, $FontSize, $myrow['taxref']);

//20140731 YS Chin: Vertical line separator does not reach the box top line - added +3 to line height
//$pdf->line($Left_Margin+178, $YPos+$LineHeight,$Left_Margin+178, $YPos-$LineHeight*2+4);
$pdf->line($Left_Margin+178, $YPos+$LineHeight+3,$Left_Margin+178, $YPos-$LineHeight*2+4);

$LineCount -= 1;
$pdf->addText($Left_Margin+180, ($YPos+$LineHeight)-$LineCount*$LineHeight, $FontSize, _('Cust. Reference No.') . ':');
$LineCount += 1;
//20140912 YS Chin: retrieve and display customerref - PO#
$pdf->addText($Left_Margin+190, ($YPos+$LineHeight)-$LineCount*$LineHeight, $FontSize, $myrow['customerref']);

/*Print a vertical line */
//20140731 YS Chin: Vertical line separator does not reach the box top line - added +3 to line height
//$pdf->line($Left_Margin+358, $YPos+$LineHeight,$Left_Margin+358, $YPos-$LineHeight*2+4);
$pdf->line($Left_Margin+358, $YPos+$LineHeight+3,$Left_Margin+358, $YPos-$LineHeight*2+4);

$LineCount -= 1;
$pdf->addText($Left_Margin+360, ($YPos+$LineHeight)-$LineCount*$LineHeight, $FontSize, _('Sales Person') . ':');
$LineCount += 1;
$pdf->addText($Left_Margin+370, ($YPos+$LineHeight)-$LineCount*$LineHeight, $FontSize, $myrow['salesmanname']);

$YPos -= 20;

/*draw a line */
$pdf->line($XPos, $YPos,$Page_Width-$Right_Margin, $YPos);

$YPos -= 12;

$TopOfColHeadings = $YPos;

$TopOfColHeadings = $YPos;

$pdf->addText($Left_Margin+5, $YPos+12, $FontSize, _('Item Code'));
$pdf->addText($Left_Margin+80, $YPos+12, $FontSize, _('Description'));
//$pdf->addText($Left_Margin+270, $YPos+12, $FontSize, _('Unit Price'));
//$pdf->addText($Left_Margin+390, $YPos+12, $FontSize, _('UOM'));
//$pdf->addText($Left_Margin+420, $YPos+12, $FontSize, _('Disc.'));
$pdf->addText($Left_Margin+400, $YPos+12, $FontSize, _('UOM'));
$pdf->addText($Left_Margin+470, $YPos+12, $FontSize, _('Qty'));

$YPos-=0;

/*draw a line */
$pdf->line($XPos, $YPos,$Page_Width-$Right_Margin, $YPos);

$YPos -= ($line_height);

?>
