<?php
/* $Id: PDFReceipt.php 6941 2014-10-26 23:18:08Z daintree $*/

include('includes/session.inc');
ob_start();

include('includes/PDFStarter.php');

if (isset($_GET['id'])) {
		$_SESSION['id'] = stripslashes($_GET['id']);
	}
	$id= $_SESSION['id'];
if (isset($_GET['transno'])) {
		$_SESSION['transno'] = stripslashes($_GET['transno']);
	}
	$transno= $_SESSION['transno'];

$FontSize=10;
$pdf->addInfo('Title', _('Sales Receipt') );

$PageNumber=1;
$line_height=12;
if ($PageNumber>1){
	$pdf->newPage();
}

$FontSize=10;
$YPos= $Page_Height-$Top_Margin;
$XPos=0;

/* Prints company logo */
$pdf->addJpegFromFile($_SESSION['LogoFile'], $XPos+20, $YPos-50, 0, 60);

/* Prints company info */
$LeftOvers = $pdf->addTextWrap(50,$YPos-($line_height*6),300,$FontSize,$_SESSION['CompanyRecord']['coyname']);


	$LeftOvers = $pdf->addTextWrap(50,$YPos-($line_height*7),300,$FontSize,$_SESSION['CompanyRecord']['gstno']);
	
$LeftOvers = $pdf->addTextWrap(50,$YPos-($line_height*8),300,$FontSize,$_SESSION['CompanyRecord']['regoffice1']);
$LeftOvers = $pdf->addTextWrap(50,$YPos-($line_height*9),300,$FontSize,$_SESSION['CompanyRecord']['regoffice2']);
$LeftOvers = $pdf->addTextWrap(50,$YPos-($line_height*10),300,$FontSize,$_SESSION['CompanyRecord']['regoffice3']);
$LeftOvers = $pdf->addTextWrap(50,$YPos-($line_height*11),300,$FontSize,$_SESSION['CompanyRecord']['regoffice4']);
$LeftOvers = $pdf->addTextWrap(50,$YPos-($line_height*12),300,$FontSize,$_SESSION['CompanyRecord']['regoffice5']);
$LeftOvers = $pdf->addTextWrap(50,$YPos-($line_height*13),300,$FontSize,$_SESSION['CompanyRecord']['regoffice6']);

$LeftOvers = $pdf->addTextWrap($Page_Width-$Right_Margin-180,$YPos-($line_height*3),550,$FontSize, _('Customer Receipt Number ').'  : ' . $transno );
$LeftOvers = $pdf->addTextWrap($Page_Width-$Right_Margin-180,$YPos-($line_height*4.5),140,$FontSize, _('Printed').': ' . Date($_SESSION['DefaultDateFormat']) . '   '. _('Page'). ' ' . $PageNumber);

$YPos -= 150;

$YPos -=$line_height;
//Note, this is ok for multilang as this is the value of a Select, text in option is different

$YPos -=(2*$line_height);

/*Draw a rectangle to put the headings in     */

$pdf->line($Left_Margin, $YPos+$line_height,$Page_Width-$Right_Margin, $YPos+$line_height);

$FontSize=10;
$YPos -= (1.5 * $line_height);

$PageNumber++;

$sql="SELECT MIN(id) as start FROM debtortrans WHERE type=12 AND transno='". $_GET['BatchNumber']. "'";
$result=DB_query($sql);
$myrow=DB_fetch_array($result);
$StartReceiptNumber=$myrow['start'];

$sql="SELECT debtorno,
			ovamount,
			invtext,
			transno,
			reference,
			account_number,
			payment_method,
			drawer_chqnumber,
			entered_by
		FROM debtortrans
		WHERE type=12
		AND id='". $id ."'";
$result = DB_query($sql);
$myrow = DB_fetch_array($result);
$DebtorNo = $myrow['debtorno'];
$Amount = $myrow['ovamount'];
$Narrative = $myrow['invtext'];
$enteredby = $myrow['entered_by'];
$reference = $myrow['reference'];
$accountnumber =$myrow['account_number'];
$pm =$myrow['payment_method'];
$chqno = $myrow['drawer_chqnumber'];
$sql="SELECT name,
             address1,
			 address2,
			 address3,
			 address4,
			 address5,
			 address6
		FROM debtorsmaster
		WHERE debtorno='".$DebtorNo."'";

$result=DB_query($sql);
$myrow=DB_fetch_array($result);

