Actualiser api/index.php
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
Security Scan (Trivy) / Trivy — Docker image scan (push) Has been cancelled
Security Scan (Trivy) / Trivy — Filesystem scan (push) Has been cancelled
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
Security Scan (Trivy) / Trivy — Docker image scan (push) Has been cancelled
Security Scan (Trivy) / Trivy — Filesystem scan (push) Has been cancelled
This commit is contained in:
+18
-4
@@ -2703,6 +2703,20 @@ function saveProduct(PDO $db): void {
|
||||
? $input['shopping_name']
|
||||
: computeShoppingName($input['name'], $input['category'] ?? '', $input['brand'] ?? '');
|
||||
|
||||
// Sous-catégorie obligatoire uniquement pour les boissons
|
||||
$category = $input['category'] ?? '';
|
||||
$subcategory = trim($input['subcategory'] ?? '');
|
||||
$validSubcategories = ['vin', 'biere', 'spiritueux', 'soda', 'jus', 'eau', 'autre'];
|
||||
if ($category === 'bevande') {
|
||||
if ($subcategory === '' || !in_array($subcategory, $validSubcategories, true)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'subcategory_required', 'message' => 'Sous-catégorie requise pour les boissons']);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$subcategory = null;
|
||||
}
|
||||
|
||||
$barcode = normalizeProductBarcode($input['barcode'] ?? null);
|
||||
|
||||
$id = !empty($input['id']) ? (int)$input['id'] : 0;
|
||||
@@ -2737,7 +2751,7 @@ function saveProduct(PDO $db): void {
|
||||
|
||||
$nutriJson = isset($input['nutriments']) ? json_encode($input['nutriments']) : null;
|
||||
$params = [
|
||||
$input['name'], $input['brand'] ?? '', $input['category'] ?? '',
|
||||
$input['name'], $input['brand'] ?? '', $category, $subcategory,
|
||||
$input['image_url'] ?? '', $input['unit'] ?? 'pz',
|
||||
$input['default_quantity'] ?? 1, $input['notes'] ?? '',
|
||||
$barcode, $input['package_unit'] ?? '',
|
||||
@@ -2758,8 +2772,8 @@ function saveProduct(PDO $db): void {
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO products (name, brand, category, image_url, unit, default_quantity, notes, barcode, package_unit, shopping_name, nutriments_json)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO products (name, brand, category, subcategory, image_url, unit, default_quantity, notes, barcode, package_unit, shopping_name, nutriments_json)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute($params);
|
||||
echo json_encode(['success' => true, 'id' => (int)$db->lastInsertId(), 'merged' => false]);
|
||||
@@ -3008,7 +3022,7 @@ function listInventory(PDO $db): void {
|
||||
EverLog::debug('listInventory');
|
||||
$location = $_GET['location'] ?? '';
|
||||
$query = "
|
||||
SELECT i.*, p.name, p.brand, p.category, p.image_url, p.unit, p.barcode, p.default_quantity, p.package_unit,
|
||||
SELECT i.*, p.name, p.brand, p.category, p.subcategory, p.image_url, p.unit, p.barcode, p.default_quantity, p.package_unit,
|
||||
COALESCE(i.vacuum_sealed, 0) as vacuum_sealed, i.opened_at, p.shopping_name
|
||||
FROM inventory i
|
||||
JOIN products p ON i.product_id = p.id
|
||||
|
||||
Reference in New Issue
Block a user