This topic is locked

Simple bill pay help

11/2/2009 9:25:02 PM
PHPRunner General questions
F
frocco author

Hello,
I need to create a bill and collect payments until the bill in paid.
So I guess it is a parent/child relation.

  1. Need to know the amount billed when in the payment list
  2. Not allow them to add payment if sum pays off the debt.
    What is the best way to do this?

    Is there an eaiser way?
    Thanks

J
Jane 11/3/2009

Hi,
please see my answers below:

  1. add total for payments table on the Fields order and totalstab. Also you can calculate total and update bill table in the After record added event on the Events tab.

    Here is a sample:

global $strTablename;

//select total for current bill

$str = "select sum(FieldName) from payments where BillID=".$_SESSION[$strTableName."_masterkey1"];

$rs = CustomQuery($str);

$data = db_fetch_numarray($rs);
//update bills table with total value

$strUpdate = "Update bills set TotalFieldName=".$data[0]." where BillID=".$_SESSION[$strTableName."_masterkey1"];

CustomQuery($strUpdate);


2. check total value in theBefore record added event and show error message if needed:

global $strTablename;

$str = "select sum(FieldName) from payments where BillID=".$_SESSION[$strTableName."_masterkey1"];

$rs = CustomQuery($str);

$data = db_fetch_numarray($rs);
$str2= "select TotalFieldName from bills where BillID=".$_SESSION[$strTableName."_masterkey1"];

$rs2 = CustomQuery($str2);

$data2 = db_fetch_numarray($rs2);

if ($data[0]>$data2[0])

{

$message = "error!";

return false;

}

return true;