<?php
/*
27/08/2010 - Started
27/09/2010 - User User_Session
05/10/2010 - 20 Rows for Invoice Nos
07/10/2010 - NOT Allowing ZERO Amount to be Posted
07/10/2010 - Invoice Entered Value NOT to be more than the Balance Value
14/10/2010 - Checking Debit and Credit Balance before Posting
14/10/2010 - Remove Printing of Details
17/12/2010 - Change Date Display
24/12/2010 - Refer Sarathy's Mail dated 24/12/2010
31/12/2010 - Value Date for Receipt NOT correct
*/
ob_start('ob_gzhandler');
include("Functions_Sales.php");

error_reporting(E_ERROR);
if($_SESSION['dbName']==""){
	header("location:../index.php");
}

//Open MySQLI Connection
$aconn = openALConnection();
$conn = openConnection();
$iconn = openIConnection();


$querylog="SELECT FA_Receipt as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')	";
	$resultlog=mysql_query($querylog,$conn) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");


$txtID = $_POST["txtID"]; if ($txtID == ""){$txtID = $_GET["txtID"];}
$txtRef = $_POST["txtRef"]; if ($txtRef == ""){$txtRef = $_GET["txtRef"];}
$txtSearchRef = $_POST["txtSearchRef"]; if ($txtSearchRef == ""){$txtSearchRef = $_GET["txtSearchRef"];}
$txtDate = $_POST["txtDate"]; if ($txtDate== ""){$txtDate = $_GET["txtDate"];} if ($txtDate== ""){$txtDate = displayToday();}
$txtReceiptDate = $_POST["txtReceiptDate"]; if ($txtReceiptDate == ""){$txtReceiptDate = $_GET["txtReceiptDate"];} if ($txtReceiptDate== ""){$txtReceiptDate = displayToday();}
$txtRemark = $_POST["txtRemark"]; if ($txtRemark == ""){$txtRemark = $_GET["txtRemark"];}
$txtRepresentative = $_POST["txtRepresentative"]; if ($txtRepresentative == ""){$txtRepresentative = $_GET["txtRepresentative"];}

$lstCashType = $_POST['lstCashType']; if ($lstCashType == ""){$lstCashType = $_GET["lstCashType"];}
$txtCashReference = $_POST['txtCashReference']; if ($txtCashReference == ""){$txtCashReference = $_GET["txtCashReference"];}
$txtManualNo = $_POST['txtManualNo']; if ($txtManualNo == ""){$txtManualNo = $_GET["txtManualNo"];}
$lstCurrency = $_POST['lstCurrency']; if ($lstCurrency == ""){$lstCurrency = $_GET["lstCurrency"];} if ($lstCurrency == ""){$lstCurrency = "NGN";}
$lstCostCentre = $_POST['lstCostCentre']; if ($lstCostCentre == ""){$lstCostCentre = $_GET["lstCostCentre"];}
$lstProject = $_POST['lstProject']; if ($lstProject == ""){$lstProject = $_GET["lstProject"];}

$txtTotDebit = $_POST['txtTotDebit']; if ($txtTotDebit == ""){$txtTotDebit = $_GET["txtTotDebit"];}
$txtTotCredit = $_POST['txtTotCredit']; if ($txtTotCredit == ""){$txtTotCredit = $_GET["txtTotCredit"];}

$act = $_POST['act']; if ($act == ""){$act = $_GET["act"];}
$prints = $_POST['prints']; if ($prints == ""){$prints = $_GET["prints"];}
$message = $_GET["message"];

//$user_level_receipt = $_POST['user_level_receipt']; if ($user_level_receipt == ""){$user_level_receipt = $_GET["user_level_receipt"];} 
$user_level_receipt = $_SESSION['user_level_receipt'];
$warehouseQuery1 = $_SESSION['warehouseQuery1'];	
$warehouseQuery2 = $_SESSION['warehouseQuery2'];
$projectQuery = $_SESSION['projectQuery'];	
$defaultProject = $_SESSION['defaultProject'];
$defaultWarehouse = $_SESSION['defaultWarehouse'];

//echo "52".$user_level_receipt;
if ($user_level_receipt == ""){
	$query = "SELECT FA_receiptMod, FA_receiptDel, FA_receiptApp, FA_receipt FROM ".$_SESSION['dbLabel'].".login where user_account= '".$_SESSION['useraccount']."'";
	$result = selectData($aconn, $query);	
	
	//$result = getUserAccess($_SESSION['dbLabel'], $_SESSION['useraccount']);
	if ($result[0] == "1"){$user_level_receipt = $user_level_receipt . "-RE-";}
	if ($result[1] == "1"){$user_level_receipt = $user_level_receipt . "-RD-";}
	if ($result[2] == "1"){$user_level_receipt = $user_level_receipt . "-RA-";}
	if ($result[3] == "1"){$user_level_receipt = $user_level_receipt . "-RV-";}

	if ($result[3] == "0"){
		header("Location: logout5.php");
	}else{
		$_SESSION['user_level_receipt'] = $user_level_receipt;	
	}
	
	$this_query = "SELECT Project_code FROM ".$_SESSION['dbLabel'].".loginstk WHERE user_account = '".$_SESSION['useraccount']."' AND Project_code IS NOT NULL ";
	$result = selectData($aconn, $this_query);
	if ($result[0] != "0" && $result[0] != "" && $result[0] != "NULL"){
		$projectQuery = " AND Project_code IN (".$this_query.")";
	}
	$_SESSION['projectQuery'] = $projectQuery;

	$this_query = "SELECT Project_code FROM ".$_SESSION['dbLabel'].".loginstk WHERE user_account = '".$_SESSION['useraccount']."' AND Default_Project = 1 ";
	$result = selectData($aconn, $this_query);
	if ($result[0] != "0" && $result[0] != "" && $result[0] != "NULL"){
		$defaultProject = $result[0];
	}
	$_SESSION['defaultProject'] = $defaultProject;
	//echo "106".$defaultProject;

	$_SESSION["userSession"] = $_SESSION['useraccount'] . insertToday() . rand();
}
//echo "<br><br>".$user_level_receipt;

