From 74ab38ce6b0dc074f0e93cce158320128f245cc7 Mon Sep 17 00:00:00 2001 From: marszayn Date: Tue, 12 Aug 2025 09:51:22 +0700 Subject: [PATCH] update: admin scan select2, convert tanggal --- .../SpjAdminController/SpjAdminController.cs | 162 +++++++++- .../Transport/SpjAdmin/Scan/Index.cshtml | 306 ++++++++++++++++-- .../Transport/SpjDriver/Submit/Struk.cshtml | 100 +++--- wwwroot/driver/css/watch.css | 57 +++- 4 files changed, 551 insertions(+), 74 deletions(-) diff --git a/Controllers/SpjAdminController/SpjAdminController.cs b/Controllers/SpjAdminController/SpjAdminController.cs index f320788..b2bb538 100644 --- a/Controllers/SpjAdminController/SpjAdminController.cs +++ b/Controllers/SpjAdminController/SpjAdminController.cs @@ -39,17 +39,35 @@ public class SpjAdminController : Controller [HttpPost("scan/process/{id:guid}", Name = "Admin_Scan_Process")] public IActionResult Process(Guid id) { - // Dummy rule: hanya GUID dummy yang dianggap valid - if (id == DummySpjGuid) + // GUID yang sudah pernah di scan + var alreadyScannedGuid = new Guid("550e8400-e29b-41d4-a716-446655440007"); + + if (id == alreadyScannedGuid) + { + return Json(new { + success = false, + message = "SPJ ini sudah pernah di scan pada 20 Agustus 2024." + }); + } + + var validGuids = new[] + { + DummySpjGuid, // GUID asli yang sudah ada + new Guid("550e8400-e29b-41d4-a716-446655440001"), // Ahmad Supriyadi + new Guid("550e8400-e29b-41d4-a716-446655440002"), // Budi Santoso + new Guid("550e8400-e29b-41d4-a716-446655440003"), // Candra Wijaya + new Guid("550e8400-e29b-41d4-a716-446655440004"), // Dedi Kurniawan + new Guid("550e8400-e29b-41d4-a716-446655440006") // Eko Prasetyo gua coba gagalin + }; + + if (validGuids.Contains(id)) { return Json(new { success = true, data = new { id, status = "Valid" } }); } + return Json(new { success = false, message = "SPJ tidak ditemukan." }); } - // Resolve kode SPJ (contoh: "SPJ/08-2025/PKM/000519") menjadi GUID. - // Catatan: Saat ini dummy (development): setiap format SPJ yang valid bakal ke GUID baru. - // Integrasi produksi: ganti dengan query DB untuk mencari SPJ berdasarkan nomor, lalu kembalikan Id GUID yang sebenarnya. [ValidateAntiForgeryToken] [HttpPost("scan/resolve", Name = "Admin_Scan_Resolve")] public IActionResult Resolve([FromForm] string code) @@ -79,13 +97,141 @@ public class SpjAdminController : Controller return Json(new { success = false, message = "Format kode tidak dikenali." }); } - // Dummy mapping: jika persis sesuai nomor di atas, kembalikan GUID tetap; selain itu anggap tidak ditemukan - if (string.Equals(code, DummySpjNumber, StringComparison.OrdinalIgnoreCase)) + // Mapping SPJ code ke GUID (semua dummy data) + var spjMapping = new Dictionary(StringComparer.OrdinalIgnoreCase) { - return Json(new { success = true, id = DummySpjGuid }); + { DummySpjNumber, DummySpjGuid }, + { "SPJ/01-2024/TRN/240815", new Guid("550e8400-e29b-41d4-a716-446655440001") }, + { "SPJ/02-2024/TRN/240816", new Guid("550e8400-e29b-41d4-a716-446655440002") }, + { "SPJ/03-2024/TRN/240817", new Guid("550e8400-e29b-41d4-a716-446655440003") }, + { "SPJ/04-2024/TRN/240818", new Guid("550e8400-e29b-41d4-a716-446655440004") }, + { "SPJ/05-2024/TRN/240819", new Guid("550e8400-e29b-41d4-a716-446655440005") }, + { "SPJ/06-2024/TRN/240820", new Guid("550e8400-e29b-41d4-a716-446655440007") } // Sudah pernah di scan + }; + + if (spjMapping.TryGetValue(code, out var mappedGuid)) + { + return Json(new { success = true, id = mappedGuid }); } return Json(new { success = false, message = "SPJ tidak ditemukan." }); } + [HttpGet("search-spj")] + public IActionResult SearchSpj(string q, int page = 1, int pageSize = 20) + { + try + { + // Dummy data buat testing + var dummySpjList = new[] + { + new { + id = "550e8400-e29b-41d4-a716-446655440001", + spjCode = "SPJ/01-2024/TRN/240815", + driverName = "Ahmad Supriyadi", + platNomor = "B 1234 ABC", + nomorPintu = "001" + }, + new { + id = "550e8400-e29b-41d4-a716-446655440002", + spjCode = "SPJ/02-2024/TRN/240816", + driverName = "Budi Santoso", + platNomor = "B 5678 DEF", + nomorPintu = "002" + }, + new { + id = "550e8400-e29b-41d4-a716-446655440003", + spjCode = "SPJ/03-2024/TRN/240817", + driverName = "Candra Wijaya", + platNomor = "B 9012 GHI", + nomorPintu = "003" + }, + new { + id = "550e8400-e29b-41d4-a716-446655440004", + spjCode = "SPJ/04-2024/TRN/240818", + driverName = "Dedi Kurniawan", + platNomor = "B 3456 JKL", + nomorPintu = "004" + }, + new { + id = "550e8400-e29b-41d4-a716-446655440005", + spjCode = "SPJ/05-2024/TRN/240819", + driverName = "Eko Prasetyo", + platNomor = "B 7890 MNO", + nomorPintu = "005" + }, + new { + id = DummySpjGuid.ToString(), + spjCode = DummySpjNumber, + driverName = "Fahmi Rahman", + platNomor = "B 2468 PQR", + nomorPintu = "006" + }, + new { + id = "550e8400-e29b-41d4-a716-446655440007", + spjCode = "SPJ/06-2024/TRN/240820", + driverName = "Gita Sari", + platNomor = "B 1357 STU", + nomorPintu = "007" + } + }; + + var filteredData = dummySpjList.AsQueryable(); + + if (!string.IsNullOrWhiteSpace(q)) + { + q = q.ToLower(); + filteredData = dummySpjList.Where(s => + s.spjCode.ToLower().Contains(q) || + s.driverName.ToLower().Contains(q) || + s.platNomor.ToLower().Contains(q) || + s.nomorPintu.ToLower().Contains(q) + ).AsQueryable(); + } + + var total = filteredData.Count(); + var items = filteredData + .Skip((page - 1) * pageSize) + .Take(pageSize) + .ToList(); + + return Json(new { + items = items, + hasMore = (page * pageSize) < total + }); + + /* + // PRODUCTION VERSION - Uncomment untuk production - tambahin sendiri yaa + var query = _context.SpjData + .Where(s => s.SpjCode.Contains(q) || + s.DriverName.Contains(q) || + s.PlatNomor.Contains(q) || + s.NomorPintu.Contains(q)) + .OrderBy(s => s.SpjCode); + + var total = await query.CountAsync(); + var items = await query + .Skip((page - 1) * pageSize) + .Take(pageSize) + .Select(s => new { + id = s.Id, + spjCode = s.SpjCode, + driverName = s.DriverName, + platNomor = s.PlatNomor, + nomorPintu = s.NomorPintu + }) + .ToListAsync(); + + return Json(new { + items = items, + hasMore = (page * pageSize) < total + }); + */ + } + catch (Exception ex) + { + return Json(new { error = ex.Message }); + } + } + } diff --git a/Views/Admin/Transport/SpjAdmin/Scan/Index.cshtml b/Views/Admin/Transport/SpjAdmin/Scan/Index.cshtml index c7da8b9..846c16b 100644 --- a/Views/Admin/Transport/SpjAdmin/Scan/Index.cshtml +++ b/Views/Admin/Transport/SpjAdmin/Scan/Index.cshtml @@ -5,6 +5,109 @@ @section Styles { + + + } @@ -107,14 +210,19 @@

Atau input manual:

@Html.AntiForgeryToken() -
- -
@@ -163,6 +271,7 @@ +