<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

$TransType = $_GET['TransType'];
if($TransType == "PV") $Title = "Payment";
if($TransType == "RV") $Title = "Receipt";
if($TransType == "CV") $Title = "Credit Note";
if($TransType == "DV") $Title = "Debit Note";
include("config.inc.php");
include("Functions_Trans.php");
//include("Forms_DataGrid.php");
include("Forms_RMA_DataGrid.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$TransType = $_GET['TransType'];

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
$query_language  = "select user_account, Language from ".$_SESSION['dbLabel'].".login  where user_account = '".$_SESSION['useraccount']."'";
$result_language = mysql_query($query_language, $connection); 
$row_language    = mysql_fetch_array($result_language);
extract($row_language);

$query_journal_labels  = "select Language, label0 as Ref1, TypeRef as TypeRef1, label3 as Folio1, label2 as Date1, label1 as Type1, Project as Project1, Disp_2_1 as Costcenter2, Remark as Remark1, ManualNo as ManualNo1, Disp_1 as LedgerNo1, LedgerName as LedgerName1, Disp_4_1 as DescX, Disp_3 as Curr1, D_C as DC1, Disp_5 as Amount1, Disp_1_3 as ValueDate1, ManualNo as ManualNo1, Desc1 as Desc1,
                          NoRecords, Perpage, Page, Disp_2_2 as Perce, Disp_1_1 as CheckNo, Disp_1_2 as Bankk, Label4 as Debitt, Label5 as Creditt, Disp_4 as Balancee
                          from ".$_SESSION['dbLabel'].".journal_label
                          where Language = '".$Language."'";
$result_journal_labels = mysql_query($query_journal_labels, $connection);
$row_journal_labels    = mysql_fetch_array($result_journal_labels);
extract($row_journal_labels);

$_SESSION['query_journal_labels'] = $query_journal_labels;

$query_navigator = "SELECT LANGUAGE,
       ClearPage,
       Excel,
       Save,
       Print,
       Addd,
       Search,
       Pending,
       CopyJV,
       PaymentRequests,
       ExportExcel,
	   cancell
FROM ".$_SESSION['dbLabel'].".mainform_label
WHERE LANGUAGE = '".$Language."'";
$result_navigator = mysql_query($query_navigator, $connection);
$row_navigator    = mysql_fetch_array($result_navigator);
extract($row_navigator);

//echo $Costcenter1; exit;
$query_project  = "select Journal as Journal1, ResultsPage as ResultsPage1
                   from ".$_SESSION['dbLabel'].".mainform_label
				   where Language = '".$Language."'";
$result_project = mysql_query($query_project, $connection);
$row_project    = mysql_fetch_array($result_project);
extract($row_project);

$querylog="SELECT FA_Journal as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
$querylog=" select ifNull(FA_JournalApp,0) As FA_JournalApp, ifNull(Login_FastPrint,0) As Login_FastPrint, ifNull(FA_LedgerAccess,0) As FA_LedgerAccess ".
		  " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Journal_DefaultCur ".
             " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(module_referencebycostcenter,0) As Module_ReferenceByCostCenter, ".
			 " ifNull(module_checks,0) As Module_checks, ".
			 " ifNull(Module_ShowBalance,0) As Module_ShowBalance, ifNull(Module_ImportExcell,0) As Module_ImportExcell, ifNull(Module_bill,0) As Module_bill ".
			" ,ifNull(module_journalRate,0) As module_journalRate,ifNull(module_ledgerrestrictcur,0) As module_ledgerrestrictcur  ".	
			" From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Read From TransSetup Table							
$querytranssetup= " select DefaultCur, DefaultProject as StpDefaultProject, DefaultCostcenter as StpDefaultCostcenter, ifnull(Hide_ValueDate,0) Hide_ValueDate,  ifnull(Hide_Base2,0) Hide_Base2
					from transsetup where JournalType = 'JV'";
$resulttranssetup=mysql_query($querytranssetup,$connection) or die(mysql_error());
while($rowtranssetup=mysql_fetch_array($resulttranssetup)){
	extract($rowtranssetup);
}

/// Journal Type
$queryjourtype="select type_name from jourtype where ifnull(type_visible,0) = 1 ";
$resultjourtype=mysql_query($queryjourtype,$connection)	or die( mysql_error($connection));



//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}

//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}

$vMainCompanyName=explode('_',$_SESSION['dbName']);  
$DirCompany  = $vMainCompanyName[0];
preg_match_all('!\d+!', $vMainCompanyName[1] ,$DirYears );
$fromdate =  '01/01/'.$DirYears[0][0];
$todate = date('d/m/Y'); 


print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 


<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<link type="text/css" rel="stylesheet" href="js/calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="js/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>

<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>

<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />

<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>

<script type="text/javascript" language="javascript">
$(document).ready(function() { 
		
	
		$(document).on('focus', '.date', function() {
			$('.date').datepick({showTrigger: '#calImg'});
		});
		
		$(document).on('focusin', '.table-focus-g1', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec','ModRec_G1','imgSubmit');
			selRecordColor(this,'SelectedRec','SelectedRecColor');
		});
		$(document).on('focusin', '.table-focus-g2', function() { 
			AutoSaveRecordGrid(this.id,'SelectedRec_G2','ModRec_G2','imgSubmit_D');
			selRecordColor(this,'SelectedRec_G2','SelectedRecColor_G2');
		});
		$(document).on('focusin', '.table-focus-g3', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec_G3','ModRec_G3','imgSubmit_C');
			selRecordColor(this,'SelectedRec_G3','SelectedRecColor_G3');
		});
		$(document).on('focusin', '.table-focus-g4', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec_G4','ModRec_G4','imgSubmit_B');
			selRecordColor(this,'SelectedRec_G4','SelectedRecColor_G4');
		});
});	
function saveTrans(){
	var actionmode = document.getElementById('actionmode').value;
	var trans_id   = document.getElementById('trans_id').value;
	var TransType  = document.getElementById('TransType').value;
	var trans_date = document.getElementById('trans_date').value;
	var txtCurr = document.getElementById('txtCurr').value;
	var txtCostCentCode = document.getElementById('txtCostCentCode').value;
	var txtProjectCode = document.getElementById('txtProjectCode').value;
	var ledger_number = document.getElementById('ledger_number').value;
	var amountCurr = document.getElementById('amountCurr').value;
	var amount_value = document.getElementById('amount_value').value;
	var amountCurr2 = document.getElementById('amountCurr2').value;
	var amount_value2 = document.getElementById('amount_value2').value;
	var ledger_number2 = document.getElementById('ledger_number2').value;
	var amountCurr3 = document.getElementById('amountCurr3').value;
	var amount_value3 = document.getElementById('amount_value3').value;
	var check_date = document.getElementById('check_date').value;
	var check_no = document.getElementById('check_no').value;
	var bank_name = document.getElementById('bank_name').value;
	var bank_branch = document.getElementById('bank_branch').value;
	if(txtCurr == ''){
		alert("Currency is required!");
	}
	else
		if(ledger_number == ""){
			alert("Cash Account is required!");
		}
		else
			if(ledger_number2 == ""){
				alert("Check Account is required!");
			}
		else
			if(amount_value == "" && amount_value2 == ""){
				alert("Cash Amounts are required!");
			}
			else
				if(amount_value3 == ""){
					alert("Bank Amount is required!");
				}
				else
					if(check_date == ""){
							alert("Check Date is required!");
						}
						else
							if(check_no == ""){
								alert("Check Number is required!");
							}
							else
								if(bank_name == ""){
									alert("Bank Name is required!");
								}
								else
								if(bank_branch == ""){
									alert("Bank Branch is required!");
								}
		else{
			var str = "Form_TransDirect_Actions.php?actionmode="+actionmode+"&trans_id="+trans_id+"&TransType="+TransType+"&trans_date="+trans_date+"&txtCurr="+txtCurr+"&txtCostCentCode="+txtCostCentCode+"&txtProjectCode="+txtProjectCode+"&ledger_number="+ledger_number+"&amountCurr="+amountCurr+"&amount_value="+amount_value+"&amountCurr2="+amountCurr2+"&amount_value2="+amount_value2+"&ledger_number2="+ledger_number2+"&amountCurr3="+amountCurr3+"&amount_value3="+amount_value3+"&check_date="+check_date+"&check_no="+check_no+"&bank_name="+bank_name+"&bank_branch="+bank_branch;
			var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function() {
             if (xhttp.readyState == 4 && xhttp.status == 200) { 
	            	var data = xhttp.responseText.split('[BRK]');
					
				}
            };
            xhttp.open("GET", str, true);
            xhttp.send();
		}

}
function ChangeCurrency(){
	document.getElementById('amountCurr').value = document.getElementById('txtCurr').value;
	document.getElementById('amountCurr2').value = document.getElementById('txtCurr').value;
	document.getElementById('amountCurr3').value = document.getElementById('txtCurr').value;
}
</script>

