Merge branch 'develop' of github.com:Frappet/BMA-EHR-BackEnd into develop
This commit is contained in:
commit
31c21469ec
13 changed files with 3455 additions and 86 deletions
|
|
@ -10313,7 +10313,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
.Where(x => x.Receivers.Where(x => x.RefPlacementProfileId == id).FirstOrDefault() != null)
|
||||
.Select(x => new
|
||||
{
|
||||
CommandSubject = x.CommandSubject,
|
||||
CommandSubject = $"{x.CommandNo}/{Int32.Parse(x.CommandYear) + 543} {x.CommandSubject}",
|
||||
CreatedAt = x.CreatedAt,
|
||||
LastUpdatedAt = x.LastUpdatedAt,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
var isDuplicate = await CheckDuplicateLeave(rawData.KeycloakUserId, rawData.LeaveStartDate.Date, rawData.LeaveEndDate.Date);
|
||||
var isDuplicate = await CheckDuplicateLeave(rawData.KeycloakUserId, rawData.LeaveStartDate.Date, rawData.LeaveEndDate.Date, rawData.LeaveRange ?? "ALL");
|
||||
if (isDuplicate)
|
||||
{
|
||||
throw new Exception("ไม่สามารถขอลาในช่วงเวลาเดียวกันได้ เนื่องจากมีการขอลาในช่วงเวลาดังกล่าวแล้ว");
|
||||
|
|
@ -577,17 +577,34 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return 0;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckDuplicateLeave(Guid keycloakUserId, DateTime startDate, DateTime endDate)
|
||||
public async Task<bool> CheckDuplicateLeave(Guid keycloakUserId, DateTime startDate, DateTime endDate, string range)
|
||||
{
|
||||
var leaveStatus = new List<string>() { "NEW", "PENDING", "APPROVE" };
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date == startDate.Date || x.LeaveEndDate.Date == endDate.Date)
|
||||
.Where(x => leaveStatus.Contains(x.LeaveStatus))
|
||||
.ToListAsync();
|
||||
if (range == "ALL")
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
//.Where(x => x.LeaveRange == "ALL")
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date == startDate.Date || x.LeaveEndDate.Date == endDate.Date)
|
||||
.Where(x => leaveStatus.Contains(x.LeaveStatus))
|
||||
.ToListAsync();
|
||||
|
||||
return data.Count > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.LeaveRange == range)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date == startDate.Date || x.LeaveEndDate.Date == endDate.Date)
|
||||
.Where(x => leaveStatus.Contains(x.LeaveStatus))
|
||||
.ToListAsync();
|
||||
|
||||
return data.Count > 0;
|
||||
}
|
||||
|
||||
return data.Count > 0;
|
||||
}
|
||||
|
||||
public async Task DeleteLeaveDocumentAsync(Guid Id)
|
||||
|
|
@ -602,6 +619,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<LeaveRequest?> GetLeavePeriodAsync(Guid keycloakUserId, DateTime date)
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStatus == "APPROVE")
|
||||
.Where(x => x.LeaveStartDate.Date >= date.Date && x.LeaveEndDate <= date.Date)
|
||||
.FirstOrDefaultAsync();
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -631,7 +631,7 @@ namespace BMA.EHR.DisciplineDisciplinary.Service.Controllers
|
|||
data.DisciplineDisciplinaryExtends.Add(
|
||||
new DisciplineDisciplinaryExtend
|
||||
{
|
||||
Name = sumExtend > 0 ? "ขยายครั้งที่" + sumExtend : "วันที่สอบสวน",
|
||||
Name = sumExtend > 0 ? "ขยายครั้งที่ " + sumExtend : "วันที่สอบสวน",
|
||||
Num = sumExtend,
|
||||
DaysExtend = data.DisciplinaryDaysExtend,
|
||||
DateStart = sumExtend > 0 && data.DisciplinaryDateEnd != null ? data.DisciplinaryDateEnd.Value.AddDays(data.DisciplinaryDaysExtend == null ? 0 : -(double)data.DisciplinaryDaysExtend + 1) : data.DisciplinaryDateStart,
|
||||
|
|
@ -657,8 +657,8 @@ namespace BMA.EHR.DisciplineDisciplinary.Service.Controllers
|
|||
new DisciplineDisciplinary_DirectorInvestigate
|
||||
{
|
||||
DisciplineDirector = director,
|
||||
Duty = isDirector == null ? "" : isDirector.Duty,
|
||||
CommandNo = isDirector == null ? "" : isDirector.CommandNo,
|
||||
Duty = isDirector == null ? null : isDirector.Duty,
|
||||
CommandNo = isDirector == null ? null : isDirector.CommandNo,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
|
|
|
|||
|
|
@ -396,7 +396,7 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
|
|||
data.DisciplineInvestigateExtends.Add(
|
||||
new DisciplineInvestigateExtend
|
||||
{
|
||||
Name = sumExtend > 0 ? "ขยายครั้งที่" + sumExtend : "วันที่สืบสวน",
|
||||
Name = sumExtend > 0 ? "ขยายครั้งที่ " + sumExtend : "วันที่สืบสวน",
|
||||
Num = sumExtend,
|
||||
DaysExtend = data.InvestigationDaysExtend,
|
||||
DateStart = sumExtend > 0 && data.InvestigationDateEnd != null ? data.InvestigationDateEnd.Value.AddDays(data.InvestigationDaysExtend == null ? 0 : -(double)data.InvestigationDaysExtend + 1) : data.InvestigationDateStart,
|
||||
|
|
@ -422,8 +422,8 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
|
|||
new DisciplineInvestigate_Director
|
||||
{
|
||||
DisciplineDirector = director,
|
||||
Duty = isDirector == null ? "" : isDirector.Duty,
|
||||
CommandNo = isDirector == null ? "" : isDirector.CommandNo,
|
||||
Duty = isDirector == null ? null : isDirector.Duty,
|
||||
CommandNo = isDirector == null ? null : isDirector.CommandNo,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@
|
|||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
//"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB",
|
||||
"DefaultConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"ExamConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_exam_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"LeaveConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_leave_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"DisciplineConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_discipline_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
||||
"DefaultConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"ExamConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_exam_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"LeaveConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_leave_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"DisciplineConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_discipline_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI",
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ namespace BMA.EHR.Domain.Models.Discipline
|
|||
[Required, Comment("อ้างอิงเรื่องสอบสวน")]
|
||||
public DisciplineDisciplinary DisciplineDisciplinary { get; set; }
|
||||
[Comment("หน้าที่")]
|
||||
public string Duty { get; set; } = string.Empty;
|
||||
public string? Duty { get; set; } = string.Empty;
|
||||
[Comment("เลขที่คำสั่ง")]
|
||||
public string CommandNo { get; set; } = string.Empty;
|
||||
public string? CommandNo { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ namespace BMA.EHR.Domain.Models.Discipline
|
|||
[Required, Comment("อ้างอิงเรื่องสืบสวน")]
|
||||
public DisciplineInvestigate DisciplineInvestigate { get; set; }
|
||||
[Comment("หน้าที่")]
|
||||
public string Duty { get; set; } = string.Empty;
|
||||
public string? Duty { get; set; } = string.Empty;
|
||||
[Comment("เลขที่คำสั่ง")]
|
||||
public string CommandNo { get; set; } = string.Empty;
|
||||
public string? CommandNo { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,146 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class updatetableDisciplineDirectorscommandnonullable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Duty",
|
||||
table: "DisciplineInvestigate_Directors",
|
||||
type: "longtext",
|
||||
nullable: true,
|
||||
comment: "หน้าที่",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "longtext",
|
||||
oldComment: "หน้าที่")
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
.OldAnnotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "CommandNo",
|
||||
table: "DisciplineInvestigate_Directors",
|
||||
type: "longtext",
|
||||
nullable: true,
|
||||
comment: "เลขที่คำสั่ง",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "longtext",
|
||||
oldComment: "เลขที่คำสั่ง")
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
.OldAnnotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Duty",
|
||||
table: "DisciplineDisciplinary_DirectorInvestigates",
|
||||
type: "longtext",
|
||||
nullable: true,
|
||||
comment: "หน้าที่",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "longtext",
|
||||
oldComment: "หน้าที่")
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
.OldAnnotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "CommandNo",
|
||||
table: "DisciplineDisciplinary_DirectorInvestigates",
|
||||
type: "longtext",
|
||||
nullable: true,
|
||||
comment: "เลขที่คำสั่ง",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "longtext",
|
||||
oldComment: "เลขที่คำสั่ง")
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
.OldAnnotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DisciplineInvestigate_Directors",
|
||||
keyColumn: "Duty",
|
||||
keyValue: null,
|
||||
column: "Duty",
|
||||
value: "");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Duty",
|
||||
table: "DisciplineInvestigate_Directors",
|
||||
type: "longtext",
|
||||
nullable: false,
|
||||
comment: "หน้าที่",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "longtext",
|
||||
oldNullable: true,
|
||||
oldComment: "หน้าที่")
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
.OldAnnotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DisciplineInvestigate_Directors",
|
||||
keyColumn: "CommandNo",
|
||||
keyValue: null,
|
||||
column: "CommandNo",
|
||||
value: "");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "CommandNo",
|
||||
table: "DisciplineInvestigate_Directors",
|
||||
type: "longtext",
|
||||
nullable: false,
|
||||
comment: "เลขที่คำสั่ง",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "longtext",
|
||||
oldNullable: true,
|
||||
oldComment: "เลขที่คำสั่ง")
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
.OldAnnotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DisciplineDisciplinary_DirectorInvestigates",
|
||||
keyColumn: "Duty",
|
||||
keyValue: null,
|
||||
column: "Duty",
|
||||
value: "");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Duty",
|
||||
table: "DisciplineDisciplinary_DirectorInvestigates",
|
||||
type: "longtext",
|
||||
nullable: false,
|
||||
comment: "หน้าที่",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "longtext",
|
||||
oldNullable: true,
|
||||
oldComment: "หน้าที่")
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
.OldAnnotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DisciplineDisciplinary_DirectorInvestigates",
|
||||
keyColumn: "CommandNo",
|
||||
keyValue: null,
|
||||
column: "CommandNo",
|
||||
value: "");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "CommandNo",
|
||||
table: "DisciplineDisciplinary_DirectorInvestigates",
|
||||
type: "longtext",
|
||||
nullable: false,
|
||||
comment: "เลขที่คำสั่ง",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "longtext",
|
||||
oldNullable: true,
|
||||
oldComment: "เลขที่คำสั่ง")
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
.OldAnnotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1005,7 +1005,6 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
|
|||
.HasAnnotation("Relational:JsonPropertyName", "id");
|
||||
|
||||
b.Property<string>("CommandNo")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasComment("เลขที่คำสั่ง");
|
||||
|
||||
|
|
@ -1035,7 +1034,6 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
|
|||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("Duty")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasComment("หน้าที่");
|
||||
|
||||
|
|
@ -2056,7 +2054,6 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
|
|||
.HasAnnotation("Relational:JsonPropertyName", "id");
|
||||
|
||||
b.Property<string>("CommandNo")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasComment("เลขที่คำสั่ง");
|
||||
|
||||
|
|
@ -2086,7 +2083,6 @@ namespace BMA.EHR.Infrastructure.Migrations.DisciplineDb
|
|||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<string>("Duty")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext")
|
||||
.HasComment("หน้าที่");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
using System.IO.Pipelines;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Repositories.Leaves.LeaveRequests;
|
||||
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||
using BMA.EHR.Application.Repositories.MetaData;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.Leave.Requests;
|
||||
|
|
@ -12,6 +15,7 @@ using BMA.EHR.Infrastructure.Persistence;
|
|||
using BMA.EHR.Leave.Service.DTOs.Reports;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Leave.Service.Controllers
|
||||
|
|
@ -25,6 +29,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
public class LeaveReportController : BaseController
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private static CultureInfo _culture = new CultureInfo("th-TH");
|
||||
private readonly LeaveRequestRepository _leaveRequestRepository;
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
private readonly CommandRepository _commandRepository;
|
||||
|
|
@ -32,6 +38,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
private readonly ProcessUserTimeStampRepository _processUserTimeStampRepository;
|
||||
private readonly DutyTimeRepository _dutyTimeRepository;
|
||||
private readonly UserDutyTimeRepository _userDutyTimeRepository;
|
||||
private readonly HolidayRepository _holidayRepository;
|
||||
private readonly UserCalendarRepository _userCalendarRepository;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -43,7 +51,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
LeaveTypeRepository leaveTypeRepository,
|
||||
ProcessUserTimeStampRepository processUserTimeStampRepository,
|
||||
DutyTimeRepository dutyTimeRepository,
|
||||
UserDutyTimeRepository userDutyTimeRepository)
|
||||
UserDutyTimeRepository userDutyTimeRepository,
|
||||
HolidayRepository holidayRepository,
|
||||
UserCalendarRepository userCalendarRepository)
|
||||
{
|
||||
_leaveRequestRepository = leaveRequestRepository;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
|
|
@ -52,6 +62,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
_processUserTimeStampRepository = processUserTimeStampRepository;
|
||||
_dutyTimeRepository = dutyTimeRepository;
|
||||
_userDutyTimeRepository = userDutyTimeRepository;
|
||||
_holidayRepository = holidayRepository;
|
||||
_userCalendarRepository = userCalendarRepository;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -1096,66 +1108,199 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
var profile = await _userProfileRepository.GetProfileWithKeycloak();
|
||||
var date = req.StartDate.Date;
|
||||
|
||||
var holidays = await _holidayRepository.GetHolidayAsync(req.StartDate.Date, req.EndDate.Date);
|
||||
var weekend = _holidayRepository.GetWeekEnd(req.StartDate.Date, req.EndDate.Date);
|
||||
var excludeDates = holidays.Union(weekend).ToList();
|
||||
|
||||
var dateList = new List<DateTime>();
|
||||
|
||||
for (DateTime i = req.StartDate.Date; i <= req.EndDate.Date; i = i.AddDays(1))
|
||||
{
|
||||
if (!excludeDates.Contains(i))
|
||||
dateList.Add(i);
|
||||
}
|
||||
|
||||
var employees = new List<dynamic>();
|
||||
var count = 1;
|
||||
foreach (var p in profile)
|
||||
|
||||
var restTotal = 0;
|
||||
var sickTotal = 0;
|
||||
var lateTotal = 0;
|
||||
var wfhTotal = 0;
|
||||
var studyTotal = 0;
|
||||
|
||||
|
||||
foreach (var dd in dateList)
|
||||
{
|
||||
var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(p.KeycloakId ?? Guid.Empty, date);
|
||||
|
||||
var fullName = _userProfileRepository.GetUserFullName(p.KeycloakId ?? Guid.Empty);
|
||||
|
||||
|
||||
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||
if (defaultRound == null)
|
||||
foreach (var p in profile)
|
||||
{
|
||||
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
|
||||
|
||||
var keycloakUserId = p.KeycloakId ?? Guid.Empty;
|
||||
|
||||
var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(keycloakUserId, dd);
|
||||
|
||||
var fullName = _userProfileRepository.GetUserFullName(keycloakUserId);
|
||||
|
||||
|
||||
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||
if (defaultRound == null)
|
||||
{
|
||||
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
|
||||
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
|
||||
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
||||
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
||||
|
||||
var duty = userRound ?? defaultRound;
|
||||
|
||||
// check วันลาของแต่ละคน
|
||||
var leaveReq = await _leaveRequestRepository.GetLeavePeriodAsync(keycloakUserId, dd);
|
||||
var remarkStr = string.Empty;
|
||||
|
||||
if (leaveReq != null)
|
||||
{
|
||||
switch (leaveReq.Type.Code.ToUpper())
|
||||
{
|
||||
case "LV-001":
|
||||
case "LV-002":
|
||||
case "LV-005":
|
||||
remarkStr += leaveReq.Type.Name;
|
||||
var leaveRange = leaveReq.LeaveRange == null ? "" : leaveReq.LeaveRange.ToUpper();
|
||||
if (leaveRange == "MORNING")
|
||||
remarkStr += "ครึ่งวันเช้า";
|
||||
else if (leaveRange == "AFTERNOON")
|
||||
remarkStr += "ครึ่งวันบ่าย";
|
||||
break;
|
||||
default:
|
||||
remarkStr += leaveReq.Type.Name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeStamps == null)
|
||||
{
|
||||
if (dd <= DateTime.Now.Date)
|
||||
remarkStr = "ขาดราชการ";
|
||||
else remarkStr = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
// check status ของการลงเวลา
|
||||
if (timeStamps.CheckOut != null)
|
||||
{
|
||||
if (timeStamps.CheckOutStatus == "ABSENT")
|
||||
remarkStr = "ขาดราชการ";
|
||||
else if (timeStamps.CheckInStatus == "ABSENT")
|
||||
remarkStr = "ขาดราชการ";
|
||||
else if (timeStamps.CheckInStatus == "LATE")
|
||||
{
|
||||
remarkStr = "สาย";
|
||||
lateTotal += 1;
|
||||
}
|
||||
else
|
||||
remarkStr = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeStamps.CheckInStatus == "ABSENT")
|
||||
remarkStr = "ขาดราชการ";
|
||||
else if (timeStamps.CheckInStatus == "LATE")
|
||||
{
|
||||
remarkStr = "สาย";
|
||||
lateTotal += 1;
|
||||
}
|
||||
else
|
||||
remarkStr = "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var emp = new
|
||||
{
|
||||
no = count,
|
||||
fullName = fullName,
|
||||
dutyTimeName = $"{duty.StartTimeMorning} - {duty.EndTimeAfternoon} น.",
|
||||
checkInLocation = timeStamps == null ? "" : timeStamps.CheckInPOI,
|
||||
checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.ToString("HH:mm")} น.",
|
||||
|
||||
checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutPOI ?? "",
|
||||
checkOutTime = timeStamps == null ? "" :
|
||||
timeStamps.CheckOut != null ?
|
||||
$"{timeStamps.CheckOut.Value.ToString("HH:mm")} น." :
|
||||
"",
|
||||
|
||||
//remark = timeStamps == null ? "ขาดราชการ" : "",
|
||||
remark = remarkStr,
|
||||
|
||||
checkInDate = timeStamps == null ? dd.Date.ToThaiFullDate2().ToThaiNumber() : timeStamps.CheckIn.Date.ToThaiFullDate2().ToThaiNumber(),
|
||||
checkedOutDate = timeStamps == null ? dd.Date.ToThaiFullDate2().ToThaiNumber() :
|
||||
timeStamps.CheckOut != null ?
|
||||
timeStamps.CheckOut.Value.ToThaiFullDate2().ToThaiNumber() :
|
||||
"",
|
||||
};
|
||||
|
||||
if (timeStamps != null)
|
||||
{
|
||||
if (timeStamps.IsLocationCheckIn)
|
||||
wfhTotal += 1;
|
||||
else
|
||||
{
|
||||
if (leaveReq != null)
|
||||
{
|
||||
switch (leaveReq.Type.Code.ToUpper())
|
||||
{
|
||||
case "LV-001":
|
||||
case "LV-002":
|
||||
sickTotal += 1;
|
||||
break;
|
||||
case "LV-005":
|
||||
restTotal += 1;
|
||||
break;
|
||||
case "LV-008":
|
||||
studyTotal += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
employees.Add(emp);
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
|
||||
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
|
||||
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
||||
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
||||
|
||||
var duty = userRound ?? defaultRound;
|
||||
|
||||
var emp = new
|
||||
{
|
||||
no = count,
|
||||
fullName = fullName,
|
||||
dutyTimeName = $"{duty.StartTimeMorning} - {duty.EndTimeAfternoon} น.",
|
||||
checkInLocation = timeStamps == null ? "" : timeStamps.CheckInPOI,
|
||||
checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.ToString("HH:mm")} น.",
|
||||
|
||||
checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutPOI ?? "",
|
||||
checkOutTime = timeStamps == null ? "" :
|
||||
timeStamps.CheckOut != null ?
|
||||
$"{timeStamps.CheckOut.Value.ToString("HH:mm")} น." :
|
||||
"",
|
||||
|
||||
remark = timeStamps == null ? "ขาดราชการ" : "",
|
||||
|
||||
checkInDate = timeStamps == null ? "" : timeStamps.CheckIn.Date.ToThaiFullDate2().ToThaiNumber(),
|
||||
checkedOutDate = timeStamps == null ? "" :
|
||||
timeStamps.CheckOut != null ?
|
||||
timeStamps.CheckOut.Value.ToThaiFullDate2().ToThaiNumber() :
|
||||
"",
|
||||
};
|
||||
|
||||
employees.Add(emp);
|
||||
count++;
|
||||
}
|
||||
|
||||
var dateStamp = "";
|
||||
switch (req.Type.ToUpper())
|
||||
{
|
||||
case "MONTH":
|
||||
{
|
||||
var dd = req.StartDate.Date;
|
||||
dateStamp = $"เดือน {dd.ToString("MMMM", _culture.DateTimeFormat)} พ.ศ. {dd.Year.ToThaiYear()}".ToThaiNumber();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dateStamp = req.StartDate.Date.ToThaiFullDate().ToThaiNumber();
|
||||
break;
|
||||
}
|
||||
|
||||
var item = new
|
||||
{
|
||||
DateTimeStamp = date.Date.ToThaiFullDate(),
|
||||
DateTimeStamp = dateStamp,
|
||||
officerTotal = profile.Count,
|
||||
workTotal = (count - 1),
|
||||
restTotal = 0,
|
||||
sickTotal = 0,
|
||||
lateTotal = 0,
|
||||
wfhTotal = 0,
|
||||
studyTotal = 0,
|
||||
restTotal = restTotal,
|
||||
sickTotal = sickTotal,
|
||||
lateTotal = lateTotal,
|
||||
wfhTotal = wfhTotal,
|
||||
studyTotal = studyTotal,
|
||||
employees = employees
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -707,7 +707,62 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
isLeave = govAge >= 365;
|
||||
break;
|
||||
case "LV-010":
|
||||
var maxEnd = new DateTime(req.StartLeaveDate.Year + 2, req.StartLeaveDate.Month, req.StartLeaveDate.Day - 1);
|
||||
int yy, mm, dd;
|
||||
yy = req.StartLeaveDate.Year + 2;
|
||||
if (req.StartLeaveDate.Day == 1)
|
||||
{
|
||||
if (req.StartLeaveDate.Month == 1)
|
||||
{
|
||||
mm = 12;
|
||||
dd = 31;
|
||||
}
|
||||
else
|
||||
{
|
||||
mm = req.StartLeaveDate.Month - 1;
|
||||
switch (mm)
|
||||
{
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
{
|
||||
dd = 31;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (DateTime.IsLeapYear(yy))
|
||||
{
|
||||
dd = 29;
|
||||
}
|
||||
else
|
||||
dd = 28;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
{
|
||||
dd = 30;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dd = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mm = req.StartLeaveDate.Month;
|
||||
dd = req.StartLeaveDate.Day - 1;
|
||||
}
|
||||
|
||||
var maxEnd = new DateTime(yy, mm, dd);
|
||||
isLeave = req.EndLeaveDate.Date <= maxEnd;
|
||||
break;
|
||||
case "LV-011":
|
||||
|
|
@ -1562,15 +1617,15 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
}
|
||||
|
||||
|
||||
[HttpGet("holiday/test")]
|
||||
public async Task<ActionResult<ResponseObject>> GetHolidayTestAsync()
|
||||
{
|
||||
var start = new DateTime(2024, 1, 1);
|
||||
var end = new DateTime(2024, 1, 3);
|
||||
var count = await _holidayRepository.GetHolidayCountAsync(start, end);
|
||||
// [HttpGet("holiday/test")]
|
||||
// public async Task<ActionResult<ResponseObject>> GetHolidayTestAsync()
|
||||
// {
|
||||
// var start = new DateTime(2024, 1, 1);
|
||||
// var end = new DateTime(2024, 1, 3);
|
||||
// var count = await _holidayRepository.GetHolidayCountAsync(start, end);
|
||||
|
||||
return Success(new { holiday = count });
|
||||
}
|
||||
// return Success(new { holiday = count });
|
||||
// }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ namespace BMA.EHR.Leave.Service.DTOs.Reports
|
|||
{
|
||||
public DateTime StartDate { get; set; } = DateTime.MinValue;
|
||||
|
||||
//public DateTime EndDate { get; set; } = DateTime.MinValue;
|
||||
public DateTime EndDate { get; set; } = DateTime.MinValue;
|
||||
|
||||
public string Type { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue