Merge branch 'develop' into working

This commit is contained in:
Suphonchai Phoonsawat 2023-07-27 09:10:55 +07:00
commit 73407d3e73
100 changed files with 47619 additions and 47 deletions

View file

@ -30,6 +30,10 @@ namespace BMA.EHR.Domain.Models.HR
[Comment("ชื่อเครื่องราชฯ")]
// public string? Insignia { get; set; }
public Insignia? Insignia { get; set; }
[Comment("เอกสารอ้างอิง (เลขที่คำสั่ง)")]
public string? RefCommandNo { get; set; }
[Comment("เอกสารอ้างอิง (ลงวันที่)")]
public DateTime? RefCommandDate { get; set; }
public virtual List<ProfileInsigniaHistory> ProfileInsigniaHistorys { get; set; } = new List<ProfileInsigniaHistory>();
public virtual Profile? Profile { get; set; }
}

View file

@ -28,7 +28,7 @@ namespace BMA.EHR.Domain.Models.Placement
[MaxLength(1000), Comment("ทุน")]
public string? FundName { get; set; }
[Comment("ระยะเวลาหลักสูตร")]
public int DurationYear { get; set; }
public int? DurationYear { get; set; }
[Comment("วันที่สำเร็จการศึกษา")]
public DateTime? FinishDate { get; set; }
[Comment("ประเภทช่วงเวลาการศึกษา")]

View file

@ -87,10 +87,10 @@ namespace BMA.EHR.Domain.Models.Placement
[Comment("วันที่ออกบัตร")]
public DateTime? CitizenDate { get; set; }
[MaxLength(20), Comment("โทรศัพท์")]
[MaxLength(200), Comment("โทรศัพท์")]
public string? Telephone { get; set; }
[MaxLength(20), Comment("โทรศัพท์มือถือ")]
[MaxLength(200), Comment("โทรศัพท์มือถือ")]
public string? MobilePhone { get; set; }
[Comment("ความสามารถพิเศษ")]
@ -189,7 +189,7 @@ namespace BMA.EHR.Domain.Models.Placement
[MaxLength(200), Comment("อีเมล บริษัท")]
public string? OccupationEmail { get; set; }
[MaxLength(20), Comment("โทรศัพท์ บริษัท")]
[MaxLength(200), Comment("โทรศัพท์ บริษัท")]
public string? OccupationTelephone { get; set; }
[Comment("ตำแหน่งอาชีพ")]
@ -232,10 +232,10 @@ namespace BMA.EHR.Domain.Models.Placement
public double? PointC { get; set; }
[Comment("ลำดับที่สอบได้")]
public int ExamNumber { get; set; }
public int? ExamNumber { get; set; }
[Comment("จำนวนครั้งที่สมัครสอบ")]
public int ExamRound { get; set; }
public int? ExamRound { get; set; }
[Comment("ผลสมัครสอบ")]
public string? Pass { get; set; }

View file

