diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index 90d2f576..3a71ea7c 100644 --- a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs +++ b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs @@ -18,7 +18,7 @@ public interface ICheckoutRepository : IRepository /// /// /// - (bool hasChekout, double FamilyAlloance, double OverTimePay) HasCheckout(long workshopId, long employeId, + (bool hasChekout, double FamilyAlloance, double OverTimePay, double RotatingShift, double Nightwork, double Fridaywork, double YraesPay) HasCheckout(long workshopId, long employeId, string year, string month); EditCheckout GetDetails(long id); diff --git a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs index c46dea77..9aa53393 100644 --- a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs +++ b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs @@ -33,4 +33,14 @@ public interface IInstitutionContractRepository : IRepository workshopViewModels); InstitutionContract InstitutionContractByEmployerId(long employerId); + + + /// + /// ایجاد سند مالی حضور غیاب + /// + /// + /// + /// + /// + void RollcallServiceCreateTransaction(); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs index 342ad846..57ac69f0 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/IInstitutionContractApplication.cs @@ -15,6 +15,14 @@ public interface IInstitutionContractApplication List Search(InstitutionContractSearchModel searchModel); List NewSearch(InstitutionContractSearchModel searchModel); + + /// + /// دریافت اطلاعات قزداد های مالی فعال + ///دارای کارگاه + /// جهت ست کردن سرویس ها از طریق اکسل + /// + /// + List GetInstitutionContractToSetServicesExcelImport(); List PrintAll(List id); InstitutionContractViewModel PrintOne(long id); OperationResult Active(long id); diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index b228581a..fd87513b 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -579,6 +579,14 @@ public class InstitutionContractApplication : IInstitutionContractApplication return _institutionContractRepository.NewSearch(searchModel); } + + public List GetInstitutionContractToSetServicesExcelImport() + { + var result = _institutionContractRepository.NewSearch(new InstitutionContractSearchModel()); + + return result.Where(x => x.IsActiveString == "true" && x.IsContractingPartyBlock !="true" && x.WorkshopCount != "0" && x.ContractStartGr <= DateTime.Now && x.ContractEndGr >= DateTime.Now).ToList(); + } + public string ExpCheckColor(DateTime now, DateTime ContractEndGr, DateTime endThisMontGr, string ContractAmount, string isActiveString) { string result = ""; diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index 251be235..3e5b1d16 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -440,6 +440,12 @@ public class InsuranceListApplication : IInsuranceListApplication bool employeeHasCheckout = true; double familyAllowance = 0; double overTimePay = 0; + + double rotatingShift = 0; + double nightWork = 0; + double fridayWork = 0; + double yearsPay = 0; + if (hasWorkshopOverTimeOrFamilyAllowance && (leftDate >= startDateGr || employee.LeftWorkDateGr == null)) { var checkout = _checkoutRepository.HasCheckout(workshopId, employee.EmployeeId, @@ -450,6 +456,11 @@ public class InsuranceListApplication : IInsuranceListApplication familyAllowance = checkout.FamilyAlloance; overTimePay = checkout.OverTimePay; + rotatingShift = checkout.RotatingShift; + nightWork = checkout.Nightwork; + fridayWork = checkout.Fridaywork; + yearsPay = checkout.YraesPay; + } else { @@ -537,12 +548,21 @@ public class InsuranceListApplication : IInsuranceListApplication var employeeListData = employeeInsurancDataPreviusList .FirstOrDefault(e => e.EmployeeId == employee.EmployeeId); //مزیای عیر مشمول لیست قبل - var benefitsIncludedNonContinuous = - employeeListData != null ? employeeListData.BenefitsIncludedNonContinuous : 0; + //var benefitsIncludedNonContinuous = + // employeeListData != null ? employeeListData.BenefitsIncludedNonContinuous : 0; + double benefitsIncludedNonContinuous = 0; if (workshop.InsuranceCheckoutFamilyAllowance && employeeHasCheckout && !isManager) - { + { + double addOptionsfromCheckout = familyAllowance; - benefitsIncludedNonContinuous = GetRoundValue(benefitsIncludedNonContinuous + familyAllowance); + //استثنا کارگته بازرگانی سیم آهن مهراکو + //if (workshopId == 666) + //{ + // addOptionsfromCheckout = familyAllowance + rotatingShift + nightWork + fridayWork + yearsPay; + //} + + + benefitsIncludedNonContinuous = GetRoundValue(benefitsIncludedNonContinuous + addOptionsfromCheckout); } diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 478b00fb..9da33ea6 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -71,7 +71,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos /// /// /// - public (bool hasChekout, double FamilyAlloance, double OverTimePay) HasCheckout(long workshopId, long employeId, string year, string month) + public (bool hasChekout, double FamilyAlloance, double OverTimePay, double RotatingShift, double Nightwork, double Fridaywork, double YraesPay) HasCheckout(long workshopId, long employeId, string year, string month) { var farisMonthName = Tools.ToFarsiMonthByNumber(month); @@ -79,9 +79,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos x.WorkshopId == workshopId && x.EmployeeId == employeId && x.Year == year && x.Month == farisMonthName && x.IsActiveString == "true"); if (res == null) - return (false, 0, 0); + return (false, 0, 0,0,0,0,0); - return (true, res.FamilyAllowance, res.OvertimePay); + return (true, res.FamilyAllowance, res.OvertimePay, res.ShiftPay, res.NightworkPay, res.FridayPay,res.YearsPay); } public EditCheckout GetDetails(long id) @@ -240,6 +240,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var now = DateTime.Now; DateTime currentStart = ($"{DateTime.Now.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime(); DateTime currentEnd = ($"{DateTime.Now.ToFarsi().FindeEndOfMonth()}").ToGeorgianDateTime(); + var chekoutCreated = result.checkout.FirstOrDefault(x => x.ContractStart < endSearch && x.ContractEnd > startSreach && x.IsActiveString == "true"); if (chekoutCreated != null) @@ -265,13 +266,20 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } var employeeJoin = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork .contractWorkshopEmployee.employee.id; - - bool hasRollCall = - _rollCallEmployeeRepository.HasRollCallRecord(employeeJoin, workshopId, startSreach, endSearch); + var leftWork = result.contractWorkshopEmployeeleftWorkPersonnelCode.contractWorkshopEmployeeleftWork .leftwork; + var startStatusSearch = leftWork.StartWorkDate > startSreach && leftWork.StartWorkDate <= endSearch + ? leftWork.StartWorkDate + : startSreach; + var endStatusSearch = leftWork.HasLeft && leftWork.LeftWorkDate > startSreach && leftWork.LeftWorkDate <= endSearch + ? leftWork.LeftWorkDate.AddDays(-1) + : startSreach; + bool hasRollCall = + _rollCallEmployeeRepository.HasRollCallRecord(employeeJoin, workshopId, startStatusSearch, endStatusSearch); + bool extension = true; bool laterThanEnd = false; string description = ""; @@ -2221,40 +2229,41 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos if (!hasSearch && !hasEmployeeOrWorkshpSearch) { - + return checkouts.Select(x => new CheckoutViewModel() - { + { - Id = x.ch.id, - EmployeeFullName = x.ch.EmployeeFullName, - ContractStart = x.ch.ContractStart.ToFarsi(), - ContractEnd = x.ch.ContractEnd.ToFarsi(), - ContractStartGr = x.ch.ContractStart, - ContractEndGr = x.ch.ContractEnd, - PersonnelCode = x.ch.PersonnelCode, - PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), - ArchiveCode = x.workshop.ArchiveCode, - SumOfWorkingDays = x.ch.SumOfWorkingDays, - WorkshopName = x.workshop.WorkshopName, - Month = x.ch.Month, - Year = x.ch.Year, - ContractNo = x.ch.ContractNo, - ContractId = x.ch.ContractId, - WorkshopId = x.ch.WorkshopId, - EmployeeId = x.ch.EmployeeId, - EmployerId = x.workshopEmployer.EmployerId, - IsActiveString = x.ch.IsActiveString, - Signature = x.ch.Signature, - CreationDate = x.ch.CreationDate, - EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", - IsBlockCantracingParty = x.contractingParty.IsBlock, - HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout + Id = x.ch.id, + EmployeeFullName = x.ch.EmployeeFullName, + ContractStart = x.ch.ContractStart.ToFarsi(), + ContractEnd = x.ch.ContractEnd.ToFarsi(), + ContractStartGr = x.ch.ContractStart, + ContractEndGr = x.ch.ContractEnd, + PersonnelCode = x.ch.PersonnelCode, + PersonnelCodeInt = Convert.ToInt32(x.ch.PersonnelCode), + ArchiveCode = x.workshop.ArchiveCode, + SumOfWorkingDays = x.ch.SumOfWorkingDays, + WorkshopName = x.workshop.WorkshopName, + Month = x.ch.Month, + Year = x.ch.Year, + ContractNo = x.ch.ContractNo, + ContractId = x.ch.ContractId, + WorkshopId = x.ch.WorkshopId, + EmployeeId = x.ch.EmployeeId, + EmployerId = x.workshopEmployer.EmployerId, + IsActiveString = x.ch.IsActiveString, + Signature = x.ch.Signature, + CreationDate = x.ch.CreationDate, + EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", + IsBlockCantracingParty = x.contractingParty.IsBlock, + HasSignCheckout = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout - }).OrderByDescending(x => x.Id).ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).Take(200) - .GroupBy(x => x.Id) - .Select(x => x.First()).ToList() - .OrderByDescending(x => x.Id).ThenByDescending(x => x.Year).ThenBy(x => x.PersonnelCodeInt).Take(50).ToList(); + }).OrderByDescending(x=>x.Id).Take(3000).ToList().DistinctBy(x => x.Id) + .OrderByDescending(x => x.Id).ThenByDescending(x => x.Year) + .ThenBy(x => x.PersonnelCodeInt) + .Take(50).ToList(); + } else if (hasSearch && !hasEmployeeOrWorkshpSearch) { diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index 7bce4b2f..64653737 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -7,14 +7,18 @@ using _0_Framework.Application; using _0_Framework.InfraStructure; using Company.Domain.ContractingPartyAccountAgg; using Company.Domain.empolyerAgg; +using Company.Domain.FinancialStatmentAgg; +using Company.Domain.FinancialTransactionAgg; using Company.Domain.InstitutionContractAgg; using Company.Domain.WorkshopAgg; using CompanyManagment.App.Contracts.Employer; using CompanyManagment.App.Contracts.InstitutionContract; using CompanyManagment.App.Contracts.Workshop; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using PersianTools.Core; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace CompanyManagment.EFCore.Repository; @@ -759,6 +763,226 @@ public class InstitutionContractRepository : RepositoryBase + /// ایجاد سند مالی حضور غیاب + /// + /// + /// + /// + /// + + #region RollcallServicCreateTransaction + + public void RollcallServiceCreateTransaction() + { + DateTime now = DateTime.Now; + var nowFa = now.ToFarsi(); + var endOfMonth = nowFa.FindeEndOfMonth(); + + DateTime endOfMonthGr = endOfMonth.ToGeorgianDateTime(); + + + #region FindeNextMonth 1th + var year = Convert.ToInt32(endOfMonth.Substring(0, 4)); + var month = Convert.ToInt32(endOfMonth.Substring(5, 2)); + var nextM = new PersianDateTime(year, month, 1).AddMonths(1); + var nextMonthGr = ($"{nextM}").ToGeorgianDateTime(); + var endOfCurrentMonth = (($"{endOfMonth.Substring(0, 8)}/01").FindeEndOfMonth()).ToGeorgianDateTime(); + #endregion + #region GetAvtiveContracts + var institutionContracts = _context.InstitutionContractSet.Where(x => x.IsActiveString == "true").Select(x => new InstitutionContractViewModel + { + Id = x.id, + ContractingPartyId = x.ContractingPartyId, + ContractingPartyName = x.ContractingPartyName, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + IsActiveString = x.IsActiveString, + SearchAmount = x.ContractAmount, + TypeOfContract = x.TypeOfContract + }).Where(x => + x.ContractStartGr < endOfMonthGr && x.ContractEndGr >= endOfMonthGr && x.SearchAmount > 0) + .ToList(); + #endregion + + #region GetFutureContracts + + List futureContracts = _context.InstitutionContractSet + .Where(x => x.IsActiveString == "true" && + x.ContractStartGr == nextMonthGr && x.ContractAmount > 0) + .Select(x => new InstitutionContractViewModel + { + Id = x.id, + ContractingPartyId = x.ContractingPartyId, + ContractingPartyName = x.ContractingPartyName, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + IsActiveString = x.IsActiveString, + TypeOfContract = x.TypeOfContract, + ExtensionNo = x.ExtensionNo, + }).ToList(); + + #endregion + + #region GetDectivedContractOnCurrentMonth + + if (futureContracts.Any()) + { + List futureContractIds = futureContracts.Select(x => x.ContractingPartyId).ToList(); + List deatcivedContract = _context.InstitutionContractSet + .Where(x => x.IsActiveString == "false" && futureContractIds.Contains(x.ContractingPartyId) && + x.ContractEndGr == endOfCurrentMonth && x.ContractAmount > 0) + .Select(x => new InstitutionContractViewModel + { + Id = x.id, + ContractingPartyId = x.ContractingPartyId, + ContractingPartyName = x.ContractingPartyName, + ContractStartGr = x.ContractStartGr, + ContractStartFa = x.ContractStartFa, + ContractEndGr = x.ContractEndGr, + ContractEndFa = x.ContractEndFa, + IsActiveString = x.IsActiveString, + SearchAmount = x.ContractAmount, + TypeOfContract = x.TypeOfContract + }).ToList(); + + if (deatcivedContract.Any()) + institutionContracts.AddRange(deatcivedContract); + } + + List exceptionContractingPartyIds = [30520, 30739]; + institutionContracts = institutionContracts + .Where(x => !exceptionContractingPartyIds.Contains(x.ContractingPartyId)).ToList(); + int counter = 0; + var rollcallServiceList = + _context.RollCallServices.Where(x => x.IsActiveString == "true").ToList(); + var activeStatusDate = new DateTime(2121, 03, 21); + + foreach (var item in institutionContracts) + { + + //var isblock = contractingParty.IsBlock == "true" ? true : false; + + var employers = _context.Employers.Where(x => x.ContractingPartyId == item.ContractingPartyId).Select(x => x.id); + var workshops = _context.WorkshopEmployers.Where(x => employers.Contains(x.EmployerId)).Select(x => x.WorkshopId).Distinct().ToList(); + + + var srvices = + rollcallServiceList.Where(x => workshops.Contains(x.WorkshopId)).ToList(); + if (rollcallServiceList.Count > 0) + { + + foreach (var rollCallService in srvices) + { + //var spaning = (int)(endOfMonthGr - rollCallService.StartService).TotalDays + 1; + int monthCounter = 0; + + var currentMonthStart = ($"{(endOfMonthGr.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime(); + var prevMonthEnd = currentMonthStart.AddDays(-1); + var prevMonthStart = ($"{(prevMonthEnd.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime(); + + var monthCurrent = endOfMonth.Substring(5, 2); + var yearCurrent = endOfMonth.Substring(0, 4); + var currentMonthName = monthCurrent.ToFarsiMonthByNumber(); + var workshop = _context.Workshops.FirstOrDefault(x => x.id == rollCallService.WorkshopId); + + string description = ""; + if (rollCallService.StartService <= prevMonthStart) + { + var monthPrev = prevMonthEnd.ToFarsi().Substring(5, 2); + var yearPrev = prevMonthEnd.ToFarsi().Substring(0, 4); + var prevMonthName = monthPrev.ToFarsiMonthByNumber(); + description = $"{prevMonthName} و {currentMonthName} {yearCurrent} - {workshop.WorkshopFullName}"; + monthCounter = 2; + }else if (rollCallService.StartService <= currentMonthStart && + rollCallService.StartService > prevMonthStart) + { + monthCounter = 1; + + description = $"{currentMonthName} {yearCurrent} - {workshop.WorkshopFullName}"; + } + + + + var employees = + _context.RollCallEmployees.Where(x => x.WorkshopId == rollCallService.WorkshopId).Select(x=>x.id); + + var employeeCount = _context.RollCallEmployeesStatus.Where(x => employees.Contains(x.RollCallEmployeeId)) + .Count(x => x.EndDate.Date == activeStatusDate.Date); + + if (employeeCount > 0 && monthCounter > 0) + { + + counter++; + + + var dailyWageYearlySalery = _context.YearlySalaries.Include(i => i.YearlySalaryItemsList).FirstOrDefault(x => + x.StartDate.Date <= DateTime.Now.Date && x.EndDate >= DateTime.Now.Date); + + var dailyWage = dailyWageYearlySalery.YearlySalaryItemsList.Where(x => x.ItemName == "مزد روزانه") + .Select(x => x.ItemValue).FirstOrDefault(); + + var planPercentage = _context.PlanPercentages.FirstOrDefault(); + + var countPersonnel = employeeCount; + var planByCountPerson = _context.InstitutionPlans + .FirstOrDefault(x => x.CountPerson == countPersonnel); + + var amountForOneMonth =(((dailyWage * planPercentage.RollCallPercent) / 100) * planByCountPerson.CountPerson * + planByCountPerson.IncreasePercentage); + + + var amountWithoutTax = amountForOneMonth * monthCounter; + + + var tenPercent = amountWithoutTax * 10 / 100; + var totalAmonut = amountWithoutTax + tenPercent; + + Console.WriteLine( counter + " - " + rollCallService.StartService.ToFarsi() + " - " + rollCallService.WorkshopId + " - " + monthCounter + " - " + employeeCount + $" - {amountWithoutTax}"); + + var financialStatment = + _context.FinancialStatments.FirstOrDefault(x => + x.ContractingPartyId == item.ContractingPartyId); + long financialStatementId = 0; + if (financialStatment != null) + { + financialStatementId = financialStatment.id; + } + else + { + var statement = new FinancialStatment(item.ContractingPartyId, item.ContractingPartyName); + _context.FinancialStatments.Add(statement); + _context.SaveChanges(); + + financialStatementId = statement.id; + } + + var transaction = new FinancialTransaction(financialStatementId, endOfMonthGr, endOfMonth, + description, + "debt", "بابت سرویس حضور غیاب", totalAmonut, 0, 0); + _context.FinancialTransactions.Add(transaction); + _context.SaveChanges(); + + //Console.WriteLine(" number : " + counter + " - " + rollCallService.StartService.ToFarsi() + " - WorkshopId : " + rollCallService.WorkshopId + " - monthCount : " + monthCounter + " - employeeCount : " + employeeCount + $" - Amount : {amountWithoutTax.ToMoney()}" + $" - ten : {tenPercent.ToMoney()} total : {totalAmonut.ToMoney()}"); + } + + } + } + + } + + #endregion + } + + #endregion + + #region CustomViewModels diff --git a/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml b/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml index 99c516e7..f1f68907 100644 --- a/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml @@ -466,7 +466,7 @@
  • - +