[ ['code' => '1', 'name' => 'V6', 'price' => 849000, 'status' => 'موجود'], ['code' => '2', 'name' => '8000N', 'price' => 849000, 'status' => 'موجود'], ['code' => '3', 'name' => '8000M', 'price' => 849000, 'status' => 'موجود'], ['code' => '4', 'name' => '330', 'price' => 899000, 'status' => 'موجود'], ['code' => '5', 'name' => '335', 'price' => 899000, 'status' => 'موجود'], ['code' => '6', 'name' => 'B210', 'price' => 899000, 'status' => 'موجود'], ['code' => '7', 'name' => '105 2023', 'price' => 1149000, 'status' => 'موجود'], ['code' => '8', 'name' => '106 2023', 'price' => 1149000, 'status' => 'موجود'], ['code' => '9', 'name' => '5300 2G', 'price' => 1199000, 'status' => 'موجود'], ['code' => '10', 'name' => '106 2024', 'price' => 1249000, 'status' => 'موجود'], ['code' => '11', 'name' => '106', 'price' => 1449000, 'status' => 'توقف تولید'], ['code' => '12', 'name' => '105 2024', 'price' => 1449000, 'status' => 'موجود'], ['code' => '13', 'name' => '150 2024', 'price' => 1449000, 'status' => 'موجود'], ['code' => '14', 'name' => '15 Pro', 'price' => 1449000, 'status' => 'موجود'], ['code' => '15', 'name' => '105 2021', 'price' => 1549000, 'status' => 'توقف تولید'], ['code' => '16', 'name' => '105 2022', 'price' => 1549000, 'status' => 'توقف تولید'], ['code' => '17', 'name' => '110 2023', 'price' => 1549000, 'status' => 'توقف تولید'], ['code' => '18', 'name' => '110 2021', 'price' => 1749000, 'status' => 'توقف تولید'], ['code' => '19', 'name' => '6700', 'price' => 1749000, 'status' => 'موجود'], ['code' => '20', 'name' => '6303', 'price' => 1749000, 'status' => 'موجود'], ['code' => '21', 'name' => '215', 'price' => 1749000, 'status' => 'موجود'], ['code' => '22', 'name' => '3310-2024', 'price' => 1849000, 'status' => 'موجود'], ['code' => '23', 'name' => '235', 'price' => 1949000, 'status' => 'موجود'], ['code' => '24', 'name' => '150 2019', 'price' => 2099000, 'status' => 'توقف تولید'], ['code' => '25', 'name' => '210', 'price' => 2199000, 'status' => 'توقف تولید'], ['code' => '26', 'name' => '3310', 'price' => 2199000, 'status' => 'توقف تولید'], ['code' => '27', 'name' => '5320', 'price' => 2199000, 'status' => 'موجود'], ['code' => '28', 'name' => '150 2023', 'price' => 2399000, 'status' => 'توقف تولید'], ['code' => '29', 'name' => '6310', 'price' => 2399000, 'status' => 'توقف تولید'], ['code' => '30', 'name' => '8210', 'price' => 2399000, 'status' => 'توقف تولید'], ['code' => '31', 'name' => '2760', 'price' => 2399000, 'status' => 'موجود'], ['code' => '32', 'name' => '2760 new', 'price' => 2599000, 'status' => 'موجود'], ['code' => '33', 'name' => '2720 Flip', 'price' => 2599000, 'status' => 'موجود'], ['code' => '34', 'name' => '5720', 'price' => 2699000, 'status' => 'موجود'], ['code' => '35', 'name' => 'V5 Pro', 'price' => 2799000, 'status' => 'توقف تولید'], ['code' => '36', 'name' => 'V6 Pro', 'price' => 2799000, 'status' => 'موجود'], ['code' => '37', 'name' => '5300 4G', 'price' => 3599000, 'status' => 'موجود'], ['code' => '38', 'name' => 'H3', 'price' => 7999000, 'status' => 'موجود'], ], 'customers' => [], 'invoices' => [] ]; // تابع خواندن داده‌ها function getData() { global $dataFile, $initialData; if (!file_exists($dataFile)) { file_put_contents($dataFile, json_encode($initialData, JSON_UNESCAPED_UNICODE)); return $initialData; } return json_decode(file_get_contents($dataFile), true); } // تابع ذخیره داده‌ها function saveData($data) { global $dataFile; file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); } // پردازش درخواست‌های API if (isset($_GET['action'])) { header('Content-Type: application/json'); $action = $_GET['action']; $data = getData(); if ($action === 'get_data') { echo json_encode($data); exit; } if ($action === 'save_invoice' && $_SERVER['REQUEST_METHOD'] === 'POST') { $input = json_decode(file_get_contents('php://input'), true); $invoice = $input; $invoice['id'] = uniqid(); $invoice['createdAt'] = date('c'); // ISO 8601 // افزودن فاکتور array_unshift($data['invoices'], $invoice); // افزودن مشتری اگر جدید باشد $customerExists = false; foreach ($data['customers'] as $c) { if ($c['name'] === $invoice['customerName']) { $customerExists = true; break; } } if (!$customerExists) { $data['customers'][] = [ 'id' => uniqid(), 'name' => $invoice['customerName'], 'phone' => $invoice['customerPhone'], 'address' => $invoice['customerAddress'], 'postalCode' => $invoice['customerPostalCode'] ]; } saveData($data); echo json_encode(['success' => true, 'id' => $invoice['id']]); exit; } if ($action === 'update_invoice' && $_SERVER['REQUEST_METHOD'] === 'POST') { $input = json_decode(file_get_contents('php://input'), true); $id = $input['id']; foreach ($data['invoices'] as &$inv) { if ($inv['id'] === $id) { // بروزرسانی فیلدها foreach ($input as $key => $value) { if ($key !== 'id') $inv[$key] = $value; } break; } } saveData($data); echo json_encode(['success' => true]); exit; } if ($action === 'delete_invoice' && $_SERVER['REQUEST_METHOD'] === 'POST') { $input = json_decode(file_get_contents('php://input'), true); $id = $input['id']; $data['invoices'] = array_filter($data['invoices'], function($inv) use ($id) { return $inv['id'] !== $id; }); // بازنشانی کلیدها $data['invoices'] = array_values($data['invoices']); saveData($data); echo json_encode(['success' => true]); exit; } exit; } ?> سیستم مدیریت هانوفر

سیستم مدیریت هانوفر