1441 lines
60 KiB
C#
1441 lines
60 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.CheckoutAgg;
|
|
using Company.Domain.LeftWorkAgg;
|
|
using Company.Domain.RollCallAgg;
|
|
using CompanyManagment.App.Contracts.Checkout;
|
|
using CompanyManagment.App.Contracts.Contract;
|
|
using CompanyManagment.App.Contracts.Employee;
|
|
using CompanyManagment.App.Contracts.Leave;
|
|
using CompanyManagment.App.Contracts.LeftWork;
|
|
using CompanyManagment.App.Contracts.WorkingHours;
|
|
using CompanyManagment.App.Contracts.WorkingHoursTemp;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using PersianTools.Core;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class CheckoutRepository : RepositoryBase<long, Checkout>, ICheckoutRepository
|
|
|
|
{
|
|
private readonly CompanyContext _context;
|
|
|
|
private readonly IEmployeeApplication _employeeApplication;
|
|
private readonly IWorkshopApplication _workshopApplication;
|
|
private readonly IContractApplication _contractApplication;
|
|
private readonly IWorkingHoursApplication _workingHoursApplication;
|
|
private readonly IWorkingHoursTempApplication _workingHoursTempApplication;
|
|
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ILeftWorkRepository _leftWorkRepository;
|
|
private readonly IRollCallRepository _rollCallRepository;
|
|
|
|
public CheckoutRepository(IEmployeeApplication employeeApplication, IWorkshopApplication workshopApplication,
|
|
IContractApplication contractApplication, IWorkingHoursApplication workingHoursApplication,
|
|
IAuthHelper authHelper, CompanyContext context, IConfiguration configuration, ILeftWorkRepository leftWorkRepository, IWorkingHoursTempApplication workingHoursTempApplication, IRollCallRepository rollCallRepository) : base(context)
|
|
{
|
|
_employeeApplication = employeeApplication;
|
|
_workshopApplication = workshopApplication;
|
|
_contractApplication = contractApplication;
|
|
_workingHoursApplication = workingHoursApplication;
|
|
_authHelper = authHelper;
|
|
_context = context;
|
|
_configuration = configuration;
|
|
_leftWorkRepository = leftWorkRepository;
|
|
_workingHoursTempApplication = workingHoursTempApplication;
|
|
_rollCallRepository = rollCallRepository;
|
|
}
|
|
|
|
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,
|
|
})
|
|
.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public void 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.ExecuteSqlInterpolated(
|
|
$"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}");
|
|
}
|
|
|
|
|
|
public async Task<List<CheckoutViewModel>> Search(CheckoutSearchModel searchModel)
|
|
{
|
|
List<CheckoutViewModel> query = null;
|
|
var connection = _configuration.GetConnectionString("MesbahDb");
|
|
//var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
var AcountID = _authHelper.CurrentAccountId();
|
|
var workshopAcounts = _context.WorkshopAccounts.Where(x => x.AccountId == AcountID)
|
|
.Select(x => x.WorkshopId).ToList();
|
|
//Console.WriteLine("acID.. " + watch.Elapsed);
|
|
|
|
//var watchmp = System.Diagnostics.Stopwatch.StartNew();
|
|
var emp = _context.WorkshopEmployers.Where(x => workshopAcounts.Contains(x.WorkshopId))
|
|
.Select(x => x.EmployerId);
|
|
var emp2 = _context.WorkshopEmployers.Where(x => x.EmployerId == searchModel.EmployerId)
|
|
.Select(x => x.WorkshopId).ToList();
|
|
|
|
//Console.WriteLine("emp.. " + watchmp.Elapsed);
|
|
//var employerlist = _context.Employers.Where(x => emp.Contains(x.id)).ToList();
|
|
|
|
|
|
//var stored = _context.CheckoutSet.FromSqlInterpolated($"SelectQuery_AllChekouts2").AsNoTracking()
|
|
// .ToList();
|
|
//var watchusing = System.Diagnostics.Stopwatch.StartNew();
|
|
using (var conn = new SqlConnection(connection))
|
|
{
|
|
await conn.OpenAsync();
|
|
|
|
var command = new SqlCommand("ChekoutMainList", conn);
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
|
|
|
|
using (var reader = await command.ExecuteReaderAsync())
|
|
{
|
|
query = new List<CheckoutViewModel>();
|
|
|
|
while (await reader.ReadAsync())
|
|
{
|
|
var item = new CheckoutViewModel();
|
|
|
|
item.Id = (long) reader["Id"];
|
|
item.EmployeeFullName = (string) reader?["EmployeeFullName"];
|
|
var start = (DateTime) reader["ContractStart"];
|
|
item.ContractStart = start.ToFarsi();
|
|
var end = (DateTime) reader["ContractEnd"];
|
|
item.ContractEnd = end.ToFarsi();
|
|
item.ContractStartGr = start;
|
|
item.ContractEndGr = end;
|
|
item.PersonnelCode = (string) reader?["PersonnelCode"];
|
|
item.PersonnelCodeInt = item.PersonnelCode.ConvertToInt();
|
|
item.ArchiveCode = (string) reader?["ArchiveCode"];
|
|
item.SumOfWorkingDays = (string) reader?["SumOfWorkingDays"];
|
|
item.WorkshopName = (string) reader?["WorkshopName"];
|
|
item.Month = reader["Month"] != DBNull.Value ? (string) reader["Month"] : null;
|
|
item.Year = reader["Year"] != DBNull.Value ? (string) reader["Year"] : null;
|
|
item.ContractNo = (string) reader?["ContractNo"];
|
|
item.ContractId = (long) reader["ContractId"];
|
|
item.WorkshopId = (long) reader["WorkshopId"];
|
|
item.EmployeeId = (long) reader["EmployeeId"];
|
|
item.IsActiveString = (string) reader["IsActiveString"];
|
|
item.Signature = (string) reader["Signature"];
|
|
item.CreationDate = (DateTime) reader["CreationDate"];
|
|
|
|
|
|
query.Add(item);
|
|
}
|
|
}
|
|
}
|
|
//Console.WriteLine("using.. " + watchusing.Elapsed);
|
|
//var query = stored.Select(x => new CheckoutViewModel()
|
|
//{
|
|
// Id = x.id,
|
|
// EmployeeFullName = x.EmployeeFullName,
|
|
// ContractStart = x.ContractStart.ToFarsi(),
|
|
// ContractEnd = x.ContractEnd.ToFarsi(),
|
|
// ContractStartGr = x.ContractStart,
|
|
// ContractEndGr = x.ContractEnd,
|
|
// PersonnelCode = x.PersonnelCode,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// SumOfWorkingDays = x.SumOfWorkingDays,
|
|
// WorkshopName = x.WorkshopName,
|
|
// Month = x.Month,
|
|
// Year = x.Year,
|
|
// ContractNo = x.ContractNo,
|
|
// ContractId = x.ContractId,
|
|
// WorkshopId = x.WorkshopId,
|
|
// EmployeeId = x.EmployeeId,
|
|
|
|
// IsActiveString = x.IsActiveString,
|
|
// Signature = x.Signature,
|
|
// CreationDate = x.CreationDate
|
|
//});
|
|
|
|
//var watchif = System.Diagnostics.Stopwatch.StartNew();
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo) && searchModel.ContractId != 0)
|
|
query = query.Where(x =>
|
|
x.ContractNo == searchModel.ContractNo && x.ContractId == searchModel.ContractId).ToList();
|
|
if (searchModel.WorkshopId != 0)
|
|
query = query.Where(x => x.WorkshopId == searchModel.WorkshopId).ToList();
|
|
if (searchModel.EmployeeId != 0)
|
|
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId).ToList();
|
|
if (searchModel.EmployerId != 0)
|
|
{
|
|
query = query.Where(x => emp2.Contains(x.WorkshopId)).ToList();
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo))
|
|
query = query.Where(x => x.ContractNo == searchModel.ContractNo).ToList();
|
|
|
|
|
|
if (searchModel.IsActiveString == null)
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "true").ToList();
|
|
}
|
|
|
|
if (searchModel.IsActiveString == "false")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false").ToList();
|
|
}
|
|
else if (searchModel.IsActiveString == "both")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false" || x.IsActiveString == "true").ToList();
|
|
}
|
|
|
|
query = query.Where(e => workshopAcounts.Contains(e.WorkshopId)).ToList();
|
|
//سرچ سال
|
|
if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month) &&
|
|
(string.IsNullOrWhiteSpace(searchModel.ContractStart) ||
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd)))
|
|
{
|
|
var startYear = searchModel.Year + "/01/01";
|
|
var startyearGr = startYear.ToGeorgianDateTime();
|
|
var endYear = $"{searchModel.Year}/12/01".FindeEndOfMonth();
|
|
var endYearGr = endYear.ToGeorgianDateTime();
|
|
|
|
|
|
query = query.Where(x => x.ContractStartGr >= startyearGr && x.ContractEndGr <= endYearGr).ToList();
|
|
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
|
|
return query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt).ToList();
|
|
|
|
|
|
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) &&
|
|
string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
|
|
string.IsNullOrWhiteSpace(searchModel.ContractEnd))
|
|
{
|
|
//سرچ سال و ماه
|
|
string y1 = $"{searchModel.Year}/{searchModel.Month}/01";
|
|
var startDate = y1.ToGeorgianDateTime();
|
|
string y2 = string.Empty;
|
|
int month = Convert.ToInt32(searchModel.Month);
|
|
int year = Convert.ToInt32(searchModel.Year);
|
|
|
|
if (month <= 6)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/31";
|
|
}
|
|
else if (month > 6 && month < 12)
|
|
{
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
}
|
|
else if (month == 12)
|
|
{
|
|
switch (year)
|
|
{
|
|
case 1346:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1350:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1354:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1358:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1362:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1366:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1370:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1375:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1379:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1383:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1387:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1391:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1395:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1399:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1403:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1408:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1412:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1416:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1420:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1424:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1428:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1432:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1436:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1441:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
case 1445:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/30";
|
|
break;
|
|
|
|
default:
|
|
y2 = $"{searchModel.Year}/{searchModel.Month}/29";
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
var endDate = y2.ToGeorgianDateTime();
|
|
|
|
//query = query.Where(x => x.ContractEndGr >= start && x.ContractEndGr <= end).ToList();
|
|
query = query.Where(x =>
|
|
x.ContractStartGr >= startDate && x.ContractStartGr < endDate && x.ContractEndGr > startDate &&
|
|
x.ContractEndGr <= endDate ||
|
|
x.ContractStartGr <= startDate && x.ContractEndGr >= endDate ||
|
|
startDate <= x.ContractStartGr && endDate > x.ContractStartGr ||
|
|
endDate >= x.ContractEndGr && startDate < x.ContractEndGr).ToList();
|
|
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
|
|
return query.OrderBy(x => x.PersonnelCodeInt).ToList();
|
|
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.ContractEnd) &&
|
|
string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month))
|
|
{
|
|
//سرچ تاریخ
|
|
var start = searchModel.ContractStart.ToGeorgianDateTime();
|
|
var endd = searchModel.ContractEnd.ToGeorgianDateTime();
|
|
query = query.Where(x =>
|
|
x.ContractStartGr >= start && x.ContractEndGr <= endd).ToList();
|
|
|
|
if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0)
|
|
return query.OrderByDescending(x => x.ContractEndGr).ThenBy(x => x.PersonnelCodeInt).ToList();
|
|
|
|
}
|
|
|
|
return query.OrderByDescending(x => x.Id)
|
|
.ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).Take(100).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//foreach(var items in query)
|
|
//{
|
|
// var employeId = _context.WorkshopEmployers?.Where(x => x.WorkshopId == items.WorkshopId)
|
|
// .Select(x => x.EmployerId).FirstOrDefault();
|
|
// var employerName = _context.Employers?.FirstOrDefault(x => x.id == employeId).FullName;
|
|
// items.EmployerName = employerName;
|
|
//}
|
|
//Console.WriteLine("SearchModel.. " + watchif.Elapsed);
|
|
//if (searchModel.EmployeeId != 0 || !string.IsNullOrWhiteSpace(searchModel.Year) && searchModel.WorkshopId != 0)
|
|
//{
|
|
// if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month))
|
|
// {
|
|
// var startOfYear = searchModel.Year + "/01/01";
|
|
// var startOfyearGr = startOfYear.ToGeorgianDateTime();
|
|
// var endOfYear = $"{searchModel.Year}/12/01".FindeEndOfMonth();
|
|
// var endOfYearGr = endOfYear.ToGeorgianDateTime();
|
|
|
|
|
|
// query = query.Where(x => x.ContractStartGr >= startOfyearGr && x.ContractEndGr <= endOfYearGr).ToList();
|
|
// }
|
|
// return query.OrderBy(x => x.PersonnelCode).ToList();
|
|
//}
|
|
}
|
|
|
|
public List<CheckoutViewModel> SimpleSearch(CheckoutSearchModel searchModel)
|
|
{
|
|
var query = _context.CheckoutSet.Select(x => new CheckoutViewModel()
|
|
{
|
|
Id = x.id,
|
|
EmployeeId = x.EmployeeId,
|
|
WorkshopId = x.WorkshopId,
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
ContractStart = x.ContractStart.ToFarsi(),
|
|
ContractEnd = x.ContractEnd.ToFarsi(),
|
|
Signature = x.Signature,
|
|
Year = x.Year,
|
|
Month = x.Month,
|
|
ContractNo = x.ContractNo,
|
|
ContractId = x.ContractId,
|
|
HasRollCall = x.HasRollCall
|
|
|
|
});
|
|
|
|
if (searchModel.EmployeeId != 0 && searchModel.WorkshopId != 0)
|
|
query = query.Where(x =>
|
|
x.EmployeeId == searchModel.EmployeeId && x.WorkshopId == searchModel.WorkshopId);
|
|
if (searchModel.EmployeeId == 0 && searchModel.WorkshopId != 0)
|
|
query = query.Where(x => x.WorkshopId == searchModel.WorkshopId);
|
|
if (searchModel.EmployeeId != 0 && searchModel.WorkshopId == 0)
|
|
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractNo) && searchModel.ContractId > 0)
|
|
query = query.Where(x => x.ContractNo == searchModel.ContractNo);
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.ContractEnd) &&
|
|
(searchModel.EmployeeId != 0 && searchModel.WorkshopId != 0))
|
|
{
|
|
var start = searchModel.ContractStart.ToGeorgianDateTime();
|
|
var end = searchModel.ContractEnd.ToGeorgianDateTime();
|
|
query = query.Where(x => x.ContractStartGr == start && x.ContractEndGr == end && x.EmployeeId == searchModel.EmployeeId && x.WorkshopId == searchModel.WorkshopId);
|
|
}
|
|
|
|
return query.OrderBy(x => x.ContractStartGr).ToList();
|
|
|
|
}
|
|
|
|
public List<CheckoutViewModel> PrintAll(List<long> id)
|
|
{
|
|
var query = new List<CheckoutViewModel>();
|
|
foreach (var item in id)
|
|
{
|
|
var ch = _context.CheckoutSet.Select(x => new CheckoutViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
ContractId = x.ContractId,
|
|
EmployeeId = x.EmployeeId,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
FathersName = x.FathersName,
|
|
NationalCode = x.NationalCode,
|
|
DateOfBirth = x.DateOfBirth,
|
|
WorkshopName = x.WorkshopName,
|
|
Month = x.Month,
|
|
Year = x.Year,
|
|
PersonnelCode = x.PersonnelCode,
|
|
PersonnelCodeInt = Convert.ToInt32(x.PersonnelCode),
|
|
ContractNo = x.ContractNo,
|
|
MonthlySalary = x.MonthlySalary.ToMoney(),
|
|
BaseYearsPay = x.BaseYearsPay.ToMoney(),
|
|
ConsumableItems = x.ConsumableItems.ToMoney(),
|
|
HousingAllowance = x.HousingAllowance.ToMoney(),
|
|
OvertimePay = x.OvertimePay.ToMoney(),
|
|
NightworkPay = x.NightworkPay.ToMoney(),
|
|
FridayPay = x.FridayPay.ToMoney(),
|
|
MissionPay = x.MissionPay.ToMoney(),
|
|
ShiftPay = x.ShiftPay.ToMoney(),
|
|
FamilyAllowance = x.FamilyAllowance.ToMoney(),
|
|
BonusesPay = x.BonusesPay.ToMoney(),
|
|
YearsPay = x.YearsPay.ToMoney(),
|
|
LeavePay = x.LeavePay.ToMoney(),
|
|
InsuranceDeduction = x.InsuranceDeduction.ToMoney(),
|
|
TaxDeducation = x.TaxDeducation.ToMoney(),
|
|
InstallmentDeduction = x.InstallmentDeduction.ToMoney(),
|
|
SalaryAidDeduction = x.SalaryAidDeduction.ToMoney(),
|
|
AbsenceDeduction = x.AbsenceDeduction.ToMoney(),
|
|
TotalClaims = x.TotalClaims,
|
|
TotalDeductions = x.TotalDeductions,
|
|
TotalPayment = x.TotalPayment.ToMoney(),
|
|
RewardPay = x.RewardPay.ToMoneyNullable(),
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
IsLeft = false,
|
|
LeftWorkDate = "",
|
|
LastDayOfWork = "",
|
|
MarriedAllowance = x.MarriedAllowance.ToMoney(),
|
|
HasRollCall = x.HasRollCall,
|
|
SumOfWorkingDays = x.SumOfWorkingDays,
|
|
OverTimeWorkValue = x.OverTimeWorkValue,
|
|
OverNightWorkValue = x.OverNightWorkValue,
|
|
FridayWorkValue = x.FridayWorkValue,
|
|
RotatingShiftValue = x.RotatingShiftValue,
|
|
AbsenceValue = x.AbsenceValue,
|
|
MaritalStatus = "",
|
|
TotalDayOfLeaveCompute = x.TotalDayOfLeaveCompute,
|
|
TotalDayOfYearsCompute = x.TotalDayOfYearsCompute,
|
|
TotalDayOfBunosesCompute = x.TotalDayOfBunosesCompute
|
|
|
|
}).SingleOrDefault(x => x.Id == item);
|
|
var workshopName = _context.Workshops.FirstOrDefault(x => x.id == ch.WorkshopId);
|
|
ch.WorkshopName = workshopName.WorkshopName;
|
|
ch.TotalPaymentHide = workshopName.TotalPaymentHide;
|
|
var emp = _context.WorkshopEmployers.Where(x => x.WorkshopId == ch.WorkshopId)
|
|
.Select(x => x.EmployerId);
|
|
var employerlist = _context.Employers.Where(x => emp.Contains(x.id));
|
|
var employers = new List<EmprViewModel>();
|
|
|
|
foreach (var em in employerlist)
|
|
{
|
|
var employer = new EmprViewModel()
|
|
{
|
|
EmployerFullName = em.FName + " " + em.LName,
|
|
IsLegal = em.IsLegal,
|
|
};
|
|
employers.Add(employer);
|
|
}
|
|
|
|
ch.MaritalStatus = _context.Employees.Find(ch.EmployeeId)?.MaritalStatus;
|
|
ch.EmployerList = employers;
|
|
var workingHours = _workingHoursTempApplication.GetByContractIdConvertToShiftwork4(ch.ContractId);
|
|
ch.CreateWorkingHoursTemp = workingHours;
|
|
var AbsenceDeduction = ch.AbsenceDeduction.MoneyToDouble();
|
|
var InstallmentDeduction = ch.InstallmentDeduction.MoneyToDouble();
|
|
var InsuranceDeduction = ch.InsuranceDeduction.MoneyToDouble();
|
|
var SalaryAidDeduction = ch.SalaryAidDeduction.MoneyToDouble();
|
|
var TaxDeducation = ch.TaxDeducation.MoneyToDouble();
|
|
var TotalDeduction = AbsenceDeduction + InsuranceDeduction + InstallmentDeduction + SalaryAidDeduction +
|
|
TaxDeducation;
|
|
ch.TotalDeductions = TotalDeduction.ToMoney();
|
|
|
|
|
|
var leftWorkSearch = new LeftWorkSearchModel() { WorkshopId = ch.WorkshopId, EmployeeId = ch.EmployeeId };
|
|
var leftworkResult = _leftWorkRepository.search(leftWorkSearch).FirstOrDefault();
|
|
var leftCheck = _leftWorkRepository.CheckoutleftWorkCheck(ch.ContractStartGr, ch.WorkshopId, ch.EmployeeId);
|
|
var contractLeftWorkDate = ch.ContractEndGr.AddDays(1);
|
|
if (leftCheck != null && leftCheck.LeftWorkDateGr == contractLeftWorkDate)
|
|
{
|
|
ch.IsLeft = true;
|
|
ch.LeftWorkDate = leftCheck.LeftWorkDate;
|
|
ch.LastDayOfWork = ch.ContractEndGr.ToFarsi();
|
|
}
|
|
//var checkBonusesPay = leftworkResult != null && leftworkResult.AddBonusesPay;
|
|
//var checkYearsPay = leftworkResult != null && leftworkResult.AddYearsPay;
|
|
//var checkLeavePay = leftworkResult != null && leftworkResult.AddLeavePay;
|
|
|
|
//if (!checkBonusesPay || !checkYearsPay || !checkLeavePay)
|
|
//{
|
|
// double sumOfBonusAndYearsPay = 0;
|
|
// if (!checkBonusesPay)
|
|
// {
|
|
// var bonusesPay = ch.BonusesPay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += bonusesPay;
|
|
// ch.BonusesPay = "0";
|
|
|
|
// }
|
|
|
|
// if (!checkYearsPay)
|
|
// {
|
|
// var yearsPay = ch.YearsPay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += yearsPay;
|
|
// ch.YearsPay = "0";
|
|
// }
|
|
|
|
// if (!checkLeavePay)
|
|
// {
|
|
// var leavePay = ch.LeavePay.MoneyToDouble();
|
|
// sumOfBonusAndYearsPay += leavePay;
|
|
// ch.LeavePay = "0";
|
|
// }
|
|
// var totalClaimsDouble = ch.TotalClaims.MoneyToDouble();
|
|
// var totalClaims = totalClaimsDouble - sumOfBonusAndYearsPay;
|
|
// ch.TotalClaims = totalClaims.ToMoney();
|
|
|
|
// var totalPayment = totalClaims - TotalDeduction;
|
|
// ch.TotalPayment = totalPayment.ToMoney();
|
|
|
|
|
|
//}
|
|
|
|
//if (ch.WorkshopId == 40 || ch.WorkshopId == 68 || ch.WorkshopId == 44 || ch.WorkshopId == 45 || ch.WorkshopId == 280)
|
|
//{
|
|
// ch.TotalClaims = "";
|
|
// ch.TotalDeductions = "";
|
|
// ch.TotalPayment = "";
|
|
//}
|
|
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);
|
|
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.Select(x => new CheckoutViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
ContractId = x.ContractId,
|
|
EmployeeId = x.EmployeeId,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
FathersName = x.FathersName,
|
|
NationalCode = x.NationalCode,
|
|
DateOfBirth = x.DateOfBirth,
|
|
WorkshopName = x.WorkshopName,
|
|
Month = x.Month,
|
|
Year = x.Year,
|
|
ContractNo = x.ContractNo,
|
|
MonthlySalary = x.MonthlySalary.ToMoney(),
|
|
BaseYearsPay = x.BaseYearsPay.ToMoney(),
|
|
ConsumableItems = x.ConsumableItems.ToMoney(),
|
|
HousingAllowance = x.HousingAllowance.ToMoney(),
|
|
OvertimePay = x.OvertimePay.ToMoney(),
|
|
NightworkPay = x.NightworkPay.ToMoney(),
|
|
FridayPay = x.FridayPay.ToMoney(),
|
|
MissionPay = x.MissionPay.ToMoney(),
|
|
ShiftPay = x.ShiftPay.ToMoney(),
|
|
FamilyAllowance = x.FamilyAllowance.ToMoney(),
|
|
BonusesPay = x.BonusesPay.ToMoney(),
|
|
YearsPay = x.YearsPay.ToMoney(),
|
|
LeavePay = x.LeavePay.ToMoney(),
|
|
InsuranceDeduction = x.InsuranceDeduction.ToMoney(),
|
|
TaxDeducation = x.TaxDeducation.ToMoney(),
|
|
InstallmentDeduction = x.InstallmentDeduction.ToMoney(),
|
|
SalaryAidDeduction = x.SalaryAidDeduction.ToMoney(),
|
|
AbsenceDeduction = x.AbsenceDeduction.ToMoney(),
|
|
TotalClaims = x.TotalClaims,
|
|
TotalDeductions = x.TotalDeductions,
|
|
TotalPayment = x.TotalPayment.ToMoney(),
|
|
RewardPay = x.RewardPay.ToMoneyNullable(),
|
|
ContractStartGr = x.ContractStart,
|
|
ContractEndGr = x.ContractEnd,
|
|
IsLeft = false,
|
|
LeftWorkDate = "",
|
|
LastDayOfWork = "",
|
|
MarriedAllowance = x.MarriedAllowance.ToMoney(),
|
|
HasRollCall = x.HasRollCall,
|
|
SumOfWorkingDays = x.SumOfWorkingDays,
|
|
OverTimeWorkValue = x.OverTimeWorkValue,
|
|
OverNightWorkValue = x.OverNightWorkValue,
|
|
FridayWorkValue = x.FridayWorkValue,
|
|
RotatingShiftValue = x.RotatingShiftValue,
|
|
AbsenceValue = x.AbsenceValue,
|
|
MaritalStatus = "",
|
|
TotalDayOfLeaveCompute = x.TotalDayOfLeaveCompute,
|
|
TotalDayOfYearsCompute = x.TotalDayOfYearsCompute,
|
|
TotalDayOfBunosesCompute = x.TotalDayOfBunosesCompute
|
|
|
|
|
|
}).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 = "";
|
|
//}
|
|
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);
|
|
|
|
return ch;
|
|
}
|
|
|
|
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.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),
|
|
|
|
}).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>> 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 watch = System.Diagnostics.Stopwatch.StartNew();
|
|
|
|
|
|
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,
|
|
|
|
|
|
});
|
|
|
|
|
|
Console.WriteLine("storedProc" + watch.Elapsed);
|
|
|
|
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.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();
|
|
}
|
|
|
|
#endregion
|
|
} |