add client checkout list controller

This commit is contained in:
2026-01-18 12:51:58 +03:30
parent 8ec13ffae1
commit 63a3027a17
5 changed files with 539 additions and 413 deletions

View File

@@ -80,4 +80,6 @@ public interface ICheckoutRepository : IRepository<long, Checkout>
#endregion
Task<Checkout> GetByWorkshopIdEmployeeIdInDate(long workshopId, long employeeId, DateTime inDate);
Task<PagedResult<CheckoutListClientDto>> GetListForClient(long workshopId,
CheckoutListClientSearchModel searchModel);
}

View File

@@ -62,4 +62,40 @@ public interface ICheckoutApplication
long workshopId, DateTime start, DateTime end);
#endregion
Task<PagedResult<CheckoutListClientDto>> GetListForClient(long workshopId,
CheckoutListClientSearchModel searchModel);
}
public class CheckoutListClientSearchModel:PaginationRequest
{
public long? EmployeeId { get; set; }
public string Year { get; set; }
public string Month { get; set; }
public string StartDate { get; set; }
public string EndDate { get; set; }
public CheckoutClientListOrderType? OrderType { get; set; }
}
public class CheckoutListClientDto
{
public long Id { get; set; }
public string Year { get; set; }
public string Month { get; set; }
public string EmployeeName { get; set; }
public string ContractNo { get; set; }
public string ContractStart { get; set; }
public string ContractEnd { get; set; }
public bool Signature { get; set; }
}
public enum CheckoutClientListOrderType
{
ByCheckoutCreationDate,
BySignedCheckout,
ByUnSignedCheckout,
ByPersonnelCode,
ByPersonnelCodeDescending,
ByCheckoutStartDate,
ByCheckoutStartDateDescending
}

View File

@@ -706,5 +706,10 @@ public class CheckoutApplication : ICheckoutApplication
return _checkoutRepository.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, start, end);
}
public async Task<PagedResult<CheckoutListClientDto>> GetListForClient(long workshopId,CheckoutListClientSearchModel searchModel)
{
return await _checkoutRepository.GetListForClient(workshopId, searchModel);
}
#endregion
}

View File