if($act == "deleteRow"){
	//Delete chkjourdt
	$query = "DELETE FROM chkjourdt WHERE TransDt_Id = '".$_POST['txtDeleteRowCode']."'";
	updateIData($iconn, $query, false);
	
	//Delete cstjourdt
	$query = "DELETE FROM cstjourdt WHERE TransDt_Id = '".$_POST['txtDeleteRowCode']."'";
	updateIData($iconn, $query, false);

	//Delete acclink
	$query = "DELETE FROM acclink WHERE Journal_Id = '".$_POST['txtDeleteRowCode']."'";
	updateIData($iconn, $query, false);

	//Delete transdt
	$query = "DELETE FROM TransDt WHERE TransDt_Id = '".$_POST['txtDeleteRowCode']."'";
	updateIData($iconn, $query, true);	
	$message = "Row Deleted";
}else if($act == "submitRecord" || $act == "saveChanges"){	
	//$query = "SELECT SUM(Transdt_Amount) FROM transdt WHERE TransDt_dbcd = 'C' AND User_Account = '".$_SESSION['userSession']."' ";
	$query = "SELECT SUM(Transdt_Amount) FROM transdt WHERE TransDt_dbcd = 'C' AND trans_id = '".$txtID."' ";
	$result = selectData($conn, $query);
	$total_credit = $result[0];

	//$query = "SELECT SUM(Transdt_Amount) FROM transdt WHERE TransDt_dbcd = 'D' AND User_Account = '".$_SESSION['userSession']."' ";
	$query = "SELECT SUM(Transdt_Amount) FROM transdt WHERE TransDt_dbcd = 'D' AND trans_id = '".$txtID."' ";
	$result = selectData($conn, $query);
	$total_debit = $result[0];

	if ($total_credit == $total_debit){		
		$query = "UPDATE TransDt SET User_Account = '' WHERE User_Account = '".$_SESSION['userSession']."' ";		
		if (updateIData($iconn, $query, false)){
			//echo "<br><br>".$query;
			$query = "UPDATE chkjourdt SET User_Account = '' WHERE User_Account = '".$_SESSION['userSession']."'";
			if (updateIData($iconn, $query, false)){
				//echo "<br><br>".$query;
				$query = "UPDATE cstjourdt SET User_Account = '' WHERE User_Account = '".$_SESSION['userSession']."'";
				if (updateIData($iconn, $query, false)){
					//echo "<br><br>".$query;
					$query = "UPDATE acclink SET User_Account = '' WHERE User_Account = '".$_SESSION['userSession']."'";
					if (updateIData($iconn, $query, false)){
						//echo "<br><br>".$query;
						$txtCashTypeRef = "0";
						if ($lstCashType != "" && $act == "submitRecord"){
							$query = "SELECT cashtype_Reference FROM cashType WHERE CashType_Code = '".$lstCashType."' AND Journal_Type = 'RV'";
							$result = selectData($conn, $query);
							$txtCashTypeRef = $result[0];
							if ($txtCashTypeRef == "" || $txtCashTypeRef == "NULL" || $txtCashTypeRef == "null"){$txtCashTypeRef = 0;}
							$txtCashTypeRef = $txtCashTypeRef*1 + 1;

							$query = "UPDATE cashType SET cashtype_Reference = '".($txtCashTypeRef*1 + 1)."' WHERE CashType_Code = '".$lstCashType."' AND Journal_Type = 'RV'";
							updateIData($iconn, $query, false);	
							//echo "<br><br>".$query;
						}

						$j_id = get_nextsequence("journal_id" , "",$conn);
		
						if($act == "submitRecord"){
							$txtRef = get_nextsequence("Receipt_RefGovernment" , "",$conn);
							//$query = "UPDATE trans SET Trans_SysDate = CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), Trans_Date = CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), Trans_Remark = '".$txtRemark."', Trans_Representative = '".$txtRepresentative."', Currency_Code = '".$lstCurrency."', Project_Code = '".$lstProject."', Trans_Reference = '".$txtRef."', Trans_AmountDb1 = '".($txtTotDebit * $rate_dt)."', Trans_AmountDb2 = '".($txtTotDebit / $parity_dt)."' , Trans_Amountcd1 = '".($txtTotCredit * $rate_dt)."' , Trans_Amountcd2 = '".($txtTotCredit / $parity_dt)."', Trans_Type = 'RV' , CashType_Code = '".$lstCashType."' , Trans_CashReference = '".$txtCashTypeRef."', Trans_ManualNo = '".$txtManualNo."' WHERE Trans_ID = ".$txtID."";
							$query = "UPDATE trans SET Trans_SysDate = CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), Trans_Date = CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), Trans_Remark = '".$txtRemark."', Trans_Representative = '".$txtRepresentative."', Currency_Code = '".$lstCurrency."', Project_Code = '".$lstProject."', Trans_Reference = '".$txtRef."', Trans_AmountDb1 = convertcurfunc('".$lstCurrency."', (select BASE1 from setup), CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), 0, 0, '', '', ".$txtTotDebit."), Trans_AmountDb2 = convertcurfunc('".$lstCurrency."', (select BASE2 from setup), CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), 0, 0, '', '', ".$txtTotDebit."), Trans_Amountcd1 = Trans_AmountDb1, Trans_Amountcd2 = Trans_AmountDb2, Trans_Type = 'RV' , CashType_Code = '".$lstCashType."' , Trans_CashReference = '".$txtCashTypeRef."', Trans_ManualNo = '".$txtManualNo."', Journal_id = '".$j_id."', User_account = '".$_SESSION["useraccount"]."' WHERE Trans_ID = ".$txtID."";
							$message = "Record Added";
						}else{
							//$query = "UPDATE trans SET Trans_SysDate = CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), Trans_Date = CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), Trans_Remark = '".$txtRemark."', Trans_Representative = '".$txtRepresentative."', Currency_Code = '".$lstCurrency."', Project_Code = '".$lstProject."', Trans_AmountDb1 = '".($txtTotDebit * $rate_dt)."', Trans_AmountDb2 = '".($txtTotDebit / $parity_dt)."' , Trans_Amountcd1 = '".($txtTotCredit * $rate_dt)."' , Trans_Amountcd2 = '".($txtTotCredit / $parity_dt)."', Trans_ManualNo = '".$txtManualNo."' WHERE Trans_ID = ".$txtID."";
							$query = "UPDATE trans SET Trans_SysDate = CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), Trans_Date = CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), Trans_Remark = '".$txtRemark."', Trans_Representative = '".$txtRepresentative."', Currency_Code = '".$lstCurrency."', Project_Code = '".$lstProject."', Trans_AmountDb1 = convertcurfunc(Currency_Code, (select BASE1 from setup), CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), 0, 0, '', '', ".$txtTotDebit."), Trans_AmountDb2 = convertcurfunc(Currency_Code, (select BASE2 from setup), CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), 0, 0, '', '', ".$txtTotDebit."), Trans_Amountcd1 = Trans_AmountDb1, Trans_Amountcd2 = Trans_AmountDb2, Trans_ManualNo = '".$txtManualNo."', Journal_id = '".$j_id."' WHERE Trans_ID = ".$txtID."";
							$message = "Record Updated";
						}
						$commit_flag = true;
						//echo "<br><br>".$query;
						if (updateIData($iconn, $query, false)){
							if($act == "submitRecord"){
								//Create JV Master (Header)								
								$query = "INSERT INTO journal (journal_id, journal_refgovernment, journal_folio, journal_type, journal_flag, User_account, User_Name, Journal_Date, Journal_SysDate, Journal_Time, Project_Code, Journal_dtincr, Journal_typeref, Amnt1_db, Amnt1_cd, Amnt2_db, Amnt2_cd) VALUES (".$j_id.", ".get_nextsequence("journal_refgovernment" , "",$conn).", '".jFolio($conn)."', 'RV', 'N', '".$_SESSION["useraccount"]."', '', CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), '".$lstProject."', 100, 'RV".addZero(get_nextsequence("Journal_typeref" , "",$conn), 8)."', convertcurfunc('".$lstCurrency."', (select BASE1 from setup), CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), 0, 0, '', '', ".$txtTotDebit."), Amnt1_db, convertcurfunc('".$lstCurrency."', (select BASE2 from setup), CONCAT('".displayParadoxDate(insertDate($txtDate))." ', RIGHT(NOW(), 8)), 0, 0, '', '', ".$txtTotDebit."), Amnt2_db)";
								//echo "<br><br>".$query;
								if (updateIData($iconn, $query, false)){
									//Do Nothing
								}else{
									$commit_flag = false;
								}
							}else{
								$query = "UPDATE journal, trans SET journal.Amnt1_db = convertcurfunc('".$lstCurrency."', (select BASE1 from setup), CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), 0, 0, '', '', ".$txtTotDebit."), journal.Amnt1_cd = journal.Amnt1_db, journal.Amnt2_db = convertcurfunc('".$lstCurrency."', (select BASE2 from setup), CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), 0, 0, '', '', ".$txtTotDebit."), journal.Amnt2_cd = journal.Amnt2_db WHERE journal.journal_id = trans.journal_id and trans.trans_id = '".$txtID."' ";
								//echo "<br><br>".$query;
								if (updateIData($iconn, $query, false)){
									$query = "DELETE FROM journaldt where journal_id = (select journal_id FROM trans where trans_id = '".$txtID."')";
									//echo "<br><br>".$query;
									updateIData($iconn, $query, false);
								}
								$query = "select journal_id FROM trans where trans_id = '".$txtID."'";
								$j_result = selectData($conn, $query);
								$j_id = $j_result[0];
							}
							$query = "SELECT trans_id, trans_date, Ledger_number, Currency_Code, Transdt_Description, Transdt_Amount, Transdt_Amount1, Transdt_Amount2, TransDt_dbcd, transdt_id FROM transdt where trans_id = '".$txtID."'";
							$result = mysql_query($query, $conn);
							$count = 0;							
							while ($cur = mysql_fetch_row($result)){
								$count++;
								//$query = "INSERT INTO journaldt (journaldt_id, journal_id, Ledger_Number, Document, Currency_Code, Journaldt_DBCD, Journaldt_dbcdAra, Journaldt_Desc, Journal_date, Journaldt_valuedate, Journaldt_Amount, Journaldt_Amount1, Journaldt_Amount2) VALUES (".(($j_id*1000000)+$count).", ".$j_id.", '".$cur[2]."', '".$cur[2]."', '".$cur[3]."', '".$cur[8]."', '?', '".ereg_replace("\'", "''", trim($cur[4]))."', '".$cur[1]."', '".$cur[1]."', '".$cur[5]."', '".$cur[6]."', '".$cur[7]."')";
								$query = "INSERT INTO journaldt (journaldt_id, journal_id, Ledger_Number, Document, Currency_Code, Journaldt_DBCD, Journaldt_dbcdAra, Journaldt_Desc, Journal_date, Journaldt_valuedate, Journaldt_Amount, Journaldt_Amount1, Journaldt_Amount2) VALUES (".(($j_id*1000000)+$count).", ".$j_id.", '".$cur[2]."', '".$cur[2]."', '".$cur[3]."', '".$cur[8]."', '?', '".ereg_replace("\'", "''", trim("RECEIPT: ".$txtRef." ". $cur[4]))."', CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), CONCAT('".displayParadoxDate(insertDate($txtReceiptDate))." ', RIGHT(NOW(), 8)), '".$cur[5]."', '".$cur[6]."', '".$cur[7]."')";
								//echo "<br><br>".$query;
								if (updateIData($iconn, $query, false)){
									//Insert INTO chkjour
									$chk_query = "SELECT Chk_number, Chk_Bank, Chk_ValueDate, Currency_code, Chk_Amount, Chk_Amount1, Chk_Amount2, Ledger_Number FROM chkjourdt WHERE TransDt_Id = '".$cur[9]."'";									
									$chk_result = mysql_query($chk_query, $conn);
									while ($chk_cur = mysql_fetch_row($chk_result)){
										$query = "INSERT INTO chkjour (Chk_number, Chk_Bank, Chk_ValueDate, Currency_code, Chk_Amount, Chk_Amount1, Chk_Amount2, Ledger_Number, journaldt_id) VALUES ('".$chk_cur[0]."', '".$chk_cur[1]."', '".$chk_cur[2]."', '".$chk_cur[3]."', '".$chk_cur[4]."', '".$chk_cur[5]."', '".$chk_cur[6]."', '".$chk_cur[7]."', '".(($j_id*1000000)+$count)."')";
										//echo "<br><br>".$query;
										if (updateIData($iconn, $query, false)){
											$query = "UPDATE journaldt SET Journaldt_valuedate = '".$chk_cur[2]."' WHERE journal_id = ".$j_id;
											if (updateIData($iconn, $query, false)){
												//Do Nothing
											}else{
												$commit_flag = false;
											}											
										}else{
											$commit_flag = false;
										}
									}

									//Insert INTO cstjour
									$cst_query = "SELECT Project_code, CstjourDt_Per, CstJourDt_Amount, CstJourDt_Amount1, CstJourDt_Amount2 FROM cstjourdt WHERE TransDt_Id = '".$cur[9]."'";
									$cst_result = mysql_query($cst_query, $conn);
									while ($cst_cur = mysql_fetch_row($cst_result)){
										$query = "INSERT INTO cstjour (Project_code, Cstjour_prcnt, CstJour_Amount, CstJour_Amount1, CstJour_Amount2, journaldt_id) VALUES ('".$cst_cur[0]."', '".$cst_cur[1]."', '".$cst_cur[2]."', '".$cst_cur[3]."', '".$cst_cur[4]."', '".(($j_id*1000000)+$count)."')";
										//echo "<br><br>".$query;
										if (updateIData($iconn, $query, false)){
											//Do Nothing
										}else{
											$commit_flag = false;
										}
									}
								}else{
									$commit_flag = false;
								}
							}
							if ($commit_flag){
								mysqli_commit($iconn);
								header("Location: receipt_form.php?act=viewRecord&txtRef=".$txtRef."&txtID=".$txtID."&message=Record Added");
								$act = "viewRecord";
							}else{
								$message = "Receipt COULD NOT be Posted/ Saved [JV/ Cheque/ Project NOT Posted]";
							}
						}else{
							$message = "Receipt COULD NOT be Posted/ Saved";
						}						
					}
				}
			}
		}
	}else{
		$message = "Receipt COULD NOT be Posted/ Saved. DEBIT Total DOES NOT match CREDIT Total";
		$act = "";
	}
}else if($act == "deleteRecord"){
	//Delete chkjourdt
	$query = "DELETE FROM chkjourdt, transdt WHERE transdt.Trans_id = '".$txtID."' AND transdt.TransDt_Id = chkjourdt.TransDt_Id";
	updateIData($iconn, $query, false);
	//echo "<br><br>".$query;
	
	//Delete cstjourdt
	$query = "DELETE FROM cstjourdt, transdt WHERE transdt.Trans_id = '".$txtID."' AND transdt.TransDt_Id = cstjourdt.TransDt_Id";
	updateIData($iconn, $query, false);
	//echo "<br><br>".$query;

	//Delete acclink
	$query = "DELETE FROM acclink, transdt WHERE transdt.Trans_id = '".$txtID."' AND transdt.TransDt_Id = acclink.Journal_Id";
	updateIData($iconn, $query, false);
	//echo "<br><br>".$query;

	//Delete transdt
	$query = "DELETE FROM transdt WHERE Trans_id = '".$txtID."'";
	updateIData($iconn, $query, true);	
	//echo "<br><br>".$query;

	$query = "DELETE FROM trans WHERE Trans_id = ".$txtID."";
	updateIData($iconn, $query, true);
	//echo "<br><br>".$query;

	header("Location: receipt_form.php?message=Record Deleted");
}else if ($act == "clearPage"){
	clearPage($iconn, $_SESSION['userSession'], "Receipt");	
}

