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..cdd470b2 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,23 @@ public interface ILeaveApplication /// Task ListPrint(List ids); + + /// + /// محاسبه مدت مرخصی ساعتی + /// + /// + /// + /// + Task GetHourlyLeaveDuration(string startHours, string endHours); + + /// + /// محاسبه مدت مرخصی روزانه + /// + /// + /// + /// + Task GetDailyLeaveDuration(string startDate, string endDate); + } public class LeavePrintResponseViewModel diff --git a/CompanyManagment.Application/LeaveApplication.cs b/CompanyManagment.Application/LeaveApplication.cs index 2bcffefe..92816477 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,72 @@ public class LeaveApplication : ILeaveApplication { return await _leaveRepository.ListPrint(ids); } + + + public async Task GetHourlyLeaveDuration(string startHours, string endHours) + { + if (string.IsNullOrWhiteSpace(startHours) || string.IsNullOrWhiteSpace(endHours)) + return ""; + + 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}"); + + } + + public async Task GetDailyLeaveDuration(string startDate, string endDate) + { + if (string.IsNullOrWhiteSpace(startDate) || string.IsNullOrWhiteSpace(endDate)) + return ""; + + if (startDate.TryToGeorgianDateTime(out var start) == false || endDate.TryToGeorgianDateTime(out var end) == false) + return ""; + + + + if (end >= start) + { + var daysSpan = (end - start).TotalDays + 1; + return $"{(int)daysSpan} روز"; + } + else + { + return "تاریخ پایان از تاریخ شروع کوچکتر است."; + } + } } \ 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..53dd1aca 100644 --- a/ServiceHost/Areas/Client/Controllers/LeaveController.cs +++ b/ServiceHost/Areas/Client/Controllers/LeaveController.cs @@ -48,16 +48,16 @@ public class LeaveController : ClientBaseController return Ok(result); } - /// - /// چک کردن تاریخ شروع مرخصی - /// - /// - /// - [HttpGet("CheckIsInvalidLeave")] - public async Task> CheckIsInvalidLeave(string startLeaveDate) - { - return await _leaveApplication.CheckIsInvalidLeave(startLeaveDate, _workshopId); - } + ///// + ///// چک کردن تاریخ شروع مرخصی + ///// + ///// + ///// + //[HttpGet("CheckIsInvalidLeave")] + //public async Task> CheckIsInvalidLeave(string startLeaveDate) + //{ + // return await _leaveApplication.CheckIsInvalidLeave(startLeaveDate, _workshopId); + //} /// /// ایجاد مرخصی @@ -76,6 +76,7 @@ public class LeaveController : ClientBaseController /// /// دریافت شیفت گردشی اگر داشت + /// در مودال ایجاد /// /// /// @@ -86,6 +87,35 @@ public class LeaveController : ClientBaseController return await _leaveApplication.HasRotatingShift(_workshopId, employeeId, startLeaveDate); } + + /// + /// محاسبه مدت مرخصی ساعتی + /// در مودال ایجاد + /// + /// + /// + /// + [HttpGet("GetHourlyLeaveDuration")] + public async Task> GetHourlyLeaveDuration(string startHours, string endHours) + { + var result =await _leaveApplication.GetHourlyLeaveDuration(startHours, endHours); + return Ok(new { LeaveDuration = result }); + } + + /// + /// محاسبه مدت مرخصی روزانه + /// در مودال ایجاد + /// + /// + /// + /// + [HttpGet("GetDailyLeaveDuration")] + public async Task> GetDailyLeaveDuration(string startDate, string endDate) + { + var result = await _leaveApplication.GetDailyLeaveDuration(startDate, endDate); + return Ok(new { LeaveDuration = result }); + } + /// /// پرینت تکی /// @@ -122,4 +152,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, + }); + + } + }