create levave api and get rotating shift api
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
namespace CompanyManagment.App.Contracts.Leave;
|
||||
|
||||
public class CheckIsInvalidLeaveDto
|
||||
{
|
||||
/// <summary>
|
||||
/// آیا تعطیل است
|
||||
/// </summary>
|
||||
public bool IsHoliday { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// فاقد/دارای اعتبار فیش غیر رسمی
|
||||
/// </summary>
|
||||
public bool CanCreateInvalid { get; set; }
|
||||
|
||||
}
|
||||
78
CompanyManagment.App.Contracts/Leave/CreateLeaveDto.cs
Normal file
78
CompanyManagment.App.Contracts/Leave/CreateLeaveDto.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using CompanyManagment.App.Contracts.CustomizeWorkshopSettings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.Leave;
|
||||
|
||||
public class CreateLeaveDto
|
||||
{
|
||||
/// <summary>
|
||||
/// تاریخ شروع مرخصی
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "این مقدار نمی تواند خالی باشد")]
|
||||
public string StartLeave { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// تاریخ پایان مرخصی
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "این مقدار نمی تواند خالی باشد")]
|
||||
public string EndLeave { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// آی دی کارگاه
|
||||
/// </summary>
|
||||
public long WorkshopId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// آی دی پرسنل
|
||||
/// </summary>
|
||||
public long EmployeeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// نوع مدت مرخص روزانه/ ساعتی
|
||||
/// </summary>
|
||||
public PaidLeaveType PaidLeaveType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// نوع مرخصی استحقاقی/استعلاجی
|
||||
/// </summary>
|
||||
public LeaveType LeaveType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// نام کامل کارگاه
|
||||
/// </summary>
|
||||
public string WorkshopName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ساعت شروع مرخصی
|
||||
/// </summary>
|
||||
public string StartHoures { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ساعت پایان مرخصی
|
||||
/// </summary>
|
||||
public string EndHours { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// موافقت / عدم موافقت کارفرما
|
||||
/// </summary>
|
||||
public bool IsAccepted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// توضیحات
|
||||
/// </summary>
|
||||
public string Decription { get; set; }
|
||||
|
||||
|
||||
public List<CustomizeRotatingShiftsViewModel> RotatingShifts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// دارای اعتبار / فاقد اعتبار فیش غیررسمی
|
||||
/// </summary>
|
||||
public bool IsInvallid { get; set; }
|
||||
public CustomizeRotatingShiftsViewModel SelectedShift { get; set; }
|
||||
|
||||
}
|
||||
@@ -70,7 +70,33 @@ public interface ILeaveApplication
|
||||
|
||||
Task<List<LeavePrintResponseViewModel>> PrintAllAsync(List<long> ids, long workshopId);
|
||||
Task<LeavePrintResponseViewModel> PrintOneAsync(long id, long workshopId);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// چک میکند که تاریخ وارد شده در شروع مرخصی تعطیل است یا خیر
|
||||
/// دارای/فاقد اعتبار فیش غیررسمی را چک میکند
|
||||
/// </summary>
|
||||
/// <param name="startLeaveDate"></param>
|
||||
/// <param name="workshopId"></param>
|
||||
/// <returns></returns>
|
||||
Task<OperationResult<CheckIsInvalidLeaveDto>> CheckIsInvalidLeave(string startLeaveDate, long workshopId);
|
||||
|
||||
/// <summary>
|
||||
/// ایجاد مرخصی از ای پی آی
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
Task<OperationResult> CreateLeave(CreateLeaveDto command);
|
||||
|
||||
/// <summary>
|
||||
/// چک میکند که آیا پرسنل حضور غیاب دارای شیفت گردشی دارد یا خیر
|
||||
/// اگر داشت دریافت شیف گردشی
|
||||
/// </summary>
|
||||
/// <param name="workshopId"></param>
|
||||
/// <param name="employeeId"></param>
|
||||
/// <param name="startLeaveDate"></param>
|
||||
/// <returns></returns>
|
||||
Task<OperationResult<RotatingShiftDto>> HasRotatingShift(long workshopId, long employeeId, string startLeaveDate);
|
||||
|
||||
}
|
||||
|
||||
public class LeavePrintResponseViewModel
|
||||
|
||||
17
CompanyManagment.App.Contracts/Leave/PaidLeaveType.cs
Normal file
17
CompanyManagment.App.Contracts/Leave/PaidLeaveType.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace CompanyManagment.App.Contracts.Leave;
|
||||
|
||||
/// <summary>
|
||||
/// نوع مدت مرخصی
|
||||
/// </summary>
|
||||
public enum PaidLeaveType
|
||||
{
|
||||
/// <summary>
|
||||
/// روزانه
|
||||
/// </summary>
|
||||
Daily,
|
||||
|
||||
/// <summary>
|
||||
/// ساعتی
|
||||
/// </summary>
|
||||
Hourly,
|
||||
}
|
||||
17
CompanyManagment.App.Contracts/Leave/RotatingShiftDto.cs
Normal file
17
CompanyManagment.App.Contracts/Leave/RotatingShiftDto.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using CompanyManagment.App.Contracts.CustomizeWorkshopSettings;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.Leave;
|
||||
|
||||
public class RotatingShiftDto
|
||||
{
|
||||
/// <summary>
|
||||
/// آیا حضورغیاب به همراه گروهبندی گردشی دارد
|
||||
/// </summary>
|
||||
public bool HasRollCall {get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// لیست شیفت های گردشی پرسنل
|
||||
/// </summary>
|
||||
public List<CustomizeRotatingShiftsViewModel> RotatingShifts { get; set; }
|
||||
}
|
||||
@@ -1,18 +1,25 @@
|
||||
using System;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
|
||||
using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg;
|
||||
using Company.Domain.EmployeeAgg;
|
||||
using Company.Domain.HolidayItemAgg;
|
||||
using Company.Domain.LeaveAgg;
|
||||
using Company.Domain.RollCallAgg;
|
||||
using Company.Domain.RollCallServiceAgg;
|
||||
using Company.Domain.WorkshopAgg;
|
||||
using CompanyManagment.App.Contracts.CustomizeWorkshopSettings;
|
||||
using CompanyManagment.App.Contracts.HolidayItem;
|
||||
using CompanyManagment.App.Contracts.Leave;
|
||||
using CompanyManagment.App.Contracts.RollCallEmployeeStatus;
|
||||
using CompanyManagment.App.Contracts.RollCallService;
|
||||
using CompanyManagment.EFCore.Migrations;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
|
||||
using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg;
|
||||
using Company.Domain.EmployeeAgg;
|
||||
using Company.Domain.LeaveAgg;
|
||||
using Company.Domain.RollCallAgg;
|
||||
using Company.Domain.WorkshopAgg;
|
||||
using CompanyManagment.App.Contracts.Leave;
|
||||
using CompanyManagment.App.Contracts.RollCallEmployeeStatus;
|
||||
|
||||
namespace CompanyManagment.Application;
|
||||
|
||||
@@ -24,9 +31,12 @@ public class LeaveApplication : ILeaveApplication
|
||||
private readonly IRollCallRepository _rollCallRepository;
|
||||
private readonly ICustomizeWorkshopEmployeeSettingsRepository _employeeSettingsRepository;
|
||||
private readonly IRollCallEmployeeStatusApplication _rollCallEmployeeStatusApplication;
|
||||
private readonly IHolidayItemRepository _holidayItemRepository;
|
||||
private readonly IRollCallServiceRepository _rollCallServiceRepository;
|
||||
|
||||
|
||||
|
||||
public LeaveApplication(ILeaveRepository leaveRepository, IEmployeeRepository employeeRepository, IWorkshopRepository workshopRepository, IRollCallRepository rollCallRepository, ICustomizeWorkshopEmployeeSettingsRepository employeeSettingsRepository, IRollCallEmployeeStatusApplication rollCallEmployeeStatusApplication)
|
||||
public LeaveApplication(ILeaveRepository leaveRepository, IEmployeeRepository employeeRepository, IWorkshopRepository workshopRepository, IRollCallRepository rollCallRepository, ICustomizeWorkshopEmployeeSettingsRepository employeeSettingsRepository, IRollCallEmployeeStatusApplication rollCallEmployeeStatusApplication, IHolidayItemRepository holidayItemRepository, IRollCallServiceRepository rollCallServiceRepository)
|
||||
{
|
||||
_leaveRepository = leaveRepository;
|
||||
_employeeRepository = employeeRepository;
|
||||
@@ -34,6 +44,8 @@ public class LeaveApplication : ILeaveApplication
|
||||
_rollCallRepository = rollCallRepository;
|
||||
_employeeSettingsRepository = employeeSettingsRepository;
|
||||
_rollCallEmployeeStatusApplication = rollCallEmployeeStatusApplication;
|
||||
_holidayItemRepository = holidayItemRepository;
|
||||
_rollCallServiceRepository = rollCallServiceRepository;
|
||||
}
|
||||
|
||||
public OperationResult Create(CreateLeave command)
|
||||
@@ -238,7 +250,7 @@ public class LeaveApplication : ILeaveApplication
|
||||
|
||||
var employeeFullName = _employeeRepository.GetDetails(command.EmployeeId).EmployeeFullName;
|
||||
var workshopName = _workshopRepository.GetDetails(command.WorkshopId).WorkshopName;
|
||||
var leave = new Leave(start, end, totalhourses, command.WorkshopId, command.EmployeeId
|
||||
var leave = new Company.Domain.LeaveAgg.Leave(start, end, totalhourses, command.WorkshopId, command.EmployeeId
|
||||
, command.PaidLeaveType, command.LeaveType, employeeFullName, workshopName, command.IsAccepted, command.Decription,
|
||||
year, month, shiftDuration, hasShiftDuration,command.IsInvallid);
|
||||
_leaveRepository.Create(leave);
|
||||
@@ -672,5 +684,280 @@ public class LeaveApplication : ILeaveApplication
|
||||
return (await _leaveRepository.PrintAllAsync([id],workshopId)).FirstOrDefault();
|
||||
}
|
||||
|
||||
|
||||
public async Task<OperationResult<CheckIsInvalidLeaveDto>> CheckIsInvalidLeave(string startLeaveDate, long workshopId)
|
||||
{
|
||||
var op = new OperationResult<CheckIsInvalidLeaveDto>();
|
||||
var result = new CheckIsInvalidLeaveDto();
|
||||
if (startLeaveDate.TryToGeorgianDateTime(out var startLeaveDateGr) == false)
|
||||
{
|
||||
return op.Failed("تاریخ وارد شده صحیح نیست");
|
||||
}
|
||||
|
||||
if (startLeaveDateGr.DayOfWeek == DayOfWeek.Friday || _holidayItemRepository.GetHoliday(startLeaveDateGr))
|
||||
{
|
||||
result.IsHoliday = true;
|
||||
}
|
||||
|
||||
if (result.IsHoliday)
|
||||
{
|
||||
var rollCallService = _rollCallServiceRepository.GetActiveServiceByWorkshopId(workshopId);
|
||||
if (rollCallService != null)
|
||||
{
|
||||
result.CanCreateInvalid = rollCallService.HasCustomizeCheckoutService == "true";
|
||||
}
|
||||
}
|
||||
|
||||
return op.Succcedded(result);
|
||||
}
|
||||
|
||||
|
||||
public async Task<OperationResult> CreateLeave(CreateLeaveDto command)
|
||||
{
|
||||
TimeSpan shiftDuration = TimeSpan.Zero;
|
||||
bool hasShiftDuration = false;
|
||||
var startH = new TimeSpan();
|
||||
var endH = new TimeSpan();
|
||||
var op = new OperationResult();
|
||||
if ((command.PaidLeaveType == PaidLeaveType.Daily && command.LeaveType == LeaveType.PaidLeave) || command.LeaveType == LeaveType.SickLeave)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(command.StartLeave))
|
||||
{
|
||||
return op.Failed("لطفا تاریخ شروع را وارد کنید");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(command.EndLeave))
|
||||
{
|
||||
return op.Failed("لطفا تاریخ پایان را وارد کنید");
|
||||
}
|
||||
}
|
||||
else if (command.PaidLeaveType == PaidLeaveType.Hourly)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(command.StartLeave))
|
||||
return op.Failed("لطفا تاریخ شروع را وارد کنید");
|
||||
if (string.IsNullOrWhiteSpace(command.StartHoures) || string.IsNullOrWhiteSpace(command.EndHours))
|
||||
return op.Failed("ساعت شروع و پایان نمیتواند خالی باشد");
|
||||
|
||||
string pattern = @"^([01]\d|2[0-3]):[0-5]\d$";
|
||||
|
||||
if (!Regex.IsMatch(command.StartHoures, pattern))
|
||||
return op.Failed("لطفا ساعت شروع را به درستی وارد کنید");
|
||||
|
||||
if (!Regex.IsMatch(command.EndHours, pattern))
|
||||
return op.Failed("لطفا ساعت پایان را به درستی وارد کنید");
|
||||
|
||||
startH = TimeSpan.Parse(command.StartHoures);
|
||||
endH = TimeSpan.Parse(command.EndHours);
|
||||
if (startH == endH)
|
||||
return op.Failed("ساعت شروع و پایان نباید برابر باشد");
|
||||
}
|
||||
|
||||
|
||||
//if (command.LeaveType == LeaveType.SickLeave && string.IsNullOrWhiteSpace(command.StartLeave))
|
||||
// return op.Failed("لطفا تاریخ شروع را وارد کنید");
|
||||
//if (command.LeaveType == LeaveType.SickLeave && string.IsNullOrWhiteSpace(command.EndLeave))
|
||||
// return op.Failed("لطفا تاریخ پایان را وارد کنید");
|
||||
|
||||
|
||||
if (command.StartLeave.TryToGeorgianDateTime(out var start) == false)
|
||||
{
|
||||
return op.Failed("تاریخ شروع صحیح نیست");
|
||||
}
|
||||
|
||||
var end = new DateTime();
|
||||
if (command.PaidLeaveType == PaidLeaveType.Daily)
|
||||
{
|
||||
if (command.EndLeave.TryToGeorgianDateTime(out end) == false)
|
||||
{
|
||||
return op.Failed("تاریخ پایان صحیح نیست");
|
||||
}
|
||||
}
|
||||
end = start;
|
||||
|
||||
|
||||
var checkErr = _leaveRepository.CheckErrors(start, end, command.EmployeeId, command.WorkshopId, command.IsInvallid);
|
||||
|
||||
|
||||
if (checkErr.HasChekout)
|
||||
return op.Failed(checkErr.CheckoutErrMessage);
|
||||
if (checkErr.HasNotContract)
|
||||
return op.Failed(checkErr.ContractErrMessage);
|
||||
if (checkErr.HasLeftWork)
|
||||
return op.Failed(checkErr.LeftWorlErrMessage);
|
||||
|
||||
if (start > end)
|
||||
return op.Failed("تارخ شروع از پایان بزرگتر است");
|
||||
|
||||
|
||||
var totalhourses = "-";
|
||||
if (command.LeaveType == LeaveType.PaidLeave && command.PaidLeaveType == PaidLeaveType.Hourly)
|
||||
{
|
||||
|
||||
start = new DateTime(start.Year, start.Month, start.Day, startH.Hours, startH.Minutes, startH.Seconds);
|
||||
end = new DateTime(start.Year, start.Month, start.Day, endH.Hours, endH.Minutes, endH.Seconds);
|
||||
if (start > end)
|
||||
end = end.AddDays(1);
|
||||
|
||||
var totalLeavHourses = (end - start);
|
||||
var h = totalLeavHourses.Hours < 10 ? $"0{totalLeavHourses.Hours}" : $"{totalLeavHourses.Hours}";
|
||||
var m = totalLeavHourses.Minutes < 10 ? $"0{totalLeavHourses.Minutes}" : $"{totalLeavHourses.Minutes}";
|
||||
totalhourses = $"{h}:{m}";
|
||||
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی"))
|
||||
return op.Failed("برای ساعت شروع سابقه مرخصی وجود دارد");
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی"))
|
||||
return op.Failed("برای ساعت پایان سابقه مرخصی وجود دارد");
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی"))
|
||||
return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است");
|
||||
|
||||
var end24 = endH.Hours == 0 && endH.Minutes == 0 ? end.AddDays(-1) : end;
|
||||
if (_leaveRepository.Exists(x =>
|
||||
(x.StartLeave.Date == start.Date || x.EndLeave.Date == end24.Date) && (x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")))
|
||||
return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است");
|
||||
}
|
||||
else if (command.LeaveType == LeaveType.PaidLeave && command.PaidLeaveType == PaidLeaveType.Daily)
|
||||
{
|
||||
var totalLeavHourses = (end - start).TotalDays + 1;
|
||||
totalhourses = $"{(int)totalLeavHourses}";
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه"))
|
||||
return op.Failed("برای تاریخ شروع سابقه مرخصی وجود دارد");
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه"))
|
||||
return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد");
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه"))
|
||||
return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است");
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی"))
|
||||
return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است");
|
||||
|
||||
var employeeSettings = _employeeSettingsRepository.GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(command.WorkshopId, command.EmployeeId);
|
||||
|
||||
var isActive = _rollCallEmployeeStatusApplication.IsActiveInPeriod(command.EmployeeId, command.WorkshopId, start, end);
|
||||
var hasRollCall = isActive && employeeSettings.WorkshopShiftStatus == WorkshopShiftStatus.Rotating;
|
||||
if (hasRollCall)
|
||||
{
|
||||
|
||||
if ((end - start).TotalDays > 1 && employeeSettings.WorkshopShiftStatus != WorkshopShiftStatus.Regular)
|
||||
{
|
||||
return op.Failed("شما نمیتوانید بیشتر از یک روز مرخصی روزانه ثبت کنید");
|
||||
}
|
||||
|
||||
if (employeeSettings.WorkshopShiftStatus == WorkshopShiftStatus.Rotating &&
|
||||
command.SelectedShift == null)
|
||||
{
|
||||
return op.Failed("لطفا شیفت پرسنل را انتخاب کنید");
|
||||
}
|
||||
|
||||
if (command.SelectedShift != null)
|
||||
{
|
||||
var validShiftStart = TimeOnly.TryParse(command.SelectedShift.StartTime, out var shiftStart);
|
||||
var validShiftEnd = TimeOnly.TryParse(command.SelectedShift.EndTime, out var shiftEnd);
|
||||
|
||||
if (validShiftStart == false && validShiftEnd == false)
|
||||
{
|
||||
return op.Failed("شیفت های انتخاب شده معتبر نمیباشد");
|
||||
}
|
||||
|
||||
var shiftStartDateTime = new DateTime(new DateOnly(), shiftStart);
|
||||
var shiftEndDateTime = new DateTime(new DateOnly(), shiftEnd);
|
||||
if (shiftEndDateTime <= shiftStartDateTime)
|
||||
shiftEndDateTime = shiftEndDateTime.AddDays(1);
|
||||
shiftDuration = shiftEndDateTime - shiftStartDateTime;
|
||||
hasShiftDuration = true;
|
||||
}
|
||||
else if (employeeSettings is { WorkshopShiftStatus: WorkshopShiftStatus.Irregular })
|
||||
{
|
||||
if ((end - start).TotalDays > 1)
|
||||
{
|
||||
return op.Failed("شما نمیتوانید بیشتر از یک روز مرخصی روزانه ثبت کنید");
|
||||
}
|
||||
|
||||
|
||||
if (isActive)
|
||||
{
|
||||
shiftDuration = employeeSettings.IrregularShift.WorkshopIrregularShifts switch
|
||||
{
|
||||
WorkshopIrregularShifts.TwelveThirtySix => TimeSpan.FromHours(12),
|
||||
WorkshopIrregularShifts.TwelveTwentyFour => TimeSpan.FromHours(12),
|
||||
WorkshopIrregularShifts.TwentyFourFortyEight => TimeSpan.FromHours(24),
|
||||
WorkshopIrregularShifts.TwentyFourTwentyFour => TimeSpan.FromHours(24),
|
||||
_ => new TimeSpan()
|
||||
};
|
||||
hasShiftDuration = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (command.LeaveType == LeaveType.SickLeave)
|
||||
{
|
||||
var totalLeavHourses = (end - start).TotalDays + 1;
|
||||
totalhourses = $"{(int)totalLeavHourses}";
|
||||
command.PaidLeaveType = PaidLeaveType.Daily;
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه"))
|
||||
return op.Failed("برای تاریخ شروع سابقه مرخصی وجود دارد");
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه"))
|
||||
return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد");
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه"))
|
||||
return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است");
|
||||
if (_leaveRepository.Exists(x =>
|
||||
x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی"))
|
||||
return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است");
|
||||
}
|
||||
var year = Convert.ToInt32(command.StartLeave.Substring(0, 4));
|
||||
var month = Convert.ToInt32(command.StartLeave.Substring(5, 2));
|
||||
var paidLeaveType = command.PaidLeaveType == PaidLeaveType.Daily ? "روزانه" : "ساعتی";
|
||||
var leaveType = command.LeaveType == LeaveType.PaidLeave ? "استحقاقی" : "استعلاجی";
|
||||
var validation = ValidateNewLeaveWithExistingRollCalls(command.WorkshopId, command.EmployeeId, paidLeaveType, start, end);
|
||||
if (validation.IsSuccedded == false)
|
||||
return validation;
|
||||
|
||||
var employeeFullName = _employeeRepository.GetDetails(command.EmployeeId).EmployeeFullName;
|
||||
var workshopName = _workshopRepository.GetDetails(command.WorkshopId).WorkshopName;
|
||||
var leave = new Company.Domain.LeaveAgg.Leave(start, end, totalhourses, command.WorkshopId, command.EmployeeId
|
||||
, paidLeaveType, leaveType, employeeFullName, workshopName, command.IsAccepted, command.Decription,
|
||||
year, month, shiftDuration, hasShiftDuration, command.IsInvallid);
|
||||
await _leaveRepository.CreateAsync(leave);
|
||||
await _leaveRepository.SaveChangesAsync();
|
||||
return op.Succcedded();
|
||||
}
|
||||
|
||||
|
||||
public async Task<OperationResult<RotatingShiftDto>> HasRotatingShift(long workshopId,long employeeId, string startLeaveDate)
|
||||
{
|
||||
var op = new OperationResult<RotatingShiftDto>();
|
||||
var result = new RotatingShiftDto();
|
||||
if (startLeaveDate.TryToGeorgianDateTime(out var startDateTimeGr) == false)
|
||||
{
|
||||
return op.Failed("تاریخ شروع صحیح نیست");
|
||||
}
|
||||
var employeeSettings = _employeeSettingsRepository.GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(workshopId, employeeId);
|
||||
//اگر گروه بندی نداشت
|
||||
if (employeeSettings == null)
|
||||
{
|
||||
return op.Succcedded(result);
|
||||
}
|
||||
|
||||
var isActive = _rollCallEmployeeStatusApplication.IsActiveInPeriod(employeeId, workshopId, startDateTimeGr, startDateTimeGr);
|
||||
|
||||
result.HasRollCall = isActive && employeeSettings.WorkshopShiftStatus == WorkshopShiftStatus.Rotating;
|
||||
result.RotatingShifts = employeeSettings.CustomizeRotatingShifts.Select(x =>
|
||||
new CustomizeRotatingShiftsViewModel()
|
||||
{
|
||||
EndTime = x.EndTime.ToString("HH:mm"),
|
||||
StartTime = x.StartTime.ToString("HH:mm")
|
||||
}).ToList();
|
||||
return op.Succcedded(result);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using _0_Framework.Application;
|
||||
using Company.Domain.EmployeeAgg;
|
||||
using CompanyManagment.App.Contracts.InstitutionPlan;
|
||||
using CompanyManagment.App.Contracts.InsuranceList;
|
||||
using CompanyManagment.App.Contracts.Leave;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -47,14 +48,61 @@ public class LeaveController : ClientBaseController
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// چک کردن تاریخ شروع مرخصی
|
||||
/// </summary>
|
||||
/// <param name="startLeaveDate"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("CheckIsInvalidLeave")]
|
||||
public async Task<OperationResult<CheckIsInvalidLeaveDto>> CheckIsInvalidLeave(string startLeaveDate)
|
||||
{
|
||||
return await _leaveApplication.CheckIsInvalidLeave(startLeaveDate, _workshopId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ایجاد مرخصی
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("CreateLeave")]
|
||||
public async Task<ActionResult<OperationResult>> CreateLeave([FromBody] CreateLeaveDto command)
|
||||
{
|
||||
command.WorkshopId = _workshopId;
|
||||
|
||||
var result = await _leaveApplication.CreateLeave(command);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// دریافت شیفت گردشی اگر داشت
|
||||
/// </summary>
|
||||
/// <param name="startLeaveDate"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetRotatingShift")]
|
||||
public async Task<OperationResult<RotatingShiftDto>> GetRotatingShift(long employeeId, string startLeaveDate)
|
||||
{
|
||||
|
||||
return await _leaveApplication.HasRotatingShift(_workshopId, employeeId, startLeaveDate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// پرینت تکی
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("print/{id}")]
|
||||
public async Task<ActionResult<LeavePrintResponseViewModel>> PrintOneAsync(long id)
|
||||
{
|
||||
var leavePrint = await _leaveApplication.PrintOneAsync(id, _workshopId);
|
||||
return leavePrint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// پرینت گروهی
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("print")]
|
||||
public async Task<ActionResult<List<LeavePrintResponseViewModel>>> PrintAllAsync([FromQuery] List<long> ids)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user