@ -8,6 +8,8 @@ namespace BMA.EHR.Domain.Models.Retirement
{
[Comment("ครั้งที่")]
public int Round { get; set; }
[Comment("ปีงบประมาณ")]
public int Year { get; set; }
[Comment("ประเภท")]
public string Type { get; set; } = string.Empty;
public virtual List<RetirementProfile> RetirementProfiles { get; set; } = new List<RetirementProfile>();

View file

@ -12,7 +12,7 @@ namespace BMA.EHR.Domain.Models.Retirement
[Required, Comment("เหตุผล")]
public string Reason { get; set; } = string.Empty;
[Comment("ลบออกจากเกษียญ")]
public bool Remove { get; set; } = false;
public string Remove { get; set; } = "pending";
public RetirementPeriod RetirementPeriod { get; set; }
public Profile Profile { get; set; }
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,76 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updateTableretireaddyear : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Remove",
table: "RetirementProfiles",
type: "longtext",
nullable: false,
comment: "ลบออกจากเกษียญ",
oldClrType: typeof(bool),
oldType: "tinyint(1)",
oldComment: "ลบออกจากเกษียญ")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<int>(
name: "Year",
table: "RetirementPeriods",
type: "int",
nullable: false,
defaultValue: 0,
comment: "ปีงบประมาณ");
// migrationBuilder.AddColumn<DateTime>(
// name: "RefCommandDate",
// table: "ProfileInsignias",
// type: "datetime(6)",
// nullable: true,
// comment: "เอกสารอ้างอิง (ลงวันที่)");
// migrationBuilder.AddColumn<string>(
// name: "RefCommandNo",
// table: "ProfileInsignias",
// type: "longtext",
// nullable: true,
// comment: "เอกสารอ้างอิง (เลขที่คำสั่ง)")
// .Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Year",
table: "RetirementPeriods");
// migrationBuilder.DropColumn(
// name: "RefCommandDate",
// table: "ProfileInsignias");
// migrationBuilder.DropColumn(
// name: "RefCommandNo",
// table: "ProfileInsignias");
migrationBuilder.AlterColumn<bool>(
name: "Remove",
table: "RetirementProfiles",
type: "tinyint(1)",
nullable: false,
comment: "ลบออกจากเกษียญ",
oldClrType: typeof(string),
oldType: "longtext",
oldComment: "ลบออกจากเกษียญ")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
}
}

View file

@ -0,0 +1,84 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updateTableplacementExamNumbernullable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "ExamRound",
table: "PlacementProfiles",
type: "int",
nullable: true,
comment: "จำนวนครั้งที่สมัครสอบ",
oldClrType: typeof(int),
oldType: "int",
oldComment: "จำนวนครั้งที่สมัครสอบ");
migrationBuilder.AlterColumn<int>(
name: "ExamNumber",
table: "PlacementProfiles",
type: "int",
nullable: true,
comment: "ลำดับที่สอบได้",
oldClrType: typeof(int),
oldType: "int",
oldComment: "ลำดับที่สอบได้");
migrationBuilder.AlterColumn<int>(
name: "DurationYear",
table: "PlacementEducations",
type: "int",
nullable: true,
comment: "ระยะเวลาหลักสูตร",
oldClrType: typeof(int),
oldType: "int",
oldComment: "ระยะเวลาหลักสูตร");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "ExamRound",
table: "PlacementProfiles",
type: "int",
nullable: false,
defaultValue: 0,
comment: "จำนวนครั้งที่สมัครสอบ",
oldClrType: typeof(int),
oldType: "int",
oldNullable: true,
oldComment: "จำนวนครั้งที่สมัครสอบ");
migrationBuilder.AlterColumn<int>(
name: "ExamNumber",
table: "PlacementProfiles",
type: "int",
nullable: false,
defaultValue: 0,
comment: "ลำดับที่สอบได้",
oldClrType: typeof(int),
oldType: "int",
oldNullable: true,
oldComment: "ลำดับที่สอบได้");
migrationBuilder.AlterColumn<int>(
name: "DurationYear",
table: "PlacementEducations",
type: "int",
nullable: false,
defaultValue: 0,
comment: "ระยะเวลาหลักสูตร",
oldClrType: typeof(int),
oldType: "int",
oldNullable: true,
oldComment: "ระยะเวลาหลักสูตร");
}
}
}

View file

@ -0,0 +1,78 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updateTableplacementprofilemobolelimit200 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Telephone",
table: "PlacementProfiles",
type: "varchar(200)",
maxLength: 200,
nullable: true,
comment: "โทรศัพท์",
oldClrType: typeof(string),
oldType: "varchar(20)",
oldMaxLength: 20,
oldNullable: true,
oldComment: "โทรศัพท์")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AlterColumn<string>(
name: "MobilePhone",
table: "PlacementProfiles",
type: "varchar(200)",
maxLength: 200,
nullable: true,
comment: "โทรศัพท์มือถือ",
oldClrType: typeof(string),
oldType: "varchar(20)",
oldMaxLength: 20,
oldNullable: true,
oldComment: "โทรศัพท์มือถือ")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Telephone",
table: "PlacementProfiles",
type: "varchar(20)",
maxLength: 20,
nullable: true,
comment: "โทรศัพท์",
oldClrType: typeof(string),
oldType: "varchar(200)",
oldMaxLength: 200,
oldNullable: true,
oldComment: "โทรศัพท์")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AlterColumn<string>(
name: "MobilePhone",
table: "PlacementProfiles",
type: "varchar(20)",
maxLength: 20,
nullable: true,
comment: "โทรศัพท์มือถือ",
oldClrType: typeof(string),
oldType: "varchar(200)",
oldMaxLength: 200,
oldNullable: true,
oldComment: "โทรศัพท์มือถือ")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
}
}

