<?php
/**********************************************************************
	Copyright (C) Evolve Techniologies
	Author : Danushka Widanage
	Email : dwidanage@gmail.com
	Company : Evolve Technologies(pvt)Ltd
***********************************************************************/
/*****
*
*	Set document type dependent elements of common page layout.
*
*/
	$Addr1 = array(
			'title' => _("To:"),
			'name' => @$this->formData['br_name'] ? $this->formData['br_name'] : @$this->formData['DebtorName'],
			'address' => @$this->formData['br_address'] ? $this->formData['br_address'] : @$this->formData['address']
	);
	/**********************BOF Chat Commented********************/
	/*$Addr2 = array(
			'title' => _("Delivered To"),
			'name' => @$this->formData['deliver_to'],
			'address' => @$this->formData['delivery_address']
	);*/
	/**********************EOF Chat Commented********************/
	
	// default item column headers
	//$this->headers = array(_("Programme Code"), _("Programme Description"), _("Quantity"), _("Unit"), _("Fee"), _(""), _("Total"));
	
	/***************************BOF Chat Added**********************/
	//$this->headers = array(_("Programme Code"), _("Programme Description"), _("Year"), _("Level"), _("Fee"), _("Total"));
	$this->headers = array(_("Programme Detail"), _("Description"), _("Total"));
	/***************************EOF Chat Added**********************/
	
	// for links use 'text' => 'url'
	//$Footer[0] = _("All amounts stated in") . " - " . @$this->formData['curr_code'];
	
	$amount_lkr = _("All amounts stated in") . " - " . @$this->formData['curr_code'];
	
	if (!isset($Payment_Terms))
	{
		$id = $this->formData['payment_terms'];
		$sql = "SELECT terms FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($id);
		$result = db_query($sql,"could not get paymentterms");
		$row = db_fetch($result);
		$Payment_Terms = _("Payment Terms") . ': ' . $row["terms"];
		
	}
	
	switch ($this->formData['doctype'])
	{

		case ST_PURCHORDER:
			$this->title = _("PURCHASE ORDER");
			$this->formData['document_name'] =_("Purchase Order No.");
			$Addr1['title'] = _("Order To");
			$Addr1['name'] = $this->formData['supp_name'];
			$Addr1['address'] = $this->formData['address'];
			$Addr2['title'] = _("Deliver To");
			$Addr2['name'] = $this->company['coy_name'];
			//$Addr2['address'] = $this->company['postal_address']; No, don't destroy delivery address!
			$this->formData['document_date'] = $this->formData['ord_date'];
			//$this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference']) ? $this->formData['reference'] : $this->formData['order_no'];
			$this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference']) ? $this->formData['order_no'] : $this->formData['order_no'];
			$this->formData['quotation_no'] = $this->formData['requisition_no'];
			/*$aux_info = array(
				_("Customers Reference") => $this->formData['supp_account_no'],
				_("Sales Person") => '',
				_("Your VAT no.") => '',
				_("Our Order No") => '',
				_("Due Date") => '',
			);*/

			$this->headers = array(_("Item Code"), _("Item Description"), _("Delivery Date"), _("Quantity"), 	_("Unit"), _("Price"), _("Total"));
			break;

		

	}

	// default values
	if (!isset($this->formData['document_date']))
		$this->formData['document_date'] = $this->formData['tran_date'];

	if (!isset($this->formData['document_number']))
		$this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference'])
			? $this->formData['reference'] : @$this->formData['trans_no'];

	/*if (!isset($Payment_Terms))
	{
		$id = $this->formData['payment_terms'];
		$sql = "SELECT terms FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($id);
		$result = db_query($sql,"could not get paymentterms");
		$row = db_fetch($result);
		$Payment_Terms = _("Payment Terms") . ': ' . $row["terms"];
	}*/

	// footer generic content
	//if (@$this->formData['bank_name'])
		//$Footer[] = _("Bank"). ": ".$this->formData['bank_name']. ", " . _("Bank Account") . ": " . $this->formData['bank_account_number'];
		//$Footer[] = _("Bank"). ": ".$this->formData['bank_name']. ", " . _("Bank Account") . ": " . $this->formData['bank_account_number'];

	if (@$this->formData['payment_service'])	//payment link
	{
		$amt = number_format($this->formData["ov_freight"] + $this->formData["ov_gst"] + $this->formData["ov_amount"], user_price_dec());
		$service = $this->formData['payment_service'];
		$url = payment_link($service, array(
			'company_email' => $this->company['email'],
			'amount' => $amt,
			'currency' => $this->formData['curr_code'],
			'comment' => $this->title . " " . $this->formData['reference']
			));
		$Footer[_("You can pay through"). " $service: "] = "$url";
	}

	if ($this->formData['doctype'] == ST_CUSTPAYMENT)
 		$Footer[] = _("* Subject to Realisation of the Cheque.");

	if ($this->params['comments'] != '')
		$Footer[] = $this->params['comments'];

	if (($this->formData['doctype'] == ST_SALESINVOICE || $this->formData['doctype'] == ST_STATEMENT) && $this->company['legal_text'] != "") 
	{
		foreach(explode("\n", $this->company['legal_text']) as $line)
			$Footer[] = $line;
	}

?>
