<?
session_start();
include_once("../test.php");
include_once("../opendb.php");
include_once("../includes/function.php");
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

$jvno=$_REQUEST['jvno'];
$rs=mysqli_query($db,"select max(crno) from cshrec where brcode='$brcode'");
$cr_row=mysqli_fetch_row($rs);
 if($cr_row[0]<=0)
   $crno=1;
 else   
   $crno=$cr_row[0]+1;
?>


<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>World Wide Automotive Center</title>


<link type="text/css" href="../includes/style1.css" rel="stylesheet" />
      <link type="text/css" href="../css/form1.css" rel="stylesheet" />

<script type="text/javascript">




  var rawTags;
   var inputField;
   var  initInputFieldValue;
   var dataList;
    var initNbVirgules ;




<?



$select=mysqli_query($db,"select * from ledger where grp != 'Cash in hand' and grp!='Sundry Debtors' and brcode='$brcode' order by led") or die("ERR6:".mysqli_error($db));
$select1=mysqli_query($db,"select distinct led from ledger where grp ='Sundry Debtors' order by led") or die("ERR6:".mysqli_error($db));
   $xxx="[";
 while($row=mysqli_fetch_array($select))
 
   {
        $xxx.='"'.$row[0].'",';

   
    }
 while($row1=mysqli_fetch_array($select1))
 
   {
        $xxx.='"'.$row1[0].'",';

   
    }  

  
   $xxx.="]"; ?>
rawTags=<?echo $xxx;?>;

 //rawTags = ["alf", "alfred", "alphonse", "bart", "batman", "calimero", "dora", "einstein", "jimmy", "joe dalton", "timo", "trollface", "william dalton", "pikachu"];


  function xx(str,event,this1)
  {


  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;


 	if (keyCode == 37){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     document.getElementById('myTable2').rows[row-1].cells[5].getElementsByTagName("input")[0].focus();

	 }

     
 	if (keyCode == 38){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                    // document.getElementById('myTable2').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();

	 }

       
 	if (keyCode == 40){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     //document.getElementById('myTable2').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();

	 }

         if (keyCode == 46){
			  var i=this1.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable2').deleteRow(i);
					delRow2(this1);
                                  document.getElementById('myTable2').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable2').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			  
        }

 inputField = document.getElementById(str);

 initInputFieldValue = inputField.value;
 dataList = document.getElementById('htmlListTags');

		if(keyCode!='40')
              {
                if(keyCode!='38')
              {
         

yy(str,event,this1); 


}
 


     }
 
 }
  function yy(str,event,this1)
    {


     initNbVirgules = (initInputFieldValue.match(/,/g)||[]).length;
fillDatalist("",str,event,this1);
    } 
  
function fillDatalist(prefix,str,event,this1) {



	var nbRawList = rawTags.length;
       
	while(dataList.childNodes.length > 0) {
		dataList.removeChild(dataList.childNodes[0]);
	}
	
	for (i=0; i < nbRawList; i++ ) {
		var nOpt = document.createElement("option");
		nOpt.value = prefix+rawTags[i];
		dataList.appendChild(nOpt);
	}

   var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

  
   var itemval=document.getElementById(str).value;


    if((keyCode=='13') &&(itemval!=''))
              {


         closingbal(itemval,this1);
         handleEnter(this1, event);
         
   	
              }  

        if (keyCode == 40){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                    document.getElementById('myTable2').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();

	 }




}

//mainLoop();


</script>









<style>


#mask {
	display: none;
	background:url(images/bgimg1.gif) repeat;
	//background: #000; 
	position: fixed; left: 0; top: 0; 
	z-index: 10;
	width: 100%; height: 100%;
	opacity: 0.8;
	z-index: 999;
}

