คำนวนอายุการทำงาน(ยังไม่เสร็จ)
This commit is contained in:
parent
bf111fab00
commit
eb308cfeee
4 changed files with 363 additions and 274 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
|
using System.Text;
|
||||||
using BMA.EHR.Application.Common.Interfaces;
|
using BMA.EHR.Application.Common.Interfaces;
|
||||||
using BMA.EHR.Application.Responses;
|
using BMA.EHR.Application.Responses;
|
||||||
using BMA.EHR.Domain.Extensions;
|
using BMA.EHR.Domain.Extensions;
|
||||||
|
|
@ -12,6 +13,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using static BMA.EHR.Domain.Extensions.DateTimeExtension;
|
||||||
|
|
||||||
namespace BMA.EHR.Application.Repositories.Reports
|
namespace BMA.EHR.Application.Repositories.Reports
|
||||||
{
|
{
|
||||||
|
|
@ -49,6 +51,37 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
#region ใบสมัครสอบ
|
#region ใบสมัครสอบ
|
||||||
public async Task<dynamic> GetExamCandidateAsync(Guid id)
|
public async Task<dynamic> GetExamCandidateAsync(Guid id)
|
||||||
{
|
{
|
||||||
|
var careers = await _dbExamContext.Set<Career>()
|
||||||
|
.AsQueryable()
|
||||||
|
.Where(x => x.Candidate.Id == id)
|
||||||
|
.ToListAsync();
|
||||||
|
var yearDiff = 0;
|
||||||
|
var monthDiff = 0;
|
||||||
|
var dayDiff = 0;
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
foreach (var career in careers)
|
||||||
|
{
|
||||||
|
var rangeObj = career.DurationStart.CalculateBetweenDateV2Value(career.DurationEnd);
|
||||||
|
yearDiff = yearDiff + rangeObj.years;
|
||||||
|
monthDiff = monthDiff + rangeObj.months;
|
||||||
|
dayDiff = dayDiff + rangeObj.days;
|
||||||
|
if (dayDiff >= 30)
|
||||||
|
{
|
||||||
|
monthDiff = monthDiff + (int)(dayDiff / 30);
|
||||||
|
dayDiff = dayDiff % 30;
|
||||||
|
}
|
||||||
|
if (monthDiff >= 12)
|
||||||
|
{
|
||||||
|
yearDiff = yearDiff + (int)(monthDiff / 12);
|
||||||
|
monthDiff = monthDiff % 12;
|
||||||
|
}
|
||||||
|
sb.Clear();
|
||||||
|
sb.Append(yearDiff == 0 ? "" : $"{yearDiff} ปี ");
|
||||||
|
sb.Append(monthDiff == 0 ? "" : $"{monthDiff} เดือน ");
|
||||||
|
sb.Append(dayDiff == 0 ? "" : $"{dayDiff} วัน ");
|
||||||
|
sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
var data = await _dbExamContext.Set<Candidate>().AsQueryable()
|
var data = await _dbExamContext.Set<Candidate>().AsQueryable()
|
||||||
.Where(x => x.Id == id)
|
.Where(x => x.Id == id)
|
||||||
.Select(p => new
|
.Select(p => new
|
||||||
|
|
@ -85,6 +118,7 @@ namespace BMA.EHR.Application.Repositories.Reports
|
||||||
OccupationOrg = p.OccupationOrg,
|
OccupationOrg = p.OccupationOrg,
|
||||||
OccupationTelephone = p.OccupationTelephone,
|
OccupationTelephone = p.OccupationTelephone,
|
||||||
|
|
||||||
|
CareersTotal = sb,
|
||||||
Careers = p.Careers.Select(y => new
|
Careers = p.Careers.Select(y => new
|
||||||
{
|
{
|
||||||
Position = y.Position,
|
Position = y.Position,
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,61 @@ namespace BMA.EHR.Domain.Extensions
|
||||||
sb.Append(days == 0 ? "" : $"{days} วัน ");
|
sb.Append(days == 0 ? "" : $"{days} วัน ");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
public static CalculateBetweenDateV2ValueObj? CalculateBetweenDateV2Value(this DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
if (startDate == null || endDate == null)
|
||||||
|
return null;
|
||||||
|
DateTime today = endDate;
|
||||||
|
DateTime birthDate = Convert.ToDateTime(startDate).AddDays(-1);
|
||||||
|
var years1 = birthDate;
|
||||||
|
var years2 = endDate;
|
||||||
|
var years3 = endDate.Subtract(birthDate);
|
||||||
|
var years4 = endDate.Subtract(birthDate).Ticks;
|
||||||
|
var years5 = new DateTime(endDate.Subtract(birthDate).Ticks);
|
||||||
|
var years6 = new DateTime(endDate.Subtract(birthDate).Ticks).Year;
|
||||||
|
int years = new DateTime(endDate.Subtract(birthDate).Ticks).Year - 1;
|
||||||
|
DateTime pastYearDate = birthDate.AddYears(years);
|
||||||
|
int months = 0;
|
||||||
|
for (int i = 1; i <= 12; i++)
|
||||||
|
{
|
||||||
|
if (pastYearDate.AddMonths(i) == today)
|
||||||
|
{
|
||||||
|
months = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (pastYearDate.AddMonths(i) >= today)
|
||||||
|
{
|
||||||
|
months = i - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int days = today.Subtract(pastYearDate.AddMonths(months)).Days;
|
||||||
|
if (today.Day < pastYearDate.Day)
|
||||||
|
{
|
||||||
|
if (System.DateTime.DaysInMonth(pastYearDate.Year, pastYearDate.Month) > System.DateTime.DaysInMonth(pastYearDate.AddMonths(months).Year, pastYearDate.AddMonths(months).Month))
|
||||||
|
{
|
||||||
|
days += 1;
|
||||||
|
}
|
||||||
|
if (System.DateTime.DaysInMonth(pastYearDate.Year, pastYearDate.Month) < System.DateTime.DaysInMonth(pastYearDate.AddMonths(months).Year, pastYearDate.AddMonths(months).Month))
|
||||||
|
{
|
||||||
|
days -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Clear();
|
||||||
|
sb.Append(years == 0 ? "" : $"{years} ปี ");
|
||||||
|
sb.Append(months == 0 ? "" : $"{months} เดือน ");
|
||||||
|
sb.Append(days == 0 ? "" : $"{days} วัน ");
|
||||||
|
return new CalculateBetweenDateV2ValueObj { years = years, months = months, days = days };
|
||||||
|
}
|
||||||
|
public class CalculateBetweenDateV2ValueObj
|
||||||
|
{
|
||||||
|
public int years { get; set; }
|
||||||
|
|
||||||
|
public int months { get; set; }
|
||||||
|
|
||||||
|
public int days { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
BIN
BMA.EHR.Report.Service/Reports/ผลสอบคัดเลือกรายบุคคล.trdp.bak
Normal file
BIN
BMA.EHR.Report.Service/Reports/ผลสอบคัดเลือกรายบุคคล.trdp.bak
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue