2318 lines
106 KiB
C#
2318 lines
106 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.Application;
|
|
using AccountMangement.Infrastructure.EFCore;
|
|
using Company.Domain.ReportAgg;
|
|
using Company.Domain.WorkshopEmployerAgg;
|
|
using CompanyManagment.App.Contracts.LeftWork;
|
|
using CompanyManagment.App.Contracts.Report;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PersianTools.Core;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class ReportRepository : IReportRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
private readonly AccountContext _accountContext;
|
|
|
|
public ReportRepository(CompanyContext context, AccountContext accountContext)
|
|
{
|
|
_context = context;
|
|
_accountContext = accountContext;
|
|
}
|
|
|
|
//public AllReport getAll(string year, string month)
|
|
//{
|
|
|
|
// var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
// //یافتن آغاز و پایان ماه جاری
|
|
// //یافتن آغاز و پایان ماه بعد
|
|
// #region FindMonthStartAndEnd
|
|
|
|
// string nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
|
|
// if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
// nowFa = $"{year}/{month}/01";
|
|
|
|
|
|
// var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
// //شروع ماه جاری
|
|
// var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
// // پایان کاه جاری
|
|
// var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
|
|
|
|
|
|
// int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
// var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
// var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
|
|
// //شروع ماه بعد
|
|
// var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
// //پایان ماه بعد
|
|
// var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
// #endregion
|
|
|
|
// // کاهش درخواستهای تکراری به پایگاه داده
|
|
// var checkoutAccountLeftWorks = _accountContext.AccountLeftWorks
|
|
// .Where(x => x.RoleId == 5 && x.StartWorkGr < currentMonthEnd && x.LeftWorkGr > currentMonthStart)
|
|
// .Select(x => new { x.WorkshopId, x.AccountId }).ToList();
|
|
|
|
// var allCheckoutAccountLeftWorkWorkshopIds = checkoutAccountLeftWorks.Select(x => x.WorkshopId).Distinct().ToList();
|
|
|
|
// var checkoutWorkshopEmployer = _context.WorkshopEmployers
|
|
// .Where(x => allCheckoutAccountLeftWorkWorkshopIds.Contains(x.WorkshopId))
|
|
// .Include(x => x.Employer.ContractingParty)
|
|
// .Where(x => x.Employer.ContractingParty.IsBlock != "true" && x.Employer.ContractingParty.IsActiveString == "true" && x.Workshop.IsActiveString == "true")
|
|
// .ToList();
|
|
|
|
// var checkoutWithOutInstitutionContract = checkoutWorkshopEmployer
|
|
// .Where(x => x.Employer.ContractingPartyId == 30428)
|
|
// .Select(x => x.WorkshopId)
|
|
// .ToList();
|
|
|
|
// var checkoutFindHasInstitutionContract = _context.InstitutionContractSet
|
|
// .Where(c => c.ContractStartGr <= currentMonthStart && c.ContractEndGr >= currentMonthEnd)
|
|
// .Select(c => c.ContractingPartyId)
|
|
// .ToHashSet();
|
|
|
|
// var checkoutWithInstitutionContract = checkoutWorkshopEmployer
|
|
// .Where(x => x.Employer.ContractingPartyId != 30428 && checkoutFindHasInstitutionContract.Contains(x.Employer.ContractingPartyId))
|
|
// .Select(x => x.WorkshopId)
|
|
// .Distinct()
|
|
// .ToList();
|
|
|
|
// var checkoutMixWitAndWitOut = checkoutWithInstitutionContract.Concat(checkoutWithOutInstitutionContract).Distinct().ToList();
|
|
|
|
// var allCheckoutLeftworks = _context.LeftWorkList
|
|
// .Where(x => checkoutMixWitAndWitOut.Contains(x.WorkshopId) && x.StartWorkDate <= currentMonthEnd && x.LeftWorkDate > currentMonthStart)
|
|
// .Select(x => x.EmployeeId)
|
|
// .ToHashSet();
|
|
|
|
// var allCheckoutCreated = _context.CheckoutSet
|
|
// .Where(x => allCheckoutLeftworks.Contains(x.EmployeeId) && x.ContractStart.Date >= currentMonthStart.Date && x.ContractEnd.Date <= currentMonthEnd.Date && x.IsActiveString == "true")
|
|
// .ToList();
|
|
|
|
// var allCheckoutSigned = allCheckoutCreated.Count(x => x.Signature == "1");
|
|
|
|
// // بهینهسازی و کاهش پردازشهای اضافی
|
|
// var checkoutPercent = allCheckoutLeftworks.Count > 0 ? (allCheckoutCreated.Count * 100) / allCheckoutLeftworks.Count : 0;
|
|
// var checkoutSignaturePercent = allCheckoutCreated.Count > 0 ? (allCheckoutSigned * 100) / allCheckoutCreated.Count : 0;
|
|
|
|
// return new AllReport
|
|
// {
|
|
// CheckoutPercent = checkoutPercent,
|
|
// CheckoutSignaturePercent = checkoutSignaturePercent,
|
|
// // سایر فیلدهای موردنیاز
|
|
// };
|
|
|
|
//}
|
|
|
|
//public async Task<AllReport> GetAllActiveWorkshopsNew(string year, string month)
|
|
//{
|
|
// var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
|
|
// // Parse the start and end dates for the current and next months
|
|
// #region FindMonthStartAndEnd
|
|
|
|
// string nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
|
|
// if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
// nowFa = $"{year}/{month}/01";
|
|
|
|
|
|
// var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
// //شروع ماه جاری
|
|
// var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
// // پایان کاه جاری
|
|
// var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
|
|
|
|
|
|
// int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
// var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
// var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
|
|
// //شروع ماه بعد
|
|
// var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
// //پایان ماه بعد
|
|
// var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
// #endregion
|
|
|
|
// // Preload data to reduce database calls
|
|
// var accountLeftWorks = await _accountContext.AccountLeftWorks
|
|
// .Where(x => x.RoleId == 5)
|
|
// .ToListAsync();
|
|
|
|
// var leftWorkList = await _context.LeftWorkList
|
|
// .Where(x => x.StartWorkDate <= nextMonthEnd && x.LeftWorkDate > currentMonthStart)
|
|
// .ToListAsync();
|
|
|
|
// var institutionContracts = await _context.InstitutionContractSet
|
|
// .Where(c => c.ContractStartGr <= nextMonthEnd && c.ContractEndGr >= currentMonthStart)
|
|
// .ToListAsync();
|
|
|
|
// var accounts = await _accountContext.Accounts
|
|
// .Where(x => x.RoleId == 5)
|
|
// .ToListAsync();
|
|
|
|
// // Filter workshops
|
|
// var activeWorkshops = await _context.WorkshopEmployers
|
|
// .Include(x => x.Workshop)
|
|
// .Include(x => x.Employer.ContractingParty)
|
|
// .Where(x => x.Workshop.IsActiveString == "true" &&
|
|
// x.Employer.ContractingParty.IsActiveString == "true" &&
|
|
// x.Employer.ContractingParty.IsBlock != "true")
|
|
// .ToListAsync();
|
|
|
|
// // Group workshops by contract type
|
|
// var workshopsWithContracts = activeWorkshops
|
|
// .Where(x => institutionContracts.Any(c => c.ContractingPartyId == x.Employer.ContractingPartyId))
|
|
// .Select(x => x.WorkshopId)
|
|
// .Distinct()
|
|
// .ToList();
|
|
|
|
// var workshopsWithoutContracts = activeWorkshops
|
|
// .Where(x => x.Employer.ContractingPartyId == 30428)
|
|
// .Select(x => x.WorkshopId)
|
|
// .Distinct()
|
|
// .ToList();
|
|
|
|
// var allWorkshops = workshopsWithContracts.Concat(workshopsWithoutContracts).Distinct().ToList();
|
|
|
|
// // Calculate left works and contracts
|
|
// var leftWorks = leftWorkList
|
|
// .Where(x => allWorkshops.Contains(x.WorkshopId))
|
|
// .ToList();
|
|
|
|
// var leftWorkEmployeeIds = leftWorks.Select(x => x.EmployeeId).ToHashSet();
|
|
|
|
// var contracts = await _context.Contracts
|
|
// .Where(x => leftWorkEmployeeIds.Contains(x.EmployeeId) &&
|
|
// x.ContarctStart.Date <= nextMonthEnd.Date &&
|
|
// x.ContractEnd.Date > nextMonthStart.Date &&
|
|
// x.IsActiveString == "true")
|
|
// .ToListAsync();
|
|
|
|
// var signedContracts = contracts.Count(x => x.Signature == "1");
|
|
|
|
// // Calculate checkouts
|
|
// var checkouts = await _context.CheckoutSet
|
|
// .Where(x => leftWorkEmployeeIds.Contains(x.EmployeeId) &&
|
|
// x.ContractStart.Date >= currentMonthStart.Date &&
|
|
// x.ContractEnd.Date <= currentMonthEnd.Date &&
|
|
// x.IsActiveString == "true")
|
|
// .ToListAsync();
|
|
|
|
// var signedCheckouts = checkouts.Count(x => x.Signature == "1");
|
|
|
|
// // Calculate percentages
|
|
// var contractToBe = leftWorks.Count;
|
|
// var createdContracts = contracts.Count;
|
|
// var checkoutToBe = leftWorks.Count;
|
|
// var createdCheckouts = checkouts.Count;
|
|
|
|
// var contractPercent = contractToBe > 0 ? (createdContracts * 100) / contractToBe : 0;
|
|
// var contractSignaturePercent = createdContracts > 0 ? (signedContracts * 100) / createdContracts : 0;
|
|
// var checkoutPercent = checkoutToBe > 0 ? (createdCheckouts * 100) / checkoutToBe : 0;
|
|
// var checkoutSignaturePercent = createdCheckouts > 0 ? (signedCheckouts * 100) / createdCheckouts : 0;
|
|
|
|
// // Prepare the final result
|
|
// var finalResult = new AllReport
|
|
// {
|
|
// AllPercent = (contractPercent + contractSignaturePercent + checkoutPercent + checkoutSignaturePercent) / 4,
|
|
// ContractPercent = contractPercent,
|
|
// ContractSignaturePercent = contractSignaturePercent,
|
|
// CheckoutPercent = checkoutPercent,
|
|
// CheckoutSignaturePercent = checkoutSignaturePercent,
|
|
// Year = $"{currentMonthStart.Year}",
|
|
// Month = nowFa.Substring(5, 2),
|
|
// AllContract = contractToBe,
|
|
// ContractNotDone = contractToBe - createdContracts,
|
|
// ContrcatDone = createdContracts,
|
|
// ContractSignNotDone = createdContracts - signedContracts,
|
|
// ContractSignDone = signedContracts,
|
|
// AllCheckout = checkoutToBe,
|
|
// CheckoutNotDone = checkoutToBe - createdCheckouts,
|
|
// CheckoutDone = createdCheckouts,
|
|
// CheckoutSignDone = signedCheckouts,
|
|
// CheckoutSignNotDone = createdCheckouts - signedCheckouts
|
|
// };
|
|
|
|
// Console.WriteLine("Optimized method execution time: " + watch.Elapsed);
|
|
// return finalResult;
|
|
//}
|
|
|
|
|
|
public Task<AllReport> GetAllActiveWorkshopsNew(string year, string month)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
//یافتن آغاز و پایان ماه جاری
|
|
//یافتن آغاز و پایان ماه بعد
|
|
#region FindMonthStartAndEnd
|
|
|
|
string nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
nowFa = $"{year}/{month}/01";
|
|
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
//شروع ماه جاری
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
// پایان کاه جاری
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
|
|
|
|
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
|
|
//شروع ماه بعد
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
//پایان ماه بعد
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
#endregion
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
Console.WriteLine("========================== 1403/12/01 - 1403/12/30 ==========================");
|
|
|
|
|
|
//var allLeft = _context.LeftWorkList
|
|
|
|
|
|
#region checkout
|
|
//یاتن اکانتهای قراداد ساده
|
|
var checkoutAccountLeftWorks = _accountContext.AccountLeftWorks
|
|
.Where(x => x.RoleId == 5)
|
|
.Where(x => x.StartWorkGr < currentMonthEnd && x.LeftWorkGr > currentMonthStart);
|
|
|
|
var allCheckoutAccountLeftWorkWorkshopIds = checkoutAccountLeftWorks.Select(x => x.WorkshopId).ToList();
|
|
|
|
//یافتن کارگاه هایی که فعال هستند و طرف حساب انها فعال است
|
|
var checkoutWorkshopEmployer = _context.WorkshopEmployers
|
|
.Where(x => allCheckoutAccountLeftWorkWorkshopIds.Contains(x.WorkshopId))
|
|
.Include(x => x.Workshop)
|
|
.Include(x => x.Employer)
|
|
.ThenInclude(x => x.ContractingParty)
|
|
.Where(x => x.Employer.ContractingParty.IsBlock != "true" && x.Employer.ContractingParty.IsActiveString == "true")
|
|
.Where(x => x.Workshop.IsActiveString == "true");
|
|
|
|
//یافتن کارگاه های استثنا بدون قردادمالی
|
|
var checkoutWithOutInstitutionContract = checkoutWorkshopEmployer.Where(x => x.Employer.ContractingPartyId == 30428)
|
|
.GroupBy(x => x.Workshop).Select(x => x.Key.id);
|
|
|
|
//یافتن قردادمالی برای کارگاه های یافت شده در تاریخ مورد نظر
|
|
var checkoutFindHasInstitutionContract = _context.InstitutionContractSet
|
|
.Where(c => c.ContractStartGr <= currentMonthStart && c.ContractEndGr >= currentMonthEnd)
|
|
.Select(c => c.ContractingPartyId);
|
|
|
|
//فیلتر کارگاه های غیر استثنا با کمک کوئری بالا
|
|
var checkoutWithInstitutionContract = checkoutWorkshopEmployer.Where(x => x.Employer.ContractingPartyId != 30428 && checkoutFindHasInstitutionContract.Contains(x.Employer.ContractingPartyId)).GroupBy(x => x.WorkshopId).Select(x => x.Key);
|
|
|
|
|
|
//ترکیب کارگاه های استثنا و دارای قراداد
|
|
var checkoutMixWitAndWitOut = checkoutWithInstitutionContract.Concat(checkoutWithOutInstitutionContract);
|
|
|
|
|
|
//تمام پرسنل فعال برای تصفیه حساب در ماه مورد نظر
|
|
var allCheckoutLeftworks = _context.LeftWorkList
|
|
.Where(x => checkoutMixWitAndWitOut.Contains(x.WorkshopId))
|
|
.Where(x =>
|
|
x.StartWorkDate <= currentMonthEnd && x.LeftWorkDate > currentMonthStart);
|
|
|
|
|
|
var allCheckoutLeftworkEmployeeIds = allCheckoutLeftworks.Select(x => x.EmployeeId);
|
|
var allCheckoutLeftworkWorkshopIds = allCheckoutLeftworks.Select(x => x.WorkshopId).ToList();
|
|
|
|
var allCheckoutToBeTople = allCheckoutLeftworks.Select(x => new { x.EmployeeId, x.WorkshopId }).ToList();
|
|
//تمام تصفیه حساب های ایجاد شده ماه مورد نظر
|
|
var allCheckoutCreated = _context.CheckoutSet
|
|
.Where(x => allCheckoutLeftworkEmployeeIds.Contains(x.EmployeeId) && allCheckoutLeftworkWorkshopIds.Contains(x.WorkshopId))
|
|
.Where(x =>
|
|
x.ContractStart.Date >= currentMonthStart.Date && x.ContractEnd.Date <= currentMonthEnd.Date && x.IsActiveString == "true");
|
|
|
|
|
|
var allChekoutCreated = allCheckoutCreated.Select(x => x.WorkshopId).ToList();
|
|
//تصفیه حساب هایی که امضاء شده
|
|
var allCheckoutSigned = allCheckoutCreated.Count(x => x.Signature == "1");
|
|
var allCheckoutSignedList = allCheckoutCreated.Where(x => x.Signature == "1").Select(x => x.WorkshopId).ToList();
|
|
#endregion
|
|
|
|
#region Contracts
|
|
//یاتن اکانتهای قراداد ساده
|
|
var contractsAccountLeftWorks = _accountContext.AccountLeftWorks
|
|
.Where(x => x.RoleId == 5)
|
|
.Where(x => x.StartWorkGr < nextMonthEnd && x.LeftWorkGr > nextMonthStart);
|
|
var allContractAccountLeftWorkWorkshopIds = contractsAccountLeftWorks.Select(x => x.WorkshopId).ToList();
|
|
//#if DEBUG
|
|
// contractsAccountLeftWorks = contractsAccountLeftWorks.Where(x => x.AccountId == 25);
|
|
// allContractAccountLeftWorkWorkshopIds = allContractAccountLeftWorkWorkshopIds.Where(x=>x == 296).ToList();
|
|
//#endif
|
|
|
|
|
|
|
|
//یافتن کارگاه هایی که فعال هستند و طرف حساب انها فعال است
|
|
var contractWorkshopEmployer = _context.WorkshopEmployers
|
|
.Where(x => allContractAccountLeftWorkWorkshopIds.Contains(x.WorkshopId))
|
|
.Include(x => x.Workshop)
|
|
.Include(x => x.Employer)
|
|
.ThenInclude(x => x.ContractingParty)
|
|
.Where(x => x.Employer.ContractingParty.IsBlock != "true" && x.Employer.ContractingParty.IsActiveString == "true")
|
|
.Where(x => x.Workshop.IsActiveString == "true");
|
|
|
|
//یافتن کارگاه های استثنا بدون قردادمالی
|
|
var contractWithOutInstitutionContract = contractWorkshopEmployer.Where(x => x.Employer.ContractingPartyId == 30428)
|
|
.GroupBy(x => x.Workshop).Select(x => x.Key.id).ToList();
|
|
|
|
//یافتن قردادمالی برای کارگاه های یافت شده در تاریخ مورد نظر
|
|
var contractFindHasInstitutionContract = _context.InstitutionContractSet
|
|
.Where(c => c.ContractStartGr <= nextMonthStart && c.ContractEndGr >= nextMonthEnd)
|
|
.Select(c => c.ContractingPartyId);
|
|
|
|
//فیلتر کارگاه های غیر استثنا با کمک کوئری بالا
|
|
var contractWithInstitutionContract = contractWorkshopEmployer.Where(x => x.Employer.ContractingPartyId != 30428 && contractFindHasInstitutionContract
|
|
.Contains(x.Employer.ContractingPartyId)).GroupBy(x => x.WorkshopId)
|
|
.Select(x => x.Key).ToList();
|
|
|
|
|
|
//ترکیب کارگاه های استثنا و دارای قراداد
|
|
var contractMixWitAndWitOut = contractWithInstitutionContract.Concat(contractWithOutInstitutionContract).ToList();
|
|
|
|
|
|
//تمام پرسنل فعال برای قراداد در ماه مورد نظر
|
|
var allContractLeftworks = _context.LeftWorkList
|
|
.Where(x => contractMixWitAndWitOut.Contains(x.WorkshopId))
|
|
.Where(x =>
|
|
x.StartWorkDate <= nextMonthEnd && x.LeftWorkDate > nextMonthStart);
|
|
|
|
//تمام قرارداد های ایجاد شده ماه مورد نظر
|
|
var allContractLeftworkEmployeeIds = allContractLeftworks.Select(x => x.EmployeeId);
|
|
var allContracToBeTople = allContractLeftworks.Select(x => new { x.EmployeeId, x.WorkshopId }).ToList();
|
|
var allContractLeftworkWorkshopIds = allContractLeftworks.Select(x => x.WorkshopId).ToList();
|
|
var allContractCreated = _context.Contracts
|
|
.Where(x => allContractLeftworkEmployeeIds.Contains(x.EmployeeId) && allContractLeftworkWorkshopIds.Contains(x.WorkshopIds))
|
|
.Where(x =>
|
|
x.ContarctStart.Date <= nextMonthEnd.Date && x.ContractEnd.Date > nextMonthStart.Date && x.IsActiveString == "true");
|
|
var allContractCreatedlist = allContractCreated.Select(x => x.WorkshopIds).ToList();
|
|
//قرارداد هایی که امضاء شده
|
|
var allContractSigned = allContractCreated.Count(x => x.Signature == "1");
|
|
var allContractSignedList = allContractCreated.Where(x => x.Signature == "1").Select(x => x.WorkshopIds).ToList();
|
|
|
|
#endregion
|
|
|
|
//قرارداد هایی که باید ایجاد می شد
|
|
var contractToBe = allContractLeftworks.Count();
|
|
|
|
//قراردادهای ایجاد شده
|
|
var createdContracts = allContractCreated.Count();
|
|
// قراداد های امضاء شده
|
|
var signedContracts = allContractSigned;
|
|
|
|
|
|
// تصفیه هایی که باید ایجاد می شد
|
|
var checkoutToBe = allCheckoutLeftworks.Count();
|
|
|
|
// تصفیه های ایجاد شده
|
|
var createdCheckouts = allCheckoutCreated.Count();
|
|
//تصفیه های امضاء شده
|
|
var signedChckouts = allCheckoutSigned;
|
|
|
|
Console.WriteLine("contractsToBe : " + allContractLeftworks.Count());
|
|
Console.WriteLine("contracts created: " + allContractCreated.Count());
|
|
Console.WriteLine("contracts signed: " + allContractSigned);
|
|
|
|
|
|
Console.WriteLine("checkoutsToBe : " + allCheckoutLeftworks.Count());
|
|
Console.WriteLine("checkouts created: " + allCheckoutCreated.Count());
|
|
Console.WriteLine("checkouts signed: " + allCheckoutSigned);
|
|
|
|
|
|
|
|
var accounts = _accountContext.Accounts.Where(x => x.RoleId == 5);
|
|
|
|
|
|
|
|
#region checkoutAccounts
|
|
|
|
|
|
var checkoutAccountGroup = checkoutAccountLeftWorks
|
|
.Where(x => allCheckoutLeftworkWorkshopIds.Contains(x.WorkshopId))
|
|
.GroupBy(x => x.AccountId).Select(x => new AccountResults()
|
|
{
|
|
AccountId = x.Key,
|
|
AccountFullName = accounts.FirstOrDefault(a => a.id == x.Key)!.Fullname,
|
|
WorkshopList = x.Select(w => w.WorkshopId).ToList()
|
|
// CheckoutDonePercent = (x.Sum(c => c.) * 100) / x.Sum(c => c.CheckoutLeftWorkCount),
|
|
//CheckoutSignPercent = x.Sum(c => c.CheckoutDoneCount) > 0 ? (x.Sum(c => c.CheckoutSignDoneCount) * 100) / (x.Sum(c => c.CheckoutDoneCount)) : 0,
|
|
|
|
}).AsEnumerable();
|
|
|
|
|
|
var checkoutAccountGroupresult = checkoutAccountGroup.Select(grouped =>
|
|
{
|
|
var toBe = allCheckoutToBeTople.Where(n => grouped.WorkshopList.Contains(n.WorkshopId)).GroupBy(n => n.EmployeeId).Select(n => n.Key).ToList();
|
|
int checkoutToBe = toBe.Count;
|
|
//int checkoutToBe = allCheckoutLeftworkWorkshopIds.Count(n => grouped.WorkshopList.Contains(n));
|
|
int createdCheckouts = allChekoutCreated.Count(n => grouped.WorkshopList.Contains(n));
|
|
int signedCheckout = allCheckoutSignedList.Count(n => grouped.WorkshopList.Contains(n));
|
|
|
|
if (checkoutToBe > 0)
|
|
{
|
|
return new AccountResults()
|
|
{
|
|
WorkshopList = grouped.WorkshopList,
|
|
AccountId = grouped.AccountId,
|
|
AccountFullName = grouped.AccountFullName,
|
|
CheckoutDonePercent = (createdCheckouts * 100) / checkoutToBe,
|
|
CheckoutSignPercent = createdCheckouts > 0 ? (signedCheckout * 100) / createdCheckouts : 0,
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return new AccountResults()
|
|
{
|
|
AccountId = 0,
|
|
|
|
};
|
|
}
|
|
|
|
}).Where(x => x.AccountId > 0).ToList();
|
|
#endregion
|
|
|
|
#region contractAccouns
|
|
var contractAccountGroup = contractsAccountLeftWorks
|
|
.Where(x => allContractLeftworkWorkshopIds.Contains(x.WorkshopId))
|
|
.GroupBy(x => x.AccountId).Select(x => new AccountResults()
|
|
{
|
|
AccountId = x.Key,
|
|
AccountFullName = accounts.FirstOrDefault(a => a.id == x.Key)!.Fullname,
|
|
WorkshopList = x.Select(w => w.WorkshopId).ToList()
|
|
|
|
|
|
}).AsEnumerable();
|
|
|
|
|
|
var contractAccountGroupResult = contractAccountGroup.Select(grouped =>
|
|
{
|
|
var toBe = allContracToBeTople.Where(n => grouped.WorkshopList.Contains(n.WorkshopId)).GroupBy(n => n.EmployeeId).Select(n => n.Key).ToList();
|
|
int contractToBe = toBe.Count;
|
|
int createdContracts = allContractCreatedlist.Count(n => grouped.WorkshopList.Contains(n));
|
|
int signedContracts = allContractSignedList.Count(n => grouped.WorkshopList.Contains(n));
|
|
if (contractToBe > 0)
|
|
{
|
|
return new AccountResults()
|
|
{
|
|
WorkshopList = grouped.WorkshopList,
|
|
AccountId = grouped.AccountId,
|
|
AccountFullName = grouped.AccountFullName,
|
|
ContractDonePercent = (createdContracts * 100) / contractToBe,
|
|
ContractSignPercent = createdContracts > 0 ? (signedContracts * 100) / createdContracts : 0,
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return new AccountResults()
|
|
{
|
|
AccountId = 0,
|
|
|
|
};
|
|
}
|
|
|
|
|
|
}).Where(x => x.AccountId > 0).ToList();
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
//قرارداد
|
|
var contractPercent = contractToBe > 0 ? (createdContracts * 100) / contractToBe : 0;
|
|
//امضاء قراداد
|
|
var contractSignaturePercent = createdContracts > 0 ? (signedContracts * 100) / createdContracts : 0;
|
|
// تصفیه
|
|
var checkoutPercent = (createdCheckouts * 100) / checkoutToBe;
|
|
// امضاء تصفیه حساب
|
|
var checkoutSignaturePercent = createdCheckouts > 0 ? (signedChckouts * 100) / createdCheckouts : 0;
|
|
var finalResult = new AllReport()
|
|
{
|
|
//همه
|
|
AllPercent = (contractPercent + contractSignaturePercent + checkoutPercent + checkoutSignaturePercent) / 4,
|
|
//قرارداد
|
|
ContractPercent = contractPercent,
|
|
//امضاء قراداد
|
|
ContractSignaturePercent = contractSignaturePercent,
|
|
// تصفیه
|
|
CheckoutPercent = checkoutPercent,
|
|
// امضاء تصفیه حساب
|
|
CheckoutSignaturePercent = checkoutSignaturePercent,
|
|
|
|
Year = $"{currentYear}",
|
|
Month = nowFa.Substring(5, 2),
|
|
ContractAccountResults = contractAccountGroupResult,
|
|
CheckoutAccountResults = checkoutAccountGroupresult,
|
|
|
|
AllContract = contractToBe,
|
|
ContractNotDone = contractToBe - createdContracts,
|
|
ContrcatDone = createdContracts,
|
|
ContractSignNotDone = createdContracts - signedContracts,
|
|
ContractSignDone = signedContracts,
|
|
|
|
|
|
AllCheckout = checkoutToBe,
|
|
CheckoutNotDone = checkoutToBe - createdCheckouts,
|
|
CheckoutDone = createdCheckouts,
|
|
CheckoutSignDone = signedChckouts,
|
|
CheckoutSignNotDone = createdCheckouts - signedChckouts,
|
|
|
|
|
|
};
|
|
Console.WriteLine("new metod >>>>>: " + watch.Elapsed);
|
|
return Task.FromResult(finalResult);
|
|
}
|
|
|
|
public AllReport GetAllActiveWorkshops(string year, string month)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
//var instititionContracts = _context.InstitutionContractSet.Where(x => x.IsActiveString == "true").Select(x=>x.ContractingPartyId).ToList();
|
|
var blockContractingPartyIds = _context.PersonalContractingParties.Where(x => x.IsBlock == "false" && x.IsActiveString == "true").Select(x => x.id).ToList();
|
|
//blockContractingPartyIds = blockContractingPartyIds.Where(x => instititionContracts.Contains(x)).ToList();
|
|
var workshops = _context.Workshops.Where(x => x.IsActiveString == "true")
|
|
.Include(x => x.WorkshopEmployers)
|
|
.Include(x => x.LeftWorks)
|
|
.Select(x => new ActiveWorkshops
|
|
{
|
|
Id = x.id,
|
|
ContractLeftWorkCount = 0,
|
|
CheckoutLeftWorkCount = 0,
|
|
ContractingPartId = x.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(),
|
|
AccountIdList = _context.WorkshopAccounts.Where(m => m.WorkshopId == x.id && m.ContractAndCheckout == "true" && m.IsActiveSting == "true").Select(a => a.AccountId).ToList(),
|
|
#region Contracts
|
|
|
|
//contractLeft This Mont
|
|
|
|
ContractLeftIds = x.LeftWorks.Select(l => new LeftWorkViewModel()
|
|
{
|
|
EmployeeId = l.EmployeeId,
|
|
StartWorkDateGr = l.StartWorkDate,
|
|
LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
}).Where(l =>
|
|
(l.StartWorkDateGr <= nextMonthStart && l.LeftWorkDateGr > nextMonthStart) ||
|
|
(l.StartWorkDateGr <= nextMonthEnd && l.LeftWorkDateGr >= nextMonthEnd) ||
|
|
(l.StartWorkDateGr >= nextMonthStart && l.StartWorkDateGr <= nextMonthEnd) ||
|
|
(l.LeftWorkDateGr >= nextMonthStart && l.LeftWorkDateGr <= nextMonthEnd)).Select(l => l.EmployeeId).ToList(),
|
|
#endregion
|
|
|
|
#region Checkouts
|
|
|
|
//CheckoutLeft befor This Month
|
|
|
|
CheckoutLeftIds = x.LeftWorks.Select(l => new LeftWorkViewModel()
|
|
{
|
|
EmployeeId = l.EmployeeId,
|
|
StartWorkDateGr = l.StartWorkDate,
|
|
LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
}).Where(l => (l.StartWorkDateGr <= currentMonthStart && l.LeftWorkDateGr > currentMonthStart) ||
|
|
(l.StartWorkDateGr <= currentMonthEnd && l.LeftWorkDateGr >= currentMonthEnd) ||
|
|
(l.StartWorkDateGr >= currentMonthStart && l.StartWorkDateGr <= currentMonthEnd) ||
|
|
(l.LeftWorkDateGr >= currentMonthStart && l.LeftWorkDateGr <= currentMonthEnd)).Select(l => l.EmployeeId).ToList(),
|
|
|
|
#endregion
|
|
|
|
|
|
}).Where(e => blockContractingPartyIds.Contains(e.ContractingPartId) && e.AccountIdList.Count > 0).AsSplitQuery();
|
|
|
|
var workshopsList = workshops.Select(x => new ActiveWorkshops
|
|
{
|
|
Id = x.Id,
|
|
|
|
|
|
AccountIdList = x.AccountIdList,
|
|
|
|
#region Contracts
|
|
|
|
//contractLeft This Month
|
|
ContractLeftIds = _context.InstitutionContractSet.Any(c => c.ContractingPartyId == x.ContractingPartId && c.ContractStartGr <= nextMonthStart && c.ContractEndGr >= nextMonthEnd) ? x.ContractLeftIds : new List<long>(),
|
|
|
|
#endregion
|
|
|
|
#region Checkouts
|
|
|
|
////CheckoutLeft befor This Month
|
|
CheckoutLeftIds = _context.InstitutionContractSet.Any(c => c.ContractingPartyId == x.ContractingPartId && c.ContractStartGr <= currentMonthStart && c.ContractEndGr >= currentMonthEnd) ? x.CheckoutLeftIds : new List<long>(),
|
|
|
|
#endregion
|
|
}).AsSplitQuery();
|
|
//var wCount = workshops.Count();
|
|
//var partyId = workshops.Select(x => x.ContractingPartId).ToList();
|
|
|
|
Console.WriteLine("Ripo query 1 >>>>>: " + watch.Elapsed);
|
|
var res = workshopsList.AsEnumerable();
|
|
watch.Restart();
|
|
var result = res.Select(x => new ActiveWorkshops
|
|
{
|
|
Id = x.Id,
|
|
ContractLeftWorkCount = x.ContractLeftIds.Count,
|
|
CheckoutLeftWorkCount = x.CheckoutLeftIds.Count,
|
|
|
|
|
|
AccountIdList = x.AccountIdList,
|
|
CheckoutDoneCount = x.CheckoutLeftIds.Count > 0
|
|
? _context.CheckoutSet.Where(ch => ch.WorkshopId == x.Id)
|
|
.Where(ch => x.CheckoutLeftIds.Contains(ch.EmployeeId))
|
|
.Count(ch =>
|
|
ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd &&
|
|
ch.IsActiveString == "true")
|
|
: 0,
|
|
CheckoutSignDoneCount = x.CheckoutLeftIds.Count > 0
|
|
? _context.CheckoutSet.Where(ch => ch.WorkshopId == x.Id)
|
|
.Where(ch => x.CheckoutLeftIds.Contains(ch.EmployeeId))
|
|
.Count(ch =>
|
|
ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd &&
|
|
ch.IsActiveString == "true" && ch.Signature == "1")
|
|
: 0,
|
|
|
|
ContrctDoneCount = x.ContractLeftIds.Count > 0
|
|
? _context.Contracts.Where(ct => ct.WorkshopIds == x.Id && ct.IsActiveString == "true")
|
|
.Where(ct => x.ContractLeftIds.Contains(ct.EmployeeId))
|
|
.Count(l => (l.ContarctStart <= nextMonthStart && l.ContractEnd >= nextMonthStart) ||
|
|
(l.ContarctStart <= nextMonthEnd && l.ContractEnd >= nextMonthEnd) ||
|
|
(l.ContarctStart >= nextMonthStart && l.ContarctStart <= nextMonthEnd) ||
|
|
(l.ContractEnd >= nextMonthStart && l.ContractEnd <= nextMonthEnd))
|
|
: 0,
|
|
ContrctSignDoneCount = x.ContractLeftIds.Count > 0
|
|
? _context.Contracts
|
|
.Where(ct => ct.WorkshopIds == x.Id && ct.IsActiveString == "true" && ct.Signature == "1")
|
|
.Where(ct => x.ContractLeftIds.Contains(ct.EmployeeId))
|
|
.Count(l => (l.ContarctStart <= nextMonthStart && l.ContractEnd >= nextMonthStart) ||
|
|
(l.ContarctStart <= nextMonthEnd && l.ContractEnd >= nextMonthEnd) ||
|
|
(l.ContarctStart >= nextMonthStart && l.ContarctStart <= nextMonthEnd) ||
|
|
(l.ContractEnd >= nextMonthStart && l.ContractEnd <= nextMonthEnd))
|
|
: 0,
|
|
|
|
}).AsEnumerable();
|
|
|
|
Console.WriteLine("Ripo query 2 >>>>>: " + watch.Elapsed);
|
|
var contractAccountResult = result.Select(x => new ActiveWorkshops()
|
|
{
|
|
Id = x.Id,
|
|
//AccountId = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5)
|
|
// ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.id : 0,
|
|
//AccountFullname = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5)
|
|
// ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.Fullname : "",
|
|
AccountId = _accountContext.AccountLeftWorks.Any(e => x.AccountIdList.Contains(e.AccountId) && e.StartWorkGr <= currentMonthStart && e.LeftWorkGr >= currentMonthEnd) ?
|
|
_accountContext.AccountLeftWorks.FirstOrDefault(e => x.AccountIdList.Contains(e.AccountId) && e.StartWorkGr <= currentMonthStart && e.LeftWorkGr >= currentMonthEnd)!.AccountId : 0,
|
|
|
|
ContractLeftWorkCount = x.ContractLeftWorkCount,
|
|
ContrctDoneCount = x.ContrctDoneCount,
|
|
ContrctSignDoneCount = x.ContrctSignDoneCount,
|
|
|
|
IsActiveString = x.IsActiveString,
|
|
WorkshopFullName = x.WorkshopFullName,
|
|
|
|
}).Where(x => x.AccountId != 0 && x.ContractLeftWorkCount > 0).ToList();
|
|
var checkoutAccountResult = result.Select(x => new ActiveWorkshops()
|
|
{
|
|
Id = x.Id,
|
|
//AccountId = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5)
|
|
// ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.id : 0,
|
|
//AccountFullname = _accountContext.Accounts.Any(e => x.AccountIdList.Contains(e.id) && e.RoleId == 5)
|
|
// ? _accountContext.Accounts.Where(e => x.AccountIdList.Contains(e.id)).FirstOrDefault(e => e.RoleId == 5)!.Fullname : "",
|
|
AccountId = _accountContext.AccountLeftWorks.Any(e => x.AccountIdList.Contains(e.AccountId) && e.StartWorkGr <= nextMonthStart && e.LeftWorkGr >= nextMonthEnd) ?
|
|
_accountContext.AccountLeftWorks.FirstOrDefault(e => x.AccountIdList.Contains(e.AccountId) && e.StartWorkGr <= nextMonthStart && e.LeftWorkGr >= nextMonthEnd)!.AccountId : 0,
|
|
|
|
|
|
CheckoutLeftWorkCount = x.CheckoutLeftWorkCount,
|
|
CheckoutDoneCount = x.CheckoutDoneCount,
|
|
CheckoutSignDoneCount = x.CheckoutSignDoneCount,
|
|
|
|
IsActiveString = x.IsActiveString,
|
|
WorkshopFullName = x.WorkshopFullName,
|
|
|
|
}).Where(x => x.AccountId != 0 && x.CheckoutLeftWorkCount > 0).ToList();
|
|
watch.Restart();
|
|
//قرارداد هایی که باید ایجاد می شد
|
|
var contractToBe = contractAccountResult.Sum(x => x.ContractLeftWorkCount);
|
|
|
|
//قراردادهای ایجاد شده
|
|
var createdContracts = contractAccountResult.Sum(x => x.ContrctDoneCount);
|
|
// قراداد های امضاء شده
|
|
var signedContracts = contractAccountResult.Sum(x => x.ContrctSignDoneCount);
|
|
|
|
|
|
// تصفیه هایی که باید ایجاد می شد
|
|
var checkoutToBe = checkoutAccountResult.Sum(x => x.CheckoutLeftWorkCount);
|
|
|
|
// تصفیه های ایجاد شده
|
|
var createdCheckouts = checkoutAccountResult.Sum(x => x.CheckoutDoneCount);
|
|
//تصفیه های امضاء شده
|
|
var signedChckouts = checkoutAccountResult.Sum(x => x.CheckoutSignDoneCount);
|
|
|
|
|
|
var contractGroupResult = contractAccountResult.GroupBy(x => x.AccountId).Select(x => new AccountResults()
|
|
{
|
|
AccountId = x.Key,
|
|
AccountFullName = _accountContext.Accounts.FirstOrDefault(a => a.id == x.Key)!.Fullname,
|
|
|
|
ContractDonePercent = (x.Sum(c => c.ContrctDoneCount) * 100) / (x.Sum(c => c.ContractLeftWorkCount)),
|
|
ContractSignPercent = x.Sum(c => c.ContrctDoneCount) > 0 ? (x.Sum(c => c.ContrctSignDoneCount) * 100) / (x.Sum(c => c.ContrctDoneCount)) : 0,
|
|
|
|
|
|
}).ToList();
|
|
var checkoutGroupResult = checkoutAccountResult.GroupBy(x => x.AccountId).Select(x => new AccountResults()
|
|
{
|
|
AccountId = x.Key,
|
|
AccountFullName = _accountContext.Accounts.FirstOrDefault(a => a.id == x.Key)!.Fullname,
|
|
|
|
CheckoutDonePercent = (x.Sum(c => c.CheckoutDoneCount) * 100) / x.Sum(c => c.CheckoutLeftWorkCount),
|
|
CheckoutSignPercent = x.Sum(c => c.CheckoutDoneCount) > 0 ? (x.Sum(c => c.CheckoutSignDoneCount) * 100) / (x.Sum(c => c.CheckoutDoneCount)) : 0,
|
|
|
|
}).ToList();
|
|
#region ComputePercentage
|
|
|
|
//قرارداد
|
|
var contractPercent = (createdContracts * 100) / contractToBe;
|
|
//امضاء قراداد
|
|
var contractSignaturePercent = createdContracts > 0 ? (signedContracts * 100) / createdContracts : 0;
|
|
// تصفیه
|
|
var checkoutPercent = (createdCheckouts * 100) / checkoutToBe;
|
|
// امضاء تصفیه حساب
|
|
var checkoutSignaturePercent = createdCheckouts > 0 ? (signedChckouts * 100) / createdCheckouts : 0;
|
|
var finalResult = new AllReport()
|
|
{
|
|
//همه
|
|
AllPercent = (contractPercent + contractSignaturePercent + checkoutPercent + checkoutSignaturePercent) / 4,
|
|
//قرارداد
|
|
ContractPercent = contractPercent,
|
|
//امضاء قراداد
|
|
ContractSignaturePercent = contractSignaturePercent,
|
|
// تصفیه
|
|
CheckoutPercent = checkoutPercent,
|
|
// امضاء تصفیه حساب
|
|
CheckoutSignaturePercent = checkoutSignaturePercent,
|
|
|
|
Year = $"{currentYear}",
|
|
Month = nowFa.Substring(5, 2),
|
|
ContractAccountResults = contractGroupResult,
|
|
CheckoutAccountResults = checkoutGroupResult,
|
|
|
|
AllContract = contractToBe,
|
|
ContractNotDone = contractToBe - createdContracts,
|
|
ContrcatDone = createdContracts,
|
|
ContractSignNotDone = createdContracts - signedContracts,
|
|
ContractSignDone = signedContracts,
|
|
|
|
|
|
AllCheckout = checkoutToBe,
|
|
CheckoutNotDone = checkoutToBe - createdCheckouts,
|
|
CheckoutDone = createdCheckouts,
|
|
CheckoutSignDone = signedChckouts,
|
|
CheckoutSignNotDone = createdCheckouts - signedChckouts,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endregion
|
|
Console.WriteLine("App 1 >>>>>: " + watch.Elapsed);
|
|
|
|
return finalResult;
|
|
|
|
}
|
|
|
|
public WorkshopResult GetWorkshopContractDone(string year, string month, long accountId, List<long> workshopList)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
|
|
////var instititionContracts = _context.InstitutionContractSet.Where(x => x.IsActiveString == "true").Select(x => x.ContractingPartyId).ToList();
|
|
//var blockContractingPartyIds = _context.PersonalContractingParties.Where(x => x.IsBlock == "false" && x.IsActiveString == "true").Select(x => x.id).ToList();
|
|
////blockContractingPartyIds = blockContractingPartyIds.Where(x => instititionContracts.Contains(x)).ToList();
|
|
//var workshops = _context.Workshops.Where(x => workshopList.Contains(x.id))
|
|
// .Include(x => x.LeftWorks)
|
|
// .Select(x => new ActiveWorkshops
|
|
// {
|
|
// Id = x.id,
|
|
// IsActiveString = x.IsActiveString,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
|
|
|
|
|
|
// #region Contracts
|
|
|
|
// //contractLeft This Mont
|
|
|
|
// ContractLeftIds = x.LeftWorks.Where(l =>
|
|
// l.StartWorkDate <= nextMonthEnd && l.LeftWorkDate > nextMonthStart).Select(l => l.id).ToList(),
|
|
// #endregion
|
|
|
|
|
|
|
|
// }).AsSplitQuery();
|
|
|
|
//var workshopsList = workshops.Select(x => new ActiveWorkshops
|
|
//{
|
|
// Id = x.Id,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContractingPartId = x.ContractingPartId,
|
|
// AccountIdList = x.AccountIdList,
|
|
// #region Contracts
|
|
|
|
// //contractLeft This Month
|
|
// ContractLeftIds = _context.InstitutionContractSet.Any(c => c.ContractingPartyId == x.ContractingPartId && c.ContractStartGr <= nextMonthStart && c.ContractEndGr >= nextMonthEnd) ? x.ContractLeftIds : new List<long>(),
|
|
|
|
// #endregion
|
|
|
|
|
|
//}).ToList();
|
|
|
|
//var result = workshops.Select(x => new ActiveWorkshops
|
|
//{
|
|
// Id = x.Id,
|
|
// ContractLeftWorkCount = x.ContractLeftIds.Count,
|
|
// ContractLeftIds = x.ContractLeftIds,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContrctDoneCount = x.ContractLeftIds.Count > 0 ? _context.Contracts.Count(c => x.ContractLeftIds.Contains(c.EmployerId) &&
|
|
// c.ContarctStart.Date <= nextMonthEnd.Date && c.ContractEnd.Date > nextMonthStart.Date && c.IsActiveString == "true") : 0,
|
|
|
|
|
|
//}).Where(x => x.ContractLeftWorkCount > 0).ToList();
|
|
|
|
#region NewChanges
|
|
|
|
//تمام پرسنل فعال برای قراداد در ماه مورد نظر
|
|
var allContractLeftworks = _context.LeftWorkList
|
|
.Where(x => workshopList.Contains(x.WorkshopId))
|
|
.Where(x =>
|
|
x.StartWorkDate <= nextMonthEnd && x.LeftWorkDate > nextMonthStart);
|
|
|
|
var allContractLeftworksWorkshopIdList = allContractLeftworks.Select(x => x.WorkshopId).ToList();
|
|
|
|
var allContractLeftworkEmployeeIds = allContractLeftworks.Select(x => x.EmployeeId).ToList();
|
|
|
|
var allContractLeftworkEmployeeIdsList = allContractLeftworks
|
|
.Select(x => new { x.EmployeeId, x.WorkshopId })
|
|
.ToList();
|
|
//تمام قرارداد های ایجاد شده ماه مورد نظر
|
|
|
|
|
|
|
|
|
|
var allContractCreated = _context.Contracts
|
|
.Where(x => allContractLeftworkEmployeeIds.Contains(x.EmployeeId))
|
|
.Where(x =>
|
|
x.ContarctStart.Date <= nextMonthEnd.Date && x.ContractEnd.Date > nextMonthStart.Date && x.IsActiveString == "true");
|
|
|
|
var allContractCreatedWorkshopIdList = allContractCreated.Select(x => new { x.EmployeeId, x.WorkshopIds })
|
|
.ToList();
|
|
|
|
|
|
//قرارداد هایی که امضاء شده
|
|
var allContractSigned = allContractCreated.Count(x => x.Signature == "1");
|
|
Console.WriteLine("ajax 1 >>>>>: " + watch.Elapsed);
|
|
var workshops = _context.Workshops.Include(x => x.LeftWorks).Where(x => allContractLeftworksWorkshopIdList.Contains(x.id)).ToList();
|
|
var workshopListResult = workshops
|
|
.Select(workshop =>
|
|
{
|
|
var toBe = workshop.LeftWorks.Where(x =>
|
|
x.StartWorkDate <= nextMonthEnd && x.LeftWorkDate > nextMonthStart)
|
|
.GroupBy(x => x.EmployeeId)
|
|
.Select(x => x.Key).ToList();
|
|
var contractToBe = toBe.Count();
|
|
//var contractToBe = allContractLeftworkEmployeeIdsList.Count(x=> x.WorkshopId == workshop.id);
|
|
var contractCreated = allContractCreatedWorkshopIdList.Count(x => x.WorkshopIds == workshop.id);
|
|
if (contractToBe > 0)
|
|
{
|
|
return new workshopSearch()
|
|
{
|
|
Id = workshop.id,
|
|
WorkshopFullName = workshop.WorkshopFullName,
|
|
ArchiveCode = workshop.ArchiveCode,
|
|
ContractDonePercent = ((contractCreated * 100) / contractToBe),
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
})
|
|
.Where(x => x != null)
|
|
.OrderBy(x => x.ContractDonePercent)
|
|
.ToList(); // تبدیل به لیست
|
|
|
|
|
|
var badWorkshop = workshopListResult.FirstOrDefault();
|
|
var badWorkshopTobe = allContractLeftworks.Where(x => x.WorkshopId == badWorkshop.Id);
|
|
var badWorkshopCreated = allContractCreated.Where(x => x.WorkshopIds == badWorkshop.Id).Select(x => x.EmployeeId);
|
|
var notDoneEmployes = badWorkshopTobe.Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.EmployeeFullName,
|
|
|
|
}).Where(l => !badWorkshopCreated.Contains(l.Id)).ToList();
|
|
|
|
var finalResult = new WorkshopResult()
|
|
{
|
|
WorkshopSearches = workshopListResult,
|
|
EmployeeNotDones = notDoneEmployes,
|
|
};
|
|
Console.WriteLine("ajax 2 >>>>>: " + watch.Elapsed);
|
|
|
|
#endregion
|
|
|
|
return finalResult;
|
|
}
|
|
|
|
public WorkshopResult GetWorkshopContractSignDone(string year, string month, long accountId,
|
|
List<long> workshopList)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
//var instititionContracts = _context.InstitutionContractSet.Where(x => x.IsActiveString == "true").Select(x => x.ContractingPartyId).ToList();
|
|
//var blockContractingPartyIds = _context.PersonalContractingParties.Where(x => x.IsBlock == "false" && x.IsActiveString == "true").Select(x => x.id).ToList();
|
|
////blockContractingPartyIds = blockContractingPartyIds.Where(x => instititionContracts.Contains(x)).ToList();
|
|
//var workshops = _context.Workshops.Where(x => x.IsActiveString == "true")
|
|
// .Include(x => x.WorkshopEmployers)
|
|
// .Include(x => x.LeftWorks)
|
|
// .Select(x => new ActiveWorkshops
|
|
// {
|
|
// Id = x.id,
|
|
// IsActiveString = x.IsActiveString,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContractingPartId = x.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(),
|
|
// AccountIdList = _context.WorkshopAccounts.Where(m => m.WorkshopId == x.id).Select(a => a.AccountId).ToList(),
|
|
// #region Contracts
|
|
|
|
// //contractLeft This Mont
|
|
|
|
// ContractLeftIds = x.LeftWorks.Select(l => new LeftWorkViewModel()
|
|
// {
|
|
// EmployeeId = l.EmployeeId,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
// }).Where(l =>
|
|
// (l.StartWorkDateGr <= nextMonthStart && l.LeftWorkDateGr > nextMonthStart) ||
|
|
// (l.StartWorkDateGr <= nextMonthEnd && l.LeftWorkDateGr >= nextMonthEnd) ||
|
|
// (l.StartWorkDateGr >= nextMonthStart && l.StartWorkDateGr <= nextMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= nextMonthStart && l.LeftWorkDateGr <= nextMonthEnd)).Select(l => l.EmployeeId).ToList(),
|
|
// #endregion
|
|
|
|
|
|
// }).Where(e => blockContractingPartyIds.Contains(e.ContractingPartId))
|
|
// .Where(a => a.AccountIdList.Contains(accountId)).AsSplitQuery();
|
|
//var workshopsList = workshops.Select(x => new ActiveWorkshops
|
|
//{
|
|
// Id = x.Id,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContractingPartId = x.ContractingPartId,
|
|
// AccountIdList = x.AccountIdList,
|
|
// #region Contracts
|
|
|
|
// //contractLeft This Month
|
|
// ContractLeftIds = _context.InstitutionContractSet.Any(c => c.ContractingPartyId == x.ContractingPartId && c.ContractStartGr <= nextMonthStart && c.ContractEndGr >= nextMonthEnd) ? x.ContractLeftIds : new List<long>(),
|
|
|
|
// #endregion
|
|
|
|
|
|
//}).ToList();
|
|
|
|
//var result = workshopsList.Select(x => new ActiveWorkshops
|
|
//{
|
|
// Id = x.Id,
|
|
// ContractLeftWorkCount = x.ContractLeftIds.Count,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContrctDoneCount = x.ContractLeftIds.Count > 0 ? _context.Contracts.Where(ch => ch.WorkshopIds == x.Id && ch.IsActiveString == "true").Where(ch => x.ContractLeftIds.Contains(ch.EmployeeId))
|
|
// .Count(l => (l.ContarctStart <= nextMonthStart && l.ContractEnd >= nextMonthStart) ||
|
|
// (l.ContarctStart <= nextMonthEnd && l.ContractEnd >= nextMonthEnd) ||
|
|
// (l.ContarctStart >= nextMonthStart && l.ContarctStart <= nextMonthEnd) ||
|
|
// (l.ContractEnd >= nextMonthStart && l.ContractEnd <= nextMonthEnd)) : 0,
|
|
// ContrctSignDoneCount = x.ContractLeftIds.Count > 0 ?_context.Contracts.Where(ct => ct.WorkshopIds == x.Id && ct.IsActiveString == "true" && ct.Signature == "1").Where(ct => x.ContractLeftIds.Contains(ct.EmployeeId))
|
|
// .Count(l => (l.ContarctStart <= nextMonthStart && l.ContractEnd >= nextMonthStart) ||
|
|
// (l.ContarctStart <= nextMonthEnd && l.ContractEnd >= nextMonthEnd) ||
|
|
// (l.ContarctStart >= nextMonthStart && l.ContarctStart <= nextMonthEnd) ||
|
|
// (l.ContractEnd >= nextMonthStart && l.ContractEnd <= nextMonthEnd)) : 0,
|
|
|
|
|
|
//}).Where(x => x.ContrctDoneCount > 0).ToList();
|
|
//var workshopList = result.Select(x => new workshopSearch()
|
|
//{
|
|
// Id = x.Id,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
|
|
// ContractSignPercent = ((x.ContrctSignDoneCount * 100) / x.ContrctDoneCount),
|
|
|
|
//}).OrderBy(x => x.ContractSignPercent).ToList();
|
|
|
|
//var badWorkshop = workshopList.FirstOrDefault();
|
|
//var badWorkshopLeftWorks = _context.LeftWorkList.Where(l => l.WorkshopId == badWorkshop.Id).Select(l => new LeftWorkViewModel()
|
|
//{
|
|
// Id = l.id,
|
|
// EmployeeId = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate,
|
|
|
|
//}).Where(l =>
|
|
// (l.StartWorkDateGr <= nextMonthStart && l.LeftWorkDateGr > nextMonthStart) ||
|
|
// (l.StartWorkDateGr <= nextMonthEnd && l.LeftWorkDateGr >= nextMonthEnd) ||
|
|
// (l.StartWorkDateGr >= nextMonthStart && l.StartWorkDateGr <= nextMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= nextMonthStart && l.LeftWorkDateGr <= nextMonthEnd)).ToList();
|
|
//var badWorkshopContracts = _context.Contracts.Where(ct => ct.WorkshopIds == badWorkshop.Id && ct.IsActiveString == "true" && ct.Signature == "1")
|
|
// .Where(l => (l.ContarctStart <= nextMonthStart && l.ContractEnd >= nextMonthStart) ||
|
|
// (l.ContarctStart <= nextMonthEnd && l.ContractEnd >= nextMonthEnd) ||
|
|
// (l.ContarctStart >= nextMonthStart && l.ContarctStart <= nextMonthEnd) ||
|
|
// (l.ContractEnd >= nextMonthStart && l.ContractEnd <= nextMonthEnd)).Select(x => x.EmployeeId).ToList();
|
|
//var notDoneEmployes = badWorkshopLeftWorks.Select(l => new EmployeeNotDone()
|
|
//{
|
|
// Id = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
|
|
//}).Where(l => !badWorkshopContracts.Contains(l.Id)).ToList();
|
|
|
|
//var finalResult = new WorkshopResult()
|
|
//{
|
|
// WorkshopSearches = workshopList,
|
|
// EmployeeNotDones = notDoneEmployes,
|
|
//};
|
|
|
|
#region NewChanges
|
|
|
|
//تمام پرسنل فعال برای قراداد در ماه مورد نظر
|
|
var allContractLeftworks = _context.LeftWorkList
|
|
.Where(x => workshopList.Contains(x.WorkshopId))
|
|
.Where(x =>
|
|
x.StartWorkDate <= nextMonthEnd && x.LeftWorkDate > nextMonthStart);
|
|
|
|
|
|
|
|
|
|
var allContractLeftworkEmployeeIds = allContractLeftworks.Select(x => x.EmployeeId).ToList();
|
|
|
|
|
|
|
|
//تمام قرارداد های ایجاد شده ماه مورد نظر
|
|
|
|
|
|
|
|
var allContractCreated = _context.Contracts
|
|
.Where(x => allContractLeftworkEmployeeIds.Contains(x.EmployeeId))
|
|
.Where(x =>
|
|
x.ContarctStart.Date <= nextMonthEnd.Date && x.ContractEnd.Date > nextMonthStart.Date && x.IsActiveString == "true");
|
|
|
|
var createdContractWorkshopids = allContractCreated.Select(x => x.WorkshopIds).ToList();
|
|
|
|
//قرارداد هایی که امضاء شده
|
|
var allContractSigned = allContractCreated.Where(x => x.Signature == "1");
|
|
|
|
|
|
|
|
var createdContractTople = allContractCreated
|
|
.Select(x => new { x.EmployeeId, x.WorkshopIds })
|
|
.ToList();
|
|
var signedContracTople = allContractCreated.Where(x => x.Signature == "1")
|
|
.Select(x => new { x.EmployeeId, x.WorkshopIds })
|
|
.ToList();
|
|
|
|
Console.WriteLine("ajax 1 >>>>>: " + watch.Elapsed);
|
|
var workshops = _context.Workshops.Where(x => createdContractWorkshopids.Contains(x.id)).ToList();
|
|
var workshopListResult = workshops
|
|
.Select(workshop =>
|
|
{
|
|
//var contractToBe = allContractLeftworks.Count(x => x.WorkshopId == workshop.id);
|
|
var contractCreated = createdContractTople.Count(x => x.WorkshopIds == workshop.id);
|
|
var signedContract = signedContracTople.Count(x => x.WorkshopIds == workshop.id);
|
|
if (contractCreated > 0)
|
|
{
|
|
return new workshopSearch()
|
|
{
|
|
Id = workshop.id,
|
|
WorkshopFullName = workshop.WorkshopFullName,
|
|
ArchiveCode = workshop.ArchiveCode,
|
|
ContractSignPercent = ((signedContract * 100) / contractCreated),
|
|
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
})
|
|
.Where(x => x != null)
|
|
.OrderBy(x => x.ContractSignPercent)
|
|
.ToList(); // تبدیل به لیست
|
|
if (workshopListResult.Count == 0)
|
|
return new WorkshopResult()
|
|
{
|
|
WorkshopSearches = workshopListResult,
|
|
EmployeeNotDones = new(),
|
|
};
|
|
|
|
var badWorkshop = workshopListResult.FirstOrDefault();
|
|
var badWorkshopCreated = allContractCreated.Where(x => x.WorkshopIds == badWorkshop.Id);
|
|
var badWorkshopSigned = allContractSigned.Where(x => x.WorkshopIds == badWorkshop.Id).Select(x => x.EmployeeId);
|
|
var notDoneEmployes = badWorkshopCreated.Include(x => x.Employee).Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.Employee.FullName,
|
|
|
|
}).Where(l => !badWorkshopSigned.Contains(l.Id)).ToList();
|
|
|
|
var finalResult = new WorkshopResult()
|
|
{
|
|
WorkshopSearches = workshopListResult,
|
|
EmployeeNotDones = notDoneEmployes,
|
|
};
|
|
|
|
|
|
#endregion
|
|
Console.WriteLine("ajax >>>>>: " + watch.Elapsed);
|
|
return finalResult;
|
|
}
|
|
|
|
public WorkshopResult GetWorkshopCheckoutDone(string year, string month, long accountId, List<long> workshopList)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
//var instititionContracts = _context.InstitutionContractSet.Where(x => x.IsActiveString == "true").Select(x => x.ContractingPartyId).ToList();
|
|
//var blockContractingPartyIds = _context.PersonalContractingParties.Where(x => x.IsBlock == "false" && x.IsActiveString == "true").Select(x => x.id).ToList();
|
|
////blockContractingPartyIds = blockContractingPartyIds.Where(x => instititionContracts.Contains(x)).ToList();
|
|
//var workshops = _context.Workshops.Where(x => x.IsActiveString == "true")
|
|
// .Include(x => x.WorkshopEmployers)
|
|
// .Include(x => x.LeftWorks)
|
|
// .Select(x => new ActiveWorkshops
|
|
// {
|
|
// Id = x.id,
|
|
// IsActiveString = x.IsActiveString,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContractingPartId = x.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(),
|
|
// AccountIdList = _context.WorkshopAccounts.Where(m => m.WorkshopId == x.id).Select(a => a.AccountId).ToList(),
|
|
|
|
|
|
// #region Checkouts
|
|
|
|
// //CheckoutLeft befor This Month
|
|
// CheckoutLeftIds = x.LeftWorks.Select(l => new LeftWorkViewModel()
|
|
// {
|
|
// EmployeeId = l.EmployeeId,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
// }).Where(l =>
|
|
// (l.StartWorkDateGr <= currentMonthStart && l.LeftWorkDateGr > currentMonthStart) ||
|
|
// (l.StartWorkDateGr <= currentMonthEnd && l.LeftWorkDateGr >= currentMonthEnd) ||
|
|
// (l.StartWorkDateGr >= currentMonthStart && l.StartWorkDateGr <= currentMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= currentMonthStart && l.LeftWorkDateGr <= currentMonthEnd)).Select(l => l.EmployeeId).ToList(),
|
|
|
|
// #endregion
|
|
|
|
// }).Where(e => blockContractingPartyIds.Contains(e.ContractingPartId))
|
|
// .Where(a => a.AccountIdList.Contains(accountId)).AsSplitQuery();
|
|
//var workshopsList = workshops.Select(x => new ActiveWorkshops
|
|
//{
|
|
// Id = x.Id,
|
|
// IsActiveString = x.IsActiveString,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContractingPartId = x.ContractingPartId,
|
|
// AccountIdList = x.AccountIdList,
|
|
|
|
|
|
// #region Checkouts
|
|
|
|
// ////CheckoutLeft befor This Month
|
|
// CheckoutLeftIds = _context.InstitutionContractSet.Any(c => c.ContractingPartyId == x.ContractingPartId && c.ContractStartGr <= currentMonthStart && c.ContractEndGr >= currentMonthEnd) ? x.CheckoutLeftIds : new List<long>(),
|
|
|
|
|
|
// #endregion
|
|
//}).ToList();
|
|
|
|
//var result = workshopsList.Select(x => new ActiveWorkshops
|
|
//{
|
|
// Id = x.Id,
|
|
// CheckoutLeftWorkCount = x.CheckoutLeftIds.Count,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// CheckoutDoneCount = x.CheckoutLeftIds.Count > 0 ? _context.CheckoutSet.Where(ch => ch.WorkshopId == x.Id).Where(ct => x.CheckoutLeftIds.Contains(ct.EmployeeId))
|
|
// .Count(ch =>
|
|
// ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd &&
|
|
// ch.IsActiveString == "true") : 0,
|
|
|
|
|
|
//}).Where(x => x.CheckoutLeftWorkCount > 0).ToList();
|
|
//var workshopList = result.Select(x => new workshopSearch()
|
|
//{
|
|
// Id = x.Id,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// CheckoutDonePercent = ((x.CheckoutDoneCount * 100) / x.CheckoutLeftWorkCount),
|
|
|
|
//}).OrderBy(x => x.CheckoutDonePercent).ToList();
|
|
|
|
//var badWorkshop = workshopList.FirstOrDefault();
|
|
//var badWorkshopLeftWorks = _context.LeftWorkList.Where(l => l.WorkshopId == badWorkshop.Id).Select(l => new LeftWorkViewModel()
|
|
//{
|
|
// Id = l.id,
|
|
// EmployeeId = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
//}).Where(l => (l.StartWorkDateGr <= currentMonthStart && l.LeftWorkDateGr > currentMonthStart) ||
|
|
// (l.StartWorkDateGr <= currentMonthEnd && l.LeftWorkDateGr >= currentMonthEnd) ||
|
|
// (l.StartWorkDateGr >= currentMonthStart && l.StartWorkDateGr <= currentMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= currentMonthStart && l.LeftWorkDateGr <= currentMonthEnd)).ToList();
|
|
//var badWorkshopCheckouts = _context.CheckoutSet.Where(ch => ch.WorkshopId == badWorkshop.Id)
|
|
// .Where(ch =>
|
|
// ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd &&
|
|
// ch.IsActiveString == "true").Select(x => x.EmployeeId).ToList();
|
|
//var notDoneEmployes = badWorkshopLeftWorks.Select(l => new EmployeeNotDone()
|
|
//{
|
|
// Id = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
|
|
//}).Where(l => !badWorkshopCheckouts.Contains(l.Id)).ToList();
|
|
|
|
//var finalResult = new WorkshopResult()
|
|
//{
|
|
// WorkshopSearches = workshopList,
|
|
// EmployeeNotDones = notDoneEmployes,
|
|
//};
|
|
|
|
#region NewChanges
|
|
|
|
//تمام پرسنل فعال برای قراداد در ماه مورد نظر
|
|
var allContractLeftworks = _context.LeftWorkList
|
|
.Where(x => workshopList.Contains(x.WorkshopId))
|
|
.Where(x =>
|
|
x.StartWorkDate <= currentMonthEnd && x.LeftWorkDate > currentMonthStart);
|
|
|
|
var allContractLeftworkWorkshopIds = allContractLeftworks.Select(x => x.WorkshopId).ToList();
|
|
|
|
var allContractToBe = allContractLeftworks
|
|
.Select(x => new { x.EmployeeId, x.WorkshopId })
|
|
.ToList();
|
|
|
|
//تمام قرارداد های ایجاد شده ماه مورد نظر
|
|
var allContractLeftworkEmployeeIds = allContractLeftworks.Select(x => x.EmployeeId);
|
|
|
|
|
|
var allContractCreated = _context.CheckoutSet
|
|
.Where(x => allContractLeftworkEmployeeIds.Contains(x.EmployeeId))
|
|
.Where(x =>
|
|
x.ContractStart.Date <= currentMonthEnd.Date && x.ContractEnd.Date > currentMonthStart.Date && x.IsActiveString == "true");
|
|
|
|
var createdContractTople = allContractCreated
|
|
.Select(x => new { x.EmployeeId, x.WorkshopId })
|
|
.ToList();
|
|
|
|
|
|
//قرارداد هایی که امضاء شده
|
|
var allContractSigned = allContractCreated.Count(x => x.Signature == "1");
|
|
Console.WriteLine("ajax 1 >>>>>: " + watch.Elapsed);
|
|
var workshops = _context.Workshops.Include(x => x.LeftWorks).Where(x => allContractLeftworkWorkshopIds.Contains(x.id)).ToList();
|
|
var workshopListResult = workshops
|
|
.Select(workshop =>
|
|
{
|
|
var toBe = workshop.LeftWorks.Where(x =>
|
|
x.StartWorkDate <= currentMonthEnd && x.LeftWorkDate > currentMonthStart)
|
|
.GroupBy(x => x.EmployeeId)
|
|
.Select(x => x.Key).ToList();
|
|
var contractToBe = toBe.Count();
|
|
//var contractToBe = allContractToBe.Count(x => x.WorkshopId == workshop.id);
|
|
var contractCreated = createdContractTople.Count(x => x.WorkshopId == workshop.id);
|
|
if (contractToBe > 0)
|
|
{
|
|
return new workshopSearch()
|
|
{
|
|
Id = workshop.id,
|
|
WorkshopFullName = workshop.WorkshopFullName,
|
|
ArchiveCode = workshop.ArchiveCode,
|
|
CheckoutDonePercent = ((contractCreated * 100) / contractToBe),
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
})
|
|
.Where(x => x != null)
|
|
.OrderBy(x => x.CheckoutDonePercent)
|
|
.ToList(); // تبدیل به لیست
|
|
if (workshopListResult.Count == 0)
|
|
return new WorkshopResult()
|
|
{
|
|
WorkshopSearches = workshopListResult,
|
|
EmployeeNotDones = new(),
|
|
};
|
|
|
|
var badWorkshop = workshopListResult.FirstOrDefault();
|
|
var badWorkshopTobe = allContractLeftworks.Where(x => x.WorkshopId == badWorkshop.Id);
|
|
var badWorkshopCreated = allContractCreated.Where(x => x.WorkshopId == badWorkshop.Id).Select(x => x.EmployeeId);
|
|
var notDoneEmployes = badWorkshopTobe.Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.EmployeeFullName,
|
|
|
|
}).Where(l => !badWorkshopCreated.Contains(l.Id)).ToList();
|
|
|
|
var finalResult = new WorkshopResult()
|
|
{
|
|
WorkshopSearches = workshopListResult,
|
|
EmployeeNotDones = notDoneEmployes,
|
|
};
|
|
|
|
|
|
#endregion
|
|
Console.WriteLine("ajax >>>>>: " + watch.Elapsed);
|
|
return finalResult;
|
|
}
|
|
|
|
public WorkshopResult GetWorkshopCheckoutSignDone(string year, string month, long accountId,
|
|
List<long> workshopList)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
//var instititionContracts = _context.InstitutionContractSet.Where(x => x.IsActiveString == "true").Select(x => x.ContractingPartyId).ToList();
|
|
//var blockContractingPartyIds = _context.PersonalContractingParties.Where(x => x.IsBlock == "false" && x.IsActiveString == "true").Select(x => x.id).ToList();
|
|
////blockContractingPartyIds = blockContractingPartyIds.Where(x => instititionContracts.Contains(x)).ToList();
|
|
//var workshops = _context.Workshops.Where(x => x.IsActiveString == "true")
|
|
// .Include(x => x.WorkshopEmployers)
|
|
// .Include(x => x.LeftWorks)
|
|
// .Select(x => new ActiveWorkshops
|
|
// {
|
|
// Id = x.id,
|
|
// IsActiveString = x.IsActiveString,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContractingPartId = x.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(),
|
|
// AccountIdList = _context.WorkshopAccounts.Where(m => m.WorkshopId == x.id).Select(a => a.AccountId).ToList(),
|
|
|
|
|
|
// #region Checkouts
|
|
|
|
// //CheckoutLeft befor This Month
|
|
// CheckoutLeftIds = x.LeftWorks.Select(l => new LeftWorkViewModel()
|
|
// {
|
|
// EmployeeId = l.EmployeeId,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
// }).Where(l =>
|
|
// (l.StartWorkDateGr <= currentMonthStart && l.LeftWorkDateGr > currentMonthStart) ||
|
|
// (l.StartWorkDateGr <= currentMonthEnd && l.LeftWorkDateGr >= currentMonthEnd) ||
|
|
// (l.StartWorkDateGr >= currentMonthStart && l.StartWorkDateGr <= currentMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= currentMonthStart && l.LeftWorkDateGr <= currentMonthEnd)).Select(l => l.EmployeeId).ToList(),
|
|
|
|
// #endregion
|
|
|
|
// }).Where(e => blockContractingPartyIds.Contains(e.ContractingPartId))
|
|
// .Where(a => a.AccountIdList.Contains(accountId)).AsSplitQuery();
|
|
//var workshopsList = workshops.Select(x => new ActiveWorkshops
|
|
//{
|
|
// Id = x.Id,
|
|
// IsActiveString = x.IsActiveString,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// ContractingPartId = x.ContractingPartId,
|
|
// AccountIdList = x.AccountIdList,
|
|
|
|
|
|
// #region Checkouts
|
|
|
|
// ////CheckoutLeft befor This Month
|
|
// CheckoutLeftIds = _context.InstitutionContractSet.Any(c => c.ContractingPartyId == x.ContractingPartId && c.ContractStartGr <= currentMonthStart && c.ContractEndGr >= currentMonthEnd) ? x.CheckoutLeftIds : new List<long>(),
|
|
|
|
|
|
// #endregion
|
|
//}).ToList();
|
|
|
|
//var result = workshopsList.Select(x => new ActiveWorkshops
|
|
//{
|
|
// Id = x.Id,
|
|
// CheckoutLeftWorkCount = x.CheckoutLeftIds.Count,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// CheckoutDoneCount = x.CheckoutLeftIds.Count > 0 ? _context.CheckoutSet.Where(ch => ch.WorkshopId == x.Id).Where(ct => x.CheckoutLeftIds.Contains(ct.EmployeeId))
|
|
// .Count(ch =>
|
|
// ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd &&
|
|
// ch.IsActiveString == "true") : 0,
|
|
// CheckoutSignDoneCount = x.CheckoutLeftIds.Count > 0 ? _context.CheckoutSet.Where(ch => ch.WorkshopId == x.Id && ch.Signature == "1").Where(ct => x.CheckoutLeftIds.Contains(ct.EmployeeId))
|
|
// .Count(ch =>
|
|
// ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd &&
|
|
// ch.IsActiveString == "true") : 0,
|
|
|
|
|
|
//}).Where(x => x.CheckoutDoneCount > 0).ToList();
|
|
//var workshopList = result.Select(x => new workshopSearch()
|
|
//{
|
|
// Id = x.Id,
|
|
// WorkshopFullName = x.WorkshopFullName,
|
|
// ArchiveCode = x.ArchiveCode,
|
|
// CheckoutSignPercent = ((x.CheckoutSignDoneCount * 100) / x.CheckoutDoneCount),
|
|
|
|
//}).OrderBy(x => x.CheckoutSignPercent).ToList();
|
|
|
|
//var badWorkshop = workshopList.FirstOrDefault();
|
|
//var badWorkshopLeftWorks = _context.LeftWorkList.Where(l => l.WorkshopId == badWorkshop.Id).Select(l => new LeftWorkViewModel()
|
|
//{
|
|
// Id = l.id,
|
|
// EmployeeId = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
//}).Where(l => (l.StartWorkDateGr <= currentMonthStart && l.LeftWorkDateGr > currentMonthStart) ||
|
|
// (l.StartWorkDateGr <= currentMonthEnd && l.LeftWorkDateGr >= currentMonthEnd) ||
|
|
// (l.StartWorkDateGr >= currentMonthStart && l.StartWorkDateGr <= currentMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= currentMonthStart && l.LeftWorkDateGr <= currentMonthEnd)).ToList();
|
|
//var badWorkshopCheckouts = _context.CheckoutSet.Where(ch => ch.WorkshopId == badWorkshop.Id)
|
|
// .Where(ch =>
|
|
// ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd && ch.Signature == "1" &&
|
|
// ch.IsActiveString == "true").Select(x => x.EmployeeId).ToList();
|
|
//var notDoneEmployes = badWorkshopLeftWorks.Select(l => new EmployeeNotDone()
|
|
//{
|
|
// Id = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
|
|
//}).Where(l => !badWorkshopCheckouts.Contains(l.Id)).ToList();
|
|
|
|
//var finalResult = new WorkshopResult()
|
|
//{
|
|
// WorkshopSearches = workshopList,
|
|
// EmployeeNotDones = notDoneEmployes,
|
|
//};
|
|
|
|
#region NewChanges
|
|
|
|
//تمام پرسنل فعال برای قراداد در ماه مورد نظر
|
|
var allContractLeftworks = _context.LeftWorkList
|
|
.Where(x => workshopList.Contains(x.WorkshopId))
|
|
.Where(x =>
|
|
x.StartWorkDate <= currentMonthEnd && x.LeftWorkDate > currentMonthStart);
|
|
|
|
//تمام قرارداد های ایجاد شده ماه مورد نظر
|
|
var allContractLeftworkEmployeeIds = allContractLeftworks.Select(x => x.EmployeeId);
|
|
|
|
|
|
var allContractCreated = _context.CheckoutSet
|
|
.Where(x => allContractLeftworkEmployeeIds.Contains(x.EmployeeId))
|
|
.Where(x =>
|
|
x.ContractStart.Date <= currentMonthEnd.Date && x.ContractEnd.Date > currentMonthStart.Date && x.IsActiveString == "true");
|
|
|
|
var createdContractWorkshopids = allContractCreated.Select(x => x.WorkshopId).ToList();
|
|
|
|
//قرارداد هایی که امضاء شده
|
|
var allContractSigned = allContractCreated.Where(x => x.Signature == "1");
|
|
var createdContractTople = allContractCreated
|
|
.Select(x => new { x.EmployeeId, x.WorkshopId })
|
|
.ToList();
|
|
var signedContracTople = allContractCreated.Where(x => x.Signature == "1")
|
|
.Select(x => new { x.EmployeeId, x.WorkshopId })
|
|
.ToList();
|
|
Console.WriteLine("ajax 1 >>>>>: " + watch.Elapsed);
|
|
var workshops = _context.Workshops.Where(x => createdContractWorkshopids.Contains(x.id)).ToList();
|
|
var workshopListResult = workshops
|
|
.Select(workshop =>
|
|
{
|
|
//var contractToBe = allContractLeftworks.Count(x => x.WorkshopId == workshop.id);
|
|
var contractCreated = createdContractTople.Count(x => x.WorkshopId == workshop.id);
|
|
var signedContract = signedContracTople.Count(x => x.WorkshopId == workshop.id);
|
|
if (contractCreated > 0)
|
|
{
|
|
return new workshopSearch()
|
|
{
|
|
Id = workshop.id,
|
|
WorkshopFullName = workshop.WorkshopFullName,
|
|
ArchiveCode = workshop.ArchiveCode,
|
|
CheckoutSignPercent = ((signedContract * 100) / contractCreated),
|
|
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
})
|
|
.Where(x => x != null)
|
|
.OrderBy(x => x.CheckoutSignPercent)
|
|
.ToList(); // تبدیل به لیست
|
|
if (workshopListResult.Count == 0)
|
|
return new WorkshopResult()
|
|
{
|
|
WorkshopSearches = workshopListResult,
|
|
EmployeeNotDones = new(),
|
|
};
|
|
|
|
var badWorkshop = workshopListResult.FirstOrDefault();
|
|
var badWorkshopCreated = allContractCreated.Where(x => x.WorkshopId == badWorkshop.Id);
|
|
var badWorkshopSigned = allContractSigned.Where(x => x.WorkshopId == badWorkshop.Id).Select(x => x.EmployeeId);
|
|
var notDoneEmployes = badWorkshopCreated.Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.EmployeeFullName,
|
|
|
|
}).Where(l => !badWorkshopSigned.Contains(l.Id)).ToList();
|
|
|
|
var finalResult = new WorkshopResult()
|
|
{
|
|
WorkshopSearches = workshopListResult,
|
|
EmployeeNotDones = notDoneEmployes,
|
|
};
|
|
|
|
|
|
#endregion
|
|
Console.WriteLine("ajax >>>>>: " + watch.Elapsed);
|
|
return finalResult;
|
|
}
|
|
|
|
#region getEmployeeNotDonBySelectWorkshop
|
|
|
|
public List<EmployeeNotDone> GetEmployeeContract(string year, string month, long workshopId)
|
|
{
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
// پرسنلی که باید انجام میشد
|
|
//var workshopLeftWorks = _context.LeftWorkList.Where(l => l.WorkshopId == workshopId).Select(l => new LeftWorkViewModel()
|
|
//{
|
|
// Id = l.id,
|
|
// EmployeeId = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
//}).Where(l =>
|
|
// (l.StartWorkDateGr <= nextMonthStart && l.LeftWorkDateGr > nextMonthStart) ||
|
|
// (l.StartWorkDateGr <= nextMonthEnd && l.LeftWorkDateGr >= nextMonthEnd) ||
|
|
// (l.StartWorkDateGr >= nextMonthStart && l.StartWorkDateGr <= nextMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= nextMonthStart && l.LeftWorkDateGr <= nextMonthEnd)).ToList();
|
|
////پرسنلی که کارشان انجام شده
|
|
//var workshopContracts = _context.Contracts.Where(ct => ct.WorkshopIds == workshopId && ct.IsActiveString == "true")
|
|
// .Where(l => (l.ContarctStart <= nextMonthStart && l.ContractEnd >= nextMonthStart) ||
|
|
// (l.ContarctStart <= nextMonthEnd && l.ContractEnd >= nextMonthEnd) ||
|
|
// (l.ContarctStart >= nextMonthStart && l.ContarctStart <= nextMonthEnd) ||
|
|
// (l.ContractEnd >= nextMonthStart && l.ContractEnd <= nextMonthEnd)).Select(x => x.EmployeeId).ToList();
|
|
|
|
|
|
|
|
#region New
|
|
|
|
var allContractLeftworks = _context.LeftWorkList
|
|
.Where(x => x.WorkshopId == workshopId)
|
|
.Where(x =>
|
|
x.StartWorkDate <= nextMonthEnd && x.LeftWorkDate > nextMonthStart);
|
|
var allContractLeftworkEmployeeIds = allContractLeftworks.Select(x => x.EmployeeId).ToList();
|
|
var allContractCreated = _context.Contracts
|
|
.Where(x => allContractLeftworkEmployeeIds.Contains(x.EmployeeId) && x.WorkshopIds == workshopId)
|
|
.Where(x =>
|
|
x.ContarctStart.Date <= nextMonthEnd.Date && x.ContractEnd.Date > nextMonthStart.Date && x.IsActiveString == "true");
|
|
var allContractCreatedEmoployeeIds = allContractCreated.Select(x => x.EmployeeId).ToList();
|
|
|
|
return allContractLeftworks.Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.EmployeeFullName,
|
|
}).Where(x => !allContractCreatedEmoployeeIds.Contains(x.Id)).ToList();
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
public List<EmployeeNotDone> GetEmployeeContractSign(string year, string month, long workshopId)
|
|
{
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
//var badWorkshopLeftWorks = _context.LeftWorkList.Where(l => l.WorkshopId == workshopId).Select(l => new LeftWorkViewModel()
|
|
//{
|
|
// Id = l.id,
|
|
// EmployeeId = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
//}).Where(l =>
|
|
// (l.StartWorkDateGr <= nextMonthStart && l.LeftWorkDateGr > nextMonthStart) ||
|
|
// (l.StartWorkDateGr <= nextMonthEnd && l.LeftWorkDateGr >= nextMonthEnd) ||
|
|
// (l.StartWorkDateGr >= nextMonthStart && l.StartWorkDateGr <= nextMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= nextMonthStart && l.LeftWorkDateGr <= nextMonthEnd)).ToList();
|
|
//var badWorkshopContracts = _context.Contracts.Where(ct => ct.WorkshopIds == workshopId && ct.IsActiveString == "true" && ct.Signature == "1")
|
|
// .Where(l => (l.ContarctStart <= nextMonthStart && l.ContractEnd >= nextMonthStart) ||
|
|
// (l.ContarctStart <= nextMonthEnd && l.ContractEnd >= nextMonthEnd) ||
|
|
// (l.ContarctStart >= nextMonthStart && l.ContarctStart <= nextMonthEnd) ||
|
|
// (l.ContractEnd >= nextMonthStart && l.ContractEnd <= nextMonthEnd)).Select(x => x.EmployeeId).ToList();
|
|
|
|
#region New
|
|
|
|
|
|
var allContractNotSignedEmployeeIds = _context.Contracts
|
|
.Where(x => x.WorkshopIds == workshopId)
|
|
.Where(x =>
|
|
x.ContarctStart.Date <= nextMonthEnd.Date && x.ContractEnd.Date > nextMonthStart.Date && x.IsActiveString == "true" && x.Signature == "0")
|
|
.Select(x => x.EmployeeId)
|
|
.ToList();
|
|
if (allContractNotSignedEmployeeIds.Count == 0)
|
|
return new List<EmployeeNotDone>();
|
|
|
|
return _context.Employees.Where(x => allContractNotSignedEmployeeIds.Contains(x.id))
|
|
.Select(x => new EmployeeNotDone()
|
|
{
|
|
Id = x.id,
|
|
EmployeeFullName = x.FullName
|
|
|
|
}).ToList();
|
|
#endregion
|
|
|
|
}
|
|
|
|
public List<EmployeeNotDone> GetEmployeeCheckout(string year, string month, long workshopId)
|
|
{
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
//var badWorkshopLeftWorks = _context.LeftWorkList.Where(l => l.WorkshopId == workshopId).Select(l => new LeftWorkViewModel()
|
|
//{
|
|
// Id = l.id,
|
|
// EmployeeId = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
//}).Where(l => (l.StartWorkDateGr <= currentMonthStart && l.LeftWorkDateGr > currentMonthStart) ||
|
|
// (l.StartWorkDateGr <= currentMonthEnd && l.LeftWorkDateGr >= currentMonthEnd) ||
|
|
// (l.StartWorkDateGr >= currentMonthStart && l.StartWorkDateGr <= currentMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= currentMonthStart && l.LeftWorkDateGr <= currentMonthEnd)).ToList();
|
|
//var badWorkshopCheckouts = _context.CheckoutSet.Where(ch => ch.WorkshopId == workshopId)
|
|
// .Where(ch =>
|
|
// ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd &&
|
|
// ch.IsActiveString == "true").Select(x => x.EmployeeId).ToList();
|
|
//return badWorkshopLeftWorks.Select(l => new EmployeeNotDone()
|
|
//{
|
|
// Id = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
//}).Where(l => !badWorkshopCheckouts.Contains(l.Id)).ToList();
|
|
|
|
#region New
|
|
|
|
var allContractLeftworks = _context.LeftWorkList
|
|
.Where(x => x.WorkshopId == workshopId)
|
|
.Where(x =>
|
|
x.StartWorkDate <= currentMonthEnd && x.LeftWorkDate > currentMonthStart);
|
|
var allContractLeftworkEmployeeIds = allContractLeftworks.Select(x => x.EmployeeId).ToList();
|
|
var allContractCreated = _context.CheckoutSet
|
|
.Where(x => allContractLeftworkEmployeeIds.Contains(x.EmployeeId) && x.WorkshopId == workshopId)
|
|
.Where(x =>
|
|
x.ContractStart.Date <= currentMonthEnd.Date && x.ContractEnd.Date > currentMonthStart.Date && x.IsActiveString == "true");
|
|
var allContractCreatedEmoployeeIds = allContractCreated.Select(x => x.EmployeeId).ToList();
|
|
|
|
return allContractLeftworks.Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.EmployeeFullName,
|
|
}).Where(x => !allContractCreatedEmoployeeIds.Contains(x.Id)).ToList();
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
public List<EmployeeNotDone> GetEmployeeCheckoutSign(string year, string month, long workshopId)
|
|
{
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
//var badWorkshopLeftWorks = _context.LeftWorkList.Where(l => l.WorkshopId == workshopId).Select(l => new LeftWorkViewModel()
|
|
//{
|
|
// Id = l.id,
|
|
// EmployeeId = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
// StartWorkDateGr = l.StartWorkDate,
|
|
// LeftWorkDateGr = l.LeftWorkDate.AddDays(-1),
|
|
|
|
//}).Where(l => (l.StartWorkDateGr <= currentMonthStart && l.LeftWorkDateGr > currentMonthStart) ||
|
|
// (l.StartWorkDateGr <= currentMonthEnd && l.LeftWorkDateGr >= currentMonthEnd) ||
|
|
// (l.StartWorkDateGr >= currentMonthStart && l.StartWorkDateGr <= currentMonthEnd) ||
|
|
// (l.LeftWorkDateGr >= currentMonthStart && l.LeftWorkDateGr <= currentMonthEnd)).ToList();
|
|
//var badWorkshopCheckouts = _context.CheckoutSet.Where(ch => ch.WorkshopId == workshopId)
|
|
// .Where(ch =>
|
|
// ch.ContractStart >= currentMonthStart && ch.ContractStart < currentMonthEnd && ch.Signature == "1" &&
|
|
// ch.IsActiveString == "true").Select(x => x.EmployeeId).ToList();
|
|
|
|
|
|
#region New
|
|
|
|
|
|
var allCheckoutNotSignedEmployeeIds = _context.CheckoutSet
|
|
.Where(x => x.WorkshopId == workshopId)
|
|
.Where(x =>
|
|
x.ContractStart.Date <= currentMonthEnd.Date && x.ContractEnd.Date > currentMonthStart.Date && x.IsActiveString == "true" && x.Signature == "0")
|
|
.Select(x => x.EmployeeId)
|
|
.ToList();
|
|
if (allCheckoutNotSignedEmployeeIds.Count == 0)
|
|
return new List<EmployeeNotDone>();
|
|
|
|
return _context.Employees.Where(x => allCheckoutNotSignedEmployeeIds.Contains(x.id))
|
|
.Select(x => new EmployeeNotDone()
|
|
{
|
|
Id = x.id,
|
|
EmployeeFullName = x.FullName
|
|
|
|
}).ToList();
|
|
#endregion
|
|
//return badWorkshopLeftWorks.Select(l => new EmployeeNotDone()
|
|
//{
|
|
// Id = l.EmployeeId,
|
|
// EmployeeFullName = l.EmployeeFullName,
|
|
//}).Where(l => !badWorkshopCheckouts.Contains(l.Id)).ToList();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region PrintAll
|
|
public PrintAllContractCheckout GetPrintAllContractDone(string year, string month, long accountId,
|
|
List<long> workshopList)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
#region New
|
|
|
|
|
|
var accountWorkshopList = _context.Workshops
|
|
.Where(x => workshopList.Contains(x.id))
|
|
.Include(x => x.LeftWorks.Where(left =>
|
|
left.StartWorkDate <= nextMonthEnd && left.LeftWorkDate > nextMonthStart))
|
|
.Include(x => x.Contracts2.Where(contract =>
|
|
contract.ContarctStart.Date <= nextMonthEnd.Date && contract.ContractEnd.Date > nextMonthStart.Date &&
|
|
contract.IsActiveString == "true")).ToList();
|
|
|
|
var notCompletedWorkshops = accountWorkshopList.Select(workshop =>
|
|
{
|
|
var lefts = workshop.LeftWorks.Select(x => new { x.EmployeeId, x.EmployeeFullName }).Distinct().ToList();
|
|
var contractToBe = lefts.Count;
|
|
var contractCreated = workshop.Contracts2.Count();
|
|
var createdContractEmployeeIdList = workshop.Contracts2.Select(x => x.EmployeeId).ToList();
|
|
var contractDonePercent = contractToBe > 0 ? ((contractCreated * 100) / contractToBe) : 100;
|
|
if (contractDonePercent < 100)
|
|
{
|
|
|
|
var employeeNotDone =
|
|
lefts.Where(x => !createdContractEmployeeIdList.Contains(x.EmployeeId)).Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.EmployeeFullName,
|
|
|
|
}).ToList();
|
|
return new workshopSearch()
|
|
{
|
|
Id = workshop.id,
|
|
WorkshopFullName = workshop.WorkshopFullName,
|
|
ArchiveCode = workshop.ArchiveCode,
|
|
ContractDonePercent = contractDonePercent,
|
|
EmployeeNotDones = employeeNotDone
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}).Where(x => x != null)
|
|
.OrderBy(x => x.ContractDonePercent)
|
|
.ToList();
|
|
|
|
#endregion
|
|
|
|
|
|
var finalResult = new PrintAllContractCheckout()
|
|
{
|
|
AccountId = accountId,
|
|
AccountFullName = _accountContext.Accounts.FirstOrDefault(x => x.id == accountId)?.Fullname,
|
|
Year = $"{nextMonthStartFa.Year}",
|
|
Month = nextMonthStartFa.Month.ToFarsiMonthByIntNumber(),
|
|
ReportType = "تنظیم قرارداد",
|
|
WorkshopSearches = notCompletedWorkshops,
|
|
};
|
|
|
|
Console.WriteLine("ajax >>>>>: " + watch.Elapsed);
|
|
return finalResult;
|
|
}
|
|
|
|
public PrintAllContractCheckout GetPrintAllContractSignDone(string year, string month, long accountId,
|
|
List<long> workshopList)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
|
|
#region New
|
|
|
|
|
|
var accountWorkshopList = _context.Workshops
|
|
.Where(x => workshopList.Contains(x.id)).Include(x => x.LeftWorks.Where(left =>
|
|
left.StartWorkDate <= nextMonthEnd && left.LeftWorkDate > nextMonthStart))
|
|
.Include(x => x.Contracts2.Where(contract =>
|
|
contract.ContarctStart.Date <= nextMonthEnd.Date && contract.ContractEnd.Date > nextMonthStart.Date &&
|
|
contract.IsActiveString == "true")).ToList();
|
|
|
|
var notCompletedWorkshops = accountWorkshopList.Select(workshop =>
|
|
{
|
|
var contractSigned = workshop.Contracts2.Count(x => x.Signature == "1");
|
|
var contractCreated = workshop.Contracts2.Count();
|
|
int contractSignedPercent = 0;
|
|
if (contractSigned > 0)
|
|
{
|
|
contractSignedPercent = workshop.Contracts2.Any(x => x.Signature == "0") ? ((contractSigned * 100) / contractCreated) : 100;
|
|
}
|
|
else
|
|
{
|
|
contractSignedPercent = 0;
|
|
}
|
|
|
|
if (contractSignedPercent < 100 && contractCreated > 0)
|
|
{
|
|
|
|
var employeeNotDone =
|
|
workshop.Contracts2.Where(x => x.Signature == "0").Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = workshop.LeftWorks.FirstOrDefault(x => x.EmployeeId == l.EmployeeId)!.EmployeeFullName,
|
|
|
|
}).ToList();
|
|
return new workshopSearch()
|
|
{
|
|
Id = workshop.id,
|
|
WorkshopFullName = workshop.WorkshopFullName,
|
|
ArchiveCode = workshop.ArchiveCode,
|
|
ContractSignPercent = contractSignedPercent,
|
|
EmployeeNotDones = employeeNotDone
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}).Where(x => x != null)
|
|
.OrderBy(x => x.ContractSignPercent)
|
|
.ToList();
|
|
|
|
#endregion
|
|
|
|
|
|
var finalResult = new PrintAllContractCheckout()
|
|
{
|
|
AccountId = accountId,
|
|
AccountFullName = _accountContext.Accounts.FirstOrDefault(x => x.id == accountId)?.Fullname,
|
|
Year = $"{nextMonthStartFa.Year}",
|
|
Month = nextMonthStartFa.Month.ToFarsiMonthByIntNumber(),
|
|
ReportType = "امضاء قرارداد",
|
|
WorkshopSearches = notCompletedWorkshops,
|
|
};
|
|
Console.WriteLine("ajax >>>>>: " + watch.Elapsed);
|
|
return finalResult;
|
|
}
|
|
|
|
public PrintAllContractCheckout GetPrintAllCheckoutDone(string year, string month, long accountId,
|
|
List<long> workshopList)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
#region New
|
|
|
|
|
|
var accountWorkshopList = _context.Workshops
|
|
.Where(x => workshopList.Contains(x.id))
|
|
.Include(x => x.LeftWorks.Where(left =>
|
|
left.StartWorkDate <= currentMonthEnd && left.LeftWorkDate > currentMonthStart))
|
|
.Include(x => x.Checkouts.Where(contract =>
|
|
contract.ContractStart.Date <= currentMonthEnd.Date && contract.ContractEnd.Date > currentMonthStart.Date &&
|
|
contract.IsActiveString == "true")).ToList();
|
|
|
|
var notCompletedWorkshops = accountWorkshopList.Select(workshop =>
|
|
{
|
|
var lefts = workshop.LeftWorks.Select(x => new { x.EmployeeId, x.EmployeeFullName }).Distinct().ToList();
|
|
var contractToBe = lefts.Count;
|
|
var contractCreated = workshop.Checkouts.Count();
|
|
var createdContractEmployeeIdList = workshop.Checkouts.Select(x => x.EmployeeId).ToList();
|
|
var contractDonePercent = contractToBe > 0 ? ((contractCreated * 100) / contractToBe) : 100;
|
|
if (contractDonePercent < 100)
|
|
{
|
|
|
|
var employeeNotDone =
|
|
lefts.Where(x => !createdContractEmployeeIdList.Contains(x.EmployeeId)).Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.EmployeeFullName,
|
|
|
|
}).ToList();
|
|
return new workshopSearch()
|
|
{
|
|
Id = workshop.id,
|
|
WorkshopFullName = workshop.WorkshopFullName,
|
|
ArchiveCode = workshop.ArchiveCode,
|
|
CheckoutDonePercent = contractDonePercent,
|
|
EmployeeNotDones = employeeNotDone
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}).Where(x => x != null)
|
|
.OrderBy(x => x.ContractDonePercent)
|
|
.ToList();
|
|
|
|
#endregion
|
|
|
|
var finalResult = new PrintAllContractCheckout()
|
|
{
|
|
AccountId = accountId,
|
|
AccountFullName = _accountContext.Accounts.FirstOrDefault(x => x.id == accountId)?.Fullname,
|
|
Year = year,
|
|
Month = month.ToFarsiMonthByNumber(),
|
|
ReportType = "تنظیم تصفیه حساب",
|
|
WorkshopSearches = notCompletedWorkshops,
|
|
};
|
|
Console.WriteLine("ajax >>>>>: " + watch.Elapsed);
|
|
return finalResult;
|
|
}
|
|
|
|
public PrintAllContractCheckout GetPrintAllCheckoutSignDone(string year, string month, long accountId,
|
|
List<long> workshopList)
|
|
{
|
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
string nowFa = "";
|
|
if (!string.IsNullOrWhiteSpace(year) && !string.IsNullOrWhiteSpace(month))
|
|
{
|
|
nowFa = $"{year}/{month}/01";
|
|
}
|
|
else
|
|
{
|
|
nowFa = $"{(DateTime.Now.ToFarsi()).Substring(0, 8)}01";
|
|
}
|
|
|
|
var currentEndOfMonth = nowFa.FindeEndOfMonth();
|
|
|
|
var currentMonthStart = nowFa.ToGeorgianDateTime();
|
|
var currentMonthEnd = currentEndOfMonth.ToGeorgianDateTime();
|
|
int currentYear = Convert.ToInt32(nowFa.Substring(0, 4));
|
|
var currentMonth = Convert.ToInt32(nowFa.Substring(5, 2));
|
|
var nextMonthStartFa = new PersianDateTime(currentYear, currentMonth, 1).AddMonths(1);
|
|
var nextMonthStart = ($"{nextMonthStartFa}").ToGeorgianDateTime();
|
|
var nextMonthEnd = (($"{nextMonthStartFa}").FindeEndOfMonth()).ToGeorgianDateTime();
|
|
|
|
|
|
#region New
|
|
|
|
|
|
var accountWorkshopList = _context.Workshops
|
|
.Where(x => workshopList.Contains(x.id))
|
|
.Include(x => x.Checkouts.Where(contract =>
|
|
contract.ContractStart.Date <= currentMonthEnd.Date && contract.ContractEnd.Date > currentMonthStart.Date &&
|
|
contract.IsActiveString == "true")).ToList();
|
|
|
|
var notCompletedWorkshops = accountWorkshopList.Select(workshop =>
|
|
{
|
|
var checkoutSigned = workshop.Checkouts.Count(x => x.Signature == "1");
|
|
var checkoutCreated = workshop.Checkouts.Count();
|
|
|
|
var contractSignedPercent = workshop.Checkouts.Any(x => x.Signature == "0") ? ((checkoutSigned * 100) / checkoutCreated) : 100;
|
|
if (contractSignedPercent < 100 && checkoutCreated > 0)
|
|
{
|
|
|
|
var employeeNotDone =
|
|
workshop.Checkouts.Where(x => x.Signature == "0").Select(l => new EmployeeNotDone()
|
|
{
|
|
Id = l.EmployeeId,
|
|
EmployeeFullName = l.EmployeeFullName,
|
|
|
|
}).ToList();
|
|
return new workshopSearch()
|
|
{
|
|
Id = workshop.id,
|
|
WorkshopFullName = workshop.WorkshopFullName,
|
|
ArchiveCode = workshop.ArchiveCode,
|
|
CheckoutSignPercent = contractSignedPercent,
|
|
EmployeeNotDones = employeeNotDone
|
|
};
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}).Where(x => x != null)
|
|
.OrderBy(x => x.CheckoutSignPercent)
|
|
.ToList();
|
|
|
|
#endregion
|
|
var finalResult = new PrintAllContractCheckout()
|
|
{
|
|
AccountId = accountId,
|
|
AccountFullName = _accountContext.Accounts.FirstOrDefault(x => x.id == accountId)?.Fullname,
|
|
Year = year,
|
|
Month = month.ToFarsiMonthByNumber(),
|
|
ReportType = "امضاء تصفیه حساب",
|
|
WorkshopSearches = notCompletedWorkshops,
|
|
};
|
|
Console.WriteLine("ajax >>>>>: " + watch.Elapsed);
|
|
return finalResult;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
|
|
|