@@ -7,6 +7,7 @@ using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Threading.Tasks;
using _0_Framework.Application;
using _0_Framework.Exceptions;
using _0_Framework.InfraStructure;
using Company.Domain.CheckoutAgg;
using Company.Domain.LeftWorkAgg;
@@ -50,9 +51,11 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
private readonly IRollCallMandatoryRepository _rollCallMandatoryRepository;
private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository;
public CheckoutRepository(IAuthHelper authHelper, CompanyContext context, IConfiguration configuration, ILeftWorkRepository leftWorkRepository, IWorkingHoursTempApplication workingHoursTempApplication, IRollCallRepository rollCallRepository, IRollCallMandatoryRepository rollCallMandatoryRepository, IRollCallEmployeeRepository rollCallEmployeeRepository) : base(context)
public CheckoutRepository(IAuthHelper authHelper, CompanyContext context, IConfiguration configuration,
ILeftWorkRepository leftWorkRepository, IWorkingHoursTempApplication workingHoursTempApplication,
IRollCallRepository rollCallRepository, IRollCallMandatoryRepository rollCallMandatoryRepository,
IRollCallEmployeeRepository rollCallEmployeeRepository) : base(context)
{
_authHelper = authHelper;
_context = context;
_configuration = configuration;
@@ -71,7 +74,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
/// <param name="سال به صورت رشته عددی"></param>
/// <param name="ماه بصورت رشته عددی"></param>
/// <returns></returns>
public (bool hasChekout, double FamilyAlloance, double OverTimePay, double RotatingShift, double Nightwork, double Fridaywork, double YraesPay) HasCheckout(long workshopId, long employeId, string year, string month)
public (bool hasChekout, double FamilyAlloance, double OverTimePay, double RotatingShift, double Nightwork, double
Fridaywork, double YraesPay) HasCheckout(long workshopId, long employeId, string year, string month)
{
var farisMonthName = Tools.ToFarsiMonthByNumber(month);
@@ -90,7 +94,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
}
return (true, res.FamilyAllowance, res.OvertimePay, res.ShiftPay, res.NightworkPay, res.FridayPay,res.YearsPay);
return (true, res.FamilyAllowance, res.OvertimePay, res.ShiftPay, res.NightworkPay, res.FridayPay,
res.YearsPay);
}
public EditCheckout GetDetails(long id)
@@ -136,7 +141,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
ContractEndGr = x.ContractEnd,
ContractStart = x.ContractStart.ToFarsi(),
ContractEnd = x.ContractEnd.ToFarsi()
})
.FirstOrDefault(x => x.Id == id);
}
@@ -152,7 +156,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
/// <param name="contractEnd"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<CreateCheckoutListViewModel> GetContractResultToCreateCheckout(long workshopId, long employeeId, string year, string month, string contractStart,
public async Task<CreateCheckoutListViewModel> GetContractResultToCreateCheckout(long workshopId, long employeeId,
string year, string month, string contractStart,
string contractEnd)
{
DateTime startSreach;
@@ -165,7 +170,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
}
else
{
if (month == "0" && year == "0")
{
DateTime now = DateTime.Now;
@@ -195,8 +199,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
startSreach = startStr.ToGeorgianDateTime();
endSearch = (startStr.FindeEndOfMonth()).ToGeorgianDateTime();
}
}
var timer = new Stopwatch();
timer.Start();
@@ -211,7 +215,9 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
contractWorkshop => contractWorkshop.contract.EmployeeId,
employee => employee.id,
(contractWorkshop, employee) => new { contractWorkshop, employee })
.Join(_context.LeftWorkList.AsSplitQuery().Where(l => l.WorkshopId == workshopId && l.StartWorkDate < endSearch && l.LeftWorkDate > startSreach),
.Join(
_context.LeftWorkList.AsSplitQuery().Where(l =>
l.WorkshopId == workshopId && l.StartWorkDate < endSearch && l.LeftWorkDate > startSreach),
contractWorkshopEmployee => contractWorkshopEmployee.contractWorkshop.contract.EmployeeId,
leftwork => leftwork.EmployeeId,
(contractWorkshopEmployee, leftwork) => new { contractWorkshopEmployee, leftwork })
@@ -221,16 +227,15 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
personnelCode => personnelCode.EmployeeId,
(contractWorkshopEmployeeleftWork, personnelCode) =>
new { contractWorkshopEmployeeleftWork, personnelCode })
.GroupJoin(_context.CheckoutSet.AsSplitQuery(),
contractWorkshopEmployeeleftWorkPersonnelCode => contractWorkshopEmployeeleftWorkPersonnelCode
.contractWorkshopEmployeeleftWork.contractWorkshopEmployee.contractWorkshop.contract.id,
checkout => checkout.ContractId,
(contractWorkshopEmployeeleftWorkPersonnelCode, checkout) =>
new { contractWorkshopEmployeeleftWorkPersonnelCode, checkout })
.GroupJoin(_context.EmployeeComputeOptionsSet.Where(o => o.WorkshopId == workshopId),
x => x.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork.leftwork.EmployeeId,
x => x.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork.leftwork
.EmployeeId,
option => option.EmployeeId,
(x, options) => new { x.checkout, x.contractWorkshopEmployeeleftWorkPersonnelCode, options })
.SelectMany(
@@ -250,11 +255,11 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
DateTime currentStart = ($"{DateTime.Now.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime();
DateTime currentEnd = ($"{DateTime.Now.ToFarsi().FindeEndOfMonth()}").ToGeorgianDateTime();
var chekoutCreated = result.checkout.FirstOrDefault(x => x.ContractStart < endSearch && x.ContractEnd > startSreach && x.IsActiveString == "true");
var chekoutCreated = result.checkout.FirstOrDefault(x =>
x.ContractStart < endSearch && x.ContractEnd > startSreach && x.IsActiveString == "true");
if (chekoutCreated != null)
{
return new CreateCheckoutListViewModel
{
Id = chekoutCreated.ContractId,
@@ -273,6 +278,7 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
EmployeeHasCreateCheckout = true
};
}
var employeeJoin = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
.contractWorkshopEmployee.employee.id;
@@ -283,11 +289,13 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
var startStatusSearch = leftWork.StartWorkDate > startSreach && leftWork.StartWorkDate <= endSearch
? leftWork.StartWorkDate
: startSreach;
var endStatusSearch = leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch
var endStatusSearch = leftWork.HasLeft && leftWork.LeftWorkDate > startSreach &&
leftWork.LeftWorkDate <= endSearch
? leftWork.LeftWorkDate.AddDays(-1)
: startSreach;
bool hasRollCall =
_rollCallEmployeeRepository.HasRollCallRecord(employeeJoin, workshopId, startStatusSearch, endStatusSearch);
_rollCallEmployeeRepository.HasRollCallRecord(employeeJoin, workshopId, startStatusSearch,
endStatusSearch);
bool extension = true;
bool laterThanEnd = false;
@@ -300,11 +308,11 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
.contractWorkshopEmployee.contractWorkshop.contract.ContarctStart;
var contractEndGr = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
.contractWorkshopEmployee.contractWorkshop.contract.ContractEnd;
#region HasRollCall
if (hasRollCall)
{
// اگر ترک کار کرده بود
// اگر ترک کارش در بازه انتخاب شده بود
if (leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch)
@@ -322,7 +330,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
? leftWork.StartWorkDate.ToFarsi()
: startSreach.ToFarsi();
contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi();
}
else
{
@@ -334,7 +341,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
? leftWork.StartWorkDate.ToFarsi()
: startSreach.ToFarsi();
contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi();
}
}
else if (endSearch < currentStart)
@@ -357,7 +363,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
: startSreach.ToFarsi();
contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi();
}
}
else if (leftWork.HasLeft && leftWork.LeftWorkDate <= startSreach)
{
@@ -365,7 +370,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
extension = false;
description = "به دلیل ترک کار پیش از تاریخ انتخاب شده مجاز به ایجاد فیش نمی باشید";
leftWorkDate = leftWork.LeftWorkDate.ToFarsi();
}
else if (!leftWork.HasLeft && startSreach == currentStart)
{
@@ -376,13 +380,9 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
? leftWork.StartWorkDate.ToFarsi()
: startSreach.ToFarsi();
contractEnd = endSearch.ToFarsi();
}
else if (!leftWork.HasLeft && startSreach < currentStart)
{
if (contractStartGr <= startSreach && contractStartGr > endSearch)
{
laterThanEnd = true;
@@ -397,12 +397,11 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
contractStart = leftWork.StartWorkDate > startSreach
? leftWork.StartWorkDate.ToFarsi()
: startSreach.ToFarsi();
contractEnd = (leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch) ? leftWork.LeftWorkDate.AddDays(-1).ToFarsi() : endSearch.ToFarsi();
contractEnd = (leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch)
? leftWork.LeftWorkDate.AddDays(-1).ToFarsi()
: endSearch.ToFarsi();
}
}
}
#endregion
@@ -468,13 +467,11 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
contractEnd = endSearch.ToFarsi();
}
}
}
#endregion
return new CreateCheckoutListViewModel
{
Id = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
@@ -498,15 +495,14 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
ContractStart = contractStart,
ContractEnd = contractEnd,
LeftWorkDate = leftWorkDate,
EmployeeHasCreateCheckout = result.option != null ? result.option.CreateCheckout : result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork.contractWorkshopEmployee.contractWorkshop.workshop.CreateCheckout
EmployeeHasCreateCheckout = result.option != null
? result.option.CreateCheckout
: result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
.contractWorkshopEmployee.contractWorkshop.workshop.CreateCheckout
};
}).Where(x => x.EmployeeHasCreateCheckout).OrderByDescending(x => x.Extension).ToList();
Console.WriteLine("process : " + timer.Elapsed);
return new CreateCheckoutListViewModel()
@@ -517,7 +513,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
public async Task CreateCkeckout(Checkout command)
{
var creationDates = DateTime.Now;
//var result = await _context.Database.ExecuteSqlInterpolatedAsync($"EXEC InsertQuery_Checkout {id},{employeeFullName},{isActiveString},{signature},{fathersName},{nationalCode},{dateOfBirth},{employeeId},{workshopName},{workshopId},{contractNo},{contractStart},{contractEnd},{month},{year},{contractId},{workingHoursId},{monthlySalary},{baseYearsPay},{consumableItems},{housingAllowance},{overtimePay},{nightworkPay},{fridayPay},{missionPay},{shiftPay},{familyAllowance},{bonusesPay},{yearsPay},{leavePay},{insuranceDeduction},{taxDeducation},{installmentDeduction},{salaryAidDeduction},{absenceDeduction},{creationDate},{archiveCode},{personnelCode},{sumOfWorkingDays},{totalClaims},{taxDeducation},{totalPayment}");
@@ -536,7 +531,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
if (command.HasInsuranceShareTheSameAsList)
entity.SetInsuranceShare();
await _context.SaveChangesAsync();
}
@@ -678,9 +672,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
query = query.Where(x => x.ContractStartGr >= startyearGr && x.ContractEndGr <= endYearGr).ToList();
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
return query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt).ToList();
}
else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) &&
string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
@@ -799,7 +790,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
endDate >= x.ContractEndGr && startDate < x.ContractEndGr).ToList();
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
return query.OrderBy(x => x.PersonnelCodeInt).ToList();
}
else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
!string.IsNullOrWhiteSpace(searchModel.ContractEnd) &&
@@ -813,17 +803,12 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
return query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt).ToList();
}
return query.OrderByDescending(x => x.Id)
.ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).Take(100).ToList();
//foreach(var items in query)
//{
// var employeId = _context.WorkshopEmployers?.Where(x => x.WorkshopId == items.WorkshopId)
@@ -865,7 +850,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
ContractNo = x.ContractNo,
ContractId = x.ContractId,
HasRollCall = x.HasRollCall
});
if (searchModel.EmployeeId != 0 && searchModel.WorkshopId != 0)
@@ -884,11 +868,12 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
{
var start = searchModel.ContractStart.ToGeorgianDateTime();
var end = searchModel.ContractEnd.ToGeorgianDateTime();
query = query.Where(x => x.ContractStartGr == start && x.ContractEndGr == end && x.EmployeeId == searchModel.EmployeeId && x.WorkshopId == searchModel.WorkshopId);
query = query.Where(x =>
x.ContractStartGr == start && x.ContractEndGr == end && x.EmployeeId == searchModel.EmployeeId &&
x.WorkshopId == searchModel.WorkshopId);
}
return query.OrderBy(x => x.ContractStartGr).ToList();
}
public List<CheckoutViewModel> PrintAll(List<long> id)
@@ -969,7 +954,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
SalaryAidDateTimeFa = s.SalaryAidDateTimeFa,
SalaryAidDateTimeGe = s.SalaryAidDateTime
}).ToList(),
CheckoutRollCall = item.CheckoutRollCall != null ? new CheckoutRollCallViewModel()
CheckoutRollCall = item.CheckoutRollCall != null
? new CheckoutRollCallViewModel()
{
TotalPresentTimeSpan = item.CheckoutRollCall.TotalPresentTimeSpan,
TotalBreakTimeSpan = item.CheckoutRollCall.TotalBreakTimeSpan,
@@ -977,7 +963,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
TotalPaidLeaveTmeSpan = item.CheckoutRollCall.TotalPaidLeaveTmeSpan,
TotalMandatoryTimeSpan = item.CheckoutRollCall.TotalMandatoryTimeSpan,
TotalSickLeaveTimeSpan = item.CheckoutRollCall.TotalSickLeaveTimeSpan,
RollCallDaysCollection = item.CheckoutRollCall.RollCallDaysCollection.Select(d => new CheckoutRollCallDayViewModel()
RollCallDaysCollection = item.CheckoutRollCall.RollCallDaysCollection.Select(d =>
new CheckoutRollCallDayViewModel()
{
WorkingTimeSpan = d.WorkingTimeSpan,
BreakTimeSpan = d.BreakTimeSpan,
@@ -994,11 +981,12 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
SecondEndDate = d.SecondEndDate,
SecondStartDate = d.SecondStartDate,
}).ToList(),
} : null,
}
: null,
HasAmountConflict = item.HasAmountConflict,
EmployeeMandatoryHoursTimeSpan = item.EmployeeMandatoryHours,
EmployeeMandatoryHoursStr = Tools.ToFarsiHoursAndMinutes(Convert.ToInt32(item.EmployeeMandatoryHours.TotalHours),item.EmployeeMandatoryHours.Minutes,"-")
EmployeeMandatoryHoursStr = Tools.ToFarsiHoursAndMinutes(
Convert.ToInt32(item.EmployeeMandatoryHours.TotalHours), item.EmployeeMandatoryHours.Minutes, "-")
};
var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId);
ch.WorkshopName = workshopName.WorkshopName;
@@ -1122,9 +1110,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
var totalPaidLeaveTimeSpans = hourlyPaidLeaveTimeSpans.Concat(dailyPaidLeaveTimeSpans);
ch.TotalHourlyLeave = new TimeSpan(hourlyPaidLeaveTimeSpans.Sum(x => x.Ticks));
ch.TotalPaidLeave = new TimeSpan(totalPaidLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-");
ch.TotalPaidLeave =
new TimeSpan(totalPaidLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-");
#endregion
@@ -1142,7 +1129,9 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
ch.TotalBreakTimeStr = ch.CheckoutRollCall.TotalBreakTimeSpan.ToFarsiHoursAndMinutes("-");
ch.TotalPresentTimeStr = ch.CheckoutRollCall.TotalPresentTimeSpan.ToFarsiHoursAndMinutes("-");
ch.TotalMandatoryTimeStr = ch.CheckoutRollCall.TotalMandatoryTimeSpan.ToFarsiHoursAndMinutes("-");
ch.TotalPaidLeave = Tools.ToFarsiHoursAndMinutes(Convert.ToInt32(ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.TotalHours), ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.Minutes, "-");
ch.TotalPaidLeave = Tools.ToFarsiHoursAndMinutes(
Convert.ToInt32(ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.TotalHours),
ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.Minutes, "-");
ch.MonthlyRollCall = ch.CheckoutRollCall.RollCallDaysCollection
.Select(x => new CheckoutDailyRollCallViewModel
{
@@ -1163,13 +1152,12 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
BreakTimeString = $"{(int)(x.BreakTimeSpan.TotalHours)}:{x.BreakTimeSpan.Minutes:00}",
RollCallDateFa = x.Date.ToFarsi()
}).ToList();
}
else
{
if (ch.HasRollCall)
ch.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(ch.EmployeeId, ch.WorkshopId, ch.ContractStartGr, ch.ContractEndGr);
ch.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(ch.EmployeeId, ch.WorkshopId,
ch.ContractStartGr, ch.ContractEndGr);
else
{
ch.CreateWorkingHoursTemp.ContractStartGr = ch.ContractStartGr;
@@ -1178,9 +1166,11 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
ch.CreateWorkingHoursTemp.ContractEnd = ch.ContractEndGr.ToFarsi();
ch.CreateWorkingHoursTemp.EmployeeId = ch.EmployeeId;
ch.CreateWorkingHoursTemp.WorkshopId = ch.WorkshopId;
ch.MonthlyRollCall = ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking);
ch.MonthlyRollCall =
ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking);
}
}
query.Add(ch);
}
@@ -1191,6 +1181,7 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
printNumer += 1;
rec.PrintCounter = printNumer;
}
return query;
}
@@ -1216,7 +1207,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
Id = x.id,
EmployerFullName = x.FName + " " + x.LName,
IsLegal = x.IsLegal,
}).Where(x => emp.Contains(x.Id)).ToList();
if (employerlist.Count > 0)
{
@@ -1245,7 +1235,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
//}
var leaveList = _context.LeaveList.Where(x => x.WorkshopId == ch.WorkshopId && x.EmployeeId == ch.EmployeeId && x.LeaveType == "استحقاقی");
var leaveList = _context.LeaveList.Where(x =>
x.WorkshopId == ch.WorkshopId && x.EmployeeId == ch.EmployeeId && x.LeaveType == "استحقاقی");
var leaveViewModel = new List<LeaveViewModel>();
foreach (var list in leaveList)
@@ -1370,7 +1361,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
SalaryAidDateTimeFa = s.SalaryAidDateTimeFa,
SalaryAidDateTimeGe = s.SalaryAidDateTime
}).ToList(),
}).SingleOrDefault(x => x.Id == id);
var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId);
@@ -1390,6 +1380,7 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
};
employers.Add(employer);
}
ch.MaritalStatus = _context.Employees.Find(ch.EmployeeId)?.MaritalStatus;
ch.EmployerList = employers;
var workingHours = _workingHoursTempApplication.GetByContractIdConvertToShiftwork4(ch.ContractId);
@@ -1484,7 +1475,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
ch.TotalSickLeave = new TimeSpan(sickLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-");
var hourlyPaidLeaveTimeSpans = hourlyPaidLeave.Select(x => TimeOnly.Parse(x.LeaveHourses).ToTimeSpan()).ToList();
var hourlyPaidLeaveTimeSpans =
hourlyPaidLeave.Select(x => TimeOnly.Parse(x.LeaveHourses).ToTimeSpan()).ToList();
var dailyPaidLeaveTimeSpans = dailyPaidLeave.Select(x =>
{
@@ -1497,20 +1489,19 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
ch.TotalHourlyLeave = new TimeSpan(hourlyPaidLeaveTimeSpans.Sum(x => x.Ticks));
ch.TotalPaidLeave = new TimeSpan(totalPaidLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-");
#endregion
if (ch.TotalPaymentHide == false)
{
ch.TotalClaims = "";
ch.TotalDeductions = "";
ch.TotalPayment = "";
}
if (ch.HasRollCall)
ch.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(ch.EmployeeId, ch.WorkshopId, ch.ContractStartGr, ch.ContractEndGr);
ch.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(ch.EmployeeId, ch.WorkshopId,
ch.ContractStartGr, ch.ContractEndGr);
else
{
ch.CreateWorkingHoursTemp.ContractStartGr = ch.ContractStartGr;
@@ -1519,12 +1510,15 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
ch.CreateWorkingHoursTemp.ContractEnd = ch.ContractEndGr.ToFarsi();
ch.CreateWorkingHoursTemp.EmployeeId = ch.EmployeeId;
ch.CreateWorkingHoursTemp.WorkshopId = ch.WorkshopId;
ch.MonthlyRollCall = ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking);
ch.MonthlyRollCall =
ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking);
}
return ch;
}
private List<CheckoutDailyRollCallViewModel> ConvertStaticToRollCall(CreateWorkingHoursTemp workingHours, bool workshopHolidayWorking)
private List<CheckoutDailyRollCallViewModel> ConvertStaticToRollCall(CreateWorkingHoursTemp workingHours,
bool workshopHolidayWorking)
{
var rollCalls = _rollCallMandatoryRepository.ConvertStaticHoursToRollCall(workingHours,
workshopHolidayWorking);
@@ -1557,7 +1551,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
int dateRange = (int)(lastDayOfCurrentMonth - firstDayOfCurrentMonth).TotalDays + 1;
var holidays = _context.HolidayItems.Where(x => x.HolidayYear.Contains(year.ToString())).Select(x => new HolidayItemViewModel
var holidays = _context.HolidayItems.Where(x => x.HolidayYear.Contains(year.ToString())).Select(x =>
new HolidayItemViewModel
{
Id = x.id,
Holidaydate = x.Holidaydate.ToFarsi(),
@@ -1570,7 +1565,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
holidays = [];
//all the dates from start to end, to be compared with present days to get absent dates
var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => startMonthDay.AddDays(offset).Date).ToList();
var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => startMonthDay.AddDays(offset).Date)
.ToList();
var absentRecords = completeDaysList
.ExceptBy(rollCalls.Select(x => x.ShiftDate.Date), y => y.Date)
@@ -1596,11 +1592,13 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
var presentDays = rollCalls.GroupBy(x => x.ShiftDate.Date).Select(x =>
{
var orderedRollcalls = x.OrderBy(y => y.ShiftDate).ToList();
var rollCallTimeSpanPerDay =
new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => y.ShiftEndWithoutRest == null ? (y.EndDate - y.StartDate).Value!.Ticks : (y.ShiftEndWithoutRest - y.StartDate)!.Value.Ticks));
new TimeSpan(x.Where(y => y.EndDate != null).Sum(y =>
y.ShiftEndWithoutRest == null
? (y.EndDate - y.StartDate).Value!.Ticks
: (y.ShiftEndWithoutRest - y.StartDate)!.Value.Ticks));
var breakTimePerDay = new TimeSpan(x.Sum(r => r.BreakTimeSpan.Ticks));
var firstRollCall = orderedRollcalls.FirstOrDefault();
@@ -1614,7 +1612,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
secondRCEndDate = secondRollCall.ShiftEndWithoutRest ?? secondRollCall.EndDate;
return new CheckoutDailyRollCallViewModel()
{
StartDate1 = firstRollCall?.StartDate?.ToString("HH:mm") ?? "",
@@ -1686,12 +1683,15 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
{
return new List<CheckoutViewModel>();
}
var employers =
_context.Employers.Where(x => x.ContractingPartyId == contracingPartyAcc.PersonalContractingPartyId).Select(x => x.id).ToList();
_context.Employers.Where(x => x.ContractingPartyId == contracingPartyAcc.PersonalContractingPartyId)
.Select(x => x.id).ToList();
if (employers.Count < 1)
{
return new List<CheckoutViewModel>();
}
var workshopIds = _context.WorkshopEmployers.Where(x => employers.Contains(x.EmployerId))
.Select(x => x.WorkshopId).ToList();
var checkValid = workshopIds.Any(x => x == searchModel.WorkshopId);
@@ -1699,7 +1699,9 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
{
return new List<CheckoutViewModel>();
}
#endregion
var query = _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList)
.AsSplitQuery().Select(x => new CheckoutViewModel()
{
@@ -1741,9 +1743,7 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
{
WarningMessage = wm.WarningMessage,
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
}).ToList()
}).Where(x => x.WorkshopId == searchModel.WorkshopId);
if (searchModel.EmployeeId > 0)
{
@@ -1857,16 +1857,20 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
default:
y2 = $"{searchModel.Year}/{searchModel.Month}/29";
break;
}
}
var start = y.ToGeorgianDateTime();
var end = y2.ToGeorgianDateTime();
query = query.Where(x => x.ContractStartGr >= start && x.ContractStartGr < end && x.ContractEndGr > start && x.ContractEndGr <= end ||
x.ContractStartGr <= start && x.ContractEndGr >= end || start <= x.ContractStartGr && end > x.ContractStartGr || end >= x.ContractEndGr && start < x.ContractEndGr);
query = query.Where(x =>
x.ContractStartGr >= start && x.ContractStartGr < end && x.ContractEndGr > start &&
x.ContractEndGr <= end ||
x.ContractStartGr <= start && x.ContractEndGr >= end ||
start <= x.ContractStartGr && end > x.ContractStartGr ||
end >= x.ContractEndGr && start < x.ContractEndGr);
}
if (searchModel.SearchAll)
return query.OrderByDescending(x => x.Id).ToList();
switch (searchModel.Sorting)
@@ -1897,8 +1901,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
break;
default: return query.OrderByDescending(x => x.Id).Skip(searchModel.PageIndex).Take(30).ToList();
}
}
#endregion
@@ -1928,12 +1930,10 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
try
{
var checkout = _context.CheckoutSet.Where(x => x.id == id)?.FirstOrDefault();
_context.CheckoutSet.Remove(checkout);
_context.SaveChanges();
return op.Succcedded(-1, "حذف با موفقیت انجام شد.");
}
catch (Exception)
{
@@ -1951,6 +1951,7 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
notRemoveList.Add(item);
}
}
return notRemoveList;
}
@@ -2010,7 +2011,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
// );
var checkouts =
_context.CheckoutSet.Include(w=>w.CheckoutWarningMessageList).Where(x => workshopAcounts.Contains(x.WorkshopId))
_context.CheckoutSet.Include(w => w.CheckoutWarningMessageList)
.Where(x => workshopAcounts.Contains(x.WorkshopId))
.Join(_context.Workshops.AsSplitQuery(),
ch => ch.WorkshopId,
workshop => workshop.id,
@@ -2033,7 +2035,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
{
res.ch,
res.workshop,
option = _context.EmployeeComputeOptionsSet.FirstOrDefault(x=>x.WorkshopId == res.ch.WorkshopId &&x.EmployeeId == res.ch.EmployeeId),
option = _context.EmployeeComputeOptionsSet.FirstOrDefault(x =>
x.WorkshopId == res.ch.WorkshopId && x.EmployeeId == res.ch.EmployeeId),
res.workshopEmployer,
contractingParty = _context.PersonalContractingParties
.Include(p => p.Employers)
@@ -2050,15 +2053,18 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
hasEmployeeOrWorkshpSearch = true;
checkouts = checkouts.Where(x => x.ch.WorkshopId == searchModel.WorkshopId);
}
if (searchModel.EmployeeId != 0)
{
hasEmployeeOrWorkshpSearch = true;
checkouts = checkouts.Where(x => x.ch.EmployeeId == searchModel.EmployeeId);
}
if (searchModel.EmployerId != 0)
{
hasEmployeeOrWorkshpSearch = true;
checkouts = checkouts.Where(x => x.contractingParty.Employers.Select(c => c.id).Contains(searchModel.EmployerId));
checkouts = checkouts.Where(x =>
x.contractingParty.Employers.Select(c => c.id).Contains(searchModel.EmployerId));
}
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo))
@@ -2068,7 +2074,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
}
//if (searchModel.IsActiveString == null)
//{
// checkouts = checkouts.Where(x => x.ch.IsActiveString == "true");
@@ -2100,7 +2105,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
checkouts = checkouts.Where(x => x.ch.ContractStart >= startyearGr && x.ch.ContractEnd <= endYearGr);
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
checkouts = checkouts.OrderByDescending(x => x.ch.ContractEnd);
}
else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) &&
string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
@@ -2220,7 +2224,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
endDate >= x.ch.ContractEnd && startDate < x.ch.ContractEnd);
//if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
// checkouts = checkouts.OrderBy(x => x.ch.PersonnelCodeInt);
}
else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
!string.IsNullOrWhiteSpace(searchModel.ContractEnd) &&
@@ -2240,22 +2243,20 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
if (!string.IsNullOrEmpty(searchModel.EmployeeName))
{
hasSearch = true;
var employeeList = _context.Employees.Where(x => (!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchModel.EmployeeName)) ||
(!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchModel.EmployeeName))).Select(x => x.id).ToList();
var employeeList = _context.Employees.Where(x =>
(!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchModel.EmployeeName)) ||
(!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchModel.EmployeeName))).Select(x => x.id)
.ToList();
checkouts = checkouts.Where(x => employeeList.Contains(x.ch.EmployeeId));
}
#endregion
if (!hasSearch && !hasEmployeeOrWorkshpSearch)
{
return checkouts.Select(x => new CheckoutViewModel()
{
Id = x.ch.id,
EmployeeFullName = x.ch.EmployeeFullName,
ContractStart = x.ch.ContractStart.ToFarsi(),
@@ -2281,26 +2282,21 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
IsBlockCantracingParty = x.contractingParty.IsBlock,
HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout,
IsUpdateNeeded = x.ch.IsUpdateNeeded,
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm=> new CheckoutWarningMessageModel
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm =>
new CheckoutWarningMessageModel
{
WarningMessage = wm.WarningMessage,
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
}).ToList()
}).OrderByDescending(x => x.Id).Take(3000).ToList().DistinctBy(x => x.Id)
.OrderByDescending(x => x.Id).ThenByDescending(x => x.Year)
.ThenBy(x => x.PersonnelCodeInt)
.Take(50).ToList();
}
else if (hasSearch && !hasEmployeeOrWorkshpSearch)
{
var result = checkouts.Select(x => new CheckoutViewModel()
{
Id = x.ch.id,
EmployeeFullName = x.ch.EmployeeFullName,
ContractStart = x.ch.ContractStart.ToFarsi(),
@@ -2326,19 +2322,17 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
IsBlockCantracingParty = x.contractingParty.IsBlock,
HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout,
IsUpdateNeeded = x.ch.IsUpdateNeeded,
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm =>
new CheckoutWarningMessageModel
{
WarningMessage = wm.WarningMessage,
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
}).ToList()
}).OrderByDescending(x => x.Id)
.GroupBy(x => x.Id)
.Select(x => x.First());
if ((string.IsNullOrWhiteSpace(searchModel.ContractStart) ||
string.IsNullOrWhiteSpace(searchModel.ContractEnd)) && string.IsNullOrWhiteSpace(searchModel.Month))
{
@@ -2348,7 +2342,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
.OrderByDescending(x => x.ContractStartGr).ToList();
}
else if ((string.IsNullOrWhiteSpace(searchModel.ContractStart) ||
string.IsNullOrWhiteSpace(searchModel.ContractEnd)) && !string.IsNullOrWhiteSpace(searchModel.Month) && !string.IsNullOrWhiteSpace(searchModel.Year))
string.IsNullOrWhiteSpace(searchModel.ContractEnd)) &&
!string.IsNullOrWhiteSpace(searchModel.Month) && !string.IsNullOrWhiteSpace(searchModel.Year))
{
//اگر فقط سال و ماه رو سرچ کرد
return result.Take(300)
@@ -2366,14 +2361,11 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
return result.ToList().OrderByDescending(x => x.Id)
.ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).ToList();
}
else if (hasEmployeeOrWorkshpSearch && !hasSearch)
{
return checkouts.Select(x => new CheckoutViewModel()
{
Id = x.ch.id,
EmployeeFullName = x.ch.EmployeeFullName,
ContractStart = x.ch.ContractStart.ToFarsi(),
@@ -2399,13 +2391,12 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
IsBlockCantracingParty = x.contractingParty.IsBlock,
HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout,
IsUpdateNeeded = x.ch.IsUpdateNeeded,
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm =>
new CheckoutWarningMessageModel
{
WarningMessage = wm.WarningMessage,
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
}).ToList()
}).GroupBy(x => x.Id).Select(x => x.First()).ToList()
.OrderByDescending(x => x.ContractStartGr).ToList();
}
@@ -2413,7 +2404,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
{
return checkouts.Select(x => new CheckoutViewModel()
{
Id = x.ch.id,
EmployeeFullName = x.ch.EmployeeFullName,
ContractStart = x.ch.ContractStart.ToFarsi(),
@@ -2439,26 +2429,21 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
IsBlockCantracingParty = x.contractingParty.IsBlock,
HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout,
IsUpdateNeeded = x.ch.IsUpdateNeeded,
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm =>
new CheckoutWarningMessageModel
{
WarningMessage = wm.WarningMessage,
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
}).ToList()
}).GroupBy(x => x.Id)
.Select(x => x.First()).ToList()
.OrderByDescending(x => x.Id)
.ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).ToList();
}
}
}
public async Task<List<CheckoutViewModel>> SearchForMainCheckout(CheckoutSearchModel searchModel)
{
bool hasSearch = false;
bool hasEmployeeOrWorkshpSearch = false;
//List<CheckoutViewModel> query = null;
@@ -2476,11 +2461,8 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
.Select(x => x.WorkshopId).ToList();
var query = _context.CheckoutSet.Select(x => new CheckoutViewModel()
{
Id = x.id,
EmployeeFullName = x.EmployeeFullName,
//var start = ;
@@ -2503,13 +2485,9 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
IsActiveString = x.IsActiveString,
Signature = x.Signature,
CreationDate = x.CreationDate,
});
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo) && searchModel.ContractId != 0)
query = query.Where(x =>
x.ContractNo == searchModel.ContractNo && x.ContractId == searchModel.ContractId);
@@ -2518,11 +2496,13 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
hasEmployeeOrWorkshpSearch = true;
query = query.Where(x => x.WorkshopId == searchModel.WorkshopId);
}
if (searchModel.EmployeeId != 0)
{
hasEmployeeOrWorkshpSearch = true;
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
}
if (searchModel.EmployerId != 0)
{
hasEmployeeOrWorkshpSearch = true;
@@ -2566,7 +2546,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
query = query.Where(x => x.ContractStartGr >= startyearGr && x.ContractEndGr <= endYearGr);
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
query = query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt);
}
else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) &&
string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
@@ -2686,7 +2665,6 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
endDate >= x.ContractEndGr && startDate < x.ContractEndGr);
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
query = query.OrderBy(x => x.PersonnelCodeInt);
}
else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
!string.IsNullOrWhiteSpace(searchModel.ContractEnd) &&
@@ -2701,16 +2679,18 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
query = query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt);
}
if (!string.IsNullOrEmpty(searchModel.EmployeeName))
{
hasSearch = true;
var employeeList = _context.Employees.Where(x => (!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchModel.EmployeeName)) ||
(!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchModel.EmployeeName))).Select(x => x.id).ToList();
var employeeList = _context.Employees.Where(x =>
(!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchModel.EmployeeName)) ||
(!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchModel.EmployeeName))).Select(x => x.id)
.ToList();
query = query.Where(x => employeeList.Contains(x.EmployeeId));
}
if (hasSearch)
return query.OrderByDescending(x => x.Id)
.ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).ToList();
@@ -2721,22 +2701,17 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
.ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).Take(50).ToList();
// Console.WriteLine("return" + watch.Elapsed);
}
#endregion
#region Pooya
public List<(long EmployeeId, DateTime CheckoutStart, DateTime CheckoutEnd)> GetLastCheckoutsByWorkshopIdForWorkFlow(long workshopId, DateTime start, DateTime end)
public List<(long EmployeeId, DateTime CheckoutStart, DateTime CheckoutEnd)>
GetLastCheckoutsByWorkshopIdForWorkFlow(long workshopId, DateTime start, DateTime end)
{
return _context.CheckoutSet.AsSplitQuery().Where(x => x.ContractEnd.Date >= start && x.ContractStart.Date <= end && x.WorkshopId == workshopId).Select(x => new
return _context.CheckoutSet.AsSplitQuery().Where(x =>
x.ContractEnd.Date >= start && x.ContractStart.Date <= end && x.WorkshopId == workshopId).Select(x => new
{
EmployeeId = x.EmployeeId,
CheckoutEnd = x.ContractEnd,
@@ -2751,5 +2726,88 @@ public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepos
x.ContractEnd >= inDate);
}
public async Task<PagedResult<CheckoutListClientDto>> GetListForClient(long workshopId,
CheckoutListClientSearchModel searchModel)
{
var query = _context.CheckoutSet.Where(x => x.WorkshopId == workshopId);
if (searchModel.EmployeeId is > 0)
{
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
}
if (!string.IsNullOrWhiteSpace(searchModel.StartDate) && !string.IsNullOrWhiteSpace(searchModel.EndDate))
{
if (!searchModel.StartDate.TryToGeorgianDateTime(out var startDateGr))
throw new BadRequestException("تاریخ شروع جستجو نامعتبر است");
if (!searchModel.EndDate.TryToGeorgianDateTime(out var endDateGr))
{
throw new BadRequestException("تاریخ پایان جستجو نامعتبر است");
}
query = query.Where(x => x.ContractStart <= endDateGr && x.ContractEnd >= startDateGr);
}
if (!string.IsNullOrWhiteSpace(searchModel.Year))
{
query = query.Where(x => x.Year == searchModel.Year);
}
if (!string.IsNullOrWhiteSpace(searchModel.Month))
{
var searchedMonth = Convert.ToInt32(searchModel.Month).ToFarsiMonthByIntNumber();
query = query.Where(x => x.Month == searchedMonth);
}
query = searchModel.OrderType switch
{
CheckoutClientListOrderType.ByCheckoutCreationDate =>
query.OrderBy(x => x.CreationDate),
CheckoutClientListOrderType.ByCheckoutStartDate =>
query.OrderBy(x => x.ContractStart),
CheckoutClientListOrderType.ByCheckoutStartDateDescending =>
query.OrderByDescending(x => x.ContractStart),
CheckoutClientListOrderType.ByPersonnelCode =>
query.OrderBy(x => x.PersonnelCode),
CheckoutClientListOrderType.ByPersonnelCodeDescending =>
query.OrderByDescending(x => x.PersonnelCode),
CheckoutClientListOrderType.BySignedCheckout =>
query.OrderByDescending(x => x.Signature == "1"),
CheckoutClientListOrderType.ByUnSignedCheckout =>
query.OrderBy(x => x.Signature == "1"),
_ => query.OrderByDescending(x => x.id)
};
var list =await query.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync();
var resList = list.Select(x => new CheckoutListClientDto()
{
Id = x.id,
ContractStart = x.ContractStart.ToFarsi(),
ContractEnd = x.ContractEnd.ToFarsi(),
Year = x.Year,
Month = x.Month,
ContractNo = x.ContractNo,
EmployeeName = x.EmployeeFullName,
Signature = x.Signature == "1"
}).ToList();
var res = new PagedResult<CheckoutListClientDto>
{
TotalCount = await query.CountAsync(),
List = resList
};
return res;
}
#endregion
}

View File

@@ -0,0 +1,25 @@
using _0_Framework.Application;
using CompanyManagment.App.Contracts.Checkout;
using Microsoft.AspNetCore.Mvc;
using ServiceHost.BaseControllers;
namespace ServiceHost.Areas.Client.Controllers;
public class CheckoutController:ClientBaseController
{
private readonly ICheckoutApplication _checkoutApplication;
private readonly long _workshopId;
public CheckoutController(ICheckoutApplication checkoutApplication,IAuthHelper authHelper)
{
_checkoutApplication = checkoutApplication;
_workshopId = authHelper.GetWorkshopId();
}
[HttpGet]
public async Task<ActionResult<PagedResult<CheckoutListClientDto>>> GetList(CheckoutListClientSearchModel searchModel)
{
var res =await _checkoutApplication.GetListForClient(_workshopId, searchModel);
return res;
}
}