38471-vm/includes/stock_helper.php
2026-05-07 08:08:50 +00:00

26 lines
1023 B
PHP

<?php
// includes/stock_helper.php
if (!function_exists('current_outlet_id')) {
function current_outlet_id() {
if (session_status() === PHP_SESSION_NONE && !headers_sent()) session_start();
return (int)($_SESSION['outlet_id'] ?? 1);
}
}
if (!function_exists('update_stock')) {
function update_stock($item_id, $qty, $outlet_id = null) {
// With local stock items, item_id is unique and holds the correct stock_quantity.
// We can update it directly.
// We ignore $outlet_id because item_id already implies the outlet (if we enforce separation).
// However, for extra safety or validation, we could check.
// But for now, simple update is best.
$normalizedQty = function_exists('normalize_quantity') ? normalize_quantity($qty) : round((float)$qty, 2);
$db = db();
$stmt = $db->prepare("UPDATE stock_items SET stock_quantity = stock_quantity + ? WHERE id = ?");
$stmt->execute([$normalizedQty, $item_id]);
}
}