/* Prints customer info */
$LeftOvers = $pdf->addTextWrap(50,$YPos,300,$FontSize,_('Received From').' :');
$LeftOvers = $pdf->addTextWrap(150,$YPos,300,$FontSize, htmlspecialchars_decode($myrow['name']));
$LeftOvers = $pdf->addTextWrap(150,$YPos-($line_height*1),300,$FontSize,_('Account Number: ').$accountnumber);
$LeftOvers = $pdf->addTextWrap(150,$YPos-($line_height*2),300,$FontSize, htmlspecialchars_decode($myrow['address1']));
$LeftOvers = $pdf->addTextWrap(150,$YPos-($line_height*3),300,$FontSize, htmlspecialchars_decode($myrow['address2']));
$LeftOvers = $pdf->addTextWrap(150,$YPos-($line_height*4),300,$FontSize, htmlspecialchars_decode($myrow['address3']));
$LeftOvers = $pdf->addTextWrap(150,$YPos-($line_height*5),300,$FontSize, htmlspecialchars_decode($myrow['address4']));
$LeftOvers = $pdf->addTextWrap(150,$YPos-($line_height*6),300,$FontSize, htmlspecialchars_decode($myrow['address5']));
$LeftOvers = $pdf->addTextWrap(150,$YPos-($line_height*7),300,$FontSize, htmlspecialchars_decode($myrow['address6']));

$YPos=$YPos-($line_height*9);

$LeftOvers = $pdf->addTextWrap(50,$YPos,300,$FontSize, _('The Sum Of').' :');
include('includes/CurrenciesArray.php'); // To get the currency name from the currency code.
$LeftOvers = $pdf->addTextWrap(150,$YPos,300,$FontSize, _('FJD '). locale_number_format(-$Amount,2));

$YPos=$YPos-($line_height*2);

$LeftOvers = $pdf->addTextWrap(50,$YPos,500,$FontSize, _('Details').' :');
$LeftOvers = $pdf->addTextWrap(150,$YPos,500,$FontSize, $reference);
$YPos=$YPos-($line_height*2);
$LeftOvers = $pdf->addTextWrap(50,$YPos,500,$FontSize, _('Payment Method'.' :'));
$LeftOvers = $pdf->addTextWrap(150,$YPos,500,$FontSize, $pm.' '.$chqno);
$YPos=$YPos-($line_height*8);

$LeftOvers = $pdf->addTextWrap(50,$YPos,500,$FontSize,_('Signed On Behalf Of').' :     '.$_SESSION['CompanyRecord']['coyname']);

$YPos=$YPos-($line_height*10);
/* Prints company logo */
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set JPEG quality
$pdf->setJPEGQuality(75);
$image_file = 'companystamp.jpg';
//Image( filename, left, top, width, height, type, link, align, resize, dpi, align, ismask, imgmask, border, fitbox, hidden, fitonpage)
//filename : name of the file containing the image
//left : from left
//top: from top
//width: width of the image. Zero for automatically calculated
//height : height of the image. Zero for automatically calculated.
//type: JPG, JPEG, PNG. If not specified, the type is inferred from the file extension.
//link:URL or identifier returned by AddLink()
//align: T (top), M (middle), B (bottom), N (next line)
//resize: true/false. If true resize (reduce) the image to fit :w and :h (requires RMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
//dpi: dot-per-inch resolution used on resize. Recommended 300
//align: align L (left), C (center), R (right)
//ismask: true if this image is a mask, false otherwise
//imgmask: image object returned by this function or false.
//border: 0: no border (default) 1: frame or a string containing some or all of the following characters (in any order): L: left T: top R: right B: bottom
//fitbox: If true scale image dimensions proportionally to fit within the (:w, :h) box.
//hidden: true/false
//fitonpage: if true the image is resized to not exceed page dimensions.

$LeftOvers= $pdf->Image($image_file, 150, 500, 260,65, 'JPG', '', '', true, 150, '', false, false, 0, false, false, false);
$YPos=$YPos-($line_height*2);
$LeftOvers = $pdf->addTextWrap(50,$YPos,300,$FontSize,'______________________________________________________________________________');
$YPos=$YPos-($line_height*2);
$LeftOvers = $pdf->addTextWrap(50,$YPos,300,$FontSize,$enteredby);
$YPos=$YPos-($line_height*2);
$LeftOvers = $pdf->addTextWrap(230,$YPos,300,$FontSize,_('Powered by E-Business ERP 2.0'));


$pdf->Output('Receipt-'.$transno, 'I');
?>