From ea04831451ef243c60c940842efd16a7335e74fe Mon Sep 17 00:00:00 2001 From: perco Date: Fri, 29 May 2026 15:05:11 +0200 Subject: [PATCH] =?UTF-8?q?fix(garage):=20tous=20les=20champs=20optionnels?= =?UTF-8?q?=20vides=20=E2=86=92=20NULL=20dans=20INSERT=20maintenance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/garage/api.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/garage/api.php b/modules/garage/api.php index c36c936..312a07b 100644 --- a/modules/garage/api.php +++ b/modules/garage/api.php @@ -259,8 +259,23 @@ if ($action === 'maintenances') { $photo = handleUpload('invoice_photo', $UPLOAD_DIR); $d = $_POST ?: gBody(); if (!($d['vehicle_id'] ?? null)) gErr('vehicle_id manquant'); $stmt = $pdo->prepare("INSERT INTO pf_maintenances (vehicle_id,type,description,date,km,cost,mechanic,garage_name,next_km,next_date,invoice_photo,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"); - $cost = ($d['cost'] ?? '') !== '' ? (float)$d['cost'] : null; - $stmt->execute([$d['vehicle_id'], $d['type']??'', $d['description']??null, $d['date']??date('Y-m-d'), $d['km']??null, $cost, $d['mechanic']??null, $d['garage_name']??null, $d['next_km']??null, $d['next_date']??null, $photo, $d['notes']??null]); + $nullInt = fn($v) => ($v ?? '') !== '' ? (int)$v : null; + $nullFloat = fn($v) => ($v ?? '') !== '' ? (float)$v : null; + $nullStr = fn($v) => ($v ?? '') !== '' ? $v : null; + $stmt->execute([ + $d['vehicle_id'], + $d['type'] ?? '', + $nullStr($d['description'] ?? null), + $d['date'] ?? date('Y-m-d'), + $nullInt($d['km'] ?? null), + $nullFloat($d['cost'] ?? null), + $nullStr($d['mechanic'] ?? null), + $nullStr($d['garage_name'] ?? null), + $nullInt($d['next_km'] ?? null), + $nullStr($d['next_date'] ?? null), + $photo, + $nullStr($d['notes'] ?? null), + ]); $mid = $pdo->lastInsertId(); if (!empty($d['km'])) { $pdo->prepare("UPDATE pf_vehicles SET current_km = GREATEST(current_km, ?), updated_at = NOW() WHERE id = ?")->execute([$d['km'], $d['vehicle_id']]); } gOk(['id' => $mid]);