$productName = $db->escape($data['productName']); $quantity = (int)$data['quantity']; // Check if the product exists in the database $product = find_product_by_part_number($productName); if ($product) { // Insert the incoming goods record into the database $sql = "INSERT INTO incoming_goods (product_id, quantity, arrival_date) VALUES ('{$product['id']}', '{$quantity}', '{$transactionDate}')"; if ($db->query($sql)) { // Update the product quantity in stock update_product_qty($quantity, $product['id'], true); $session->msg('s', 'Incoming goods data added successfully!'); } else { $session->msg('d', 'Failed to add incoming goods.'); } } else { // Product not found $session->msg('d', 'Product not found.'); }