<?php  ob_start(); 
	require_once ('class.numbertoword.php');

	$page_security = 'SA_SUPPTRANSVIEW';
	$path_to_root = "..";
	
	include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
	include_once($path_to_root . "/includes/session.inc");
	include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");

//-----------add new code for the get compny details---15.08.2012----
	$result = get_company_details();
	while($myrow = db_fetch($result)){
		if($myrow[0] == 'coy_name')
		$company_name = $myrow['value'];
		if($myrow[0] == 'postal_address')
		$company_address = $myrow['value'];
		if($myrow[0] == 'phone')
		$company_phone = $myrow['value'];
		if($myrow[0] == 'fax')
		$company_fax = $myrow['value'];
		if($myrow[0] == 'email')
		$company_email = $myrow['value'];
	}
//-----------add new code for the get compny details---15.08.2012----

	$trans_no = $_REQUEST['trans_id'];
		
		$result_items = get_voucher_details($trans_no);		
		while($row_items = mysql_fetch_array($result_items)){
			
			$voucher_no = $row_items['reference'];// add 20.12.2011 voucher number modificaton
			
			$mysql_invoice = get_supp_details($row_items['trans_no_to']);
			
			$invoice_number = db_fetch($mysql_invoice,0,'supp_reference');
			$supp_address = db_fetch($mysql_invoice,0,'address');
			$payee_name = html_entity_decode(db_fetch($mysql_invoice,0,'supp_name'));
			
			$result_tax = get_trans_tax_details(20, $row_items['trans_no_to']);
			$without_tax = $row_items['amt'] - db_fetch($result_tax,0,'amount');
			//----tax details------
			
//-------------------items of invoice--------------			
			 $items .=	'<tr height=50>
							<td width="290">Settlement of Supplier Invoice - '.$invoice_number.'</td>
							<td width="100" align="right">'.number_format($without_tax,2,'.',',').'</td>
							<td width="65" align="right">'.number_format(db_fetch($result_tax,0,'amount'),2,'.',',').'</td>
							<td width="85" align="right">'.number_format($row_items['amt'],2,'.',',').'</td>
						</tr>';

//-------------------items of invoice--------------			

			$total_amt = $total_amt + $row_items['amt'];
			
//----------cheque details-------------- 15.12.2011 changes
			$result_cheque_details = get_gl_trans_voucher(22, $row_items['trans_no_from']);
			
			$new_chk_no = db_fetch($result_cheque_details,0,'cheque_no');
			
			if($new_chk_no !='null'){
				$pay_chk_no = db_fetch($result_cheque_details,0,'cheque_no');	//--payment cheque number
			}else{
				$pay_chk_no = $row_items['chk_no'];	//--payment cheque number
			}
			
		}

	
	 $amount = abs($total_amt);
	$iNumber = number_format($amount,2,'.','');
	$number_amount = number_format($iNumber,2,'.',',');
		
		$values = explode(".", $iNumber);
		$rupees  = intval($values[0]);
		$cents  = intval($values[1]);
		
		 str_pad($iNumber,'0',STR_PAD_LEFT);
		
		switch ($cents) {
			case 0:
				$amount_w_db =  CLASS_Numbertoword::convert($rupees,'en').' Only';
				break;
			case 1:
				$amount_w_db =  CLASS_Numbertoword::convert($rupees,'en').' and '.CLASS_Numbertoword::convert($cents,'en').' Cent Only';
				break;
			default:
			   $amount_w_db =  CLASS_Numbertoword::convert($rupees,'en').' and '.CLASS_Numbertoword::convert($cents,'en').' Cents Only';
		}
// -------------total row of invoice-------------		
		$items .=	'<tr>
						<td width="455" colspan="3" align = "center">Total</td>
						<td width="85" align="right">'.number_format($amount,2,'.',',').'</td>
					</tr>';
// -------------total row of invoice-------------	

		$date = date("y-m-d");

$word = '<table cellspacing="0" cellpadding="1" border="0">
    <tr>
        <td>Amount of '.$amount_w_db.'</td>
    </tr>
</table>';

$word_last = '<table cellspacing="0" cellpadding="1" border="0">
    <tr>
        <td>Received with thanks from  <b>'.$company_name.'</b> The sum of Rupees  <b>'.$amount_w_db.'</b></td>
    </tr>
</table>';
//-------------------select bank trans paymode------------------------
	
	$result_bank_trans = get_bank_acc_type($_REQUEST['trans_id'],22);
	$account_type = db_fetch($result_bank_trans,0,'account_type');

	switch ($account_type) {
		case 0:
			$voucher_eading =  'PAYMENT VOUCHER CHEQUE';
			break;
		case 1:
			$voucher_eading =  'PAYMENT VOUCHER CHEQUE';
			break;
		case 2:
			$voucher_eading =  'PAYMENT VOUCHER CASH';
			break;
		case 3:
			/*******************BOF Added if Petty Cash selected***************/
		    if($_REQUEST['bankcode'] == "8")
			{
				$voucher_eading =  'PETTY CASH PAYMENT VOUCHER';
			}
			else
			/*******************EOF Added if Petty Cash selected***************/
			$voucher_eading =  'PAYMENT VOUCHER CASH';
			break;
		default:
		   $voucher_eading =  'PAYMENT VOUCHER CHEQUE';
	}



