GetHourlyLeaveDuration

This commit is contained in:
SamSys
2025-12-27 15:49:39 +03:30
parent daded35ab1
commit a98300cacd
5 changed files with 81 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ public interface ILeaveRepository : IRepository<long, Leave>
{
EditLeave GetDetails(long id);
List<LeaveViewModel> search(LeaveSearchModel searchModel);
OperationResult RemoveLeave(long id);
Task<OperationResult> RemoveLeave(long id);
#region Pooya
List<LeaveViewModel> GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime start, DateTime end);

View File

@@ -19,6 +19,7 @@ public interface ILeaveApplication
GroupLeavePrintViewModel PrintPersonnelLeaveList(List<long> id);
OperationResult RemoveLeave(long id);
Task<OperationResult> RemoveLeaveAsync(long id);
LeaveViewModel LeavOnChekout(DateTime starContract, DateTime endContract, long employeeId, long workshopId);
List<LeaveMainViewModel> searchClient(LeaveSearchModel search);
@@ -104,6 +105,15 @@ public interface ILeaveApplication
/// <returns></returns>
Task<LeaveListPrintDto> ListPrint(List<long> ids);
/// <summary>
/// محاسبه مدت مرخصی ساعتی
/// </summary>
/// <param name="startHours"></param>
/// <param name="endHours"></param>
/// <returns></returns>
Task<string> GetHourlyLeaveDuration(string startHours, string endHours);
}
public class LeavePrintResponseViewModel

View File

@@ -522,7 +522,12 @@ public class LeaveApplication : ILeaveApplication
public OperationResult RemoveLeave(long id)
{
return _leaveRepository.RemoveLeave(id);
return _leaveRepository.RemoveLeave(id).GetAwaiter().GetResult();
}
public async Task<OperationResult> RemoveLeaveAsync(long id)
{
return await _leaveRepository.RemoveLeave(id);
}
public LeaveViewModel LeavOnChekout(DateTime starContract, DateTime endContract, long employeeId, long workshopId)
@@ -966,4 +971,48 @@ public class LeaveApplication : ILeaveApplication
{
return await _leaveRepository.ListPrint(ids);
}
public async Task<string> GetHourlyLeaveDuration(string startHours, string endHours)
{
var start = new DateTime();
var end = new DateTime();
try
{
start = Convert.ToDateTime(startHours);
end = Convert.ToDateTime(endHours);
}
catch (Exception)
{
return "";
}
if (start > end || start == end)
{
end = end.AddDays(1);
}
var HourlyDate = (end - start);
var hours = (int)HourlyDate.TotalHours;
var minutes = HourlyDate.TotalMinutes % 60;
if (hours > 0 && minutes > 0)
{
return (hours + " " + "ساعت و" + " " + minutes + " " + "دقیقه");
}
else if (hours > 0 && minutes == 0)
{
return (hours + " " + "ساعت ");
}
else if (hours == 0 && minutes > 0)
{
return (minutes + " " + "دقیقه");
}
return ($"{hours}");
}
}

View File

@@ -435,15 +435,15 @@ public class LeaveRepository : RepositoryBase<long, Leave>, ILeaveRepository
public OperationResult RemoveLeave(long id)
public async Task<OperationResult> RemoveLeave(long id)
{
var op = new OperationResult();
var item = _context.LeaveList.FirstOrDefault(x => x.id == id);
if (item != null)
{
var checkoutExist = _context.CheckoutSet
var checkoutExist =await _context.CheckoutSet
.Where(x => x.WorkshopId == item.WorkshopId && x.EmployeeId == item.EmployeeId)
.Where(x => item.StartLeave <= x.ContractEnd).ToList();
.Where(x => item.StartLeave <= x.ContractEnd).ToListAsync();
if (checkoutExist.Count > 0)
{
return op.Failed("در بازه زمانی این مرخصی و یا بعد از آن فیش حقوقی وجود دارد");

View File

@@ -122,4 +122,21 @@ public class LeaveController : ClientBaseController
return Ok(leavePrints);
}
/// <summary>
/// حذف مرخصی
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("RemoveLeave/{id}")]
public async Task<ActionResult<object>> RemoveLeaveAsync(long id)
{
var op =await _leaveApplication.RemoveLeaveAsync(id);
return Ok(new
{
isSuccedded = op.IsSuccedded,
message = op.Message,
});
}
}