2706 lines
122 KiB
C#
2706 lines
122 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Reflection.Metadata.Ecma335;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.CheckoutAgg;
|
|
using Company.Domain.LeftWorkAgg;
|
|
using Company.Domain.RollCallAgg;
|
|
using Company.Domain.RollCallEmployeeAgg;
|
|
using Company.Domain.WorkshopEmployerAgg;
|
|
using CompanyManagment.App.Contracts.Checkout;
|
|
using CompanyManagment.App.Contracts.Contract;
|
|
using CompanyManagment.App.Contracts.Employee;
|
|
using CompanyManagment.App.Contracts.HolidayItem;
|
|
using CompanyManagment.App.Contracts.InsuranceList;
|
|
using CompanyManagment.App.Contracts.Leave;
|
|
using CompanyManagment.App.Contracts.LeftWork;
|
|
using CompanyManagment.App.Contracts.Loan;
|
|
using CompanyManagment.App.Contracts.RollCall;
|
|
using CompanyManagment.App.Contracts.SalaryAid;
|
|
using CompanyManagment.App.Contracts.WorkingHours;
|
|
using CompanyManagment.App.Contracts.WorkingHoursTemp;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using CompanyManagment.EFCore.Migrations;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using PersianTools.Core;
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepository
|
|
|
|
{
|
|
private readonly CompanyContext _context;
|
|
|
|
|
|
private readonly IWorkingHoursTempApplication _workingHoursTempApplication;
|
|
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ILeftWorkRepository _leftWorkRepository;
|
|
private readonly IRollCallRepository _rollCallRepository;
|
|
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)
|
|
{
|
|
|
|
_authHelper = authHelper;
|
|
_context = context;
|
|
_configuration = configuration;
|
|
_leftWorkRepository = leftWorkRepository;
|
|
_workingHoursTempApplication = workingHoursTempApplication;
|
|
_rollCallRepository = rollCallRepository;
|
|
_rollCallMandatoryRepository = rollCallMandatoryRepository;
|
|
_rollCallEmployeeRepository = rollCallEmployeeRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// چیک میکند که آیا پرسنل در سال و ماه درخواستی در این کارگاه فیش حقوقی دارد یا خیر
|
|
/// </summary>
|
|
/// <param name="workshopId"></param>
|
|
/// <param name="employeId"></param>
|
|
/// <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)
|
|
{
|
|
var farisMonthName = Tools.ToFarsiMonthByNumber(month);
|
|
|
|
var res = _context.CheckoutSet.FirstOrDefault(x =>
|
|
x.WorkshopId == workshopId && x.EmployeeId == employeId && x.Year == year && x.Month == farisMonthName &&
|
|
x.IsActiveString == "true");
|
|
if (res == null)
|
|
return (false, 0, 0,0,0,0,0);
|
|
|
|
return (true, res.FamilyAllowance, res.OvertimePay, res.ShiftPay, res.NightworkPay, res.FridayPay,res.YearsPay);
|
|
}
|
|
|
|
public EditCheckout GetDetails(long id)
|
|
{
|
|
return _context.CheckoutSet.Select(x => new EditCheckout()
|
|
{
|
|
Id = x.id,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
FathersName = x.FathersName,
|
|
NationalCode = x.NationalCode,
|
|
DateOfBirth = x.DateOfBirth,
|
|
WorkshopName = x.WorkshopName,
|
|
Month = x.Month,
|
|
Year = x.Year,
|
|
ContractNo = x.ContractNo,
|
|
MonthlySalary = x.MonthlySalary,
|
|
BaseYearsPay = x.BaseYearsPay,
|
|
ConsumableItems = x.ConsumableItems.ToMoney(),
|
|
HousingAllowance = x.HousingAllowance.ToMoney(),
|
|
OvertimePay = x.OvertimePay,
|
|
NightworkPay = x.NightworkPay,
|
|
FridayPay = x.FridayPay,
|
|
MissionPay = x.MissionPay,
|
|
ShiftPay = x.ShiftPay,
|
|
FamilyAllowance = x.FamilyAllowance.ToMoney(),
|
|
BonusesPay = x.BonusesPay,
|
|
YearsPay = x.YearsPay,
|
|
LeavePay = x.LeavePay,
|
|
InsuranceDeduction = x.InsuranceDeduction,
|
|
TaxDeducation = x.TaxDeducation,
|
|
InstallmentDeduction = x.InstallmentDeduction,
|
|
SalaryAidDeduction = x.SalaryAidDeduction,
|
|
AbsenceDeduction = x.AbsenceDeduction,
|
|
TotalClaims = x.TotalClaims,
|
|
TotalDeductions = x.TotalDeductions,
|
|
TotalPayment = x.TotalPayment,
|
|
RewardPay = x.RewardPay,
|
|
HasRollCall = x.HasRollCall,
|
|
EmployeeId = x.EmployeeId,
|
|
WorkshopId = x.WorkshopId,
|
|
ContractId = x.ContractId,
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
ContractStart = x.ContractStart.ToFarsi(),
|
|
ContractEnd = x.ContractEnd.ToFarsi()
|
|
|
|
})
|
|
.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// لود لیست اولیه جهت ایجاد فیش حقوقی
|
|
/// </summary>
|
|
/// <param name="workshopId"></param>
|
|
/// <param name="employeeId"></param>
|
|
/// <param name="year"></param>
|
|
/// <param name="month"></param>
|
|
/// <param name="contractStart"></param>
|
|
/// <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,
|
|
string contractEnd)
|
|
{
|
|
DateTime startSreach;
|
|
DateTime endSearch;
|
|
|
|
if (!string.IsNullOrWhiteSpace(contractStart) && !string.IsNullOrWhiteSpace(contractEnd))
|
|
{
|
|
startSreach = contractStart.ToGeorgianDateTime();
|
|
endSearch = contractEnd.ToGeorgianDateTime();
|
|
}
|
|
else
|
|
{
|
|
|
|
if (month == "0" && year == "0")
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
string startStr = $"{now.ToFarsi().Substring(0, 8)}01";
|
|
startSreach = startStr.ToGeorgianDateTime();
|
|
endSearch = (startStr.FindeEndOfMonth()).ToGeorgianDateTime();
|
|
}
|
|
else if (month == "0" && year != "0")
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
|
|
string startStr = $"{year}/{now.ToFarsi().Substring(5, 2)}/01";
|
|
startSreach = startStr.ToGeorgianDateTime();
|
|
endSearch = (startStr.FindeEndOfMonth()).ToGeorgianDateTime();
|
|
}
|
|
else if (month != "0" && year == "0")
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
|
|
string startStr = $"{now.ToFarsi().Substring(0, 4)}/{month}/01";
|
|
startSreach = startStr.ToGeorgianDateTime();
|
|
endSearch = (startStr.FindeEndOfMonth()).ToGeorgianDateTime();
|
|
}
|
|
else
|
|
{
|
|
string startStr = $"{year}/{month}/01";
|
|
startSreach = startStr.ToGeorgianDateTime();
|
|
endSearch = (startStr.FindeEndOfMonth()).ToGeorgianDateTime();
|
|
}
|
|
|
|
}
|
|
var timer = new Stopwatch();
|
|
timer.Start();
|
|
|
|
var contracts = _context.Contracts.AsSplitQuery()
|
|
.Where(x => x.WorkshopIds == workshopId && x.IsActiveString == "true" && startSreach < x.ContractEnd &&
|
|
endSearch > x.ContarctStart)
|
|
.Join(_context.Workshops.AsSplitQuery(),
|
|
contract => contract.WorkshopIds,
|
|
workshop => workshop.id,
|
|
(contract, workshop) => new { contract, workshop })
|
|
.Join(_context.Employees.AsSplitQuery(),
|
|
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),
|
|
contractWorkshopEmployee => contractWorkshopEmployee.contractWorkshop.contract.EmployeeId,
|
|
leftwork => leftwork.EmployeeId,
|
|
(contractWorkshopEmployee, leftwork) => new { contractWorkshopEmployee, leftwork })
|
|
.Join(_context.PersonnelCodeSet.AsSplitQuery().Where(p => p.WorkshopId == workshopId),
|
|
contractWorkshopEmployeeleftWork => contractWorkshopEmployeeleftWork.contractWorkshopEmployee
|
|
.contractWorkshop.contract.EmployeeId,
|
|
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,
|
|
option => option.EmployeeId,
|
|
(x, options) => new { x.checkout, x.contractWorkshopEmployeeleftWorkPersonnelCode, options })
|
|
.SelectMany(
|
|
x => x.options.DefaultIfEmpty(),
|
|
(x, option) => new { x.checkout, x.contractWorkshopEmployeeleftWorkPersonnelCode, option })
|
|
.ToList();
|
|
Console.WriteLine("query : " + timer.Elapsed);
|
|
timer.Reset();
|
|
timer.Start();
|
|
if (employeeId > 0)
|
|
contracts = contracts.Where(x =>
|
|
x.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.contractWorkshopEmployee.contractWorkshop.contract.EmployeeId == employeeId).ToList();
|
|
var finalResult = contracts.Select(result =>
|
|
{
|
|
var now = DateTime.Now;
|
|
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");
|
|
|
|
if (chekoutCreated != null)
|
|
{
|
|
|
|
return new CreateCheckoutListViewModel
|
|
{
|
|
Id = chekoutCreated.ContractId,
|
|
|
|
EmployeeId = chekoutCreated.EmployeeId,
|
|
ContractNo = chekoutCreated.ContractNo,
|
|
WorkshopName = chekoutCreated.WorkshopName,
|
|
EmployeeName = chekoutCreated.EmployeeFullName,
|
|
ContractStart = chekoutCreated.ContractStart.ToFarsi(),
|
|
ContractEnd = chekoutCreated.ContractEnd.ToFarsi(),
|
|
PersonnelCode = Convert.ToInt64(chekoutCreated.PersonnelCode),
|
|
LaterThanEnd = false,
|
|
Extension = false,
|
|
Description = "دارای فیش حقوقی",
|
|
HasCheckout = true,
|
|
EmployeeHasCreateCheckout = true
|
|
};
|
|
}
|
|
var employeeJoin = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.contractWorkshopEmployee.employee.id;
|
|
|
|
|
|
var leftWork = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.leftwork;
|
|
|
|
var startStatusSearch = leftWork.StartWorkDate > startSreach && leftWork.StartWorkDate <= endSearch
|
|
? leftWork.StartWorkDate
|
|
: startSreach;
|
|
var endStatusSearch = leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch
|
|
? leftWork.LeftWorkDate.AddDays(-1)
|
|
: startSreach;
|
|
bool hasRollCall =
|
|
_rollCallEmployeeRepository.HasRollCallRecord(employeeJoin, workshopId, startStatusSearch, endStatusSearch);
|
|
|
|
bool extension = true;
|
|
bool laterThanEnd = false;
|
|
string description = "";
|
|
string leftWorkDate = "";
|
|
string contractStart = "";
|
|
string contractEnd = "";
|
|
|
|
var contractStartGr = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.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)
|
|
{
|
|
//اگر بازه انتخاب شده در تاریخ جاری بود
|
|
if (startSreach == currentStart && endSearch == currentEnd)
|
|
{
|
|
//اگر ترک کارش قبل یا مساوی تاریخ جاری بود
|
|
if (leftWork.LeftWorkDate <= now)
|
|
{
|
|
//مجاز به ایجاد تصفیه
|
|
extension = true;
|
|
leftWorkDate = leftWork.LeftWorkDate.ToFarsi();
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi();
|
|
|
|
}
|
|
else
|
|
{
|
|
// مجاز نیست
|
|
extension = false;
|
|
description = "بعد از تاریخ ترک کار می توانید فیش صادر کنید";
|
|
leftWorkDate = leftWork.LeftWorkDate.ToFarsi();
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi();
|
|
|
|
}
|
|
}
|
|
else if (endSearch < currentStart)
|
|
{
|
|
extension = true;
|
|
leftWorkDate = leftWork.LeftWorkDate.ToFarsi();
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi();
|
|
}
|
|
else if (startSreach > currentEnd)
|
|
{
|
|
// مجاز نیست
|
|
extension = false;
|
|
description = "بعد از تاریخ ترک کار می توانید فیش صادر کنید";
|
|
leftWorkDate = leftWork.LeftWorkDate.ToFarsi();
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi();
|
|
}
|
|
|
|
}
|
|
else if (leftWork.HasLeft && leftWork.LeftWorkDate <= startSreach)
|
|
{
|
|
// مجاز نیست
|
|
extension = false;
|
|
description = "به دلیل ترک کار پیش از تاریخ انتخاب شده مجاز به ایجاد فیش نمی باشید";
|
|
leftWorkDate = leftWork.LeftWorkDate.ToFarsi();
|
|
|
|
}
|
|
else if (!leftWork.HasLeft && startSreach == currentStart)
|
|
{
|
|
// مجاز نیست
|
|
extension = false;
|
|
description = "به دلیل داشتن حضورغیاب تا پایان ماه مجاز به ایجاد فیش نمی باشید";
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = endSearch.ToFarsi();
|
|
|
|
}
|
|
else if (!leftWork.HasLeft && startSreach < currentStart)
|
|
{
|
|
|
|
|
|
|
|
if (contractStartGr <= startSreach && contractStartGr > endSearch)
|
|
{
|
|
laterThanEnd = true;
|
|
extension = true;
|
|
contractStart = startSreach.ToFarsi();
|
|
contractEnd = endSearch.ToFarsi();
|
|
}
|
|
else
|
|
{
|
|
laterThanEnd = false;
|
|
extension = true;
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = (leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch) ? leftWork.LeftWorkDate.AddDays(-1).ToFarsi() : endSearch.ToFarsi();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static
|
|
|
|
if (!hasRollCall)
|
|
{
|
|
if (leftWork.HasLeft)
|
|
{
|
|
if (leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch)
|
|
{
|
|
extension = true;
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = leftWork.LeftWorkDate.AddDays(-1).ToFarsi();
|
|
leftWorkDate = leftWork.LeftWorkDate.ToFarsi();
|
|
}
|
|
else if (leftWork.LeftWorkDate <= startSreach)
|
|
{
|
|
// مجاز نیست
|
|
extension = false;
|
|
description = "به دلیل ترک کار پیش از تاریخ انتخاب شده مجاز به ایجاد فیش نمی باشید";
|
|
leftWorkDate = leftWork.LeftWorkDate.ToFarsi();
|
|
}
|
|
else if (leftWork.LeftWorkDate > endSearch)
|
|
{
|
|
extension = true;
|
|
|
|
if (contractStartGr <= startSreach && contractStartGr > endSearch)
|
|
{
|
|
laterThanEnd = true;
|
|
|
|
contractStart = startSreach.ToFarsi();
|
|
contractEnd = endSearch.ToFarsi();
|
|
}
|
|
else
|
|
{
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = endSearch.ToFarsi();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
extension = true;
|
|
|
|
if (contractStartGr <= startSreach && contractStartGr > endSearch)
|
|
{
|
|
laterThanEnd = true;
|
|
|
|
contractStart = startSreach.ToFarsi();
|
|
contractEnd = endSearch.ToFarsi();
|
|
}
|
|
else
|
|
{
|
|
contractStart = leftWork.StartWorkDate > startSreach
|
|
? leftWork.StartWorkDate.ToFarsi()
|
|
: startSreach.ToFarsi();
|
|
contractEnd = endSearch.ToFarsi();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
return new CreateCheckoutListViewModel
|
|
{
|
|
Id = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.contractWorkshopEmployee.contractWorkshop.contract.id,
|
|
|
|
EmployeeId = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.contractWorkshopEmployee.employee.id,
|
|
ContractNo = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.contractWorkshopEmployee.contractWorkshop.contract.ContractNo,
|
|
//EmployerName = result.contract.EmployerName,
|
|
WorkshopName = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.contractWorkshopEmployee.contractWorkshop.workshop.WorkshopFullName,
|
|
EmployeeName = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork
|
|
.contractWorkshopEmployee.employee.FullName,
|
|
|
|
PersonnelCode = result.contractWorkshopEmployeeleftWorkPersonnelCode.personnelCode.PersonnelCode,
|
|
//PersonnelCodeInt = Convert.ToInt32(result.contract.PersonnelCode),
|
|
LaterThanEnd = laterThanEnd,
|
|
Extension = extension,
|
|
Description = description,
|
|
ContractStart = contractStart,
|
|
ContractEnd = contractEnd,
|
|
LeftWorkDate = leftWorkDate,
|
|
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()
|
|
{
|
|
CreateCheckoutList = finalResult
|
|
};
|
|
}
|
|
|
|
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}");
|
|
var result = (_context.Database
|
|
.SqlQuery<long>(
|
|
$"EXEC InsertQuery_CreateChekoute {command.EmployeeFullName},{"true"},{command.Signature},{command.FathersName},{command.NationalCode},{command.DateOfBirth},{command.EmployeeId},{command.WorkshopName},{command.WorkshopId},{command.ContractNo},{command.ContractStart},{command.ContractEnd},{command.Month},{command.Year},{command.ContractId},{command.WorkingHoursId},{command.MonthlySalary},{command.BaseYearsPay},{command.ConsumableItems},{command.HousingAllowance},{command.OvertimePay},{command.NightworkPay},{command.FridayPay},{command.MissionPay},{command.ShiftPay},{command.FamilyAllowance},{command.BonusesPay},{command.YearsPay},{command.LeavePay},{command.InsuranceDeduction},{command.TaxDeducation},{command.InstallmentDeduction},{command.SalaryAidDeduction},{command.AbsenceDeduction},{creationDates},{command.ArchiveCode},{command.PersonnelCode},{command.SumOfWorkingDays},{command.TotalClaims},{command.TotalDeductions},{command.TotalPayment},{0},{command.MarriedAllowance},{command.AbsencePeriod},{command.AverageHoursPerDay},{command.CreditLeaves},{command.LeaveCheckout},{command.HasRollCall},{command.OverTimeWorkValue},{command.OverNightWorkValue},{command.FridayWorkValue},{command.RotatingShiftValue},{command.AbsenceValue}, {command.TotalDayOfLeaveCompute},{command.TotalDayOfYearsCompute},{command.TotalDayOfBunosesCompute}")
|
|
.AsEnumerable())// این قسمت مهمه!
|
|
.FirstOrDefault();
|
|
|
|
var entity = await _context.CheckoutSet.FirstOrDefaultAsync(x => x.id == result);
|
|
|
|
entity.SetSalaryAid(command.SalaryAids, command.SalaryAidDeduction);
|
|
entity.SetLoanInstallment(command.LoanInstallments, command.InstallmentDeduction);
|
|
entity.SetCheckoutRollCall(command.CheckoutRollCall);
|
|
await _context.SaveChangesAsync();
|
|
|
|
}
|
|
|
|
|
|
public async Task<List<CheckoutViewModel>> Search(CheckoutSearchModel searchModel)
|
|
{
|
|
List<CheckoutViewModel> query = null;
|
|
var connection = _configuration.GetConnectionString("MesbahDb");
|
|
//var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
var AcountID = _authHelper.CurrentAccountId();
|
|
var workshopAcounts = _context.WorkshopAccounts.Where(x => x.AccountId == AcountID)
|
|
.Select(x => x.WorkshopId).ToList();
|
|
//Console.WriteLine("acID.. " + watch.Elapsed);
|
|
|
|
//var watchmp = System.Diagnostics.Stopwatch.StartNew();
|
|
var emp = _context.WorkshopEmployers.Where(x => workshopAcounts.Contains(x.WorkshopId))
|
|
.Select(x => x.EmployerId);
|
|
var emp2 = _context.WorkshopEmployers.Where(x => x.EmployerId == searchModel.EmployerId)
|
|
.Select(x => x.WorkshopId).ToList();
|
|
|
|
//Console.WriteLine("emp.. " + watchmp.Elapsed);
|
|
//var employerlist = _context.Employers.Where(x => emp.Contains(x.id)).ToList();
|
|
|
|
|
|
//var stored = _context.CheckoutSet.FromSqlInterpolated($"SelectQuery_AllChekouts2").AsNoTracking()
|
|
// .ToList();
|
|
//var watchusing = System.Diagnostics.Stopwatch.StartNew();
|
|
using (var conn = new SqlConnection(connection))
|
|
{
|
|
await conn.OpenAsync();
|
|
|
|
var command = new SqlCommand("ChekoutMainList", conn);
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
|
|
|
|
using (var reader = await command.ExecuteReaderAsync())
|
|
{
|
|
query = new List<CheckoutViewModel>();
|
|
|
|
while (await reader.ReadAsync())
|
|
{
|
|
var item = new CheckoutViewModel();
|
|
|
|
item.Id = (long)reader["Id"];
|
|
item.EmployeeFullName = (string)reader?["EmployeeFullName"];
|
|
var start = (DateTime)reader["ContractStart"];
|
|
item.ContractStart = start.ToFarsi();
|
|
var end = (DateTime)reader["ContractEnd"];
|
|
item.ContractEnd = end.ToFarsi();
|
|
item.ContractStartGr = start;
|
|
item.ContractEndGr = end;
|
|
item.PersonnelCode = (string)reader?["PersonnelCode"];
|
|
item.PersonnelCodeInt = item.PersonnelCode.ConvertToInt();
|
|
item.ArchiveCode = (string)reader?["ArchiveCode"];
|
|
item.SumOfWorkingDays = (string)reader?["SumOfWorkingDays"];
|
|
item.WorkshopName = (string)reader?["WorkshopName"];
|
|
item.Month = reader["Month"] != DBNull.Value ? (string)reader["Month"] : null;
|
|
item.Year = reader["Year"] != DBNull.Value ? (string)reader["Year"] : null;
|
|
item.ContractNo = (string)reader?["ContractNo"];
|
|
item.ContractId = (long)reader["ContractId"];
|
|
item.WorkshopId = (long)reader["WorkshopId"];
|
|
item.EmployeeId = (long)reader["EmployeeId"];
|
|
item.IsActiveString = (string)reader["IsActiveString"];
|
|
item.Signature = (string)reader["Signature"];
|
|
item.CreationDate = (DateTime)reader["CreationDate"];
|
|
|
|
|
|
query.Add(item);
|
|
}
|
|
}
|
|
}
|
|
//Console.WriteLine("using.. " + watchusing.Elapsed);
|
|
//var query = stored.Select(x => new CheckoutViewModel()
|
|
//{
|
|
// Id = x.id,
|
|
// EmployeeFullName = x.EmployeeFullName,
|
|
// ContractStart = x.ContractStart.ToFarsi(),
|
|
// ContractEnd = x.ContractEnd.ToFarsi(),
|
|
// ContractStartGr = x.ContractStart,
|
|
// ContractEndGr = x.ContractEnd,
|
|
// PersonnelCode = x.PersonnelCode,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// SumOfWorkingDays = x.SumOfWorkingDays,
|
|
// WorkshopName = x.WorkshopName,
|
|
// Month = x.Month,
|
|
// Year = x.Year,
|
|
// ContractNo = x.ContractNo,
|
|
// ContractId = x.ContractId,
|
|
// WorkshopId = x.WorkshopId,
|
|
// EmployeeId = x.EmployeeId,
|
|
|
|
// IsActiveString = x.IsActiveString,
|
|
// Signature = x.Signature,
|
|
// CreationDate = x.CreationDate
|
|
//});
|
|
|
|
//var watchif = System.Diagnostics.Stopwatch.StartNew();
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo) && searchModel.ContractId != 0)
|
|
query = query.Where(x =>
|
|
x.ContractNo == searchModel.ContractNo && x.ContractId == searchModel.ContractId).ToList();
|
|
if (searchModel.WorkshopId != 0)
|
|
query = query.Where(x => x.WorkshopId == searchModel.WorkshopId).ToList();
|
|
if (searchModel.EmployeeId != 0)
|
|
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId).ToList();
|
|
if (searchModel.EmployerId != 0)
|
|
{
|
|
query = query.Where(x => emp2.Contains(x.WorkshopId)).ToList();
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo))
|
|
query = query.Where(x => x.ContractNo == searchModel.ContractNo).ToList();
|
|
|
|
|
|
if (searchModel.IsActiveString == null)
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "true").ToList();
|
|
}
|
|
|
|
if (searchModel.IsActiveString == "false")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false").ToList();
|
|
}
|
|
else if (searchModel.IsActiveString == "both")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false" || x.IsActiveString == "true").ToList();
|
|
}
|
|
|
|
query = query.Where(e => workshopAcounts.Contains(e.WorkshopId)).ToList();
|
|
//سرچ سال
|
|
if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month) &&
|
|
(string.IsNullOrWhiteSpace(searchModel.ContractStart) ||
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd)))
|
|
{
|
|
var startYear = searchModel.Year + "/01/01";
|
|
var startyearGr = startYear.ToGeorgianDateTime();
|
|
var endYear = $"{searchModel.Year}/12/01".FindeEndOfMonth();
|
|
var endYearGr = endYear.ToGeorgianDateTime();
|
|
|
|
|
|
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) &&
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd))
|
|
{
|
|
//سرچ سال و ماه
|
|
string y1 = $"{searchModel.Year}/{searchModel.Month}/01";
|
|
var startDate = y1.ToGeorgianDateTime();
|
|
string y2 = string.Empty;
|
|
int month = Convert.ToInt32(searchModel.Month);
|
|
int year = Convert.ToInt32(searchModel.Year);
|
|
|
|
if (month <= 6)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/31";
|
|
}
|
|
else if (month > 6 && month < 12)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
}
|
|
else if (month == 12)
|
|
{
|
|
switch (year)
|
|
{
|
|
case 1346:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1350:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1354:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1358:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1362:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1366:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1370:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1375:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1379:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1383:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1387:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1391:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1395:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1399:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1403:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1408:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1412:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1416:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1420:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1424:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1428:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1432:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1436:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1441:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1445:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
|
|
default:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/29";
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
var endDate = y2.ToGeorgianDateTime();
|
|
|
|
//query = query.Where(x => x.ContractEndGr >= start && x.ContractEndGr <= end).ToList();
|
|
query = query.Where(x =>
|
|
x.ContractStartGr >= startDate && x.ContractStartGr < endDate && x.ContractEndGr > startDate &&
|
|
x.ContractEndGr <= endDate ||
|
|
x.ContractStartGr <= startDate && x.ContractEndGr >= endDate ||
|
|
startDate <= x.ContractStartGr && endDate > x.ContractStartGr ||
|
|
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) &&
|
|
string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month))
|
|
{
|
|
//سرچ تاریخ
|
|
var start = searchModel.ContractStart.ToGeorgianDateTime();
|
|
var endd = searchModel.ContractEnd.ToGeorgianDateTime();
|
|
query = query.Where(x =>
|
|
x.ContractStartGr >= start && x.ContractEndGr <= endd).ToList();
|
|
|
|
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)
|
|
// .Select(x => x.EmployerId).FirstOrDefault();
|
|
// var employerName = _context.Employers?.FirstOrDefault(x => x.id == employeId).FullName;
|
|
// items.EmployerName = employerName;
|
|
//}
|
|
//Console.WriteLine("SearchModel.. " + watchif.Elapsed);
|
|
//if (searchModel.EmployeeId != 0 || !string.IsNullOrWhiteSpace(searchModel.Year) && searchModel.WorkshopId != 0)
|
|
//{
|
|
// if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month))
|
|
// {
|
|
// var startOfYear = searchModel.Year + "/01/01";
|
|
// var startOfyearGr = startOfYear.ToGeorgianDateTime();
|
|
// var endOfYear = $"{searchModel.Year}/12/01".FindeEndOfMonth();
|
|
// var endOfYearGr = endOfYear.ToGeorgianDateTime();
|
|
|
|
|
|
// query = query.Where(x => x.ContractStartGr >= startOfyearGr && x.ContractEndGr <= endOfYearGr).ToList();
|
|
// }
|
|
// return query.OrderBy(x => x.PersonnelCode).ToList();
|
|
//}
|
|
}
|
|
|
|
public List<CheckoutViewModel> SimpleSearch(CheckoutSearchModel searchModel)
|
|
{
|
|
var query = _context.CheckoutSet.Select(x => new CheckoutViewModel()
|
|
{
|
|
Id = x.id,
|
|
EmployeeId = x.EmployeeId,
|
|
WorkshopId = x.WorkshopId,
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
ContractStart = x.ContractStart.ToFarsi(),
|
|
ContractEnd = x.ContractEnd.ToFarsi(),
|
|
Signature = x.Signature,
|
|
Year = x.Year,
|
|
Month = x.Month,
|
|
ContractNo = x.ContractNo,
|
|
ContractId = x.ContractId,
|
|
HasRollCall = x.HasRollCall
|
|
|
|
});
|
|
|
|
if (searchModel.EmployeeId != 0 && searchModel.WorkshopId != 0)
|
|
query = query.Where(x =>
|
|
x.EmployeeId == searchModel.EmployeeId && x.WorkshopId == searchModel.WorkshopId);
|
|
if (searchModel.EmployeeId == 0 && searchModel.WorkshopId != 0)
|
|
query = query.Where(x => x.WorkshopId == searchModel.WorkshopId);
|
|
if (searchModel.EmployeeId != 0 && searchModel.WorkshopId == 0)
|
|
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo) && searchModel.ContractId > 0)
|
|
query = query.Where(x => x.ContractNo == searchModel.ContractNo);
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.ContractEnd) &&
|
|
(searchModel.EmployeeId != 0 && searchModel.WorkshopId != 0))
|
|
{
|
|
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);
|
|
}
|
|
|
|
return query.OrderBy(x => x.ContractStartGr).ToList();
|
|
|
|
}
|
|
|
|
public List<CheckoutViewModel> PrintAll(List<long> id)
|
|
{
|
|
var query = new List<CheckoutViewModel>();
|
|
foreach (var item in id)
|
|
{
|
|
var ch = _context.CheckoutSet
|
|
.AsSplitQuery().Select(x => new CheckoutViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
ContractId = x.ContractId,
|
|
EmployeeId = x.EmployeeId,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
FathersName = x.FathersName,
|
|
NationalCode = x.NationalCode,
|
|
DateOfBirth = x.DateOfBirth,
|
|
WorkshopName = x.WorkshopName,
|
|
Month = x.Month,
|
|
Year = x.Year,
|
|
PersonnelCode = x.PersonnelCode,
|
|
PersonnelCodeInt = Convert.ToInt32(x.PersonnelCode),
|
|
ContractNo = x.ContractNo,
|
|
MonthlySalary = x.MonthlySalary.ToMoney(),
|
|
BaseYearsPay = x.BaseYearsPay.ToMoney(),
|
|
ConsumableItems = x.ConsumableItems.ToMoney(),
|
|
HousingAllowance = x.HousingAllowance.ToMoney(),
|
|
OvertimePay = x.OvertimePay.ToMoney(),
|
|
NightworkPay = x.NightworkPay.ToMoney(),
|
|
FridayPay = x.FridayPay.ToMoney(),
|
|
MissionPay = x.MissionPay.ToMoney(),
|
|
ShiftPay = x.ShiftPay.ToMoney(),
|
|
FamilyAllowance = x.FamilyAllowance.ToMoney(),
|
|
BonusesPay = x.BonusesPay.ToMoney(),
|
|
YearsPay = x.YearsPay.ToMoney(),
|
|
LeavePay = x.LeavePay.ToMoney(),
|
|
InsuranceDeduction = x.InsuranceDeduction.ToMoney(),
|
|
TaxDeducation = x.TaxDeducation.ToMoney(),
|
|
InstallmentDeduction = x.InstallmentDeduction.ToMoney(),
|
|
SalaryAidDeduction = x.SalaryAidDeduction.ToMoney(),
|
|
AbsenceDeduction = x.AbsenceDeduction.ToMoney(),
|
|
TotalClaims = x.TotalClaims,
|
|
TotalDeductions = x.TotalDeductions,
|
|
TotalPayment = x.TotalPayment.ToMoney(),
|
|
RewardPay = x.RewardPay.ToMoneyNullable(),
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
IsLeft = false,
|
|
LeftWorkDate = "",
|
|
LastDayOfWork = "",
|
|
MarriedAllowance = x.MarriedAllowance.ToMoney(),
|
|
HasRollCall = x.HasRollCall,
|
|
SumOfWorkingDays = "-",
|
|
OverTimeWorkValue = x.OverTimeWorkValue,
|
|
OverNightWorkValue = x.OverNightWorkValue,
|
|
FridayWorkValue = x.FridayWorkValue,
|
|
RotatingShiftValue = x.RotatingShiftValue,
|
|
AbsenceValue = x.AbsenceValue,
|
|
MaritalStatus = "",
|
|
TotalDayOfLeaveCompute = "-",
|
|
TotalDayOfYearsCompute = "-",
|
|
TotalDayOfBunosesCompute = "-",
|
|
InstallmentViewModels = x.LoanInstallments.Select(i => new LoanInstallmentViewModel()
|
|
{
|
|
Amount = i.AmountForMonth,
|
|
AmountDouble = i.AmountForMonth.MoneyToDouble(),
|
|
Year = i.Year,
|
|
Month = i.Month,
|
|
IsActive = i.IsActive,
|
|
RemainingAmount = i.LoanRemaining,
|
|
LoanAmount = i.LoanAmount
|
|
}).ToList(),
|
|
SalaryAidViewModels = x.SalaryAids.Select(s => new SalaryAidViewModel()
|
|
{
|
|
Amount = s.Amount,
|
|
AmountDouble = s.Amount.MoneyToDouble(),
|
|
SalaryAidDateTimeFa = s.SalaryAidDateTimeFa,
|
|
SalaryAidDateTimeGe = s.SalaryAidDateTime
|
|
}).ToList(),
|
|
CheckoutRollCall = x.CheckoutRollCall != null ? new CheckoutRollCallViewModel()
|
|
{
|
|
TotalPresentTimeSpan = x.CheckoutRollCall.TotalPresentTimeSpan,
|
|
TotalBreakTimeSpan = x.CheckoutRollCall.TotalBreakTimeSpan,
|
|
TotalWorkingTimeSpan = x.CheckoutRollCall.TotalWorkingTimeSpan,
|
|
TotalPaidLeaveTmeSpan = x.CheckoutRollCall.TotalPaidLeaveTmeSpan,
|
|
TotalMandatoryTimeSpan = x.CheckoutRollCall.TotalMandatoryTimeSpan,
|
|
TotalSickLeaveTimeSpan = x.CheckoutRollCall.TotalSickLeaveTimeSpan,
|
|
RollCallDaysCollection = x.CheckoutRollCall.RollCallDaysCollection.Select(d => new CheckoutRollCallDayViewModel()
|
|
{
|
|
WorkingTimeSpan = d.WorkingTimeSpan,
|
|
BreakTimeSpan = d.BreakTimeSpan,
|
|
IsSliced = d.IsSliced,
|
|
IsAbsent = d.IsAbsent,
|
|
IsFriday = d.IsFriday,
|
|
IsHoliday = d.IsHoliday,
|
|
LeaveType = d.LeaveType,
|
|
CheckoutId = d.CheckoutId,
|
|
Date = d.Date,
|
|
FirstEndDate = d.FirstEndDate,
|
|
FirstStartDate = d.FirstStartDate,
|
|
Id = d.Id,
|
|
SecondEndDate = d.SecondEndDate,
|
|
SecondStartDate = d.SecondStartDate,
|
|
}).ToList()
|
|
|
|
} : null,
|
|
HasAmountConflict =x.HasAmountConflict,
|
|
}).SingleOrDefault(x => x.Id == item);
|
|
var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId);
|
|
ch.WorkshopName = workshopName.WorkshopName;
|
|
ch.TotalPaymentHide = workshopName.TotalPaymentHide;
|
|
var emp = _context.WorkshopEmployers.Where(x => x.WorkshopId == ch.WorkshopId)
|
|
.Select(x => x.EmployerId);
|
|
var employerlist = _context.Employers.Where(x => emp.Contains(x.id));
|
|
var employers = new List<EmprViewModel>();
|
|
|
|
foreach (var em in employerlist)
|
|
{
|
|
var employer = new EmprViewModel()
|
|
{
|
|
EmployerFullName = em.FName + " " + em.LName,
|
|
IsLegal = em.IsLegal,
|
|
};
|
|
employers.Add(employer);
|
|
}
|
|
|
|
ch.MaritalStatus = _context.Employees.Find(ch.EmployeeId)?.MaritalStatus;
|
|
ch.EmployerList = employers;
|
|
var workingHours = _workingHoursTempApplication.GetByContractIdConvertToShiftwork4(ch.ContractId);
|
|
ch.CreateWorkingHoursTemp = workingHours;
|
|
var AbsenceDeduction = ch.AbsenceDeduction.MoneyToDouble();
|
|
var InstallmentDeduction = ch.InstallmentDeduction.MoneyToDouble();
|
|
var InsuranceDeduction = ch.InsuranceDeduction.MoneyToDouble();
|
|
var SalaryAidDeduction = ch.SalaryAidDeduction.MoneyToDouble();
|
|
var TaxDeducation = ch.TaxDeducation.MoneyToDouble();
|
|
var TotalDeduction = AbsenceDeduction + InsuranceDeduction + InstallmentDeduction + SalaryAidDeduction +
|
|
TaxDeducation;
|
|
ch.TotalDeductions = TotalDeduction.ToMoney();
|
|
|
|
|
|
var leftWorkSearch = new LeftWorkSearchModel() { WorkshopId = ch.WorkshopId, EmployeeId = ch.EmployeeId };
|
|
var leftworkResult = _leftWorkRepository.search(leftWorkSearch).FirstOrDefault();
|
|
var leftCheck = _leftWorkRepository.CheckoutleftWorkCheck(ch.ContractStartGr, ch.WorkshopId, ch.EmployeeId);
|
|
var contractLeftWorkDate = ch.ContractEndGr.AddDays(1);
|
|
if (leftCheck != null && leftCheck.LeftWorkDateGr == contractLeftWorkDate)
|
|
{
|
|
ch.IsLeft = true;
|
|
ch.LeftWorkDate = leftCheck.LeftWorkDate;
|
|
ch.LastDayOfWork = ch.ContractEndGr.ToFarsi();
|
|
}
|
|
//var checkBonusesPay = leftworkResult != null && leftworkResult.AddBonusesPay;
|
|
//var checkYearsPay = leftworkResult != null && leftworkResult.AddYearsPay;
|
|
//var checkLeavePay = leftworkResult != null && leftworkResult.AddLeavePay;
|
|
|
|
//if (!checkBonusesPay || !checkYearsPay || !checkLeavePay)
|
|
//{
|
|
// double sumOfBonusAndYearsPay = 0;
|
|
// if (!checkBonusesPay)
|
|
// {
|
|
// var bonusesPay = ch.BonusesPay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += bonusesPay;
|
|
// ch.BonusesPay = "0";
|
|
|
|
// }
|
|
|
|
// if (!checkYearsPay)
|
|
// {
|
|
// var yearsPay = ch.YearsPay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += yearsPay;
|
|
// ch.YearsPay = "0";
|
|
// }
|
|
|
|
// if (!checkLeavePay)
|
|
// {
|
|
// var leavePay = ch.LeavePay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += leavePay;
|
|
// ch.LeavePay = "0";
|
|
// }
|
|
// var totalClaimsDouble = ch.TotalClaims.MoneyToDouble();
|
|
// var totalClaims = totalClaimsDouble - sumOfBonusAndYearsPay;
|
|
// ch.TotalClaims = totalClaims.ToMoney();
|
|
|
|
// var totalPayment = totalClaims - TotalDeduction;
|
|
// ch.TotalPayment = totalPayment.ToMoney();
|
|
|
|
|
|
//}
|
|
|
|
//if (ch.WorkshopId == 40 || ch.WorkshopId == 68 || ch.WorkshopId == 44 || ch.WorkshopId == 45 || ch.WorkshopId == 280)
|
|
//{
|
|
// ch.TotalClaims = "";
|
|
// ch.TotalDeductions = "";
|
|
// ch.TotalPayment = "";
|
|
//}
|
|
|
|
#region Leave
|
|
|
|
var leavesQuery = _context.LeaveList
|
|
.Where(x => x.EmployeeId == ch.EmployeeId && x.WorkshopId == ch.WorkshopId &&
|
|
x.StartLeave <= ch.ContractEndGr && x.EndLeave >= ch.ContractStartGr)
|
|
.AsNoTracking();
|
|
|
|
var paidLeave = leavesQuery.Where(x => x.LeaveType == "استحقاقی");
|
|
var sickLeave = leavesQuery.Where(x => x.LeaveType == "استعلاجی").ToList();
|
|
|
|
|
|
var dailyPaidLeave = paidLeave.Where(x => x.PaidLeaveType == "روزانه").ToList();
|
|
var hourlyPaidLeave = paidLeave.Where(x => x.PaidLeaveType == "ساعتی").ToList();
|
|
|
|
var sickLeaveTimeSpans = sickLeave.Select(x =>
|
|
{
|
|
var startLeave = ch.ContractStartGr > x.StartLeave ? ch.ContractStartGr : x.StartLeave;
|
|
var endLeave = ch.ContractEndGr < x.EndLeave ? ch.ContractEndGr : x.EndLeave;
|
|
|
|
return (endLeave - startLeave).Add(TimeSpan.FromDays(1));
|
|
});
|
|
|
|
ch.TotalSickLeave = new TimeSpan(sickLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-");
|
|
|
|
var hourlyPaidLeaveTimeSpans = hourlyPaidLeave.Select(x => TimeOnly.Parse(x.LeaveHourses).ToTimeSpan());
|
|
|
|
var dailyPaidLeaveTimeSpans = dailyPaidLeave.Select(x =>
|
|
{
|
|
var startLeave = ch.ContractStartGr > x.StartLeave ? ch.ContractStartGr : x.StartLeave;
|
|
var endLeave = ch.ContractEndGr < x.EndLeave ? ch.ContractEndGr : x.EndLeave;
|
|
return (endLeave - startLeave).Add(TimeSpan.FromDays(1));
|
|
});
|
|
|
|
var totalPaidLeaveTimeSpans = hourlyPaidLeaveTimeSpans.Concat(dailyPaidLeaveTimeSpans);
|
|
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.CheckoutRollCall != null)
|
|
{
|
|
ch.TotalWorkingTimeStr = ch.CheckoutRollCall.TotalWorkingTimeSpan.ToFarsiHoursAndMinutes("-");
|
|
ch.TotalBreakTimeStr = ch.CheckoutRollCall.TotalBreakTimeSpan.ToFarsiHoursAndMinutes("-");
|
|
ch.TotalPresentTimeStr = ch.CheckoutRollCall.TotalPresentTimeSpan.ToFarsiHoursAndMinutes("-");
|
|
ch.TotalMandatoryTimeStr = ch.CheckoutRollCall.TotalMandatoryTimeSpan.ToFarsiHoursAndMinutes("-");
|
|
ch.TotalPaidLeave = ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.ToFarsiDaysAndHoursAndMinutes("-");
|
|
ch.MonthlyRollCall = ch.CheckoutRollCall.RollCallDaysCollection
|
|
.Select(x => new CheckoutDailyRollCallViewModel
|
|
{
|
|
DayOfWeek = x.Date.DayOfWeek.DayOfWeeKToPersian(),
|
|
StartDate1 = x.FirstStartDate,
|
|
EndDate1 = x.FirstEndDate,
|
|
StartDate2 = x.SecondStartDate,
|
|
EndDate2 = x.SecondEndDate,
|
|
TotalhourseSpan = x.WorkingTimeSpan,
|
|
IsSliced = x.IsSliced,
|
|
BreakTimeTimeSpan = x.BreakTimeSpan,
|
|
LeaveType = x.LeaveType,
|
|
IsAbsent = x.IsAbsent,
|
|
IsFriday = x.IsFriday,
|
|
IsHoliday = x.IsHoliday,
|
|
DateTimeGr = x.Date,
|
|
TotalWorkingHours = $"{(int)(x.WorkingTimeSpan.TotalHours)}:{x.WorkingTimeSpan.Minutes:00}",
|
|
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);
|
|
else
|
|
{
|
|
ch.CreateWorkingHoursTemp.ContractStartGr = ch.ContractStartGr;
|
|
ch.CreateWorkingHoursTemp.ContractEndGr = ch.ContractEndGr;
|
|
ch.CreateWorkingHoursTemp.ContarctStart = ch.ContractStartGr.ToFarsi();
|
|
ch.CreateWorkingHoursTemp.ContractEnd = ch.ContractEndGr.ToFarsi();
|
|
ch.CreateWorkingHoursTemp.EmployeeId = ch.EmployeeId;
|
|
ch.CreateWorkingHoursTemp.WorkshopId = ch.WorkshopId;
|
|
ch.MonthlyRollCall = ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking);
|
|
}
|
|
}
|
|
query.Add(ch);
|
|
}
|
|
|
|
query = query.OrderBy(x => x.PersonnelCodeInt).ToList();
|
|
int printNumer = 0;
|
|
foreach (var rec in query)
|
|
{
|
|
printNumer += 1;
|
|
rec.PrintCounter = printNumer;
|
|
}
|
|
return query;
|
|
}
|
|
|
|
public CheckoutLeavePrintViewModel PrintLeave(long id)
|
|
{
|
|
var ch = _context.CheckoutSet.Select(x => new CheckoutLeavePrintViewModel()
|
|
{
|
|
Id = x.id,
|
|
EmployeeId = x.EmployeeId,
|
|
ContractNo = x.ContractNo,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
NationalCode = x.NationalCode,
|
|
WorkshopId = x.WorkshopId,
|
|
WorkshopName = x.WorkshopName,
|
|
LeaveList = new List<LeaveViewModel>(),
|
|
EmployerList = new List<EmprViewModel>(),
|
|
}).SingleOrDefault(x => x.Id == id);
|
|
|
|
var emp = _context.WorkshopEmployers.Where(x => x.WorkshopId == ch.WorkshopId)
|
|
.Select(x => x.EmployerId).ToList();
|
|
var employerlist = _context.Employers.Select(x => new EmprViewModel()
|
|
{
|
|
Id = x.id,
|
|
EmployerFullName = x.FName + " " + x.LName,
|
|
IsLegal = x.IsLegal,
|
|
|
|
}).Where(x => emp.Contains(x.Id)).ToList();
|
|
if (employerlist.Count > 0)
|
|
{
|
|
ch.EmployerList = employerlist;
|
|
}
|
|
else
|
|
{
|
|
ch.EmployerList = new List<EmprViewModel>();
|
|
}
|
|
|
|
|
|
//var leaveList = _context.LeaveList.Select(x => new LeaveViewModel()
|
|
//{
|
|
// Id = x.id,
|
|
// StartLeave = x.StartLeave.ToFarsi(),
|
|
// EndLeave = x.EndLeave.ToFarsi(),
|
|
// LeaveHourses = x.LeaveHourses,
|
|
// WorkshopId = x.WorkshopId,
|
|
// EmployeeId = x.EmployeeId,
|
|
// PaidLeaveType = x.PaidLeaveType,
|
|
// LeaveType = x.LeaveType,
|
|
//}).Where(x => x.WorkshopId == ch.WorkshopId && x.EmployeeId == ch.EmployeeId && x.LeaveType == "استحقاقی").ToList();
|
|
//if (leaveList.Count > 0)
|
|
//{
|
|
// ch.LeaveList = leaveList;
|
|
//}
|
|
|
|
|
|
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)
|
|
{
|
|
var StartTime = Convert.ToDateTime(list.StartLeave);
|
|
var EndTime = Convert.ToDateTime(list.EndLeave);
|
|
if (StartTime > EndTime || StartTime == EndTime)
|
|
{
|
|
EndTime = EndTime.AddDays(1);
|
|
}
|
|
|
|
var ConvertTime = (Convert.ToDateTime(EndTime) - Convert.ToDateTime(StartTime));
|
|
var hours = (int)ConvertTime.TotalHours;
|
|
var minutes = ConvertTime.TotalMinutes % 60;
|
|
|
|
var LeaveHourses = "";
|
|
if (hours > 0 && minutes > 0)
|
|
{
|
|
LeaveHourses = hours + " " + "ساعت و" + " " + minutes + " " + "دقیقه";
|
|
}
|
|
else if (hours > 0 && minutes == 0)
|
|
{
|
|
LeaveHourses = hours + " " + "ساعت";
|
|
}
|
|
else if (hours == 0 && minutes > 0)
|
|
{
|
|
LeaveHourses = minutes + " " + "دقیقه";
|
|
}
|
|
|
|
var leave = new LeaveViewModel()
|
|
{
|
|
Id = list.id,
|
|
StartLeave = list.StartLeave.ToFarsi(),
|
|
EndLeave = list.EndLeave.ToFarsi(),
|
|
StartLeaveGr = list.StartLeave,
|
|
EndLeaveGr = list.EndLeave,
|
|
LeaveHourses = LeaveHourses,
|
|
WorkshopId = list.WorkshopId,
|
|
EmployeeId = list.EmployeeId,
|
|
PaidLeaveType = list.PaidLeaveType,
|
|
LeaveType = list.LeaveType,
|
|
};
|
|
leaveViewModel.Add(leave);
|
|
}
|
|
|
|
ch.LeaveList = leaveViewModel;
|
|
|
|
|
|
return ch;
|
|
}
|
|
|
|
public CheckoutViewModel PrintOne(long id)
|
|
{
|
|
var ch = _context.CheckoutSet
|
|
.AsSplitQuery().Select(x => new CheckoutViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
ContractId = x.ContractId,
|
|
EmployeeId = x.EmployeeId,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
FathersName = x.FathersName,
|
|
NationalCode = x.NationalCode,
|
|
DateOfBirth = x.DateOfBirth,
|
|
WorkshopName = x.WorkshopName,
|
|
Month = x.Month,
|
|
Year = x.Year,
|
|
ContractNo = x.ContractNo,
|
|
MonthlySalary = x.MonthlySalary.ToMoney(),
|
|
BaseYearsPay = x.BaseYearsPay.ToMoney(),
|
|
ConsumableItems = x.ConsumableItems.ToMoney(),
|
|
HousingAllowance = x.HousingAllowance.ToMoney(),
|
|
OvertimePay = x.OvertimePay.ToMoney(),
|
|
NightworkPay = x.NightworkPay.ToMoney(),
|
|
FridayPay = x.FridayPay.ToMoney(),
|
|
MissionPay = x.MissionPay.ToMoney(),
|
|
ShiftPay = x.ShiftPay.ToMoney(),
|
|
FamilyAllowance = x.FamilyAllowance.ToMoney(),
|
|
BonusesPay = x.BonusesPay.ToMoney(),
|
|
YearsPay = x.YearsPay.ToMoney(),
|
|
LeavePay = x.LeavePay.ToMoney(),
|
|
InsuranceDeduction = x.InsuranceDeduction.ToMoney(),
|
|
TaxDeducation = x.TaxDeducation.ToMoney(),
|
|
InstallmentDeduction = x.InstallmentDeduction.ToMoney(),
|
|
SalaryAidDeduction = x.SalaryAidDeduction.ToMoney(),
|
|
AbsenceDeduction = x.AbsenceDeduction.ToMoney(),
|
|
TotalClaims = x.TotalClaims,
|
|
TotalDeductions = x.TotalDeductions,
|
|
TotalPayment = x.TotalPayment.ToMoney(),
|
|
RewardPay = x.RewardPay.ToMoneyNullable(),
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
IsLeft = false,
|
|
LeftWorkDate = "",
|
|
LastDayOfWork = "",
|
|
MarriedAllowance = x.MarriedAllowance.ToMoney(),
|
|
HasRollCall = x.HasRollCall,
|
|
SumOfWorkingDays = "-",
|
|
OverTimeWorkValue = x.OverTimeWorkValue,
|
|
OverNightWorkValue = x.OverNightWorkValue,
|
|
FridayWorkValue = x.FridayWorkValue,
|
|
RotatingShiftValue = x.RotatingShiftValue,
|
|
AbsenceValue = x.AbsenceValue,
|
|
MaritalStatus = "",
|
|
TotalDayOfLeaveCompute = "-",
|
|
TotalDayOfYearsCompute = "-",
|
|
TotalDayOfBunosesCompute = "-",
|
|
InstallmentViewModels = x.LoanInstallments.Select(i => new LoanInstallmentViewModel()
|
|
{
|
|
Amount = i.AmountForMonth,
|
|
AmountDouble = i.AmountForMonth.MoneyToDouble(),
|
|
Year = i.Year,
|
|
Month = i.Month,
|
|
IsActive = i.IsActive,
|
|
RemainingAmount = i.LoanRemaining,
|
|
LoanAmount = i.LoanAmount
|
|
}).ToList(),
|
|
SalaryAidViewModels = x.SalaryAids.Select(s => new SalaryAidViewModel()
|
|
{
|
|
Amount = s.Amount,
|
|
AmountDouble = s.Amount.MoneyToDouble(),
|
|
SalaryAidDateTimeFa = s.SalaryAidDateTimeFa,
|
|
SalaryAidDateTimeGe = s.SalaryAidDateTime
|
|
}).ToList(),
|
|
|
|
}).SingleOrDefault(x => x.Id == id);
|
|
|
|
var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId);
|
|
ch.WorkshopName = workshopName.WorkshopName;
|
|
ch.TotalPaymentHide = workshopName.TotalPaymentHide;
|
|
var emp = _context.WorkshopEmployers.Where(x => x.WorkshopId == ch.WorkshopId)
|
|
.Select(x => x.EmployerId);
|
|
var employerlist = _context.Employers.Where(x => emp.Contains(x.id));
|
|
var employers = new List<EmprViewModel>();
|
|
|
|
foreach (var em in employerlist)
|
|
{
|
|
var employer = new EmprViewModel()
|
|
{
|
|
EmployerFullName = em.FName + " " + em.LName,
|
|
IsLegal = em.IsLegal,
|
|
};
|
|
employers.Add(employer);
|
|
}
|
|
ch.MaritalStatus = _context.Employees.Find(ch.EmployeeId)?.MaritalStatus;
|
|
ch.EmployerList = employers;
|
|
var workingHours = _workingHoursTempApplication.GetByContractIdConvertToShiftwork4(ch.ContractId);
|
|
ch.CreateWorkingHoursTemp = workingHours;
|
|
var AbsenceDeduction = ch.AbsenceDeduction.MoneyToDouble();
|
|
var InstallmentDeduction = ch.InstallmentDeduction.MoneyToDouble();
|
|
var InsuranceDeduction = ch.InsuranceDeduction.MoneyToDouble();
|
|
var SalaryAidDeduction = ch.SalaryAidDeduction.MoneyToDouble();
|
|
var TaxDeducation = ch.TaxDeducation.MoneyToDouble();
|
|
|
|
var TotalDeduction = AbsenceDeduction + InsuranceDeduction + InstallmentDeduction + SalaryAidDeduction +
|
|
TaxDeducation;
|
|
ch.TotalDeductions = TotalDeduction.ToMoney();
|
|
|
|
|
|
var leftWorkSearch = new LeftWorkSearchModel() { WorkshopId = ch.WorkshopId, EmployeeId = ch.EmployeeId };
|
|
var leftworkResult = _leftWorkRepository.search(leftWorkSearch).FirstOrDefault();
|
|
var leftCheck = _leftWorkRepository.CheckoutleftWorkCheck(ch.ContractStartGr, ch.WorkshopId, ch.EmployeeId);
|
|
var contractLeftWorkDate = ch.ContractEndGr.AddDays(1);
|
|
if (leftCheck != null && leftCheck.LeftWorkDateGr == contractLeftWorkDate)
|
|
{
|
|
ch.IsLeft = true;
|
|
ch.LeftWorkDate = leftCheck.LeftWorkDate;
|
|
ch.LastDayOfWork = ch.ContractEndGr.ToFarsi();
|
|
}
|
|
|
|
//var checkBonusesPay = leftworkResult != null && leftworkResult.AddBonusesPay;
|
|
//var checkYearsPay = leftworkResult != null && leftworkResult.AddYearsPay;
|
|
//var checkLeavePay = leftworkResult != null && leftworkResult.AddLeavePay;
|
|
|
|
//if (!checkBonusesPay || !checkYearsPay || !checkLeavePay)
|
|
//{
|
|
// double sumOfBonusAndYearsPay = 0;
|
|
// if (!checkBonusesPay)
|
|
// {
|
|
// var bonusesPay = ch.BonusesPay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += bonusesPay;
|
|
// ch.BonusesPay = "0";
|
|
|
|
// }
|
|
|
|
// if (!checkYearsPay)
|
|
// {
|
|
// var yearsPay = ch.YearsPay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += yearsPay;
|
|
// ch.YearsPay = "0";
|
|
// }
|
|
|
|
// if (!checkLeavePay)
|
|
// {
|
|
// var leavePay = ch.LeavePay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += leavePay;
|
|
// ch.LeavePay = "0";
|
|
// }
|
|
// var totalClaimsDouble = ch.TotalClaims.MoneyToDouble();
|
|
// var totalClaims = totalClaimsDouble - sumOfBonusAndYearsPay;
|
|
// ch.TotalClaims = totalClaims.ToMoney();
|
|
|
|
// var totalPayment = totalClaims - TotalDeduction;
|
|
// ch.TotalPayment = totalPayment.ToMoney();
|
|
|
|
//}
|
|
|
|
//if (ch.WorkshopId == 40 || ch.WorkshopId == 68 || ch.WorkshopId == 44 || ch.WorkshopId == 45 || ch.WorkshopId == 280)
|
|
//{
|
|
// ch.TotalClaims = "";
|
|
// ch.TotalDeductions = "";
|
|
// ch.TotalPayment = "";
|
|
//}
|
|
|
|
#region Leave
|
|
|
|
var leavesQuery = _context.LeaveList
|
|
.Where(x => x.EmployeeId == ch.EmployeeId && x.WorkshopId == ch.WorkshopId &&
|
|
x.StartLeave <= ch.ContractEndGr && x.EndLeave >= ch.ContractStartGr)
|
|
.AsNoTracking();
|
|
|
|
var paidLeave = leavesQuery.Where(x => x.LeaveType == "استحقاقی");
|
|
var sickLeave = leavesQuery.Where(x => x.LeaveType == "استعلاجی").ToList();
|
|
|
|
|
|
var dailyPaidLeave = paidLeave.Where(x => x.PaidLeaveType == "روزانه").ToList();
|
|
var hourlyPaidLeave = paidLeave.Where(x => x.PaidLeaveType == "ساعتی").ToList();
|
|
|
|
var sickLeaveTimeSpans = sickLeave.Select(x =>
|
|
{
|
|
var startLeave = ch.ContractStartGr > x.StartLeave ? ch.ContractStartGr : x.StartLeave;
|
|
var endLeave = ch.ContractEndGr < x.EndLeave ? ch.ContractEndGr : x.EndLeave;
|
|
|
|
return (endLeave - startLeave).Add(TimeSpan.FromDays(1));
|
|
});
|
|
|
|
ch.TotalSickLeave = new TimeSpan(sickLeaveTimeSpans.Sum(x => x.Ticks)).ToFarsiDaysAndHoursAndMinutes("-");
|
|
|
|
var hourlyPaidLeaveTimeSpans = hourlyPaidLeave.Select(x => TimeOnly.Parse(x.LeaveHourses).ToTimeSpan()).ToList();
|
|
|
|
var dailyPaidLeaveTimeSpans = dailyPaidLeave.Select(x =>
|
|
{
|
|
var startLeave = ch.ContractStartGr > x.StartLeave ? ch.ContractStartGr : x.StartLeave;
|
|
var endLeave = ch.ContractEndGr < x.EndLeave ? ch.ContractEndGr : x.EndLeave;
|
|
return (endLeave - startLeave).Add(TimeSpan.FromDays(1));
|
|
});
|
|
|
|
var totalPaidLeaveTimeSpans = hourlyPaidLeaveTimeSpans.Concat(dailyPaidLeaveTimeSpans);
|
|
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);
|
|
else
|
|
{
|
|
ch.CreateWorkingHoursTemp.ContractStartGr = ch.ContractStartGr;
|
|
ch.CreateWorkingHoursTemp.ContractEndGr = ch.ContractEndGr;
|
|
ch.CreateWorkingHoursTemp.ContarctStart = ch.ContractStartGr.ToFarsi();
|
|
ch.CreateWorkingHoursTemp.ContractEnd = ch.ContractEndGr.ToFarsi();
|
|
ch.CreateWorkingHoursTemp.EmployeeId = ch.EmployeeId;
|
|
ch.CreateWorkingHoursTemp.WorkshopId = ch.WorkshopId;
|
|
ch.MonthlyRollCall = ConvertStaticToRollCall(ch.CreateWorkingHoursTemp, workshopName.WorkshopHolidayWorking);
|
|
}
|
|
return ch;
|
|
}
|
|
|
|
private List<CheckoutDailyRollCallViewModel> ConvertStaticToRollCall(CreateWorkingHoursTemp workingHours, bool workshopHolidayWorking)
|
|
{
|
|
var rollCalls = _rollCallMandatoryRepository.ConvertStaticHoursToRollCall(workingHours,
|
|
workshopHolidayWorking);
|
|
var workshopId = workingHours.WorkshopId;
|
|
var employeeId = workingHours.EmployeeId;
|
|
var year = Convert.ToInt32(workingHours.ContarctStart.Substring(0, 4));
|
|
var month = Convert.ToInt32(workingHours.ContarctStart.Substring(5, 2));
|
|
var startMonthDay = $"{year:0000}/{month:00}/01".ToGeorgianDateTime();
|
|
var endMonthDay = workingHours.ContractEndGr;
|
|
|
|
var leaves = _context.LeaveList.Where(x =>
|
|
x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.EndLeave.Date >= startMonthDay.Date &&
|
|
x.StartLeave.Date <= endMonthDay.Date).ToList();
|
|
|
|
var firstDayOfCurrentMonth = new DateTime(year, month, 1, new PersianCalendar());
|
|
|
|
|
|
if (month == 12)
|
|
{
|
|
year += 1;
|
|
month = 1;
|
|
}
|
|
else
|
|
month += 1;
|
|
|
|
var nextMonthDate = new DateTime(year, month, 1, new PersianCalendar());
|
|
|
|
var lastDayOfCurrentMonth = nextMonthDate.AddDays(-1);
|
|
|
|
int dateRange = (int)(lastDayOfCurrentMonth - firstDayOfCurrentMonth).TotalDays + 1;
|
|
|
|
|
|
var holidays = _context.HolidayItems.Where(x => x.HolidayYear.Contains(year.ToString())).Select(x => new HolidayItemViewModel
|
|
{
|
|
Id = x.id,
|
|
Holidaydate = x.Holidaydate.ToFarsi(),
|
|
HolidayId = x.HolidayId,
|
|
HolidayYear = x.HolidayYear,
|
|
HolidaydateGr = x.Holidaydate
|
|
}).ToList();
|
|
|
|
if (workshopHolidayWorking)
|
|
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 absentRecords = completeDaysList
|
|
.ExceptBy(rollCalls.Select(x => x.ShiftDate.Date), y => y.Date)
|
|
.Select(x =>
|
|
{
|
|
var leave = leaves.FirstOrDefault(y =>
|
|
y.EmployeeId == employeeId && y.EndLeave.Date >= x.Date && y.StartLeave.Date <= x.Date);
|
|
var isHoliday = false;
|
|
var isFriday = x.Date.DayOfWeek == DayOfWeek.Friday;
|
|
var isNormalWorkingDay = isHoliday == false && isFriday == false;
|
|
return new CheckoutDailyRollCallViewModel()
|
|
{
|
|
StartDate1 = null,
|
|
EndDate1 = null,
|
|
DateTimeGr = x.Date,
|
|
DayOfWeek = x.Date.DayOfWeek.DayOfWeeKToPersian(),
|
|
RollCallDateFa = x.Date.ToFarsi(),
|
|
LeaveType = leave != null ? leave.LeaveType : "",
|
|
IsAbsent = leave == null && isNormalWorkingDay
|
|
};
|
|
});
|
|
|
|
|
|
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));
|
|
var breakTimePerDay = new TimeSpan(x.Sum(r => r.BreakTimeSpan.Ticks));
|
|
|
|
var firstRollCall = orderedRollcalls.FirstOrDefault();
|
|
var secondRollCall = orderedRollcalls.Skip(1).FirstOrDefault();
|
|
DateTime? secondRCEndDate = null;
|
|
DateTime? firstRCEndDate = null;
|
|
|
|
if (firstRollCall != null)
|
|
firstRCEndDate = firstRollCall.ShiftEndWithoutRest ?? firstRollCall.EndDate;
|
|
if (secondRollCall != null)
|
|
secondRCEndDate = secondRollCall.ShiftEndWithoutRest ?? secondRollCall.EndDate;
|
|
|
|
|
|
|
|
return new CheckoutDailyRollCallViewModel()
|
|
{
|
|
StartDate1 = firstRollCall?.StartDate?.ToString("HH:mm") ?? "",
|
|
EndDate1 = firstRCEndDate?.ToString("HH:mm") ?? "",
|
|
|
|
StartDate2 = secondRollCall?.StartDate?.ToString("HH:mm") ?? "",
|
|
EndDate2 = secondRCEndDate?.ToString("HH:mm") ?? "",
|
|
|
|
TotalhourseSpan = rollCallTimeSpanPerDay - breakTimePerDay,
|
|
|
|
BreakTimeTimeSpan = breakTimePerDay,
|
|
|
|
DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(),
|
|
RollCallDateFa = x.Key.Date.ToFarsi(),
|
|
DateTimeGr = x.Key.Date,
|
|
IsSliced = x.Count() > 2,
|
|
IsAbsent = false
|
|
};
|
|
});
|
|
|
|
|
|
presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel
|
|
{
|
|
StartDate1 = x.StartDate1,
|
|
EndDate1 = x.EndDate1,
|
|
EndDate2 = x.EndDate2,
|
|
StartDate2 = x.StartDate2,
|
|
TotalWorkingHours = $"{(int)(x.TotalhourseSpan.TotalHours)}:{x.TotalhourseSpan.Minutes:00}",
|
|
BreakTimeString = $"{(int)(x.BreakTimeTimeSpan.TotalHours)}:{x.BreakTimeTimeSpan.Minutes:00}",
|
|
TotalhourseSpan = x.TotalhourseSpan,
|
|
BreakTimeTimeSpan = x.BreakTimeTimeSpan,
|
|
DayOfWeek = x.DayOfWeek,
|
|
RollCallDateFa = x.RollCallDateFa,
|
|
DateTimeGr = x.DateTimeGr,
|
|
IsSliced = x.IsSliced,
|
|
IsAbsent = false
|
|
});
|
|
|
|
var result = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList();
|
|
result.ForEach(x =>
|
|
{
|
|
x.IsHoliday = holidays.Any(y => x.DateTimeGr.Date == y.HolidaydateGr.Date);
|
|
x.IsFriday = x.DateTimeGr.DayOfWeek == DayOfWeek.Friday;
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
public OperationResult RemoveCheckout(long id)
|
|
{
|
|
var op = new OperationResult();
|
|
var item = _context.CheckoutSet.FirstOrDefault(x => x.id == id);
|
|
if (item != null)
|
|
_context.CheckoutSet.Remove(item);
|
|
|
|
_context.SaveChanges();
|
|
return op.Succcedded();
|
|
}
|
|
|
|
#region Client
|
|
|
|
public List<CheckoutViewModel> SearchForClient(CheckoutSearchModel searchModel)
|
|
{
|
|
#region CheckValidtWorkshop
|
|
|
|
var accountId = _authHelper.CurrentAccountId();
|
|
var contracingPartyAcc = _context.ContractingPartyAccounts.FirstOrDefault(x => x.AccountId == accountId);
|
|
if (contracingPartyAcc == null)
|
|
{
|
|
return new List<CheckoutViewModel>();
|
|
}
|
|
var employers =
|
|
_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);
|
|
if (!checkValid)
|
|
{
|
|
return new List<CheckoutViewModel>();
|
|
}
|
|
#endregion
|
|
var query = _context.CheckoutSet
|
|
.AsSplitQuery().Select(x => new CheckoutViewModel()
|
|
{
|
|
Id = x.id,
|
|
EmployeeId = x.EmployeeId,
|
|
WorkshopId = x.WorkshopId,
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
ContractStart = x.ContractStart.ToFarsi(),
|
|
ContractEnd = x.ContractEnd.ToFarsi(),
|
|
Signature = x.Signature,
|
|
Year = x.Year,
|
|
Month = x.Month,
|
|
ContractNo = x.ContractNo,
|
|
ContractId = x.ContractId,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
PersonnelCode = x.PersonnelCode,
|
|
PersonnelCodeInt = Convert.ToInt32(x.PersonnelCode),
|
|
InstallmentViewModels = x.LoanInstallments.Select(i => new LoanInstallmentViewModel()
|
|
{
|
|
Amount = i.AmountForMonth,
|
|
AmountDouble = i.AmountForMonth.MoneyToDouble(),
|
|
Year = i.Year,
|
|
Month = i.Month,
|
|
IsActive = i.IsActive,
|
|
RemainingAmount = i.LoanRemaining,
|
|
LoanAmount = i.LoanAmount
|
|
}).ToList(),
|
|
SalaryAidViewModels = x.SalaryAids.Select(s => new SalaryAidViewModel()
|
|
{
|
|
Amount = s.Amount,
|
|
AmountDouble = s.Amount.MoneyToDouble(),
|
|
SalaryAidDateTimeFa = s.SalaryAidDateTimeFa,
|
|
SalaryAidDateTimeGe = s.SalaryAidDateTime
|
|
}).ToList(),
|
|
HasAmountConflict = x.HasAmountConflict
|
|
|
|
}).Where(x => x.WorkshopId == searchModel.WorkshopId);
|
|
if (searchModel.EmployeeId > 0)
|
|
{
|
|
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
|
|
searchModel.Sorting = "ContractStart-Max";
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.ContractEnd))
|
|
{
|
|
var start = searchModel.ContractStart.ToGeorgianDateTime();
|
|
var endd = searchModel.ContractEnd.ToGeorgianDateTime();
|
|
query = query.Where(x =>
|
|
x.ContractStartGr >= start && x.ContractEndGr <= endd);
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month))
|
|
{
|
|
var y = searchModel.Year + "/" + searchModel.Month + "/01";
|
|
string y2 = string.Empty;
|
|
int month = Convert.ToInt32(searchModel.Month);
|
|
int year = Convert.ToInt32(searchModel.Year);
|
|
|
|
if (month <= 6)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/31";
|
|
}
|
|
else if (month > 6 && month < 12)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
}
|
|
else if (month == 12)
|
|
{
|
|
switch (year)
|
|
{
|
|
case 1346:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1350:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1354:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1358:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1362:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1366:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1370:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1375:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1379:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1383:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1387:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1391:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1395:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1399:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1403:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1408:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1412:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1416:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1420:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1424:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1428:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1432:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1436:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1441:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1445:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
|
|
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);
|
|
}
|
|
if (searchModel.SearchAll)
|
|
return query.OrderByDescending(x => x.Id).ToList();
|
|
switch (searchModel.Sorting)
|
|
{
|
|
case "CreationDate-Max":
|
|
return query.OrderByDescending(x => x.Id).Skip(searchModel.PageIndex).Take(30).ToList();
|
|
break;
|
|
case "CreationDate-Min":
|
|
return query.OrderBy(x => x.Id).Skip(searchModel.PageIndex).Take(30).ToList();
|
|
break;
|
|
case "PersonelCode-Max":
|
|
return query.OrderByDescending(x => x.PersonnelCodeInt).Skip(searchModel.PageIndex).Take(30).ToList();
|
|
break;
|
|
case "PersonelCode-Min":
|
|
return query.OrderBy(x => x.PersonnelCodeInt).Skip(searchModel.PageIndex).Take(30).ToList();
|
|
break;
|
|
case "ContractStart-Min":
|
|
return query.OrderBy(x => x.ContractStartGr).Skip(searchModel.PageIndex).Take(30).ToList();
|
|
break;
|
|
case "ContractStart-Max":
|
|
return query.OrderByDescending(x => x.ContractStartGr).Skip(searchModel.PageIndex).Take(30).ToList();
|
|
break;
|
|
case "Signature-Min":
|
|
return query.OrderByDescending(x => x.Signature == "0").Skip(searchModel.PageIndex).Take(30).ToList();
|
|
break;
|
|
case "Signature-Max":
|
|
return query.OrderByDescending(x => x.Signature == "1").Skip(searchModel.PageIndex).Take(30).ToList();
|
|
break;
|
|
default: return query.OrderByDescending(x => x.Id).Skip(searchModel.PageIndex).Take(30).ToList();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region NewChangeByHeydari
|
|
|
|
public OperationResult DeleteAllCheckouts(List<long> ids)
|
|
{
|
|
var op = new OperationResult();
|
|
|
|
try
|
|
{
|
|
var contracts = _context.CheckoutSet.Where(x => ids.Contains(x.id)).ToList();
|
|
_context.CheckoutSet.RemoveRange(contracts);
|
|
_context.SaveChanges();
|
|
return op.Succcedded(-1, "حذف با موفقیت شد.");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return op.Failed("حذف با خطا مواجه شد.");
|
|
}
|
|
}
|
|
|
|
public OperationResult DeleteCheckout(long id)
|
|
{
|
|
var op = new OperationResult();
|
|
|
|
try
|
|
{
|
|
|
|
var checkout = _context.CheckoutSet.Where(x => x.id == id)?.FirstOrDefault();
|
|
_context.CheckoutSet.Remove(checkout);
|
|
_context.SaveChanges();
|
|
return op.Succcedded(-1, "حذف با موفقیت انجام شد.");
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return op.Failed("حذف با خطا مواجه شد.");
|
|
}
|
|
}
|
|
|
|
public List<long> CheckHasSignature(List<long> ids)
|
|
{
|
|
List<long> notRemoveList = new List<long>();
|
|
foreach (var item in ids)
|
|
{
|
|
if (_context.CheckoutSet.Any(x => x.id == item && x.Signature == "1"))
|
|
{
|
|
notRemoveList.Add(item);
|
|
}
|
|
}
|
|
return notRemoveList;
|
|
}
|
|
|
|
public async Task<List<CheckoutViewModel>> SearchCheckoutOptimized(CheckoutSearchModel searchModel)
|
|
{
|
|
bool hasSearch = false;
|
|
bool hasEmployeeOrWorkshpSearch = false;
|
|
|
|
//bool noHasSearch = searchModel.WorkshopId == 0 && searchModel.EmployerId == 0
|
|
// && searchModel.EmployeeId == 0
|
|
// && string.IsNullOrWhiteSpace(searchModel.EmployeeName)
|
|
// && string.IsNullOrWhiteSpace(searchModel.Year)
|
|
// && string.IsNullOrWhiteSpace(searchModel.Month)
|
|
// && string.IsNullOrWhiteSpace(searchModel.ContractStart)
|
|
// && string.IsNullOrWhiteSpace(searchModel.ContractEnd)
|
|
// && string.IsNullOrWhiteSpace(searchModel.ContractNo);
|
|
var acountID = _authHelper.CurrentAccountId();
|
|
var workshopAcounts = _context.WorkshopAccounts.Where(x => x.AccountId == acountID)
|
|
.Select(x => x.WorkshopId);
|
|
|
|
//var checkouts =
|
|
// _context.CheckoutSet.Where(x => workshopAcounts.Contains(x.WorkshopId))
|
|
// .Join(_context.Workshops.AsSplitQuery(),
|
|
// ch => ch.WorkshopId,
|
|
// workshop => workshop.id,
|
|
// (ch, workshop) => new { ch, workshop })
|
|
// .GroupJoin(_context.EmployeeComputeOptionsSet.AsSplitQuery(),
|
|
// x => x.workshop.id,
|
|
// option => option.WorkshopId,
|
|
// (x, options) => new { x.ch, x.workshop, options })
|
|
// .SelectMany(
|
|
// x => x.options.DefaultIfEmpty(),
|
|
// (x, option) => new { x.ch, x.workshop, option })
|
|
// .GroupJoin(_context.WorkshopEmployers.AsSplitQuery().Include(we => we.Employer),
|
|
// result => result.workshop.id,
|
|
// workshopEmployer => workshopEmployer.WorkshopId,
|
|
// (result, workshopEmployer) => new { result.ch, result.workshop, result.option, workshopEmployer })
|
|
// .SelectMany(
|
|
// y => y.workshopEmployer.DefaultIfEmpty(),
|
|
// (y, workshopEmployer) => new { y.option, y.ch, y.workshop, workshopEmployer })
|
|
// .GroupJoin(
|
|
// _context.PersonalContractingParties.Include(p => p.Employers),
|
|
// secondResult => secondResult.workshopEmployer.Employer.id,
|
|
// contractingParty => contractingParty.Employers.FirstOrDefault().id, // یا راه بهتر پایین
|
|
// (secondResult, contractingParties) => new { secondResult, contractingParties }
|
|
// )
|
|
// .SelectMany(
|
|
// x => x.contractingParties.DefaultIfEmpty(),
|
|
// (x, contractingParty) => new
|
|
// {
|
|
// x.secondResult.workshopEmployer,
|
|
// x.secondResult.workshop,
|
|
// x.secondResult.option,
|
|
// x.secondResult.ch,
|
|
// contractingParty
|
|
// }
|
|
// );
|
|
|
|
var checkouts =
|
|
_context.CheckoutSet.Where(x => workshopAcounts.Contains(x.WorkshopId))
|
|
.Join(_context.Workshops.AsSplitQuery(),
|
|
ch => ch.WorkshopId,
|
|
workshop => workshop.id,
|
|
(ch, workshop) => new { ch, workshop })
|
|
.GroupJoin(_context.EmployeeComputeOptionsSet.AsSplitQuery(),
|
|
x => x.workshop.id,
|
|
option => option.WorkshopId,
|
|
(x, options) => new { x.ch, x.workshop, options })
|
|
.SelectMany(
|
|
x => x.options.DefaultIfEmpty(),
|
|
(x, option) => new { x.ch, x.workshop, option })
|
|
.GroupJoin(_context.WorkshopEmployers.AsSplitQuery().Include(we => we.Employer),
|
|
result => result.workshop.id,
|
|
workshopEmployer => workshopEmployer.WorkshopId,
|
|
(result, workshopEmployer) => new { result.ch, result.workshop, result.option, workshopEmployer })
|
|
.SelectMany(
|
|
y => y.workshopEmployer.DefaultIfEmpty(),
|
|
(y, workshopEmployer) => new { y.option, y.ch, y.workshop, workshopEmployer })
|
|
.Select(res => new
|
|
{
|
|
res.ch,
|
|
res.workshop,
|
|
option = _context.EmployeeComputeOptionsSet.FirstOrDefault(x=>x.WorkshopId == res.ch.WorkshopId &&x.EmployeeId == res.ch.EmployeeId),
|
|
res.workshopEmployer,
|
|
contractingParty = _context.PersonalContractingParties
|
|
.Include(p => p.Employers)
|
|
.FirstOrDefault(p => p.Employers.Any(e => e.id == res.workshopEmployer.Employer.id))
|
|
});
|
|
|
|
#region SercheModel
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo) && searchModel.ContractId != 0)
|
|
checkouts = checkouts.Where(x =>
|
|
x.ch.ContractNo == searchModel.ContractNo && x.ch.ContractId == searchModel.ContractId);
|
|
if (searchModel.WorkshopId != 0)
|
|
{
|
|
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));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo))
|
|
{
|
|
hasEmployeeOrWorkshpSearch = true;
|
|
checkouts = checkouts.Where(x => x.ch.ContractNo == searchModel.ContractNo);
|
|
}
|
|
|
|
|
|
|
|
//if (searchModel.IsActiveString == null)
|
|
//{
|
|
// checkouts = checkouts.Where(x => x.ch.IsActiveString == "true");
|
|
//}
|
|
|
|
//if (searchModel.IsActiveString == "false")
|
|
//{
|
|
// checkouts = checkouts.Where(x => x.ch.IsActiveString == "false");
|
|
//}
|
|
//else if (searchModel.IsActiveString == "both")
|
|
//{
|
|
// checkouts = checkouts.Where(x => x.ch.IsActiveString == "false" || x.ch.IsActiveString == "true");
|
|
//}
|
|
|
|
|
|
//سرچ سال
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month) &&
|
|
(string.IsNullOrWhiteSpace(searchModel.ContractStart) ||
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd)))
|
|
{
|
|
hasSearch = true;
|
|
var startYear = searchModel.Year + "/01/01";
|
|
var startyearGr = startYear.ToGeorgianDateTime();
|
|
var endYear = $"{searchModel.Year}/12/01".FindeEndOfMonth();
|
|
var endYearGr = endYear.ToGeorgianDateTime();
|
|
|
|
|
|
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) &&
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd))
|
|
{
|
|
hasSearch = true;
|
|
//سرچ سال و ماه
|
|
string y1 = $"{searchModel.Year}/{searchModel.Month}/01";
|
|
var startDate = y1.ToGeorgianDateTime();
|
|
string y2 = string.Empty;
|
|
int month = Convert.ToInt32(searchModel.Month);
|
|
int year = Convert.ToInt32(searchModel.Year);
|
|
|
|
if (month <= 6)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/31";
|
|
}
|
|
else if (month > 6 && month < 12)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
}
|
|
else if (month == 12)
|
|
{
|
|
switch (year)
|
|
{
|
|
case 1346:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1350:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1354:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1358:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1362:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1366:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1370:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1375:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1379:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1383:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1387:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1391:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1395:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1399:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1403:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1408:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1412:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1416:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1420:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1424:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1428:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1432:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1436:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1441:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1445:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
|
|
default:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/29";
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
var endDate = y2.ToGeorgianDateTime();
|
|
|
|
//checkouts = checkouts.Where(x => x.ContractEndGr >= start && x.ContractEndGr <= end).ToList();
|
|
checkouts = checkouts.Where(x =>
|
|
x.ch.ContractStart >= startDate && x.ch.ContractStart < endDate && x.ch.ContractEnd > startDate &&
|
|
x.ch.ContractEnd <= endDate ||
|
|
x.ch.ContractStart <= startDate && x.ch.ContractEnd >= endDate ||
|
|
startDate <= x.ch.ContractStart && endDate > x.ch.ContractStart ||
|
|
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) &&
|
|
string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month))
|
|
{
|
|
hasSearch = true;
|
|
//سرچ تاریخ
|
|
var start = searchModel.ContractStart.ToGeorgianDateTime();
|
|
var endd = searchModel.ContractEnd.ToGeorgianDateTime();
|
|
checkouts = checkouts.Where(x =>
|
|
x.ch.ContractStart >= start && x.ch.ContractStart <= endd);
|
|
|
|
//if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
|
|
// checkouts = checkouts.OrderByDescending(x => x.ch.ContractEnd).ThenBy(x => x.ch.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();
|
|
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(),
|
|
ContractEnd = x.ch.ContractEnd.ToFarsi(),
|
|
ContractStartGr = x.ch.ContractStart,
|
|
ContractEndGr = x.ch.ContractEnd,
|
|
PersonnelCode = x.ch.PersonnelCode,
|
|
PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode),
|
|
ArchiveCode = x.workshop.ArchiveCode,
|
|
SumOfWorkingDays = x.ch.SumOfWorkingDays,
|
|
WorkshopName = x.workshop.WorkshopName,
|
|
Month = x.ch.Month,
|
|
Year = x.ch.Year,
|
|
ContractNo = x.ch.ContractNo,
|
|
ContractId = x.ch.ContractId,
|
|
WorkshopId = x.ch.WorkshopId,
|
|
EmployeeId = x.ch.EmployeeId,
|
|
EmployerId = x.workshopEmployer.EmployerId,
|
|
IsActiveString = x.ch.IsActiveString,
|
|
Signature = x.ch.Signature,
|
|
CreationDate = x.ch.CreationDate,
|
|
EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}",
|
|
IsBlockCantracingParty = x.contractingParty.IsBlock,
|
|
HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout
|
|
|
|
|
|
}).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(),
|
|
ContractEnd = x.ch.ContractEnd.ToFarsi(),
|
|
ContractStartGr = x.ch.ContractStart,
|
|
ContractEndGr = x.ch.ContractEnd,
|
|
PersonnelCode = x.ch.PersonnelCode,
|
|
PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode),
|
|
ArchiveCode = x.workshop.ArchiveCode,
|
|
SumOfWorkingDays = x.ch.SumOfWorkingDays,
|
|
WorkshopName = x.workshop.WorkshopName,
|
|
Month = x.ch.Month,
|
|
Year = x.ch.Year,
|
|
ContractNo = x.ch.ContractNo,
|
|
ContractId = x.ch.ContractId,
|
|
WorkshopId = x.ch.WorkshopId,
|
|
EmployeeId = x.ch.EmployeeId,
|
|
EmployerId = x.workshopEmployer.EmployerId,
|
|
IsActiveString = x.ch.IsActiveString,
|
|
Signature = x.ch.Signature,
|
|
CreationDate = x.ch.CreationDate,
|
|
EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}",
|
|
IsBlockCantracingParty = x.contractingParty.IsBlock,
|
|
HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout
|
|
|
|
}).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))
|
|
{
|
|
//اگر فقط سال رو سرچ کرد
|
|
return result.Take(300)
|
|
.ToList()
|
|
.OrderByDescending(x => x.ContractStartGr).ToList();
|
|
}
|
|
else if ((string.IsNullOrWhiteSpace(searchModel.ContractStart) ||
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd)) && !string.IsNullOrWhiteSpace(searchModel.Month) && !string.IsNullOrWhiteSpace(searchModel.Year))
|
|
{
|
|
//اگر فقط سال و ماه رو سرچ کرد
|
|
return result.Take(300)
|
|
.ToList()
|
|
.OrderByDescending(x => x.ContractStartGr).ToList();
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.ContractEnd))
|
|
{
|
|
//اگر فقط سال و ماه رو سرچ کرد
|
|
return result.Take(300)
|
|
.ToList()
|
|
.OrderByDescending(x => x.ContractStartGr).ToList();
|
|
}
|
|
|
|
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(),
|
|
ContractEnd = x.ch.ContractEnd.ToFarsi(),
|
|
ContractStartGr = x.ch.ContractStart,
|
|
ContractEndGr = x.ch.ContractEnd,
|
|
PersonnelCode = x.ch.PersonnelCode,
|
|
PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode),
|
|
ArchiveCode = x.workshop.ArchiveCode,
|
|
SumOfWorkingDays = x.ch.SumOfWorkingDays,
|
|
WorkshopName = x.workshop.WorkshopName,
|
|
Month = x.ch.Month,
|
|
Year = x.ch.Year,
|
|
ContractNo = x.ch.ContractNo,
|
|
ContractId = x.ch.ContractId,
|
|
WorkshopId = x.ch.WorkshopId,
|
|
EmployeeId = x.ch.EmployeeId,
|
|
EmployerId = x.workshopEmployer.EmployerId,
|
|
IsActiveString = x.ch.IsActiveString,
|
|
Signature = x.ch.Signature,
|
|
CreationDate = x.ch.CreationDate,
|
|
EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}",
|
|
IsBlockCantracingParty = x.contractingParty.IsBlock,
|
|
HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout
|
|
|
|
}).GroupBy(x => x.Id).Select(x => x.First()).ToList()
|
|
.OrderByDescending(x => x.ContractStartGr).ToList();
|
|
}
|
|
else
|
|
{
|
|
return checkouts.Select(x => new CheckoutViewModel()
|
|
{
|
|
|
|
Id = x.ch.id,
|
|
EmployeeFullName = x.ch.EmployeeFullName,
|
|
ContractStart = x.ch.ContractStart.ToFarsi(),
|
|
ContractEnd = x.ch.ContractEnd.ToFarsi(),
|
|
ContractStartGr = x.ch.ContractStart,
|
|
ContractEndGr = x.ch.ContractEnd,
|
|
PersonnelCode = x.ch.PersonnelCode,
|
|
PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode),
|
|
ArchiveCode = x.workshop.ArchiveCode,
|
|
SumOfWorkingDays = x.ch.SumOfWorkingDays,
|
|
WorkshopName = x.workshop.WorkshopName,
|
|
Month = x.ch.Month,
|
|
Year = x.ch.Year,
|
|
ContractNo = x.ch.ContractNo,
|
|
ContractId = x.ch.ContractId,
|
|
WorkshopId = x.ch.WorkshopId,
|
|
EmployeeId = x.ch.EmployeeId,
|
|
EmployerId = x.workshopEmployer.EmployerId,
|
|
IsActiveString = x.ch.IsActiveString,
|
|
Signature = x.ch.Signature,
|
|
CreationDate = x.ch.CreationDate,
|
|
EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}",
|
|
IsBlockCantracingParty = x.contractingParty.IsBlock,
|
|
HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout
|
|
|
|
}).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;
|
|
var connection = _configuration.GetConnectionString("MesbahDb");
|
|
//var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
var AcountID = _authHelper.CurrentAccountId();
|
|
var workshopAcounts = _context.WorkshopAccounts.Where(x => x.AccountId == AcountID)
|
|
.Select(x => x.WorkshopId).ToList();
|
|
//Console.WriteLine("acID.. " + watch.Elapsed);
|
|
|
|
//var watchmp = System.Diagnostics.Stopwatch.StartNew();
|
|
var emp = _context.WorkshopEmployers.Where(x => workshopAcounts.Contains(x.WorkshopId))
|
|
.Select(x => x.EmployerId).FirstOrDefault();
|
|
var emp2 = _context.WorkshopEmployers.Where(x => x.EmployerId == searchModel.EmployerId)
|
|
.Select(x => x.WorkshopId).ToList();
|
|
|
|
|
|
|
|
|
|
var query = _context.CheckoutSet.Select(x => new CheckoutViewModel()
|
|
{
|
|
|
|
Id = x.id,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
//var start = ;
|
|
ContractStart = x.ContractStart.ToFarsi(),
|
|
// var end = (DateTime)reader["ContractEnd"];
|
|
ContractEnd = x.ContractEnd.ToFarsi(),
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
PersonnelCode = x.PersonnelCode,
|
|
PersonnelCodeInt = Convert.ToInt32(x.PersonnelCode),
|
|
ArchiveCode = x.ArchiveCode,
|
|
SumOfWorkingDays = x.SumOfWorkingDays,
|
|
WorkshopName = x.WorkshopName,
|
|
Month = x.Month,
|
|
Year = x.Year,
|
|
ContractNo = x.ContractNo,
|
|
ContractId = x.ContractId,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
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);
|
|
if (searchModel.WorkshopId != 0)
|
|
{
|
|
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;
|
|
query = query.Where(x => emp2.Contains(x.WorkshopId));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo))
|
|
query = query.Where(x => x.ContractNo == searchModel.ContractNo);
|
|
|
|
|
|
if (searchModel.IsActiveString == null)
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "true");
|
|
}
|
|
|
|
if (searchModel.IsActiveString == "false")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false");
|
|
}
|
|
else if (searchModel.IsActiveString == "both")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false" || x.IsActiveString == "true");
|
|
}
|
|
|
|
query = query.Where(e => workshopAcounts.Contains(e.WorkshopId));
|
|
//var resultList = new List<CheckoutViewModel>();
|
|
//resultList = query;
|
|
//سرچ سال
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month) &&
|
|
(string.IsNullOrWhiteSpace(searchModel.ContractStart) ||
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd)))
|
|
{
|
|
hasSearch = true;
|
|
var startYear = searchModel.Year + "/01/01";
|
|
var startyearGr = startYear.ToGeorgianDateTime();
|
|
var endYear = $"{searchModel.Year}/12/01".FindeEndOfMonth();
|
|
var endYearGr = endYear.ToGeorgianDateTime();
|
|
|
|
|
|
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) &&
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd))
|
|
{
|
|
hasSearch = true;
|
|
//سرچ سال و ماه
|
|
string y1 = $"{searchModel.Year}/{searchModel.Month}/01";
|
|
var startDate = y1.ToGeorgianDateTime();
|
|
string y2 = string.Empty;
|
|
int month = Convert.ToInt32(searchModel.Month);
|
|
int year = Convert.ToInt32(searchModel.Year);
|
|
|
|
if (month <= 6)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/31";
|
|
}
|
|
else if (month > 6 && month < 12)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
}
|
|
else if (month == 12)
|
|
{
|
|
switch (year)
|
|
{
|
|
case 1346:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1350:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1354:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1358:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1362:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1366:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1370:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1375:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1379:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1383:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1387:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1391:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1395:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1399:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1403:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1408:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1412:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1416:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1420:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1424:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1428:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1432:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1436:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1441:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1445:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
|
|
default:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/29";
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
var endDate = y2.ToGeorgianDateTime();
|
|
|
|
//query = query.Where(x => x.ContractEndGr >= start && x.ContractEndGr <= end).ToList();
|
|
query = query.Where(x =>
|
|
x.ContractStartGr >= startDate && x.ContractStartGr < endDate && x.ContractEndGr > startDate &&
|
|
x.ContractEndGr <= endDate ||
|
|
x.ContractStartGr <= startDate && x.ContractEndGr >= endDate ||
|
|
startDate <= x.ContractStartGr && endDate > x.ContractStartGr ||
|
|
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) &&
|
|
string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month))
|
|
{
|
|
hasSearch = true;
|
|
//سرچ تاریخ
|
|
var start = searchModel.ContractStart.ToGeorgianDateTime();
|
|
var endd = searchModel.ContractEnd.ToGeorgianDateTime();
|
|
query = query.Where(x =>
|
|
x.ContractStartGr >= start && x.ContractEndGr <= endd);
|
|
|
|
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();
|
|
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();
|
|
else if (hasEmployeeOrWorkshpSearch && !hasSearch)
|
|
return query.OrderByDescending(x => x.ContractStartGr).ToList();
|
|
else
|
|
return query.OrderByDescending(x => x.Id)
|
|
.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)
|
|
{
|
|
|
|
|
|
|
|
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,
|
|
CheckoutStart = x.ContractStart
|
|
}).AsEnumerable().Select(x => (x.EmployeeId, x.CheckoutStart, x.CheckoutEnd)).ToList();
|
|
}
|
|
|
|
public async Task<Checkout> GetByWorkshopIdEmployeeIdInDate(long workshopId, long employeeId, DateTime inDate)
|
|
{
|
|
return await _context.CheckoutSet.FirstOrDefaultAsync(x =>
|
|
x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.ContractStart <= inDate &&
|
|
x.ContractEnd >= inDate);
|
|
}
|
|
|
|
#endregion
|
|
} |