const SPREADSHEET_ID = ‘AKfycbzeiYMqMr08s3yJTOpUgfP2fOSDGFzyqknnAPW6i0zKW9Wk_5Vb0B4ppyzaVzKW4EtL2w’; /** * ฟังก์ชันหลักที่ทำหน้าที่เปิดหน้าเว็บ HTML หรือส่งคืน JSON API */ function doGet(e) { // ตรวจสอบว่ามีการส่ง parameter ?action=getData มาหรือไม่ if (e.parameter.action === ‘getData’) { const data = getData(); // ส่งค่ากลับเป็น JSON return ContentService.createTextOutput(JSON.stringify(data)) .setMimeType(ContentService.MimeType.JSON); } // ถ้าไม่มี action หรือเปิดปกติ ให้แสดงหน้า HTML return HtmlService.createTemplateFromFile(‘index’) .evaluate() .setTitle(‘สถานะการจัดซื้อ-จัดจ้าง ครุภัณฑ์ สอช. 2569’) .setSandboxMode(HtmlService.SandboxMode.IFRAME); } /** * ดึงข้อมูลสถานะการจัดซื้อ-จัดจ้างจาก Google Sheet * และแปลงให้อยู่ในรูปแบบ Object Array */ function getData() { try { const sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheets()[0]; const values = sheet.getDataRange().getValues(); if (values.length <= 1) { return []; } const headers = values[0]; const dataRows = values.slice(1); const result = []; // การแมป Header (ชื่อคอลัมน์) ไปเป็น Key ที่จะใช้ใน HTML const keys = headers.map((header, index) => { const cleanHeader = header.trim().replace(/[\/\s\.]/g, ”); // จัดการ Header ที่ซ้ำซ้อนโดยใช้ Index (0-based) if (header.includes(‘เบอร์โทรศัพท์’)) { if (index === 10) return ‘ResponsiblePhone’; // คอลัมน์ที่ 11 if (index === 16) return ‘SupplyOfficerPhone’; // คอลัมน์ที่ 17 } if (header.includes(‘วันที่ทำสัญญาซื้อขายผูก PO’)) { if (index === 20) return ‘ContractPODate’; // คอลัมน์ที่ 21 (ครั้งที่ 1) if (index === 27) return ‘ContractPODate2’; // คอลัมน์ที่ 28 (ครั้งที่ 2) } if (header.includes(‘บริษัทผู้ขายส่งของและใบแจ้งหนี้’)) { if (index === 21) return ‘VendorDeliveryInvoice’; // คอลัมน์ที่ 22 (ครั้งที่ 1) if (index === 29) return ‘VendorDeliveryInvoice2’; // คอลัมน์ที่ 30 (ครั้งที่ 2) } // จัดการ Header อื่นๆ (คอลัมน์ 1-3 และ 6 เป็นต้นไป ที่ไม่มีชื่อซ้ำ) if (header.includes(‘ลำดับ’)) return ‘Order’; if (header.includes(‘ชื่อครุภัณฑ์’)) return ‘EquipmentName’; if (header.includes(‘จำนวน’)) return ‘Quantity’; if (header.includes(‘ราคาต่อหน่วย’)) return ‘PricePerUnit’; if (header.includes(‘ราคารวม’)) return ‘TotalPrice’; if (header.includes(‘รหัสงบประมาณ/โครงการ’)) return ‘BudgetProjectCode’; if (header.includes(‘ผู้รับผิดชอบครุภัณฑ์’)) return ‘ResponsiblePerson’; if (header.includes(‘ราคาที่ตกลงซื้อหรือจ้าง’)) return ‘AgreedPrice’; if (header.includes(‘วันที่ PCM’)) return ‘PCMDate’; if (header.includes(‘เลข PCM’)) return ‘PCMNumber’; if (header.includes(‘จำนวนวันส่งมอบ’)) return ‘DeliveryDays’; if (header.includes(‘วันที่ส่ง PCM ให้ ศบพ.สลก.’)) return ‘DatePCMSent’; if (header.includes(‘เจ้าหน้าที่พัสดุ ศบพ. ที่รับผิดชอบ’)) return ‘SupplyOfficer’; if (header.includes(‘เลขที่โครงการในระบบ e-GP’)) return ‘eGPProjectNumber’; if (header.includes(‘ผอ. แต่งตั้งคณะกรรมการจัดซื้อ/ตรวจรับ’)) return ‘DirectorAppointsCommittee’; if (header.includes(‘ผอ. เซ็นใบสั่งซื้อ/สั่งจ้าง’)) return ‘DirectorSignsPO’; if (header.includes(‘พัสดุประกาศร่าง TOR ในระบบ e-GP 3 วันทำการ’)) return ‘DraftTOR3Days’; if (header.includes(‘พัสดุประกาศ TOR ในระบบ e-GP 5 วันทำการ’)) return ‘FinalTOR5Days’; if (header.includes(‘ยื่นซอง’)) return ‘SubmissionDate’; if (header.includes(‘เปิดซองภายใน 5 วันจากวันที่ยื่นซอง’)) return ‘EvaluationDate’; if (header.includes(‘ประกาศผู้ชนะ’)) return ‘WinnerAnnouncement’; if (header.includes(‘บริษัทผู้ขายส่งจดหมายขอส่งมอบครุภัณฑ์’)) return ‘VendorDeliveryRequest’; if (header.includes(‘ราคาต่ำกว่าหรือเท่ากับ 500,000’)) return ‘PriceUnder500K’; if (header.includes(‘บริษัทที่คาดว่าจะมายื่นเสนอราคา’)) return ‘ExpectedBidders’; if (header.includes(‘บริษัทที่ 1’) && index === 30) return ‘Vendor1’; if (header.includes(‘ชื่อเซลล์และเบอร์ติดต่อ’) && index === 31) return ‘Vendor1Contact1’; if (header.includes(‘บริษัทที่ 2’) && index === 32) return ‘Vendor2’; if (header.includes(‘ชื่อเซลล์และเบอร์ติดต่อ’) && index === 33) return ‘Vendor2Contact1’; if (header.includes(‘บริษัทที่ 3’) && index === 34) return ‘Vendor3’; if (header.includes(‘ชื่อเซลล์และเบอร์ติดต่อ’) && index === 35) return ‘Vendor3Contact1’; // ถ้าไม่เข้าเงื่อนไขใดเลย ให้ใช้ชื่อ Header แบบ Clean return cleanHeader; }); dataRows.forEach((row) => { const item = {}; row.forEach((cell, colIndex) => { // แมปข้อมูลในแถวกับ Key ที่สร้างไว้ item[keys[colIndex]] = cell; }); // กรองแถวว่างเปล่าออก (ถ้า ‘EquipmentName’ เป็นค่าว่าง) if (item.EquipmentName && String(item.EquipmentName).trim() !== ”) { result.push(item); } }); return result; } catch (e) { // ใช้ Logger.log() สำหรับ Debug ใน Apps Script Editor Logger.log(‘Error fetching data: ‘ + e.toString()); return { error: ‘Error fetching data: ‘ + e.toString() }; } }


– ไม่มี


– ไม่มี


Review Your Cart
0
Add Coupon Code
Subtotal

 
Scroll to Top