diff --git a/CompanyManagment.App.Contracts/Employee/DTO/CreateLeftWorkTempDtoClient.cs b/CompanyManagment.App.Contracts/Employee/DTO/CreateLeftWorkTempDtoClient.cs new file mode 100644 index 00000000..6f2158fd --- /dev/null +++ b/CompanyManagment.App.Contracts/Employee/DTO/CreateLeftWorkTempDtoClient.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace CompanyManagment.App.Contracts.Employee.DTO; + +/// +/// ایجاد ترک کار از کلاینت +/// api +/// +public class CreateLeftWorkTempDtoClient +{ + /// + /// آی دی پرسنل + /// + public long EmployeeId { get; set; } + + + /// + /// تاریخ ترک کار + /// + public string LeftWorkTime { get; set; } + + /// + /// تاریخ آخرین روز کاری + /// + public string LastDayStanding { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Employee/DTO/GetLeftWorkTempDayOfWeekDtoClient.cs b/CompanyManagment.App.Contracts/Employee/DTO/GetLeftWorkTempDayOfWeekDtoClient.cs new file mode 100644 index 00000000..7bfaa592 --- /dev/null +++ b/CompanyManagment.App.Contracts/Employee/DTO/GetLeftWorkTempDayOfWeekDtoClient.cs @@ -0,0 +1,25 @@ +namespace CompanyManagment.App.Contracts.Employee.DTO; + +public class GetLeftWorkTempDayOfWeekDtoClient +{ + /// + /// تاریخ ترک کار + /// + public string LeftWorkTime { get; set; } + + /// + /// آخرین روز کاری + /// + public string LastDayStanding { get; set; } + + + /// + /// روز هفته ترک کار + /// + public string LeftWorkTimeDayOfWeek { get; set; } + + /// + /// روز هفته اخرین روز کاری + /// + public string LastDayStandingDayOfWeek { get; set; } +} diff --git a/CompanyManagment.App.Contracts/LeftWorkTemp/ILeftWorkTempApplication.cs b/CompanyManagment.App.Contracts/LeftWorkTemp/ILeftWorkTempApplication.cs index 4bb83c56..457e28d2 100644 --- a/CompanyManagment.App.Contracts/LeftWorkTemp/ILeftWorkTempApplication.cs +++ b/CompanyManagment.App.Contracts/LeftWorkTemp/ILeftWorkTempApplication.cs @@ -1,8 +1,9 @@ -using System; +using _0_Framework.Application; +using CompanyManagment.App.Contracts.Employee.DTO; +using CompanyManagment.App.Contracts.LeftWork; +using System; using System.Collections.Generic; using System.Threading.Tasks; -using _0_Framework.Application; -using CompanyManagment.App.Contracts.LeftWork; namespace CompanyManagment.App.Contracts.LeftWorkTemp; @@ -36,6 +37,27 @@ public interface ILeftWorkTempApplication List GetLeftWorksByWorkshopId(long workshopId); + + #region ForApi + + /// + /// ایجاد ترک کار از کلاینت + /// + /// + /// + /// + Task CreateLeftWorkTempClient(CreateLeftWorkTempDtoClient command, long workshopId); + + /// + /// دریافت روز هفته برای ترک کار و اخرین روز کاری + /// + /// + /// + /// + Task GetLeftWorkTempDayOfWeekDtoClient(string leftWorkTime, + string lastDayStanding); + + #endregion } public class LeftWorkTempViewModel diff --git a/CompanyManagment.Application/LeftWorkTempApplication.cs b/CompanyManagment.Application/LeftWorkTempApplication.cs index 75a27a98..8ee0115e 100644 --- a/CompanyManagment.Application/LeftWorkTempApplication.cs +++ b/CompanyManagment.Application/LeftWorkTempApplication.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using _0_Framework.Application; +using _0_Framework.Application; using _0_Framework_b.Application; using Company.Domain.CheckoutAgg; using Company.Domain.ContractAgg; @@ -15,11 +11,17 @@ using Company.Domain.RollCallEmployeeStatusAgg; using Company.Domain.WorkshopAgg; using CompanyManagment.App.Contracts.Checkout; using CompanyManagment.App.Contracts.Contract; +using CompanyManagment.App.Contracts.Employee.DTO; using CompanyManagment.App.Contracts.LeftWork; using CompanyManagment.App.Contracts.LeftWorkTemp; using CompanyManagment.App.Contracts.ReportClient; using CompanyManagment.App.Contracts.RollCallEmployee; using CompanyManagment.EFCore.Migrations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using PersianTools.Core; using OperationResult = _0_Framework.Application.OperationResult; using Tools = _0_Framework.Application.Tools; @@ -329,4 +331,112 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication } + + + + #region ForApi + + public async Task CreateLeftWorkTempClient(CreateLeftWorkTempDtoClient command, long workshopId) + { + var op = new OperationResult(); + + #region Validation + + if (_leftWorkTempRepository.Exists(x => x.WorkshopId == workshopId && x.EmployeeId == command.EmployeeId)) + { + return op.Failed("برای پرسنل وارد شده قبلا درخواست ترک کار ثبت کرده اید"); + } + + if (command.LeftWorkTime.TryToGeorgianDateTime(out var leftWorkDateGr) == false) + { + return op.Failed("تاریخ شروع به کار وارد شده نامعتبر است"); + } + + if (command.LastDayStanding.TryToGeorgianDateTime(out var lastDayStandingDateGr) == false) + { + return op.Failed("تاریخ شروع به کار وارد شده نامعتبر است"); + } + + var leftWork = await _leftWorkRepository.GetLastLeftWork(command.EmployeeId, workshopId); + + if (lastDayStandingDateGr.AddDays(1).Date != leftWorkDateGr) + { + return op.Failed("تاریخ آخرین روز کاری با تاریخ ترک کار یک روز اختلاف ندارند"); + } + + if (leftWork == null) + { + return op.Failed("شروع به کار پرسنل یافت نشد"); + } + + if (leftWork.HasLeft) + { + return op.Failed("پرسنل وارد شده قبلا ترک کار ثبت شده است"); + } + + if (leftWork.StartWorkDate > lastDayStandingDateGr) + { + return op.Failed("تاریخ ثبت شده قبل از شروع به کار است"); + } + + if (leftWork.WorkshopId != workshopId || leftWork.EmployeeId != command.EmployeeId) + { + return op.Failed("اطلاعات وارد شده نامعتبر است"); + } + + var leftWorkTemp = LeftWorkTemp.CreateLeftWork(leftWork.id, leftWork.StartWorkDate, leftWorkDateGr, + lastDayStandingDateGr, + workshopId, command.EmployeeId, leftWork.JobId); + + await _leftWorkTempRepository.CreateAsync(leftWorkTemp); + await _leftWorkTempRepository.SaveChangesAsync(); + return op.Succcedded(); + #endregion + } + + + public async Task GetLeftWorkTempDayOfWeekDtoClient(string leftWorkTime, + string lastDayStanding) + { + var result = new GetLeftWorkTempDayOfWeekDtoClient(); + if (!string.IsNullOrWhiteSpace(leftWorkTime) && leftWorkTime.Length == 10) + { + if (leftWorkTime.TryToGeorgianDateTime(out var left) == false) + return result; + int year = Convert.ToInt32(leftWorkTime.Substring(0, 4)); + int month = Convert.ToInt32(leftWorkTime.Substring(5, 2)); + int day = Convert.ToInt32(leftWorkTime.Substring(8, 2)); + + var leftWorkTimePersian = new PersianDateTime(year, month, day); + + result.LeftWorkTime = leftWorkTime; + result.LeftWorkTimeDayOfWeek = leftWorkTimePersian.DayOfWeek; + + var lastDayStandingPersian = leftWorkTimePersian.AddDays(-1); + result.LastDayStanding = $"{lastDayStandingPersian}"; + result.LastDayStandingDayOfWeek = lastDayStandingPersian.DayOfWeek; + } + else if(!string.IsNullOrWhiteSpace(lastDayStanding) && lastDayStanding.Length == 10) + { + if (lastDayStanding.TryToGeorgianDateTime(out var lastDay) == false) + return result; + int year = Convert.ToInt32(lastDayStanding.Substring(0, 4)); + int month = Convert.ToInt32(lastDayStanding.Substring(5, 2)); + int day = Convert.ToInt32(lastDayStanding.Substring(8, 2)); + + var lastDayStandingPersian = new PersianDateTime(year, month, day); + + result.LastDayStanding = lastDayStanding; + result.LastDayStandingDayOfWeek = lastDayStandingPersian.DayOfWeek; + + + var leftWorkTimePersian = lastDayStandingPersian.AddDays(1); + result.LeftWorkTime = $"{leftWorkTimePersian}"; + result.LeftWorkTimeDayOfWeek = leftWorkTimePersian.DayOfWeek; + + } + + return result; + } + #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/EmployeeController.cs b/ServiceHost/Areas/Client/Controllers/EmployeeController.cs index effd7e1e..ac536b1b 100644 --- a/ServiceHost/Areas/Client/Controllers/EmployeeController.cs +++ b/ServiceHost/Areas/Client/Controllers/EmployeeController.cs @@ -1,6 +1,7 @@ using _0_Framework.Application; using CompanyManagment.App.Contracts.Employee; using CompanyManagment.App.Contracts.Employee.DTO; +using CompanyManagment.App.Contracts.LeftWorkTemp; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; @@ -9,11 +10,13 @@ namespace ServiceHost.Areas.Client.Controllers; public class EmployeeController:ClientBaseController { private readonly IEmployeeApplication _employeeApplication; + private readonly ILeftWorkTempApplication _leftWorkTempApplication; private readonly long _workshopId; - public EmployeeController(IEmployeeApplication employeeApplication,IAuthHelper authHelper) + public EmployeeController(IEmployeeApplication employeeApplication,IAuthHelper authHelper, ILeftWorkTempApplication leftWorkTempApplication) { _employeeApplication = employeeApplication; + _leftWorkTempApplication = leftWorkTempApplication; _workshopId = authHelper.GetWorkshopId(); } @@ -64,4 +67,29 @@ public class EmployeeController:ClientBaseController return result; } + /// + /// اعلام ترک کار + /// + /// + /// + [HttpPost] + public async Task> CreateLeftWorkTempClient([FromBody] CreateLeftWorkTempDtoClient command) + { + var result = await _leftWorkTempApplication.CreateLeftWorkTempClient(command, _workshopId); + return result; + } + + + /// + /// دریافت روز هفته برای ترک کار و اخرین روز کاری + /// + /// + [HttpGet("GetDayOfWeek")] + public async Task GetLeftWorkTempDayOfWeekDtoClient(string leftWorkTime, + string lastDayStanding) + { + var result = await _leftWorkTempApplication.GetLeftWorkTempDayOfWeekDtoClient(leftWorkTime,lastDayStanding); + return result; + } + } \ No newline at end of file