<?php include("../../include/dbconnect.php");?>
<?php 
$tempr = "Inv Date & No Amt : ";
$id = count($invno);
if ($submit == "Submit")
{
$i = 0;
while ($i < $id) 
{ $query1=  mysql_query("select dbamt, invno, date, bcode, cramt from custledger where record ='$invno[$i]'") or die(mysql_error());
  $row1=mysql_fetch_row($query1);
  $dba = $row1[0];
  $inv = $row1[1];
  $dt = $row1[2];
  $bcode = $row1[3];
  $camt = $row1[4];
  $cdt = substr($sdt,6,4).'/'.substr($sdt,3,2).'/'.substr($sdt,0,2);
  $amt = $camt + $crnoteamt;
  if ($amt == $dba)
  {
  if ($crdr=='Credit')
  {
  $query= "update custledger set crnoteno = '$crnoteno', crnotedt = '$cdt', crnoteamt = '$crnoteamt', paystatus='Yes' where record='$invno[$i]'";
  }
  else
  {
  $query= "update custledger set drnoteno = '$drnoteno', drnotedt = '$cdt', drnoteamt = '$drnoteamt', paystatus='Yes' where record='$invno[$i]'";
  }
  }
  else
  {
  if ($crdr=='Credit')
  {
  $query= "update custledger set crnoteno = '$crnoteno', crnotedt = '$cdt', crnoteamt = '$crnoteamt' where record='$invno[$i]'";
  }
  else
  {
  $query= "update custledger set drnoteno = '$drnoteno', drnotedt = '$cdt', drnoteamt = '$drnoteamt', paystatus='Yes' where record='$invno[$i]'";
  }
  }
  mysql_query($query) or die ("Error in query: $query");
  if (empty($bcode))
  {
    $bcode=$bcd;
  }  
  
$insertquery ="insert into crnote (bcode, crnoteno, crnotedt, crnoteamt, drnoteno, drnotedt, drnoteamt, crdr, invno, invdt, invamt, narration, account_year, record) values('$bcode' , '$crnoteno', '$cdt', '$crnoteamt', '$drnoteno', '$cdt', '$crnoteamt', '$crdr', '$inv', '$dt', '$dba', '$narration', '$account_year', NULL)"; 
mysql_query($insertquery) or  die (mysql_error());
$i = $i + 1;
}
}
?>

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

