This topic is locked

DB Functions not working in popup

11/18/2023 4:52:17 AM
PHPRunner General questions
C
chrisp author

Hello,

This is my code in "after record added" from "reception" table. Query, Update and Insert not working in popup page.They work fine if I use the normal page (not popup).

Version 10.91 build 41242

Thank you,

$reception_id = $values['reception_id'];
$date = $values['date'];
// Fetch reception details
$rsReception = DB::Query("SELECT product_id, qty FROM reception_detail WHERE reception_id = $reception_id");

while ($dataReception = $rsReception->fetchAssoc()) {
$product_id = $dataReception["product_id"];
$qty = $dataReception["qty"];

// Fetch purchase order details for the given product
$rsPurchaseOrder = DB::Query("SELECT purchase_order_detail_id, qty AS qty_purchase
FROM purchase_order_detail
WHERE product_id = $product_id");

while ($dataPurchaseOrder = $rsPurchaseOrder->fetchAssoc()) {
$purchase_order_detail_id = $dataPurchaseOrder["purchase_order_detail_id"];
$qty_purchase = $dataPurchaseOrder["qty_purchase"];

if ($qty >= $qty_purchase) {
$dataUpdate["purchase_order_status_id"] = 2; // Received
} elseif ($qty < $qty_purchase and $qty > 0) {
$dataUpdate["purchase_order_status_id"] = 3; // Partially Received
} else {
$dataUpdate["purchase_order_status_id"] = 1; // Pending
}

$keyValuesUpdate["purchase_order_detail_id"] = $purchase_order_detail_id;
DB::Update("purchase_order_detail", $dataUpdate, $keyValuesUpdate);

// Insert into movement
$dataMovement = array(
"date" => "'".$date."'", // Enclosing in quotes for SQL
"product_id" => $product_id,
"qty" => $qty,
"movement_type_id" => 2, // Reception
"sector_id" => 1,
"origin_id" => $reception_id
);

// Insert into movement
DB::Insert("movement", $dataMovement);

}
}

fhumanes 11/29/2023

Without having the code/application, it is impossible for me to help you, but you can use this very simple method to purify code and identify which problem of this code is.

Greetings,
fernando

admin 11/29/2023

Database functions are executed on the server and it is irrelevant if the page is shown in a popup or not. Like Fernando suggests, you need to step through your code to figure out what exactly is not working.