garage conso html
Deploy HouseHub / deploy (push) Successful in 1s

This commit is contained in:
2026-06-20 10:09:22 +02:00
parent ad5a845f18
commit 03a97df8f1
+44 -20
View File
@@ -108,24 +108,30 @@ if ($action === 'vehicles') {
gOk($stmt->fetchAll()); gOk($stmt->fetchAll());
} }
if ($method === 'POST') { if ($method === 'POST') {
$photo = handleUpload('photo', $UPLOAD_DIR); $d = $_POST ?: gBody(); $photo = handleUpload('photo', $UPLOAD_DIR);
// Ajout de consumption dans la liste des champs et d'un '?' supplémentaire $d = $_POST ?: gBody();
// 🔥 LE FIX EST ICI : Fonctions boucliers pour MySQL Strict Mode
$nullInt = fn($v) => ($v === '' || $v === null) ? null : (int)$v;
$nullFloat = fn($v) => ($v === '' || $v === null) ? null : (float)$v;
$nullStr = fn($v) => ($v === '' || $v === null) ? null : $v;
$stmt = $pdo->prepare("INSERT INTO pf_vehicles (name,brand,model,year,license_plate,vin,fuel_type,consumption,color,purchase_date,purchase_price,current_km,photo,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $stmt = $pdo->prepare("INSERT INTO pf_vehicles (name,brand,model,year,license_plate,vin,fuel_type,consumption,color,purchase_date,purchase_price,current_km,photo,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([ $stmt->execute([
$d['name']??'', $d['name'] ?? '',
$d['brand']??'', $d['brand'] ?? '',
$d['model']??'', $d['model'] ?? '',
$d['year']??null, $nullInt($d['year'] ?? null),
$d['license_plate']??null, $nullStr($d['license_plate'] ?? null),
$d['vin']??null, $nullStr($d['vin'] ?? null),
$d['fuel_type']??'Essence', $d['fuel_type'] ?? 'Essence',
($d['consumption'] !== '' && $d['consumption'] !== null) ? (float)$d['consumption'] : null, // Cast propre en float $nullFloat($d['consumption'] ?? null),
$d['color']??null, $nullStr($d['color'] ?? null),
$d['purchase_date']??null, $nullStr($d['purchase_date'] ?? null),
$d['purchase_price']??null, $nullFloat($d['purchase_price'] ?? null),
$d['current_km']??0, $nullInt($d['current_km'] ?? null) ?? 0,
$photo, $photo,
$d['notes']??null $nullStr($d['notes'] ?? null)
]); ]);
gOk(['id' => $pdo->lastInsertId()]); gOk(['id' => $pdo->lastInsertId()]);
} }
@@ -276,9 +282,9 @@ if ($action === 'maintenances') {
$photo = handleUpload('invoice_photo', $UPLOAD_DIR); $d = $_POST ?: gBody(); $photo = handleUpload('invoice_photo', $UPLOAD_DIR); $d = $_POST ?: gBody();
if (!($d['vehicle_id'] ?? null)) gErr('vehicle_id manquant'); 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 (?,?,?,?,?,?,?,?,?,?,?,?)"); $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 (?,?,?,?,?,?,?,?,?,?,?,?)");
$nullInt = fn($v) => ($v ?? '') !== '' ? (int)$v : null; $nullInt = fn($v) => ($v === '' || $v === null) ? null : (int)$v;
$nullFloat = fn($v) => ($v ?? '') !== '' ? (float)$v : null; $nullFloat = fn($v) => ($v === '' || $v === null) ? null : (float)$v;
$nullStr = fn($v) => ($v ?? '') !== '' ? $v : null; $nullStr = fn($v) => ($v === '' || $v === null) ? null : $v;
$stmt->execute([ $stmt->execute([
$d['vehicle_id'], $d['vehicle_id'],
$d['type'] ?? '', $d['type'] ?? '',
@@ -340,8 +346,26 @@ if ($action === 'parts') {
} }
if ($method === 'POST') { if ($method === 'POST') {
$photo = handleUpload('photo', $UPLOAD_DIR); $d = $_POST ?: gBody(); $photo = handleUpload('photo', $UPLOAD_DIR); $d = $_POST ?: gBody();
$nullInt = fn($v) => ($v === '' || $v === null) ? null : (int)$v;
$nullFloat = fn($v) => ($v === '' || $v === null) ? null : (float)$v;
$nullStr = fn($v) => ($v === '' || $v === null) ? null : $v;
$stmt = $pdo->prepare("INSERT INTO pf_parts (vehicle_id,maintenance_id,brand,reference,name,category,price,quantity,unit,supplier,purchase_date,photo,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"); $stmt = $pdo->prepare("INSERT INTO pf_parts (vehicle_id,maintenance_id,brand,reference,name,category,price,quantity,unit,supplier,purchase_date,photo,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([$d['vehicle_id']??null, $d['maintenance_id']??null, $d['brand']??null, $d['reference']??null, $d['name']??'', $d['category']??'Autre', $d['price']??0, $d['quantity']??1, $d['unit']??'pièce', $d['supplier']??null, $d['purchase_date']??null, $photo, $d['notes']??null]); $stmt->execute([
$nullInt($d['vehicle_id'] ?? null),
$nullInt($d['maintenance_id'] ?? null),
$nullStr($d['brand'] ?? null),
$nullStr($d['reference'] ?? null),
$d['name'] ?? '',
$d['category'] ?? 'Autre',
$nullFloat($d['price'] ?? null) ?? 0,
$nullInt($d['quantity'] ?? null) ?? 1,
$d['unit'] ?? 'pièce',
$nullStr($d['supplier'] ?? null),
$nullStr($d['purchase_date'] ?? null),
$photo,
$nullStr($d['notes'] ?? null)
]);
gOk(['id' => $pdo->lastInsertId()]); gOk(['id' => $pdo->lastInsertId()]);
} }
if ($method === 'PUT') { if ($method === 'PUT') {
@@ -403,4 +427,4 @@ if ($action === 'upload_part_photo') {
$photo = handleUpload('photo', $UPLOAD_DIR); if (!$photo) gErr('Upload échoué'); $photo = handleUpload('photo', $UPLOAD_DIR); if (!$photo) gErr('Upload échoué');
$pdo->prepare("UPDATE pf_parts SET photo = ? WHERE id = ?")->execute([$photo, $id]); gOk(['photo' => $photo]); $pdo->prepare("UPDATE pf_parts SET photo = ? WHERE id = ?")->execute([$photo, $id]); gOk(['photo' => $photo]);
} }
gErr('Action inconnue', 404); gErr('Action inconnue', 404);