.login-popup{
		display:none;
	background:white;
	padding: 10px; 	
	border: 2px solid #ddd;
	float: left;
	font-size: 1.2em;
	position: fixed;
	top: 4%; left: 45%;
	z-index: 99999;
	box-shadow: 0px 0px 20px #999;
	-moz-box-shadow: 0px 0px 20px #999; /* Firefox */
    -webkit-box-shadow: 0px 0px 20px #999; /* Safari, Chrome */
	border-radius:3px 3px 3px 3px;
    -moz-border-radius: 3px; /* Firefox */
    -webkit-border-radius: 3px; /* Safari, Chrome */
}
}

img.btn_close {
	float: right; 
	margin: -28px -28px 0 0;
}

fieldset { 
	border:none; 
}

form.signin .textbox label { 
	display:block; 
	padding-bottom:7px; 
}

form.signin .textbox span { 
	display:block;
}

form.signin p, form.signin span { 
	color:white; 
	font-size:11px; 
	line-height:18px;
} 

form.signin .textbox input { 
	background:#666666; 
	border-bottom:1px solid #333;
	border-left:1px solid #000;
	border-right:1px solid #333;
	border-top:1px solid #000;
	color:white; 
	border-radius: 3px 3px 3px 3px;
	-moz-border-radius: 3px;
    -webkit-border-radius: 3px;
	font:13px Arial, Helvetica, sans-serif;
	padding:6px 6px 4px;
	width:200px;
}