HERE;

echo"<title>$Title</title>";
print <<<HERE
</head>
<body>
<form name='trans' id='trans' method='post' action='' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' id='actionmode' value='insert'>
<input type='hidden' name='trans_id' id='trans_id' value=''>
<input type='hidden' name='TransType' id='TransType' value='$TransType'>
HERE;




echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";

echo" <tr style='height:16px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:16px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>$Title</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";
	  

echo"<tr>
		<td  height='13'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				
				<td>";
	


echo"   </td></tr>";
echo"	</table>";
echo"</td></tr>";

$strt = $_SESSION['StartFinancial_Date'];
$end = $_SESSION['EndFinancial_Date'];
$curr_date = date("d/m/Y");

$query_setup  = "select base1, base2 from setup";
$result_setup = mysql_query($query_setup, $connection); 
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);
$query_access  = "select FI_RMA, FI_RMAApp, FI_RMAMod, FI_RMADel from ".$_SESSION['dbLabel'].".login";
$result_access = mysql_query($query_access, $connection);
$row_access    = mysql_fetch_array($result_access);
extract($row_access);
if($FI_RMAApp != 1){
	$display = "display: none";
}
$curr_date = date("d/m/Y");
echo"<tr><td id='content-body'>
<table width=93% style='margin: auto'>
<tr>
<td colspan=7><button onclick=\"clearPage(); return false;\"><span><span>Clear Page</span></span></button>
<span id='list_buttons'>
<span id='btnsearch'><button onclick=\"searchRMA(); return false;\"><span><span>Search</span></span></button></span>
<span id='btncancel' style='display: none;'><button onclick=\"cancelRMA(); return false;\"><span><span>Cancel</span></span></button></span>
<span id='btnsave' style='$display'><button onclick=\"saveTrans(); return false;\"><span><span>Save</span></span></button></span>
<span id='btnpending'><button onclick=\"openPendingList(); return false;\"><span><span>Pending</span></span></button></span>
</span>
</td>
</tr>
<tr style='height: 20px'>
<td colspan=8></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px; width: 120px'>Reference</td>
<td style='font-weight: bold; font-size: 14px; width: 120px'></td>
<td style='font-weight: bold; font-size: 14px; width: 120px'>JV Reference</td>
<td style='font-weight: bold; font-size: 14px; width: 75px'></td>
<td style='font-weight: bold; font-size: 14px; width: 120px'>Folio</td>
<td style='font-weight: bold; font-size: 14px; width: 75px'></td>
<td style='font-weight: bold; font-size: 14px; width: 90px'>Date</td>
<td style='font-weight: bold; font-size: 14px; width: 150px'><input tpe='text' name='trans_date' id='trans_date' value='$curr_date' style='width: 120px' /> <A HREF=\"#\" onClick=\"displayCalendar(document.trans.trans_date,'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px; width: 120px'>Currency</td>
<td style='font-weight: bold; font-size: 14px; width: 120px'><select name='txtCurr' id='txtCurr' style='width:60px;' onChange='ChangeCurrency();' >";
			echo"<option></option>";
			$querycurrency="select Currency_code from currency order by currency_code";
            $resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());
			while($curf=mysql_fetch_row($resultcurrency)){
			echo"<option ";
				if ($txtCurr==$curf[0])
					echo " selected ";
				echo" value='$curf[0]'>$curf[0] </option>";
			}
			echo"</select></td>";
