<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../../opendb.php");
$rs=mysqli_query($db,"select max(cpno) from cshpay where brcode='$brcode' ");
$cr_row=mysqli_fetch_row($rs);
 if($cr_row[0]<=0)
   $cpno=1;
 else   
   $cpno=$cr_row[0]+1;

?>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<html>
<head>
<script type="text/javascript">
var tq=0,tq2=0;
var cur=1;
var vv;
var drs=[];
var crs=[];
function setval(a)
{
 vv=a.name;
}
function insRow()
{
var x=document.getElementById('myTable').insertRow(cur)
if(cur>1)
 var nar=document.getElementById('dd1').value;
var a=x.insertCell(0)
var y=x.insertCell(1)
var z=x.insertCell(2)	
var z1=x.insertCell(3)	
var ag=x.insertCell(4)
var agval=x.insertCell(5)
a.innerHTML=cur
var value="<select name=dr[] onClick=setval(this)>";

for(k=0;k<drs.length;k++)
 value=value+"<option>"+drs[k]+"</option>";

value=value+"</select>";
y.innerHTML=value


z.innerHTML="<input type=text name=dr_amt[] id=dr"+cur+" size=10 style={text-align:right}>"
z1.innerHTML="<input type=text id='dd"+cur+"' name=dr_narr[] size=30 value="+nar+">"

ag.innerHTML="<select name='dragain[]'><option>OFNO</option><option>DA</option><option> ON Acc </option> <option>CHEQ</option></select>";
agval.innerHTML="<input type=text name='dragval[]'>";
//alert(cur);
cur++; 

}
function delRow(x1)
{
 var num=x1.name;
 if(cur>1)
  {
    var x=document.getElementById('myTable').deleteRow(cur-1)
    cur--;
  }
}

//************************************
function calcdr()
{
var tq=0;
for(i=1;i<cur;i++)
{
 var ele='dr'+i; //alert(ele);
 if(document.getElementById(ele).value>0)
  {
   amount=document.getElementById(ele).value;
   tq+=parseFloat(amount);
  }
 }
document.f1.tdamt.value=tq.toFixed(2);
}

function calccr()
{
var tq2=0;
for(i=1;i<cur2;i++)
{
 var ele2='cr'+i; //alert(ele);
 if(document.getElementById(ele2).value>0)
  {
   amount=document.getElementById(ele2).value;
   tq2+=parseFloat(amount);
  }
 }
//document.f1.tcamt.value=tq2.toFixed(2);
}

//-------*888888888888888888888888*********************8888
var cur2=1;
function insRow2()
{
var x=document.getElementById('myTable2').insertRow(cur2)
if(cur2>1)
 var nar=document.getElementById('d2d1').value;

var a=x.insertCell(0)
var y=x.insertCell(1)
var z=x.insertCell(2)	
var z1=x.insertCell(3)	

var crag=x.insertCell(4)
var cragval1=x.insertCell(5)

a.innerHTML=cur2
var value="<select name=cr[] onClick=setval(this)>";
for(k=0;k<crs.length;k++)
 value=value+"<option>"+crs[k]+"</option>";
value=value+"</select>";
y.innerHTML=value


z.innerHTML="<input type=text name=cr_amt[] id=cr"+cur2+" size=10>"
z1.innerHTML="<input type=text id='d2d"+cur2+"' name=cr_narr[] size=30 value='"+nar+"'>"

crag.innerHTML="<select name='cragain[]'><option>DA</option><option> ON Acc </option> <option>CHEQ</option></select>";
cragval1.innerHTML="<input type=text name='cragval[]'>";

cur2++;
}
function delRow2(x1)
{
 var num=x1.name;
 if(cur2>1)
 {
   var x=document.getElementById('myTable2').deleteRow(cur2-1)
   cur2--;
 }
}

function valid()
{
 calccr();
 calcdr();
 var d1=parseFoloat(document.f1.d.value);
 var m1=parseFoloat(document.f1.m.value);
 var y1=parseFoloat(document.f1.y.value);

 if(d1<=0||m1<=0||y1<=0)
 {
  alert('Invalid Date');
  return false;
 }
 if(document.f1.tdamt.value>0)
   return true;
 else
   {alert('Invalid Debit Amount'); return false;}
}
</script>
</head>
<title>Xpress</title>
    <script src="../../rightclick_deactive.js"></script>
    <script type="text/javascript" src="../../scripts/jquery-latest.js"></script>
	<link type="text/css" href="../../includes/style1.css" rel="stylesheet" />
      <link type="text/css" href="../../css/form.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
<body background="../../back_ground.jpg">

<?php include('top.php'); ?>
<br><br>
<table class="container"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px; color:white;">  &nbsp;&nbsp;Accounts >> Cash Payment</font>
<br><br>
<a href='../ledge.php' target='cl'>Create Ledger</a>
<center><h3>Cash Payment Number:<?print $cpno?></h3></center>
<form name=f1 action='svcshpay.php' method='post' onSubmit="return valid()">

Debit <input type="button" onclick="insRow()" value=" + ">
<input type='button' onclick='delRow(this)' value=' - '>
<input type='button' onclick='calcdr()' value=' CALCULATE DEBIT SUM  '>


<p align=center >
Date: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());?>'>
</p>

<table id="myTable" border="1" class='report'>
<th>No.<th>Dr <th>Amt <th>Narr<th>Against <th>No.
<tr>

</tr>
</table><br>
Total Debit Amount <input type=text readonly name='tdamt'>
<hr>
<!--
Credit <input type="button" onclick="insRow2()" value=" + ">
<input type='button' onclick='delRow2(this)' value=' - '>
<input type='button' onclick='calccr()' value=' CALCULATE CREDIT SUM  '>

<br>&nbsp;

<table id="myTable2" border="1" class='report'>
<th>No.<th>Cr <th>Amt <th>Narr<th>Against <th>Value
</table>

<br>
Total Credit Amount <input type=text readonly name='tcamt'>
-->
<Hr><input type=submit value='    SAVE CASH PAYMENT    '>
</form>
</td></tr></table>
</body>
<?
$re=mysqli_query($db,"select * from ledger where grp!='Cash in hand' and brcode='$brcode' order by led") or die(mysqli_error($db));
$i=0;
while($row=mysqli_fetch_row($re))
{
 print "\n<script>drs[$i]='$row[0]'; </script>";
 $i++;
}

?>
</html>