form.signin input:-moz-placeholder { color:white; text-shadow:0 0 2px #000; }
form.signin input::-webkit-input-placeholder { color:hwite; text-shadow:0 0 2px #000;  }

.submit button { 
	background: -moz-linear-gradient(center top, #f3f3f3, #dddddd);
	background: -webkit-gradient(linear, left top, left bottom, from(#f3f3f3), to(#dddddd));
	background:  -o-linear-gradient(top, #f3f3f3, #dddddd);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#f3f3f3', EndColorStr='#dddddd');
	border-color:#000; 
	border-width:1px;
	border-radius:4px 4px 4px 4px;
	-moz-border-radius: 4px;
    -webkit-border-radius: 4px;
	color:#333;
	cursor:pointer;
	display:inline-block;
	padding:6px 6px 4px;
	margin-top:10px;
	font:12px; 
	width:100px;
}

.button:hover { background:#ddd; }

.del{
      border: none;
     background: url("images/delete.png") no-repeat scroll 0 0 transparent;
}
</style>

<script type="text/javascript" src="../js/jquery.js"></script>



<!-- js code below for active enter with textfield-->

 


<script type="text/javascript" src="../tabjs/jquery_004.js"></script>
<link type="text/css" href="../css/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.16.custom.min.js"></script>
<link rel="stylesheet" href="../tabjs/style.css" type="text/css" media="screen">
<script src="../tabjs/8118fe14b349163c4420c20a933e602d581acc6d.js" async="" type="text/javascript"></script>
<script src="../tabjs/i.js" async="" type="text/javascript"></script>
<script src="../tabjs/dc.js" async="" type="text/javascript"></script>
<script type="text/javascript" src="../tabjs/jquery-1.js"></script>
<script type="text/javascript" src="../tabjs/jquery-ui-1.js"></script>
<script type="text/javascript" src="../tabjs/jquery.js"></script>
<script type="text/javascript" src="../tabjs/ajaxupload.js"></script>
<script type="text/javascript" src="../tabjs/constants.js"></script>
<script type="text/javascript" src="../tabjs/javascript.js"></script>
<link type="text/css" href="../tabjs/jquery-ui-1.css" rel="Stylesheet">
<script type="text/javascript" src="../tabjs/jquery_003.js"></script>
<script type="text/javascript" src="../tabjs/jquery-ui.js"></script>
<script type="text/javascript" src="../tabjs/jquery_002.js"></script>
<script type="text/javascript" src="../tabjs/jquery.js"></script>



<script>



var cur2=1;
var cnt2=1;
var cr=[];
var drs=[];
var crs=[];
var cr_amt=[];
var cr_narr=[];
var cragain=[];
var cragval=[];
function insRow2(event,i1,id2)
{
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

var cur_val=i1.value;


switch(keyCode)
{
case 38:
   var row=i1.parentNode.parentNode.rowIndex;
   var col  =i1.parentNode.cellIndex ;
			 
   document.getElementById('myTable2').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
  break;
case 40:
  var row=field.parentNode.parentNode.rowIndex;
  var col  =field.parentNode.cellIndex ;
			 
   document.getElementById('myTable2').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
			
  break;
case 37:
  var row=field.parentNode.parentNode.rowIndex;
  var col  =field.parentNode.cellIndex ;
			 
  document.getElementById('myTable2').rows[row].cells[col-1].getElementsByTagName("input")[0].focus();
	
}



if(id2!="insrowbttn2")
  {
   var i2=i1.parentNode.parentNode.rowIndex;
   var i3=parseFloat(i2)+parseFloat(1);
   var rowCounts = document.getElementById('myTable2').rows.length;
   var rowCounts1= rowCounts-1;
   
  
  }
else
  {
   var i2=0;
   var rowCounts1=0;
  }




		if(((keyCode == 13) && (i2==rowCounts1))||(cnt2==1)) 
 {

var rowCount = document.getElementById('myTable2').rows.length;
var rowcount1=parseFloat(rowCount)+parseFloat(1);
//alert(rowCount);
var x=document.getElementById('myTable2').insertRow(rowCount);


if(rowCount>=1)
 {
  document.getElementById('insrowbttn2').type='hidden';
 }
var k;
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)
var op=x.insertCell(6)
var dd=x.insertCell(7);

a.innerHTML=cur2;

y.innerHTML="<input type=text name='cr[]' id=cr"+cur2+"  size=20    onkeyup='xx(this.id,event,this)'   autocomplete='off' list='htmlListTags'  >";

z.innerHTML="<input type=text name='cr_amt[]' id=cr_amt"+cur2+" class='cr_amt' size=10 value='0' onchange='countcrtot(this,this.value)' onKeydown='return handleEnter(this, event)'>";
 z1.innerHTML="<input type=text name='cr_narr[]' id=cr_narr"+cur2+" class='cr_narr' size=30 onKeydown='return handleEnter(this, event)'>";

crag.innerHTML="<select name='cragain[]' class='cragain' id=cragain"+cur2+" onChange='getda(this,cur2,cr)' onKeydown='return handleEnter(this, event)'><option> </option><option>DA</option><option> ON Acc </option> <option>CHEQ</option></select>";
cragval1.innerHTML="<input type=text class='cragval' id='cragval"+cur2+"' name='cragval[]' onKeydown='return handleEnter(this, event)'  >";
op.innerHTML="<input type=text readonly id='cbal"+cur2+"' onKeyup='insRow2(event,this,this.id)' >";
dd.innerHTML="<input type='button'  onClick='delRow2(this)' class='del' >";
document.getElementById("cr"+cur2).focus();
  cur2++; 

cnt2++;



var table = document.getElementById("myTable2");
var row = table.rows[index];
console.log(secondRow.id);
}



if(keyCode == 13)
{

var tbl = document.getElementById('myTable2');
   var id3=tbl.rows[i3].cells[0].innerHTML;
document.getElementById("cr"+id3).focus();
} 
}






function delRow2(r)
{
//alert (r);

var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable2').deleteRow(i);

  var rowCount = document.getElementById('myTable2').rows.length;
   var tbl = document.getElementById('myTable2');

 if(rowCount<=1)
 {
  document.getElementById('insrowbttn2').type='button';
 }
   
var str1=0;
var n=document.getElementById('myTable2').rows.length-1;
var m;
for(m=1;m<=n;m++)	
    {
     var tbl1 = document.getElementById('myTable2');
     var id2=tbl1.rows[m].cells[0].innerHTML;
    var itemval = document.getElementById("cr_amt"+id2).value;
    
         str1=parseFloat(str1)+parseFloat(itemval); 
        
     }
  document.getElementById("crtot").value= str1.toFixed(2);

cnt2--;
     
 }

</script>


<style>
.cont
	{
	background-color:#3b5998;

	//background:url(images/bg-inner.jpg) #e9e0c3 repeat-x;
  	width: 100%;position: absolute ;
	height:99%;
    	/* Optional - just for DIV)*/
    	//border: solid 1px #000000;
	-moz-box-shadow: 0px 5px 5px #888;
	-webkit-box-shadow: 0px 5px 5px #888;
	box-shadow: 0px 5px 10px #888;
    }
.tble1 input {
background-color:transparent;
border: 0px solid;
height:20px;
//width:160px;
color:black;
}
.tble1
{
border-collapse:collapse;
border:1px solid silver;

}	
.tble1 td
{
//border-collapse:collapse;
border:1px solid silver;

}



</style>



        

<?
$sql=mysqli_query($db,"select * from journal2 where jvno='$jvno' and j_type='BP' and brcode='$brcode'");
$sql1=mysqli_fetch_array($sql);
?>		
<body style="text-align: center;"  >

<center ><h2>Bank Payment Number:<?print $sql1[tr_no];?></h2></center >
 <table class='tbl2' id='tbl2' ><tr><td align='left'>

Debit

</td></tr>
<?
$re=mysqli_query($db,"select * from journal2 where jvno='$jvno' and type='Dr'  and brcode='$brcode'") or die(mysqli_error($db));
$re2=mysqli_query($db,"select * from journal2 where jvno='$jvno' and type='Dr'  and brcode='$brcode'") or die(mysqli_error($db));
$row=mysqli_fetch_array($re);
print "<tr><td align='left'>date:".$row[date];
print "</td></tr>";
?>
<tr><td>
<table width=100% class='tble1' border=1>
<tr bgcolor='#767668' style='color:white'><th>No.<th>Dr <th>Amt <th>Narr<th>Against <th>Chq No</tr>
<?
$j=1;
$dbamttot=0;
while($row=mysqli_fetch_array($re2))
{
 print "<tr><td>".$j."</td><td>".$row[partic]."</td>";
 print "<td>".$row[dramt]."</td>";
 print "<td>".$row[narr]."</td>";
 print "<td>".$row[against]."</td>";  
 print "<td>".$row[no]."</td>";
 
$dramttot+=$row[dramt];
$j++;

}
print "</tr></table>";
print "</td></tr>";

$re3=mysqli_query($db,"select * from journal2 where jvno='$jvno' and type='Cr'  and brcode='$brcode'") or die(mysqli_error($db));
?>
<tr><td align='left'>
Credit
</td></tr>
<tr><td>
<table width=100% class='tble1' border=1>
<tr bgcolor='#767668' style='color:white'><th>No.<th>Cr <th>Amt <th>Narr<th>Against <th>Chq No</tr>

<?
$j=1;
$dbamttot=0;
while($row2=mysqli_fetch_array($re3))
{
 print "<tr><td>".$j."</td><td>".$row2[partic]."</td>";
 print "<td>".$row2[cramt]."</td>";
 print "<td>".$row2[narr]."</td>";
 print "<td>".$row2[against]."</td>";  
 print "<td>".$row2[no]."</td>";
 
$cramttot+=$row2[cramt];
$j++;

}
print "</tr></table>";

?>

</td></tr>
<tr><td colspan='6' align='right'> Total Debit Amount:<? print $dramttot; ?></td></tr>
<tr><td colspan='6' align='right'> Total Credit Amount:<? print $cramttot; ?></td></tr>
<tr><td colspan=2 align='left'><a href="#pop2"  onclick=' showHint()' style="text-decoration:none;"><img src='images/back.png'/></a></td></tr>
</table>
<datalist id="htmlListTags"></datalist>
<br>
<div id='clb'></div>
<Hr>
</table>
  </form>
			
</body></html>
</div>
