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

?>
<a href='../ledge.php' target='cl'>Create Ledger</a>
<form action='showjournal.php'>
<table border=1>
<tr><td>
Date from </td><td>dd<input type=text name='df' size=2 value='<?print date('d',time())?>'>
	mm<input type=text name='mf' size=2 value='<?print date('m',time())?>'>
	yy<input type=text name='yf' size=4 value='<?print date('Y',time())?>'>
 </td></tr>
<tr>
<td>To </td><td>dd<input type=text name='dt' size=2 value='<?print date('d',time())?>'>
	mm<input type=text name='mt' size=2 value='<?print date('m',time())?>'>
	yy<input type=text name='yt' size=4 value='<?print date('Y',time())?>'>
 </td>
<tr><td colspan=2 align=center><input type=submit value='SHOW JOURNAL'></td></tr>
</table>
</form>

<input type=button value='SHOW TB' onClick=document.location='trialb.php' style={font-weight:bold}> 

<p>&nbsp;</p>
<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=[];
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>"
z1.innerHTML="<input type=text id='dd"+cur+"' name=dr_narr[] size=30 value="+nar+">"

ag.innerHTML="<select name='dragain[]'><option>OFNO</option><option>MSNO</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;
}

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;
}

//-------*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<drs.length;k++)
 value=value+"<option>"+drs[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>OFNO</option><option>MSNO</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();
 if(document.f1.tdamt.value==document.f1.tcamt.value)
   return true;
 else
   {alert('Dr, Cr Amount mis-match'); return false;}
}
</script>
</head>

<body>
<form name=f1 action='testjour.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 style={background-color:silver}>

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">
<th>No.<th>Dr <th>Amt <th>Narr<th>Against <th>Value
<tr>
<!--
<td><input type=text name=dr[] onClick=setval()></td>
<td><input type=text name=dr_amt[]></td>
-->
</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">
<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 JOURNAL    '>
</form>

</body>
<?
include("../../opendb.php");
$re=mysqli_query($db,"select * from ledger where  grp!='Cash in hand' and grp!='Bank Accounts' and brcode='$brcode' order by led");
$i=0;
while($row=mysqli_fetch_row($re))
{
 print "\n<script>drs[$i]='$row[0]' </script>";
 $i++;
}
?>
</html>
