<?php
session_start();

require_once '../../includes/auth.php';

$itemId = (int)($_POST['item_id'] ?? 0);
$change = (float)($_POST['change'] ?? 0);

if ($itemId <= 0 || $change == 0) {
    exit('Invalid request');
}

if (!isset($_SESSION['pos_cart'][$itemId])) {
    exit('Item not found');
}

/*
    Update qty
*/
$_SESSION['pos_cart'][$itemId]['qty'] += $change;

/*
    Remove if zero or negative
*/
if ($_SESSION['pos_cart'][$itemId]['qty'] <= 0) {
    unset($_SESSION['pos_cart'][$itemId]);
}

echo 'OK';
?>