From a98300cacdf046a5364093ac4fb84148fb445880 Mon Sep 17 00:00:00 2001 From: SamSys Date: Sat, 27 Dec 2025 15:49:39 +0330 Subject: [PATCH] GetHourlyLeaveDuration --- Company.Domain/LeaveAgg/ILeaveRepository.cs | 2 +- .../Leave/ILeaveApplication.cs | 10 ++++ .../LeaveApplication.cs | 51 ++++++++++++++++++- .../Repository/LeaveRepository.cs | 6 +-- .../Client/Controllers/LeaveController.cs | 17 +++++++ 5 files changed, 81 insertions(+), 5 deletions(-) diff --git a/Company.Domain/LeaveAgg/ILeaveRepository.cs b/Company.Domain/LeaveAgg/ILeaveRepository.cs index 293114ea..ea74dd81 100644 --- a/Company.Domain/LeaveAgg/ILeaveRepository.cs +++ b/Company.Domain/LeaveAgg/ILeaveRepository.cs @@ -12,7 +12,7 @@ public interface ILeaveRepository : IRepository { EditLeave GetDetails(long id); List search(LeaveSearchModel searchModel); - OperationResult RemoveLeave(long id); + Task RemoveLeave(long id); #region Pooya List GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime start, DateTime end); diff --git a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs index 95548f1f..fa1d5a61 100644 --- a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs +++ b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs @@ -19,6 +19,7 @@ public interface ILeaveApplication GroupLeavePrintViewModel PrintPersonnelLeaveList(List id); OperationResult RemoveLeave(long id); + Task RemoveLeaveAsync(long id); LeaveViewModel LeavOnChekout(DateTime starContract, DateTime endContract, long employeeId, long workshopId); List searchClient(LeaveSearchModel search); @@ -104,6 +105,15 @@ public interface ILeaveApplication /// Task ListPrint(List ids); + + /// + /// محاسبه مدت مرخصی ساعتی + /// + /// + /// + /// + Task GetHourlyLeaveDuration(string startHours, string endHours); + } public class LeavePrintResponseViewModel diff --git a/CompanyManagment.Application/LeaveApplication.cs b/CompanyManagment.Application/LeaveApplication.cs index 2bcffefe..53d75355 100644 --- a/CompanyManagment.Application/LeaveApplication.cs +++ b/CompanyManagment.Application/LeaveApplication.cs @@ -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 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 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}"); + + } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/LeaveRepository.cs b/CompanyManagment.EFCore/Repository/LeaveRepository.cs index de080e64..97dba5ae 100644 --- a/CompanyManagment.EFCore/Repository/LeaveRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeaveRepository.cs @@ -435,15 +435,15 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository - public OperationResult RemoveLeave(long id) + public async Task 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("در بازه زمانی این مرخصی و یا بعد از آن فیش حقوقی وجود دارد"); diff --git a/ServiceHost/Areas/Client/Controllers/LeaveController.cs b/ServiceHost/Areas/Client/Controllers/LeaveController.cs index 68962504..e55c2c8f 100644 --- a/ServiceHost/Areas/Client/Controllers/LeaveController.cs +++ b/ServiceHost/Areas/Client/Controllers/LeaveController.cs @@ -122,4 +122,21 @@ public class LeaveController : ClientBaseController return Ok(leavePrints); } + /// + /// حذف مرخصی + /// + /// + /// + [HttpDelete("RemoveLeave/{id}")] + public async Task> RemoveLeaveAsync(long id) + { + var op =await _leaveApplication.RemoveLeaveAsync(id); + return Ok(new + { + isSuccedded = op.IsSuccedded, + message = op.Message, + }); + + } + }