This topic is locked
[SOLVED]

 Calculate Total from Child records

4/29/2012 3:05:35 PM
PHPRunner General questions
M
mid3vil author

I am trying to create an invoice total based off the value of child records. I found a previous post by Jane on a way to do this



global $strTableName,$dal;

$rs = CustomQuery("select sum(FieldName) from DetailTableName where DetailKey=".$_SESSION[$strTableName."_masterkey1"]);

$data = db_fetch_numarray($rs);
$dal->MasterTableName->Value["TotalFieldName"] = $data[0];

$dal->MasterTableName->Param["MasterKey"] = $_SESSION[$strTableName."_masterkey1"];

$dal->MasterTableName->Update();
where DetailKey, MasterKey, FieldName and TotalFieldName are your actual field names, DetailTableName and MasterTableName are your actual table names


I modified the code and placed it in the after record added event



global $strTableName,$dal;

$rs = CustomQuery("select sum(amount) from invoice_items where inv_id=".$_SESSION[$strTableName."_masterkey1"]);

$data = db_fetch_numarray($rs);
$dal->MasterTableName->Value["invoice_total"] = $data[0];

$dal->MasterTableName->Param["inv_id"] = $_SESSION[$strTableName."_masterkey1"];

$dal->MasterTableName->Update();


The value of invoice.invoice_total does not get updated.. any suggestions?

M
mid3vil author 4/29/2012



I modified the code and placed it in the after record added event


Missed MasterTableName above, but still not working

M
mid3vil author 5/1/2012

Anyone have an idea on how to total?

Sergey Kornilov admin 5/2/2012

Hard to tell what might be wrong just looking at your code.
If you have a valid support contract post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program. We'll be glad to help.

M
mid3vil author 5/4/2012



Hard to tell what might be wrong just looking at your code.
If you have a valid support contract post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program. We'll be glad to help.


Well thats aggravating.. 25 meg max upload

Sergey Kornilov admin 5/4/2012

Send your files directly to support via ticket system.

M
mid3vil author 5/10/2012



Send your files directly to support via ticket system.


Not 100% sure where the disconnect was, but here is the code that fixed the update issue
$rs = CustomQuery("select sum(amount) as ttt from invoice_items where inv_id=".$keys['inv_id']);

$data = db_fetch_array($rs);

CustomQuery("update invoice set invoice_total = ".$data['ttt']." where inv_id=".$keys['inv_id']);
Issue wouldn't have been resolved without the help of the Xlinesoft staff.