<?php 
/**********************************************************************
	Copyright (C) Evolve Techniologies
	Author : Evolve Technologies
	Email : info@evolve-sl.com
	Company : Evolve Technologies(pvt)Ltd
***********************************************************************/
ob_start();
$page_security = 'SA_GLTRANSVIEW';
$path_to_root = "..";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/gl/includes/gl_db.inc");

require_once('config/lang/eng.php');
require_once('tcpdf.php');
// create new PDF document
//$pdf = new TCPDF('L', PDF_UNIT, 'CH', true, 'UTF-8', false);//-----for continues check
$pdf = new TCPDF('L', PDF_UNIT, 'CHA', 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(TRUE, PDF_MARGIN_BOTTOM);
//set some language-dependent strings
$pdf->setLanguageArray($l);

$from = $_REQUEST['from'];
$to = $_REQUEST['to'];
$account = $_REQUEST['bank_account'];

$prt_Type = 50;//----cheque type define as 50 

$resultBulk = get_selected_bank_trans_for_print($account, $from, $to, $prt_Type);

$type_id_array = array();
$trans_no_array = array();

$j=0;

while($myrowsBulk = mysqli_fetch_array($resultBulk)) {
	$type_id_array[$j] = $myrowsBulk['type'];
	$trans_no_array[$j] = $myrowsBulk['trans_no'];
	$j++;
}

	if(count($trans_no_array)==0){
		$type_id_array[0] = $_GET['type_id'];
		$trans_no_array[0] = $_GET['trans_no'];
	}
	
for($i=0;$i<count($trans_no_array);){
	$result = get_gl_trans($type_id_array[$i], $trans_no_array[$i]);

while ($myrow = db_fetch($result)) 
{
	if ($myrow['amount'] == 0) continue;
	$trans_no = $myrow["reference"];	
	$date = $myrow["tran_date"];
	$myrow['account'];
	$myrow['account_name'];
	
	$memo .= $myrow['memo_'];
	
	//display_debit_or_credit_cells($myrow['amount']);
	if($myrow['amount']>0){
		$display_total = $display_total + $myrow['amount'];
		$peson_typeid = $myrow['person_type_id'];
		$personid = $myrow['person_id'];
	}
	if ($myrow['amount'] > 0 ) 
    	$debit += $myrow['amount'];
   	else 
    	$credit += $myrow['amount'];
	
		$cheque_no =  $myrow['cheque_no'];
		
		
}
	$bank_trans = db_fetch(get_bank_trans($type_id_array[$i], $trans_no_array[$i]));

//------get payee name form the banktrans table----
	$payee_name = payment_person_name_cheque($type_id_array[$i], $trans_no_array[$i], $bank_trans['person_type_id'], $bank_trans['person_id']);
	
	//$payee_name =  html_entity_decode(payment_person_name_cheque($peson_typeid,$personid));

		
		
//-------------------changed code 15.08.2012---------------	
	$result_paymode = get_payment_mode($bank_trans['cheque_reference']);
	while ($paymode_row = db_fetch($result_paymode)) {
		$pay_mode = $paymode_row['pay_mode'];//----danu add pay mode 30.11.2011	
	}
//-------------------changed code 15.08.2012---------------	
	require_once ('class.numbertoword.php');

	$amount = abs($display_total);
	$display_total = 0;
	$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 Cent '.CLASS_Numbertoword::convert($cents,'en').' only';
				break;
			default:
			   $amount_w_db =  CLASS_Numbertoword::convert($rupees,'en').' and Cents '.CLASS_Numbertoword::convert($cents,'en').' only';
		}
		
		$date = date("ymd");
		$date_array = str_split($date);
$test = '<table cellspacing="0" cellpadding="1" border="0"><tr><td>**'.$amount_w_db.'</td></tr></table>';
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', '', 12);
// add a page
$pdf->AddPage();

//-----for continues check
/*$pdf->Text(190, 4, $date_array[4]);
$pdf->Text(197, 4, $date_array[5]);
$pdf->Text(204, 4, $date_array[2]);
$pdf->Text(210, 4, $date_array[3]);
//$pdf->Text(217, 5, '2');
//$pdf->Text(224, 5, '0');
$pdf->Text(229, 4, $date_array[0]);
$pdf->Text(236, 4, $date_array[1]);*/
//-----for continues check


$pdf->Text(120, 4, $date_array[4]);
$pdf->Text(127, 4, $date_array[5]);
$pdf->Text(134, 4, $date_array[2]);
$pdf->Text(141, 4, $date_array[3]);
$pdf->Text(160, 4, $date_array[0]);
$pdf->Text(167, 4, $date_array[1]);

//==========payee name-----
//$pdf->writeHTMLCell($w=0, $h=0, $x=82, $y=19, $payee_name, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);//-----for continues check
$pdf->writeHTMLCell($w=0, $h=0, $x=12, $y=17, $payee_name, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);

//------------------amount in word-----------------
$tbl = <<<EOD
	<table width="280" height="42" border="0" cellpadding="1" cellspacing="0">
		<tr align="left">
			<td width="280">
			$test
			</td>
    </tr>
</table>
EOD;
$payee = <<<EOD
	<table width="100" height="42" border="0" cellpadding="1" cellspacing="0">
		<tr align="left">
			<td width="100">
			$payee_name
			</td>
    </tr>
</table>
EOD;
$ac_payee_only = <<<EOD
			<table width="80">
				<tr>
					<td>
					<hr width ="50">
					AC Payee Only
					<hr width ="50">
					</td>
				</tr>
			</table>
EOD;
/*
$pdf->writeHTML($tbl, true, false, false, false, '');*/
// Print text using writeHTMLCell()
//$pdf->writeHTMLCell($w=0, $h=0, $x=86, $y=29, $tbl, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);//-----for continues check
$pdf->writeHTMLCell($w=0, $h=0, $x=15, $y=27, $tbl, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);
//==============amount in number================
//$pdf->Text(188, 36, '**'.$number_amount);//-----for continues check
$pdf->Text(120, 33, '**'.$number_amount);

$pdf->SetFont('times', '', 8);
//------ac payee coly print code------------
if($pay_mode == 0)
//$pdf->writeHTMLCell($w=0, $h=0, $x=120, $y=10, $ac_payee_only, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);//-----for continues check
$pdf->writeHTMLCell($w=0, $h=0, $x=75, $y=7, $ac_payee_only, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);

//-----------authirised signature
/*$pdf->Text(150, 67, '........................................');
$pdf->Text(155, 70, 'Authorised Signature');
$pdf->Text(110, 67, '........................................');
$pdf->Text(113, 70, 'Authorised Signature');*/

$pdf->SetFont('times', '', 12);


//counter system for the continues system 
/*$pdf->Text(25, 7, date("Y-m-d"));//date
$pdf->writeHTMLCell($w=50, $h=0, $x=20, $y=15, html_entity_decode($payee), $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);
//==============amount in number================
$pdf->Text(25, 40, '**'.$number_amount);*/


$i++;
}

$pdf->lastPage();
$pdf->Output('Cheque.pdf', 'I');
//============================================================+
// END OF FILE                                                
//============================================================+
?>