5041 lines
248 KiB
C#
5041 lines
248 KiB
C#
using _0_Framework.Application;
|
||
using _0_Framework.InfraStructure;
|
||
using Company.Domain.CheckoutAgg;
|
||
using Company.Domain.EmployeeAgg;
|
||
using Company.Domain.LeftWorkAgg;
|
||
using Company.Domain.RollCallAgg;
|
||
using Company.Domain.RollCallEmployeeAgg;
|
||
using Company.Domain.WorkshopAgg;
|
||
using Company.Domain.WorkshopEmployerAgg;
|
||
using CompanyManagment.App.Contracts.Checkout;
|
||
using CompanyManagment.App.Contracts.Checkout.Dto;
|
||
using CompanyManagment.App.Contracts.Contract;
|
||
using CompanyManagment.App.Contracts.Employee;
|
||
using CompanyManagment.App.Contracts.EmployeeComputeOptions;
|
||
using CompanyManagment.App.Contracts.HolidayItem;
|
||
using CompanyManagment.App.Contracts.InstitutionPlan;
|
||
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 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 System.Xml.XPath;
|
||
using static CompanyManagment.EFCore.Repository.ContractRepository;
|
||
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)
|
||
{
|
||
var checkLeftDate = ($"{year}/{month}/01").ToGeorgianDateTime();
|
||
var hasLeftwork = _context.LeftWorkList.Any(x =>
|
||
x.EmployeeId == employeId && x.WorkshopId == workshopId && x.LeftWorkDate == checkLeftDate);
|
||
if (hasLeftwork)
|
||
return (true, 0, 0, 0, 0, 0, 0);
|
||
|
||
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).GetAwaiter().GetResult();
|
||
|
||
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)
|
||
{
|
||
// اگر ترک کار کرده بود
|
||
// اگر ترک کارش در بازه انتخاب شده بود
|
||
var leftFirstDayOfNextMonth = endSearch.AddDays(1);
|
||
if (leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= leftFirstDayOfNextMonth)
|
||
{
|
||
//اگر بازه انتخاب شده در تاریخ جاری بود
|
||
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.SetReward(command.Rewards,command.RewardPay);
|
||
entity.SetCheckoutRollCall(command.CheckoutRollCall);
|
||
entity.SetEmployeeMandatoryHours(command.EmployeeMandatoryHours);
|
||
if (command.HasInsuranceShareTheSameAsList)
|
||
entity.SetInsuranceShare();
|
||
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 checkouts = _context.CheckoutSet.Where(x => id.Contains(x.id)).ToList();
|
||
var query = new List<CheckoutViewModel>();
|
||
foreach (var item in checkouts)
|
||
{
|
||
var ch = new CheckoutViewModel()
|
||
{
|
||
Id = item.id,
|
||
WorkshopId = item.WorkshopId,
|
||
ContractId = item.ContractId,
|
||
EmployeeId = item.EmployeeId,
|
||
EmployeeFullName = item.EmployeeFullName,
|
||
FathersName = item.FathersName,
|
||
NationalCode = item.NationalCode,
|
||
DateOfBirth = item.DateOfBirth,
|
||
WorkshopName = item.WorkshopName,
|
||
Month = item.Month,
|
||
Year = item.Year,
|
||
PersonnelCode = item.PersonnelCode,
|
||
PersonnelCodeInt = Convert.ToInt32(item.PersonnelCode),
|
||
ContractNo = item.ContractNo,
|
||
MonthlySalary = item.MonthlySalary.ToMoney(),
|
||
BaseYearsPay = item.BaseYearsPay.ToMoney(),
|
||
ConsumableItems = item.ConsumableItems.ToMoney(),
|
||
HousingAllowance = item.HousingAllowance.ToMoney(),
|
||
OvertimePay = item.OvertimePay.ToMoney(),
|
||
NightworkPay = item.NightworkPay.ToMoney(),
|
||
FridayPay = item.FridayPay.ToMoney(),
|
||
MissionPay = item.MissionPay.ToMoney(),
|
||
ShiftPay = item.ShiftPay.ToMoney(),
|
||
FamilyAllowance = item.FamilyAllowance.ToMoney(),
|
||
BonusesPay = item.BonusesPay.ToMoney(),
|
||
YearsPay = item.YearsPay.ToMoney(),
|
||
LeavePay = item.LeavePay.ToMoney(),
|
||
InsuranceDeduction = item.InsuranceDeduction.ToMoney(),
|
||
TaxDeducation = item.TaxDeducation.ToMoney(),
|
||
InstallmentDeduction = item.InstallmentDeduction.ToMoney(),
|
||
SalaryAidDeduction = item.SalaryAidDeduction.ToMoney(),
|
||
AbsenceDeduction = item.AbsenceDeduction.ToMoney(),
|
||
TotalClaims = item.TotalClaims,
|
||
TotalDeductions = item.TotalDeductions,
|
||
TotalPayment = item.TotalPayment.ToMoney(),
|
||
RewardPay = item.RewardPay.ToMoney(),
|
||
ContractStartGr = item.ContractStart,
|
||
ContractEndGr = item.ContractEnd,
|
||
IsLeft = false,
|
||
LeftWorkDate = "",
|
||
LastDayOfWork = "",
|
||
MarriedAllowance = item.MarriedAllowance.ToMoney(),
|
||
HasRollCall = item.HasRollCall,
|
||
SumOfWorkingDays = "-",
|
||
OverTimeWorkValue = item.OverTimeWorkValue,
|
||
OverNightWorkValue = item.OverNightWorkValue,
|
||
FridayWorkValue = item.FridayWorkValue,
|
||
RotatingShiftValue = item.RotatingShiftValue,
|
||
AbsenceValue = item.AbsenceValue,
|
||
MaritalStatus = "",
|
||
TotalDayOfLeaveCompute = "-",
|
||
TotalDayOfYearsCompute = "-",
|
||
TotalDayOfBunosesCompute = "-",
|
||
InstallmentViewModels = item.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 = item.SalaryAids.Select(s => new SalaryAidViewModel()
|
||
{
|
||
Amount = s.Amount,
|
||
AmountDouble = s.Amount.MoneyToDouble(),
|
||
SalaryAidDateTimeFa = s.SalaryAidDateTimeFa,
|
||
SalaryAidDateTimeGe = s.SalaryAidDateTime
|
||
}).ToList(),
|
||
CheckoutRollCall = item.CheckoutRollCall != null ? new CheckoutRollCallViewModel()
|
||
{
|
||
TotalPresentTimeSpan = item.CheckoutRollCall.TotalPresentTimeSpan,
|
||
TotalBreakTimeSpan = item.CheckoutRollCall.TotalBreakTimeSpan,
|
||
TotalWorkingTimeSpan = item.CheckoutRollCall.TotalWorkingTimeSpan,
|
||
TotalPaidLeaveTmeSpan = item.CheckoutRollCall.TotalPaidLeaveTmeSpan,
|
||
TotalMandatoryTimeSpan = item.CheckoutRollCall.TotalMandatoryTimeSpan,
|
||
TotalSickLeaveTimeSpan = item.CheckoutRollCall.TotalSickLeaveTimeSpan,
|
||
RollCallDaysCollection = item.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 = item.HasAmountConflict,
|
||
EmployeeMandatoryHoursTimeSpan = item.EmployeeMandatoryHours,
|
||
EmployeeMandatoryHoursStr = Tools.ToFarsiHoursAndMinutes(
|
||
Convert.ToInt32(item.EmployeeMandatoryHours.TotalHours), item.EmployeeMandatoryHours.Minutes, "-")
|
||
};
|
||
var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId);
|
||
ch.WorkshopName = workshopName.WorkshopName;
|
||
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 = Tools.ToFarsiHoursAndMinutes(
|
||
Convert.ToInt32(ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.TotalHours),
|
||
ch.CheckoutRollCall.TotalPaidLeaveTmeSpan.Minutes, "-");
|
||
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.ToMoney(),
|
||
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.Include(w => w.CheckoutWarningMessageList)
|
||
.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,
|
||
IsUpdateNeeded = x.IsUpdateNeeded,
|
||
CheckoutWarningMessageList = x.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel
|
||
{
|
||
WarningMessage = wm.WarningMessage,
|
||
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
|
||
}).ToList()
|
||
}).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.Include(w => w.CheckoutWarningMessageList)
|
||
.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,
|
||
IsUpdateNeeded = x.ch.IsUpdateNeeded,
|
||
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm =>
|
||
new CheckoutWarningMessageModel
|
||
{
|
||
WarningMessage = wm.WarningMessage,
|
||
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
|
||
}).ToList()
|
||
}).OrderByDescending(x => x.Id).Take(3000).ToList().DistinctBy(x => x.Id)
|
||
.OrderByDescending(x => x.Id).ThenByDescending(x => x.Year)
|
||
.ThenBy(x => x.PersonnelCodeInt)
|
||
.Take(50).ToList();
|
||
}
|
||
else if (hasSearch && !hasEmployeeOrWorkshpSearch)
|
||
{
|
||
var result = checkouts.Select(x => new CheckoutViewModel()
|
||
{
|
||
Id = x.ch.id,
|
||
EmployeeFullName = x.ch.EmployeeFullName,
|
||
ContractStart = x.ch.ContractStart.ToFarsi(),
|
||
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,
|
||
IsUpdateNeeded = x.ch.IsUpdateNeeded,
|
||
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm =>
|
||
new CheckoutWarningMessageModel
|
||
{
|
||
WarningMessage = wm.WarningMessage,
|
||
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
|
||
}).ToList()
|
||
}).OrderByDescending(x => x.Id)
|
||
.GroupBy(x => x.Id)
|
||
.Select(x => x.First());
|
||
|
||
|
||
if ((string.IsNullOrWhiteSpace(searchModel.ContractStart) ||
|
||
string.IsNullOrWhiteSpace(searchModel.ContractEnd)) && string.IsNullOrWhiteSpace(searchModel.Month))
|
||
{
|
||
//اگر فقط سال رو سرچ کرد
|
||
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,
|
||
IsUpdateNeeded = x.ch.IsUpdateNeeded,
|
||
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm =>
|
||
new CheckoutWarningMessageModel
|
||
{
|
||
WarningMessage = wm.WarningMessage,
|
||
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
|
||
}).ToList()
|
||
}).GroupBy(x => x.Id).Select(x => x.First()).ToList()
|
||
.OrderByDescending(x => x.ContractStartGr).ToList();
|
||
}
|
||
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,
|
||
IsUpdateNeeded = x.ch.IsUpdateNeeded,
|
||
CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm =>
|
||
new CheckoutWarningMessageModel
|
||
{
|
||
WarningMessage = wm.WarningMessage,
|
||
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
|
||
}).ToList()
|
||
}).GroupBy(x => x.Id)
|
||
.Select(x => x.First()).ToList()
|
||
.OrderByDescending(x => x.Id)
|
||
.ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).ToList();
|
||
}
|
||
}
|
||
|
||
public async Task<List<CheckoutViewModel>> SearchForMainCheckout(CheckoutSearchModel searchModel)
|
||
{
|
||
bool hasSearch = false;
|
||
bool hasEmployeeOrWorkshpSearch = false;
|
||
//List<CheckoutViewModel> query = null;
|
||
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
|
||
|
||
|
||
#region ForApi
|
||
|
||
///ایجاد فیش
|
||
#region CreateCheckout
|
||
|
||
|
||
/// <summary>
|
||
/// دریافت سلکت لیست پرسنل کارگاه
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public async Task<List<EmployeeSelectListDto>> GetEmployeeSelectListByWorkshopId(long id)
|
||
{
|
||
var employeesHasLeftworkData = _context.LeftWorkList.Where(x => x.WorkshopId == id).Select(x => x.EmployeeId);
|
||
var employees = await _context.Employees
|
||
.Where(x => employeesHasLeftworkData.Contains(x.id))
|
||
.Select(x =>
|
||
new EmployeeSelectListDto()
|
||
{
|
||
Id = x.id,
|
||
EmployeeFullName = x.FullName
|
||
})
|
||
.AsNoTracking()
|
||
.ToListAsync();
|
||
return employees;
|
||
}
|
||
|
||
public async Task<OperationResult<GetContractAndIncludesDataToCreateDto>> GetContractsAndIncludeDataDataToCreateCheckout(List<long> ids,string year, string month, long workshopId)
|
||
{
|
||
var checkoutSelectedStartFa = $"{year}/{month}/01";
|
||
var checkoutSelectedStart = checkoutSelectedStartFa.ToGeorgianDateTime();
|
||
var checkoutSelectedEnd = checkoutSelectedStartFa.FindeEndOfMonthReturnGr();
|
||
var op = new OperationResult<GetContractAndIncludesDataToCreateDto>();
|
||
var watcher = new Stopwatch();
|
||
watcher.Start();
|
||
//دریافت قراداد ها
|
||
var getContracts =await _context.Contracts.Include(x=>x.Employee).Where(x => ids.Contains(x.id)).AsNoTracking().ToListAsync();
|
||
if (!getContracts.Any())
|
||
return op.Failed("قرادادی یافت نشد");
|
||
|
||
var employeeIds = getContracts.Select(x => x.EmployeeId).ToList();
|
||
|
||
//دریافت اطلاعات کارگاه
|
||
var workshop = await _context.Workshops.FirstAsync(x => x.id == workshopId);
|
||
var GetContractsTime = watcher.Elapsed;
|
||
watcher.Reset();
|
||
watcher.Start();
|
||
//دریافت اطلاعات پرسنل ها
|
||
// var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).AsNoTracking().ToListAsync();
|
||
//دریافت اطلاعت ساعت کاری
|
||
#region WorkingHours
|
||
var getWorkingHours = await _context.WorkingHoursSet.Where(x => ids.Contains(x.ContractId))
|
||
.Include(x => x.WorkingHoursItemsList)
|
||
.AsNoTracking()
|
||
.ToListAsync();
|
||
if (!getWorkingHours.Any())
|
||
return op.Failed("ساعات کاری قراداد یافت نشد");
|
||
|
||
var workingHoursList = new List<CreateWorkingHoursTemp>();
|
||
foreach (var workingHours in getWorkingHours)
|
||
{
|
||
if (workingHours != null)
|
||
{
|
||
var items = workingHours?.WorkingHoursItemsList;
|
||
|
||
if (workingHours.ShiftWork == "1" || workingHours.ShiftWork == "2")
|
||
{
|
||
var shanbeh = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0") ? true : false;
|
||
var yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0") ? true : false;
|
||
var doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0") ? true : false;
|
||
var seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0") ? true : false;
|
||
var cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0") ? true : false;
|
||
var pangshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0") ? true : false;
|
||
var jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0") ? true : false;
|
||
|
||
var RestTime = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0")?.RestTime
|
||
: null;
|
||
var RestTimeYekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1")?.RestTime
|
||
: null;
|
||
var RestTimeDoshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2")?.RestTime
|
||
: null;
|
||
var RestTimeSeshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3")?.RestTime
|
||
: null;
|
||
var RestTimeCheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4")?.RestTime
|
||
: null;
|
||
var RestTimePanjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5")?.RestTime
|
||
: null;
|
||
var RestTimeJomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6")?.RestTime
|
||
: null;
|
||
|
||
var SingleShift1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0")?.Start1
|
||
: null;
|
||
var SingleShift2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0")?.End1
|
||
: null;
|
||
var TowShifts1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0")?.Start2
|
||
: null;
|
||
var TowShifts2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0")?.End2
|
||
: null;
|
||
|
||
var SingleShift1Yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1")?.Start1
|
||
: null;
|
||
var SingleShift2Yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1")?.End1
|
||
: null;
|
||
var TowShifts1Yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1")?.Start2
|
||
: null;
|
||
var TowShifts2Yekshanbeh = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1")?.End2
|
||
: null;
|
||
|
||
var SingleShift1Doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2")?.Start1
|
||
: null;
|
||
var SingleShift2Doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2")?.End1
|
||
: null;
|
||
var TowShifts1Doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2")?.Start2
|
||
: null;
|
||
var TowShifts2Doshanbeh = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2")?.End2
|
||
: null;
|
||
|
||
var SingleShift1Seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3")?.Start1
|
||
: null;
|
||
var SingleShift2Seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3")?.End1
|
||
: null;
|
||
var TowShifts1Seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3")?.Start2
|
||
: null;
|
||
var TowShifts2Seshanbeh = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3")?.End2
|
||
: null;
|
||
|
||
var SingleShift1Cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4")?.Start1
|
||
: null;
|
||
var SingleShift2Cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4")?.End1
|
||
: null;
|
||
var TowShifts1Cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4")?.Start2
|
||
: null;
|
||
var TowShifts2Cheharshanbeh = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4")?.End2
|
||
: null;
|
||
|
||
var SingleShift1Panjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5")?.Start1
|
||
: null;
|
||
var SingleShift2Panjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5")?.End1
|
||
: null;
|
||
var TowShifts1Panjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5")?.Start2
|
||
: null;
|
||
var TowShifts2Panjshanbeh = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5")?.End2
|
||
: null;
|
||
|
||
var SingleShift1Jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6")?.Start1
|
||
: null;
|
||
var SingleShift2Jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6")?.End1
|
||
: null;
|
||
var TowShifts1Jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6")?.Start2
|
||
: null;
|
||
var TowShifts2Jomeh = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "0")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6")?.End2
|
||
: null;
|
||
|
||
var result = new CreateWorkingHoursTemp
|
||
{
|
||
EmployeeId = getContracts.First(x=>x.id == workingHours.ContractId).EmployeeId,
|
||
WorknigHoursId = workingHours.id,
|
||
ShiftWork = "4",
|
||
ShiftWorkTemp = "1",
|
||
|
||
#region week1
|
||
|
||
//week1
|
||
Shanbe1 = shanbeh,
|
||
YekShanbe1 = yekshanbeh,
|
||
DoShanbe1 = doshanbeh,
|
||
SeShanbe1 = seshanbeh,
|
||
CheharShanbe1 = cheharshanbeh,
|
||
PanjShanbe1 = pangshanbeh,
|
||
Jome1 = jomeh,
|
||
|
||
RestTimeShanbe1 = RestTime,
|
||
RestTimeYekShanbe1 = RestTimeYekshanbeh,
|
||
RestTimeDoShanbe1 = RestTimeDoshanbeh,
|
||
RestTimeSeShanbe1 = RestTimeSeshanbeh,
|
||
RestTimeCheharShanbe1 = RestTimeCheharshanbeh,
|
||
RestTimePanjShanbe1 = RestTimePanjshanbeh,
|
||
RestTimeJome1 = RestTimeJomeh,
|
||
|
||
SingleShift1Shanbe1 = SingleShift1,
|
||
SingleShift2Shanbe1 = SingleShift2,
|
||
TowShifts1Shanbe1 = TowShifts1,
|
||
TowShifts2Shanbe1 = TowShifts2,
|
||
|
||
SingleShift1YekShanbe1 = SingleShift1Yekshanbeh,
|
||
SingleShift2YekShanbe1 = SingleShift2Yekshanbeh,
|
||
TowShifts1YekShanbe1 = TowShifts1Yekshanbeh,
|
||
TowShifts2YekShanbe1 = TowShifts2Yekshanbeh,
|
||
|
||
SingleShift1DoShanbe1 = SingleShift1Doshanbeh,
|
||
SingleShift2DoShanbe1 = SingleShift2Doshanbeh,
|
||
TowShifts1DoShanbe1 = TowShifts1Doshanbeh,
|
||
TowShifts2DoShanbe1 = TowShifts2Doshanbeh,
|
||
|
||
SingleShift1SeShanbe1 = SingleShift1Seshanbeh,
|
||
SingleShift2SeShanbe1 = SingleShift2Seshanbeh,
|
||
TowShifts1SeShanbe1 = TowShifts1Seshanbeh,
|
||
TowShifts2SeShanbe1 = TowShifts2Seshanbeh,
|
||
|
||
SingleShift1CheharShanbe1 = SingleShift1Cheharshanbeh,
|
||
SingleShift2CheharShanbe1 = SingleShift2Cheharshanbeh,
|
||
TowShifts1CheharShanbe1 = TowShifts1Cheharshanbeh,
|
||
TowShifts2CheharShanbe1 = TowShifts2Cheharshanbeh,
|
||
|
||
SingleShift1PanjShanbe1 = SingleShift1Panjshanbeh,
|
||
SingleShift2PanjShanbe1 = SingleShift2Panjshanbeh,
|
||
TowShifts1PanjShanbe1 = TowShifts1Panjshanbeh,
|
||
TowShifts2PanjShanbe1 = TowShifts2Panjshanbeh,
|
||
|
||
SingleShift1Jome1 = SingleShift1Jomeh,
|
||
SingleShift2Jome1 = SingleShift2Jomeh,
|
||
TowShifts1Jome1 = TowShifts1Jomeh,
|
||
TowShifts2Jome1 = TowShifts2Jomeh,
|
||
|
||
#endregion
|
||
|
||
#region week2
|
||
|
||
//week2
|
||
Shanbe2 = shanbeh,
|
||
YekShanbe2 = yekshanbeh,
|
||
DoShanbe2 = doshanbeh,
|
||
SeShanbe2 = seshanbeh,
|
||
CheharShanbe2 = cheharshanbeh,
|
||
PanjShanbe2 = pangshanbeh,
|
||
Jome2 = jomeh,
|
||
|
||
RestTimeShanbe2 = RestTime,
|
||
RestTimeYekShanbe2 = RestTimeYekshanbeh,
|
||
RestTimeDoShanbe2 = RestTimeDoshanbeh,
|
||
RestTimeSeShanbe2 = RestTimeSeshanbeh,
|
||
RestTimeCheharShanbe2 = RestTimeCheharshanbeh,
|
||
RestTimePanjShanbe2 = RestTimePanjshanbeh,
|
||
RestTimeJome2 = RestTimeJomeh,
|
||
|
||
|
||
SingleShift1Shanbe2 = SingleShift1,
|
||
SingleShift2Shanbe2 = SingleShift2,
|
||
TowShifts1Shanbe2 = TowShifts1,
|
||
TowShifts2Shanbe2 = TowShifts2,
|
||
|
||
SingleShift1YekShanbe2 = SingleShift1Yekshanbeh,
|
||
SingleShift2YekShanbe2 = SingleShift2Yekshanbeh,
|
||
TowShifts1YekShanbe2 = TowShifts1Yekshanbeh,
|
||
TowShifts2YekShanbe2 = TowShifts2Yekshanbeh,
|
||
|
||
SingleShift1DoShanbe2 = SingleShift1Doshanbeh,
|
||
SingleShift2DoShanbe2 = SingleShift2Doshanbeh,
|
||
TowShifts1DoShanbe2 = TowShifts1Doshanbeh,
|
||
TowShifts2DoShanbe2 = TowShifts2Doshanbeh,
|
||
|
||
SingleShift1SeShanbe2 = SingleShift1Seshanbeh,
|
||
SingleShift2SeShanbe2 = SingleShift2Seshanbeh,
|
||
TowShifts1SeShanbe2 = TowShifts1Seshanbeh,
|
||
TowShifts2SeShanbe2 = TowShifts2Seshanbeh,
|
||
|
||
SingleShift1CheharShanbe2 = SingleShift1Cheharshanbeh,
|
||
SingleShift2CheharShanbe2 = SingleShift2Cheharshanbeh,
|
||
TowShifts1CheharShanbe2 = TowShifts1Cheharshanbeh,
|
||
TowShifts2CheharShanbe2 = TowShifts2Cheharshanbeh,
|
||
|
||
SingleShift1PanjShanbe2 = SingleShift1Panjshanbeh,
|
||
SingleShift2PanjShanbe2 = SingleShift2Panjshanbeh,
|
||
TowShifts1PanjShanbe2 = TowShifts1Panjshanbeh,
|
||
TowShifts2PanjShanbe2 = TowShifts2Panjshanbeh,
|
||
|
||
SingleShift1Jome2 = SingleShift1Jomeh,
|
||
SingleShift2Jome2 = SingleShift2Jomeh,
|
||
TowShifts1Jome2 = TowShifts1Jomeh,
|
||
TowShifts2Jome2 = TowShifts2Jomeh,
|
||
|
||
#endregion
|
||
|
||
|
||
#region week3
|
||
|
||
//week3
|
||
Shanbe3 = shanbeh,
|
||
YekShanbe3 = yekshanbeh,
|
||
DoShanbe3 = doshanbeh,
|
||
SeShanbe3 = seshanbeh,
|
||
CheharShanbe3 = cheharshanbeh,
|
||
PanjShanbe3 = pangshanbeh,
|
||
Jome3 = jomeh,
|
||
|
||
RestTimeShanbe3 = RestTime,
|
||
RestTimeYekShanbe3 = RestTimeYekshanbeh,
|
||
RestTimeDoShanbe3 = RestTimeDoshanbeh,
|
||
RestTimeSeShanbe3 = RestTimeSeshanbeh,
|
||
RestTimeCheharShanbe3 = RestTimeCheharshanbeh,
|
||
RestTimePanjShanbe3 = RestTimePanjshanbeh,
|
||
RestTimeJome3 = RestTimeJomeh,
|
||
|
||
|
||
SingleShift1Shanbe3 = SingleShift1,
|
||
SingleShift2Shanbe3 = SingleShift2,
|
||
TowShifts1Shanbe3 = TowShifts1,
|
||
TowShifts2Shanbe3 = TowShifts2,
|
||
|
||
SingleShift1YekShanbe3 = SingleShift1Yekshanbeh,
|
||
SingleShift2YekShanbe3 = SingleShift2Yekshanbeh,
|
||
TowShifts1YekShanbe3 = TowShifts1Yekshanbeh,
|
||
TowShifts2YekShanbe3 = TowShifts2Yekshanbeh,
|
||
|
||
SingleShift1DoShanbe3 = SingleShift1Doshanbeh,
|
||
SingleShift2DoShanbe3 = SingleShift2Doshanbeh,
|
||
TowShifts1DoShanbe3 = TowShifts1Doshanbeh,
|
||
TowShifts2DoShanbe3 = TowShifts2Doshanbeh,
|
||
|
||
SingleShift1SeShanbe3 = SingleShift1Seshanbeh,
|
||
SingleShift2SeShanbe3 = SingleShift2Seshanbeh,
|
||
TowShifts1SeShanbe3 = TowShifts1Seshanbeh,
|
||
TowShifts2SeShanbe3 = TowShifts2Seshanbeh,
|
||
|
||
SingleShift1CheharShanbe3 = SingleShift1Cheharshanbeh,
|
||
SingleShift2CheharShanbe3 = SingleShift2Cheharshanbeh,
|
||
TowShifts1CheharShanbe3 = TowShifts1Cheharshanbeh,
|
||
TowShifts2CheharShanbe3 = TowShifts2Cheharshanbeh,
|
||
|
||
SingleShift1PanjShanbe3 = SingleShift1Panjshanbeh,
|
||
SingleShift2PanjShanbe3 = SingleShift2Panjshanbeh,
|
||
TowShifts1PanjShanbe3 = TowShifts1Panjshanbeh,
|
||
TowShifts2PanjShanbe3 = TowShifts2Panjshanbeh,
|
||
|
||
SingleShift1Jome3 = SingleShift1Jomeh,
|
||
SingleShift2Jome3 = SingleShift2Jomeh,
|
||
TowShifts1Jome3 = TowShifts1Jomeh,
|
||
TowShifts2Jome3 = TowShifts2Jomeh,
|
||
|
||
#endregion
|
||
|
||
#region week4
|
||
|
||
//week4
|
||
Shanbe4 = shanbeh,
|
||
YekShanbe4 = yekshanbeh,
|
||
DoShanbe4 = doshanbeh,
|
||
SeShanbe4 = seshanbeh,
|
||
CheharShanbe4 = cheharshanbeh,
|
||
PanjShanbe4 = pangshanbeh,
|
||
Jome4 = jomeh,
|
||
|
||
RestTimeShanbe4 = RestTime,
|
||
RestTimeYekShanbe4 = RestTimeYekshanbeh,
|
||
RestTimeDoShanbe4 = RestTimeDoshanbeh,
|
||
RestTimeSeShanbe4 = RestTimeSeshanbeh,
|
||
RestTimeCheharShanbe4 = RestTimeCheharshanbeh,
|
||
RestTimePanjShanbe4 = RestTimePanjshanbeh,
|
||
RestTimeJome4 = RestTimeJomeh,
|
||
|
||
|
||
SingleShift1Shanbe4 = SingleShift1,
|
||
SingleShift2Shanbe4 = SingleShift2,
|
||
TowShifts1Shanbe4 = TowShifts1,
|
||
TowShifts2Shanbe4 = TowShifts2,
|
||
|
||
SingleShift1YekShanbe4 = SingleShift1Yekshanbeh,
|
||
SingleShift2YekShanbe4 = SingleShift2Yekshanbeh,
|
||
TowShifts1YekShanbe4 = TowShifts1Yekshanbeh,
|
||
TowShifts2YekShanbe4 = TowShifts2Yekshanbeh,
|
||
|
||
SingleShift1DoShanbe4 = SingleShift1Doshanbeh,
|
||
SingleShift2DoShanbe4 = SingleShift2Doshanbeh,
|
||
TowShifts1DoShanbe4 = TowShifts1Doshanbeh,
|
||
TowShifts2DoShanbe4 = TowShifts2Doshanbeh,
|
||
|
||
SingleShift1SeShanbe4 = SingleShift1Seshanbeh,
|
||
SingleShift2SeShanbe4 = SingleShift2Seshanbeh,
|
||
TowShifts1SeShanbe4 = TowShifts1Seshanbeh,
|
||
TowShifts2SeShanbe4 = TowShifts2Seshanbeh,
|
||
|
||
SingleShift1CheharShanbe4 = SingleShift1Cheharshanbeh,
|
||
SingleShift2CheharShanbe4 = SingleShift2Cheharshanbeh,
|
||
TowShifts1CheharShanbe4 = TowShifts1Cheharshanbeh,
|
||
TowShifts2CheharShanbe4 = TowShifts2Cheharshanbeh,
|
||
|
||
SingleShift1PanjShanbe4 = SingleShift1Panjshanbeh,
|
||
SingleShift2PanjShanbe4 = SingleShift2Panjshanbeh,
|
||
TowShifts1PanjShanbe4 = TowShifts1Panjshanbeh,
|
||
TowShifts2PanjShanbe4 = TowShifts2Panjshanbeh,
|
||
|
||
SingleShift1Jome4 = SingleShift1Jomeh,
|
||
SingleShift2Jome4 = SingleShift2Jomeh,
|
||
TowShifts1Jome4 = TowShifts1Jomeh,
|
||
TowShifts2Jome4 = TowShifts2Jomeh,
|
||
|
||
#endregion
|
||
};
|
||
//تفکیک ساعت استراحت
|
||
|
||
#region TafkikRest
|
||
|
||
#region Week1
|
||
|
||
var restTimeShanbe1 = result.RestTimeShanbe1;
|
||
result.RestTimeShanbe1 = restTimeShanbe1.RestTimeSplit();
|
||
result.RestTimeShanbe1Min = restTimeShanbe1.RestTimeMinSplit();
|
||
var restTimeYekShanbe1 = result.RestTimeYekShanbe1;
|
||
result.RestTimeYekShanbe1 = restTimeYekShanbe1.RestTimeSplit();
|
||
result.RestTimeYekShanbe1Min = restTimeYekShanbe1.RestTimeMinSplit();
|
||
var restTimeDoShanbe1 = result.RestTimeDoShanbe1;
|
||
result.RestTimeDoShanbe1 = restTimeDoShanbe1.RestTimeSplit();
|
||
result.RestTimeDoShanbe1Min = restTimeDoShanbe1.RestTimeMinSplit();
|
||
var restTimeSeShanbe1 = result.RestTimeSeShanbe1;
|
||
result.RestTimeSeShanbe1 = restTimeSeShanbe1.RestTimeSplit();
|
||
result.RestTimeSeShanbe1Min = restTimeSeShanbe1.RestTimeMinSplit();
|
||
var restTimeCheharShanbe1 = result.RestTimeCheharShanbe1;
|
||
result.RestTimeCheharShanbe1 = restTimeCheharShanbe1.RestTimeSplit();
|
||
result.RestTimeCheharShanbe1Min = restTimeCheharShanbe1.RestTimeMinSplit();
|
||
var restTimePanjShanbe1 = result.RestTimePanjShanbe1;
|
||
result.RestTimePanjShanbe1 = restTimePanjShanbe1.RestTimeSplit();
|
||
result.RestTimePanjShanbe1Min = restTimePanjShanbe1.RestTimeMinSplit();
|
||
var restTimeJome1 = result.RestTimeJome1;
|
||
result.RestTimeJome1 = restTimeJome1.RestTimeSplit();
|
||
result.RestTimeJome1Min = restTimeJome1.RestTimeMinSplit();
|
||
|
||
#endregion
|
||
|
||
#region week2
|
||
|
||
var restTimeShanbe2 = result.RestTimeShanbe2;
|
||
result.RestTimeShanbe2 = restTimeShanbe2.RestTimeSplit();
|
||
result.RestTimeShanbe2Min = restTimeShanbe2.RestTimeMinSplit();
|
||
var restTimeYekShanbe2 = result.RestTimeYekShanbe2;
|
||
result.RestTimeYekShanbe2 = restTimeYekShanbe2.RestTimeSplit();
|
||
result.RestTimeYekShanbe2Min = restTimeYekShanbe2.RestTimeMinSplit();
|
||
var restTimeDoShanbe2 = result.RestTimeDoShanbe2;
|
||
result.RestTimeDoShanbe2 = restTimeDoShanbe2.RestTimeSplit();
|
||
result.RestTimeDoShanbe2Min = restTimeDoShanbe2.RestTimeMinSplit();
|
||
var restTimeSeShanbe2 = result.RestTimeSeShanbe2;
|
||
result.RestTimeSeShanbe2 = restTimeSeShanbe2.RestTimeSplit();
|
||
result.RestTimeSeShanbe2Min = restTimeSeShanbe2.RestTimeMinSplit();
|
||
var restTimeCheharShanbe2 = result.RestTimeCheharShanbe2;
|
||
result.RestTimeCheharShanbe2 = restTimeCheharShanbe2.RestTimeSplit();
|
||
result.RestTimeCheharShanbe2Min = restTimeCheharShanbe2.RestTimeMinSplit();
|
||
var restTimePanjShanbe2 = result.RestTimePanjShanbe2;
|
||
result.RestTimePanjShanbe2 = restTimePanjShanbe2.RestTimeSplit();
|
||
result.RestTimePanjShanbe2Min = restTimePanjShanbe2.RestTimeMinSplit();
|
||
var restTimeJome2 = result.RestTimeJome2;
|
||
result.RestTimeJome2 = restTimeJome2.RestTimeSplit();
|
||
result.RestTimeJome2Min = restTimeJome2.RestTimeMinSplit();
|
||
|
||
#endregion
|
||
|
||
#region week3
|
||
|
||
var restTimeShanbe3 = result.RestTimeShanbe3;
|
||
result.RestTimeShanbe3 = restTimeShanbe3.RestTimeSplit();
|
||
result.RestTimeShanbe3Min = restTimeShanbe3.RestTimeMinSplit();
|
||
var restTimeYekShanbe3 = result.RestTimeYekShanbe3;
|
||
result.RestTimeYekShanbe3 = restTimeYekShanbe3.RestTimeSplit();
|
||
result.RestTimeYekShanbe3Min = restTimeYekShanbe3.RestTimeMinSplit();
|
||
var restTimeDoShanbe3 = result.RestTimeDoShanbe3;
|
||
result.RestTimeDoShanbe3 = restTimeDoShanbe3.RestTimeSplit();
|
||
result.RestTimeDoShanbe3Min = restTimeDoShanbe3.RestTimeMinSplit();
|
||
var restTimeSeShanbe3 = result.RestTimeSeShanbe3;
|
||
result.RestTimeSeShanbe3 = restTimeSeShanbe3.RestTimeSplit();
|
||
result.RestTimeSeShanbe3Min = restTimeSeShanbe3.RestTimeMinSplit();
|
||
var restTimeCheharShanbe3 = result.RestTimeCheharShanbe3;
|
||
result.RestTimeCheharShanbe3 = restTimeCheharShanbe3.RestTimeSplit();
|
||
result.RestTimeCheharShanbe3Min = restTimeCheharShanbe3.RestTimeMinSplit();
|
||
var restTimePanjShanbe3 = result.RestTimePanjShanbe3;
|
||
result.RestTimePanjShanbe3 = restTimePanjShanbe3.RestTimeSplit();
|
||
result.RestTimePanjShanbe3Min = restTimePanjShanbe3.RestTimeMinSplit();
|
||
var restTimeJome3 = result.RestTimeJome3;
|
||
result.RestTimeJome3 = restTimeJome3.RestTimeSplit();
|
||
result.RestTimeJome3Min = restTimeJome3.RestTimeMinSplit();
|
||
|
||
#endregion
|
||
|
||
#region week4
|
||
|
||
var restTimeShanbe4 = result.RestTimeShanbe4;
|
||
result.RestTimeShanbe4 = restTimeShanbe4.RestTimeSplit();
|
||
result.RestTimeShanbe4Min = restTimeShanbe4.RestTimeMinSplit();
|
||
var restTimeYekShanbe4 = result.RestTimeYekShanbe4;
|
||
result.RestTimeYekShanbe4 = restTimeYekShanbe4.RestTimeSplit();
|
||
result.RestTimeYekShanbe4Min = restTimeYekShanbe4.RestTimeMinSplit();
|
||
var restTimeDoShanbe4 = result.RestTimeDoShanbe4;
|
||
result.RestTimeDoShanbe4 = restTimeDoShanbe4.RestTimeSplit();
|
||
result.RestTimeDoShanbe4Min = restTimeDoShanbe4.RestTimeMinSplit();
|
||
var restTimeSeShanbe4 = result.RestTimeSeShanbe4;
|
||
result.RestTimeSeShanbe4 = restTimeSeShanbe4.RestTimeSplit();
|
||
result.RestTimeSeShanbe4Min = restTimeSeShanbe4.RestTimeMinSplit();
|
||
var restTimeCheharShanbe4 = result.RestTimeCheharShanbe4;
|
||
result.RestTimeCheharShanbe4 = restTimeCheharShanbe4.RestTimeSplit();
|
||
result.RestTimeCheharShanbe4Min = restTimeCheharShanbe4.RestTimeMinSplit();
|
||
var restTimePanjShanbe4 = result.RestTimePanjShanbe4;
|
||
result.RestTimePanjShanbe4 = restTimePanjShanbe4.RestTimeSplit();
|
||
result.RestTimePanjShanbe4Min = restTimePanjShanbe4.RestTimeMinSplit();
|
||
var restTimeJome4 = result.RestTimeJome4;
|
||
result.RestTimeJome4 = restTimeJome4.RestTimeSplit();
|
||
result.RestTimeJome4Min = restTimeJome4.RestTimeMinSplit();
|
||
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
workingHoursList.Add(result); ;
|
||
}
|
||
|
||
if (workingHours.ShiftWork == "4")
|
||
{
|
||
var result = new CreateWorkingHoursTemp
|
||
{
|
||
EmployeeId = getContracts.First(x => x.id == workingHours.ContractId).EmployeeId,
|
||
WorknigHoursId = workingHours.id,
|
||
ShiftWork = workingHours.ShiftWork,
|
||
ShiftWorkTemp = "4",
|
||
|
||
//week1
|
||
Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1") ? true : false,
|
||
YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1") ? true : false,
|
||
DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1") ? true : false,
|
||
SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1") ? true : false,
|
||
CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1") ? true : false,
|
||
PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1") ? true : false,
|
||
Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1") ? true : false,
|
||
|
||
RestTimeShanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.RestTime
|
||
: null,
|
||
RestTimeYekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.RestTime
|
||
: null,
|
||
RestTimeDoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.RestTime
|
||
: null,
|
||
RestTimeSeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.RestTime
|
||
: null,
|
||
RestTimeCheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.RestTime
|
||
: null,
|
||
RestTimePanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.RestTime
|
||
: null,
|
||
RestTimeJome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.RestTime
|
||
: null,
|
||
|
||
SingleShift1Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.Start1
|
||
: null,
|
||
SingleShift2Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.End1
|
||
: null,
|
||
TowShifts1Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.Start2
|
||
: null,
|
||
TowShifts2Shanbe1 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "1")?.End2
|
||
: null,
|
||
|
||
SingleShift1YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.Start1
|
||
: null,
|
||
SingleShift2YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.End1
|
||
: null,
|
||
TowShifts1YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.Start2
|
||
: null,
|
||
TowShifts2YekShanbe1 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "1")?.End2
|
||
: null,
|
||
|
||
SingleShift1DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.Start1
|
||
: null,
|
||
SingleShift2DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.End1
|
||
: null,
|
||
TowShifts1DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.Start2
|
||
: null,
|
||
TowShifts2DoShanbe1 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "1")?.End2
|
||
: null,
|
||
|
||
SingleShift1SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.Start1
|
||
: null,
|
||
SingleShift2SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.End1
|
||
: null,
|
||
TowShifts1SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.Start2
|
||
: null,
|
||
TowShifts2SeShanbe1 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "1")?.End2
|
||
: null,
|
||
|
||
SingleShift1CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.Start1
|
||
: null,
|
||
SingleShift2CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.End1
|
||
: null,
|
||
TowShifts1CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.Start2
|
||
: null,
|
||
TowShifts2CheharShanbe1 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "1")?.End2
|
||
: null,
|
||
|
||
SingleShift1PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.Start1
|
||
: null,
|
||
SingleShift2PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.End1
|
||
: null,
|
||
TowShifts1PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.Start2
|
||
: null,
|
||
TowShifts2PanjShanbe1 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "1")?.End2
|
||
: null,
|
||
|
||
SingleShift1Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.Start1
|
||
: null,
|
||
SingleShift2Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.End1
|
||
: null,
|
||
TowShifts1Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.Start2
|
||
: null,
|
||
TowShifts2Jome1 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "1")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "1")?.End2
|
||
: null,
|
||
|
||
//week2
|
||
Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2") ? true : false,
|
||
YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2") ? true : false,
|
||
DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2") ? true : false,
|
||
SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2") ? true : false,
|
||
CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2") ? true : false,
|
||
PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2") ? true : false,
|
||
Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2") ? true : false,
|
||
|
||
RestTimeShanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.RestTime
|
||
: null,
|
||
RestTimeYekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.RestTime
|
||
: null,
|
||
RestTimeDoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.RestTime
|
||
: null,
|
||
RestTimeSeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.RestTime
|
||
: null,
|
||
RestTimeCheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.RestTime
|
||
: null,
|
||
RestTimePanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.RestTime
|
||
: null,
|
||
RestTimeJome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.RestTime
|
||
: null,
|
||
|
||
SingleShift1Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.Start1
|
||
: null,
|
||
SingleShift2Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.End1
|
||
: null,
|
||
TowShifts1Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.Start2
|
||
: null,
|
||
TowShifts2Shanbe2 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "2")?.End2
|
||
: null,
|
||
|
||
SingleShift1YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.Start1
|
||
: null,
|
||
SingleShift2YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.End1
|
||
: null,
|
||
TowShifts1YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.Start2
|
||
: null,
|
||
TowShifts2YekShanbe2 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "2")?.End2
|
||
: null,
|
||
|
||
SingleShift1DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.Start1
|
||
: null,
|
||
SingleShift2DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.End1
|
||
: null,
|
||
TowShifts1DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.Start2
|
||
: null,
|
||
TowShifts2DoShanbe2 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "2")?.End2
|
||
: null,
|
||
|
||
SingleShift1SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.Start1
|
||
: null,
|
||
SingleShift2SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.End1
|
||
: null,
|
||
TowShifts1SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.Start2
|
||
: null,
|
||
TowShifts2SeShanbe2 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "2")?.End2
|
||
: null,
|
||
|
||
SingleShift1CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.Start1
|
||
: null,
|
||
SingleShift2CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.End1
|
||
: null,
|
||
TowShifts1CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.Start2
|
||
: null,
|
||
TowShifts2CheharShanbe2 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "2")?.End2
|
||
: null,
|
||
|
||
SingleShift1PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.Start1
|
||
: null,
|
||
SingleShift2PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.End1
|
||
: null,
|
||
TowShifts1PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.Start2
|
||
: null,
|
||
TowShifts2PanjShanbe2 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "2")?.End2
|
||
: null,
|
||
|
||
SingleShift1Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.Start1
|
||
: null,
|
||
SingleShift2Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.End1
|
||
: null,
|
||
TowShifts1Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.Start2
|
||
: null,
|
||
TowShifts2Jome2 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "2")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "2")?.End2
|
||
: null,
|
||
|
||
//week3
|
||
Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3") ? true : false,
|
||
YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3") ? true : false,
|
||
DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3") ? true : false,
|
||
SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3") ? true : false,
|
||
CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3") ? true : false,
|
||
PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3") ? true : false,
|
||
Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3") ? true : false,
|
||
|
||
RestTimeShanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.RestTime
|
||
: null,
|
||
RestTimeYekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.RestTime
|
||
: null,
|
||
RestTimeDoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.RestTime
|
||
: null,
|
||
RestTimeSeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.RestTime
|
||
: null,
|
||
RestTimeCheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.RestTime
|
||
: null,
|
||
RestTimePanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.RestTime
|
||
: null,
|
||
RestTimeJome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.RestTime
|
||
: null,
|
||
|
||
SingleShift1Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.Start1
|
||
: null,
|
||
SingleShift2Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.End1
|
||
: null,
|
||
TowShifts1Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.Start2
|
||
: null,
|
||
TowShifts2Shanbe3 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "3")?.End2
|
||
: null,
|
||
|
||
SingleShift1YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.Start1
|
||
: null,
|
||
SingleShift2YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.End1
|
||
: null,
|
||
TowShifts1YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.Start2
|
||
: null,
|
||
TowShifts2YekShanbe3 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "3")?.End2
|
||
: null,
|
||
|
||
SingleShift1DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.Start1
|
||
: null,
|
||
SingleShift2DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.End1
|
||
: null,
|
||
TowShifts1DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.Start2
|
||
: null,
|
||
TowShifts2DoShanbe3 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "3")?.End2
|
||
: null,
|
||
|
||
SingleShift1SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.Start1
|
||
: null,
|
||
SingleShift2SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.End1
|
||
: null,
|
||
TowShifts1SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.Start2
|
||
: null,
|
||
TowShifts2SeShanbe3 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "3")?.End2
|
||
: null,
|
||
|
||
SingleShift1CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.Start1
|
||
: null,
|
||
SingleShift2CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.End1
|
||
: null,
|
||
TowShifts1CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.Start2
|
||
: null,
|
||
TowShifts2CheharShanbe3 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "3")?.End2
|
||
: null,
|
||
|
||
SingleShift1PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.Start1
|
||
: null,
|
||
SingleShift2PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.End1
|
||
: null,
|
||
TowShifts1PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.Start2
|
||
: null,
|
||
TowShifts2PanjShanbe3 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "3")?.End2
|
||
: null,
|
||
|
||
SingleShift1Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.Start1
|
||
: null,
|
||
SingleShift2Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.End1
|
||
: null,
|
||
TowShifts1Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.Start2
|
||
: null,
|
||
TowShifts2Jome3 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "3")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "3")?.End2
|
||
: null,
|
||
|
||
|
||
//week4
|
||
Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4") ? true : false,
|
||
YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4") ? true : false,
|
||
DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4") ? true : false,
|
||
SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4") ? true : false,
|
||
CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4") ? true : false,
|
||
PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4") ? true : false,
|
||
Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4") ? true : false,
|
||
|
||
RestTimeShanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.RestTime
|
||
: null,
|
||
RestTimeYekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.RestTime
|
||
: null,
|
||
RestTimeDoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.RestTime
|
||
: null,
|
||
RestTimeSeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.RestTime
|
||
: null,
|
||
RestTimeCheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.RestTime
|
||
: null,
|
||
RestTimePanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.RestTime
|
||
: null,
|
||
RestTimeJome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.RestTime
|
||
: null,
|
||
|
||
SingleShift1Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.Start1
|
||
: null,
|
||
SingleShift2Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.End1
|
||
: null,
|
||
TowShifts1Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.Start2
|
||
: null,
|
||
TowShifts2Shanbe4 = items.Any(x => x.DayOfWork == "0" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "0" && x.WeekNumber == "4")?.End2
|
||
: null,
|
||
|
||
SingleShift1YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.Start1
|
||
: null,
|
||
SingleShift2YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.End1
|
||
: null,
|
||
TowShifts1YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.Start2
|
||
: null,
|
||
TowShifts2YekShanbe4 = items.Any(x => x.DayOfWork == "1" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "1" && x.WeekNumber == "4")?.End2
|
||
: null,
|
||
|
||
SingleShift1DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.Start1
|
||
: null,
|
||
SingleShift2DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.End1
|
||
: null,
|
||
TowShifts1DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.Start2
|
||
: null,
|
||
TowShifts2DoShanbe4 = items.Any(x => x.DayOfWork == "2" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "2" && x.WeekNumber == "4")?.End2
|
||
: null,
|
||
|
||
SingleShift1SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.Start1
|
||
: null,
|
||
SingleShift2SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.End1
|
||
: null,
|
||
TowShifts1SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.Start2
|
||
: null,
|
||
TowShifts2SeShanbe4 = items.Any(x => x.DayOfWork == "3" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "3" && x.WeekNumber == "4")?.End2
|
||
: null,
|
||
|
||
SingleShift1CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.Start1
|
||
: null,
|
||
SingleShift2CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.End1
|
||
: null,
|
||
TowShifts1CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.Start2
|
||
: null,
|
||
TowShifts2CheharShanbe4 = items.Any(x => x.DayOfWork == "4" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "4" && x.WeekNumber == "4")?.End2
|
||
: null,
|
||
|
||
SingleShift1PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.Start1
|
||
: null,
|
||
SingleShift2PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.End1
|
||
: null,
|
||
TowShifts1PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.Start2
|
||
: null,
|
||
TowShifts2PanjShanbe4 = items.Any(x => x.DayOfWork == "5" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "5" && x.WeekNumber == "4")?.End2
|
||
: null,
|
||
|
||
SingleShift1Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.Start1
|
||
: null,
|
||
SingleShift2Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.End1
|
||
: null,
|
||
TowShifts1Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.Start2
|
||
: null,
|
||
TowShifts2Jome4 = items.Any(x => x.DayOfWork == "6" && x.WeekNumber == "4")
|
||
? items.FirstOrDefault(x => x.DayOfWork == "6" && x.WeekNumber == "4")?.End2
|
||
: null
|
||
};
|
||
//تفکیک ساعت استراحت
|
||
|
||
#region TafkikRest
|
||
|
||
#region Week1
|
||
|
||
var restTimeShanbe1 = result.RestTimeShanbe1;
|
||
result.RestTimeShanbe1 = restTimeShanbe1.RestTimeSplit();
|
||
result.RestTimeShanbe1Min = restTimeShanbe1.RestTimeMinSplit();
|
||
var restTimeYekShanbe1 = result.RestTimeYekShanbe1;
|
||
result.RestTimeYekShanbe1 = restTimeYekShanbe1.RestTimeSplit();
|
||
result.RestTimeYekShanbe1Min = restTimeYekShanbe1.RestTimeMinSplit();
|
||
var restTimeDoShanbe1 = result.RestTimeDoShanbe1;
|
||
result.RestTimeDoShanbe1 = restTimeDoShanbe1.RestTimeSplit();
|
||
result.RestTimeDoShanbe1Min = restTimeDoShanbe1.RestTimeMinSplit();
|
||
var restTimeSeShanbe1 = result.RestTimeSeShanbe1;
|
||
result.RestTimeSeShanbe1 = restTimeSeShanbe1.RestTimeSplit();
|
||
result.RestTimeSeShanbe1Min = restTimeSeShanbe1.RestTimeMinSplit();
|
||
var restTimeCheharShanbe1 = result.RestTimeCheharShanbe1;
|
||
result.RestTimeCheharShanbe1 = restTimeCheharShanbe1.RestTimeSplit();
|
||
result.RestTimeCheharShanbe1Min = restTimeCheharShanbe1.RestTimeMinSplit();
|
||
var restTimePanjShanbe1 = result.RestTimePanjShanbe1;
|
||
result.RestTimePanjShanbe1 = restTimePanjShanbe1.RestTimeSplit();
|
||
result.RestTimePanjShanbe1Min = restTimePanjShanbe1.RestTimeMinSplit();
|
||
var restTimeJome1 = result.RestTimeJome1;
|
||
result.RestTimeJome1 = restTimeJome1.RestTimeSplit();
|
||
result.RestTimeJome1Min = restTimeJome1.RestTimeMinSplit();
|
||
|
||
#endregion
|
||
|
||
#region week2
|
||
|
||
var restTimeShanbe2 = result.RestTimeShanbe2;
|
||
result.RestTimeShanbe2 = restTimeShanbe2.RestTimeSplit();
|
||
result.RestTimeShanbe2Min = restTimeShanbe2.RestTimeMinSplit();
|
||
var restTimeYekShanbe2 = result.RestTimeYekShanbe2;
|
||
result.RestTimeYekShanbe2 = restTimeYekShanbe2.RestTimeSplit();
|
||
result.RestTimeYekShanbe2Min = restTimeYekShanbe2.RestTimeMinSplit();
|
||
var restTimeDoShanbe2 = result.RestTimeDoShanbe2;
|
||
result.RestTimeDoShanbe2 = restTimeDoShanbe2.RestTimeSplit();
|
||
result.RestTimeDoShanbe2Min = restTimeDoShanbe2.RestTimeMinSplit();
|
||
var restTimeSeShanbe2 = result.RestTimeSeShanbe2;
|
||
result.RestTimeSeShanbe2 = restTimeSeShanbe2.RestTimeSplit();
|
||
result.RestTimeSeShanbe2Min = restTimeSeShanbe2.RestTimeMinSplit();
|
||
var restTimeCheharShanbe2 = result.RestTimeCheharShanbe2;
|
||
result.RestTimeCheharShanbe2 = restTimeCheharShanbe2.RestTimeSplit();
|
||
result.RestTimeCheharShanbe2Min = restTimeCheharShanbe2.RestTimeMinSplit();
|
||
var restTimePanjShanbe2 = result.RestTimePanjShanbe2;
|
||
result.RestTimePanjShanbe2 = restTimePanjShanbe2.RestTimeSplit();
|
||
result.RestTimePanjShanbe2Min = restTimePanjShanbe2.RestTimeMinSplit();
|
||
var restTimeJome2 = result.RestTimeJome2;
|
||
result.RestTimeJome2 = restTimeJome2.RestTimeSplit();
|
||
result.RestTimeJome2Min = restTimeJome2.RestTimeMinSplit();
|
||
|
||
#endregion
|
||
|
||
#region week3
|
||
|
||
var restTimeShanbe3 = result.RestTimeShanbe3;
|
||
result.RestTimeShanbe3 = restTimeShanbe3.RestTimeSplit();
|
||
result.RestTimeShanbe3Min = restTimeShanbe3.RestTimeMinSplit();
|
||
var restTimeYekShanbe3 = result.RestTimeYekShanbe3;
|
||
result.RestTimeYekShanbe3 = restTimeYekShanbe3.RestTimeSplit();
|
||
result.RestTimeYekShanbe3Min = restTimeYekShanbe3.RestTimeMinSplit();
|
||
var restTimeDoShanbe3 = result.RestTimeDoShanbe3;
|
||
result.RestTimeDoShanbe3 = restTimeDoShanbe3.RestTimeSplit();
|
||
result.RestTimeDoShanbe3Min = restTimeDoShanbe3.RestTimeMinSplit();
|
||
var restTimeSeShanbe3 = result.RestTimeSeShanbe3;
|
||
result.RestTimeSeShanbe3 = restTimeSeShanbe3.RestTimeSplit();
|
||
result.RestTimeSeShanbe3Min = restTimeSeShanbe3.RestTimeMinSplit();
|
||
var restTimeCheharShanbe3 = result.RestTimeCheharShanbe3;
|
||
result.RestTimeCheharShanbe3 = restTimeCheharShanbe3.RestTimeSplit();
|
||
result.RestTimeCheharShanbe3Min = restTimeCheharShanbe3.RestTimeMinSplit();
|
||
var restTimePanjShanbe3 = result.RestTimePanjShanbe3;
|
||
result.RestTimePanjShanbe3 = restTimePanjShanbe3.RestTimeSplit();
|
||
result.RestTimePanjShanbe3Min = restTimePanjShanbe3.RestTimeMinSplit();
|
||
var restTimeJome3 = result.RestTimeJome3;
|
||
result.RestTimeJome3 = restTimeJome3.RestTimeSplit();
|
||
result.RestTimeJome3Min = restTimeJome3.RestTimeMinSplit();
|
||
|
||
#endregion
|
||
|
||
#region week4
|
||
|
||
var restTimeShanbe4 = result.RestTimeShanbe4;
|
||
result.RestTimeShanbe4 = restTimeShanbe4.RestTimeSplit();
|
||
result.RestTimeShanbe4Min = restTimeShanbe4.RestTimeMinSplit();
|
||
var restTimeYekShanbe4 = result.RestTimeYekShanbe4;
|
||
result.RestTimeYekShanbe4 = restTimeYekShanbe4.RestTimeSplit();
|
||
result.RestTimeYekShanbe4Min = restTimeYekShanbe4.RestTimeMinSplit();
|
||
var restTimeDoShanbe4 = result.RestTimeDoShanbe4;
|
||
result.RestTimeDoShanbe4 = restTimeDoShanbe4.RestTimeSplit();
|
||
result.RestTimeDoShanbe4Min = restTimeDoShanbe4.RestTimeMinSplit();
|
||
var restTimeSeShanbe4 = result.RestTimeSeShanbe4;
|
||
result.RestTimeSeShanbe4 = restTimeSeShanbe4.RestTimeSplit();
|
||
result.RestTimeSeShanbe4Min = restTimeSeShanbe4.RestTimeMinSplit();
|
||
var restTimeCheharShanbe4 = result.RestTimeCheharShanbe4;
|
||
result.RestTimeCheharShanbe4 = restTimeCheharShanbe4.RestTimeSplit();
|
||
result.RestTimeCheharShanbe4Min = restTimeCheharShanbe4.RestTimeMinSplit();
|
||
var restTimePanjShanbe4 = result.RestTimePanjShanbe4;
|
||
result.RestTimePanjShanbe4 = restTimePanjShanbe4.RestTimeSplit();
|
||
result.RestTimePanjShanbe4Min = restTimePanjShanbe4.RestTimeMinSplit();
|
||
var restTimeJome4 = result.RestTimeJome4;
|
||
result.RestTimeJome4 = restTimeJome4.RestTimeSplit();
|
||
result.RestTimeJome4Min = restTimeJome4.RestTimeMinSplit();
|
||
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
workingHoursList.Add(result);
|
||
}
|
||
else
|
||
{
|
||
var result = new CreateWorkingHoursTemp
|
||
{
|
||
EmployeeId = getContracts.First(x => x.id == workingHours.ContractId).EmployeeId,
|
||
WorknigHoursId = workingHours.id,
|
||
ShiftWork = workingHours.ShiftWork,
|
||
ShiftWorkTemp = "5",
|
||
StartComplex = items.FirstOrDefault()?.ComplexStart,
|
||
EndComplex = items.FirstOrDefault()?.ComplexEnd,
|
||
WeeklyWorkingTime = workingHours.WeeklyWorkingTime
|
||
};
|
||
workingHoursList.Add(result);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
var workingHoursTime = watcher.Elapsed;
|
||
watcher.Reset();
|
||
watcher.Start();
|
||
//دریافت اطلاعات شروع بکار/ترک کار
|
||
#region LeftWorks
|
||
|
||
var leftWorks = await _context.LeftWorkList
|
||
.Where(x => x.WorkshopId == workshopId)
|
||
.Where(x => employeeIds.Contains(x.EmployeeId)).AsNoTracking().ToListAsync();
|
||
|
||
#endregion
|
||
|
||
var leftWorkTime = watcher.Elapsed;
|
||
watcher.Reset();
|
||
watcher.Stop();
|
||
|
||
//جداسازی شروع و پایان فیش از قراداد با توجه به شروع بکار و ترک کار
|
||
#region Separation
|
||
|
||
var timer = new Stopwatch();
|
||
timer.Start();
|
||
var separation = new List<ContractSeparationViewModel>();
|
||
var seprationData = getContracts.Select(x => new { x.EmployeeId, x.ContarctStart, x.ContractEnd }).ToList();
|
||
|
||
foreach (var contract in seprationData)
|
||
{
|
||
var leftWork = leftWorks.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId && contract.ContarctStart < x.LeftWorkDate && contract.ContractEnd >= x.StartWorkDate);
|
||
var start = new DateTime();
|
||
var end = new DateTime();
|
||
if (leftWork == null)
|
||
{
|
||
separation.Add(new ContractSeparationViewModel()
|
||
{
|
||
checker = false,
|
||
EmployeeId = contract.EmployeeId
|
||
});
|
||
continue;
|
||
}
|
||
for (var current = contract.ContarctStart; current <= contract.ContractEnd; current=current.AddDays(1))
|
||
{
|
||
if (start == new DateTime() && current >= checkoutSelectedStart && current <= checkoutSelectedEnd)
|
||
{
|
||
start = current;
|
||
}
|
||
|
||
if (end == new DateTime() && current == checkoutSelectedEnd)
|
||
{
|
||
end = current;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
var leftFirstDayOfNextMonth = end.AddDays(1);
|
||
if (leftWork.HasLeft && leftWork.LeftWorkDate <= leftFirstDayOfNextMonth &&
|
||
leftWork.LeftWorkDate > start)
|
||
{
|
||
var ContractEnd = leftWork.LeftWorkDate.AddDays(-1);
|
||
separation.Add(new ContractSeparationViewModel()
|
||
{
|
||
StartWorkDate = leftWork.StartWorkDate,
|
||
LeftWorkDate = ContractEnd,
|
||
HasLeft = true,
|
||
ContarctStart = start.ToFarsi(),
|
||
ContractEnd = ContractEnd.ToFarsi(),
|
||
ContractStartGr = start,
|
||
ContractEndGr = ContractEnd,
|
||
checker = true,
|
||
EmployeeId = contract.EmployeeId
|
||
});
|
||
}
|
||
else if(leftWork.HasLeft && leftWork.LeftWorkDate > leftFirstDayOfNextMonth)
|
||
{
|
||
separation.Add(new ContractSeparationViewModel()
|
||
{
|
||
StartWorkDate = leftWork.StartWorkDate,
|
||
LeftWorkDate = leftWork.LeftWorkDate.AddDays(-1),
|
||
HasLeft = false,
|
||
ContarctStart = start.ToFarsi(),
|
||
ContractEnd = end.ToFarsi(),
|
||
ContractStartGr = start,
|
||
ContractEndGr = end,
|
||
checker = true,
|
||
EmployeeId = contract.EmployeeId
|
||
});
|
||
}
|
||
else if(!leftWork.HasLeft)
|
||
{
|
||
separation.Add(new ContractSeparationViewModel()
|
||
{
|
||
StartWorkDate = leftWork.StartWorkDate,
|
||
LeftWorkDate = new DateTime(2121, 3, 21),
|
||
HasLeft = false,
|
||
ContarctStart = start.ToFarsi(),
|
||
ContractEnd = end.ToFarsi(),
|
||
ContractStartGr = start,
|
||
ContractEndGr = end,
|
||
checker = true,
|
||
EmployeeId = contract.EmployeeId
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
//foreach (var item in seprationData)
|
||
//{
|
||
// bool hasLeft = false;
|
||
// var ContractEnd = item.ContractEnd;
|
||
// var contractStart = item.ContarctStart;
|
||
// var leftWork = leftWorks.FirstOrDefault(x => x.EmployeeId == item.EmployeeId && item.ContarctStart <= x.LeftWorkDate && item.ContractEnd >= x.StartWorkDate);
|
||
// if (leftWork == null)
|
||
// {
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// checker = false,
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
// }
|
||
|
||
// if (leftWork.HasLeft && leftWork.LeftWorkDate < item.ContractEnd &&
|
||
// leftWork.LeftWorkDate >= item.ContarctStart)
|
||
// {
|
||
// ContractEnd = leftWork.LeftWorkDate.AddDays(-1);
|
||
// hasLeft = true;
|
||
// var start = contractStart.ToFarsi();
|
||
// var end = ContractEnd.ToFarsi();
|
||
// var ContractPreiodsList = new List<PeriodStartEnd>();
|
||
// var CheckoutMonth = int.Parse(month);
|
||
|
||
// var syear = Convert.ToInt32(start.Substring(0, 4));
|
||
// var smonth = Convert.ToInt32(start.Substring(5, 2));
|
||
// var sday = Convert.ToInt32(start.Substring(8, 2));
|
||
|
||
// var eyear = Convert.ToInt32(end.Substring(0, 4));
|
||
// var emonth = Convert.ToInt32(end.Substring(5, 2));
|
||
// var eday = Convert.ToInt32(end.Substring(8, 2));
|
||
|
||
// var PersianStartDate = new PersianDateTime(syear, smonth, sday);
|
||
// var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1);
|
||
// var PersianEndDate = new PersianDateTime(eyear, emonth, eday);
|
||
|
||
|
||
// var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1;
|
||
// for (int i = 0; i < totalmonth; i++)
|
||
// {
|
||
|
||
|
||
// var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1);
|
||
// if (currentEndDate > PersianEndDate)
|
||
// {
|
||
// currentEndDate = PersianEndDate;
|
||
// }
|
||
|
||
// var period = new PeriodStartEnd
|
||
// {
|
||
// startC = PersianStartDate.ToString("yyyy/MM/dd"),
|
||
// endC = currentEndDate.ToString("yyyy/MM/dd"),
|
||
// monthC = currentEndDate.Month
|
||
// };
|
||
// ContractPreiodsList.Add(period);
|
||
// //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}");
|
||
|
||
// PersianStartDate = PersianStartDate.AddMonths(1);
|
||
// PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1);
|
||
|
||
|
||
// }
|
||
|
||
// var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth);
|
||
// if (periodSelect != null)
|
||
// {
|
||
// var startDate = periodSelect.startC.ToGeorgianDateTime();
|
||
// var endDate = periodSelect.endC.ToGeorgianDateTime();
|
||
|
||
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// StartWorkDate = leftWork.StartWorkDate,
|
||
// LeftWorkDate = ContractEnd,
|
||
// HasLeft = hasLeft,
|
||
// ContarctStart = periodSelect.startC,
|
||
// ContractEnd = periodSelect.endC,
|
||
// ContractStartGr = startDate,
|
||
// ContractEndGr = endDate,
|
||
// checker = true,
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
// }
|
||
// else
|
||
// {
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// checker = false,
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
// }
|
||
// }
|
||
|
||
// if (leftWork.HasLeft && leftWork.LeftWorkDate >= item.ContractEnd &&
|
||
// leftWork.LeftWorkDate > item.ContarctStart)
|
||
// {
|
||
// var lastWorkDay = leftWork.LeftWorkDate.AddDays(-1);
|
||
|
||
// if (leftWork.LeftWorkDate == ContractEnd)
|
||
// {
|
||
// ContractEnd = lastWorkDay;
|
||
// hasLeft = true;
|
||
// }
|
||
|
||
// if (lastWorkDay == ContractEnd)
|
||
// {
|
||
// hasLeft = true;
|
||
// }
|
||
|
||
// var start = contractStart.ToFarsi();
|
||
// var end = ContractEnd.ToFarsi();
|
||
// var ContractPreiodsList = new List<PeriodStartEnd>();
|
||
// var CheckoutMonth = int.Parse(month);
|
||
|
||
// var syear = Convert.ToInt32(start.Substring(0, 4));
|
||
// var smonth = Convert.ToInt32(start.Substring(5, 2));
|
||
// var sday = Convert.ToInt32(start.Substring(8, 2));
|
||
|
||
// var eyear = Convert.ToInt32(end.Substring(0, 4));
|
||
// var emonth = Convert.ToInt32(end.Substring(5, 2));
|
||
// var eday = Convert.ToInt32(end.Substring(8, 2));
|
||
|
||
// var PersianStartDate = new PersianDateTime(syear, smonth, sday);
|
||
// var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1);
|
||
// var PersianEndDate = new PersianDateTime(eyear, emonth, eday);
|
||
|
||
|
||
|
||
// var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1;
|
||
// for (int i = 0; i < totalmonth; i++)
|
||
// {
|
||
|
||
|
||
// var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1);
|
||
// if (currentEndDate > PersianEndDate)
|
||
// {
|
||
// currentEndDate = PersianEndDate;
|
||
// }
|
||
|
||
// var period = new PeriodStartEnd
|
||
// {
|
||
// startC = PersianStartDate.ToString("yyyy/MM/dd"),
|
||
// endC = currentEndDate.ToString("yyyy/MM/dd"),
|
||
// monthC = currentEndDate.Month
|
||
// };
|
||
// ContractPreiodsList.Add(period);
|
||
// //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}");
|
||
|
||
// PersianStartDate = PersianStartDate.AddMonths(1);
|
||
// PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1);
|
||
|
||
|
||
// }
|
||
|
||
// var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth);
|
||
// if (periodSelect != null)
|
||
// {
|
||
// var startDate = periodSelect.startC.ToGeorgianDateTime();
|
||
// var endDate = periodSelect.endC.ToGeorgianDateTime();
|
||
|
||
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// StartWorkDate = leftWork.StartWorkDate,
|
||
// LeftWorkDate = ContractEnd,
|
||
// HasLeft = hasLeft,
|
||
// ContarctStart = periodSelect.startC,
|
||
// ContractEnd = periodSelect.endC,
|
||
// ContractStartGr = startDate,
|
||
// ContractEndGr = endDate,
|
||
// checker = true,
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
// }
|
||
// else
|
||
// {
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// checker = false,
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
// }
|
||
// }
|
||
// else if (leftWork.HasLeft && contractStart > leftWork.LeftWorkDate)
|
||
// {
|
||
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// checker = false,
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
// }
|
||
// else if (!leftWork.HasLeft)
|
||
// {
|
||
// var start = contractStart.ToFarsi();
|
||
// var end = ContractEnd.ToFarsi();
|
||
// var ContractPreiodsList = new List<PeriodStartEnd>();
|
||
// var CheckoutMonth = int.Parse(month);
|
||
|
||
// var syear = Convert.ToInt32(start.Substring(0, 4));
|
||
// var smonth = Convert.ToInt32(start.Substring(5, 2));
|
||
// var sday = Convert.ToInt32(start.Substring(8, 2));
|
||
|
||
// var eyear = Convert.ToInt32(end.Substring(0, 4));
|
||
// var emonth = Convert.ToInt32(end.Substring(5, 2));
|
||
// var eday = Convert.ToInt32(end.Substring(8, 2));
|
||
|
||
// var PersianStartDate = new PersianDateTime(syear, smonth, sday);
|
||
// var PersianStartDateAddingMount = new PersianDateTime(syear, smonth, 1);
|
||
// var PersianEndDate = new PersianDateTime(eyear, emonth, eday);
|
||
|
||
// var totalmonth = ((PersianEndDate.Year - PersianStartDateAddingMount.Year) * 12) + (PersianEndDate.Month - PersianStartDateAddingMount.Month) + 1;
|
||
// for (int i = 0; i < totalmonth; i++)
|
||
// {
|
||
|
||
|
||
// var currentEndDate = PersianStartDateAddingMount.AddMonths(1).AddDays(-1);
|
||
// if (currentEndDate > PersianEndDate)
|
||
// {
|
||
// currentEndDate = PersianEndDate;
|
||
// }
|
||
|
||
// var period = new PeriodStartEnd
|
||
// {
|
||
// startC = PersianStartDate.ToString("yyyy/MM/dd"),
|
||
// endC = currentEndDate.ToString("yyyy/MM/dd"),
|
||
// monthC = currentEndDate.Month
|
||
// };
|
||
// ContractPreiodsList.Add(period);
|
||
// //Console.WriteLine($"Month {i + 1} : {PersianStartDate.ToString("yyyy-MM-dd")} to {currentEndDate.ToString("yyyy-MM-dd")}");
|
||
|
||
// PersianStartDate = PersianStartDate.AddMonths(1);
|
||
// PersianStartDate = new PersianDateTime(PersianStartDate.Year, PersianStartDate.Month, 1);
|
||
|
||
|
||
// }
|
||
|
||
// var periodSelect = ContractPreiodsList.FirstOrDefault(x => x.monthC == CheckoutMonth);
|
||
// if (periodSelect != null)
|
||
// {
|
||
// var startDate = periodSelect.startC.ToGeorgianDateTime();
|
||
// var endDate = periodSelect.endC.ToGeorgianDateTime();
|
||
|
||
|
||
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// StartWorkDate = leftWork.StartWorkDate,
|
||
// HasLeft = hasLeft,
|
||
// ContarctStart = periodSelect.startC,
|
||
// ContractEnd = periodSelect.endC,
|
||
// ContractStartGr = startDate,
|
||
// ContractEndGr = endDate,
|
||
// checker = true,
|
||
// LeftWorkDate = new DateTime(2121, 3, 21),
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
|
||
// }
|
||
// else
|
||
// {
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// checker = false,
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// separation.Add(new ContractSeparationViewModel()
|
||
// {
|
||
// checker = false,
|
||
// EmployeeId = item.EmployeeId
|
||
// });
|
||
|
||
// }
|
||
//}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
var SeparationTime = timer.Elapsed;
|
||
timer.Stop();
|
||
var optionTimer = new Stopwatch();
|
||
optionTimer.Start();
|
||
//دریافت تنظیمات فنی پرسنل ها
|
||
#region EmployeeOptions
|
||
|
||
var employeeOptions = await _context.EmployeeComputeOptionsSet.Where(x => x.WorkshopId == workshopId).Select(x => new EmployeeComputeOptionsViewModel
|
||
{
|
||
Id = x.id,
|
||
WorkshopId = x.WorkshopId,
|
||
EmployeeId = x.EmployeeId,
|
||
ComputeOptions = x.ComputeOptions,
|
||
YearsOptions = x.YearsOptions,
|
||
BonusesOptions = x.BonusesOptions,
|
||
}).AsNoTracking().ToListAsync();
|
||
|
||
#endregion
|
||
|
||
var optionTime = optionTimer.Elapsed;
|
||
optionTimer.Stop();
|
||
|
||
|
||
var toListTimer = new Stopwatch();
|
||
toListTimer.Start();
|
||
var yearsOption = workshop.YearsOptions;
|
||
var bonusesOption = workshop.BonusesOptions;
|
||
var computeOption = workshop.ComputeOptions;
|
||
var incloudedData = getContracts.Select(x =>
|
||
{
|
||
|
||
var employeeOption = employeeOptions.FirstOrDefault(option => option.EmployeeId == x.EmployeeId);
|
||
if(employeeOption != null)
|
||
{
|
||
yearsOption = employeeOption.YearsOptions;
|
||
bonusesOption = employeeOption.BonusesOptions;
|
||
computeOption = employeeOption.ComputeOptions;
|
||
}
|
||
return new ContractIncludedData
|
||
{
|
||
//اطلاعات هویتی پرسنل
|
||
#region EmployeeData
|
||
EmployeeId = x.EmployeeId,
|
||
EmployeeFullName = x.Employee.FullName,
|
||
FathersName = x.Employee.FatherName,
|
||
NationalCode = x.Employee.NationalCode,
|
||
DateOfBirth = x.Employee.DateOfBirth.ToFarsi(),
|
||
PersonnelCode = $"{x.PersonnelCode}",
|
||
MaritalStatus = x.Employee.MaritalStatus,
|
||
#endregion
|
||
|
||
//ساعت کاری پرسنل
|
||
#region WorkingHours
|
||
WorkingHours = workingHoursList.FirstOrDefault(wh => wh.EmployeeId == x.EmployeeId),
|
||
#endregion
|
||
|
||
//اطلاعات جداسازی تاریخ فیش از قرارداد
|
||
#region Saparation
|
||
Separation = separation.FirstOrDefault(sep => sep.EmployeeId == x.EmployeeId),
|
||
#endregion
|
||
|
||
//تنظیمات فنی پرسنل
|
||
#region EmployeeOption
|
||
|
||
YearsOption = yearsOption,
|
||
BonusesOption = bonusesOption,
|
||
ComputeOption = computeOption,
|
||
|
||
#endregion
|
||
|
||
//اطلاعات قراداد
|
||
#region ContractData
|
||
|
||
ContractNo = x.ContractNo,
|
||
ContractStart = x.ContarctStart.ToFarsi(),
|
||
ContractEnd = x.ContractEnd.ToFarsi(),
|
||
ContractStartGr = x.ContarctStart,
|
||
ContractEndGr = x.ContractEnd,
|
||
ContractId = x.id,
|
||
DailySalaryUnAffected = x.DailySalaryUnAffected,
|
||
DailyWageType = x.DailyWageType,
|
||
FirstGetWorkingDay = x.GetWorkDate.ToFarsi(),
|
||
#endregion
|
||
};
|
||
}).ToList();
|
||
|
||
var finalResult = new GetContractAndIncludesDataToCreateDto()
|
||
{
|
||
//اطلاعات کارگاه
|
||
#region WorkshopData
|
||
|
||
WorkshopId = workshop.id,
|
||
ArchiveCode = workshop.ArchiveCode,
|
||
WorkshopName = workshop.WorkshopName,
|
||
IsStaticCheckout = workshop.IsStaticCheckout,
|
||
HasInsuranceCheckoutOverTime = workshop.InsuranceCheckoutOvertime,
|
||
FixedSalary = workshop.FixedSalary,
|
||
InsuranceJobId = workshop.InsuranceJobId,
|
||
Population = workshop.Population,
|
||
TypeOfInsuranceSend = workshop.TypeOfInsuranceSend,
|
||
|
||
#endregion
|
||
|
||
|
||
ContractIncludedData = incloudedData,
|
||
};
|
||
|
||
var tolistTime = toListTimer.Elapsed;
|
||
Console.WriteLine("GetContracts - employeeIds - workshop: " + GetContractsTime);
|
||
Console.WriteLine("workingHours " + workingHoursTime);
|
||
Console.WriteLine("leftWork " + leftWorkTime);
|
||
Console.WriteLine("Separation " + SeparationTime);
|
||
Console.WriteLine("EmployeeOptions : " + optionTime);
|
||
Console.WriteLine("TolistTime : " + tolistTime);
|
||
Console.WriteLine("===================== sum : " + (GetContractsTime + workingHoursTime + leftWorkTime + SeparationTime + optionTime + tolistTime) + "===================");
|
||
|
||
|
||
return op.Succcedded(finalResult);
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// دریافت لیست فیش حقوقی
|
||
/// </summary>
|
||
/// <param name="searchModel"></param>
|
||
/// <returns></returns>
|
||
public async Task<PagedResult<CheckoutDto>> GetList(CheckoutSearchModelDto searchModel)
|
||
{
|
||
var acountID = _authHelper.CurrentAccountId();
|
||
var workshopAccounts = _context.WorkshopAccounts.Where(x => x.AccountId == acountID)
|
||
.Select(x => x.WorkshopId);
|
||
|
||
|
||
var watch = new Stopwatch();
|
||
watch.Start();
|
||
var checkouts =
|
||
(
|
||
from workshop in _context.Workshops.Where(x => workshopAccounts.Contains(x.id))
|
||
join x in _context.CheckoutSet
|
||
on workshop.id equals x.WorkshopId
|
||
select new
|
||
{
|
||
Id = x.id,
|
||
EmployeeFullName = x.EmployeeFullName,
|
||
EmployeeId = x.EmployeeId,
|
||
ContractStart = x.ContractStart,
|
||
ContractEnd = x.ContractEnd,
|
||
PersonnelCode = x.PersonnelCode,
|
||
SumOfWorkingDays = x.SumOfWorkingDays,
|
||
Month = x.Month,
|
||
Year = x.Year,
|
||
ContractNo = x.ContractNo,
|
||
IsActiveString = x.IsActiveString,
|
||
Signature = x.Signature,
|
||
IsUpdateNeeded = x.IsUpdateNeeded,
|
||
WorkshopId = x.WorkshopId,
|
||
ArchiveCode = workshop.ArchiveCode,
|
||
WorkshopName = workshop.WorkshopFullName,
|
||
WorkshopSignCheckout = workshop.SignCheckout,
|
||
}
|
||
).OrderByDescending(x => x.Id)
|
||
.ThenByDescending(x => x.Year)
|
||
.ThenByDescending(x => x.ContractStart)
|
||
.ThenBy(x => x.PersonnelCode).AsNoTracking();
|
||
|
||
Console.WriteLine("getList======================= : " + watch.Elapsed);
|
||
|
||
#region SercheModel
|
||
|
||
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo))
|
||
checkouts = checkouts.Where(x =>
|
||
x.ContractNo == searchModel.ContractNo);
|
||
if (searchModel.WorkshopId != 0)
|
||
{
|
||
checkouts = checkouts.Where(x => x.WorkshopId == searchModel.WorkshopId)
|
||
.OrderByDescending(x => x.ContractStart)
|
||
.ThenBy(x => x.PersonnelCode);
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(searchModel.EmployeeFullName))
|
||
{
|
||
checkouts = checkouts.Where(x => x.EmployeeFullName.Contains(searchModel.EmployeeFullName));
|
||
}
|
||
|
||
if (searchModel.EmployerId != 0)
|
||
{
|
||
var workshopIds = _context.WorkshopEmployers.Where(e => e.EmployerId == searchModel.EmployerId)
|
||
.Select(e => e.WorkshopId);
|
||
checkouts = checkouts.Where(x => workshopIds.Contains(x.WorkshopId))
|
||
.OrderByDescending(x => x.ContractStart);
|
||
}
|
||
|
||
|
||
//سرچ سال
|
||
|
||
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();
|
||
|
||
|
||
checkouts = checkouts.Where(x => x.ContractStart >= startyearGr && x.ContractEnd <= endYearGr);
|
||
if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) ||
|
||
searchModel.EmployerId > 0)
|
||
checkouts = checkouts.OrderByDescending(x => x.ContractEnd);
|
||
}
|
||
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();
|
||
|
||
//checkouts = checkouts.Where(x => x.ContractEndGr >= start && x.ContractEndGr <= end).ToList();
|
||
checkouts = checkouts.Where(x =>
|
||
x.ContractStart >= startDate && x.ContractStart < endDate && x.ContractEnd > startDate &&
|
||
x.ContractEnd <= endDate ||
|
||
x.ContractStart <= startDate && x.ContractEnd >= endDate ||
|
||
startDate <= x.ContractStart && endDate > x.ContractStart ||
|
||
endDate >= x.ContractEnd && startDate < x.ContractEnd);
|
||
//if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
|
||
// checkouts = checkouts.OrderBy(x => x.PersonnelCodeInt);
|
||
}
|
||
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();
|
||
checkouts = checkouts.Where(x =>
|
||
x.ContractStart >= start && x.ContractStart <= endd);
|
||
|
||
if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) ||
|
||
searchModel.EmployerId > 0)
|
||
checkouts = checkouts.OrderByDescending(x => x.ContractEnd).ThenBy(x => x.PersonnelCode);
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
watch.Reset();
|
||
watch.Start();
|
||
|
||
var checkoutQueryFilter =
|
||
await checkouts.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync();
|
||
Console.WriteLine("pagination===================== : " + watch.Elapsed);
|
||
|
||
var employers = await
|
||
_context.WorkshopEmployers.Where(x => checkoutQueryFilter
|
||
.Select(c => c.WorkshopId).Contains(x.WorkshopId))
|
||
.Select(x => new { x.Employer, x.WorkshopId }).ToListAsync();
|
||
var contractingPartiesIds = employers.Select(x => x.Employer.ContractingPartyId).ToList();
|
||
var warningMessages = await _context.CheckoutWarningMessages.Where(x => checkoutQueryFilter
|
||
.Select(c => c.Id).Contains(x.CheckoutId)).ToListAsync();
|
||
|
||
|
||
var contractnigParties = await _context.PersonalContractingParties
|
||
.Where(x => contractingPartiesIds.Contains(x.id)).ToListAsync();
|
||
|
||
var options = await _context.EmployeeComputeOptionsSet.Where(x => checkoutQueryFilter
|
||
.Select(c => c.WorkshopId).Contains(x.WorkshopId)).ToListAsync();
|
||
|
||
watch.Reset();
|
||
watch.Start();
|
||
var result = checkoutQueryFilter.Select(x =>
|
||
|
||
|
||
{
|
||
var warningMessage = warningMessages.Where(wm => wm.CheckoutId == x.Id);
|
||
var empl = employers.First(em => em.WorkshopId == x.WorkshopId);
|
||
var isBlock =
|
||
contractnigParties.Any(cp => cp.id == empl.Employer.ContractingPartyId && cp.IsBlock == "true");
|
||
var option = options.FirstOrDefault(o => o.WorkshopId == x.WorkshopId && o.EmployeeId == x.EmployeeId);
|
||
return new CheckoutDto
|
||
{
|
||
Id = x.Id,
|
||
EmployeeFullName = x.EmployeeFullName,
|
||
ContractStart = x.ContractStart.ToFarsi(),
|
||
ContractEnd = x.ContractEnd.ToFarsi(),
|
||
PersonnelCode = x.PersonnelCode,
|
||
ArchiveCode = x.ArchiveCode,
|
||
SumOfWorkingDays = x.SumOfWorkingDays,
|
||
WorkshopName = x.WorkshopName,
|
||
Month = x.Month,
|
||
Year = x.Year,
|
||
ContractNo = x.ContractNo,
|
||
IsActive = x.IsActiveString == "true",
|
||
Signature = x.Signature == "1",
|
||
EmployerName = $"{empl.Employer.FullName}",
|
||
IsBlockCantracingParty = isBlock,
|
||
HasSignCheckoutOption = option != null ? option.SignCheckout : x.WorkshopSignCheckout,
|
||
IsUpdateNeeded = x.IsUpdateNeeded,
|
||
CheckoutWarningMessageList = warningMessage.Select(wm => new CheckoutWarningMessageModel
|
||
{
|
||
WarningMessage = wm.WarningMessage,
|
||
TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning,
|
||
}).ToList()
|
||
};
|
||
})
|
||
.ToList();
|
||
var count = await checkouts.CountAsync();
|
||
Console.WriteLine("FinalList================================ : " + watch.Elapsed);
|
||
return new PagedResult<CheckoutDto>()
|
||
{
|
||
TotalCount = count,
|
||
List = result
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// پرینت فیش حقوقی
|
||
/// Api
|
||
/// </summary>
|
||
/// <param name="ids"></param>
|
||
/// <returns></returns>
|
||
public async Task<List<CheckoutPrintDto>> CheckoutPrint(List<long> ids)
|
||
{
|
||
if (ids.Count == 0)
|
||
return new List<CheckoutPrintDto>();
|
||
|
||
var watch = new Stopwatch();
|
||
watch.Start();
|
||
|
||
var getCheckouts = await _context.CheckoutSet.Where(x => ids.Contains(x.id))
|
||
.AsNoTracking()
|
||
.ToListAsync();
|
||
|
||
var employers = await _context.WorkshopEmployers
|
||
.Where(x => x.WorkshopId == getCheckouts.First().WorkshopId).AsNoTracking()
|
||
.Select(x => new CheckoutEmployersList
|
||
{
|
||
IsLegal = x.Employer.IsLegal,
|
||
EmployerFullName = x.Employer.FullName
|
||
}).ToListAsync();
|
||
|
||
var employees =
|
||
(from x in _context.Employees.Where(x => getCheckouts.Select(ch => ch.EmployeeId).Contains(x.id))
|
||
select new
|
||
{
|
||
EmployeeId = x.id,
|
||
MaritalStatus = x.MaritalStatus
|
||
}
|
||
).AsNoTracking();
|
||
var workshop = await _context.Workshops.AsNoTracking().FirstAsync(x => x.id == getCheckouts.First().WorkshopId);
|
||
var showSumOfPayments = workshop.TotalPaymentHide;
|
||
bool isLegal = employers.Any(x => x.IsLegal == "حقوقی");
|
||
|
||
var leftWorks = await _context.LeftWorkList.AsNoTracking()
|
||
.Where(x => x.WorkshopId == workshop.id).ToListAsync();
|
||
|
||
var result = getCheckouts.Select(x =>
|
||
{
|
||
var leftCheck = leftWorks
|
||
.FirstOrDefault(l =>
|
||
l.EmployeeId == x.EmployeeId && x.ContractStart >= l.StartWorkDate &&
|
||
x.ContractStart <= l.LeftWorkDate && l.HasLeft);
|
||
bool hasLeft = false;
|
||
var leftWorkDate = "";
|
||
var lastDayOfWork = "";
|
||
if (leftCheck != null)
|
||
{
|
||
var contractLeftWorkDate = x.ContractEnd.AddDays(1);
|
||
if (leftCheck.HasLeft && leftCheck.LeftWorkDate == contractLeftWorkDate)
|
||
{
|
||
hasLeft = true;
|
||
leftWorkDate = leftCheck.LeftWorkDate.ToFarsi();
|
||
lastDayOfWork = x.ContractEnd.ToFarsi();
|
||
}
|
||
}
|
||
|
||
var overTimeWorkValue = x.OvertimePay > 0 ? x.OverTimeWorkValue : "-";
|
||
var overNightWorkValue = x.NightworkPay > 0 ? x.OverNightWorkValue : "-";
|
||
var fridayWorkValue = x.FridayPay > 0 ? x.FridayWorkValue : "-";
|
||
var maritalStatus = employees.First(e => e.EmployeeId == x.EmployeeId).MaritalStatus;
|
||
var rewardPay = x.RewardPay == 0 ? "-" : x.RewardPay.ToMoney();
|
||
var rotatingShiftValue = x.ShiftPay > 0 ? x.RotatingShiftValue : "-";
|
||
var totalDeduction = "-";
|
||
var totalPayment = "-";
|
||
var totalClaims = "-";
|
||
if (showSumOfPayments)
|
||
{
|
||
totalDeduction = x.TotalDeductions;
|
||
totalPayment = x.TotalPayment.ToMoneyCheckZero();
|
||
totalClaims = x.TotalClaims;
|
||
}
|
||
|
||
List<CheckoutPrintRollCallDto> rollcalls = [];
|
||
TimeSpan TotalPresentTimeSpan;
|
||
TimeSpan TotalBreakTimeSpan;
|
||
TimeSpan TotalWorkingTimeSpan;
|
||
TimeSpan TotalPaidLeaveTmeSpan;
|
||
TimeSpan TotalMandatoryTimeSpan;
|
||
TimeSpan TotalSickLeaveTimeSpan;
|
||
if (x.CheckoutRollCall != null)
|
||
{
|
||
TotalMandatoryTimeSpan = x.CheckoutRollCall.TotalPresentTimeSpan;
|
||
TotalBreakTimeSpan = x.CheckoutRollCall.TotalBreakTimeSpan;
|
||
TotalWorkingTimeSpan = x.CheckoutRollCall.TotalWorkingTimeSpan;
|
||
TotalPaidLeaveTmeSpan = x.CheckoutRollCall.TotalPaidLeaveTmeSpan;
|
||
TotalMandatoryTimeSpan = x.CheckoutRollCall.TotalMandatoryTimeSpan;
|
||
TotalSickLeaveTimeSpan = x.CheckoutRollCall.TotalSickLeaveTimeSpan;
|
||
rollcalls = x.CheckoutRollCall.RollCallDaysCollection.Select(r => new CheckoutPrintRollCallDto()
|
||
{
|
||
DayOfWeek = r.Date.DayOfWeek.DayOfWeeKToPersian(),
|
||
StartDate1 = r.FirstStartDate,
|
||
EndDate1 = r.FirstEndDate,
|
||
StartDate2 = r.SecondStartDate,
|
||
EndDate2 = r.SecondEndDate,
|
||
IsSliced = r.IsSliced,
|
||
LeaveType = r.LeaveType,
|
||
IsAbsent = r.IsAbsent,
|
||
IsFriday = r.IsFriday,
|
||
IsHoliday = r.IsHoliday,
|
||
TotalWorkingHours = $"{(int)(r.WorkingTimeSpan.TotalHours)}:{r.WorkingTimeSpan.Minutes:00}",
|
||
BreakTimeString = $"{(int)(r.BreakTimeSpan.TotalHours)}:{r.BreakTimeSpan.Minutes:00}",
|
||
RollCallDateFa = r.Date.ToFarsi()
|
||
|
||
}).ToList();
|
||
}
|
||
else
|
||
{
|
||
|
||
// if (x.HasRollCall)
|
||
// x.MonthlyRollCall = _rollCallRepository.GetEmployeeRollCallsForMonth(x.EmployeeId, x.WorkshopId,
|
||
// x.ContractStartGr, x.ContractEndGr);
|
||
// else
|
||
// {
|
||
// x.CreateWorkingHoursTemp.ContractStartGr = x.ContractStartGr;
|
||
// x.CreateWorkingHoursTemp.ContractEndGr = x.ContractEndGr;
|
||
// x.CreateWorkingHoursTemp.ContarctStart = x.ContractStartGr.ToFarsi();
|
||
// x.CreateWorkingHoursTemp.ContractEnd = x.ContractEndGr.ToFarsi();
|
||
// x.CreateWorkingHoursTemp.EmployeeId = x.EmployeeId;
|
||
// x.CreateWorkingHoursTemp.WorkshopId = x.WorkshopId;
|
||
// x.MonthlyRollCall =
|
||
// ConvertStaticToRollCall(x.CreateWorkingHoursTemp,
|
||
// workshopName.WorkshopHolidayWorking);
|
||
// }
|
||
}
|
||
|
||
return new CheckoutPrintDto()
|
||
{
|
||
Id = x.id,
|
||
|
||
// هدر فیش
|
||
// اطلاعات هویتی
|
||
// اطلاعات کارگاه
|
||
|
||
#region Header
|
||
|
||
EmployeeFullName = x.EmployeeFullName,
|
||
FathersName = x.FathersName,
|
||
NationalCode = x.NationalCode,
|
||
DateOfBirth = x.DateOfBirth,
|
||
WorkshopName = workshop.WorkshopName,
|
||
ContractNo = x.ContractNo,
|
||
Month = x.Month,
|
||
Year = x.Year,
|
||
EmployersLists = employers,
|
||
EmployerIslegal = isLegal,
|
||
HasLeft = hasLeft,
|
||
LastDayOfWork = lastDayOfWork,
|
||
LeftWorkDate = leftWorkDate,
|
||
|
||
#endregion
|
||
|
||
//جدول مطالبات و کسورات
|
||
|
||
#region PaymentAndDeductionTable
|
||
|
||
//مطالبات
|
||
PaymentList =
|
||
[
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 1, Title = "حقوق و مزد", Value = $"{x.SumOfWorkingDays}",
|
||
Amount = x.MonthlySalary.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 2, Title = "پایه سنوات", Value = "-", Amount = x.BaseYearsPay.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 3, Title = "کمک هزینه اقلام مصرفی خانوار", Value = "-",
|
||
Amount = x.ConsumableItems.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 4, Title = "کمک هزینه مسکن", Value = "-",
|
||
Amount = x.HousingAllowance.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 5, Title = "فوق العاده اضافه کاری", Value = overTimeWorkValue,
|
||
Amount = x.OvertimePay.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 6, Title = "فوق العاده شب کاری", Value = overNightWorkValue,
|
||
Amount = x.NightworkPay.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 7, Title = "فوق العاده جمعه کاری", Value = fridayWorkValue,
|
||
Amount = x.FridayPay.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{ RowNumber = 8, Title = "فوق العاده ماموریت", Value = "-", Amount = "-", },
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 9, Title = "فوق العاده نوبت کاری", Value = rotatingShiftValue,
|
||
Amount = x.ShiftPay.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 10, Title = "کمک هزینه عائله مندی", Value = "-",
|
||
Amount = x.FamilyAllowance.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 11, Title = "حق تاهل", Value = maritalStatus,
|
||
Amount = x.MarriedAllowance.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{ RowNumber = 12, Title = "پاداش", Value = "-", Amount = rewardPay, },
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 13, Title = "عیدی و پاداش", Value = "-",
|
||
Amount = x.BonusesPay.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 14, Title = "سنوات", Value = "-",
|
||
Amount = x.YearsPay.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 15, Title = "مزد مرخصی", Value = "-",
|
||
Amount = x.LeavePay.ToMoneyCheckZero(),
|
||
}
|
||
],
|
||
|
||
//کسورات
|
||
DeductionList =
|
||
[
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 1, Title = "حق بیمه سهم کارگر", Value = "-",
|
||
Amount = x.InsuranceDeduction.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 2, Title = "مالیات بر حقوق", Value = "-",
|
||
Amount = x.TaxDeducation.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 3, Title = "قسط تسهیلات", Value = "-",
|
||
Amount = x.InstallmentDeduction.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{
|
||
RowNumber = 4, Title = "مساعده", Value = "-", Amount = x.SalaryAidDeduction.ToMoneyCheckZero(),
|
||
},
|
||
|
||
new PaymentAndDeductionList()
|
||
{ RowNumber = 5, Title = "غیبت", Value = "-", Amount = "-", }
|
||
],
|
||
|
||
TotalPayment = totalPayment,
|
||
TotalDeductions = totalDeduction,
|
||
TotalClaims = totalClaims,
|
||
|
||
#endregion
|
||
|
||
//لیست ورود و خروج پرسنل
|
||
//اطلاعات ساعات کار و موظقی
|
||
|
||
#region RollCallData
|
||
|
||
MonthlyRollCall =rollcalls,
|
||
#endregion
|
||
|
||
|
||
//اقساط - مساعده
|
||
|
||
#region SalaryAidAndInstallmentData
|
||
SalaryAids= x.SalaryAids.Select(s=> new CheckoutPrintSalaryAidDto()
|
||
{
|
||
Amount = s.Amount,
|
||
SalaryAidDateTimeFa = s.SalaryAidDateTimeFa,
|
||
}).ToList(),
|
||
|
||
Installments = x.LoanInstallments.Select(i=>new CheckoutPrintInstallmentDto()
|
||
{
|
||
Amount = i.AmountForMonth,
|
||
RemainingAmount = i.LoanRemaining,
|
||
LoanAmount = i.LoanAmount
|
||
}).ToList(),
|
||
|
||
|
||
#endregion
|
||
};
|
||
}).ToList();
|
||
|
||
Console.WriteLine("print : " + watch.Elapsed);
|
||
return result;
|
||
}
|
||
|
||
#endregion
|
||
} |