92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
using System.Diagnostics;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using eSPJ.Models;
|
|
|
|
namespace eSPJ.Controllers.SpjAdminController;
|
|
|
|
[Route("admin")]
|
|
public class SpjAdminController : Controller
|
|
{
|
|
private static readonly Guid DummySpjGuid = new Guid("9f5b8f3a-1c2d-4a5b-9a7c-1234567890ab");
|
|
private const string DummySpjNumber = "SPJ/08-2025/PKM/000519";
|
|
|
|
[HttpGet("")]
|
|
public IActionResult Index()
|
|
{
|
|
return View("~/Views/Admin/Transport/SpjAdmin/Home/Index.cshtml");
|
|
}
|
|
|
|
[HttpGet("scan")]
|
|
public IActionResult Scan()
|
|
{
|
|
return View("~/Views/Admin/Transport/SpjAdmin/Scan/Index.cshtml");
|
|
}
|
|
|
|
[HttpGet("history")]
|
|
public IActionResult History()
|
|
{
|
|
return View("~/Views/Admin/Transport/SpjAdmin/History/Index.cshtml");
|
|
}
|
|
|
|
[HttpGet("history/details/{id}")]
|
|
public IActionResult Details(int id)
|
|
{
|
|
ViewData["Id"] = id;
|
|
return View("~/Views/Admin/Transport/SpjAdmin/History/Details.cshtml");
|
|
}
|
|
|
|
[ValidateAntiForgeryToken]
|
|
[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)
|
|
{
|
|
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)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(code))
|
|
{
|
|
return Json(new { success = false, message = "Kode kosong." });
|
|
}
|
|
|
|
code = code.Trim();
|
|
|
|
// Jika sudah GUID, langsung kembalikan (tetap izinkan test langsung GUID dummy)
|
|
if (Guid.TryParse(code, out var guid))
|
|
{
|
|
return Json(new { success = true, id = guid });
|
|
}
|
|
|
|
// Pola SPJ
|
|
var isSpj = System.Text.RegularExpressions.Regex.IsMatch(
|
|
code,
|
|
@"^SPJ/\d{2}-\d{4}/[A-Z]+/\d{6}$",
|
|
System.Text.RegularExpressions.RegexOptions.IgnoreCase
|
|
);
|
|
|
|
if (!isSpj)
|
|
{
|
|
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))
|
|
{
|
|
return Json(new { success = true, id = DummySpjGuid });
|
|
}
|
|
|
|
return Json(new { success = false, message = "SPJ tidak ditemukan." });
|
|
}
|
|
|
|
}
|