if($Module_CostCenter == 1 || $Module_CostCenterDt == 1){			
echo"<td style='font-weight: bold; font-size: 14px; width: 120px'>Costcenter</td>
<td style='font-weight: bold; font-size: 14px; width: 120px'><input type='text' name='txtCostCentCode' value='$defaultcostcent' id='txtCostCentCode' style='width: 75px' /> <img src='img/openlist.png' width=20 height=20 style='cursor: pointer; vertical-align: middle' onclick=\"openCostCentList()\" /></td>";
}
else{
	echo "<input type='hidden' name='txtCostCentCode' id='txtCostCentCode' value='$defaultcostcent' style='width: 75px' />";
}
if($Module_Project == 1 || $Module_ProjectDt == 1){
echo"<td style='font-weight: bold; font-size: 14px; width: 120px'>Project</td>
<td style='font-weight: bold; font-size: 14px; width: 120px'><input type='text' name='txtProjectCode' id='txtProjectCode' value='$defaultproject' style='width: 75px' /> <img src='img/openlist.png' width=20 height=20 style='cursor: pointer; vertical-align: middle' onclick=\"openProjectList()\" /></td>";
}
else{
	echo "<input type='hidden' name='txtProjectCode' id='txtProjectCode' style='width: 75px' />";
}
echo"<td style='font-weight: bold; font-size: 14px; width: 120px'></td>
<td style='font-weight: bold; font-size: 14px; width: 120px'></td>
</tr>
<tr style='height: 20px'>
<td colspan=8></td>
</tr>
<tr>
<td colspan=8>
<fieldset>
<legend style='font-size: 14px;'>Cash</legend>
<table width=900>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Ledger No.</td>
<td><input type='text' name='ledger_number' id='ledger_number' style='width: 75px;' />&nbsp;&nbsp;<input type='text' name='ledger_name' id='ledger_name' style='width: 200px;' /> <img src='img/btnopen.jpg' width=20 style='cursor: pointer; vertical-align: middle' onclick=\"openListLedger()\" /></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Amount</td>
<td><select name='amountCurr' id='amountCurr' style='width:75px;' >";
			echo"<option></option>";
			$querycurrency="select Currency_code from currency order by currency_code";
            $resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());
			while($curf=mysql_fetch_row($resultcurrency)){
			echo"<option ";
				if ($txtCurr==$curf[0])
					echo " selected ";
				echo" value='$curf[0]'>$curf[0] </option>";
			}
			echo"</select>&nbsp;&nbsp;<input type='text' name='amount_value' id='amount_value' style='width: 200px;' /></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Amount</td>