require_once('config/lang/eng.php');
require_once('tcpdf.php');

// create new PDF document
//$pdf = new TCPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//$pdf = new TCPDF('L', PDF_UNIT, 'PV', true, 'UTF-8', false);
$pdf = new TCPDF('L', PDF_UNIT, 'A5', true, 'UTF-8', false);
//$pdf = new TCPDF('L', PDF_UNIT, 'PVB', true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);

// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set auto page breaks
$pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);

//set some language-dependent strings
$pdf->setLanguageArray($l);

//set margins
$pdf->SetMargins(0, 0, 0,0);
// ---------------------------------------------------------

// set font
$pdf->SetFont('times', '', 10);

//SetFont($family, $style='', $size=0, $fontfile='', $subset='default')
// add a page
$pdf->AddPage();


$pdf->SetFont('times', '', 16);
$pdf->Text(140, 10, 'VOUCHER NO : ');//---voucher number
$pdf->SetFont('Courier', '', 16);

$pdf->Text(185, 10, $voucher_no);//---voucher number

$pdf->SetFont('times', 'BI', 16);
$pdf->Text(14, 5, $company_name);//---company name

$pdf->SetFont('times', '', 10);
$pdf->Text(14, 11, $company_address);//---company address
$pdf->Text(14, 15, 'Tel : '.$company_phone.' Fax : '.$company_fax);//---company contacts
$pdf->Text(14, 19, $company_email);//---company emails

$pdf->SetFont('times', 'UB', 16);
$pdf->Text(14, 26, $voucher_eading);//---voucher heading------------


//==============amount in number================
$pdf->SetFont('times', 'B', 10);
$pdf->Text(140, 32, 'Date : ');
$pdf->SetFont('times', '', 10);
$pdf->Text(150, 32, $date);
$pdf->SetFont('times', 'B', 10);
$pdf->Text(140, 40, 'Cheque No : ');//---cheque number
$pdf->SetFont('times', '', 10);
$pdf->Text(165, 40, $pay_chk_no);//---cheque number

//==========payee name-----
$pdf->SetFont('times', 'B', 10);
$pdf->Text(14, 34, 'Name : ');
$pdf->SetFont('times', '', 10);
$pdf->Text(30, 34, $payee_name);
$pdf->SetFont('times', 'B', 10);
$pdf->Text(14, 40, 'Address : ');
$pdf->SetFont('times', '', 10);
$pdf->Text(30, 40, $supp_address);
$pdf->SetFont('times', 'B', 10);
$pdf->Text(14, 45, 'Payment : ');
$pdf->SetFont('times', '', 10);

//------------------amount in word-----------------
$amout_words = <<<EOD
	<table width="500" height="42" border="0" cellpadding="1" cellspacing="0">
		<tr align="left">
			<td width="500">
			$word
			</td>
    </tr>
</table>
EOD;

$amout_words_last = <<<EOD
	<table width="500" height="42" border="0" cellpadding="1" cellspacing="0">
		<tr align="left">
			<td width="500">
			$word_last
			</td>
    </tr>
</table>
EOD;

$item_table = <<<EOD
				<table width="500" height="42" border="1" cellpadding="1" cellspacing="0">
						<tr  style="background-color:#D8ECF2; font-weight:bold">
							<td width="290" align="center"><b>Description</b></td>
							<td width="100" align="center"><b>Before VAT Value</b></td>
							<td width="65" align="center"><b>VAT %</b></td>
							<td width="85" align="center"><b>Invoice Value</b></td>
						</tr>
					$items
				</table>
EOD;

$amount_table = <<<EOD
					<table width="180" border="1" height="20">
						<tr>
							<td height="20">
								&nbsp;&nbsp;Rs. : **$number_amount
							</td>
						</tr>
					</table>
EOD;
/*
$pdf->writeHTML($tbl, true, false, false, false, '');*/

// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x=14, $y=100, $amout_words, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);

$pdf->writeHTMLCell($w=0, $h=0, $x=14, $y=65, $item_table, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);//item details

$pdf->writeHTMLCell($w=0, $h=0, $x=140, $y=20, $amount_table, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);//number amount



$pdf->SetFont('times', 'B', 10);
$pdf->Text(24, 112, 'Prepared');
$pdf->Text(100, 112, 'Checked by');
$pdf->Text(180, 112, 'Authorized');
$pdf->SetFont('times', 'B', 10);
$pdf->Text(14, 115, '----------------------------------------------------------------------------------------');

$pdf->SetFont('times', '', 10);
$pdf->writeHTMLCell($w=0, $h=0, $x=14, $y=120, $amout_words_last, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);//number amount


$pdf->SetFont('times', 'BI', 10);
$pdf->Text(14, 135, 'Rs : ');
$pdf->SetFont('times', '', 10);
$pdf->Text(22, 135, '**'.$number_amount);

$pdf->SetFont('times', 'BI', 10);
$pdf->Text(170, 137, 'Signature Of Receiver');

//$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);

//Close and output PDF document
$pdf->Output('arrival_report.pdf', 'I');

//============================================================+
// END OF FILE                                                
//============================================================+
?>