if($act == "viewRecord"){
	$query = "SELECT Trans_ID, Trans_SysDate, Trans_Date, Trans_Remark, Trans_Representative, Currency_Code, Costcent_code, Project_Code, CashType_Code, Trans_CashReference, Trans_ManualNo FROM trans WHERE Trans_Reference = ".$txtRef;
	//echo "<br><br>".$query;
	$result = selectData($conn, $query);
	$txtID = $result[0];
	$txtDate = displayDate(insertParadoxDate($result[1]));
	$txtReceiptDate = displayDate(insertParadoxDate($result[2]));
	$txtRemark = $result[3];
	$txtRepresentative = $result[4];
	$lstCurrency = $result[5];
	$lstCostCentre = $result[6];
	$lstProject = $result[7];
	$lstCashType = $result[8];
	$txtCashReference = $result[9];
	$txtManualNo = $result[10];
}

?>

<head>
<title>Receipt</title>
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">

function deleteRow(a){
	x = document.frm1;
	if (confirm('Delete this Row')){
		x.act.value = 'deleteRow';
		x.txtDeleteRowCode.value = a;
		x.submit();
	}
}

function searchPage(){
	x = document.frm1;
	x.act.value = 'searchPage';	
	x.submit();
}

function openWindow(a){ 
	x = document.frm1;
	if (x.lstProject.value == ''){
		alert('Please Select the Project');
		x.lstProject.focus();
	}else{
		var trans_type = "D";
		if (a == 2){
			trans_type = "C";
		}
		win = window.open('ReceiptChild.php?txtID='+x.txtID.value+'&txtRef='+x.txtRef.value+'&txtDate='+x.txtDate.value+'&txtRemark='+x.txtRemark.value+'&txtRepresentative='+x.txtRepresentative.value+'&lstCashType='+x.lstCashType.value+'&lstCurrency='+x.lstCurrency.value+'&lstCostCentre='+x.lstCostCentre.value+'&txtTransType='+trans_type+'&lstProject='+x.lstProject.value+'&user_level_receipt='+x.user_level_receipt.value+'&txtManualNo='+x.txtManualNo.value+'&txtTotDebit='+x.txtTotDebit.value+'&txtTotCredit='+x.txtTotCredit.value, 'ReceiptChild', 'toolbar=no,menubar=no,scrollbars=yes,resize=yes,maximize=no,location=no,height=625,width=800'); 
		win.creator = self;
		win.focus();
	}
}