<td><select name='amountCurr2' id='amountCurr2' style='width:75px;' >";
			echo"<option></option>";
			$querycurrency="select Currency_code from currency order by currency_code";
            $resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());
			while($curf=mysql_fetch_row($resultcurrency)){
			echo"<option ";
				if ($txtCurr==$curf[0])
					echo " selected ";
				echo" value='$curf[0]'>$curf[0] </option>";
			}
			echo"</select>&nbsp;&nbsp;<input type='text' name='amount_value2' id='amount_value2' style='width: 200px;' /></td>
</tr>
</table>
</fieldset>
<div style='height: 15px'></div>
<fieldset>
<legend style='font-size: 14px;'>Check</legend>
<table width=900>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Ledger No.</td>
<td><input type='text' name='ledger_number2' id='ledger_number2' style='width: 75px;' />&nbsp;&nbsp;<input type='text' name='ledger_name2' id='ledger_name2' style='width: 200px;' /> <img src='img/btnopen.jpg' width=20 style='cursor: pointer; vertical-align: middle' onclick=\"openListLedger2()\" /></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Amount</td>
<td><select name='amountCurr3' id='amountCurr3' style='width:75px;' >";
			echo"<option></option>";
			$querycurrency="select Currency_code from currency order by currency_code";
            $resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());
			while($curf=mysql_fetch_row($resultcurrency)){
			echo"<option ";
				if ($txtCurr==$curf[0])
					echo " selected ";
				echo" value='$curf[0]'>$curf[0] </option>";
			}
			echo"</select>&nbsp;&nbsp;<input type='text' name='amount_value3' id='amount_value3' style='width: 200px;' /></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Check Date</td>
<td><input type='text' name='check_date' id='check_date' style='width: 264px;' value='$curr_date' /> <a HREF='#' onClick=\"displayCalendar(document.getElementById('check_date'),'dd/mm/yyyy',this);  return false;\" NAME='anchor1' ID='anchor1'><img src='./img/cal.gif' width='17' height='17' border=0 align=center></a></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Check No.</td>
<td><input type='text' name='check_no' id='check_no' style='width: 287px;' /></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Bank Name</td>
<td><input type='text' name='bank_name' id='bank_name' style='width: 287px;'  /></td>
</tr>
<tr>
<td style='font-weight: bold; font-size: 14px;'>Bank Branch</td>
<td><input type='text' name='bank_branch' id='bank_branch' style='width: 287px;'  /></td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>

		</td></tr>";

echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
echo" </table>  ";//end of last table menu





print <<<HERE


</body>
</html>

HERE;

?>