This topic is locked

after record added delete records other table

11/19/2019 4:00:57 PM
PHPRunner General questions
L
luchoadmin author

Hi,
I have two tables

1 stock table with a number_part column

2 table export with a number_part column

and wanted to add the data in export to delete it from stock. it's possible?
I did tests with the afetr aded event

with this code

global $conn;
$StockData = $pageObject->getMasterRecord(); // Returns an array of the master record

$StockData["part_stock"]; //Get current stock count
IF($values["mvt_type"] == "I")

{

$NewStock = $StockData["part_stock"] + $values["mvt_qty"]; // Add value to current stock

}

ELSE

{

$NewStock = $StockData["part_stock"] - $values["mvt_qty"]; // Deduct value from current stocck

}
//Update the new stock count to the parent stock part number

$StockUpdate = "UPDATE stock SET part_stock = ".$NewStock." where part_no = ".$values["part_no"]."";

db_exec($StockUpdate,$conn);

M
MikeT 11/19/2019

You could write a trigger in the database that decrements the stock quantity after an insert.

L
luchoadmin author 11/20/2019



You could write a trigger in the database that decrements the stock quantity after an insert.


I'm going to try it, thank you

L
luchoadmin author 11/20/2019

I thought another option would be to move the data from the stock table to export.

M
MikeT 11/20/2019

It's probably a design decision. Since this looks like an important business rule to me I'd personally keep it "as close to the metal" as possible.