tablename_init() hook
Posted: 2013-06-27 14:26
EstimateItem is child table of Product and EstimateForm
When update Product.price will use below script to update EstimateItem contains updated Product.
function Product_after_update($data, $memberInfo, &$args){
// update item price
$id=$data['selectedID'];
$product_price=$data['id'];
$price=sqlValue("select Product.price from Product where id='$product_price'");
sql("update EstimateItem set total='$price'*qty where EstimateItem.price='$product_price'", $eo);
return TRUE;
}
I use below script to update EstimateForm contains updated EstimateItem.
function EstimateForm_after_update($data, $memberInfo, &$args){
updateEstimateTotals($data['selectedID']);
return TRUE;
}
function updateEstimateTotals($estimate_codeID){
// update EstimateForm estimate_total, other_total and total
$estimate_codeID=makeSafe($estimate_codeID);
$total1=sqlValue("select sum(total) from EstimateItem where estimate_code='$estimate_codeID'");
$total2=sqlValue("select sum(total) from OtherItem where estimate_code='$estimate_codeID'");
$total=$total1 + $total2;
sql("update EstimateForm set estimate_total='$total1' where id='$estimate_codeID'", $eo);
sql("update EstimateForm set other_total='$total2' where id='$estimate_codeID'", $eo);
sql("update EstimateForm set total='$total' where id='$estimate_codeID'", $eo);
}
Problem is that EstimateForm contains updated EstimateItem does not update when directly open it or by link from EstimateItem.
I use below script but not worked.
function EstimateForm_init(&$options, $memberInfo, &$args){
updateEstimateTotals($data['selectedID']);
return TRUE;
}