<?php
/**********************************************************************
    	Copyright (C) Evolve Techniologies
	Author : Evolve Technologies
	Email : info@evolve-sl.com
	Company : Evolve Technologies(pvt)Ltd

***********************************************************************/
$page_security = 'SA_SUPPTRANSVIEW';
$path_to_root = "..";
include($path_to_root . "/purchasing/includes/po_class.inc");
include($path_to_root . "/includes/session.inc");
include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
function get_orderd_qty($order_no, $stock_id){
	$sql = "SELECT * FROM `".TB_PREF."purch_order_details` WHERE order_no = ".db_escape($order_no)." AND item_code = ".db_escape($stock_id);
	
	$result = db_query($sql, "The grn sent is not valid");

	$row = db_fetch($result);
	return $order_qty = $row["quantity_ordered"];
}


$purchase_order = new purch_order;

read_grn($_GET["trans_no"], $purchase_order);

//---------------------------

$purchase_order->supplier_name;

$purchase_order->curr_code;
$purchase_order->order_no;
$purchase_order->orig_order_date;
$purchase_order->reference;
$purchase_order->supp_ref;
$purchase_order->delivery_address;
$purchase_order->Comments;
//---------------------------
//print_r($purchase_order->order_no);
$total = 0;
$k = 0;  //row colour counter
$count = 1;

foreach ($purchase_order->line_items as $stock_item)
{

	$line_total = $stock_item->qty_received * $stock_item->price;

	$dec = get_qty_dec($stock_item->stock_id);
	$total += $line_total;
	
	
	$line_total;
	$k;
	$stock_item->stock_id;
	$stock_item->req_del_date;
	$dec;
	$stock_item->qty_received;
	$stock_item->units;
	$stock_item->price;
	$line_total;
	$stock_item->qty_inv;
	
	$items .= '<tr>
				<td width="85" align="center">'.$stock_item->stock_id.'</td>
				<td width="230" align="left">'.$stock_item->item_description.'</td>
				<td width="30" align="center">'.$stock_item->units.'</td>
				<td width="45" align="center">'.get_orderd_qty($purchase_order->order_no, $stock_item->stock_id).'</td>
				<td width="45" align="center">'.$stock_item->qty_received.'</td>
				<td width="125" align="right"></td>
			</tr>';
	
	$count = $count+1;
}

	/*$items .= '<tr>
				<td colspan="5" align="right"><b>Total</b></td>
				<td width="85" align="right">'.price_format($total).'</td>
			</tr>';
*/


 $display_sub_tot = number_format2($total,user_price_dec());

 $taxes = $purchase_order->get_taxes();
 //$tax_total = display_edit_tax_items($taxes, 6, $purchase_order->tax_included, 1);

// $display_total = price_format(($total + $tax_total));



//--------------pdf function start here--------------------------------
require_once('config/lang/eng.php');
require_once('tcpdf.php');

// create new PDF document
$pdf = new TCPDF('P', PDF_UNIT, 'A4', 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);

// ---------------------------------------------------------
// add a page
$pdf->AddPage();

// set font
$pdf->SetFont('helvetica', 'B', 16);
$pdf->Text(35, 6, 'Northshore College of Bisuness & Technology(Pvt) LTD.');//------------hotel name---------------

$pdf->SetFont('helvetica', '', 10);
$pdf->Text(65, 13, '141, Church Road, Colombo - 15, Sri Lanka.');//-------hotel address-----------------

$pdf->SetFont('helvetica', '', 10);
$pdf->Text(75, 18, 'Tel : +94 11 2368690');//-------hotel address-----------------

$pdf->SetFont('helvetica', '', 11);
$pdf->Text(81, 22, 'GOODS RECEIVED NOTE');//----------------------bill heading-------

//-----------------supplier details-------------
$pdf->SetFont('helvetica', '', 10);
$pdf->Text(5, 30, 'Supplier`s Name : '.$purchase_order->supplier_name);
$pdf->Text(35, 35, $purchase_order->delivery_address);
$pdf->Text(5, 40, 'Supp. Reference : '.$purchase_order->supp_ref);//$purchase_order->reference

//$pdf->Text(150, 25, 'GRN No  :  '.$_GET['trans_no']);
$pdf->Text(150, 25, 'GRN No  :  '.$purchase_order->reference);

$pdf->Text(150, 30, 'P/Order No  :  '.$purchase_order->order_no);
$pdf->Text(150, 40, 'Date : '.$purchase_order->orig_order_date);
//-----------------end supplier details-------------------

$item_table = <<<EOD
				<table width="500" height="42" border="1" cellpadding="1" cellspacing="0">
						<tr style="background-color:#D8ECF2; font-weight:bold">
							<td width="85" align="center"><b>Code</b></td>
							<td width="230" align="center"><b>Description</b></td>
							<td width="30" align="center"><b>Unit</b></td>
							<td width="45" align="center">QTY Ordered</td>
							<td width="45" align="center">QTY Recived</td>
							
							<td width="125" align="center"><b>Remark</b></td>
						</tr>
					$items
				</table>
EOD;

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

if($count=1){

$val = 50+(30*$count);
$val_potioion = 55+(30*$count);
	
}else{
	
$val = 70+(10*$count);
$val_potioion = 55+(10*$count);
	
}

//$pdf->Text(10, 260, '......................');
$pdf->Text(40, 260, '.....................................');
//$pdf->Text(95, 260, '......................');
$pdf->Text(120, 260, '....................................');
///$pdf->Text(175, 260, '......................');



//$pdf->Text(10, 265, 'Store Keeeper');
//$pdf->Text(50, 265, 'Accontant');
$pdf->Text(50, 265, 'Received by');
$pdf->Text(130, 265, 'Authorized by');
//$pdf->Text(180, 265, 'Authoris');

$pdf->Output('gl_chk.pdf', 'I');

//============================================================+
// END OF FILE                                                
//============================================================+


?>
