CreateEmployeeTemp for client completed

This commit is contained in:
SamSys
2025-12-29 19:24:53 +03:30
parent 6b6ec79faa
commit 0a7d80c2fe
5 changed files with 220 additions and 9 deletions

View File

@@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace CompanyManagment.App.Contracts.Employee.DTO;
/// <summary>
/// ایجاد ترک کار از کلاینت
/// api
/// </summary>
public class CreateLeftWorkTempDtoClient
{
/// <summary>
/// آی دی پرسنل
/// </summary>
public long EmployeeId { get; set; }
/// <summary>
/// تاریخ ترک کار
/// </summary>
public string LeftWorkTime { get; set; }
/// <summary>
/// تاریخ آخرین روز کاری
/// </summary>
public string LastDayStanding { get; set; }
}

View File

@@ -0,0 +1,25 @@
namespace CompanyManagment.App.Contracts.Employee.DTO;
public class GetLeftWorkTempDayOfWeekDtoClient
{
/// <summary>
/// تاریخ ترک کار
/// </summary>
public string LeftWorkTime { get; set; }
/// <summary>
/// آخرین روز کاری
/// </summary>
public string LastDayStanding { get; set; }
/// <summary>
/// روز هفته ترک کار
/// </summary>
public string LeftWorkTimeDayOfWeek { get; set; }
/// <summary>
/// روز هفته اخرین روز کاری
/// </summary>
public string LastDayStandingDayOfWeek { get; set; }
}

View File

@@ -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<LeftWorkTempViewModel> GetLeftWorksByWorkshopId(long workshopId);
#region ForApi
/// <summary>
/// ایجاد ترک کار از کلاینت
/// </summary>
/// <param name="command"></param>
/// <param name="workshopId"></param>
/// <returns></returns>
Task<OperationResult> CreateLeftWorkTempClient(CreateLeftWorkTempDtoClient command, long workshopId);
/// <summary>
/// دریافت روز هفته برای ترک کار و اخرین روز کاری
/// </summary>
/// <param name="leftWorkTime"></param>
/// <param name="lastDayStanding"></param>
/// <returns></returns>
Task<GetLeftWorkTempDayOfWeekDtoClient> GetLeftWorkTempDayOfWeekDtoClient(string leftWorkTime,
string lastDayStanding);
#endregion
}
public class LeftWorkTempViewModel

View File

@@ -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<OperationResult> 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> 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
}

View File

@@ -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;
}
/// <summary>
/// اعلام ترک کار
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
[HttpPost]
public async Task<ActionResult<OperationResult>> CreateLeftWorkTempClient([FromBody] CreateLeftWorkTempDtoClient command)
{
var result = await _leftWorkTempApplication.CreateLeftWorkTempClient(command, _workshopId);
return result;
}
/// <summary>
/// دریافت روز هفته برای ترک کار و اخرین روز کاری
/// </summary>
/// <returns></returns>
[HttpGet("GetDayOfWeek")]
public async Task<GetLeftWorkTempDayOfWeekDtoClient> GetLeftWorkTempDayOfWeekDtoClient(string leftWorkTime,
string lastDayStanding)
{
var result = await _leftWorkTempApplication.GetLeftWorkTempDayOfWeekDtoClient(leftWorkTime,lastDayStanding);
return result;
}
}