126 lines
4.8 KiB
C#
126 lines
4.8 KiB
C#
|
|
|
|
using _0_Framework.Application;
|
|
using Company.Domain.CustomizeCheckoutAgg;
|
|
using Company.Domain.EmployeeAgg;
|
|
using Company.Domain.LeftWorkAgg;
|
|
using Company.Domain.RollCallEmployeeAgg;
|
|
using Company.Domain.RollCallEmployeeStatusAgg;
|
|
using Company.Domain.WorkshopAgg;
|
|
using CompanyManagment.App.Contracts.CustomizeCheckout;
|
|
using CompanyManagment.App.Contracts.LeftWork;
|
|
using CompanyManagment.App.Contracts.RollCallEmployeeStatus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
|
|
namespace CompanyManagment.Application
|
|
{
|
|
public class CustomizeCheckoutApplication : ICustomizeCheckoutApplication
|
|
{
|
|
private readonly ICustomizeCheckoutRepository _customizeCheckoutRepository;
|
|
private readonly IEmployeeRepository _employeeRepository;
|
|
private readonly ILeftWorkRepository _leftWorkRepository;
|
|
private readonly IRollCallEmployeeStatusRepository _rollCallEmployeeStatusRepository;
|
|
public CustomizeCheckoutApplication(ICustomizeCheckoutRepository customizeCheckoutRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository, ILeftWorkRepository leftWorkRepository, IEmployeeRepository employeeRepository)
|
|
{
|
|
_customizeCheckoutRepository = customizeCheckoutRepository;
|
|
_rollCallEmployeeStatusRepository = rollCallEmployeeStatusRepository;
|
|
_leftWorkRepository = leftWorkRepository;
|
|
_employeeRepository = employeeRepository;
|
|
}
|
|
|
|
public IEnumerable<CustomizeCheckoutMandatoryViewModel> Search(SearchCustomizeCheckout searchModel)
|
|
{
|
|
return _customizeCheckoutRepository.Search(searchModel);
|
|
}
|
|
//public OperationResult Create(CreateCustomizeCheckout command)
|
|
//{
|
|
|
|
// OperationResult op = new();
|
|
|
|
// //validate employee
|
|
|
|
// //validate workshop
|
|
|
|
|
|
// //validate month and year
|
|
// if (command.Year < 1398 || command.Year > 1500 || command.Month < 1 || command.Month > 12)
|
|
// return op.Failed("خطای سیستمی");
|
|
|
|
// //validate parsed datetime
|
|
// var date = new DateTime(command.Year, command.Month, 1, new PersianCalendar());
|
|
|
|
// //get contract
|
|
|
|
|
|
// //validate employee rollCallStatus
|
|
// if (
|
|
|
|
|
|
// //get employeeSettings
|
|
|
|
// //get workshopSettings
|
|
|
|
// //get rewardPay
|
|
|
|
// //get loan
|
|
|
|
// //get salaryAidDeduction
|
|
|
|
// //get fineDeduction
|
|
|
|
|
|
// //get sumOfWorkingDays
|
|
|
|
// var entity = new CustomizeCheckout(contract.End, contract.Start, command.EmployeeId, command.WorkshopId, contract.Id,
|
|
// employeeSettings.Salary, employeeSettings.FridayPay, employeeSettings.OverTimePay, employeeSettings.BaseYearsPay,
|
|
// employeeSettings.BonusesPay, employeeSettings.NightWorkPay, employeeSettings.MarriedAllowance, employeeSettings.ShiftPay,
|
|
// employeeSettings.FamilyAllowance, employeeSettings.LeavePay, employeeSettings.InsuranceDeduction, employeeSettings.FineAbsenceDeduction,
|
|
// employeeSettings.LateToWork, employeeSettings.EarlyExit, rewardPay, salaryAidDeduction, installmentDeduction, fineDeduction, taxDeduction,
|
|
// sumOfWorkingDays, 0, 0, 0);
|
|
|
|
|
|
// _customizeCheckoutRepository.Create(entity);
|
|
// _customizeCheckoutRepository.SaveChanges();
|
|
// return op.Succeeded();
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
public List<(long Id, string Name)> GetWorkshopEmployeesEligibleForCheckoutInDates(long workshopId, int yearFa, int monthFa)
|
|
{
|
|
|
|
var startDateFa = $"{yearFa:0000}/{monthFa:00}/01";
|
|
if (startDateFa.TryToGeorgianDateTime(out var startDateGr) == false)
|
|
return new();
|
|
|
|
startDateGr.FindFirstDayOfNextMonth(out var endDateGr);
|
|
endDateGr = endDateGr.AddDays(-1);
|
|
|
|
|
|
if (startDateGr.Date > DateTime.Now.Date)
|
|
return new();
|
|
|
|
if (endDateGr.Date > DateTime.Now.Date)
|
|
endDateGr = DateTime.Now.Date;
|
|
|
|
|
|
List<RollCallEmployeeStatusViewModel> rollCallEmployeeStatus = _rollCallEmployeeStatusRepository.GetActiveByWorkshopIdInDate(workshopId, startDateGr, endDateGr);
|
|
|
|
List<LeftWorkViewModel> leftWorks = _leftWorkRepository.GetByWorkshopIdInDates(workshopId, startDateGr, endDateGr);
|
|
|
|
rollCallEmployeeStatus = rollCallEmployeeStatus
|
|
.Where(x => leftWorks.Any(y => y.EmployeeId == x.EmployeeId && y.StartWorkDateGr.Date <= x.StartDateGr.Date &&
|
|
y.LeftWorkDateGr.Date > x.EndDateGr.Date)).ToList();
|
|
|
|
var employees = _employeeRepository.SimpleGetRangeByIds(rollCallEmployeeStatus.Select(x => x.EmployeeId));
|
|
return employees;
|
|
}
|
|
|
|
}
|
|
}
|