I want to make a condition on my vouchers, that if total of both debit an credits are not equal,
then voucher should not post.
For example
Line No. Debit Credit
===== ======
- 2000 0
- 0 1000
========================
Sum 2000 1000
========================
In the above case vouchers should not be posted.
i am using following code in Row_inserting event.
function Row_Inserting($rsold, &$rsnew) {
global $conn;
$sql = "select sum(ifnull(DEBIT,0)) vdebit
from tr_detail where tr_detail.tr_id='".$rsnew['tr_id']."' ";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {
$finaldebit = $row['vdebit'];
}
$sql = "select sum(ifnull(CREDIT,0)) vcredit
from tr_detail where tr_detail.tr_id='".$rsnew['tr_id']."' ";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {
$finalcredit = $row['vcredit'];
}
$vbalance=$finaldebit-$finalcredit;
if ($vbalance==0) {
return true;
}
elseif ($vbalance <> 0) {
return false;
}
}
but it is not working. Please help.