function submitRecord(){
	x = document.frm1;
	if (x.lstCurrency.value == '' || x.lstProject.value == '' || check_valid_date(x.txtReceiptDate.value) == false){
		alert("Please ensure to select the Currency and Project. Please ensure Date Fields are in the Format DD/MM/YYYY");
		x.lstProject.focus();
	}else{
		x.act.value = 'submitRecord';
		//win = window.open('ReceiptChild.php', 'ReceiptChild', 'toolbar=no,menubar=no,scrollbars=yes,resize=yes,maximize=no,location=no,height=250,width=800'); 
		//win.close();
		x.submit();
	}
}

function saveChanges(){
	x = document.frm1;
	if (x.lstCurrency.value == '' || x.lstProject.value == '' || check_valid_date(x.txtReceiptDate.value) == false){
		alert("Please ensure to select the Currency and Project. Please ensure Date Fields are in the Format DD/MM/YYYY");
		x.lstProject.focus();
	}else{
		x.act.value = 'saveChanges';
		//win = window.open('ReceiptChild.php', 'ReceiptChild', 'toolbar=no,menubar=no,scrollbars=yes,resize=yes,maximize=no,location=no,height=250,width=800'); 
		//win.close();
		x.submit();
	}
}

function deleteRecord(){
	x = document.frm1;
	if (confirm('Delete this Record')){
		x.act.value = 'deleteRecord';
		x.submit();
	}
}

