<?php  include("../../include/dbconnect.php");?>
<?php 
$tempr = "Inv Date & No Amt : ";
$id = count($invno);
//echo "count : " . "$id";
//echo "cheque date : " . "$cheque_dt";
if ($submit == "Submit")
{
$i = 0;
while ($i < $id) 
{
$query1=  mysql_query("select dbamt, invno, date, bcode from custledger where record ='$invno[$i]'") or die(mysql_error());
//echo "$query1";
  $row1=mysql_fetch_row($query1);
  $tempr1 =  $tempr1 .  $row1[1] . "," . $row1[2] . "," . $row1[0] . ":::" ;
  $bcd = $row1[3];
  $tmpamt = $chequeamt;
  if ($chequeamt >= $row1[0])
  {
     $invamt = $row1[0];
	 $status ='Yes';
	 $chequeamt = $chequeamt - $invamt;
   }	 
   else
   {
     $invamt = $chequeamt;	 
	 $chequeamt = $chequeamt - $invamt;
	 $status ='No';
  }
$chdt = substr($sdt,6,4).'-'.substr($sdt,3,2).'-'.substr($sdt,0,2);

$depdt = substr($dsdt,6,4).'-'.substr($dsdt,3,2).'-'.substr($ddt,0,2);

$tddt = substr($rdt,6,4).'-'.substr($rdt,3,2).'-'.substr($rdt,0,2);
$query= "update custledger set bankcode='$bankno[0]',chequeno='$chequeno',cheque_dt='$chdt',paystatus='$status', cramt='$invamt', deposit_dt='$deptdt', paymode='$paymode' where record='$invno[$i]'";
//echo "$query";
mysql_query($query) or die ("Error in query: $query");
print "<em>Updated!</em><br /><br />";
$i = $i + 1;
}
$tempr3 =  "$tempr" . "$tempr1";
if ($Party_Ledger == "Yes")
{
$insertquery ="insert into custledger (bcode, narration, bankcode, chequeno, cheque_dt, chequeamt, deposit_dt, record) values('$bcd','$tempr3',' $bankno[0]','$chequeno','$chdt','$tmpamt', '$depdt', NULL)"; 
//echo "$insertquery";
mysql_query($insertquery) or  die (mysql_error());
print "<em>Inserted!</em><br /><br />";
}
if ($Bank_Ledger == "Yes")
{
$btranquery= "insert into btrans values ('$accno','$bcd','$tddt','  ','$chequeno','$chdt','$tddt','$depdt','$bankno[0]',$tmpamt,0,'$tempr3',NULL,' ','T','Y','' )";
//echo "$btransquery";
 mysql_query($btranquery) or die(mysql_error());
}
}

?>



<center>
</center>
</body>
<meta http-equiv="refresh" content="0 url=../../index.html">