<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}
include("config.inc.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");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}


$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2,maxperpage from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;

if($voyyear == '') 		$voyyear = date('y');
if ($searchOn == '') 	$searchOn = 0;
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">


<title>Manifest Deposit</title>
<script>
function openclient(){
	win = window.open('list_client.php?str=2', 'clientlist', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=900,height=500,top=100');		
	win.focus();
}

function SubmitRecord(){
	var x = document.manifestdeposit;	
	
	if (x.depositid.value == '')
		var mode = 'insert';
	else var mode = 'update';
	
	if (x.voyyear.value == ''){
		alert('Year is Empty!');
		x.voyyear.focus();
		return 0;
	} else if (x.clientcode.value == ''){
		alert('Client is Empty!');
		openclient();
		return 0;
	} else if (x.currencycode.value == ''){
		alert('Currency is Empty!');
		x.currencycode.focus();
		return 0;
	} else if (x.depamount.value == ''){
		alert('Amount is Empty!');
		x.depamount.focus();
		return 0;
	}
	
	else {
		x.action = "Form_ManifestDeposit_Action.php?mode="+mode;
		x.submit();
	}
}

function ClearPage(){
	var x = document.manifestdeposit;
	
	x.depositid.value 	= '';
	x.message.value 	= '';
	x.voyyear.value 	= '';
	x.clientcode.value 	= '';
	x.clientname.value 	= '';
	x.deptype.value 	= '';
	
	x.cnttype.value 	 = '';
	x.depamount.value 	 = '';
	x.currencycode.value = '';
	x.searchOn.value 	 = 0;
	
	x.action = "Form_ManifestDeposit.php";
	x.submit();
	
}

function deleteRec(manifestdeposit){
	var x = document.manifestdeposit;
	if(confirm('Delete This Record?')){ 
		x.action = "Form_ManifestDeposit_Action.php?mode=delete&manifestdeposit="+manifestdeposit;
		x.submit();
	}
}

function editRec(depid){
	document.manifestdeposit.manifestdeposit.value = depid;
	document.manifestdeposit.submit();
}

function RefreshPage(){
	document.manifestdeposit.action='Form_ManifestDeposit.php?startrange=0';
	document.manifestdeposit.submit();
}


function SetFirstPage(startrange,perpage){
	document.manifestdeposit.action='Form_ManifestDeposit.php?startrange=0&perpage='+perpage;
	document.manifestdeposit.submit();
}

function SetLastPage(perpage,totalrows){
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	document.manifestdeposit.action='Form_ManifestDeposit.php?startrange='+startrange+'&perpage='+perpage;
	document.manifestdeposit.submit();
}


function SetNextPage(startrange,perpage,option){ 

	document.manifestdeposit.action='Form_ManifestDeposit.php?keyword=&startrange='+startrange+'&perpage='+perpage+'&option='+option;
	document.manifestdeposit.submit();
}

function SetPrvPage(startrange,perpage,option){

	document.manifestdeposit.action='Form_ManifestDeposit.php?keyword=&startrange='+startrange+'&perpage='+perpage+'&option='+option;
	document.manifestdeposit.submit();
}

function searchPage(){
	document.manifestdeposit.searchOn.value = 1;
	document.manifestdeposit.submit();
}
</script>
<style>
	.det1 {
		color: #5151FF;
		font-size: 12px;
	}
</style>
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
</head>
<body >
<form name='manifestdeposit' id='manifestdeposit' method='post' >
<input type='hidden' name='depositid' value='$depositid'>
<input type='hidden' name='searchOn' value='$searchOn'>
<input type='hidden' name='message' value='$message'>
HERE;

if ($amntfeet_id != ''){
	$queryEdit = "select voy_year, client_code, Ledger_name, dep_type, cntr_type, dep_amount, Manifest_Deposit.currency_code
				 from Manifest_Deposit inner join clients on Ledger_number = client_code 
				 where deposit_id = $amntfeet_id";
	$resultEdit = mysql_query($queryEdit, $connection);
	$rwEdit = mysql_fetch_row($resultEdit);
	
	$voyyear 		= $rwEdit[0];
	$clientcode 	= $rwEdit[1];
	$clientname 	= $rwEdit[2];
	$deptype 		= $rwEdit[3];
	$cnttype 		= $rwEdit[4];
	$depamount 		= $rwEdit[5];
	$currencycode 	= $rwEdit[6];
	
}

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:26px;'>
		<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:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title' style='text-transform: uppercase'>Manifest Deposit</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";
	  

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
		<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='38'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px'>
					<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>ClearPage</span></span></button>";
					
					echo "<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(); return false;' title='Save Changes' ><span><span>Save</span></span></button>&nbsp;";
					echo "<button type='button' id='btnSearch' name='btnSearch' onclick=\"searchPage(); return false;\" title='Search' ><span><span>Search</span></span></button>&nbsp;";
				echo"</td>
				<td align='left' width='250px'>
					</td>
				<td align='left'></td>
			</tr>
		</table>
	</td>
</tr>
<tr>
	<td id='content-body'>
		<table border='0'  align='center' valign='top'  class='tablecontent' >
				<col width=100%>
				<tr bgcolor='#F7F7F7' >
					<td valign='top' align='left'>
						<table border='0' style='table-layout:fixed' width='1100px' align='left'  cellpadding='0' cellspacing='0' valign='top'>
						<col width='125px'><col width='150px'><col width='125px'><col width='150px'><col width='125px'><col width='150px'><col width='125px'><col width='150px'>";

$querycur = "select currency_code from currency order by currency_code";
$rescur = mysql_query($querycur, $connection);

//header
echo "<tr bgcolor='#F7F7F7' height='25'>
			<td valign='center' align='left' ><span class='style1'>Year</span></td>
			<td align='left'><input type='text' name='voyyear' id='voyyear' value='".$voyyear."' style='font-size:12px; width:80px; ' maxlength=2 /></td>
			<td></td><td></td>
			<td valign='center' align='left' ><span class='style1'>Deposite Type</span></td>
			<td align='left'><select name='deptype' id='deptype' style='width:130px;'>
				<option value='C' ".($deptype == 'C'?'selected':'').">Cash</option>
				<option value='Y' ".($deptype == 'Y'?'selected':'').">Yearly</option>
			</select></td>
			<td valign='center' align='left' ><span class='style1'>Container Type</span></td>
			<td align='left'><select name='cnttype' id='cnttype' style='width:100px;'>
				<option value='20' ".($cnttype == '20'?'selected':'').">20</option>
				<option value='40' ".($cnttype == '40'?'selected':'').">40</option>
			</select></td>
			
		</tr>";


echo "<tr bgcolor='#F7F7F7' height='25'>
			<td align='left' valign='center'><span class='style1'>Client</span></td>
			<td align='left' colspan='3'><input type='text' name='clientcode' id='clientcode' value='".$clientcode."' style='font-size:12px; width:150px; ' maxlength=20 />
					<input type='text' name='clientname' id='clientname' value='".$clientname."' style='font-size:12px; width:200px; '  />
					<input type='image' src='img/btnopen.jpg' title='Select client ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" onclick='openclient(); return false' style='cursor: pointer;'>
			</td>
			<td align='left' valign='center'><span class='style1'>Amount</span></td>
			<td align='left'><input type='text' name='depamount' id='depamount' value='".$depamount."' style='font-size:12px; width:120px; ' />
			<td align='left' valign='center'><span class='style1'>Currency</span></td>
			<td align='left'><select name='currencycode' id='currencycode' style='font-size:12px; width:80px; '>
					<option value='' ".($currencycode==''?'selected':'')."></option>";
			while ($rwc = mysql_fetch_array($rescur)){
				echo "<option value='$rwc[0]' ".($currencycode==$rwc[0]?'selected':'').">$rwc[0]</option>";
			}		
echo "		</select></td>
	  </tr>";

echo "<tr bgcolor='#F7F7F7' height='25'><td colspan='8'></td></tr>";	  
echo "</table></td></tr>";

// Query Search
$queryall = "select deposit_id, voy_year, client_code, ledger_name, dep_amount, Manifest_Deposit.currency_code, if(dep_type = 'C', 'Cash', 'Yearly') as deptype, cntr_type
			from Manifest_Deposit inner join clients on ledger_number = client_code ";
$queryall .= " where 1=1 ";			

if ($voyyear != '') 		$queryall .= " and voy_year = '$voyyear' ";			
if ($clientcode != '') 		$queryall .= " and client_code like '%$clientcode%' ";
if ($clientname != '') 		$queryall .= " and ledger_name = '$clientname' ";
if ($deptype != '') 		$queryall .= " and dep_type = '$deptype' ";
if ($cnttype != '') 		$queryall .= " and cntr_type = '$cnttype' ";
if ($currencycode != '') 	$queryall .= " and Manifest_Deposit.currency_code = '$currencycode' ";

$queryall .= " order by voy_year, client_code, dep_type ";
$resultall = mysql_query($queryall, $connection);	 			
$totalrows = mysql_num_rows($resultall);
	
$queryall .= " limit ".$startrange.",".$perpage;	
		
echo "<tr><td><table border='0' style='table-layout:fixed' width='1100px' align='left'  cellpadding='0' cellspacing='0' valign='top'>
	 <col width='40px'><col width='40px'><col width='80px'><col width='150px'><col width='200px'><col width='140px'><col width='120px'><col width='120px'><col width='100px'><col width='110px'>";

echo "<tr height=30px>
		<td colspan='4'></td>
		<td><span class='style4'>Per Page</span><span class='style4'> <select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPage();\">";
	if ($perpage==20)
		$s20 = 'selected';
	else if ($perpage==30)
		$s30 = 'selected';
	else if ($perpage==40)
		$s40 = 'selected';
	else if ($perpage==50)
		$s50 = 'selected';	
echo '<option '.$s20.' value="20">20</option>
	 <option '.$s30.' value="30">30</option>
	 <option '.$s40.' value="40">40</option>
	 <option '.$s50.' value="50">50</option>';		
echo "</select></td><td>";
	if($startrange > 0)
		echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."','".$option."')>";

	$diff= $startrange - $perpage;
		
	if (($diff) >= 0 ){
		$prvstartrange = $startrange - $perpage;
		echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."','".$option."')>";
	}
	else
		echo "&nbsp;";
echo "</td><td>";
	if ($startrange <= $totalrows){
		$startrange1 = $startrange + $perpage;
		if  ($startrange1 < $totalrows){
			echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."','".$option."')>";
			echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."','".$option."')>";	
		}
	} else
		echo "&nbsp;";	
echo "</td><td colspan='3'></td></tr>";
	 
echo "<tr height=30px>
		<td></td>
		<td></td>
		<td align='center'><span class='style1'>Year</span></td>
		<td align='center'><span class='style1'>Client Code</span></td>
		<td align='center'><span class='style1'>Client Name</span></td>
		<td align='center'><span class='style1'>Amount</span></td>
		<td align='center'><span class='style1'>Currency</span></td>
		<td align='center'><span class='style1'>Deposit Type</span></td>
		<td align='center'><span class='style1'>Container Type</span></td>
		<td align='center'></td>
	 </tr>";
echo "<tr><td colspan='10'><hr></td></tr>";
$ct = 0;

echo "<tr><td colspan='10'><div style='overflow-x: hidden;overflow-y: scroll;height: 500px;'><table border='0' style='table-layout:fixed' width='1100px' align='left'  cellpadding='0' cellspacing='0' valign='top'>
	 <col width='40px'><col width='40px'><col width='80px'><col width='150px'><col width='200px'><col width='140px'><col width='120px'><col width='120px'><col width='100px'><col width='110px'>";
$resultall = mysql_query($queryall, $connection);	 
while ($rwall = mysql_fetch_array($resultall)){
	
	if($ct%2) $bgcolor = "bgcolor='#E6E6E6'";
	else 	$bgcolor = "bgcolor='#F7F7F7'";
	
	echo "<tr $bgcolor height='15px'>
		<td align='center'><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover=\"this.style.cursor='pointer'\" onclick=\"deleteRec('$rwall[0]');\" style='cursor: pointer;'></td>
		<td><img border='0' src='img/edit.png' width='17' height='17' title='Delete Detail' onmouseover=\"this.style.cursor='pointer'\" onclick=\"editRec('$rwall[0]');\" style='cursor: pointer;'></td>
		<td align='center'><span class='det1'>$rwall[1]</span></td>
		<td align='center'><span class='det1'>$rwall[2]</span></td>
		<td align='center'><span class='det1'>$rwall[3]</span></td>
		<td align='center'><span class='det1'>$rwall[4]</span></td>
		<td align='center'><span class='det1'>$rwall[5]</span></td>
		<td align='center'><span class='det1'>$rwall[6]</span></td>
		<td align='center'><span class='det1'>$rwall[7]</span></td>
		<td align='center'></td>
	</tr>";
	$ct++;
}
echo "</table></div></td></tr>";
echo "</table></td></tr>";
echo "	</table></td></tr>
	</td>
	</tr>";							
echo" 	</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
</form>
</body>

HERE;

?>














