605 lines
25 KiB
C#
605 lines
25 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.ContractingPartyAccountAgg;
|
|
using Company.Domain.empolyerAgg;
|
|
using Company.Domain.InstitutionContractAgg;
|
|
using Company.Domain.WorkshopAccountAgg;
|
|
using Company.Domain.WorkshopAgg;
|
|
using CompanyManagment.App.Contracts.Employee;
|
|
using CompanyManagment.App.Contracts.Employer;
|
|
using CompanyManagment.App.Contracts.FinancialStatment;
|
|
using CompanyManagment.App.Contracts.InstitutionContract;
|
|
using CompanyManagment.App.Contracts.LeftWork;
|
|
using CompanyManagment.App.Contracts.LeftWorkInsurance;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PersianTools.Core;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class InstitutionContractRepository : RepositoryBase<long, InstitutionContract>, IInstitutionContractRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
private readonly IEmployerRepository _employerRepository;
|
|
private readonly IWorkshopRepository _workshopRepository;
|
|
public InstitutionContractRepository(CompanyContext context, IEmployerRepository employerRepository, IWorkshopRepository workshopRepository) : base(context)
|
|
{
|
|
_context = context;
|
|
_employerRepository = employerRepository;
|
|
_workshopRepository = workshopRepository;
|
|
}
|
|
|
|
public EditInstitutionContract GetDetails(long id)
|
|
{
|
|
return _context.InstitutionContractSet.Select(x => new EditInstitutionContract()
|
|
{
|
|
Id = x.id,
|
|
ContractNo = x.ContractNo,
|
|
ContractStartGr = x.ContractStartGr,
|
|
ContractStartFa = x.ContractStartFa,
|
|
ContractEndGr = x.ContractEndGr,
|
|
ContractEndFa = x.ContractEndFa,
|
|
RepresentativeName = x.RepresentativeName,
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
RepresentativeId = x.RepresentativeId,
|
|
ContractingPartyId = x.ContractingPartyId,
|
|
ContractDateFa = x.ContractDateFa,
|
|
State = x.State,
|
|
City = x.City,
|
|
Address = x.Address,
|
|
Description = x.Description,
|
|
WorkshopManualCount = x.WorkshopManualCount,
|
|
EmployeeManualCount = x.EmployeeManualCount,
|
|
ContractAmountString = x.ContractAmount.ToMoney(),
|
|
ContractAmount = x.ContractAmount,
|
|
DailyCompenseationString = x.DailyCompenseation.ToMoney(),
|
|
ObligationString = x.Obligation.ToMoney(),
|
|
TotalAmountString = x.TotalAmount.ToMoney(),
|
|
ExtensionNo = x.ExtensionNo,
|
|
OfficialCompany = x.OfficialCompany,
|
|
TypeOfContract = x.TypeOfContract,
|
|
Signature = x.Signature,
|
|
HasValueAddedTax = x.HasValueAddedTax,
|
|
ValueAddedTax = x.ValueAddedTax,
|
|
|
|
})
|
|
.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public EditInstitutionContract GetFirstContract(long contractingPartyId, string typeOfContract)
|
|
{
|
|
return _context.InstitutionContractSet.Select(x => new EditInstitutionContract()
|
|
{
|
|
Id = x.id,
|
|
ContractNo = x.ContractNo,
|
|
ContractStartGr = x.ContractStartGr,
|
|
ContractStartFa = x.ContractStartFa,
|
|
ContractEndGr = x.ContractEndGr,
|
|
ContractEndFa = x.ContractEndFa,
|
|
RepresentativeName = x.RepresentativeName,
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
RepresentativeId = x.RepresentativeId,
|
|
ContractingPartyId = x.ContractingPartyId,
|
|
ContractDateFa = x.ContractDateFa,
|
|
State = x.State,
|
|
City = x.City,
|
|
Address = x.Address,
|
|
Description = x.Description,
|
|
WorkshopManualCount = x.WorkshopManualCount,
|
|
EmployeeManualCount = x.EmployeeManualCount,
|
|
ContractAmountString = x.ContractAmount.ToMoney(),
|
|
DailyCompenseationString = x.DailyCompenseation.ToMoney(),
|
|
ObligationString = x.Obligation.ToMoney(),
|
|
TotalAmountString = x.TotalAmount.ToMoney(),
|
|
ExtensionNo = x.ExtensionNo,
|
|
OfficialCompany = x.OfficialCompany,
|
|
TypeOfContract = x.TypeOfContract,
|
|
Signature = x.Signature
|
|
|
|
})
|
|
.Where(x => x.ContractingPartyId == contractingPartyId && x.TypeOfContract == typeOfContract).OrderBy(x => x.ExtensionNo).FirstOrDefault();
|
|
}
|
|
|
|
|
|
public List<InstitutionContractViewModel> Search(InstitutionContractSearchModel searchModel)
|
|
{
|
|
//var stored = _context.InstitutionContractSet.FromSqlInterpolated($"SelectQuery_InstitutionContract").AsNoTracking()
|
|
// .ToList();
|
|
|
|
var query = _context.InstitutionContractSet.Select(x => new InstitutionContractViewModel()
|
|
{
|
|
Id = x.id,
|
|
ContractNo = x.ContractNo,
|
|
ContractStartGr = x.ContractStartGr,
|
|
ContractStartFa = x.ContractStartFa,
|
|
ContractEndGr = x.ContractEndGr,
|
|
ContractEndFa = x.ContractEndFa,
|
|
RepresentativeId = x.RepresentativeId,
|
|
RepresentativeName = x.RepresentativeName,
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
ContractingPartyId = x.ContractingPartyId,
|
|
ContractAmount = x.ContractAmount.ToMoney(),
|
|
TotalAmount = x.TotalAmount.ToMoney(),
|
|
SearchAmount = x.ContractAmount,
|
|
IsActiveString = x.IsActiveString,
|
|
OfficialCompany = x.OfficialCompany,
|
|
TypeOfContract = x.TypeOfContract,
|
|
Signature = x.Signature
|
|
|
|
|
|
});
|
|
|
|
if (searchModel.Id != 0)
|
|
query = query.Where(x => x.Id == searchModel.Id);
|
|
if (searchModel.RepresentativeId != 0)
|
|
query = query.Where(x => x.RepresentativeId == searchModel.RepresentativeId);
|
|
if (searchModel.ContractingPartyId != 0)
|
|
query = query.Where(x => x.ContractingPartyId == searchModel.ContractingPartyId);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.StartAmount) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.EndAmount))
|
|
{
|
|
var start = Convert.ToDouble(searchModel.StartAmount);
|
|
var end = Convert.ToDouble(searchModel.EndAmount);
|
|
query = query.Where(x =>
|
|
x.SearchAmount >= start && x.SearchAmount <= end);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(searchModel.StartAmount) &&
|
|
string.IsNullOrWhiteSpace(searchModel.EndAmount))
|
|
{
|
|
var start = Convert.ToDouble(searchModel.StartAmount);
|
|
var end = Convert.ToDouble(searchModel.EndAmount);
|
|
query = query.Where(x =>
|
|
x.SearchAmount >= start);
|
|
}
|
|
if (string.IsNullOrWhiteSpace(searchModel.StartAmount) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.EndAmount))
|
|
{
|
|
var start = Convert.ToDouble(searchModel.StartAmount);
|
|
var end = Convert.ToDouble(searchModel.EndAmount);
|
|
query = query.Where(x =>
|
|
x.SearchAmount >= start);
|
|
query = query.Where(x =>
|
|
x.SearchAmount <= end);
|
|
|
|
}
|
|
|
|
if (searchModel.IsActiveString == null)
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "true" || x.IsActiveString == "blue");
|
|
}
|
|
|
|
if (searchModel.IsActiveString == "false")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false");
|
|
}
|
|
else if (searchModel.IsActiveString == "both")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false" || x.IsActiveString == "true" || x.IsActiveString == "blue");
|
|
}
|
|
|
|
if (searchModel.OfficialCompany == "Official")
|
|
query = query.Where(x => x.OfficialCompany == "Official");
|
|
if (searchModel.OfficialCompany == "NotOfficial")
|
|
query = query.Where(x => x.OfficialCompany == "NotOfficial");
|
|
|
|
if (searchModel.TypeOfContract == "both")
|
|
{
|
|
query = query.Where(x => x.TypeOfContract == "JobRelation" || x.TypeOfContract == "taxAndFinancial");
|
|
}
|
|
else if (searchModel.TypeOfContract == "JobRelation" || string.IsNullOrWhiteSpace(searchModel.TypeOfContract))
|
|
{
|
|
query = query.Where(x => x.TypeOfContract == "JobRelation");
|
|
}
|
|
else if (searchModel.TypeOfContract == "taxAndFinancial")
|
|
{
|
|
query = query.Where(x => x.TypeOfContract == "taxAndFinancial");
|
|
}
|
|
|
|
|
|
if (searchModel.Signature == "2")
|
|
{
|
|
query = query.Where(x => x.Signature == "0" || x.Signature == "1");
|
|
}
|
|
|
|
if (searchModel.Signature == "1")
|
|
{
|
|
query = query.Where(x => x.Signature == "1");
|
|
}
|
|
else if (searchModel.Signature == "0")
|
|
{
|
|
query = query.Where(x => x.Signature == "0");
|
|
}
|
|
//var sumList = query.Select(x => x.SearchAmount).ToList();
|
|
//double sum = 0;
|
|
//foreach (var amount in sumList)
|
|
//{
|
|
// sum += amount;
|
|
//}
|
|
//Console.WriteLine(sum);
|
|
|
|
|
|
return query.OrderByDescending(x => x.Id).ToList();
|
|
}
|
|
|
|
public List<InstitutionContractViewModel> NewSearch(InstitutionContractSearchModel searchModel)
|
|
{
|
|
var timer = Stopwatch.StartNew();
|
|
var query = _context.InstitutionContractSet.Select(x => new InstitutionContractViewModel()
|
|
{
|
|
Id = x.id,
|
|
ContractNo = x.ContractNo,
|
|
ContractStartGr = x.ContractStartGr,
|
|
ContractStartFa = x.ContractStartFa,
|
|
ContractEndGr = x.ContractEndGr,
|
|
ContractEndFa = x.ContractEndFa,
|
|
RepresentativeId = x.RepresentativeId,
|
|
RepresentativeName = x.RepresentativeName,
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
ContractingPartyId = x.ContractingPartyId,
|
|
ContractAmount = x.ContractAmount.ToMoney(),
|
|
TotalAmount = x.TotalAmount.ToMoney(),
|
|
SearchAmount = x.ContractAmount,
|
|
IsActiveString = x.IsActiveString,
|
|
OfficialCompany = x.OfficialCompany,
|
|
TypeOfContract = x.TypeOfContract,
|
|
Signature = x.Signature,
|
|
|
|
WorkshopCount = "",
|
|
//WorkshopViewModels = _context.Workshops.Include(w=>w.WorkshopEmployers).Include(w => w.LeftWorks).Include(w => w.LeftWorkInsurances).Select(w => new WorkshopViewModel()
|
|
//{
|
|
// Id = w.id,
|
|
// WorkshopName = w.WorkshopName,
|
|
// WorkshopFullName = w.WorkshopFullName,
|
|
// ArchiveCode = w.ArchiveCode,
|
|
// ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(),
|
|
// LeftWorkIds = w.LeftWorks.Where(l => l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now).Select(l => l.EmployeeId).ToList(),
|
|
// InsuranceLeftWorkIds = w.LeftWorkInsurances.Where(l => (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now) || (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate == null)).Select(l => l.EmployeeId).ToList(),
|
|
//}).Where(w=>w.ContractingPartId == x.ContractingPartyId).ToList(),
|
|
WorkshopIds = _context.Workshops.Include(w => w.WorkshopEmployers).Select(w => new WorkshopViewModel()
|
|
{
|
|
Id = w.id,
|
|
ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(),
|
|
|
|
}).Where(c => c.ContractingPartId == x.ContractingPartyId).Select(w => w.Id).ToList(),
|
|
EmployerViewModels = _context.Employers.Where(e => e.ContractingPartyId == x.ContractingPartyId).Select(e =>
|
|
new EmployerViewModel()
|
|
{
|
|
Id = e.id,
|
|
FullName = e.FName + " " + e.LName,
|
|
|
|
}).GroupBy(e => e.Id).Select(e => e.First()).ToList(),
|
|
EmployerIds = _context.Employers.Where(e => e.ContractingPartyId == x.ContractingPartyId).Select(e => e.id).ToList(),
|
|
EmployerNo = "",
|
|
EmployerName = "",
|
|
|
|
IsContractingPartyBlock = _context.PersonalContractingParties.Any(p => p.id == x.ContractingPartyId && p.IsBlock == "true") ? "true" : "false",
|
|
BlockTimes = _context.PersonalContractingParties.Any(p => p.id == x.ContractingPartyId) ? _context.PersonalContractingParties.FirstOrDefault(p => p.id == x.ContractingPartyId).BlockTimes : 0,
|
|
|
|
});
|
|
|
|
if (searchModel.Id != 0)
|
|
query = query.Where(x => x.Id == searchModel.Id);
|
|
if (searchModel.RepresentativeId != 0)
|
|
query = query.Where(x => x.RepresentativeId == searchModel.RepresentativeId);
|
|
if (searchModel.ContractingPartyId != 0)
|
|
query = query.Where(x => x.ContractingPartyId == searchModel.ContractingPartyId);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.StartAmount) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.EndAmount))
|
|
{
|
|
var start = Convert.ToDouble(searchModel.StartAmount);
|
|
var end = Convert.ToDouble(searchModel.EndAmount);
|
|
query = query.Where(x =>
|
|
x.SearchAmount >= start && x.SearchAmount <= end);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(searchModel.StartAmount) &&
|
|
string.IsNullOrWhiteSpace(searchModel.EndAmount))
|
|
{
|
|
var start = Convert.ToDouble(searchModel.StartAmount);
|
|
var end = Convert.ToDouble(searchModel.EndAmount);
|
|
query = query.Where(x =>
|
|
x.SearchAmount >= start);
|
|
}
|
|
if (string.IsNullOrWhiteSpace(searchModel.StartAmount) &&
|
|
!string.IsNullOrWhiteSpace(searchModel.EndAmount))
|
|
{
|
|
var start = Convert.ToDouble(searchModel.StartAmount);
|
|
var end = Convert.ToDouble(searchModel.EndAmount);
|
|
query = query.Where(x =>
|
|
x.SearchAmount >= start);
|
|
query = query.Where(x =>
|
|
x.SearchAmount <= end);
|
|
|
|
}
|
|
|
|
|
|
if (searchModel.IsActiveString == null)
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "true" || x.IsActiveString == "blue");
|
|
}
|
|
|
|
if (searchModel.IsActiveString == "false")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false");
|
|
}
|
|
else if (searchModel.IsActiveString == "both")
|
|
{
|
|
query = query.Where(x => x.IsActiveString == "false" || x.IsActiveString == "true" || x.IsActiveString == "blue");
|
|
}
|
|
|
|
if (searchModel.OfficialCompany == "Official")
|
|
query = query.Where(x => x.OfficialCompany == "Official");
|
|
if (searchModel.OfficialCompany == "NotOfficial")
|
|
query = query.Where(x => x.OfficialCompany == "NotOfficial");
|
|
|
|
if (searchModel.TypeOfContract == "both")
|
|
{
|
|
query = query.Where(x => x.TypeOfContract == "JobRelation" || x.TypeOfContract == "taxAndFinancial");
|
|
}
|
|
else if (searchModel.TypeOfContract == "JobRelation" || string.IsNullOrWhiteSpace(searchModel.TypeOfContract))
|
|
{
|
|
query = query.Where(x => x.TypeOfContract == "JobRelation");
|
|
}
|
|
else if (searchModel.TypeOfContract == "taxAndFinancial")
|
|
{
|
|
query = query.Where(x => x.TypeOfContract == "taxAndFinancial");
|
|
}
|
|
|
|
if (searchModel.WorkshopId != 0)
|
|
{
|
|
query = query.Where(x => x.WorkshopIds.Count > 0 && x.WorkshopIds.Any(e => e == searchModel.WorkshopId));
|
|
}
|
|
|
|
if (searchModel.EmployerId != 0)
|
|
{
|
|
query = query.Where(x => x.EmployerIds.Count > 0 && x.EmployerIds.Any(e => e == searchModel.EmployerId));
|
|
}
|
|
if (searchModel.Signature == "2")
|
|
{
|
|
query = query.Where(x => x.Signature == "0" || x.Signature == "1");
|
|
}
|
|
|
|
if (searchModel.Signature == "1")
|
|
{
|
|
query = query.Where(x => x.Signature == "1");
|
|
}
|
|
else if (searchModel.Signature == "0")
|
|
{
|
|
query = query.Where(x => x.Signature == "0");
|
|
}
|
|
|
|
|
|
var listQuery = query.ToList();
|
|
|
|
|
|
listQuery = listQuery.Select(x => new InstitutionContractViewModel()
|
|
{
|
|
Id = x.Id,
|
|
ContractNo = x.ContractNo,
|
|
ContractStartGr = x.ContractStartGr,
|
|
ContractStartFa = x.ContractStartFa,
|
|
ContractEndGr = x.ContractEndGr,
|
|
ContractEndFa = x.ContractEndFa,
|
|
RepresentativeId = x.RepresentativeId,
|
|
RepresentativeName = x.RepresentativeName,
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
ContractingPartyId = x.ContractingPartyId,
|
|
ContractAmount = x.ContractAmount,
|
|
TotalAmount = x.TotalAmount,
|
|
SearchAmount = x.SearchAmount,
|
|
IsActiveString = x.IsActiveString,
|
|
OfficialCompany = x.OfficialCompany,
|
|
TypeOfContract = x.TypeOfContract,
|
|
Signature = x.Signature,
|
|
ExpireColor = ExpColor(x.ContractEndGr, x.SearchAmount,
|
|
x.IsActiveString),
|
|
BalanceDouble = TotalBalance(x.ContractingPartyId).TotalBalanceDbl,
|
|
BalanceStr = TotalBalance(x.ContractingPartyId).TotalBalanceStr,
|
|
EmployerViewModels = x.EmployerViewModels,
|
|
EmployerNo = x.EmployerNo,
|
|
// EmployerName = x.EmployerViewModels.Select(n => n.FullName).FirstOrDefault(),
|
|
// WorkshopViewModels = x.WorkshopViewModels,
|
|
WorkshopCount = Convert.ToString(x.WorkshopIds.Count),
|
|
IsContractingPartyBlock = x.IsContractingPartyBlock,
|
|
BlockTimes = x.BlockTimes,
|
|
// EmployeeCount = ((x.WorkshopViewModels.Sum(w => w.LeftWorkIds.Count)) + (x.WorkshopViewModels.Sum(w => w.InsuranceLeftWorkIds.Count(c => !w.LeftWorkIds.Contains(c))))).ToString(),
|
|
// ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0,
|
|
WorkshopViewModels = _context.Workshops.Where(w => x.WorkshopIds.Contains(w.id)).Include(w => w.LeftWorks).Include(w => w.LeftWorkInsurances).Select(w => new WorkshopViewModel()
|
|
{
|
|
Id = w.id,
|
|
WorkshopName = w.WorkshopName,
|
|
WorkshopFullName = w.WorkshopFullName,
|
|
ArchiveCode = w.ArchiveCode,
|
|
ContractingPartId = w.WorkshopEmployers.Select(e => e.Employer.ContractingPartyId).FirstOrDefault(),
|
|
LeftWorkIds = w.LeftWorks.Where(l => l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now).Select(l => l.EmployeeId).ToList(),
|
|
InsuranceLeftWorkIds = w.LeftWorkInsurances.Where(l => (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate > DateTime.Now) || (l.StartWorkDate <= DateTime.Now && l.LeftWorkDate == null)).Select(l => l.EmployeeId).ToList(),
|
|
}).ToList(),
|
|
|
|
}).ToList();
|
|
listQuery = listQuery.Select(x => new InstitutionContractViewModel()
|
|
{
|
|
Id = x.Id,
|
|
ContractNo = x.ContractNo,
|
|
ContractStartGr = x.ContractStartGr,
|
|
ContractStartFa = x.ContractStartFa,
|
|
ContractEndGr = x.ContractEndGr,
|
|
ContractEndFa = x.ContractEndFa,
|
|
RepresentativeId = x.RepresentativeId,
|
|
RepresentativeName = x.RepresentativeName,
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
ContractingPartyId = x.ContractingPartyId,
|
|
ContractAmount = x.ContractAmount,
|
|
TotalAmount = x.TotalAmount,
|
|
SearchAmount = x.SearchAmount,
|
|
IsActiveString = x.IsActiveString,
|
|
OfficialCompany = x.OfficialCompany,
|
|
TypeOfContract = x.TypeOfContract,
|
|
Signature = x.Signature,
|
|
ExpireColor = x.ExpireColor,
|
|
BalanceDouble = x.BalanceDouble,
|
|
BalanceStr = x.BalanceStr,
|
|
EmployerViewModels = x.EmployerViewModels,
|
|
EmployerNo = x.EmployerNo,
|
|
EmployerName = x.EmployerViewModels.Select(n => n.FullName).FirstOrDefault(),
|
|
WorkshopViewModels = x.WorkshopViewModels,
|
|
WorkshopCount = x.WorkshopCount,
|
|
IsContractingPartyBlock = x.IsContractingPartyBlock,
|
|
BlockTimes = x.BlockTimes,
|
|
EmployeeCount =
|
|
((x.WorkshopViewModels.Sum(w => w.LeftWorkIds.Count)) + (x.WorkshopViewModels.Sum(w =>
|
|
w.InsuranceLeftWorkIds.Count(c => !w.LeftWorkIds.Contains(c))))).ToString(),
|
|
ArchiveCode = x.WorkshopViewModels.Count > 0 ? ArchiveCodeFinder(x.WorkshopViewModels) : 0,
|
|
|
|
|
|
}).OrderBy(x => x.WorkshopCount != "0" && string.IsNullOrWhiteSpace(x.ExpireColor))
|
|
.ThenBy(x => x.WorkshopCount == "0" && string.IsNullOrWhiteSpace(x.ExpireColor))
|
|
.ThenBy(x => x.ExpireColor == "red")
|
|
.ThenBy(x => x.ExpireColor == "purple")
|
|
.ThenBy(x => x.ExpireColor == "black").ToList();
|
|
Console.WriteLine("test >>> " + timer.Elapsed);
|
|
return listQuery;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<InstitutionContractViewModel> PrintAll(List<long> id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public InstitutionContractViewModel PrintOne(long id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void RemoveContract(long id)
|
|
{
|
|
var op = new OperationResult();
|
|
var institutionContarct = _context.InstitutionContractSet.FirstOrDefault(x => x.id == id);
|
|
var contactInfo = _context.InstitutionContractContactInfos.Where(x => x.InstitutionContractId == id)
|
|
.ToList();
|
|
if (contactInfo.Count > 0)
|
|
{
|
|
foreach (var item in contactInfo)
|
|
{
|
|
_context.InstitutionContractContactInfos.Remove(item);
|
|
_context.SaveChanges();
|
|
}
|
|
}
|
|
|
|
if (institutionContarct != null)
|
|
{
|
|
_context.InstitutionContractSet.Remove(institutionContarct);
|
|
|
|
_context.SaveChanges();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public void CreateContractingPartyAccount(long contractingPartyid, long accountId)
|
|
{
|
|
var create = new ContractingPartyAccount(contractingPartyid, accountId);
|
|
_context.ContractingPartyAccounts.Add(create);
|
|
_context.SaveChanges();
|
|
}
|
|
|
|
public double GetcontractAmount(int countPerson)
|
|
{
|
|
double res = 0;
|
|
if (countPerson > 0)
|
|
{
|
|
var plan = _context.InstitutionPlans.FirstOrDefault(x => x.CountPerson == countPerson);
|
|
if (plan != null)
|
|
{
|
|
res = plan.FinalContractAmont;
|
|
}
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
public string ExpColor(DateTime contractEndGr, double contractAmount,
|
|
string isActiveString)
|
|
{
|
|
var now = DateTime.Now;
|
|
var nowFa = now.ToFarsi();
|
|
var endFa = nowFa.FindeEndOfMonth();
|
|
var endThisMontGr = endFa.ToGeorgianDateTime();
|
|
string result = "";
|
|
|
|
if (contractEndGr < now)
|
|
result = "black";
|
|
if (contractEndGr >= now && contractEndGr <= endThisMontGr)
|
|
result = "red";
|
|
if (contractAmount == 0)
|
|
result = "purple";
|
|
if (isActiveString == "blue")
|
|
result = "blue";
|
|
return result;
|
|
}
|
|
|
|
|
|
#region ExteraMetods
|
|
|
|
public TotalbalancViewModel TotalBalance(long contractingPartyId)
|
|
{
|
|
var result = new TotalbalancViewModel();
|
|
|
|
var firstGetStatement = _context.FinancialStatments.Include(x => x.FinancialTransactionList)
|
|
.FirstOrDefault(x => x.ContractingPartyId == contractingPartyId);
|
|
|
|
if (firstGetStatement != null)
|
|
{
|
|
if (firstGetStatement.FinancialTransactionList != null)
|
|
{
|
|
var allTransactions = firstGetStatement.FinancialTransactionList;
|
|
allTransactions = allTransactions.OrderBy(x => x.TdateGr).ToList();
|
|
var debt = allTransactions.Sum(x => x.Deptor);
|
|
var credit = allTransactions.Sum(x => x.Creditor);
|
|
result.TotalBalanceDbl = debt - credit;
|
|
result.TotalBalanceStr = result.TotalBalanceDbl.ToMoney();
|
|
}
|
|
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public int ArchiveCodeFinder(List<WorkshopViewModel> workshopViewModels)
|
|
{
|
|
var workshop = workshopViewModels.OrderBy(x => x.Id)?.ToList();
|
|
|
|
var arc = workshop.Select(x => new ArchiveCodConvertoint
|
|
{
|
|
ArchiveCodeInt = x.ArchiveCode.Substring(0, 1) == "b" ? 10000000 : x.ArchiveCode.ConvertToInt(),
|
|
}).OrderBy(x => x.ArchiveCodeInt).ToList();
|
|
var minArchiveCode = arc.Min(x => x.ArchiveCodeInt);
|
|
return minArchiveCode == 10000000 ? 0 : minArchiveCode;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CustomViewModels
|
|
|
|
|
|
|
|
public class WorkshopsAndEmployeeViewModel
|
|
{
|
|
public List<WorkshopViewModel> WorkshopViewModels { get; set; }
|
|
public string WorkshopCount { get; set; }
|
|
public string EmployeeCount { get; set; }
|
|
public int ArchiveCode { get; set; }
|
|
}
|
|
|
|
#endregion
|
|
} |