'That product no longer exists.'])); } if (!intval($product['product_track_stock'])) { exit(json_encode(['error' => escapeHtml($product['product_name']) . " doesn't track stock. Turn on Track stock in Edit to count it."])); } $product_id = intval($product['product_id']); $on_hand = floatval($product['product_stock']); $vendor_id = intval($product['product_vendor_id']); $mode = in_array($_GET['mode'] ?? '', ['receive', 'count', 'write_off'], true) ? $_GET['mode'] : 'receive'; $currency = (string) $product['product_currency_code']; $cost = floatval($product['product_cost']) > 0 ? number_format(floatval($product['product_cost']), 2, '.', '') : ''; $level = floatval($product['product_reorder_level']); // Recent expenses to link - the product's vendor's first. Expenses are Financial's, // so only for a role that can see them, and only the clients' it can open $expenses = []; $can_expenses = lookupUserPermission('module_financial') >= 1; if ($can_expenses) { $sql = mysqli_query($mysqli, "SELECT expense_id, expense_description, expense_date, expense_amount, expense_currency_code, expense_vendor_id, vendor_name FROM expenses LEFT JOIN vendors ON vendor_id = expense_vendor_id WHERE expense_archived_at IS NULL AND expense_date >= CURDATE() - INTERVAL 1 YEAR " . clientScopeSql('expense_client_id') . " ORDER BY (expense_vendor_id = $vendor_id AND $vendor_id > 0) DESC, expense_date DESC, expense_id DESC LIMIT 150"); while ($row = mysqli_fetch_assoc($sql)) { $expenses[] = $row; } } $modes = [ 'receive' => ['label' => 'Receive', 'icon' => 'fa-dolly', 'note' => 'It came in'], 'count' => ['label' => 'Count', 'icon' => 'fa-clipboard-check', 'note' => 'What is on the shelf'], 'write_off' => ['label' => 'Write off', 'icon' => 'fa-minus-circle', 'note' => 'Damaged, lost, used'], ]; ob_start(); ?>