View file

@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updateTableplacementprofilemobilelimit200 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "OccupationTelephone",
table: "PlacementProfiles",
type: "varchar(200)",
maxLength: 200,
nullable: true,
comment: "โทรศัพท์ บริษัท",
oldClrType: typeof(string),
oldType: "varchar(20)",
oldMaxLength: 20,
oldNullable: true,
oldComment: "โทรศัพท์ บริษัท")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "OccupationTelephone",
table: "PlacementProfiles",
type: "varchar(20)",
maxLength: 20,
nullable: true,
comment: "โทรศัพท์ บริษัท",
oldClrType: typeof(string),
oldType: "varchar(200)",
oldMaxLength: 200,
oldNullable: true,
oldComment: "โทรศัพท์ บริษัท")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
}
}

View file

@ -3364,6 +3364,14 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("datetime(6)")
.HasComment("ลงวันที่");
b.Property<DateTime?>("RefCommandDate")
.HasColumnType("datetime(6)")
.HasComment("เอกสารอ้างอิง (ลงวันที่)");
b.Property<string>("RefCommandNo")
.HasColumnType("longtext")
.HasComment("เอกสารอ้างอิง (เลขที่คำสั่ง)");
b.Property<string>("Section")
.HasMaxLength(30)
.HasColumnType("varchar(30)")
@ -9613,7 +9621,7 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("varchar(1000)")
.HasComment("ระยะเวลา");
b.Property<int>("DurationYear")
b.Property<int?>("DurationYear")
.HasColumnType("int")
.HasComment("ระยะเวลาหลักสูตร");
@ -9844,11 +9852,11 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("varchar(200)")
.HasComment("อีเมล");
b.Property<int>("ExamNumber")
b.Property<int?>("ExamNumber")
.HasColumnType("int")
.HasComment("ลำดับที่สอบได้");
b.Property<int>("ExamRound")
b.Property<int?>("ExamRound")
.HasColumnType("int")
.HasComment("จำนวนครั้งที่สมัครสอบ");
@ -9949,8 +9957,8 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("char(36)");
b.Property<string>("MobilePhone")
.HasMaxLength(20)
.HasColumnType("varchar(20)")
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasComment("โทรศัพท์มือถือ");
b.Property<string>("MotherFirstName")
@ -10003,8 +10011,8 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasComment("ตำแหน่งอาชีพ");
b.Property<string>("OccupationTelephone")
.HasMaxLength(20)
.HasColumnType("varchar(20)")
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasComment("โทรศัพท์ บริษัท");
b.Property<string>("OccupationType")
@ -10139,8 +10147,8 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasComment("เอกสารอ้างอิง");
b.Property<string>("Telephone")
.HasMaxLength(20)
.HasColumnType("varchar(20)")
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasComment("โทรศัพท์");
b.HasKey("Id");
@ -10317,6 +10325,10 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext")
.HasComment("ประเภท");
b.Property<int>("Year")
.HasColumnType("int")
.HasComment("ปีงบประมาณ");
b.HasKey("Id");
b.ToTable("RetirementPeriods");
@ -10381,8 +10393,9 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext")
.HasComment("เหตุผล");
b.Property<bool>("Remove")
.HasColumnType("tinyint(1)")
b.Property<string>("Remove")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ลบออกจากเกษียญ");
b.Property<Guid>("RetirementPeriodId")

View file

