24 lines
897 B
PHP
24 lines
897 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.
|
|
|
|
$db = db();
|
|
$stmt = $db->prepare("UPDATE stock_items SET stock_quantity = stock_quantity + ? WHERE id = ?");
|
|
$stmt->execute([$qty, $item_id]);
|
|
}
|
|
}
|