Return False if totals not equal

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
shahparzsoft
User
Posts: 361

Return False if totals not equal

Post by shahparzsoft »

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
===== ======

  1. 2000 0
  2. 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.


mobhar
User
Posts: 11715

Post by mobhar »

shahparzsoft wrote:
but it is not working. Please help.

Please explain it in more detail? What did you mean by "it is not working"? How? Did you see any error message?

In addition, you should not use PHP mysql_query() and another mysql_...() functions as they will not be used anymore in the latest PHP version.


shahparzsoft
User
Posts: 361

Post by shahparzsoft »

the totals are not populating.
and
what should i use other then mysql_query ?


mobhar
User
Posts: 11715

Post by mobhar »

You may use ew_Execute() PHPMaker built-in function. Just search in this forum based on that keyword for more info and examples.


arbei
User
Posts: 9379

Post by arbei »

Do you mean you want to have the checking under Grid-Add/Grid-Edit, and need check the total of the Debit is equal to the total of the Credit of the records?

If so, you should perform your checking in Grid_Inserting/ Grid_Updating and return false if the totals are not equal.

Read the example in help file topic: "Server Events and Client Scripts" -> "Grid_Updating" for more information.


shahparzsoft
User
Posts: 361

Post by shahparzsoft »

It was solved by using Grid_Inserting/ Grid_Updating.

Is it possible to show totals of Grid Inserting / Grid Updating before saving ?


mobhar
User
Posts: 11715

Post by mobhar »

You may refer to the generated Javascript validation code in the Add Page. Let's say we're talking about "orders" table in the demo project. In "ordersadd.php" file, just search for this code:

fordersadd.Validate = function() {

As you can see, inside that function, there is "infix" variable which will handle if the validation is being used by "gridinsert".

You may simply use that validation code for your table to calculate the total for the certain field. Just put your Javascript validation code in "Startup Script" that belongs to the List Page of your detail table.


Post Reply