@ -14,8 +14,8 @@
"AllowedHosts": "*",
"ConnectionStrings": {
//"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB",
"DefaultConnection": "server=127.0.0.1;user=root;password=P@ssw0rd;port=3308;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
// "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;"
// "DefaultConnection": "server=127.0.0.1;user=root;password=P@ssw0rd;port=3308;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
"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;"
},
"Jwt": {
"Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI",

View file

@ -353,6 +353,63 @@ namespace BMA.EHR.OrganizationEmployee.Service.Controllers
var organizationEmployee = await _context.OrganizationEmployees
.Where(x => x.Profile == null || (x.Profile != null && x.Profile == profile))
.Select(x => new
{
Id = x.Id,
Use = x.Profile == null ? false : (x.Profile == profile ? true : false),
Agency = x.Agency,
ConditionNote = x.ConditionNote,
Department = x.Department,
Government = x.Government,
IsActive = x.IsActive,
IsCondition = x.IsCondition,
IsDirector = x.IsDirector,
OrganizationUserNote = x.OrganizationUserNote,
Qualification = x.Qualification,
Pile = x.Pile,
PosNo = x.PosNo,
PositionCondition = x.PositionCondition,
PositionMasterUserNote = x.PositionMasterUserNote,
OrganizationOrder = x.OrganizationOrder,
OrganizationFaxId = x.OrganizationFax == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationFax.Id,
OrganizationLevelId = x.OrganizationLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationLevel.Id,
OrganizationOrganizationId = x.OrganizationOrganization == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationOrganization.Id,
OrganizationTelExternalId = x.OrganizationTelExternal == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationTelExternal.Id,
OrganizationTelInternalId = x.OrganizationTelInternal == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationTelInternal.Id,
OrganizationTypeId = x.OrganizationType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationType.Id,
PositionEmployeeStatusId = x.PositionEmployeeStatus == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.PositionEmployeeStatus.Id,
PositionEmployeeLineId = x.PositionEmployeeLine == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.PositionEmployeeLine.Id,
PositionEmployeePositionId = x.PositionEmployeePosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.PositionEmployeePosition.Id,
OrganizationAgencyId = x.OrganizationAgency == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationAgency.Id,
OrganizationGovernmentAgencyId = x.OrganizationGovernmentAgency == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationGovernmentAgency.Id,
OrganizationShortNameId = x.OrganizationShortName == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OrganizationShortName.Id,
OrganizationFaxName = x.OrganizationFax == null ? null : x.OrganizationFax.Name,
OrganizationLevelName = x.OrganizationLevel == null ? null : x.OrganizationLevel.Name,
OrganizationOrganizationName = x.OrganizationOrganization == null ? null : x.OrganizationOrganization.Name,
OrganizationTelExternalName = x.OrganizationTelExternal == null ? null : x.OrganizationTelExternal.Name,
OrganizationTelInternalName = x.OrganizationTelInternal == null ? null : x.OrganizationTelInternal.Name,
OrganizationTypeName = x.OrganizationType == null ? null : x.OrganizationType.Name,
PositionEmployeeStatusName = x.PositionEmployeeStatus == null ? null : x.PositionEmployeeStatus.Name,
PositionEmployeeLineName = x.PositionEmployeeLine == null ? null : x.PositionEmployeeLine.Name,
PositionEmployeePositionName = x.PositionEmployeePosition == null ? null : x.PositionEmployeePosition.Name,
OrganizationAgencyName = x.OrganizationShortName == null ? null : x.OrganizationShortName.AgencyCode,
OrganizationGovernmentAgencyName = x.OrganizationShortName == null ? null : x.OrganizationShortName.GovernmentCode,
// OrganizationAgencyName = x.OrganizationAgency == null ? null : x.OrganizationAgency.Name,
// OrganizationGovernmentAgencyName = x.OrganizationGovernmentAgency == null ? null : x.OrganizationGovernmentAgency.Name,
OrganizationShortNameName = x.OrganizationShortName == null ? null : x.OrganizationShortName.Name,
PositionEmployeeLevels = x.OrganizationPositionEmployeeLevels.Select(y => new
{
Id = y.PositionEmployeeLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : y.PositionEmployeeLevel.Id,
Name = y.PositionEmployeeLevel == null ? null : y.PositionEmployeeLevel.Name,
}),
PositionEmployeePositionSides = x.OrganizationPositionEmployeePositionSides.Select(y => new
{
Id = y.PositionEmployeePositionSide == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : y.PositionEmployeePositionSide.Id,
Name = y.PositionEmployeePositionSide == null ? null : y.PositionEmployeePositionSide.Name,
}),
})
.ToListAsync();
return Success(organizationEmployee);
@ -370,6 +427,11 @@ namespace BMA.EHR.OrganizationEmployee.Service.Controllers
.FirstOrDefaultAsync(x => x.Id == req.OrganizationEmployeeId);
if (organizationEmployee == null)
return Error(GlobalMessages.OrganizationEmployeeNotFound, 404);
var organizationEmployeeProfile = await _context.OrganizationEmployees
.Include(x => x.Profile)
.FirstOrDefaultAsync(x => x.Profile == profile);
if (organizationEmployeeProfile != null)
organizationEmployeeProfile.Profile = null;
organizationEmployee.Profile = profile;
_context.SaveChanges();

View file

@ -56,7 +56,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (type.Trim().ToUpper().Contains("OFFICER"))
{
var profiles = await _context.RetirementProfiles
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.RetirementPeriod.Year == year)
.Where(x => x.RetirementPeriod.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.OrderBy(x => x.Profile.OrganizationOrganization)
.ThenBy(x => x.Profile.PositionType == null ? null : x.Profile.PositionType.Name)
@ -75,7 +75,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (type.Trim().ToUpper().Contains("EMPLOYEE"))
{
var profiles = await _context.RetirementProfiles
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.RetirementPeriod.Year == year)
.Where(x => x.RetirementPeriod.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.OrderBy(x => x.Profile.OrganizationOrganization)
.ThenBy(x => x.Profile.EmployeeType)
@ -112,7 +112,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var retire_old = await _context.RetirementPeriods
.Include(x => x.RetirementProfiles)
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.Year == year)
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.OrderByDescending(x => x.Round)
.FirstOrDefaultAsync();
@ -121,13 +121,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var data = await _context.RetirementPeriods
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.Where(x => year > 0 ? (x.CreatedAt.Year == year) : (x.CreatedAt.Year > 0))
.Where(x => year > 0 ? (x.Year == year) : (x.Year > 0))
.Select(x => new
{
Id = x.Id,
CreatedAt = x.CreatedAt,
Year = x.Year,
Round = x.Round,
Total = retire_old.Id == x.Id ? retire_old.RetirementProfiles.Count() : retire_old.RetirementProfiles.Count() - x.RetirementProfiles.Where(x => x.Remove == true).Count(),
Total = retire_old.Id == x.Id ? retire_old.RetirementProfiles.Count() : retire_old.RetirementProfiles.Count() - x.RetirementProfiles.Where(x => x.Remove != "pending").Count(),
}).OrderByDescending(x => x.CreatedAt)
.ToListAsync();
return Success(data);
@ -152,17 +153,20 @@ namespace BMA.EHR.Retirement.Service.Controllers
var round = 1;
var retire_old = await _context.RetirementPeriods
.Include(x => x.RetirementProfiles)
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.Year == year)
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.OrderByDescending(x => x.Round)
.FirstOrDefaultAsync();
if (retire_old != null)
round = retire_old.Round + 1;
if (!type.Trim().ToUpper().Contains("EMPLOYEE") && !type.Trim().ToUpper().Contains("OFFICER"))
return Error("ประเภทพ้นราชการไม่ถูกต้อง");
var retire = new RetirementPeriod
{
Round = round,
Type = type.Trim().ToUpper(),
Year = year,
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
@ -175,7 +179,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var profiles = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire_old)
.Where(x => x.Remove == false)
.Where(x => x.Remove == "pending")
.Where(x => x.RetirementPeriod.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.ToListAsync();
foreach (var profile in profiles)
@ -198,14 +202,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
// where p.BirthDate.CalculateRetireDate().Year == year
// select p)
// .ToListAsync();
profiles = profiles.Where(x=>x.BirthDate.CalculateRetireDate().Year == year).ToList();
profiles = profiles.Where(x => x.BirthDate.CalculateRetireDate().Year == year).ToList();
var order = 1;
foreach (var profile in profiles)
{
var data = new RetirementProfile
{
Order = order,
Remove = false,
Remove = "pending",
RetirementPeriod = retire,
Profile = profile,
CreatedUserId = FullName ?? "",
@ -220,15 +224,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
}
}
_context.SaveChanges();
var retire_all_year = await _context.RetirementPeriods
.Where(x => x.CreatedAt.Year == year)
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.CountAsync();
if (retire_all_year <= 1)
{
await GenOrderByYear(type.Trim().ToUpper(), year);
}
_context.SaveChanges();
var profile_new = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire)
@ -255,7 +250,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
PosNoEmployee = x.Profile.PosNoEmployee,
})
.ToListAsync();
return Success(new { retire.Id, retire.CreatedAt, retire.Round, retire.Type, profile = profile_new });
return Success(new { retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, profile = profile_new });
}
/// <summary>
@ -277,6 +272,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
var retire_old = await _context.RetirementPeriods
.Where(x => x.CreatedAt < retire.CreatedAt)
.Where(x => x.Year == retire.Year)
.Where(x => x.Type.Trim().ToUpper().Contains(retire.Type.Trim().ToUpper()))
.ToListAsync();
@ -326,7 +322,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
_context.RetirementProfiles.Remove(profile);
profile.Remove = "delete";
profile.LastUpdateFullName = FullName ?? "System Administrator";
profile.LastUpdateUserId = UserId ?? "";
profile.LastUpdatedAt = DateTime.Now;
_context.SaveChanges();
return Success();
@ -356,9 +355,13 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Error(GlobalMessages.InvalidRetirementRequest, 404);
var order = 1;
var retire_old = await _context.RetirementPeriods
.Where(x => x.CreatedAt.Year == retire.CreatedAt.Year)
.Include(x => x.RetirementProfiles)
.ThenInclude(x => x.Profile)
.Where(x => x.Year == retire.Year)
.Where(x => x.Type.Trim().ToUpper().Contains(retire.Type.Trim().ToUpper()))
.ToListAsync();
if (retire_old.Where(x => x.RetirementProfiles.Where(y => y.Profile == profile).Count() > 0).Count() > 0)
return Error("บุคคลนี้ได้ทำการเลือกไว้อยู่แล้ว");
var last_order = await _context.RetirementProfiles
.Where(x => retire_old.Contains(x.RetirementPeriod))
@ -370,7 +373,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
var data = new RetirementProfile
{
Order = order,
Remove = false,
Remove = "pending",
RetirementPeriod = retire,
Profile = profile,
CreatedUserId = FullName ?? "",
@ -380,10 +383,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
if (retire_old.Count() <= 1)
{
await GenOrderByYear(retire.Type.Trim().ToUpper(), retire.CreatedAt.Year);
}
_context.RetirementProfiles.Add(data);
_context.SaveChanges();
@ -409,7 +408,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
profile.Remove = true;
profile.Remove = "change";
profile.Reason = req.Reason;
profile.LastUpdateFullName = FullName ?? "System Administrator";
profile.LastUpdateUserId = UserId ?? "";
@ -443,5 +442,27 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Success(profile);
}
/// <summary>
/// View รายชื่อผู้เกษียณอายุราชการในประกาศ
/// </summary>
/// <param name="retireId">Id ประกาศ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("{retireId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdateProfileRetirement(Guid retireId)
{
var retire = await _context.RetirementPeriods
.FirstOrDefaultAsync(x => x.Id == retireId);
if (retire == null)
return Error(GlobalMessages.InvalidRetirementRequest, 404);
await GenOrderByYear(retire.Type.Trim().ToUpper(), retire.Year);
return Success();
}
}
}