<?
session_start();
include("../test.php");
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");

if($submit)
{
 $dt=$y.'-'.$m.'-'.$d;
if(strlen($formno)<=0 || strlen($name)<=0)
{
 print "<script>alert('Invalid Customer'); document.location='advform.php';</script>";
 return;
}
 
if(!checkdate($m,$d,$y))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}
if($amt<=0)
{
 print "<script> alert('Invalid Amount'); history.back(1); </script>";
 return;
}
 $sql="insert into advcollection (formno,date,type, amount,brcode,rem) values('$formno','$dt','$type','$amt','$brcode','$rem')";
 mysqli_query($db,$sql) or die(mysqli_error());
}

?>


<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
th{background-color:green;color:white}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'><?
 print "  &nbsp;&nbsp;&nbsp;Customer Name: <font color=red><b>".$name;
?>
<table border=0 width=100%>
<tr> <td width=40%>
<form action='<?print $PHP_SELF?>'>
<input type=hidden name='formno' value='<?print $formno?>'>
<input type=hidden name='name' value='<?print $name?>'>

<table border=1 width=100%>
<tr><td>Date </td><td>dd <input type=text name='d' size='2' value='<?print date("d",time())?>'>
			mm <input type=text name='m' size='2' value='<?print date("m",time())?>'>
			yy <input type=text name='y' size='4' value='<?print date("Y",time())?>'>

</td></tr>
<tr><td>Payment Type </td><td><select name='type'>	
	<option>Cash</option> 
	<option>Cheque</option> 
<?
$rr=mysqli_query($db,"select code,finname,city from fin_master where branch='$brcode' order by finname ");
while($fin_row=mysqli_fetch_array($rr))
{
 print "<option>$fin_row[1]-$fin_row[city]</option>";
}
?>
	<option>Veh-Exchange</option>
	</select>
 </td></tr>
<tr><td>Amount </td><td><input type=text name='amt' style={text-align:right}>	</td></tr>
<tr><td>Cheque Det. </td><td><input type=text name='rem' size=25 onKeyDown=chkey(this)>	</td></tr>
<tr><td colspan=2 align=center><input type=submit name='submit' value='Save'>
<input type=button value='Cancel' onClick=history.back(1)>
</td></tr>
</table>
<td align=center valign=top>
<table border=1>
<tr><td colspan=5 align=center bgcolor='green'><b><font color='ivory'> PAYMENT DETAILS </font></td></tr>
<tr bgcolor=silver><td>Date</td><td>Type </td><td>Amount </td><td>Remarks</td> <td>Del</td></tr>
<?
 $t=0;
$res=mysqli_query($db,"select * from advcollection where formno='$formno'");
while($row=mysqli_fetch_array($res))
{
 $t+=$row[amount];
 print "<tr><td>".datetohtml($row[1])."</td><td>$row[2]</td><td align=right>$row[3]</td><td>$row[rem]</td><td align=center>";
 if($row[clearing]=='n')
 print"<a href='javascript:del($row[code],$row[amount])'><img src='../img/delete2.gif' border=0></a></td>";
 else
  print "<font color=green size=4><b>&copy;</td>";
}
print "<tr><td colspan=2 align=right><font color='darkbrown'>Total</td><td align=right><font color='darkbrown'>".putComa($t)."</td></tr>";
?>
</td>
</tr>
</table>
</form>
</td></tr>
</table>
<script>
 function del(code,amt)
 {
  if (confirm("Delete amount "+amt+" ?"))
   document.location='deladvamt.php?code='+code;
 }

function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
}
</script>