function confirmRecord(){
	x = document.frm1;
	if (confirm('Confirm Preparation Order')){
		x.act.value = 'confirmRecord';
		x.submit();
	}
}

function printPage(a, b){
	//win = window.open('receipt_form.php?prints=yes&act=viewRecord&txtID='+a+'&txtRef='+b, '', 'toolbar=no,menubar=no,scrollbars=yes,resize=yes,maximize=yes,location=no,height=768,width=1024');
	window.open('receipt_form.php?prints=yes&act=viewRecord&txtID='+a+'&txtRef='+b);
}

function clearPage(){
	//win = window.open('ReceiptChild.php', 'ReceiptChild', 'toolbar=no,menubar=no,scrollbars=yes,resize=yes,maximize=no,location=no,height=600,width=600');
	//win.close();
	window.location.href = "receipt_form.php?act=clearPage";
}
</script>

<style type="text/css">
<!--
.style1 {
	color: #000000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style4 {color: #999999; font-size: 12px; }
.style5 {
	color: #333333;
	font-weight: bold;
	font-size: 13px;
}
.style12 {color: #666666; font-weight: bold; font-size: 12; }
.style13 {font-size: 12px}
body {
	margin-top: 0px;
}
.style14 {
	color: #FF0000;
	font-weight: bold;
}

#footer {position: absolute; bottom: 0; left: 0; width: 600px; height: 50px;} 
-->
</style>
<style>.fb1{font-family:'Verdana';font-size:'10';font-weight:'bold';color:'#A0A0A0';} .f1{font-family:'Verdana';font-size:'10';color:'#A0A0A0';} .f2{font-family:'Verdana';font-size:'20';color:'#A0A0A0';}</style>
</head>
<?php
	if ($prints == "yes"){
		//print "<body onLoad='window.print();window.close();'>";
		print "<body onLoad='window.print();'>";
	}else{
		print "<body>";
	}
?>
<form id="frm1" name="frm1" method="post" action="receipt_form.php">
	<input type='hidden' name='act'><input type='hidden' name='txtDeleteRowCode'>
 <table width="100%" border="0" align="center">
  <tr>
      <td bgcolor="#FFFFFF" width='100%' colspan='4'>
		<?php
			include_once("MenuBar.php");
		?>
	 </td>
    </tr>
    <tr>
      <td height="40" bgcolor="#FFFFFF" colspan='4'><span class="style1">RECEIPT</span></td>
    </tr>
	<tr>
		<?php
			print "<td bgcolor='#FFFFFF' colspan='4' align='center'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>";
		?>
    </tr>
    <tr bgcolor="#F7F7F7">
		<?php
			print "<script>function check_valid_date(z){".				
				"if(z.length != 10 || z.substring(6,10)*1 < 1900 || z.substring(6,10)*1 > 2200){".
					"return false;".
				"}else{".
					"if (z.substring(0,2)*1 < 28 && z.substring(3,5)*1 < 13 && z.substring(2,3) == '/'  && z.substring(5,6) == '/'){".
						"return true;".
					"}else{".
						"if ((z.substring(3,5)*1 == 4 || z.substring(3,5)*1 == 6 || z.substring(3,5)*1 == 9 || z.substring(3,5)*1 == 11) && z.substring(0,2)*1 < 31){".
							"return true;".
						"}else if (z.substring(3,5)*1 == 2 && z.substring(6,10)*1 % 4 == 0 && z.substring(0,2)*1 < 30){".
							"return true;".
						"}else if (z.substring(3,5)*1 == 2 && z.substring(6,10)*1 % 4 != 0 && z.substring(0,2)*1 < 29){".
							"return true;".
						"}else if ((z.substring(3,5)*1 == 1 || z.substring(3,5)*1 == 3 || z.substring(3,5)*1 == 5 || z.substring(3,5)*1 == 7 || z.substring(3,5)*1 == 8 || z.substring(3,5)*1 == 10 || z.substring(3,5)*1 == 12) && z.substring(0,2)*1 < 32){".
							"return true;".
						"}else{".
							"return false;".
						"}".
					"}".
				"}".
			"}</script>";
			
			print "<input type='hidden' name='user_level_receipt' value='".$user_level_receipt."'>";
			print "<input type='hidden' name='lstWarehouse' value='".$lstWarehouse."'>";

			displayTextbox("txtRef", "Reference", $txtRef, "yes", "", "15%", "35%");
			print "<input type='hidden' name='txtID' value='".$txtID."'>";
			//displayTextbox("txtDate", "Date", $txtDate, "yes", "10", "15%", "35%");
			print "<input type='hidden' name='txtDate' value='".$txtDate."'>";
			print "<td>&nbsp;</td><td>&nbsp;</td>";
		?>		
    </tr>
    <tr bgcolor="#F7F7F7">
		<?php
			$query = "SELECT currency_code, currency_name FROM currency ORDER BY currency_code";
			if ($lstCurrency != ""){
				displayList("lstCurrency", "Currency", $lstCurrency, "yes", $conn, $query, "", "15%", "35%");
			}else{
				displayList("lstCurrency", "Currency", $lstCurrency, $prints, $conn, $query, "", "15%", "35%");
			}			
			displayTextbox("txtReceiptDate", "Receipt Date", $txtReceiptDate, $prints, "10", "15%", "35%");
		?>		
	</tr>

    <tr bgcolor="#F7F7F7">
		<?php
			displayTextbox("txtCashReference", "Cash Type Ref", $txtCashReference, "yes", "50", "15%", "35%");			
			displayTextbox("txtManualNo", "Manual No", $txtManualNo, $prints, "50", "15%", "35%");
		?>
	</tr>

	<tr bgcolor="#F7F7F7">
		<?php
			$query = "SELECT CashType_Code, CashType_Description FROM CashType WHERE Journal_Type = 'RV' ORDER BY CashType_Code";
			if ($lstCashType != "" && $txtID != ""){
				displayList("lstCashType", "Cash Type", $lstCashType, "yes", $conn, $query, "", "15%", "35%");
			}else{
				displayList("lstCashType", "Cash Type", $lstCashType, $prints, $conn, $query, "", "15%", "35%");
			}			
			displayTextbox("txtRemark", "Remark", $txtRemark, $prints, "50", "15%", "35%");			
		?>
	</tr>
    <tr bgcolor="#F7F7F7">
		<?php
			//$query = "SELECT costcent_code, costcent_name FROM costcent ORDER BY costcent_name";
			//displayList("lstCostCentre", "Cost Centre", $lstCostCentre, $prints, $conn, $query, "", "15%", "35%");
			print "<input type='hidden' name='lstCostCentre'>";
			if ($lstProject == "" && $defaultProject != ""){
				$lstProject = $defaultProject;
			}
			$query = "SELECT project_code, CONCAT(project_name, ' - ', project_code) FROM project WHERE project_code is NOT NULL ".$projectQuery." ORDER BY project_name";
			if ($txtConfirmed == "Yes" || $act == "viewRecord"){				
				displayList("lstProject", "Project", $lstProject, "yes", $conn, $query, "", "15%", "35%");
			}else{
				displayList("lstProject", "Project", $lstProject, $prints, $conn, $query, "", "15%", "35%");
			}
			displayTextbox("txtRepresentative", "Representative", $txtRepresentative, $prints, "50", "15%", "35%");
		?>
	</tr>    
	<tr>
      <td colspan="4" valign="top" bgcolor="#FFFFFF" class="style4"><label></label>        <label></label>
      <label></label>        <label></label></td>
    </tr>
    <tr>
		<td bgcolor="#E0E0E0">&nbsp;</td>
		<td bgcolor="#E0E0E0" colspan='3'>
			<?php
				if ($prints != "yes" && (strpos($user_level_receipt, "-RE-") !== false || strpos($user_level_receipt, "-RA-") !== false)){
					print "<input type='button' id='addBank' onclick='javascript:openWindow(1)' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana; font-size:12px; width:75px;' title='Add Bank/Cash Transaction' value='Bank/Cash'/>&nbsp;<input type='button' id='addBank' onclick='javascript:openWindow(2)' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; width:50px;' title='Add Client Transaction' value='Client'/>";
					//print "<input name='clearPage' type='button' id='clearPage' onclick=javascript:window.location.href='receipt_form.php' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' title='Clear Page' value='Clear Page'/>&nbsp;";
				}
			?>
		</td>
	</tr>
</table>
<?php
$tot_d = 0;
//$tot_discount = 0;
$tot_c = 0;
print "<table width='100%' border='1' cellspacing='-1' cellpadding='-1'>";
//print "<tr><td class='style3' colspan='9'><b>Account List:</b></td> </tr>";
print "<tr><td bgcolor='#E0E0E0' class='style3'>&nbsp;</td> <td bgcolor='#E0E0E0' class='style3'>Ledger No</td> <td bgcolor='#E0E0E0' class='style3'>Ledger</td> <td bgcolor='#E0E0E0' class='style3'>Desc</td> <td bgcolor='#E0E0E0' class='style3'>Debit</td> <td bgcolor='#E0E0E0' class='style3'>Credit</td> <td bgcolor='#E0E0E0' class='style3'>&nbsp;</td> </tr>";
if ($txtRef == ""){	
	$query = "SELECT TransDt_Id, Trans_id, TransDt.Ledger_number, ledger.Ledger_name, Currency_code, TransDt_Description, Transdt_Amount, TransDt_dbcd FROM TransDt, Ledger WHERE TransDt.Ledger_number = ledger.Ledger_number AND User_Account = '".$_SESSION['userSession']."' AND Trans_id = '".$txtID."' ORDER BY TransDt_dbcd";
}else{	
	$query = "SELECT TransDt_Id, Trans_id, TransDt.Ledger_number, ledger.Ledger_name, Currency_code, TransDt_Description, Transdt_Amount, TransDt_dbcd FROM TransDt, Ledger WHERE TransDt.Ledger_number = ledger.Ledger_number AND Trans_id = '".$txtID."' ORDER BY TransDt_dbcd";
}
//echo "<br><br>".$query;
$result = mysql_query($query, $conn);
while ($cur = mysql_fetch_row($result)){	
	print "<tr><td class='style4'>";
	if ($prints != "yes" && (strpos($user_level_receipt, "-RE-") !== false || strpos($user_level_receipt, "-RA-") !== false) && $txtRef == ""){
		print "<a href='#' onClick='javascript:deleteRow(".$cur[0].")'>Delete</a>";
	}else{
		print "&nbsp;";
	}
	if ($cur[5] == ""){
		$cur[5] = "&nbsp;";
	}
	print "</td> <td class='style4'>".$cur[2]."</td> <td class='style4'>".$cur[3]."</td> <td class='style4'>".$cur[5]."</td>";
	if ($cur[7] == "C"){
		print "<td class='style4'>&nbsp;</td> <td class='style4'>".addComma($cur[6])."</td>";
		$tot_c = $tot_c + $cur[6];
	}else{
		print "<td class='style4'>".addComma($cur[6])."</td> <td class='style4'>&nbsp;</td>";
		$tot_d = $tot_d + $cur[6];
	}
	print "<td>";
		if ($prints != "yes"){
			$query = "SELECT Chk_number, Chk_bank, Chk_ValueDate, Chk_Amount FROM chkjourdt WHERE TransDt_Id = '".$cur[0]."'";
			$sub_result = mysql_query($query, $conn);
			if (mysql_num_rows($sub_result) > 0){
				print "<table width='100%' border='1' cellspacing='-1'>";
					print "<tr><td bgcolor='#F0F0F0'><span class='fb1'>Cheque No</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Bank</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Value Date</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Amount</span></td> </tr>";
					while ($sub_cur = mysql_fetch_row($sub_result)){
						print "<tr><td><span class='f1'>".$sub_cur[0]."</span></td> <td><span class='f1'>".$sub_cur[1]."</span></td> <td><span class='f1'>".$sub_cur[2]."</span></td> <td><span class='f1'>".addComma($sub_cur[3])."</span></td> </tr>";
					}
				print "</table>";
				print "<br>";
			}
		
			$query = "SELECT Project.project_name, Costcenter_Code, CstjourDt_Per, CstJourDt_Amount FROM cstjourdt, Project WHERE Project.Project_Code = cstjourdt.Project_code AND TransDt_Id = '".$cur[0]."'";			
			$sub_result = mysql_query($query, $conn);
			if (mysql_num_rows($sub_result) > 0){
				print "<table width='100%' border='1' cellspacing='-1'>";
					print "<tr><td bgcolor='#F0F0F0'><span class='fb1'>Project</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Cost Centre</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Percentage</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Amount</span></td> </tr>";
					while ($sub_cur = mysql_fetch_row($sub_result)){
						print "<tr><td><span class='f1'>".$sub_cur[0]."</span></td> <td><span class='f1'>&nbsp;</span></td> <td><span class='f1'>".$sub_cur[2]."</span></td> <td><span class='f1'>".addComma($sub_cur[3])."</span></td> </tr>";
					}
				print "</table>";
			}
			
			$query = "SELECT Link_ref, Sale_NetTotal, Sale_PaidAmnt, Sale_RemainAmnt FROM acclink WHERE Journal_ID = '".$cur[0]."'";			
			$sub_result = mysql_query($query, $conn);
			if (mysql_num_rows($sub_result) > 0){
				print "<br><table width='100%' border='1' cellspacing='-1'>";
					print "<tr><td bgcolor='#F0F0F0'><span class='fb1'>Invoice Ref</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Invoice Value</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Paid Amt</span></td> <td bgcolor='#F0F0F0'><span class='fb1'>Balance Amt</span></td> </tr>";
					while ($sub_cur = mysql_fetch_row($sub_result)){
						print "<tr><td><span class='f1'>".$sub_cur[0]."</span></td> <td><span class='f1'>".addComma($sub_cur[1])."</span></td> <td><span class='f1'>".addComma($sub_cur[2])."</span></td> <td><span class='f1'>".addComma($sub_cur[3])."</span></td> </tr>";
					}
				print "</table>";
			}
		}else{
			print "&nbsp;";
		}
	print "</td></tr>";
	if ($prints != "yes"){
		print "<tr><td bgcolor='#FAFAFA'><span class='f1'>&nbsp;</span></td> <td bgcolor='#FAFAFA'><span class='f1'>&nbsp;</span></td> <td bgcolor='#FAFAFA'><span class='f1'>&nbsp;</span></td> <td bgcolor='#FAFAFA'><span class='f1'>&nbsp;</span></td> <td bgcolor='#FAFAFA'><span class='f1'>&nbsp;</span></td> <td bgcolor='#FAFAFA'><span class='f1'>&nbsp;</span></td> <td bgcolor='#FAFAFA'><span class='f1'>&nbsp;</span></td> </tr>";
	}
}
print "<tr><td bgcolor='#E0E0E0' class='style3'>&nbsp;</td> <td bgcolor='#E0E0E0' class='style3'>&nbsp;</td> <td bgcolor='#E0E0E0' class='style3'>&nbsp;</td> <td bgcolor='#E0E0E0' class='style3'>Totals</td> <td bgcolor='#E0E0E0' class='style3'>".addComma($tot_d)."</td> <td bgcolor='#E0E0E0' class='style3'>".addComma($tot_c)."</td> <td bgcolor='#E0E0E0' class='style3'>&nbsp;</td> </tr>";
print "<input type='hidden' name='txtTotDebit' value='".$tot_d."'>";
print "<input type='hidden' name='txtTotCredit' value='".$tot_c."'>";
print "</table>";

print "<table width='100%'>";
print "<tr>".
	"<td width='15%' bgcolor='#E0E0E0'>&nbsp;</td>".
	"<td width='85%' bgcolor='#E0E0E0' colspan='3'>";
		if ($txtRef == "" && $tot_d == $tot_c && $tot_d != 0){
			if ($prints != "yes" && strpos($user_level_receipt, "-RA-") !== false){
				//New Record
				print "<input type='button' onclick='javascript:submitRecord()' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' title='Post Record' value='Post Record'/>&nbsp;";
			}
		}else if ($txtRef != "" && $tot_d == $tot_c){
			if ($prints != "yes" && strpos($user_level_receipt, "-RE-") !== false){
				print "<input type='button' onclick='javascript:saveChanges()' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' title='Save Changes' value='Save Changes'/>&nbsp;";
			}
			if ($prints != "yes"){
				print "<input type='button' onclick='javascript:printPage(".$txtID.", ".$txtRef.")' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' title='Print' value='Print'/>&nbsp;";
			}			
			if ($prints != "yes" && strpos($user_level_receipt, "-RD-") !== false){
				print "<input type='button' onclick='javascript:deleteRecord()' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' title='Delete Record' value='Delete Record'/>&nbsp;";
			}
		}		
	print "</td>";
print "</tr>";
print "<tr>".
	"<td width='15%' bgcolor='#FFFFFF'>&nbsp;</td>".
	"<td width='85%' bgcolor='#FFFFFF' colspan='3'>";
		if ($prints != "yes"){
			//print "<input name='searchPending' type='button' id='searchPending' onclick=javascript:window.location.href='receipt_form.php?act=searchPending' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; width=220px' title='Search Pending Preparation Order' value='Search Pending Preparation Order'/>&nbsp;";			
			print "<input type='button' onclick='javascript:clearPage()' style='background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' title='Clear Page' value='Clear Page'/>&nbsp;";
			print "&nbsp;&nbsp;&nbsp;&nbsp;<font face='Verdana' size='2'>Ref No:</font><input name='txtSearchRef' size='5' value='".$txtSearchRef."'><input type='button' onclick='javascript:searchPage()' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' title='Search' value='Search'/>&nbsp;";
		}
	print "</td>";
print "</tr>";
print "</table>";

if ($act == "searchPage"){
	//clearPage($conn, $_SESSION['userSession'], "Receipt");

	print "<table width='100%'>";	
	print "<tr><td bgcolor='#E0E0E0' class='style3'>Ref No</td> <td bgcolor='#E0E0E0' class='style3'>Date</td> <td bgcolor='#E0E0E0' class='style3'>Cash Type</td> <td bgcolor='#E0E0E0' class='style3'>Project</td> <td bgcolor='#E0E0E0' class='style3'>Remark</td> <td bgcolor='#E0E0E0' class='style3'>Representative</td> <td bgcolor='#E0E0E0' class='style3'>Amount</td> </tr>";
	$query = "SELECT Trans_ID, Trans_Reference, Trans_SysDate, Trans_Date, Trans_Remark, Trans_Representative, Trans_AmountDb1, Costcent_code, Project_Code, CashType_Code FROM Trans WHERE LENGTH(Trans.Trans_Reference) > 0 ".$projectQuery." ";
	if ($txtSearchRef != ""){
		$query = $query . " AND Trans.Trans_Reference = '".$txtSearchRef."' ";
	}
	if ($lstCashType != ""){
		$query = $query . " AND Trans.CashType_Code = '".$lstCashType."' ";
	}
	if ($lstProject != ""){
		$query = $query . " AND Trans.Project_code = '".$lstProject."' ";
	}
	if ($txtRemark != ""){
		$query = $query . " AND Trans.Trans_Remark LIKE '%".$txtRemark."%' ";
	}
	if ($txtRepresentative != ""){
		$query = $query . " AND Trans.Trans_Representative = '%".$txtRepresentative."%' ";
	}
	$query = $query . " ORDER BY Trans.Trans_Reference DESC ";

	//echo $query;
	$result = mysql_query($query, $conn);
	while ($cur = mysql_fetch_row($result)){
		print "<tr><td bgcolor='#E0E0E0' class='style4'><a href='receipt_form.php?act=viewRecord&txtRef=".$cur[1]."&txtID=".$cur[0]."'>".$cur[1]."</a></td> <td bgcolor='#E0E0E0' class='style4'>".displayDate(insertParadoxDate($cur[3]))."</td> <td bgcolor='#E0E0E0' class='style4'>".$cur[9]."</td> <td bgcolor='#E0E0E0' class='style4'>".$cur[8]."</td> <td bgcolor='#E0E0E0' class='style4'>".$cur[4]."</td> <td bgcolor='#E0E0E0' class='style4'>".$cur[5]."</td> <td bgcolor='#E0E0E0' class='style4'>".addComma($cur[6])."</td> </tr>";		
	}	
	print "</table>";
}

if ($prints == "yes"){
	print "<div id='footer'>"; 
		footer("R");
	print "</div>"; 
}
?>
</form>
