11756 lines
669 KiB
C#
11756 lines
669 KiB
C#
using BMA.EHR.Application.Common.Interfaces;
|
|
using BMA.EHR.Application.Messaging;
|
|
using BMA.EHR.Application.Requests.Commands;
|
|
using BMA.EHR.Application.Responses;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.Commands.Core;
|
|
using BMA.EHR.Domain.Models.HR;
|
|
using BMA.EHR.Domain.Models.MetaData;
|
|
using BMA.EHR.Domain.Models.Notifications;
|
|
using BMA.EHR.Domain.Models.OrganizationEmployee;
|
|
using BMA.EHR.Domain.Models.Organizations;
|
|
using BMA.EHR.Domain.Models.Placement;
|
|
using BMA.EHR.Domain.Models.Retirement;
|
|
using BMA.EHR.Domain.Shared;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using System.Net.Http.Headers;
|
|
using System.Net.Http.Json;
|
|
using System.Net.Http.Json;
|
|
using Command = BMA.EHR.Domain.Models.Commands.Core.Command;
|
|
using Profile = BMA.EHR.Domain.Models.HR.Profile;
|
|
|
|
namespace BMA.EHR.Application.Repositories.Commands
|
|
{
|
|
public class CommandRepository : GenericRepository<Guid, Command>
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly IApplicationDBContext _dbContext;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
|
private readonly UserProfileRepository _userProfileRepository;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly EmailSenderService _emailSenderService;
|
|
|
|
#endregion
|
|
|
|
#region " Constructor and Destuctor "
|
|
|
|
public CommandRepository(IApplicationDBContext dbContext,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
OrganizationCommonRepository organizationCommonRepository,
|
|
UserProfileRepository userProfileRepository,
|
|
IConfiguration configuration,
|
|
EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor)
|
|
{
|
|
_dbContext = dbContext;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_organizationCommonRepository = organizationCommonRepository;
|
|
_userProfileRepository = userProfileRepository;
|
|
_configuration = configuration;
|
|
_emailSenderService = emailSenderService;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Properties "
|
|
|
|
protected Guid UserOrganizationId
|
|
{
|
|
get
|
|
{
|
|
if (UserId != null || UserId != "")
|
|
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
|
else
|
|
return Guid.Empty;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
|
|
public void SendMail()
|
|
{
|
|
_emailSenderService.SendMail("Test Send Email", "ทดสอบส่งเมล์", "suphonchai.ph@gmail.com");
|
|
}
|
|
|
|
#region " Private "
|
|
|
|
#region " List Receiver "
|
|
|
|
public async Task<List<CommandReceiver>> GetReceiverForByCommndTypeAsync(Command command, string token = "")
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
|
|
switch (command.CommandType.CommandCode.Trim().ToUpper())
|
|
{
|
|
case "C-PM-01":
|
|
result = await GetReceiver01Async(command);
|
|
break;
|
|
case "C-PM-02":
|
|
result = await GetReceiver02Async(command);
|
|
break;
|
|
case "C-PM-03":
|
|
result = await GetReceiver03Async(command);
|
|
break;
|
|
case "C-PM-04":
|
|
result = await GetReceiver04Async(command);
|
|
break;
|
|
case "C-PM-05":
|
|
result = await GetReceiver05Async(command);
|
|
break;
|
|
case "C-PM-06":
|
|
result = await GetReceiver06Async(command);
|
|
break;
|
|
case "C-PM-07":
|
|
result = await GetReceiver07Async(command);
|
|
break;
|
|
case "C-PM-08":
|
|
result = await GetReceiver08Async(command);
|
|
break;
|
|
case "C-PM-09":
|
|
result = await GetReceiver09Async(command);
|
|
break;
|
|
case "C-PM-10":
|
|
result = await GetReceiver10Async(command);
|
|
break;
|
|
case "C-PM-11":
|
|
result = await GetReceiver11Async(command, token);
|
|
break;
|
|
case "C-PM-12":
|
|
result = await GetReceiver12Async(command, token);
|
|
break;
|
|
case "C-PM-13":
|
|
result = await GetReceiver13Async(command);
|
|
break;
|
|
case "C-PM-14":
|
|
result = await GetReceiver14Async(command);
|
|
break;
|
|
case "C-PM-15":
|
|
result = await GetReceiver15Async(command);
|
|
break;
|
|
case "C-PM-16":
|
|
result = await GetReceiver16Async(command);
|
|
break;
|
|
case "C-PM-17":
|
|
result = await GetReceiver17Async(command);
|
|
break;
|
|
case "C-PM-18":
|
|
result = await GetReceiver18Async(command);
|
|
break;
|
|
case "C-PM-19":
|
|
result = await GetReceiver19Async(command, token);
|
|
break;
|
|
case "C-PM-20":
|
|
result = await GetReceiver20Async(command, token);
|
|
break;
|
|
case "C-PM-21":
|
|
result = await GetReceiver21Async(command);
|
|
break;
|
|
case "C-PM-22":
|
|
result = await GetReceiver22Async(command);
|
|
break;
|
|
case "C-PM-23":
|
|
result = await GetReceiver23Async(command);
|
|
break;
|
|
case "C-PM-24":
|
|
result = await GetReceiver24Async(command);
|
|
break;
|
|
case "C-PM-25":
|
|
result = await GetReceiver25Async(command, token);
|
|
break;
|
|
case "C-PM-26":
|
|
result = await GetReceiver26Async(command, token);
|
|
break;
|
|
case "C-PM-27":
|
|
result = await GetReceiver27Async(command, token);
|
|
break;
|
|
case "C-PM-28":
|
|
result = await GetReceiver28Async(command, token);
|
|
break;
|
|
case "C-PM-29":
|
|
result = await GetReceiver29Async(command, token);
|
|
break;
|
|
case "C-PM-30":
|
|
result = await GetReceiver30Async(command, token);
|
|
break;
|
|
case "C-PM-31":
|
|
result = await GetReceiver31Async(command, token);
|
|
break;
|
|
case "C-PM-32":
|
|
result = await GetReceiver32Async(command, token);
|
|
break;
|
|
case "C-PM-33":
|
|
result = await GetReceiver33Async(command, token);
|
|
break;
|
|
case "C-PM-34":
|
|
result = await GetReceiver34Async(command, token);
|
|
break;
|
|
case "C-PM-35":
|
|
result = await GetReceiver35Async(command, token);
|
|
break;
|
|
case "C-PM-36":
|
|
result = await GetReceiver36Async(command, token);
|
|
break;
|
|
case "C-PM-37":
|
|
result = await GetReceiver37Async(command, token);
|
|
break;
|
|
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver01Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper().StartsWith("C-PM-01"))
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.Placement)
|
|
.ThenInclude(x => x.PlacementType)
|
|
.Include(x => x.Prefix)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => x.Placement.Id == command.Placement.Id)
|
|
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
|
|
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
|
.Where(x => x.Draft! == true)
|
|
.Where(x => x.Placement!.PlacementType!.Name == "สอบแข่งขัน")
|
|
.OrderBy(x => x.ExamNumber)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
if (!(await CheckIsActiveOfficerAsync(item.CitizenId!)))
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.CitizenId!,
|
|
Prefix = item.Prefix,
|
|
FirstName = item.Firstname!,
|
|
LastName = item.Lastname!,
|
|
RefPlacementProfileId = item.Id,
|
|
};
|
|
seq++;
|
|
result.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver02Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-02")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.Placement)
|
|
.ThenInclude(x => x.PlacementType)
|
|
.Include(x => x.Prefix)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => x.Placement.Id == command.Placement.Id)
|
|
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
|
|
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
|
.Where(x => x.Draft! == true)
|
|
.Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน")
|
|
.OrderBy(x => x.ExamNumber)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
if (!(await CheckIsActiveOfficerAsync(item.CitizenId!)))
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.CitizenId!,
|
|
Prefix = item.Prefix,
|
|
FirstName = item.Firstname!,
|
|
LastName = item.Lastname!,
|
|
RefPlacementProfileId = item.Id,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver03Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-03")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.Placement)
|
|
.ThenInclude(x => x.PlacementType)
|
|
.Include(x => x.Prefix)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => x.Placement.Id == command.Placement.Id)
|
|
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
|
|
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
|
.Where(x => x.Draft! == true)
|
|
.OrderBy(x => x.ExamNumber)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!);
|
|
if (await CheckIsActiveOfficerAsync(item.CitizenId!))
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.CitizenId!,
|
|
Prefix = item.Prefix,
|
|
FirstName = item.Firstname!,
|
|
LastName = item.Lastname!,
|
|
RefPlacementProfileId = item.Id,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-04 - คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver04Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-04")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.Placement)
|
|
.ThenInclude(x => x.PlacementType)
|
|
.Include(x => x.Prefix)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.Organization)
|
|
.Where(x => x.Placement.Id == command.Placement.Id)
|
|
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
|
|
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
|
.Where(x => x.Draft! == true)
|
|
.OrderBy(x => x.ExamNumber)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var profile_oc = await GetProfileOrganizationAsync(item.CitizenId!);
|
|
if (await CheckIsActiveOfficerAsync(item.CitizenId!))
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.CitizenId!,
|
|
Prefix = item.Prefix,
|
|
FirstName = item.Firstname!,
|
|
LastName = item.Lastname!,
|
|
RefPlacementProfileId = item.Id,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-05 - คำสั่งแต่งตั้ง
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver05Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-05")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementAppointment>()
|
|
//.Include(x => x.CommandType)
|
|
//.Include(x => x.Prefix)
|
|
//.Include(x => x.OrganizationPosition)
|
|
//.ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
//.Where(x => x.CommandType!.Id == command.CommandType!.Id)
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-06 - คำสั่งเลื่อน
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver06Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-06")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementAppointment>()
|
|
//.Include(x => x.CommandType)
|
|
//.Include(x => x.Prefix)
|
|
//.Include(x => x.OrganizationPosition)
|
|
//.ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
//.Where(x => x.CommandType!.Id == command.CommandType!.Id)
|
|
//.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId!,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-07 - คำสั่งย้าย
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver07Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-07")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementAppointment>()
|
|
//.Include(x => x.CommandType)
|
|
//.Include(x => x.Prefix)
|
|
//.Include(x => x.OrganizationPosition)
|
|
//.ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
//.Where(x => x.CommandType!.Id == command.CommandType!.Id)
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-08 - คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver08Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-08")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<RetirementOther>()
|
|
.Include(x => x.CommandType)
|
|
// .Include(x => x.Prefix)
|
|
//.Include(x => x.OrganizationPosition)
|
|
//.ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.Where(x => x.CommandType!.Id == command.CommandType!.Id)
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-09 - คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver09Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-09")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<RetirementOther>()
|
|
.Include(x => x.CommandType)
|
|
//.Include(x => x.Prefix)
|
|
//.Include(x => x.OrganizationPosition)
|
|
//.ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.Where(x => x.CommandType!.Id == command.CommandType!.Id)
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-10 - คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver10Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
var seq = 1;
|
|
// เอาชื่อของกรรมการ ไปหาจากทะเบียนประวัติ
|
|
|
|
var p1 = (await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.Select(x => new
|
|
{
|
|
profileId = x.Id,
|
|
citizenId = x.CitizenId,
|
|
prefix = x.Prefix.Name,
|
|
firstName = x.FirstName,
|
|
lastName = x.LastName,
|
|
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
|
|
})
|
|
.ToListAsync())
|
|
.FirstOrDefault(x => x.fullName == command.ChairManFullName);
|
|
|
|
if (p1 != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = p1.citizenId!,
|
|
Prefix = p1.prefix!,
|
|
FirstName = p1.firstName!,
|
|
LastName = p1.lastName!,
|
|
RefPlacementProfileId = p1.profileId,
|
|
};
|
|
seq++;
|
|
result.Add(receiver);
|
|
}
|
|
|
|
var p2 = (await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.Select(x => new
|
|
{
|
|
profileId = x.Id,
|
|
citizenId = x.CitizenId,
|
|
prefix = x.Prefix.Name,
|
|
firstName = x.FirstName,
|
|
lastName = x.LastName,
|
|
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
|
|
})
|
|
.ToListAsync())
|
|
.FirstOrDefault(x => x.fullName == command.Member1FullName);
|
|
|
|
if (p2 != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = p2.citizenId!,
|
|
Prefix = p2.prefix!,
|
|
FirstName = p2.firstName!,
|
|
LastName = p2.lastName!,
|
|
RefPlacementProfileId = p2.profileId,
|
|
};
|
|
seq++;
|
|
result.Add(receiver);
|
|
}
|
|
|
|
var p3 = (await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.Select(x => new
|
|
{
|
|
profileId = x.Id,
|
|
citizenId = x.CitizenId,
|
|
prefix = x.Prefix.Name,
|
|
firstName = x.FirstName,
|
|
lastName = x.LastName,
|
|
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
|
|
})
|
|
.ToListAsync())
|
|
.FirstOrDefault(x => x.fullName == command.Member2FullName);
|
|
|
|
if (p3 != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = p3.citizenId!,
|
|
Prefix = p3.prefix!,
|
|
FirstName = p3.firstName!,
|
|
LastName = p3.lastName!,
|
|
RefPlacementProfileId = p3.profileId,
|
|
};
|
|
seq++;
|
|
result.Add(receiver);
|
|
}
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-11 - คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver11Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["Node:API"];
|
|
var apiUrl = $"{baseAPI}/report/pass";
|
|
|
|
var response = new PassProbationResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassProbationResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.data)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.person.id);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver12Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["Node:API"];
|
|
var apiUrl = $"{baseAPI}/report/not-pass";
|
|
|
|
var response = new PassProbationResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassProbationResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.data)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.person.id);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-13 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver13Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-13")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementTransfer>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.Profile!.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.Profile!.CitizenId!,
|
|
Prefix = item.Profile!.Prefix!.Name,
|
|
FirstName = item.Profile!.FirstName!,
|
|
LastName = item.Profile!.LastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-14 - คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver14Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-14")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementReceive>()
|
|
//.Include(x => x.Prefix)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x!.Organization)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-15 - คำสั่งให้ช่วยราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver15Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-15")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementOfficer>()
|
|
//.Include(x => x.Profile)
|
|
//.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId!,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName!,
|
|
LastName = item.lastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-16 - คำสั่งส่งตัวกลับ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver16Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-16")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementRepatriation>()
|
|
//.Include(x => x.Profile)
|
|
//.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId!,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName!,
|
|
LastName = item.lastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-17 - คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver17Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-17")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<RetirementResign>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
|
|
.Where(x => x.Profile.ProfileType == "officer")
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.Profile!.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.Profile!.CitizenId!,
|
|
Prefix = item.Profile!.Prefix!.Name,
|
|
FirstName = item.Profile!.FirstName!,
|
|
LastName = item.Profile!.LastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-18 - คำสั่งให้ออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver18Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-18")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<RetirementOut>()
|
|
//.Include(x => x.Profile)
|
|
//.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.OrganizationId == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-19 - คำสั่งปลดออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver19Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-19")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<RetirementDischarge>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.Profile!.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.Profile!.CitizenId!,
|
|
Prefix = item.Profile!.Prefix!.Name,
|
|
FirstName = item.Profile!.FirstName!,
|
|
LastName = item.Profile!.LastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-19")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
Amount = 0,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-20 - คำสั่งไล่ออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver20Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-20")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<RetirementExpulsion>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.Profile!.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.Profile!.CitizenId!,
|
|
Prefix = item.Profile!.Prefix!.Name,
|
|
FirstName = item.Profile!.FirstName!,
|
|
LastName = item.Profile!.LastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-20")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
Amount = 0,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-21 - คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver21Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-21")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<OrganizationEmployeeProfile>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.Profile!.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.Profile!.CitizenId!,
|
|
Prefix = item.Profile!.Prefix!.Name,
|
|
FirstName = item.Profile!.FirstName!,
|
|
LastName = item.Profile!.LastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-22 - คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver22Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-22")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementAppointment>()
|
|
//.Include(x => x.CommandType)
|
|
//.Include(x => x.Prefix)
|
|
//.Include(x => x.OrganizationPosition)
|
|
//.ThenInclude(x => x!.Organization)
|
|
//.Include(x => x.Profile)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
//.Where(x => x.CommandType!.Id == command.CommandType!.Id)
|
|
.Where(x => x.type == "EMPLOYEE")
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-23 - คำสั่งให้ลูกจ้างออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver23Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-23")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<RetirementResign>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
|
|
.Where(x => x.Profile.ProfileType == "employee")
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.Profile!.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.Profile!.CitizenId!,
|
|
Prefix = item.Profile!.Prefix!.Name,
|
|
FirstName = item.Profile!.FirstName!,
|
|
LastName = item.Profile!.LastName!,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-24
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver24Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
var result = new List<CommandReceiver>();
|
|
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
|
|
|
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
|
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-24")
|
|
.Where(x => x.Command.Id != command.Id)
|
|
.Select(x => x.CitizenId)
|
|
.ToListAsync();
|
|
|
|
// 2. Query
|
|
var appointPeople = await _dbContext.Set<PlacementAppointment>()
|
|
//.Include(x => x.Profile)
|
|
//.ThenInclude(x => x.Prefix)
|
|
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
|
|
.Where(x => x.type == "EMPLOYEE")
|
|
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
|
|
.OrderBy(x => x.citizenId)
|
|
.ToListAsync();
|
|
|
|
// 3. Create new Record
|
|
var seq = 1;
|
|
foreach (var item in appointPeople)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.citizenId,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
RefPlacementProfileId = item.Id,
|
|
Amount = item.AmountOld,
|
|
};
|
|
seq++;
|
|
|
|
result.Add(receiver);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-25
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver25Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/stop/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-25")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-26
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver26Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/stop/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-26")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-27
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver27Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-27")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-28
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver28Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-28")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-29
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver29Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-29")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-30
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver30Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-30")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-31
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver31Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
|
|
|
|
var commandType = await _dbContext.Set<CommandType>()
|
|
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-31")
|
|
.FirstOrDefaultAsync();
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
if (commandType == null || commandType.Id != d.commandId)
|
|
continue;
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-32
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver32Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/reject/{command.ComplaintId}";
|
|
|
|
var response = new PassDisciplineResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Prefix)
|
|
.FirstOrDefaultAsync(x => x.Id == d.personId);
|
|
|
|
if (pf != null)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = pf.CitizenId!,
|
|
Prefix = pf.Prefix!.Name,
|
|
FirstName = pf.FirstName!,
|
|
LastName = pf.LastName!,
|
|
RefPlacementProfileId = pf.Id,
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-33
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver33Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/33/{command.SalaryPeriodId}";
|
|
|
|
var response = new PassSalaryResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = d.citizenId,
|
|
Prefix = d.prefix,
|
|
FirstName = d.firstName,
|
|
LastName = d.lastName,
|
|
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-34
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver34Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/34/{command.SalaryPeriodId}";
|
|
|
|
var response = new PassSalaryResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = d.citizenId,
|
|
Prefix = d.prefix,
|
|
FirstName = d.firstName,
|
|
LastName = d.lastName,
|
|
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-35
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver35Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/35/{command.SalaryPeriodId}";
|
|
|
|
var response = new PassSalaryResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = d.citizenId,
|
|
Prefix = d.prefix,
|
|
FirstName = d.firstName,
|
|
LastName = d.lastName,
|
|
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-36
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver36Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/36/{command.SalaryPeriodId}";
|
|
|
|
var response = new PassSalaryResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = d.citizenId,
|
|
Prefix = d.prefix,
|
|
FirstName = d.firstName,
|
|
LastName = d.lastName,
|
|
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-37
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task<List<CommandReceiver>> GetReceiver37Async(Command command, string token)
|
|
{
|
|
try
|
|
{
|
|
var resultData = new List<CommandReceiver>();
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/37/{command.SalaryPeriodId}";
|
|
|
|
var response = new PassSalaryResponse();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.SendAsync(req);
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
|
|
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
|
|
|
|
var seq = 1;
|
|
foreach (var d in response!.result)
|
|
{
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = d.citizenId,
|
|
Prefix = d.prefix,
|
|
FirstName = d.firstName,
|
|
LastName = d.lastName,
|
|
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
|
|
RefDisciplineId = d.id,
|
|
};
|
|
seq++;
|
|
|
|
resultData.Add(receiver);
|
|
}
|
|
}
|
|
|
|
return resultData;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Execute and Deploy "
|
|
|
|
private async Task ExecuteCommandByTypeAsync(Command command, string token = "")
|
|
{
|
|
switch (command.CommandType.CommandCode.Trim().ToUpper())
|
|
{
|
|
case "C-PM-01":
|
|
case "C-PM-02":
|
|
await ExecuteCommand01_02Async(command, token);
|
|
break;
|
|
case "C-PM-03":
|
|
await ExecuteCommand03Async(command);
|
|
break;
|
|
case "C-PM-04":
|
|
await ExecuteCommand04Async(command);
|
|
break;
|
|
case "C-PM-05":
|
|
await ExecuteCommand05Async(command);
|
|
break;
|
|
case "C-PM-06":
|
|
await ExecuteCommand06Async(command);
|
|
break;
|
|
case "C-PM-07":
|
|
await ExecuteCommand07Async(command);
|
|
break;
|
|
case "C-PM-08":
|
|
await ExecuteCommand08Async(command);
|
|
break;
|
|
case "C-PM-09":
|
|
await ExecuteCommand09Async(command);
|
|
break;
|
|
case "C-PM-10":
|
|
await ExecuteCommand10Async(command);
|
|
break;
|
|
case "C-PM-11":
|
|
await ExecuteCommand11Async(command);
|
|
break;
|
|
case "C-PM-12":
|
|
await ExecuteCommand12Async(command);
|
|
break;
|
|
case "C-PM-13":
|
|
await ExecuteCommand13Async(command);
|
|
break;
|
|
case "C-PM-14":
|
|
await ExecuteCommand14Async(command);
|
|
break;
|
|
case "C-PM-15":
|
|
await ExecuteCommand15Async(command);
|
|
break;
|
|
case "C-PM-16":
|
|
await ExecuteCommand16Async(command);
|
|
break;
|
|
case "C-PM-17":
|
|
await ExecuteCommand17Async(command);
|
|
break;
|
|
case "C-PM-18":
|
|
await ExecuteCommand18Async(command);
|
|
break;
|
|
case "C-PM-19":
|
|
await ExecuteCommand19Async(command, token);
|
|
break;
|
|
case "C-PM-20":
|
|
await ExecuteCommand20Async(command, token);
|
|
break;
|
|
case "C-PM-21":
|
|
await ExecuteCommand21Async(command);
|
|
break;
|
|
case "C-PM-22":
|
|
await ExecuteCommand22Async(command);
|
|
break;
|
|
case "C-PM-23":
|
|
await ExecuteCommand23Async(command);
|
|
break;
|
|
case "C-PM-24":
|
|
await ExecuteCommand24Async(command);
|
|
break;
|
|
case "C-PM-25":
|
|
await ExecuteCommand25Async(command, token);
|
|
break;
|
|
case "C-PM-26":
|
|
await ExecuteCommand26Async(command, token);
|
|
break;
|
|
case "C-PM-27":
|
|
await ExecuteCommand27Async(command, token);
|
|
break;
|
|
case "C-PM-28":
|
|
await ExecuteCommand28Async(command, token);
|
|
break;
|
|
case "C-PM-29":
|
|
await ExecuteCommand29Async(command, token);
|
|
break;
|
|
case "C-PM-30":
|
|
await ExecuteCommand30Async(command, token);
|
|
break;
|
|
case "C-PM-31":
|
|
await ExecuteCommand31Async(command, token);
|
|
break;
|
|
case "C-PM-32":
|
|
await ExecuteCommand32Async(command, token);
|
|
break;
|
|
case "C-PM-33":
|
|
await ExecuteCommand33Async(command, token);
|
|
break;
|
|
case "C-PM-34":
|
|
await ExecuteCommand34Async(command, token);
|
|
break;
|
|
case "C-PM-35":
|
|
await ExecuteCommand35Async(command, token);
|
|
break;
|
|
case "C-PM-36":
|
|
await ExecuteCommand36Async(command, token);
|
|
break;
|
|
case "C-PM-37":
|
|
await ExecuteCommand37Async(command, token);
|
|
break;
|
|
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้,
|
|
/// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand01_02Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
// create new profile
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
// query placement Profile
|
|
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.PlacementProfileDocs)
|
|
.ThenInclude(x => x.Document)
|
|
|
|
// .Include(x => x.Prefix)
|
|
// .Include(x => x.FatherPrefix)
|
|
// .Include(x => x.MotherPrefix)
|
|
// .Include(x => x.MarryPrefix)
|
|
// .Include(x => x.Gender)
|
|
// .Include(x => x.Relationship)
|
|
// .Include(x => x.BloodGroup)
|
|
// .Include(x => x.Religion)
|
|
|
|
// .Include(x => x.RegistSubDistrict)
|
|
// .Include(x => x.RegistDistrict)
|
|
// .Include(x => x.RegistProvince)
|
|
// .Include(x => x.CurrentSubDistrict)
|
|
// .Include(x => x.CurrentDistrict)
|
|
// .Include(x => x.CurrentProvince)
|
|
|
|
.Include(x => x.PositionPath)
|
|
.Include(x => x.PositionPathSide)
|
|
.Include(x => x.PositionType)
|
|
.Include(x => x.PositionLine)
|
|
.Include(x => x.PositionLevel)
|
|
.Include(x => x.PositionNumber)
|
|
|
|
.Include(x => x.PlacementCertificates)
|
|
.Include(x => x.PlacementEducations)
|
|
.ThenInclude(x => x.EducationLevel)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.Organization)
|
|
.ThenInclude(x => x.OrganizationShortName)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionExecutive)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionLine)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.Organization)
|
|
.ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception("Invalid placement profile: " + recv.RefPlacementProfileId);
|
|
|
|
// ใส่ฟีลจากข้อมูล
|
|
////var profile = new Profile
|
|
////{
|
|
//// ProfileType = "officer",
|
|
//// CitizenId = placementProfile.CitizenId,
|
|
//// Prefix = placementProfile.Prefix,
|
|
//// FirstName = placementProfile.Firstname,
|
|
//// LastName = placementProfile.Lastname,
|
|
//// Gender = placementProfile.Gender,
|
|
//// Nationality = placementProfile.Nationality,
|
|
//// BirthDate = placementProfile.DateOfBirth == null ? DateTime.MinValue : placementProfile.DateOfBirth.Value,
|
|
//// RelationshipId = placementProfile.Relationship == null ? Guid.Empty : placementProfile.Relationship!.Id,
|
|
//// TelephoneNumber = placementProfile.Telephone,
|
|
//// Race = placementProfile.Race,
|
|
//// ReligionId = placementProfile.Religion == null ? Guid.Empty : placementProfile.Religion.Id,
|
|
//// BloodGroupId = placementProfile.BloodGroup == null ? Guid.Empty : placementProfile.BloodGroup.Id,
|
|
|
|
//// DateAppoint = placementProfile.RecruitDate == null ? null : placementProfile.RecruitDate.Value,
|
|
//// DateStart = placementProfile.RecruitDate == null ? null : placementProfile.RecruitDate.Value,
|
|
|
|
//// RegistrationAddress = placementProfile.RegistAddress,
|
|
//// RegistrationSubDistrictId = placementProfile.RegistSubDistrict == null ? Guid.Empty : placementProfile.RegistSubDistrict!.Id,
|
|
//// RegistrationDistrictId = placementProfile.RegistDistrict == null ? Guid.Empty : placementProfile.RegistDistrict!.Id,
|
|
//// RegistrationProvinceId = placementProfile.RegistProvince == null ? Guid.Empty : placementProfile.RegistProvince!.Id,
|
|
//// RegistrationZipCode = placementProfile.RegistSubDistrict == null ? null : placementProfile.RegistSubDistrict!.ZipCode,
|
|
|
|
//// CurrentAddress = placementProfile.CurrentAddress,
|
|
//// CurrentSubDistrictId = placementProfile.CurrentSubDistrict == null ? Guid.Empty : placementProfile.CurrentSubDistrict!.Id,
|
|
//// CurrentDistrictId = placementProfile.CurrentDistrict == null ? Guid.Empty : placementProfile.CurrentDistrict!.Id,
|
|
//// CurrentProvinceId = placementProfile.CurrentProvince == null ? Guid.Empty : placementProfile.CurrentProvince!.Id,
|
|
//// CurrentZipCode = placementProfile.CurrentSubDistrict == null ? null : placementProfile.CurrentSubDistrict!.ZipCode,
|
|
|
|
//// FatherPrefixId = placementProfile.FatherPrefix == null ? null : placementProfile.FatherPrefix.Id,
|
|
//// FatherFirstName = placementProfile.FatherFirstName,
|
|
//// FatherLastName = placementProfile.FatherLastName,
|
|
//// FatherCareer = placementProfile.FatherOccupation,
|
|
//// FatherLive = true,
|
|
|
|
//// MotherPrefixId = placementProfile.MotherPrefix == null ? null : placementProfile.MotherPrefix.Id,
|
|
//// MotherFirstName = placementProfile.MotherFirstName,
|
|
//// MotherLastName = placementProfile.MotherLastName,
|
|
//// MotherCareer = placementProfile.MotherOccupation,
|
|
//// MotherLive = true,
|
|
|
|
//// Couple = placementProfile.MarryPrefix == null ? false : true,
|
|
//// CouplePrefixId = placementProfile.MarryPrefix == null ? null : placementProfile.MarryPrefix.Id,
|
|
//// CoupleFirstName = placementProfile.MarryFirstName,
|
|
//// CoupleLastName = placementProfile.MarryLastName,
|
|
//// CoupleCareer = placementProfile.MarryOccupation,
|
|
//// CoupleLive = placementProfile.MarryPrefix == null ? false : true,
|
|
|
|
//// Position = placementProfile.PositionPath,
|
|
//// PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id,
|
|
//// PositionType = placementProfile.PositionType,
|
|
//// PositionLevel = placementProfile.PositionLevel,
|
|
//// //PositionEmployeeLevel = placementProfile.PositionLevel,
|
|
//// PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id,
|
|
//// PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name,
|
|
//// PosNo = placementProfile.OrganizationPosition!.PositionNumber,
|
|
|
|
//// IsVerified = true,
|
|
//// IsProbation = true,
|
|
//// Physical = "",
|
|
//// Ability = "",
|
|
//// AvatarRef = "",
|
|
//// GovAgeAbsent = 0,
|
|
//// GovAgePlus = 0,
|
|
//// EntryStatus = "",
|
|
//// IsTransfer = false,
|
|
//// IsActive = true,
|
|
//// IsLeave = false,
|
|
//// VerifiedUser = "",
|
|
//// FirstNameOld = "",
|
|
//// LastNameOld = "",
|
|
//// // CoupleLive = false,
|
|
//// // FatherLive = false,
|
|
//// // MotherLive = false,
|
|
//// CreatedUser = "",
|
|
|
|
//// Educations = new List<ProfileEducation>(),
|
|
//// Certificates = new List<ProfileCertificate>(),
|
|
//// Salaries = new List<ProfileSalary>(),
|
|
//// CreatedAt = DateTime.Now,
|
|
//// CreatedFullName = FullName ?? "System Administrator",
|
|
//// CreatedUserId = UserId ?? "",
|
|
//// LastUpdatedAt = DateTime.Now,
|
|
//// LastUpdateFullName = FullName ?? "System Administrator",
|
|
//// LastUpdateUserId = UserId ?? "",
|
|
|
|
//// // organization
|
|
//// OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
//// OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name,
|
|
//// OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id,
|
|
//// OrganizationOrganization = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Name,
|
|
//// OcId = placementProfile.OrganizationPosition!.Organization!.Id,
|
|
//// Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"),
|
|
|
|
////};
|
|
|
|
/*ข้อมูล Profile ใหม่*/
|
|
var apiUrl = $"{_configuration["API"]}/org/profile/all";
|
|
var profileId = string.Empty;
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
|
var _res = await client.PostAsJsonAsync(apiUrl, new
|
|
{
|
|
rank = string.Empty,
|
|
prefix = placementProfile.Prefix == null ? string.Empty : placementProfile.Prefix,
|
|
firstName = placementProfile.Firstname == null ? string.Empty : placementProfile.Firstname,
|
|
lastName = placementProfile.Lastname == null ? string.Empty : placementProfile.Lastname,
|
|
citizenId = placementProfile.CitizenId == null ? string.Empty : placementProfile.CitizenId,
|
|
position = placementProfile.positionName == null ? string.Empty : placementProfile.positionName,
|
|
posLevelId = placementProfile.posLevelId == null ? string.Empty : placementProfile.posLevelId,
|
|
posTypeId = placementProfile.posTypeId == null ? string.Empty : placementProfile.posTypeId,
|
|
email = placementProfile.Email == null ? string.Empty : placementProfile.Email,
|
|
phone = placementProfile.MobilePhone == null ? string.Empty : placementProfile.MobilePhone,
|
|
keycloak = string.Empty,
|
|
isProbation = false,
|
|
isLeave = false,
|
|
dateRetire = (DateTime?)null,
|
|
dateAppoint = placementProfile.RecruitDate == null ? (DateTime?)null : placementProfile.RecruitDate,
|
|
dateStart = (DateTime?)null,
|
|
govAgeAbsent = 0,
|
|
govAgePlus = 0,
|
|
birthDate = placementProfile.DateOfBirth == null ? (DateTime?)null : placementProfile.DateOfBirth,
|
|
reasonSameDate = (DateTime?)null,
|
|
ethnicity = placementProfile.Race == null ? string.Empty : placementProfile.Race,
|
|
telephoneNumber = placementProfile.Telephone == null ? string.Empty : placementProfile.Telephone,
|
|
nationality = placementProfile.Nationality == null ? string.Empty : placementProfile.Nationality,
|
|
gender = placementProfile.Gender == null ? string.Empty : placementProfile.Gender,
|
|
relationship = placementProfile.Relationship == null ? string.Empty : placementProfile.Relationship,
|
|
religion = placementProfile.Religion == null ? string.Empty : placementProfile.Religion,
|
|
bloodGroup = string.Empty,
|
|
registrationAddress = placementProfile.RegistAddress == null ? string.Empty : placementProfile.RegistAddress,
|
|
registrationProvinceId = (String?)null,
|
|
registrationDistrictId = (String?)null,
|
|
registrationSubDistrictId = (String?)null,
|
|
registrationZipCode = placementProfile.RegistZipCode == null ? string.Empty : placementProfile.RegistZipCode,
|
|
currentAddress = placementProfile.CurrentAddress == null ? string.Empty : placementProfile.CurrentAddress,
|
|
currentProvinceId = (String?)null,
|
|
currentDistrictId = (String?)null,
|
|
currentSubDistrictId = (String?)null,
|
|
currentZipCode = placementProfile.CurrentZipCode == null ? string.Empty : placementProfile.CurrentZipCode,
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
profileId = JsonConvert.DeserializeObject<PlacementProfileId>(_result).result;
|
|
}
|
|
|
|
// add profile education
|
|
////foreach (var edu in placementProfile.PlacementEducations)
|
|
////{
|
|
//// profile.Educations.Add(new ProfileEducation
|
|
//// {
|
|
//// Country = edu.Country,
|
|
//// Degree = edu.Degree,
|
|
//// Duration = edu.Duration,
|
|
//// DurationYear = edu.DurationYear == null ? 0 : edu.DurationYear.Value,
|
|
//// EducationLevelId = edu.EducationLevel == null ? Guid.Empty : edu.EducationLevel.Id,
|
|
//// EducationLevel = edu.EducationLevel == null ? "" : edu.EducationLevel.Name,
|
|
//// StartDate = edu.StartDate,
|
|
//// EndDate = edu.EndDate,
|
|
//// Field = edu.Field,
|
|
//// FinishDate = edu.FinishDate,
|
|
//// FundName = edu.FundName,
|
|
//// Gpa = edu.Gpa,
|
|
//// Institute = edu.Institute,
|
|
//// IsActive = true,
|
|
//// CreatedAt = DateTime.Now,
|
|
//// CreatedFullName = FullName ?? "System Administrator",
|
|
//// CreatedUserId = UserId ?? "",
|
|
//// LastUpdatedAt = DateTime.Now,
|
|
//// LastUpdateFullName = FullName ?? "System Administrator",
|
|
//// LastUpdateUserId = UserId ?? "",
|
|
//// });
|
|
////}
|
|
|
|
if (placementProfile.PlacementEducations != null)
|
|
{
|
|
var apiUrlEdu = $"{_configuration["API"]}/org/profile/educations";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
foreach (var edu in placementProfile.PlacementEducations)
|
|
{
|
|
var _res = await client.PostAsJsonAsync(apiUrlEdu, new
|
|
{
|
|
profileId = profileId,
|
|
country = edu.Country == null ? string.Empty : edu.Country,
|
|
degree = edu.Degree == null ? string.Empty : edu.Degree,
|
|
duration = edu.Duration == null ? string.Empty : edu.Duration,
|
|
durationYear = edu.DurationYear == null ? 0 : edu.DurationYear,
|
|
field = edu.Field == null ? string.Empty : edu.Field,
|
|
finishDate = edu.FinishDate == null ? (DateTime?)null : edu.FinishDate,
|
|
fundName = edu.FundName == null ? string.Empty : edu.FundName,
|
|
gpa = edu.Gpa == null ? string.Empty : edu.Gpa,
|
|
institute = edu.Institute == null ? string.Empty : edu.Institute,
|
|
other = edu.Other == null ? string.Empty : edu.Other,
|
|
startDate = edu.StartDate == null ? (DateTime?)null : edu.StartDate,
|
|
endDate = edu.EndDate == null ? (DateTime?)null : edu.EndDate,
|
|
educationLevel = edu.EducationLevel == null ? string.Empty : edu.EducationLevel.Name,
|
|
educationLevelId = string.Empty,
|
|
positionPath = edu.PositionPath == null ? null : edu.PositionPath,
|
|
positionPathId = string.Empty,
|
|
isDate = edu.IsDate,
|
|
isEducation = edu.IsEducation,
|
|
note = string.Empty,
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
}
|
|
}
|
|
}
|
|
|
|
// add profile certificate
|
|
////foreach (var cert in placementProfile.PlacementCertificates)
|
|
////{
|
|
//// profile.Certificates.Add(new ProfileCertificate
|
|
//// {
|
|
//// CertificateNo = cert.CertificateNo,
|
|
//// IssueDate = cert.IssueDate,
|
|
//// Issuer = cert.Issuer,
|
|
//// CertificateType = cert.CertificateType,
|
|
//// ExpireDate = cert.ExpireDate,
|
|
//// IsActive = true,
|
|
//// CreatedAt = DateTime.Now,
|
|
//// CreatedFullName = FullName ?? "System Administrator",
|
|
//// CreatedUserId = UserId ?? "",
|
|
//// LastUpdatedAt = DateTime.Now,
|
|
//// LastUpdateFullName = FullName ?? "System Administrator",
|
|
//// LastUpdateUserId = UserId ?? "",
|
|
//// });
|
|
////}
|
|
|
|
if (placementProfile.PlacementCertificates != null)
|
|
{
|
|
var apiUrlCer = $"{_configuration["API"]}/org/profile/certificate";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
foreach (var cer in placementProfile.PlacementCertificates)
|
|
{
|
|
var _res = await client.PostAsJsonAsync(apiUrlCer, new
|
|
{
|
|
profileId = profileId,
|
|
expireDate = cer.ExpireDate == null ? (DateTime?)null : cer.ExpireDate,
|
|
issueDate = cer.IssueDate == null ? (DateTime?)null : cer.IssueDate,
|
|
certificateNo = cer.CertificateNo == null ? string.Empty : cer.CertificateNo,
|
|
certificateType = cer.CertificateType == null ? string.Empty : cer.CertificateType,
|
|
issuer = cer.Issuer == null ? string.Empty : cer.Issuer,
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
}
|
|
}
|
|
}
|
|
|
|
// add profile document
|
|
////foreach (var doc in placementProfile.PlacementProfileDocs)
|
|
////{
|
|
//// profile.Papers.Add(new ProfilePaper
|
|
//// {
|
|
//// CategoryName = "Profile Documents",
|
|
//// Document = doc.Document,
|
|
//// Detail = doc.Document.FileName,
|
|
//// CreatedAt = DateTime.Now,
|
|
//// CreatedFullName = FullName ?? "System Administrator",
|
|
//// CreatedUserId = UserId ?? "",
|
|
//// LastUpdatedAt = DateTime.Now,
|
|
//// LastUpdateFullName = FullName ?? "System Administrator",
|
|
//// LastUpdateUserId = UserId ?? "",
|
|
//// });
|
|
////}
|
|
|
|
|
|
// add profile salary
|
|
|
|
////var oc = _dbContext.Set<OrganizationEntity>()
|
|
//// .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id);
|
|
|
|
////var position = placementProfile.PositionPath;
|
|
|
|
////var positionNumber = placementProfile.PositionNumber;
|
|
|
|
////var positionType = placementProfile.PositionType;
|
|
|
|
////var positionLevel = placementProfile.PositionLevel;
|
|
|
|
|
|
////var salary = new ProfileSalary
|
|
////{
|
|
//// Order = 1,
|
|
//// Date = command.CommandAffectDate,
|
|
//// Amount = placementProfile.Amount == null ? 0 : placementProfile.Amount,
|
|
//// PositionSalaryAmount = placementProfile.PositionSalaryAmount == null ? 0 : placementProfile.PositionSalaryAmount,
|
|
//// MouthSalaryAmount = placementProfile.MouthSalaryAmount == null ? 0 : placementProfile.MouthSalaryAmount,
|
|
//// SalaryClass = "",
|
|
//// SalaryRef = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้วุฒิ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
//// OcId = oc == null ? Guid.Empty : oc.Id,
|
|
|
|
//// PositionId = position!.Id,
|
|
|
|
//// PositionLevel = placementProfile.PositionLevel,
|
|
//// PositionLineId = placementProfile.PositionLine!.Id,
|
|
//// PositionTypeId = placementProfile.PositionType!.Id,
|
|
//// OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
//// PosNoId = positionNumber!.Id,
|
|
|
|
//// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
//// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
//// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
//// PositionEmployeeGroupId = null,
|
|
//// PositionEmployeeLevelId = null,
|
|
//// PositionEmployeePositionId = null,
|
|
//// PositionEmployeePositionSideId = null,
|
|
//// PosNoEmployee = "",
|
|
|
|
|
|
//// PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
//// PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
//// PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
//// IsActive = true,
|
|
//// CreatedAt = DateTime.Now,
|
|
//// CreatedFullName = FullName ?? "System Administrator",
|
|
//// CreatedUserId = UserId ?? "",
|
|
//// LastUpdatedAt = DateTime.Now,
|
|
//// LastUpdateFullName = FullName ?? "System Administrator",
|
|
//// LastUpdateUserId = UserId ?? "",
|
|
|
|
////};
|
|
|
|
var apiUrlSalary = $"{_configuration["API"]}/org/profile/salary";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
|
|
{
|
|
profileId = profileId,
|
|
date = command.CommandAffectDate == null ? (DateTime?)null : command.CommandAffectDate,
|
|
amount = placementProfile.Amount == null ? null : placementProfile.Amount,
|
|
positionSalaryAmount = placementProfile.PositionSalaryAmount == null ? null : placementProfile.PositionSalaryAmount,
|
|
mouthSalaryAmount = placementProfile.MouthSalaryAmount == null ? null : placementProfile.MouthSalaryAmount,
|
|
posNo = placementProfile.PosNumber == null ? string.Empty : placementProfile.PosNumber.ToString(),
|
|
position = placementProfile.positionName == null ? string.Empty : placementProfile.positionName,
|
|
positionLine = string.Empty,
|
|
positionPathSide = string.Empty,
|
|
positionExecutive = string.Empty,
|
|
positionType = placementProfile.posTypeName == null ? string.Empty : placementProfile.posTypeName,
|
|
positionLevel = placementProfile.PositionLevel == null ? string.Empty : placementProfile.PositionLevel.Name,
|
|
refCommandNo = string.Empty,
|
|
templateDoc = string.Empty,
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
}
|
|
|
|
|
|
//if (placementProfile.PositionPathSide! != null)
|
|
//{
|
|
// salary.PositionPathSideId = placementProfile.PositionPathSide!.Id;
|
|
//}
|
|
//else
|
|
|
|
//if (placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! != null)
|
|
//{
|
|
// salary.PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id;
|
|
//}
|
|
|
|
//if (placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! != null)
|
|
//{
|
|
// salary.PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id;
|
|
//}
|
|
|
|
// add profile position
|
|
////var profilePosition = new ProfilePosition
|
|
////{
|
|
//// Profile = profile,
|
|
//// OrganizationPosition = placementProfile.OrganizationPosition,
|
|
//// IsActive = true,
|
|
//// IsPublished = true,
|
|
////};
|
|
////_dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
|
|
////profile.Salaries.Add(salary);
|
|
|
|
////_dbContext.Set<Profile>().Add(profile);
|
|
|
|
// update placementstatus
|
|
placementProfile.PlacementStatus = "CONTAIN";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
////// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
////// Send noti inbox and email
|
|
////var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
////var body = $"คุณได้รับรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
////_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
////var inbox = new Inbox
|
|
////{
|
|
//// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
//// Body = $"คุณได้รับรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
//// ReceiverUserId = profile.Id,
|
|
//// Payload = payload_str,
|
|
////};
|
|
////_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
////var noti = new Notification
|
|
////{
|
|
//// Body = $"คุณได้รับรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
//// ReceiverUserId = profile.Id,
|
|
//// Type = "LINK",
|
|
//// Payload = payload_str,
|
|
////};
|
|
////_dbContext.Set<Notification>().Add(noti);
|
|
////await _dbContext.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
//// send cc noti inbox
|
|
////foreach (var cc in command.Deployments)
|
|
////{
|
|
//// var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
//// if (pf != null)
|
|
//// {
|
|
//// if (cc.IsSendInbox)
|
|
//// {
|
|
//// var inbox = new Inbox
|
|
//// {
|
|
//// Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
//// Body = $"คำสั่งบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
//// ReceiverUserId = pf.Id,
|
|
//// Payload = payload_str,
|
|
//// };
|
|
//// _dbContext.Set<Inbox>().Add(inbox);
|
|
//// }
|
|
|
|
//// if (cc.IsSendMail)
|
|
//// {
|
|
//// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
//// // Send noti inbox and email
|
|
//// var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
//// var body = $"คำสั่งบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
//// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
//// }
|
|
|
|
|
|
//// var noti = new Notification
|
|
//// {
|
|
//// Body = $"คำสั่งบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
//// ReceiverUserId = pf.Id,
|
|
//// Type = "LINK",
|
|
//// Payload = payload_str,
|
|
//// };
|
|
//// _dbContext.Set<Notification>().Add(noti);
|
|
//// }
|
|
////}
|
|
|
|
////// change command status
|
|
////var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
////command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
////await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand03Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.PlacementProfileDocs)
|
|
.ThenInclude(x => x.Document)
|
|
|
|
// .Include(x => x.Prefix)
|
|
// .Include(x => x.FatherPrefix)
|
|
// .Include(x => x.MotherPrefix)
|
|
// .Include(x => x.MarryPrefix)
|
|
// .Include(x => x.Gender)
|
|
// .Include(x => x.Relationship)
|
|
// .Include(x => x.BloodGroup)
|
|
// .Include(x => x.Religion)
|
|
|
|
// .Include(x => x.RegistSubDistrict)
|
|
// .Include(x => x.RegistDistrict)
|
|
// .Include(x => x.RegistProvince)
|
|
// .Include(x => x.CurrentSubDistrict)
|
|
// .Include(x => x.CurrentDistrict)
|
|
// .Include(x => x.CurrentProvince)
|
|
|
|
.Include(x => x.PositionPath)
|
|
.Include(x => x.PositionPathSide)
|
|
.Include(x => x.PositionType)
|
|
.Include(x => x.PositionLine)
|
|
.Include(x => x.PositionLevel)
|
|
.Include(x => x.PositionNumber)
|
|
|
|
.Include(x => x.PlacementCertificates)
|
|
.Include(x => x.PlacementEducations)
|
|
.ThenInclude(x => x.EducationLevel)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.Organization)
|
|
.ThenInclude(x => x.OrganizationShortName)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionExecutive)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionLine)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.Organization)
|
|
.ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
var profile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.FirstOrDefaultAsync(x => x.CitizenId == placementProfile.CitizenId);
|
|
if (profile != null)
|
|
{
|
|
profile.Position = placementProfile.PositionPath;
|
|
profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id;
|
|
profile.PositionType = placementProfile.PositionType;
|
|
profile.PositionLevel = placementProfile.PositionLevel;
|
|
|
|
profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id;
|
|
profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name;
|
|
profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber;
|
|
|
|
// organization
|
|
profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id;
|
|
profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name;
|
|
profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id;
|
|
profile.OrganizationOrganization = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Name;
|
|
profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id;
|
|
profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/");
|
|
}
|
|
|
|
var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var oc = _dbContext.Set<OrganizationEntity>()
|
|
.FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id);
|
|
|
|
var position = placementProfile.PositionPath;
|
|
|
|
var positionNumber = placementProfile.PositionNumber;
|
|
|
|
var positionType = placementProfile.PositionType;
|
|
|
|
var positionLevel = placementProfile.PositionLevel;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
|
|
Amount = placementProfile.Amount == null ? 0 : placementProfile.Amount,
|
|
PositionSalaryAmount = placementProfile.PositionSalaryAmount == null ? 0 : placementProfile.PositionSalaryAmount,
|
|
MouthSalaryAmount = placementProfile.MouthSalaryAmount == null ? 0 : placementProfile.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งแต่งตั้ง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = oc == null ? Guid.Empty : oc.Id,
|
|
|
|
PositionId = position!.Id,
|
|
|
|
PositionLevel = placementProfile.PositionLevel,
|
|
PositionLineId = placementProfile.PositionLine!.Id,
|
|
PositionTypeId = placementProfile.PositionType!.Id,
|
|
OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
PosNoId = positionNumber!.Id,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
profile.Salaries.Add(salary);
|
|
|
|
// change profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == profile.Id);
|
|
if (profilePosition == null)
|
|
{
|
|
profilePosition = new ProfilePosition
|
|
{
|
|
Profile = profile,
|
|
OrganizationPosition = placementProfile.OrganizationPosition,
|
|
IsActive = true,
|
|
IsPublished = true,
|
|
};
|
|
_dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
}
|
|
else
|
|
{
|
|
profilePosition.OrganizationPosition = placementProfile.OrganizationPosition;
|
|
//_dbContext.Attatch(profilePosition);
|
|
}
|
|
|
|
// update placementstatus
|
|
placementProfile.PlacementStatus = "CONTAIN";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = profile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = profile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-04 - คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand04Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.PlacementProfileDocs)
|
|
.ThenInclude(x => x.Document)
|
|
|
|
|
|
// .Include(x => x.Prefix)
|
|
// .Include(x => x.FatherPrefix)
|
|
// .Include(x => x.MotherPrefix)
|
|
// .Include(x => x.MarryPrefix)
|
|
// .Include(x => x.Gender)
|
|
// .Include(x => x.Relationship)
|
|
// .Include(x => x.BloodGroup)
|
|
// .Include(x => x.Religion)
|
|
|
|
// .Include(x => x.RegistSubDistrict)
|
|
// .Include(x => x.RegistDistrict)
|
|
// .Include(x => x.RegistProvince)
|
|
// .Include(x => x.CurrentSubDistrict)
|
|
// .Include(x => x.CurrentDistrict)
|
|
// .Include(x => x.CurrentProvince)
|
|
|
|
.Include(x => x.PositionPath)
|
|
.Include(x => x.PositionPathSide)
|
|
.Include(x => x.PositionType)
|
|
.Include(x => x.PositionLine)
|
|
.Include(x => x.PositionLevel)
|
|
.Include(x => x.PositionNumber)
|
|
|
|
.Include(x => x.PlacementCertificates)
|
|
.Include(x => x.PlacementEducations)
|
|
.ThenInclude(x => x.EducationLevel)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.Organization)
|
|
.ThenInclude(x => x.OrganizationShortName)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionExecutive)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.PositionMaster)
|
|
.ThenInclude(x => x.PositionLine)
|
|
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.Organization)
|
|
.ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
var profile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.FirstOrDefaultAsync(x => x.CitizenId == placementProfile.CitizenId);
|
|
if (profile != null)
|
|
{
|
|
profile.Position = placementProfile.PositionPath;
|
|
profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id;
|
|
profile.PositionType = placementProfile.PositionType;
|
|
profile.PositionLevel = placementProfile.PositionLevel;
|
|
|
|
profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id;
|
|
profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name;
|
|
profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber;
|
|
|
|
// organization
|
|
profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id;
|
|
profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name;
|
|
profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id;
|
|
profile.OrganizationOrganization = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Name;
|
|
profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id;
|
|
profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/");
|
|
}
|
|
|
|
var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var oc = _dbContext.Set<OrganizationEntity>()
|
|
.FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id);
|
|
|
|
var position = placementProfile.PositionPath;
|
|
|
|
var positionNumber = placementProfile.PositionNumber;
|
|
|
|
var positionType = placementProfile.PositionType;
|
|
|
|
var positionLevel = placementProfile.PositionLevel;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
|
|
Amount = placementProfile.Amount == null ? 0 : placementProfile.Amount,
|
|
PositionSalaryAmount = placementProfile.PositionSalaryAmount == null ? 0 : placementProfile.PositionSalaryAmount,
|
|
MouthSalaryAmount = placementProfile.MouthSalaryAmount == null ? 0 : placementProfile.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งย้าย คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = oc == null ? Guid.Empty : oc.Id,
|
|
|
|
PositionId = position!.Id,
|
|
|
|
PositionLevel = placementProfile.PositionLevel,
|
|
PositionLineId = placementProfile.PositionLine!.Id,
|
|
PositionTypeId = placementProfile.PositionType!.Id,
|
|
OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
PosNoId = positionNumber!.Id,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
profile.Salaries.Add(salary);
|
|
|
|
// change profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == profile.Id);
|
|
if (profilePosition == null)
|
|
{
|
|
profilePosition = new ProfilePosition
|
|
{
|
|
Profile = profile,
|
|
OrganizationPosition = placementProfile.OrganizationPosition,
|
|
IsActive = true,
|
|
IsPublished = true,
|
|
};
|
|
_dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
}
|
|
else
|
|
{
|
|
profilePosition.OrganizationPosition = placementProfile.OrganizationPosition;
|
|
//_dbContext.Attatch(profilePosition);
|
|
}
|
|
|
|
// update placementstatus
|
|
placementProfile.PlacementStatus = "CONTAIN";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = profile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = profile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-05 - คำสั่งแต่งตั้ง
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand05Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var placementProfile = await _dbContext.Set<PlacementAppointment>()
|
|
//.Include(x => x.Profile)
|
|
//.ThenInclude(x => x.Salaries)
|
|
|
|
// .Include(x => x.PositionPath)
|
|
// .Include(x => x.PositionPathSide)
|
|
// .Include(x => x.PositionType)
|
|
// .Include(x => x.PositionLine)
|
|
// .Include(x => x.PositionLevel)
|
|
// .Include(x => x.PositionNumber)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationShortName)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutive)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionLine)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
// var profile = placementProfile.Profile;
|
|
// if (profile != null)
|
|
// {
|
|
// profile.Position = placementProfile.PositionPath;
|
|
// profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id;
|
|
// profile.PositionType = placementProfile.PositionType;
|
|
// profile.PositionLevel = placementProfile.PositionLevel;
|
|
|
|
// profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id;
|
|
// profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name;
|
|
// profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber;
|
|
|
|
// // organization
|
|
// profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id;
|
|
// profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name;
|
|
// profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id;
|
|
// profile.OrganizationOrganization = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Name;
|
|
// profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id;
|
|
// profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/");
|
|
// }
|
|
|
|
// var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var oc = _dbContext.Set<OrganizationEntity>()
|
|
// .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id);
|
|
|
|
// var position = placementProfile.PositionPath;
|
|
|
|
// var positionNumber = placementProfile.PositionNumber;
|
|
|
|
// var positionType = placementProfile.PositionType;
|
|
|
|
// var positionLevel = placementProfile.PositionLevel;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
|
|
// Amount = recv.Amount == null ? 0 : recv.Amount,
|
|
// PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount,
|
|
// MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งแต่งตั้ง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = oc == null ? Guid.Empty : oc.Id,
|
|
|
|
// PositionId = position!.Id,
|
|
|
|
// PositionLevel = placementProfile.PositionLevel,
|
|
// PositionLineId = placementProfile.PositionLine!.Id,
|
|
// PositionTypeId = placementProfile.PositionType!.Id,
|
|
// OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
// PosNoId = positionNumber!.Id,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
// PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
// PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// profile.Salaries.Add(salary);
|
|
|
|
// // change profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == profile.Id);
|
|
// if (profilePosition == null)
|
|
// {
|
|
// profilePosition = new ProfilePosition
|
|
// {
|
|
// Profile = profile,
|
|
// OrganizationPosition = placementProfile.OrganizationPosition,
|
|
// IsActive = true,
|
|
// IsPublished = true,
|
|
// };
|
|
// _dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
// }
|
|
// else
|
|
// {
|
|
// profilePosition.OrganizationPosition = placementProfile.OrganizationPosition;
|
|
// //_dbContext.Attatch(profilePosition);
|
|
// }
|
|
|
|
// update placementstatus
|
|
placementProfile.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-06 - คำสั่งเลื่อน
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand06Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var placementProfile = await _dbContext.Set<PlacementAppointment>()
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.Salaries)
|
|
|
|
// .Include(x => x.PositionPath)
|
|
// .Include(x => x.PositionPathSide)
|
|
// .Include(x => x.PositionType)
|
|
// .Include(x => x.PositionLine)
|
|
// .Include(x => x.PositionLevel)
|
|
// .Include(x => x.PositionNumber)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationShortName)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutive)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionLine)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
// var profile = placementProfile.Profile;
|
|
// if (profile != null)
|
|
// {
|
|
// profile.Position = placementProfile.PositionPath;
|
|
// profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id;
|
|
// profile.PositionType = placementProfile.PositionType;
|
|
// profile.PositionLevel = placementProfile.PositionLevel;
|
|
|
|
// profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id;
|
|
// profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name;
|
|
// profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber;
|
|
|
|
// // organization
|
|
// profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id;
|
|
// profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name;
|
|
// profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id;
|
|
// profile.OrganizationOrganization = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Name;
|
|
// profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id;
|
|
// profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/");
|
|
// }
|
|
|
|
// var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var oc = _dbContext.Set<OrganizationEntity>()
|
|
// .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id);
|
|
|
|
// var position = placementProfile.PositionPath;
|
|
|
|
// var positionNumber = placementProfile.PositionNumber;
|
|
|
|
// var positionType = placementProfile.PositionType;
|
|
|
|
// var positionLevel = placementProfile.PositionLevel;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
|
|
// Amount = recv.Amount == null ? 0 : recv.Amount,
|
|
// PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount,
|
|
// MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งเลื่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = oc == null ? Guid.Empty : oc.Id,
|
|
|
|
// PositionId = position!.Id,
|
|
|
|
// PositionLevel = placementProfile.PositionLevel,
|
|
// PositionLineId = placementProfile.PositionLine!.Id,
|
|
// PositionTypeId = placementProfile.PositionType!.Id,
|
|
// OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
// PosNoId = positionNumber!.Id,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
// PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
// PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// profile.Salaries.Add(salary);
|
|
|
|
// // change profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == profile.Id);
|
|
// if (profilePosition == null)
|
|
// {
|
|
// profilePosition = new ProfilePosition
|
|
// {
|
|
// Profile = profile,
|
|
// OrganizationPosition = placementProfile.OrganizationPosition,
|
|
// IsActive = true,
|
|
// IsPublished = true,
|
|
// };
|
|
// _dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
// }
|
|
// else
|
|
// {
|
|
// profilePosition.OrganizationPosition = placementProfile.OrganizationPosition;
|
|
// //_dbContext.Attatch(profilePosition);
|
|
// }
|
|
|
|
// update placementstatus
|
|
placementProfile.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-07 - คำสั่งย้าย
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand07Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var placementProfile = await _dbContext.Set<PlacementAppointment>()
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.Salaries)
|
|
|
|
// .Include(x => x.PositionPath)
|
|
// .Include(x => x.PositionPathSide)
|
|
// .Include(x => x.PositionType)
|
|
// .Include(x => x.PositionLine)
|
|
// .Include(x => x.PositionLevel)
|
|
// .Include(x => x.PositionNumber)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationShortName)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutive)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionLine)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
// var profile = placementProfile.Profile;
|
|
// if (profile != null)
|
|
// {
|
|
// profile.Position = placementProfile.PositionPath;
|
|
// profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id;
|
|
// profile.PositionType = placementProfile.PositionType;
|
|
// profile.PositionLevel = placementProfile.PositionLevel;
|
|
|
|
// profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id;
|
|
// profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name;
|
|
// profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber;
|
|
|
|
// // organization
|
|
// profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id;
|
|
// profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name;
|
|
// profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id;
|
|
// profile.OrganizationOrganization = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Name;
|
|
// profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id;
|
|
// profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/");
|
|
// }
|
|
|
|
// var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var oc = _dbContext.Set<OrganizationEntity>()
|
|
// .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id);
|
|
|
|
// var position = placementProfile.PositionPath;
|
|
|
|
// var positionNumber = placementProfile.PositionNumber;
|
|
|
|
// var positionType = placementProfile.PositionType;
|
|
|
|
// var positionLevel = placementProfile.PositionLevel;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
|
|
// Amount = recv.Amount == null ? 0 : recv.Amount,
|
|
// PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount,
|
|
// MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งย้าย คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = oc == null ? Guid.Empty : oc.Id,
|
|
|
|
// PositionId = position!.Id,
|
|
|
|
// PositionLevel = placementProfile.PositionLevel,
|
|
// PositionLineId = placementProfile.PositionLine!.Id,
|
|
// PositionTypeId = placementProfile.PositionType!.Id,
|
|
// OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
// PosNoId = positionNumber!.Id,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
// PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
// PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// profile.Salaries.Add(salary);
|
|
|
|
// // change profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == profile.Id);
|
|
// if (profilePosition == null)
|
|
// {
|
|
// profilePosition = new ProfilePosition
|
|
// {
|
|
// Profile = profile,
|
|
// OrganizationPosition = placementProfile.OrganizationPosition,
|
|
// IsActive = true,
|
|
// IsPublished = true,
|
|
// };
|
|
// _dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
// }
|
|
// else
|
|
// {
|
|
// profilePosition.OrganizationPosition = placementProfile.OrganizationPosition;
|
|
// //_dbContext.Attatch(profilePosition);
|
|
// }
|
|
|
|
// update placementstatus
|
|
placementProfile.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-08 - คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand08Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var placementProfile = await _dbContext.Set<RetirementOther>()
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.Salaries)
|
|
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.Position)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PositionPathSide)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PositionType)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PositionLine)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PositionLevel)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PosNo)
|
|
|
|
// .Include(x => x.PositionPath)
|
|
// .Include(x => x.PositionPathSide)
|
|
// .Include(x => x.PositionType)
|
|
// .Include(x => x.PositionLine)
|
|
// .Include(x => x.PositionLevel)
|
|
// .Include(x => x.PositionNumber)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationShortName)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutive)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionLine)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
// var profile = placementProfile.Profile;
|
|
// if (profile != null)
|
|
// {
|
|
// profile.IsActive = true;
|
|
// profile.IsLeave = false;
|
|
// profile.LeaveDate = null;
|
|
// profile.LeaveReason = null;
|
|
|
|
|
|
// //profile.Position = placementProfile.Profile.Position;
|
|
// //profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id;
|
|
// //profile.PositionType = placementProfile.PositionType;
|
|
// //profile.PositionLevel = placementProfile.PositionLevel;
|
|
|
|
// //profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id;
|
|
// //profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name;
|
|
// //profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber;
|
|
|
|
// // organization
|
|
// //profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id;
|
|
// //profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name;
|
|
// //profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id;
|
|
// //profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id;
|
|
// //profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/");
|
|
// }
|
|
|
|
// var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
|
|
// Amount = recv.Amount == null ? 0 : recv.Amount,
|
|
// PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount,
|
|
// MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
// PositionExecutiveId = placementProfile.OrganizationPosition == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
// PositionExecutiveSideId = placementProfile.OrganizationPosition == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// profile.Salaries.Add(salary);
|
|
|
|
// var org_pos = await _dbContext.Set<OrganizationPositionEntity>().Include(x => x.PositionNumber).FirstOrDefaultAsync(x => x.PositionNumber.Id == placementProfile.PositionNumber.Id);
|
|
|
|
// // add profile position
|
|
// var profilePosition = new ProfilePosition
|
|
// {
|
|
// Profile = profile,
|
|
// OrganizationPosition = org_pos,
|
|
// IsActive = true,
|
|
// IsPublished = true,
|
|
// };
|
|
// _dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
|
|
// update placementstatus
|
|
placementProfile.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-09 - คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand09Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var placementProfile = await _dbContext.Set<RetirementOther>()
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.Salaries)
|
|
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.Position)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PositionPathSide)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PositionType)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PositionLine)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PositionLevel)
|
|
// //.Include(x => x.Profile)
|
|
// //.ThenInclude(x => x.PosNo)
|
|
|
|
// .Include(x => x.PositionPath)
|
|
// .Include(x => x.PositionPathSide)
|
|
// .Include(x => x.PositionType)
|
|
// .Include(x => x.PositionLine)
|
|
// .Include(x => x.PositionLevel)
|
|
// .Include(x => x.PositionNumber)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationShortName)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutive)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionLine)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
// var profile = placementProfile.Profile;
|
|
// if (profile != null)
|
|
// {
|
|
// profile.IsActive = true;
|
|
// profile.IsLeave = false;
|
|
// profile.LeaveDate = null;
|
|
|
|
|
|
// //profile.Position = placementProfile.PositionPath;
|
|
// //profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id;
|
|
// //profile.PositionType = placementProfile.PositionType;
|
|
// //profile.PositionLevel = placementProfile.PositionLevel;
|
|
|
|
// //profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id;
|
|
// //profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name;
|
|
// //profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber;
|
|
|
|
// //// organization
|
|
// //profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id;
|
|
// //profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name;
|
|
// //profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id;
|
|
// //profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id;
|
|
// //profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/");
|
|
// }
|
|
|
|
// var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// //var oc = _dbContext.Set<OrganizationEntity>()
|
|
// // .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id);
|
|
|
|
// //var position = placementProfile.PositionPath;
|
|
|
|
// //var positionNumber = placementProfile.PositionNumber;
|
|
|
|
// //var positionType = placementProfile.PositionType;
|
|
|
|
// //var positionLevel = placementProfile.PositionLevel;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
|
|
// Amount = recv.Amount == null ? 0 : recv.Amount,
|
|
// PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount,
|
|
// MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
// PositionExecutiveId = placementProfile.OrganizationPosition == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
// PositionExecutiveSideId = placementProfile.OrganizationPosition == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// profile.Salaries.Add(salary);
|
|
|
|
// var org_pos = await _dbContext.Set<OrganizationPositionEntity>().Include(x => x.PositionNumber).FirstOrDefaultAsync(x => x.PositionNumber.Id == placementProfile.PositionNumber.Id);
|
|
|
|
// // add profile position
|
|
// var profilePosition = new ProfilePosition
|
|
// {
|
|
// Profile = profile,
|
|
// OrganizationPosition = org_pos,
|
|
// IsActive = true,
|
|
// IsPublished = true,
|
|
// };
|
|
// _dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
|
|
// update placementstatus
|
|
placementProfile.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// <summary>
|
|
/// C-PM-10 - คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand10Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Salaries.Add(salary);
|
|
|
|
// update placementstatus
|
|
//data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-11 - คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand11Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
data.IsProbation = false;
|
|
|
|
var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Salaries.Add(salary);
|
|
|
|
// update placementstatus
|
|
//data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand12Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
data.IsActive = false;
|
|
data.IsLeave = true;
|
|
data.LeaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
|
|
data.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == data.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// update placementstatus
|
|
//data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-13 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand13Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<PlacementTransfer>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Salaries)
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
data.Profile.IsActive = false;
|
|
data.Profile.IsLeave = true;
|
|
data.Profile.LeaveReason = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ";
|
|
data.Profile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Profile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == data.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// update placementstatus
|
|
//data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-14 - คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand14Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
// create new profile
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
// query placement Profile
|
|
var placementProfile = await _dbContext.Set<PlacementReceive>()
|
|
//.Include(x => x.Prefix)
|
|
//.Include(x => x.FatherPrefix)
|
|
//.Include(x => x.MotherPrefix)
|
|
//.Include(x => x.MarryPrefix)
|
|
.Include(x => x.Gender)
|
|
.Include(x => x.Relationship)
|
|
.Include(x => x.BloodGroup)
|
|
.Include(x => x.Religion)
|
|
|
|
//.Include(x => x.RegistSubDistrict)
|
|
//.Include(x => x.RegistDistrict)
|
|
//.Include(x => x.RegistProvince)
|
|
//.Include(x => x.CurrentSubDistrict)
|
|
//.Include(x => x.CurrentDistrict)
|
|
//.Include(x => x.CurrentProvince)
|
|
|
|
// .Include(x => x.PositionPath)
|
|
// .Include(x => x.PositionPathSide)
|
|
// .Include(x => x.PositionType)
|
|
// .Include(x => x.PositionLine)
|
|
// .Include(x => x.PositionLevel)
|
|
// .Include(x => x.PositionNumber)
|
|
|
|
//.Include(x => x.PlacementCertificates)
|
|
//.Include(x => x.PlacementEducations)
|
|
//.ThenInclude(x => x.EducationLevel)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationShortName)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutive)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionExecutiveSide)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.PositionMaster)
|
|
// .ThenInclude(x => x.PositionLine)
|
|
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception("Invalid placement profile: " + recv.RefPlacementProfileId);
|
|
|
|
// // ใส่ฟีลจากข้อมูล
|
|
// var profile = new Profile
|
|
// {
|
|
// ProfileType = "officer",
|
|
// CitizenId = placementProfile.citizenId,
|
|
// Prefix = placementProfile.prefix,
|
|
// FirstName = placementProfile.firstName,
|
|
// LastName = placementProfile.lastName,
|
|
// Gender = placementProfile.Gender,
|
|
// Nationality = placementProfile.Nationality,
|
|
// BirthDate = placementProfile.DateOfBirth,
|
|
// RelationshipId = placementProfile.Relationship == null ? Guid.Empty : placementProfile.Relationship!.Id,
|
|
// TelephoneNumber = "",
|
|
// Race = placementProfile.Race,
|
|
// ReligionId = placementProfile.Religion == null ? Guid.Empty : placementProfile.Religion.Id,
|
|
// BloodGroupId = placementProfile.BloodGroup == null ? Guid.Empty : placementProfile.BloodGroup.Id,
|
|
|
|
// DateAppoint = placementProfile.RecruitDate == null ? null : placementProfile.RecruitDate.Value,
|
|
// DateStart = placementProfile.RecruitDate == null ? null : placementProfile.RecruitDate.Value,
|
|
|
|
// //RegistrationAddress = placementProfile.RegistAddress,
|
|
// //RegistrationSubDistrictId = placementProfile.RegistSubDistrict == null ? Guid.Empty : placementProfile.RegistSubDistrict!.Id,
|
|
// //RegistrationDistrictId = placementProfile.RegistDistrict == null ? Guid.Empty : placementProfile.RegistDistrict!.Id,
|
|
// //RegistrationProvinceId = placementProfile.RegistProvince == null ? Guid.Empty : placementProfile.RegistProvince!.Id,
|
|
|
|
// //CurrentAddress = placementProfile.CurrentAddress,
|
|
// //CurrentSubDistrictId = placementProfile.CurrentSubDistrict == null ? Guid.Empty : placementProfile.CurrentSubDistrict!.Id,
|
|
// //CurrentDistrictId = placementProfile.CurrentDistrict == null ? Guid.Empty : placementProfile.CurrentDistrict!.Id,
|
|
// //CurrentProvinceId = placementProfile.CurrentProvince == null ? Guid.Empty : placementProfile.CurrentProvince!.Id,
|
|
|
|
// //FatherPrefixId = placementProfile.FatherPrefix == null ? Guid.Empty : placementProfile.FatherPrefix.Id,
|
|
// //FatherFirstName = placementProfile.FatherFirstName,
|
|
// //FatherLastName = placementProfile.FatherLastName,
|
|
// //FatherCareer = placementProfile.FatherOccupation,
|
|
|
|
// //MotherPrefixId = placementProfile.MotherPrefix == null ? Guid.Empty : placementProfile.MotherPrefix.Id,
|
|
// //MotherFirstName = placementProfile.MotherFirstName,
|
|
// //MotherLastName = placementProfile.MotherLastName,
|
|
// //MotherCareer = placementProfile.MotherOccupation,
|
|
|
|
// //CouplePrefixId = placementProfile.MarryPrefix == null ? Guid.Empty : placementProfile.MarryPrefix.Id,
|
|
// //CoupleFirstName = placementProfile.MarryFirstName,
|
|
// //CoupleLastName = placementProfile.MarryLastName,
|
|
// //CoupleCareer = placementProfile.MarryOccupation,
|
|
|
|
// Position = placementProfile.PositionPath,
|
|
// PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id,
|
|
// PositionType = placementProfile.PositionType,
|
|
// PositionLevel = placementProfile.PositionLevel,
|
|
// //PositionEmployeeLevel = placementProfile.PositionLevel,
|
|
// PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id,
|
|
// PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name,
|
|
// PosNo = placementProfile.OrganizationPosition!.PositionNumber,
|
|
|
|
// IsVerified = true,
|
|
// IsProbation = true,
|
|
// Physical = "",
|
|
// Ability = "",
|
|
// AvatarRef = "",
|
|
// GovAgeAbsent = 0,
|
|
// GovAgePlus = 0,
|
|
// EntryStatus = "",
|
|
// IsTransfer = false,
|
|
// IsActive = true,
|
|
// IsLeave = false,
|
|
// VerifiedUser = "",
|
|
// FirstNameOld = "",
|
|
// LastNameOld = "",
|
|
// CoupleLive = false,
|
|
// FatherLive = false,
|
|
// MotherLive = false,
|
|
// CreatedUser = "",
|
|
|
|
// Educations = new List<ProfileEducation>(),
|
|
// Certificates = new List<ProfileCertificate>(),
|
|
// Salaries = new List<ProfileSalary>(),
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// // organization
|
|
// OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
// OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name,
|
|
// OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id,
|
|
// OrganizationOrganization = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Name,
|
|
// OcId = placementProfile.OrganizationPosition!.Organization!.Id,
|
|
// Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"),
|
|
|
|
// };
|
|
|
|
// // add profile salary
|
|
|
|
// var oc = _dbContext.Set<OrganizationEntity>()
|
|
// .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id);
|
|
|
|
// var position = placementProfile.PositionPath;
|
|
|
|
// var positionNumber = placementProfile.PositionNumber;
|
|
|
|
// var positionType = placementProfile.PositionType;
|
|
|
|
// var positionLevel = placementProfile.PositionLevel;
|
|
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = 1,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = recv.Amount == null ? 0 : recv.Amount,
|
|
// PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount,
|
|
// MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "รับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = oc == null ? Guid.Empty : oc.Id,
|
|
|
|
// PositionId = position!.Id,
|
|
|
|
// PositionLevel = placementProfile.PositionLevel,
|
|
// PositionLineId = placementProfile.PositionLine!.Id,
|
|
// PositionTypeId = placementProfile.PositionType!.Id,
|
|
// OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id,
|
|
// PosNoId = positionNumber!.Id,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id,
|
|
// PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id,
|
|
// PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// //if (placementProfile.PositionPathSide! != null)
|
|
// //{
|
|
// // salary.PositionPathSideId = placementProfile.PositionPathSide!.Id;
|
|
// //}
|
|
// //else
|
|
|
|
// //if (placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! != null)
|
|
// //{
|
|
// // salary.PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id;
|
|
// //}
|
|
|
|
// //if (placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! != null)
|
|
// //{
|
|
// // salary.PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id;
|
|
// //}
|
|
|
|
// // add profile position
|
|
// var profilePosition = new ProfilePosition
|
|
// {
|
|
// Profile = profile,
|
|
// OrganizationPosition = placementProfile.OrganizationPosition,
|
|
// IsActive = true,
|
|
// IsPublished = true,
|
|
// };
|
|
// _dbContext.Set<ProfilePosition>().Add(profilePosition);
|
|
|
|
// profile.Salaries.Add(salary);
|
|
|
|
// _dbContext.Set<Profile>().Add(profile);
|
|
|
|
// update placementstatus
|
|
placementProfile.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = profile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-15 - คำสั่งให้ช่วยราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand15Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<PlacementOfficer>()
|
|
//.Include(x => x.Profile)
|
|
//.ThenInclude(x => x.Salaries)
|
|
//.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
//data.Profile.IsActive = false;
|
|
//data.Profile.IsLeave = true;
|
|
//data.Profile.LeaveReason = "ลาออกจากราชการ";
|
|
//data.Profile.LeaveDate = command.CommandAffectDate;
|
|
|
|
//var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
// PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
// MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งให้ช่วยราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
// PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
// //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// //data.Profile.Salaries.Add(salary);
|
|
|
|
// // update placementstatus
|
|
data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
//ReceiverUserId = data.Profile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
//ReceiverUserId = data.Profile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-16 - คำสั่งส่งตัวกลับ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand16Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<PlacementRepatriation>()
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
//data.Profile.IsActive = false;
|
|
//data.Profile.IsLeave = true;
|
|
//data.Profile.LeaveReason = "ลาออกจากราชการ";
|
|
//data.Profile.LeaveDate = command.CommandAffectDate;
|
|
|
|
// var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
// PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
// MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งส่งตัวกลับ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
// PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
// //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// data.Profile.Salaries.Add(salary);
|
|
|
|
// update placementstatus
|
|
data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = data.Profile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = data.Profile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-17 - คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand17Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<RetirementResign>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
data.Profile.IsActive = false;
|
|
data.Profile.IsLeave = true;
|
|
data.Profile.LeaveReason = "ลาออกจากราชการ";
|
|
data.Profile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Profile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == data.Profile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// update placementstatus
|
|
data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Profile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Profile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-18 - คำสั่งให้ออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand18Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<RetirementOut>()
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
// data.Profile.IsActive = false;
|
|
// data.Profile.IsLeave = true;
|
|
// data.Profile.LeaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการ";
|
|
// data.Profile.LeaveDate = command.CommandAffectDate;
|
|
|
|
// var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
// PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
// MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งให้ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
// PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
// //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// data.Profile.Salaries.Add(salary);
|
|
|
|
// // remove profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == data.Profile.Id);
|
|
// if (profilePosition != null)
|
|
// _dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// update placementstatus
|
|
data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = data.Profile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = data.Profile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-19 - คำสั่งปลดออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand19Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
data.IsActive = false;
|
|
data.IsLeave = true;
|
|
data.LeaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ";
|
|
data.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งปลดออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == data.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
var dataSend = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = dataSend });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-20 - คำสั่งไล่ออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand20Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
data.IsActive = false;
|
|
data.IsLeave = true;
|
|
data.LeaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ";
|
|
data.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งไล่ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == data.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
var dataSend = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = dataSend });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-21 - คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>GenerateCommandReportType25_Cover
|
|
private async Task ExecuteCommand21Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<OrganizationEmployeeProfile>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.Include(x => x.OrgEmployee)
|
|
.ThenInclude(x => x.Organization)
|
|
.Include(x => x.OrgEmployee)
|
|
.ThenInclude(x => x.PositionEmployeePosition)
|
|
.Include(x => x.OrgEmployee)
|
|
.ThenInclude(x => x.PositionEmployeeLine)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
data.Profile.EmployeeClass = "perm"; // ลจ ประจำ
|
|
data.Profile.OcId = data.OrgEmployee.Organization == null ? null : data.OrgEmployee.Organization.Id;
|
|
// data.Profile.Oc = "xxx";
|
|
data.Profile.PosNoEmployee = data.OrgEmployee.PosNo;
|
|
data.Profile.PositionEmployeePosition = data.OrgEmployee.PositionEmployeePosition;
|
|
// data.Profile.PositionEmployeePositionSide = data.OrgEmployee.OrganizationPositionEmployeePositionSides;
|
|
// data.Profile.PositionEmployeeLevel = data.OrgEmployee.OrganizationPositionEmployeeLevels;
|
|
// data.Profile.PositionEmployeeGroup = data.OrgEmployee.employee;
|
|
data.Profile.PositionEmployeeLine = data.OrgEmployee.PositionEmployeeLine;
|
|
|
|
var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = recv.Amount,
|
|
PositionSalaryAmount = recv.PositionSalaryAmount,
|
|
MouthSalaryAmount = recv.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
//OcId = lastSarary.OcId,
|
|
|
|
|
|
//PositionLevel = lastSarary.PositionLevel,
|
|
//PositionLineId = lastSarary.PositionLineId,
|
|
//PositionTypeId = lastSarary.PositionTypeId,
|
|
//OrganizationShortNameId = lastSarary.OrganizationShortNameId,
|
|
//PosNoId = lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
//PositionEmployeeGroupId = null,
|
|
//PositionEmployeeLevelId = null,
|
|
//PositionEmployeePositionId = null,
|
|
//PositionEmployeePositionSideId = null,
|
|
//PosNoEmployee = "",
|
|
|
|
|
|
////PositionPathSideId = lastSarary.PositionPathSideId == null,
|
|
//PositionExecutiveId = lastSarary.PositionExecutiveId,
|
|
////PositionExecutiveSideId = lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
//if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
//if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Profile.Salaries.Add(salary);
|
|
|
|
// update placementstatus
|
|
data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Profile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Profile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-22 - คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน)
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand22Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<PlacementAppointment>()
|
|
// .Include(x => x.PositionEmployeeLine)
|
|
// .Include(x => x.PositionEmployeePosition)
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.PositionEmployeeLine)
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.PositionEmployeePosition)
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.PositionEmployeeLevel)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.OrganizationShortName)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.PositionEmployeePosition)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.OrganizationPositionEmployeeLevels)
|
|
// .ThenInclude(x => x.PositionEmployeeLevel)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.PositionEmployeeLine)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
// // data.Profile.PositionEmployeeLine = data.PositionEmployeeLine;
|
|
// // data.Profile.PositionEmployeePosition = data.PositionEmployeePosition;
|
|
// data.Profile.PositionEmployeePosition = data.OrgEmployee == null ? null : data.OrgEmployee!.PositionEmployeePosition;
|
|
// // data.Profile.PositionEmployeePositionSide = data.OrgEmployee == null ? null : data.OrgEmployee!.po;
|
|
// data.Profile.PositionEmployeeLevel = data.OrgEmployee == null || data.OrgEmployee.OrganizationPositionEmployeeLevels == null || data.OrgEmployee.OrganizationPositionEmployeeLevels.Count() == 0 ? null : data.OrgEmployee!.OrganizationPositionEmployeeLevels.FirstOrDefault().PositionEmployeeLevel;
|
|
// // data.Profile.PositionEmployeeGroup = data.OrgEmployee == null ? null : data.OrgEmployee!.gr;
|
|
// data.Profile.PositionEmployeeLine = data.OrgEmployee == null ? null : data.OrgEmployee!.PositionEmployeeLine;
|
|
// data.Profile.OrganizationShortNameId = data.OrgEmployee == null || data.OrgEmployee!.OrganizationShortName == null ? null : data.OrgEmployee!.OrganizationShortName!.Id;
|
|
// data.Profile.OrganizationShortName = data.OrgEmployee == null || data.OrgEmployee!.OrganizationShortName == null ? null : data.OrgEmployee!.OrganizationShortName!.Name;
|
|
// data.Profile.OrganizationOrganizationId = data.OrgEmployee == null || data.OrgEmployee!.OrganizationOrganization == null ? null : data.OrgEmployee!.OrganizationOrganization!.Id;
|
|
// data.Profile.OrganizationOrganization = data.OrgEmployee == null || data.OrgEmployee!.OrganizationOrganization == null ? null : data.OrgEmployee!.OrganizationOrganization!.Name;
|
|
// data.Profile.PosNoEmployee = data.OrgEmployee == null ? null : data.OrgEmployee!.PosNo;
|
|
// data.Profile.OcId = data.OrgEmployee == null || data.OrgEmployee!.Organization == null ? null : data.OrgEmployee!.Organization!.Id;
|
|
// data.Profile.Oc = data.OrgEmployee == null || data.OrgEmployee!.Organization == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(data.OrgEmployee!.Organization!.Id, false, false, "/");
|
|
|
|
// var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = recv.Amount,
|
|
// PositionSalaryAmount = recv.PositionSalaryAmount,
|
|
// MouthSalaryAmount = recv.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
// //OcId = lastSarary.OcId,
|
|
// //PositionLevel = lastSarary.PositionLevel,
|
|
// //PositionLineId = lastSarary.PositionLineId,
|
|
// //PositionTypeId = lastSarary.PositionTypeId,
|
|
// //OrganizationShortNameId = lastSarary.OrganizationShortNameId,
|
|
// //PosNoId = lastSarary.PosNoId,
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
// //PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = data.Profile.PositionEmployeeLevel == null ? null : data.Profile.PositionEmployeeLevel.Id,
|
|
// PositionEmployeePositionId = data.Profile.PositionEmployeePosition == null ? null : data.Profile.PositionEmployeePosition.Id,
|
|
// //PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = data.Profile.PosNoEmployee,
|
|
// ////PositionPathSideId = lastSarary.PositionPathSideId == null,
|
|
// //PositionExecutiveId = lastSarary.PositionExecutiveId,
|
|
// ////PositionExecutiveSideId = lastSarary.PositionExecutiveSideId,
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
// };
|
|
// data.Profile.Salaries.Add(salary);
|
|
// update placementstatus
|
|
data.Status = "DONE";
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// // รอเอาข้อมูลที่ได้มาส่ง inbox noti ให้ผู้รับคำสั่ง
|
|
|
|
// //var inbox = new Inbox
|
|
// //{
|
|
// // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// // Body = $"คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// // ReceiverUserId = data.Profile.Id,
|
|
// // Payload = payload_str,
|
|
// //};
|
|
// //_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// //var noti = new Notification
|
|
// //{
|
|
// // Body = $"คุณได้รับคำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// // ReceiverUserId = data.Profile.Id,
|
|
// // Type = "LINK",
|
|
// // Payload = payload_str,
|
|
// //};
|
|
// //_dbContext.Set<Notification>().Add(noti);
|
|
// //await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-23 - คำสั่งให้ลูกจ้างออกจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand23Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<RetirementResign>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
data.Profile.IsActive = false;
|
|
data.Profile.IsLeave = true;
|
|
data.Profile.LeaveReason = "ลาออกจากราชการ";
|
|
data.Profile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งให้ลูกจ้างออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
data.Profile.Salaries.Add(salary);
|
|
|
|
// update placementstatus
|
|
data.Status = "DONE";
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Profile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = data.Profile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-24 - คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย)
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand24Async(Command command)
|
|
{
|
|
try
|
|
{
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var data = await _dbContext.Set<PlacementAppointment>()
|
|
// .Include(x => x.PositionEmployeeLine)
|
|
// .Include(x => x.PositionEmployeePosition)
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.PositionEmployeeLine)
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.PositionEmployeePosition)
|
|
// .Include(x => x.Profile)
|
|
// .ThenInclude(x => x.PositionEmployeeLevel)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.OrganizationShortName)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.OrganizationOrganization)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.Organization)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.PositionEmployeePosition)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.OrganizationPositionEmployeeLevels)
|
|
// .ThenInclude(x => x.PositionEmployeeLevel)
|
|
// .Include(x => x.OrgEmployee)
|
|
// .ThenInclude(x => x.PositionEmployeeLine)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
// // data.Profile.PositionEmployeeLine = data.PositionEmployeeLine;
|
|
// // data.Profile.PositionEmployeePosition = data.PositionEmployeePosition;
|
|
// data.Profile.PositionEmployeePosition = data.OrgEmployee == null ? null : data.OrgEmployee!.PositionEmployeePosition;
|
|
// // data.Profile.PositionEmployeePositionSide = data.OrgEmployee == null ? null : data.OrgEmployee!.po;
|
|
// data.Profile.PositionEmployeeLevel = data.OrgEmployee == null || data.OrgEmployee.OrganizationPositionEmployeeLevels == null || data.OrgEmployee.OrganizationPositionEmployeeLevels.Count() == 0 ? null : data.OrgEmployee!.OrganizationPositionEmployeeLevels.FirstOrDefault().PositionEmployeeLevel;
|
|
// // data.Profile.PositionEmployeeGroup = data.OrgEmployee == null ? null : data.OrgEmployee!.gr;
|
|
// data.Profile.PositionEmployeeLine = data.OrgEmployee == null ? null : data.OrgEmployee!.PositionEmployeeLine;
|
|
// data.Profile.OrganizationShortNameId = data.OrgEmployee == null || data.OrgEmployee!.OrganizationShortName == null ? null : data.OrgEmployee!.OrganizationShortName!.Id;
|
|
// data.Profile.OrganizationShortName = data.OrgEmployee == null || data.OrgEmployee!.OrganizationShortName == null ? null : data.OrgEmployee!.OrganizationShortName!.Name;
|
|
// data.Profile.OrganizationOrganizationId = data.OrgEmployee == null || data.OrgEmployee!.OrganizationOrganization == null ? null : data.OrgEmployee!.OrganizationOrganization!.Id;
|
|
// data.Profile.OrganizationOrganization = data.OrgEmployee == null || data.OrgEmployee!.OrganizationOrganization == null ? null : data.OrgEmployee!.OrganizationOrganization!.Name;
|
|
// data.Profile.PosNoEmployee = data.OrgEmployee == null ? null : data.OrgEmployee!.PosNo;
|
|
// data.Profile.OcId = data.OrgEmployee == null || data.OrgEmployee!.Organization == null ? null : data.OrgEmployee!.Organization!.Id;
|
|
// data.Profile.Oc = data.OrgEmployee == null || data.OrgEmployee!.Organization == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(data.OrgEmployee!.Organization!.Id, false, false, "/");
|
|
|
|
// var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = recv.Amount,
|
|
// PositionSalaryAmount = recv.PositionSalaryAmount,
|
|
// MouthSalaryAmount = recv.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
// //OcId = lastSarary.OcId,
|
|
// //PositionLevel = lastSarary.PositionLevel,
|
|
// //PositionLineId = lastSarary.PositionLineId,
|
|
// //PositionTypeId = lastSarary.PositionTypeId,
|
|
// //OrganizationShortNameId = lastSarary.OrganizationShortNameId,
|
|
// //PosNoId = lastSarary.PosNoId,
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
// //PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = data.Profile.PositionEmployeeLevel == null ? null : data.Profile.PositionEmployeeLevel.Id,
|
|
// PositionEmployeePositionId = data.Profile.PositionEmployeePosition == null ? null : data.Profile.PositionEmployeePosition.Id,
|
|
// //PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = data.Profile.PosNoEmployee,
|
|
// ////PositionPathSideId = lastSarary.PositionPathSideId == null,
|
|
// //PositionExecutiveId = lastSarary.PositionExecutiveId,
|
|
// ////PositionExecutiveSideId = lastSarary.PositionExecutiveSideId,
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
// };
|
|
// data.Profile.Salaries.Add(salary);
|
|
// update placementstatus
|
|
data.Status = "DONE";
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// // รอเอาข้อมูลที่ได้มาส่ง inbox noti ให้ผู้รับคำสั่ง
|
|
|
|
// //var inbox = new Inbox
|
|
// //{
|
|
// // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// // Body = $"คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// // ReceiverUserId = data.Profile.Id,
|
|
// // Payload = payload_str,
|
|
// //};
|
|
// //_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// //var noti = new Notification
|
|
// //{
|
|
// // Body = $"คุณได้รับคำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// // ReceiverUserId = data.Profile.Id,
|
|
// // Type = "LINK",
|
|
// // Payload = payload_str,
|
|
// //};
|
|
// //_dbContext.Set<Notification>().Add(noti);
|
|
// //await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-25 - คำสั่งพักจากราชการ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand25Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/stop/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var dataProfile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (dataProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
dataProfile.IsActive = false;
|
|
dataProfile.IsLeave = true;
|
|
dataProfile.LeaveReason = "ได้รับโทษทางวินัย พักจากราชการ";
|
|
dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งพักจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
dataProfile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-26 - คำสั่งให้ออกจากราชการไว้ก่อน
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand26Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/stop/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var dataProfile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (dataProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
dataProfile.IsActive = false;
|
|
dataProfile.IsLeave = true;
|
|
dataProfile.LeaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน";
|
|
dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งให้ออกจากราชการไว้ก่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
dataProfile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-27 - คำสั่งลงโทษ ภาคทัณฑ์
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand27Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var dataProfile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (dataProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
dataProfile.IsActive = false;
|
|
dataProfile.IsLeave = true;
|
|
dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ภาคทัณฑ์";
|
|
dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งลงโทษ ภาคทัณฑ์ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
dataProfile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-28 - คำสั่งลงโทษ ตัดเงินเดือน
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand28Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var dataProfile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (dataProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
dataProfile.IsActive = false;
|
|
dataProfile.IsLeave = true;
|
|
dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ตัดเงินเดือน";
|
|
dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งลงโทษ ตัดเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
dataProfile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-29 - คำสั่งลงโทษ ลดขั้นเงินเดือน
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand29Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var dataProfile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (dataProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
dataProfile.IsActive = false;
|
|
dataProfile.IsLeave = true;
|
|
dataProfile.LeaveReason = "ได้รับโทษทางวินัย ลงโทษ ลดขั้นเงินเดือน";
|
|
dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
dataProfile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-30 - คำสั่งเพิ่มโทษ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand30Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var dataProfile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (dataProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
dataProfile.IsActive = false;
|
|
dataProfile.IsLeave = true;
|
|
dataProfile.LeaveReason = "ได้รับโทษทางวินัย เพิ่มโทษ";
|
|
dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งเพิ่มโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
dataProfile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-31 - คำสั่งงดโทษ
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand31Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var dataProfile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (dataProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
dataProfile.IsActive = false;
|
|
dataProfile.IsLeave = true;
|
|
dataProfile.LeaveReason = "ได้รับโทษทางวินัย งดโทษ";
|
|
dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งงดโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
dataProfile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// C-PM-32 - คำสั่งยุติเรื่อง
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand32Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/discipline/result/report/reject/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
foreach (var recv in command.Receivers)
|
|
{
|
|
var dataProfile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.ThenInclude(x => x.PositionLevel)
|
|
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
if (dataProfile == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
dataProfile.IsActive = false;
|
|
dataProfile.IsLeave = true;
|
|
dataProfile.LeaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง";
|
|
dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
var order = 1;
|
|
if (lastSarary != null && lastSarary.Order != null)
|
|
order = lastSarary.Order.Value + 1;
|
|
|
|
var salary = new ProfileSalary
|
|
{
|
|
Order = order,
|
|
Date = command.CommandAffectDate,
|
|
Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
SalaryClass = "",
|
|
SalaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
PositionEmployeeGroupId = null,
|
|
PositionEmployeeLevelId = null,
|
|
PositionEmployeePositionId = null,
|
|
PositionEmployeePositionSideId = null,
|
|
PosNoEmployee = "",
|
|
|
|
|
|
//PositionPathSideId = lastSarary ==null? null : lastSarary.PositionPathSideId == null,
|
|
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
//PositionExecutiveSideId = lastSarary ==null? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
IsActive = true,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
};
|
|
|
|
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
dataProfile.Salaries.Add(salary);
|
|
|
|
// remove profile position
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
if (profilePosition != null)
|
|
_dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = dataProfile.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-33 - คำสั่งยุติเรื่อง
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand33Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/33/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
// foreach (var recv in command.Receivers)
|
|
// {
|
|
// var dataProfile = await _dbContext.Set<Profile>()
|
|
// .Include(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
// .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
// if (dataProfile == null)
|
|
// throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
// dataProfile.IsActive = false;
|
|
// dataProfile.IsLeave = true;
|
|
// dataProfile.LeaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง";
|
|
// dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
// var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
// PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
// MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// //PositionPathSideId = lastSarary ==null? null : lastSarary.PositionPathSideId == null,
|
|
// PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
// //PositionExecutiveSideId = lastSarary ==null? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// dataProfile.Salaries.Add(salary);
|
|
|
|
// // remove profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
// if (profilePosition != null)
|
|
// _dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
// }
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-34 - คำสั่งยุติเรื่อง
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand34Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/34/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
// foreach (var recv in command.Receivers)
|
|
// {
|
|
// var dataProfile = await _dbContext.Set<Profile>()
|
|
// .Include(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
// .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
// if (dataProfile == null)
|
|
// throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
// dataProfile.IsActive = false;
|
|
// dataProfile.IsLeave = true;
|
|
// dataProfile.LeaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง";
|
|
// dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
// var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
// PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
// MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// //PositionPathSideId = lastSarary ==null? null : lastSarary.PositionPathSideId == null,
|
|
// PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
// //PositionExecutiveSideId = lastSarary ==null? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// dataProfile.Salaries.Add(salary);
|
|
|
|
// // remove profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
// if (profilePosition != null)
|
|
// _dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
// }
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-35 - คำสั่งยุติเรื่อง
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand35Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/35/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
// foreach (var recv in command.Receivers)
|
|
// {
|
|
// var dataProfile = await _dbContext.Set<Profile>()
|
|
// .Include(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
// .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
// if (dataProfile == null)
|
|
// throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
// dataProfile.IsActive = false;
|
|
// dataProfile.IsLeave = true;
|
|
// dataProfile.LeaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง";
|
|
// dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
// var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
// PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
// MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// //PositionPathSideId = lastSarary ==null? null : lastSarary.PositionPathSideId == null,
|
|
// PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
// //PositionExecutiveSideId = lastSarary ==null? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// dataProfile.Salaries.Add(salary);
|
|
|
|
// // remove profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
// if (profilePosition != null)
|
|
// _dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
// }
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-36 - คำสั่งยุติเรื่อง
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand36Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/36/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
// foreach (var recv in command.Receivers)
|
|
// {
|
|
// var dataProfile = await _dbContext.Set<Profile>()
|
|
// .Include(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
// .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
// if (dataProfile == null)
|
|
// throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
// dataProfile.IsActive = false;
|
|
// dataProfile.IsLeave = true;
|
|
// dataProfile.LeaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง";
|
|
// dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
// var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
// PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
// MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// //PositionPathSideId = lastSarary ==null? null : lastSarary.PositionPathSideId == null,
|
|
// PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
// //PositionExecutiveSideId = lastSarary ==null? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// dataProfile.Salaries.Add(salary);
|
|
|
|
// // remove profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
// if (profilePosition != null)
|
|
// _dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
// }
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// C-PM-37 - คำสั่งยุติเรื่อง
|
|
/// </summary>
|
|
/// <param name="command">object ของรายการคำสั่ง</param>
|
|
/// <returns></returns>
|
|
private async Task ExecuteCommand37Async(Command command, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var data = command.Receivers.Select(x => new
|
|
{
|
|
PersonId = x.RefPlacementProfileId,
|
|
Id = x.RefDisciplineId,
|
|
});
|
|
|
|
var baseAPI = _configuration["API"];
|
|
var apiUrl = $"{baseAPI}/salary/report/command/37/resume";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
|
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
|
|
var result = await res.Content.ReadAsStringAsync();
|
|
}
|
|
// create command payload
|
|
var payload_attach = command.Documents
|
|
.Select(x => new PayloadAttachment
|
|
{
|
|
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
|
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
|
})
|
|
.ToList();
|
|
|
|
var payload = new CommandPayload()
|
|
{
|
|
attachments = payload_attach
|
|
};
|
|
|
|
var payload_str = JsonConvert.SerializeObject(payload);
|
|
// foreach (var recv in command.Receivers)
|
|
// {
|
|
// var dataProfile = await _dbContext.Set<Profile>()
|
|
// .Include(x => x.Salaries)
|
|
// .ThenInclude(x => x.PositionLevel)
|
|
// .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
|
|
|
|
// if (dataProfile == null)
|
|
// throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
// dataProfile.IsActive = false;
|
|
// dataProfile.IsLeave = true;
|
|
// dataProfile.LeaveReason = "ได้รับโทษทางวินัย ยุติเรื่อง";
|
|
// dataProfile.LeaveDate = command.CommandAffectDate;
|
|
|
|
// var lastSarary = dataProfile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// var order = 1;
|
|
// if (lastSarary != null && lastSarary.Order != null)
|
|
// order = lastSarary.Order.Value + 1;
|
|
|
|
// var salary = new ProfileSalary
|
|
// {
|
|
// Order = order,
|
|
// Date = command.CommandAffectDate,
|
|
// Amount = lastSarary == null ? null : lastSarary.Amount,
|
|
// PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
|
|
// MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
|
|
// SalaryClass = "",
|
|
// SalaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
|
|
|
|
// OcId = lastSarary == null ? null : lastSarary.OcId,
|
|
|
|
// PositionId = lastSarary == null ? null : lastSarary.PositionId,
|
|
|
|
// PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
|
|
// PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
|
|
// PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
|
|
// OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
|
|
// PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
|
|
|
|
// CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
|
|
// CommandTypeName = command.CommandType.Name,
|
|
|
|
|
|
// PositionEmployeeGroupId = null,
|
|
// PositionEmployeeLevelId = null,
|
|
// PositionEmployeePositionId = null,
|
|
// PositionEmployeePositionSideId = null,
|
|
// PosNoEmployee = "",
|
|
|
|
|
|
// //PositionPathSideId = lastSarary ==null? null : lastSarary.PositionPathSideId == null,
|
|
// PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
|
|
// //PositionExecutiveSideId = lastSarary ==null? null : lastSarary.PositionExecutiveSideId,
|
|
|
|
// IsActive = true,
|
|
// CreatedAt = DateTime.Now,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
|
|
// };
|
|
|
|
// if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
|
|
// if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
|
|
|
|
// dataProfile.Salaries.Add(salary);
|
|
|
|
// // remove profile position
|
|
// var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
// .Include(x => x.Profile)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .FirstOrDefaultAsync(x => x.Profile!.Id == dataProfile.Id);
|
|
// if (profilePosition != null)
|
|
// _dbContext.Set<ProfilePosition>().Remove(profilePosition);
|
|
|
|
// await _dbContext.SaveChangesAsync();
|
|
|
|
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// // Send noti inbox and email
|
|
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
|
|
|
|
// var inbox = new Inbox
|
|
// {
|
|
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Inbox>().Add(inbox);
|
|
|
|
// var noti = new Notification
|
|
// {
|
|
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
// ReceiverUserId = dataProfile.Id,
|
|
// Type = "LINK",
|
|
// Payload = payload_str,
|
|
// };
|
|
// _dbContext.Set<Notification>().Add(noti);
|
|
// await _dbContext.SaveChangesAsync();
|
|
// }
|
|
// send cc noti inbox
|
|
foreach (var cc in command.Deployments)
|
|
{
|
|
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
|
|
if (pf != null)
|
|
{
|
|
if (cc.IsSendInbox)
|
|
{
|
|
var inbox = new Inbox
|
|
{
|
|
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Inbox>().Add(inbox);
|
|
}
|
|
|
|
if (cc.IsSendMail)
|
|
{
|
|
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
|
|
// Send noti inbox and email
|
|
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
|
|
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
|
}
|
|
|
|
|
|
var noti = new Notification
|
|
{
|
|
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
|
|
ReceiverUserId = pf.Id,
|
|
Type = "LINK",
|
|
Payload = payload_str,
|
|
};
|
|
_dbContext.Set<Notification>().Add(noti);
|
|
}
|
|
}
|
|
|
|
// change command status
|
|
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
|
|
command.CommandStatusId = cmdStatus!.Id;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Regenerate Json File "
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region " Override "
|
|
|
|
public override async Task<Command?> GetByIdAsync(Guid id)
|
|
{
|
|
return await _dbContext.Set<Command>()
|
|
.Include(x => x.Placement)
|
|
.Include(x => x.CommandType)
|
|
.Include(x => x.Documents)
|
|
.ThenInclude(x => x.Document) //--REmove
|
|
.Include(x => x.Receivers)
|
|
.Include(x => x.CommandStatus)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
}
|
|
|
|
public async Task<Command?> GetByIdWithPlacementAsync(Guid id)
|
|
{
|
|
return await _dbContext.Set<Command>()
|
|
.Include(x => x.Placement)
|
|
.Include(x => x.CommandType)
|
|
.Include(x => x.Documents)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.Receivers)
|
|
.Include(x => x.CommandStatus)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
}
|
|
|
|
public override async Task<IReadOnlyList<Command>> GetAllAsync()
|
|
{
|
|
return await _dbContext.Set<Command>()
|
|
.Include(x => x.Placement)
|
|
.Include(x => x.CommandType)
|
|
.Include(x => x.CommandStatus)
|
|
.Include(x => x.Receivers)
|
|
.OrderBy(x => x.CommandType.CommandCode)
|
|
.ThenByDescending(x => x.CommandAffectDate)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public override async Task<Command> AddAsync(Command command)
|
|
{
|
|
var status = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == 1);
|
|
command.CommandStatus = status!;
|
|
_dbContext.Attatch(status!);
|
|
|
|
return await base.AddAsync(command);
|
|
}
|
|
|
|
public override async Task<Command> UpdateAsync(Command entity)
|
|
{
|
|
// attatch
|
|
_dbContext.Attatch(entity.CommandStatus);
|
|
_dbContext.Attatch(entity.CommandType);
|
|
if (entity.Placement != null)
|
|
_dbContext.Attatch(entity.Placement);
|
|
|
|
return await base.UpdateAsync(entity);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Execute Command "
|
|
|
|
public async Task ExecuteCommandAsync(Guid id, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Receivers)
|
|
.Include(x => x.Deployments)
|
|
.Include(x => x.CommandType)
|
|
.Include(x => x.Documents)
|
|
.ThenInclude(x => x.Document)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
else
|
|
await ExecuteCommandByTypeAsync(command, token);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Command Receiver "
|
|
|
|
public async Task SaveSelectedReceiverAsync(Guid id, List<Guid> selected, string token = "")
|
|
{
|
|
try
|
|
{
|
|
Command command = null;
|
|
|
|
var c = await _dbContext.Set<Command>()
|
|
.Include(x => x.CommandType)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (c == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
switch (c.CommandType.CommandCode.ToUpper())
|
|
{
|
|
case "C-PM-01":
|
|
case "C-PM-02":
|
|
case "C-PM-03":
|
|
case "C-PM-04":
|
|
command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Placement)
|
|
.Include(x => x.Receivers)
|
|
.Include(x => x.CommandType)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
break;
|
|
default:
|
|
command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Receivers)
|
|
.Include(x => x.CommandType)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
break;
|
|
}
|
|
|
|
var ap = (await GetReceiverForByCommndTypeAsync(command, token)).Where(x => selected.Contains(x.RefPlacementProfileId!.Value));
|
|
|
|
//var appointPeople = await _dbContext.Set<PlacementProfile>()
|
|
// .Include(x => x.Prefix)
|
|
// .Include(x => x.OrganizationPosition)
|
|
// .ThenInclude(x => x!.Organization)
|
|
// //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
// .Where(x => selected.Contains(x.Id))
|
|
// .OrderBy(x => x.ExamNumber)
|
|
// .ToListAsync();
|
|
|
|
_dbContext.Set<CommandReceiver>().RemoveRange(command.Receivers);
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
var seq = 1;
|
|
foreach (var item in ap)
|
|
{
|
|
|
|
PlacementSalaryResponse salary = new();
|
|
// ให้ Update Salary เฉพาะของ Command 01-04
|
|
switch (command.CommandType.CommandCode.ToUpper())
|
|
{
|
|
case "C-PM-01":
|
|
case "C-PM-02":
|
|
case "C-PM-03":
|
|
case "C-PM-04":
|
|
salary = await GetPlacementSalaryAsync(item.RefPlacementProfileId.Value);
|
|
break;
|
|
default:
|
|
salary = await GetCommandReceiverSalary(item.RefPlacementProfileId.Value, item.Amount, item.MouthSalaryAmount, item.PositionSalaryAmount);
|
|
break;
|
|
}
|
|
|
|
var receiver = new CommandReceiver
|
|
{
|
|
Sequence = seq,
|
|
CitizenId = item.CitizenId!,
|
|
Prefix = item.Prefix,
|
|
FirstName = item.FirstName!,
|
|
LastName = item.LastName!,
|
|
RefPlacementProfileId = item.RefPlacementProfileId,
|
|
RefDisciplineId = item.RefDisciplineId,
|
|
Amount = salary == null ? 0 : salary.SalaryAmount,
|
|
MouthSalaryAmount = salary == null ? 0 : salary.MonthSalaryAmount,
|
|
PositionSalaryAmount = salary == null ? 0 : salary.PositionSalaryAmount
|
|
};
|
|
|
|
seq++;
|
|
command.Receivers.Add(receiver);
|
|
}
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CommandReceiver>> GetReceiverForCommandAsync(Guid id, string token = "")
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Receivers)
|
|
.Include(x => x.CommandType)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
else
|
|
return await GetReceiverForByCommndTypeAsync(command, token);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
|
{
|
|
try
|
|
{
|
|
// ปรับใหม่ให้อ่านจาก database ล้วนๆ
|
|
var command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Receivers)
|
|
.Include(x => x.CommandType)
|
|
.FirstOrDefaultAsync(x => x.Id == Id);
|
|
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
else
|
|
{
|
|
if (command.Receivers != null && command!.Receivers!.Count > 0)
|
|
{
|
|
return command.Receivers;
|
|
}
|
|
else
|
|
{
|
|
// returrn empty list
|
|
return new List<CommandReceiver>();
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<CommandReceiver> DeleteCommandReceiverAsync(Guid personalId)
|
|
{
|
|
try
|
|
{
|
|
var deleted = await _dbContext.Set<CommandReceiver>()
|
|
.FirstOrDefaultAsync(x => x.Id == personalId);
|
|
|
|
if (deleted == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
_dbContext.Set<CommandReceiver>().Remove(deleted);
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
return deleted;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<CommandReceiver?> GetCommandReceiverAsync(Guid personalId)
|
|
{
|
|
try
|
|
{
|
|
var receiver = await _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
.ThenInclude(x => x.CommandType)
|
|
.FirstOrDefaultAsync(x => x.Id == personalId);
|
|
|
|
if (receiver == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
return receiver;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public async Task SwapReceiverOrderAsync(Guid personalId, string direction)
|
|
{
|
|
try
|
|
{
|
|
var current = await _dbContext.Set<CommandReceiver>()
|
|
.Include(c => c.Command)
|
|
.FirstOrDefaultAsync(x => x.Id == personalId);
|
|
|
|
if (current == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
var currentSeq = current.Sequence;
|
|
var commandID = current.Command!.Id;
|
|
|
|
switch (direction.Trim().ToLower())
|
|
{
|
|
case "up":
|
|
{
|
|
// get prev record
|
|
var prev = await _dbContext.Set<CommandReceiver>()
|
|
.Include(c => c.Command)
|
|
.Where(x => x.Command.Id == commandID)
|
|
.Where(x => x.Sequence < currentSeq)
|
|
.OrderByDescending(x => x.Sequence)
|
|
.Take(1)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (prev != null)
|
|
{
|
|
var prevSeq = prev.Sequence;
|
|
|
|
current.Sequence = prevSeq;
|
|
prev.Sequence = currentSeq;
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
break;
|
|
}
|
|
case "down":
|
|
{
|
|
// get next record
|
|
var next = await _dbContext.Set<CommandReceiver>()
|
|
.Include(c => c.Command)
|
|
.Where(x => x.Command.Id == commandID)
|
|
.Where(x => x.Sequence > currentSeq)
|
|
.OrderBy(x => x.Sequence)
|
|
.Take(1)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (next != null)
|
|
{
|
|
var nextSeq = next.Sequence;
|
|
|
|
current.Sequence = nextSeq;
|
|
next.Sequence = currentSeq;
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
break;
|
|
}
|
|
default: throw new Exception("Invalid swap direction!");
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public async Task<string> GetReceiverPositionByCommandIdAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var ret = string.Empty;
|
|
|
|
var data = await (from r in _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
join pf in _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.PositionPath)
|
|
on r.RefPlacementProfileId equals pf.Id
|
|
where r.Command.Id == id
|
|
select new
|
|
{
|
|
r.RefPlacementProfileId,
|
|
Position = pf.PositionPath!.Name
|
|
}).ToListAsync();
|
|
|
|
if (data.Count > 0)
|
|
{
|
|
foreach (var d in data)
|
|
{
|
|
if (!ret.Contains($"{d.Position},"))
|
|
ret += $"{d.Position},";
|
|
}
|
|
|
|
ret = ret.Substring(0, ret.Length - 1);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<string> GetReceiverPosition2ByCommandIdAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var ret = string.Empty;
|
|
|
|
var data = await (from r in _dbContext.Set<CommandReceiver>()
|
|
.Include(x => x.Command)
|
|
join pf in _dbContext.Set<PlacementAppointment>()
|
|
//.Include(x => x.PositionPath)
|
|
on r.RefPlacementProfileId equals pf.Id
|
|
where r.Command.Id == id
|
|
select new
|
|
{
|
|
r.RefPlacementProfileId,
|
|
Position = pf.position
|
|
}).ToListAsync();
|
|
|
|
if (data.Count > 0)
|
|
{
|
|
foreach (var d in data)
|
|
{
|
|
if (!ret.Contains($"{d.Position},"))
|
|
ret += $"{d.Position},";
|
|
}
|
|
|
|
ret = ret.Substring(0, ret.Length - 1);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CommandDeployment>> GetDeploymentByCommandIdAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Deployments)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
else
|
|
{
|
|
if (command.Deployments != null || command!.Deployments!.Count > 0)
|
|
{
|
|
return command.Deployments;
|
|
}
|
|
else
|
|
{
|
|
var orgPos = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x!.Prefix)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.Organization)
|
|
.ThenInclude(x => x!.OrganizationOrganization)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.PositionMaster)
|
|
.ThenInclude(x => x!.PositionPath)
|
|
.Where(x => x.OrganizationPosition!.IsDirector! == true)
|
|
.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (orgPos != null)
|
|
{
|
|
if (orgPos.Profile != null)
|
|
{
|
|
var dp = new CommandDeployment
|
|
{
|
|
Sequence = 1,
|
|
ReceiveUserId = orgPos!.Profile!.Id!.ToString("D"),
|
|
CitizenId = orgPos!.Profile!.CitizenId!,
|
|
Prefix = orgPos!.Profile!.Prefix!.Name,
|
|
FirstName = orgPos!.Profile!.FirstName!,
|
|
LastName = orgPos!.Profile!.LastName!,
|
|
IsSendInbox = true,
|
|
IsSendMail = true,
|
|
IsSendNotification = true,
|
|
OrganizationName = orgPos!.OrganizationPosition!.Organization!.OrganizationOrganization!.Name,
|
|
PositionName = orgPos!.OrganizationPosition!.PositionMaster!.PositionPath!.Name
|
|
};
|
|
|
|
command.Deployments.Add(dp);
|
|
}
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
|
|
}
|
|
// query for new list
|
|
return command.Deployments;
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<ProfilePosition>> GetProfileByOrganizationIdAsync(Guid orgId)
|
|
{
|
|
try
|
|
{
|
|
var orgProfiles = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x!.Prefix)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.Organization)
|
|
.ThenInclude(x => x!.OrganizationOrganization)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.PositionMaster)
|
|
.ThenInclude(x => x!.PositionPath)
|
|
.Where(x => x.OrganizationPosition!.Organization!.Id == orgId)
|
|
.ToListAsync();
|
|
|
|
return orgProfiles;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task CreateCommandDeploymentAsync(Guid commandId, List<CommandDeployment> deploy)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Deployments)
|
|
.FirstOrDefaultAsync(x => x.Id == commandId);
|
|
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
else
|
|
{
|
|
var lastSeq = 0;
|
|
var dep = command.Deployments.OrderByDescending(x => x.Sequence).FirstOrDefault();
|
|
if (dep == null) lastSeq = 1;
|
|
else lastSeq = dep.Sequence;
|
|
|
|
foreach (var dep2 in deploy)
|
|
{
|
|
dep2.Sequence = lastSeq;
|
|
lastSeq++;
|
|
}
|
|
|
|
command.Deployments.AddRange(deploy);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task UpdatCommandDeploymentAsync(List<CommandDeployment> deploys)
|
|
{
|
|
try
|
|
{
|
|
foreach (var dp in deploys)
|
|
{
|
|
var updated = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == dp.Id);
|
|
if (updated != null)
|
|
{
|
|
updated.IsSendMail = dp.IsSendMail;
|
|
updated.IsSendInbox = dp.IsSendInbox;
|
|
}
|
|
}
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task DeleteCommandDeploymentAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var deleted = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == id);
|
|
if (deleted == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
_dbContext.Set<CommandDeployment>().Remove(deleted);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<CommandDeployment?> GetCommandDeploymentById(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var data = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == id);
|
|
|
|
return data;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#region " Documents "
|
|
|
|
public async Task<List<CommandDocument>> GetExistDocument(Guid id, string category)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Documents)
|
|
.ThenInclude(x => x.Document)
|
|
.FirstOrDefaultAsync(c => c.Id == id);
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
// insert new record to comand Document
|
|
var exist = command.Documents.Where(x => x.Category == category).ToList();
|
|
|
|
return exist;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task UploadDocument(Guid id, string category, CommandDocument document)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>()
|
|
.Include(x => x.Documents)
|
|
//.ThenInclude(x =>x.Document)
|
|
.FirstOrDefaultAsync(c => c.Id == id);
|
|
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
// insert new record to comand Document
|
|
//var exist = command.Documents.Where(x => x.Category == category).ToList();
|
|
//if (exist.Any())
|
|
//{
|
|
// _dbContext.Set<CommandDocument>().RemoveRange(exist);
|
|
// await _dbContext.SaveChangesAsync();
|
|
//}
|
|
|
|
// insert new Record
|
|
command.Documents.Add(document);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<CommandDocument>> GetCommandDocumentAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var docs = await _dbContext.Set<CommandDocument>()
|
|
.Include(x => x.Command)
|
|
.Include(x => x.Document)
|
|
.Where(x => x.Command.Id == id)
|
|
.ToListAsync();
|
|
|
|
return docs;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Change Command Status "
|
|
|
|
public async Task GotoNextStateAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>().Include(c => c.CommandStatus).FirstOrDefaultAsync(x => x.Id == id);
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
var notProcess = new int[] { 4, 5 };
|
|
|
|
if (!notProcess.Contains(command.CommandStatus.Sequence))
|
|
{
|
|
var nextStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == command.CommandStatus.Sequence + 1);
|
|
command.CommandStatus = nextStatus!;
|
|
_dbContext.Attatch(nextStatus!);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task GotoPrevStateAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>().Include(c => c.CommandStatus).FirstOrDefaultAsync(x => x.Id == id);
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
var notProcess = new int[] { 1, 5 };
|
|
|
|
if (!notProcess.Contains(command.CommandStatus.Sequence))
|
|
{
|
|
var nextStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == command.CommandStatus.Sequence - 1);
|
|
command.CommandStatus = nextStatus!;
|
|
_dbContext.Attatch(nextStatus!);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Change Detail Sequence "
|
|
|
|
|
|
#endregion
|
|
|
|
#region " Placement "
|
|
|
|
public async Task<PlacementSalaryResponse> GetCommandReceiverSalary(Guid recordId, Double? _Amount, Double? _MouthSalaryAmount, Double? _PositionSalaryAmount)
|
|
{
|
|
try
|
|
{
|
|
var cmdReceiver = await _dbContext.Set<CommandReceiver>()
|
|
.FirstOrDefaultAsync(x => x.Id == recordId);
|
|
|
|
double SalaryAmount = 0;
|
|
double PositionSalaryAmount = 0;
|
|
double MonthSalaryAmount = 0;
|
|
|
|
if (cmdReceiver == null)
|
|
{
|
|
return new PlacementSalaryResponse
|
|
{
|
|
SalaryAmount = _Amount == null ? 0 : _Amount.Value,
|
|
PositionSalaryAmount = _MouthSalaryAmount == null ? 0 : _MouthSalaryAmount.Value,
|
|
MonthSalaryAmount = _PositionSalaryAmount == null ? 0 : _PositionSalaryAmount.Value,
|
|
};
|
|
}
|
|
var profile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.FirstOrDefaultAsync(p => p.CitizenId == cmdReceiver.CitizenId);
|
|
if (profile != null && profile.Salaries != null && profile.Salaries.Count() > 0)
|
|
{
|
|
SalaryAmount = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value : 0;
|
|
PositionSalaryAmount = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount.Value : 0;
|
|
MonthSalaryAmount = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().MouthSalaryAmount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().MouthSalaryAmount.Value : 0;
|
|
}
|
|
|
|
return new PlacementSalaryResponse
|
|
{
|
|
SalaryAmount = cmdReceiver.Amount != null && cmdReceiver.Amount != 0 ? cmdReceiver.Amount.Value : SalaryAmount,
|
|
PositionSalaryAmount = cmdReceiver.PositionSalaryAmount != null && cmdReceiver.PositionSalaryAmount != 0 ? cmdReceiver.PositionSalaryAmount.Value : PositionSalaryAmount,
|
|
MonthSalaryAmount = cmdReceiver.MouthSalaryAmount != null && cmdReceiver.MouthSalaryAmount != 0 ? cmdReceiver.MouthSalaryAmount.Value : MonthSalaryAmount,
|
|
};
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<PlacementSalaryResponse> GetPlacementSalaryAsync(Guid placementProfileId)
|
|
{
|
|
try
|
|
{
|
|
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
|
.FirstOrDefaultAsync(p => p.Id == placementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception($"Invalid placement profile: {placementProfileId}");
|
|
var profile = await _dbContext.Set<Profile>()
|
|
.Include(x => x.Salaries)
|
|
.FirstOrDefaultAsync(p => p.CitizenId == placementProfile.CitizenId);
|
|
Double SalaryAmount = 0;
|
|
Double PositionSalaryAmount = 0;
|
|
Double MonthSalaryAmount = 0;
|
|
if (profile != null && profile.Salaries.Count() > 0)
|
|
{
|
|
SalaryAmount = placementProfile.Amount == null || placementProfile.Amount == 0 ? (profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value : 0) : 0;
|
|
PositionSalaryAmount = placementProfile.PositionSalaryAmount == null || placementProfile.PositionSalaryAmount == 0 ? (profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount.Value : 0) : 0;
|
|
MonthSalaryAmount = placementProfile.MouthSalaryAmount == null || placementProfile.MouthSalaryAmount == 0 ? (profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().MouthSalaryAmount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().MouthSalaryAmount.Value : 0) : 0;
|
|
}
|
|
|
|
return new PlacementSalaryResponse
|
|
{
|
|
SalaryAmount = placementProfile.Amount != null && placementProfile.Amount != 0 ? placementProfile.Amount.Value : SalaryAmount,
|
|
PositionSalaryAmount = placementProfile.PositionSalaryAmount != null && placementProfile.PositionSalaryAmount != 0 ? placementProfile.PositionSalaryAmount.Value : PositionSalaryAmount,
|
|
MonthSalaryAmount = placementProfile.MouthSalaryAmount != null && placementProfile.MouthSalaryAmount != 0 ? placementProfile.MouthSalaryAmount.Value : MonthSalaryAmount,
|
|
RemarkHorizontal = placementProfile.RemarkHorizontal,
|
|
RemarkVertical = placementProfile.RemarkVertical,
|
|
};
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task UpdateCommandReceiverSalaryAsync(Guid personalId, UpdatePlacementSalaryRequest req)
|
|
{
|
|
try
|
|
{
|
|
var current = await _dbContext.Set<CommandReceiver>()
|
|
.FirstOrDefaultAsync(x => x.Id == personalId);
|
|
|
|
if (current == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
current.Amount = req.SalaryAmount;
|
|
current.PositionSalaryAmount = req.PositionSalaryAmount;
|
|
current.MouthSalaryAmount = req.MonthSalaryAmount;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task UpdatePlacementSalaryAsync(Guid personalId, UpdatePlacementSalaryRequest req)
|
|
{
|
|
try
|
|
{
|
|
var current = await _dbContext.Set<CommandReceiver>()
|
|
.FirstOrDefaultAsync(x => x.Id == personalId);
|
|
|
|
if (current == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
var placementProfile = await _dbContext.Set<PlacementProfile>()
|
|
.FirstOrDefaultAsync(p => p.Id == current.RefPlacementProfileId);
|
|
|
|
if (placementProfile == null)
|
|
throw new Exception($"Invalid placement profile: {current.RefPlacementProfileId}");
|
|
|
|
placementProfile.Amount = req.SalaryAmount;
|
|
placementProfile.PositionSalaryAmount = req.PositionSalaryAmount;
|
|
placementProfile.MouthSalaryAmount = req.MonthSalaryAmount;
|
|
|
|
placementProfile.RemarkVertical = req.RemarkVertical;
|
|
placementProfile.RemarkHorizontal = req.RemarkHorizontal;
|
|
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<PositionPath>> GetPlacementPositionPath(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var data = await _dbContext.Set<PlacementProfile>()
|
|
.Include(x => x.PositionPath)
|
|
.Include(x => x.Placement)
|
|
.Where(x => x.Placement!.Id == id)
|
|
.Where(x => x.PositionPath != null)
|
|
.Select(x => x.PositionPath)
|
|
.Distinct()
|
|
.ToListAsync();
|
|
|
|
return data!;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Command Info "
|
|
|
|
public async Task<CommandInfoResponse> GetCommandInfoAsync(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>().FirstOrDefaultAsync(x => x.Id == id);
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
return new CommandInfoResponse
|
|
{
|
|
SignDate = command.CommandExcecuteDate.Value,
|
|
OrderNo = command.CommandNo,
|
|
OrderYear = command.CommandYear,
|
|
};
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task UpdateCommandInfoAsync(Guid id, string orderNo, string orderYear, DateTime signDate)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>().FirstOrDefaultAsync(x => x.Id == id);
|
|
if (command == null)
|
|
throw new Exception(GlobalMessages.CommandNotFound);
|
|
|
|
command.CommandExcecuteDate = signDate;
|
|
command.CommandNo = orderNo;
|
|
command.CommandYear = orderYear;
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Organization and Approver "
|
|
|
|
public async Task<Guid> GetRootOcIdAsync(Guid ocId)
|
|
{
|
|
try
|
|
{
|
|
var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
|
|
.FirstOrDefaultAsync(o => o.Id == ocId);
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.OrganizationNotFound);
|
|
|
|
return data.OrganizationAgencyId == null ? ocId : data.OrganizationAgencyId!.Value;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<KeyValueItemResponse>> GetCommandOrgAsync()
|
|
{
|
|
try
|
|
{
|
|
var ret = new List<KeyValueItemResponse>();
|
|
ret.Add(new KeyValueItemResponse
|
|
{
|
|
Id = Guid.Empty,
|
|
Name = "กรุงเทพมหานคร"
|
|
});
|
|
|
|
var rootOcId = await GetRootOcIdAsync(UserOrganizationId);
|
|
|
|
var oc = await _dbContext.Set<OrganizationEntity>()
|
|
.Include(x => x.OrganizationOrganization)
|
|
.Select(x => new KeyValueItemResponse
|
|
{
|
|
Id = x.Id,
|
|
Name = x.OrganizationOrganization!.Name
|
|
})
|
|
.FirstOrDefaultAsync(x => x.Id == rootOcId);
|
|
if (oc != null)
|
|
ret.Add(oc);
|
|
|
|
return ret;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<OrganizationApproverResponse>> GetOrgApproverAsync(Guid ocId)
|
|
{
|
|
try
|
|
{
|
|
if (ocId == Guid.Empty)
|
|
return new List<OrganizationApproverResponse>() { new OrganizationApproverResponse { Id = Guid.Empty, Name = "", PositionName = "ปลัดกรุงเทพมหานคร" } };
|
|
else
|
|
{
|
|
//var ret = new List<KeyValueItemResponse>();
|
|
var oc = await _dbContext.Set<OrganizationEntity>().Include(x => x.Parent).FirstOrDefaultAsync(x => x.Id == ocId);
|
|
|
|
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.Organization)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.PositionMaster)
|
|
.ThenInclude(x => x!.PositionPath)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.PositionMaster)
|
|
.ThenInclude(x => x!.PositionExecutive)
|
|
.Where(x => x.OrganizationPosition!.Organization!.Id == ocId &&
|
|
x.OrganizationPosition!.PositionMaster!.IsDirector == true)
|
|
.Select(x => new OrganizationApproverResponse
|
|
{
|
|
Id = x.Profile!.Id,
|
|
Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}",
|
|
PositionName = x.OrganizationPosition!.PositionMaster!.PositionExecutive != null ?
|
|
x.OrganizationPosition!.PositionMaster!.PositionExecutive!.Name
|
|
:
|
|
x.OrganizationPosition!.PositionMaster!.PositionPath == null ? "" : x.OrganizationPosition!.PositionMaster!.PositionPath!.Name
|
|
})
|
|
.ToListAsync();
|
|
|
|
if (profilePosition.Count > 0)
|
|
{
|
|
return profilePosition;
|
|
}
|
|
else
|
|
{
|
|
if (oc != null && oc.Parent != null)
|
|
{
|
|
var parentProfilePosition = await _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.Organization)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.PositionMaster)
|
|
.ThenInclude(x => x!.PositionPath)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x!.PositionMaster)
|
|
.ThenInclude(x => x!.PositionExecutive)
|
|
.Where(x => x.OrganizationPosition!.Organization!.Id == oc.Parent.Id &&
|
|
x.OrganizationPosition!.PositionMaster!.IsDirector == true)
|
|
.Select(x => new OrganizationApproverResponse
|
|
{
|
|
Id = x.Profile!.Id,
|
|
Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}",
|
|
PositionName = x.OrganizationPosition!.PositionMaster!.PositionExecutive != null ?
|
|
x.OrganizationPosition!.PositionMaster!.PositionExecutive!.Name
|
|
:
|
|
x.OrganizationPosition!.PositionMaster!.PositionPath == null ? "" : x.OrganizationPosition!.PositionMaster!.PositionPath!.Name
|
|
})
|
|
.ToListAsync();
|
|
|
|
return parentProfilePosition;
|
|
}
|
|
else
|
|
return new List<OrganizationApproverResponse>();
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public async Task<dynamic> GetCommandProfileAsync(string commandType, int year, string? posno)
|
|
{
|
|
try
|
|
{
|
|
var data = (from r in await _dbContext.Set<ProfileSalary>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.PosNo)
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Position)
|
|
.ToListAsync()
|
|
where r.CommandTypeName == commandType
|
|
where r.CommandNo.Contains((year + 543).ToString())
|
|
where posno == null || posno == "" ? r.Id != null : r.CommandNo.Contains(posno)
|
|
where r.Profile != null
|
|
select new
|
|
{
|
|
Id = r.Profile.Id,
|
|
CitizenId = r.Profile.CitizenId,
|
|
FullName = $"{r.Profile.Prefix.Name}{r.Profile.FirstName} {r.Profile.LastName}",
|
|
PosNo = r.Profile.PosNo == null ? null : r.Profile.PosNo.Name,
|
|
Position = r.Profile.Position == null ? null : r.Profile.Position.Name,
|
|
})
|
|
.Distinct()
|
|
.OrderBy(x => x.CitizenId)
|
|
.ToList();
|
|
return data;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public async Task<dynamic> GetHistoryCommandByProfileAsync(string type, Guid id)
|
|
{
|
|
try
|
|
{
|
|
var command = await _dbContext.Set<Command>()
|
|
.Where(x => x.CommandType.Category == type.Trim().ToLower())
|
|
.Where(x => x.Receivers.Where(x => x.RefPlacementProfileId == id).FirstOrDefault() != null)
|
|
.Select(x => new
|
|
{
|
|
CommandSubject = $"{x.CommandNo}/{Int32.Parse(x.CommandYear) + 543} {x.CommandSubject}",
|
|
CreatedAt = x.CreatedAt,
|
|
LastUpdatedAt = x.LastUpdatedAt,
|
|
})
|
|
.ToListAsync();
|
|
return command;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|