Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,60 @@
<?php
require_once '../includes/auth.php';
require_once '../includes/db.php';
header('Content-Type: application/json; charset=utf-8');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['success' => false, 'message' => 'Invalid request method']);
exit;
}
$data = json_decode(file_get_contents('php://input'), true);
if (!$data) {
echo json_encode(['success' => false, 'message' => 'No data provided']);
exit;
}
try {
// Add vehicle_status column to history if it doesn't exist
try {
$pdo->exec("ALTER TABLE vehicle_inspections ADD COLUMN vehicle_status VARCHAR(50) NULL");
} catch (PDOException $e) {}
$pdo->beginTransaction();
// 1. Save Inspection History
$stmt = $pdo->prepare("
INSERT INTO vehicle_inspections
(vehicle_id, inspector_cid, inspection_date, inspection_time, mileage, fuel_level, other_items, items_json, vehicle_status)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$data['vehicle_id'],
$data['inspector_cid'],
$data['inspection_date'],
$data['inspection_time'],
$data['mileage'],
$data['fuel_level'],
$data['other_items'] ?? '',
json_encode($data['items'], JSON_UNESCAPED_UNICODE),
$data['vehicle_status'] ?? 'available'
]);
// 2. Update Vehicle Status
if (!empty($data['vehicle_status'])) {
$updateStmt = $pdo->prepare("UPDATE vehicles SET status = ? WHERE id = ?");
$updateStmt->execute([$data['vehicle_status'], $data['vehicle_id']]);
}
$pdo->commit();
echo json_encode(['success' => true, 'message' => 'บันทึกข้อมูลและอัปเดตสถานะรถเรียบร้อยแล้ว']);
} catch (PDOException $e) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
}