From 9a71ab6b876d85c25d36ac64c8edc254155b9e51 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 31 Jan 2025 10:43:36 +0700 Subject: [PATCH] export payment --- Controllers/PeriodExamController.cs | 26 ++++++++++++++++++ Extensions/IntegerExtension.cs | 41 +++++++++++++++++++++++++++++ Services/PeriodExamService.cs | 38 ++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/Controllers/PeriodExamController.cs b/Controllers/PeriodExamController.cs index 0c395c9..3edc976 100644 --- a/Controllers/PeriodExamController.cs +++ b/Controllers/PeriodExamController.cs @@ -365,6 +365,32 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers } } + /// + /// ข้อมูลเอกสารชำระเงิน + /// + /// รหัสรอบสมัคร + /// + /// เมื่อทำการอ่านข้อมูลชำระเงินสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("payment/{examId:length(36)}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> ExportsPaymentExamAsync(string examId) + { + try + { + var items = await _periodExamService.ExportsPaymentExamAsync(examId); + + return Success(items); + } + catch (Exception ex) + { + return Error(ex); + } + } + // /// // /// รายชื่อผู้สมัครสอบรอ จัดการเลขที่นั่งสอบ // /// diff --git a/Extensions/IntegerExtension.cs b/Extensions/IntegerExtension.cs index 5ccc256..8cc4748 100644 --- a/Extensions/IntegerExtension.cs +++ b/Extensions/IntegerExtension.cs @@ -70,5 +70,46 @@ namespace BMA.EHR.Recurit.Exam.Service.Extensions } return result.ToString(); } + + public static string NumberToThaiText(this float number) + { + int baht = (int)number; // แยกส่วนบาท + int satang = (int)Math.Round((number - baht) * 100); // คำนวณสตางค์ (ปัดเป็นจำนวนเต็ม) + + string bahtText = ConvertIntToThai(baht) + "บาท"; + string satangText = satang > 0 ? ConvertIntToThai(satang) + "สตางค์" : "ถ้วน"; + + return bahtText + satangText; + } + + public static string ConvertIntToThai(int number) + { + string[] unit = { "", "สิบ", "ร้อย", "พัน", "หมื่น", "แสน", "ล้าน" }; + string[] digit = { "ศูนย์", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า" }; + + string result = ""; + string numStr = number.ToString(); + int len = numStr.Length; + + for (int i = 0; i < len; i++) + { + int num = numStr[i] - '0'; + int pos = len - i - 1; + + if (num != 0) + { + if (pos == 1 && num == 1) + result += "สิบ"; + else if (pos == 1 && num == 2) + result += "ยี่สิบ"; + else if (pos == 0 && num == 1 && len > 1) + result += "เอ็ด"; + else + result += digit[num] + unit[pos]; + } + } + + return result; + } } } \ No newline at end of file diff --git a/Services/PeriodExamService.cs b/Services/PeriodExamService.cs index e5645b8..96c5208 100644 --- a/Services/PeriodExamService.cs +++ b/Services/PeriodExamService.cs @@ -1620,6 +1620,44 @@ namespace BMA.EHR.Recurit.Exam.Service.Services return periodExam; } + public async Task ExportsPaymentExamAsync(string candidateId) + { + var periodExam = await _context.Candidates.AsQueryable() + .Include(x => x.PeriodExam) + .ThenInclude(x => x.PeriodExamBarCodes) + .ThenInclude(x => x.Document) + .Include(x => x.PeriodExam) + .ThenInclude(x => x.PeriodExamQrCodes) + .ThenInclude(x => x.Document) + .Where(x => x.Id == Guid.Parse(candidateId)) + .FirstOrDefaultAsync(); + + if (periodExam == null) + throw new Exception(GlobalMessages.ExamNotFound); + + + return new + { + template = "candidate", + reportName = $"Candidate_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}", + data = new + { + data = new + { + FeRemarke = periodExam?.PeriodExam?.Remark ?? "-", + CompanyCode = periodExam?.PeriodExam?.CompanyCode ?? "-", + PeriodExamBarCodes = (periodExam?.PeriodExam?.PeriodExamBarCodes[0]?.Document?.Id ?? null) == null ? "" : _minioService.ImagesPath(periodExam?.PeriodExam?.PeriodExamBarCodes[0]?.Document?.Id ?? Guid.Parse("00000000-0000-0000-0000-000000000000")).Result, + Reason = periodExam?.PeriodExam?.Reason ?? "-", + RefNo1 = periodExam?.PeriodExam?.RefNo1 ?? "-", + PeriodExamQrCodes = (periodExam?.PeriodExam?.PeriodExamQrCodes[0]?.Document?.Id ?? null) == null ? "" : _minioService.ImagesPath(periodExam?.PeriodExam?.PeriodExamQrCodes[0]?.Document?.Id ?? Guid.Parse("00000000-0000-0000-0000-000000000000")).Result, + CitizenId = periodExam?.CitizenId ?? "-", + Fee = periodExam?.PeriodExam?.Fee?.ToString() ?? "-", + FeeText = (periodExam?.PeriodExam?.Fee ?? null) == null ? "-" : periodExam?.PeriodExam?.Fee.Value.NumberToThaiText() ?? "-", + } + } + }; + } + public async Task> GetsDashboardPaymentExamAsync(string examId) { var periodExam = await _context.PeriodExams.AsQueryable()