merge from AdminCheckoutapi

This commit is contained in:
gozareshgir
2026-02-05 14:25:00 +03:30
19 changed files with 2916 additions and 110 deletions

View File

@@ -21,6 +21,7 @@
<PackageReference Include="MD.PersianDateTime.Standard" Version="2.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="10.0.1" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="10.0.1" />
<!--<PackageReference Include="DNTPersianUtils.Core" Version="6.7.1" />-->

View File

@@ -70,6 +70,33 @@ public static class Tools
return Regex.IsMatch(mobileNo, "^((09))(\\d{9})$");
}
/// <summary>
/// متد رند کننده مبلغ
/// استفاده شده در بیمه
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static double GetRoundDoubleValue(double value)
{
string strValue = value.ToString();
if (strValue.IndexOf('.') > -1)
{
string a = strValue.Substring(strValue.IndexOf('.') + 1, 1);
if (int.Parse(a) > 5)
{
return (Math.Round(value, MidpointRounding.ToPositiveInfinity));
}
else
{
return (Math.Round(value, MidpointRounding.ToNegativeInfinity));
}
}
return value;
}
/// <summary>
/// تاریخ شروع و تعداد ماه را میگیرد و تاریخ پایان قراردا را بر میگرداند
/// </summary>
@@ -679,7 +706,115 @@ public static class Tools
return y2;
}
/// <summary>
/// تاریخ شمسی میگیرد و پایان ماه را به میلادی برمیگرداند
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static DateTime FindeEndOfMonthReturnGr(this string date)
{
string y2 = string.Empty;
var year = Convert.ToInt32(date.Substring(0, 4));
var month = Convert.ToInt32(date.Substring(5, 2));
var YearD = date.Substring(0, 4);
var MonthD = date.Substring(5, 2);
if (month <= 6)
{
y2 = $"{YearD}/{MonthD}/31";
}
else if (month > 6 && month < 12)
{
y2 = $"{YearD}/{MonthD}/30";
}
else if (month == 12)
{
switch (year)
{
case 1346:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1350:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1354:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1358:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1362:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1366:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1370:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1375:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1379:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1383:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1387:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1391:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1395:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1399:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1403:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1408:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1412:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1416:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1420:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1424:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1428:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1432:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1436:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1441:
y2 = $"{YearD}/{MonthD}/30";
break;
case 1445:
y2 = $"{YearD}/{MonthD}/30";
break;
default:
y2 = $"{YearD}/{MonthD}/29";
break;
}
}
return y2.ToGeorgianDateTime();
}
/// <summary>
/// تعداد روزهای سال را برمیگرداند
/// اگر کبیسهد بود سال 366 روزه برمیگرداند

View File

@@ -23,7 +23,7 @@ public interface ICheckoutRepository : IRepository<long, Checkout>
string year, string month);
EditCheckout GetDetails(long id);
Task CreateCkeckout(Checkout command);
Task<bool> CreateCheckout(Checkout command);
/// <summary>
/// لود لیست اولیه جهت ایجاد فیش حقوقی
/// </summary>
@@ -109,5 +109,16 @@ public interface ICheckoutRepository : IRepository<long, Checkout>
/// <returns></returns>
Task<List<CheckoutPrintDto>> CheckoutPrint(List<long> ids);
/// <summary>
/// دریافت قردادها و جداول وابسته برای ایجاد فیش
/// </summary>
/// <param name="ids"></param>
/// <param name="year"></param>
/// <param name="month"></param>
/// <param name="workshopId"></param>
/// <returns></returns>
Task<OperationResult<GetContractAndIncludesDataToCreateDto>> GetContractsAndIncludeDataDataToCreateCheckout(
List<long> ids, string year, string month, long workshopId);
#endregion
}

View File

@@ -16,7 +16,7 @@ namespace Company.Domain.RollCallAgg;
public interface IRollCallMandatoryRepository : IRepository<long, RollCall>
{
ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout, bool rotatingShiftCompute, double dailyWageUnAffected, bool totalLeaveCompute);
Task<ComputingViewModel> MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout, bool rotatingShiftCompute, double dailyWageUnAffected, bool totalLeaveCompute);
/// <summary>
/// محاسبه ساعات کارکرد پرسنل در صورت داشتن حضور غیاب

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using _0_Framework.Domain;
using CompanyManagment.App.Contracts.RollCallEmployee;
@@ -7,7 +8,7 @@ namespace Company.Domain.RollCallEmployeeAgg;
public interface IRollCallEmployeeRepository : IRepository<long, RollCallEmployee>
{
bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd);
Task<bool> HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd);
List<RollCallEmployeeViewModel> GetByWorkshopId(long workshopId);
EditRollCallEmployee GetDetails(long id);
RollCallEmployeeViewModel GetByEmployeeIdAndWorkshopId(long employeeId, long workshopId);

View File

@@ -0,0 +1,210 @@
using System;
using CompanyManagment.App.Contracts.Contract;
using CompanyManagment.App.Contracts.EmployeeComputeOptions;
using CompanyManagment.App.Contracts.WorkingHoursTemp;
using System.Collections.Generic;
namespace CompanyManagment.App.Contracts.Checkout.Dto;
public class GetContractAndIncludesDataToCreateDto
{
/// <summary>
/// آی دی کارگاه
/// </summary>
public long WorkshopId { get; set; }
/// <summary>
/// نام کارگاه
/// </summary>
public string WorkshopName { get; set; }
/// <summary>
/// کد بایگانی کارگاه
/// </summary>
public string ArchiveCode { get; set; }
/// <summary>
/// آیا تنظیمات کارگاه بر رو ایجاد فیش استاتیک است
/// </summary>
public bool IsStaticCheckout { get; set; }
/// <summary>
/// آیا کارگاه در تعطیلات رسمی باز است
/// </summary>
public bool WorkshopHolidayWorking { get; set; }
/// <summary>
/// محاسبه نوبت کاری در فیش حقوقی
/// </summary>
public bool RotatingShiftCompute { get; set; }
/// <summary>
/// آیا پاداش در فیش حقوقی محاسبه شود
/// </summary>
public bool RewardComputeOnCheckout { get; set; }
/// <summary>
/// آیا اضافه کار فیش حقوقی در بیمه محاسبه شود
/// </summary>
public bool HasInsuranceCheckoutOverTime { get; set; }
/// <summary>
/// آی دی صنف بیمه کارگاه
/// </summary>
public long? InsuranceJobId { get; set; }
/// <summary>
/// آیا کارگاه مشاغل مقطوع است
/// </summary>
public bool FixedSalary { get; set; }
/// <summary>
/// جمعیت شهر کارگاه
/// </summary>
public string Population { get; set; }
/// <summary>
/// نوع ارسال لیست بیمه
/// </summary>
public string TypeOfInsuranceSend { get; set; }
/// <summary>
/// قرارداد قدیمی است؟
/// </summary>
public bool IsOldContract { get; set; }
public List<ContractIncludedData> ContractIncludedData { get; set; }
}
public class ContractIncludedData
{
/// <summary>
/// شماره قرارداد
/// </summary>
public string ContractNo { get; set; }
/// <summary>
/// آی دی پرسنل
/// </summary>
public long EmployeeId { get; set; }
/// <summary>
/// نام کامل پرسنل
/// </summary>
public string EmployeeFullName { get; set; }
/// <summary>
/// نام پدر
/// </summary>
public string FathersName { get; set; }
/// <summary>
/// کد ملی
/// </summary>
public string NationalCode { get; set; }
/// <summary>
/// تاریخ تولد
/// </summary>
public string DateOfBirth { get; set; }
/// <summary>
/// کد پرسنلس
/// </summary>
public string PersonnelCode { get; set; }
/// <summary>
/// وضعیت تاهل
/// </summary>
public string MaritalStatus { get; set; }
/// <summary>
/// ساعت کاری پرسنل
/// </summary>
public CreateWorkingHoursTemp WorkingHours { get; set; }
/// <summary>
/// اطلاعات جداسازی تاریخ فیش
/// </summary>
public ContractSeparationViewModel Separation { get; set; }
/// <summary>
/// تنظیمات فنی پرسنل
/// سنوات
/// </summary>
public string YearsOption { get; set; }
/// <summary>
/// تنظیمات فنی پرسنل
/// عیدی و پاداش
/// </summary>
public string BonusesOption { get; set; }
/// <summary>
/// تنظیمات فنی پرسنل
/// مزد مرخصی
/// </summary>
public string ComputeOption { get; set; }
/// <summary>
/// ترایخ شروع قراداد
/// شمسی
/// </summary>
public string ContractStart { get; set; }
/// <summary>
/// تاریخ پایان قرارداد
/// شمسی
/// </summary>
public string ContractEnd { get; set; }
/// <summary>
/// ترایخ شروع قراداد
/// میلادی
/// </summary>
public DateTime ContractStartGr { get; set; }
/// <summary>
/// تاریخ پایان قرارداد
/// میلادی
/// </summary>
public DateTime ContractEndGr { get; set; }
/// <summary>
/// آی دی قراداد
/// </summary>
public long ContractId { get; set; }
/// <summary>
/// مزد روزانه قرداد بدون تاثیر ساعات کار
/// </summary>
public double DailySalaryUnAffected { get; set; }
/// <summary>
/// نوع مزد روزانه
/// </summary>
public string DailyWageType { get; set; }
/// <summary>
/// اولین شروع بکار پرسنل
/// </summary>
public string FirstGetWorkingDay { get; set; }
}

View File

@@ -108,6 +108,14 @@ public interface ICheckoutApplication
/// <returns></returns>
Task<OperationResult<List<ContractsListToCreateCheckoutDto>>> GetContractToCreateCheckout(long workshopId,
string year, string month, long employeeId);
/// <summary>
/// ایجاد فیش حقوقی
/// </summary>
/// <param name="ids"></param>
/// <param name="year"></param>
/// <param name="month"></param>
/// <returns></returns>
Task<OperationResult> CreateCheckoutApi(List<long> ids, string year, string month, long workshopId);
#endregion
}

View File

@@ -19,4 +19,6 @@ public class ContractSeparationViewModel
public string ConsumableItems { get; set; }
public bool checker { get; set; }
public bool HasLeft { get; set; }
public long EmployeeId { get; set; }
}

View File

@@ -0,0 +1,18 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
namespace CompanyManagment.App.Contracts.Hubs;
public class CheckoutHub : Hub
{
public async Task send(long id)
{
await Groups.AddToGroupAsync(Context.ConnectionId, GetGroupName(id));
}
public static string GetGroupName(long id)
{
return $"group-Checkout-{id}";
}
}

View File

@@ -2,11 +2,15 @@
using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects;
using Company.Domain.CheckoutAgg;
using Company.Domain.CheckoutAgg.ValueObjects;
using Company.Domain.ContractAgg;
using Company.Domain.EmployeeAgg;
using Company.Domain.empolyerAgg;
using Company.Domain.InsuranceListAgg;
using Company.Domain.LeaveAgg;
using Company.Domain.LeftWorkAgg;
using Company.Domain.LeftWorkInsuranceAgg;
using Company.Domain.RollCallAgg;
using Company.Domain.RollCallEmployeeAgg;
using Company.Domain.WorkingHoursTempAgg;
using Company.Domain.WorkshopAgg;
using Company.Domain.YearlySalaryAgg;
@@ -14,17 +18,23 @@ using CompanyManagment.App.Contracts.Checkout;
using CompanyManagment.App.Contracts.Checkout.Dto;
using CompanyManagment.App.Contracts.Contract;
using CompanyManagment.App.Contracts.HolidayItem;
using CompanyManagment.App.Contracts.Hubs;
using CompanyManagment.App.Contracts.InstitutionContract;
using CompanyManagment.App.Contracts.InsuranceList;
using CompanyManagment.App.Contracts.Leave;
using CompanyManagment.App.Contracts.MandantoryHours;
using CompanyManagment.App.Contracts.PersonalContractingParty;
using CompanyManagment.App.Contracts.RollCall;
using CompanyManagment.App.Contracts.WorkingHoursTemp;
using CompanyManagment.App.Contracts.Workshop;
using CompanyManagment.App.Contracts.YearlySalary;
using CompanyManagment.EFCore.Migrations;
using CompanyManagment.EFCore.Repository;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
@@ -48,12 +58,18 @@ public class CheckoutApplication : ICheckoutApplication
private readonly IWorkingHoursTempRepository _workingHoursTempRepository;
private readonly IWorkshopRepository _workshopRepository;
private readonly IAuthHelper _authHelper;
private readonly IHubContext<CheckoutHub> _hubContext;
private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository;
private readonly IContractRepository _contractRepository;
private readonly IInsuranceListRepository _insuranceListRepository;
private readonly ILeftWorkInsuranceRepository _leftWorkInsuranceRepository;
private readonly IInsuranceListApplication _insuranceListApplication;
public CheckoutApplication(ICheckoutRepository checkoutRepository, IYearlySalaryRepository yearlySalaryRepository,
ILeftWorkRepository leftWorkRepository,
IEmployerRepository employerRepository, IPersonalContractingPartyApp contractingPartyApp, ILeaveApplication leaveApplication, IMandatoryHoursApplication mandatoryHoursApplication, IRollCallMandatoryRepository rollCallMandatoryRepository, IRollCallRepository rollCallRepository, IHolidayItemApplication holidayItemApplication, IWorkingHoursTempRepository workingHoursTempRepository, IWorkshopRepository workshopRepository, IAuthHelper authHelper)
IEmployerRepository employerRepository, IPersonalContractingPartyApp contractingPartyApp, ILeaveApplication leaveApplication, IMandatoryHoursApplication mandatoryHoursApplication, IRollCallMandatoryRepository rollCallMandatoryRepository, IRollCallRepository rollCallRepository, IHolidayItemApplication holidayItemApplication, IWorkingHoursTempRepository workingHoursTempRepository, IWorkshopRepository workshopRepository, IAuthHelper authHelper, IHubContext<CheckoutHub> hubContext, IRollCallEmployeeRepository rollCallEmployeeRepository, IContractRepository contractRepository, IInsuranceListRepository insuranceListRepository, ILeftWorkInsuranceRepository leftWorkInsuranceRepository, IInsuranceListApplication insuranceListApplication)
{
_checkoutRepository = checkoutRepository;
_yearlySalaryRepository = yearlySalaryRepository;
@@ -68,6 +84,12 @@ public class CheckoutApplication : ICheckoutApplication
_workingHoursTempRepository = workingHoursTempRepository;
_workshopRepository = workshopRepository;
_authHelper = authHelper;
_hubContext = hubContext;
_rollCallEmployeeRepository = rollCallEmployeeRepository;
_contractRepository = contractRepository;
_insuranceListRepository = insuranceListRepository;
_leftWorkInsuranceRepository = leftWorkInsuranceRepository;
_insuranceListApplication = insuranceListApplication;
}
[SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records", MessageId = "count: 241")]
@@ -263,12 +285,12 @@ public class CheckoutApplication : ICheckoutApplication
rewardPay = rewards.Sum(x => x.AmountDouble);
}
var firstDayOfMonth = $"{command.ContractStart.Substring(0, 8)}01".ToGeorgianDateTime();
var firstDayOfCurrentMonth = new DateTime(syear, smonth, 1, new PersianCalendar());
var firstDayOfMonth = $"{command.ContractStart.Substring(0, 8)}01".ToGeorgianDateTime();
var firstDayOfCurrentMonth = new DateTime(syear, smonth, 1, new PersianCalendar());
LeaveSearchModel sickLeaveSearch = new LeaveSearchModel()
{
@@ -384,12 +406,12 @@ public class CheckoutApplication : ICheckoutApplication
var totalClaimsDouble = monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + command.OvertimePay +
command.NightworkPay + familyAllowance + bunos + years + command.LeavePay + command.FridayPay + command.ShiftPay + rewardPay;
var totalClaims = totalClaimsDouble.ToMoney();
var totalDeductionDouble = insuranceDeduction + command.AbsenceDeduction + command.InstallmentDeduction + command.SalaryAidDeduction;
var totalDeductions = totalDeductionDouble.ToMoney();
var totalPayment = totalClaimsDouble - totalDeductionDouble;
var totalClaimsDouble = monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + command.OvertimePay +
command.NightworkPay + familyAllowance + bunos + years + command.LeavePay + command.FridayPay + command.ShiftPay + rewardPay;
var totalClaims = totalClaimsDouble.ToMoney();
var totalDeductionDouble = insuranceDeduction + command.AbsenceDeduction + command.InstallmentDeduction + command.SalaryAidDeduction;
var totalDeductions = totalDeductionDouble.ToMoney();
var totalPayment = totalClaimsDouble - totalDeductionDouble;
if (_checkoutRepository.Exists(x =>
x.Month == command.Month && x.Year == command.Year && x.ContractNo == command.ContractNo))
@@ -404,15 +426,15 @@ public class CheckoutApplication : ICheckoutApplication
}
var checkout = new Checkout(command.EmployeeFullName, command.FathersName, command.NationalCode
, command.DateOfBirth, command.EmployeeId, command.WorkshopName, command.WorkshopId, command.ContractNo, command.ContractStartGr, command.ContractEndGr, month, year,
command.ContractId, command.WorkingHoursId, monthlyWage, bacicYears, consumableItem, housingAllowance
, command.OvertimePay, command.NightworkPay, command.FridayPay, 0, command.ShiftPay, familyAllowance, bunos, years, command.LeavePay, insuranceDeduction, 0, command.InstallmentDeduction, command.SalaryAidDeduction, command.AbsenceDeduction, sumOfWorkingDays,
command.ArchiveCode, command.PersonnelCode, totalClaims, totalDeductions, totalPayment, command.Signature, marriedAllowance, command.LeaveCheckout, command.CreditLeaves, command.AbsencePeriod, command.AverageHoursPerDay, command.HasRollCall, command.OverTimeWorkValue, command.OverNightWorkValue
, command.FridayWorkValue, command.RotatingShiftValue, command.AbsenceValue, command.TotalDayOfLeaveCompute, command.TotalDayOfYearsCompute, command.TotalDayOfBunosesCompute,
loanInstallments, salaryAids,checkoutRollCall,command.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay);
var checkout = new Checkout(command.EmployeeFullName, command.FathersName, command.NationalCode
, command.DateOfBirth, command.EmployeeId, command.WorkshopName, command.WorkshopId, command.ContractNo, command.ContractStartGr, command.ContractEndGr, month, year,
command.ContractId, command.WorkingHoursId, monthlyWage, bacicYears, consumableItem, housingAllowance
, command.OvertimePay, command.NightworkPay, command.FridayPay, 0, command.ShiftPay, familyAllowance, bunos, years, command.LeavePay, insuranceDeduction, 0, command.InstallmentDeduction, command.SalaryAidDeduction, command.AbsenceDeduction, sumOfWorkingDays,
command.ArchiveCode, command.PersonnelCode, totalClaims, totalDeductions, totalPayment, command.Signature, marriedAllowance, command.LeaveCheckout, command.CreditLeaves, command.AbsencePeriod, command.AverageHoursPerDay, command.HasRollCall, command.OverTimeWorkValue, command.OverNightWorkValue
, command.FridayWorkValue, command.RotatingShiftValue, command.AbsenceValue, command.TotalDayOfLeaveCompute, command.TotalDayOfYearsCompute, command.TotalDayOfBunosesCompute,
loanInstallments, salaryAids, checkoutRollCall, command.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay);
_checkoutRepository.CreateCkeckout(checkout).GetAwaiter().GetResult();
_checkoutRepository.CreateCheckout(checkout).GetAwaiter().GetResult();
//_checkoutRepository.SaveChanges();
//var employeeFullName = new SqlParameter("@EmployeeFullName", SqlDbType.NVarChar, 50);
@@ -780,11 +802,11 @@ public class CheckoutApplication : ICheckoutApplication
year = "0";
month = "0";
}
var result = await GetContractResultToCreateCheckout(workshopId, employeeId, year, month, null,
null);
if(result.CreateCheckoutList.Count == 0)
if (result.CreateCheckoutList.Count == 0)
return op.Failed("موردی یافت نشد");
var finalResult = result.CreateCheckoutList.Select(x => new ContractsListToCreateCheckoutDto
{
@@ -805,46 +827,705 @@ public class CheckoutApplication : ICheckoutApplication
}
public async Task<OperationResult> CreateCheckoutApi(List<long> ContractsId, string ConvertYear, string ConvertMonth)
public async Task<OperationResult> CreateCheckoutApi(List<long> ids, string year, string month, long workshopId)
{
var op = new OperationResult();
//آی دی کاربر لاگین شده برای استفاده در signalR
var currentAcc = _authHelper.CurrentAccountId();
var currntAcc = _authHelper.CurrentAccountId();
#region Validation
var signalR = _hubContext.Clients.Group(CheckoutHub.GetGroupName(currntAcc));
if (!string.IsNullOrWhiteSpace(ConvertYear) && string.IsNullOrWhiteSpace(ConvertMonth))
return op.Failed("ماه را انتخاب کنید");
if (string.IsNullOrWhiteSpace(ConvertYear) && !string.IsNullOrWhiteSpace(ConvertMonth))
return op.Failed("سال را انتخاب کنید");
if (string.IsNullOrWhiteSpace(ConvertYear) && string.IsNullOrWhiteSpace(ConvertMonth))
{
ConvertYear = "0";
ConvertMonth = "0";
var today = DateTime.Now;
var FaToday = today.ToFarsi();
var year = FaToday.Substring(0, 4);
var month = FaToday.Substring(5, 2);
ConvertYear = year;
ConvertMonth = month;
}
if (ContractsId.Count == 0)
return op.Failed("هیچ موردی انتخاب نشده اشت");
#endregion
var getContractsData = await
_checkoutRepository.GetContractsAndIncludeDataDataToCreateCheckout(ids, year, month, workshopId);
#region GetInsuranceData
var startMonthFa = $"{year}/{month.PadLeft(2, '0')}/01";
DateTime startDateGr = startMonthFa.ToGeorgianDateTime();
DateTime endDateGr = startMonthFa.FindeEndOfMonth().ToGeorgianDateTime();
int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2));
var insuranceListData =
_insuranceListRepository.EmployeeInsuranceDataBy(startDateGr, getContractsData.Data.WorkshopId);
var yearlysaleries = _yearlySalaryRepository.GetInsuranceItems(startDateGr, endDateGr, year);
var insuranceEmployeeData =
_leftWorkInsuranceRepository.GetEmployeeInsuranceLeftWorksAndInformation(getContractsData.Data.WorkshopId, startDateGr,
endDateGr);
#endregion
if (!getContractsData.IsSuccedded)
{
await signalR.SendAsync("StartProcessingFailed", getContractsData.Message);
return op.Failed(getContractsData.Message);
}
var timer = new Stopwatch();
timer.Start();
int successProcess = 1;
int countList = getContractsData.Data.ContractIncludedData.Count;
List<string> createFailedList = [];
int createSuccessCount = 0;
int createFailedCount = 0;
foreach (var item in getContractsData.Data.ContractIncludedData)
{
try
{
//آیا کل مرخصی به ساعت کاراضافه شود؟
bool totalLeaveCompute = false;
//آیا غیبت محاسبه شود؟
bool abcenseDeductionCompute = false;
switch (item.ComputeOption)
{
case "OnEndOfYear":
var endOfYearCheckout = item.Separation.ContractEnd.Substring(5, 2);
totalLeaveCompute = true;
abcenseDeductionCompute = item.Separation.HasLeft || endOfYearCheckout == "12";
break;
case "OnLeftWork":
totalLeaveCompute = true;
abcenseDeductionCompute = item.Separation.HasLeft;
break;
case "OnEndOfContract":
var startMonth = item.ContractStart.Substring(5, 2);
var endMonth = item.ContractEnd.Substring(5, 2);
totalLeaveCompute = startMonth != endMonth;
abcenseDeductionCompute = (startMonth != endMonth && item.Separation.HasLeft) || (startMonth != endMonth && item.ContractEndGr == item.Separation.ContractEndGr);
break;
}
//دستمزد روزانه بدون تاثیر ساعت کار
#region DailyWageCommpute
var contract = new EditContract()
{
ContractStartGr = item.ContractStartGr,
ContractEndGr = item.ContractEndGr,
DailySalaryUnAffected = item.DailySalaryUnAffected,
DailyWageType = item.DailyWageType,
ContarctStart = item.ContractStart,
ContractEnd = item.ContractEnd,
GetWorkDate = item.FirstGetWorkingDay,
GetWorkDateHide = item.FirstGetWorkingDay,
};
//دستمزد روزانه بدون تاثیر ساعت کار
var dailyWageUnAffected = await _yearlySalaryRepository.GetCheckoutDailyWage(contract,
item.Separation.ContractStartGr, item.Separation.ContractEndGr);
#endregion
var hasRollCall = await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, item.Separation.ContractStartGr, item.Separation.ContractEndGr);
if (getContractsData.Data.IsStaticCheckout)
hasRollCall = false;
var isStaticCheckout = hasRollCall == false;
//محاسبه موظفی
#region MandatoryCompute
var mandatoryCompute = new ComputingViewModel();
item.WorkingHours.ContractStartGr = item.Separation.ContractStartGr;
item.WorkingHours.ContractEndGr = item.Separation.ContractEndGr;
item.WorkingHours.ContarctStart = item.Separation.ContarctStart;
item.WorkingHours.ContractEnd = item.Separation.ContractEnd;
item.WorkingHours.GetWorkDate = contract.GetWorkDate;
item.WorkingHours.GetWorkDateHide = contract.GetWorkDate;
item.WorkingHours.WorkshopId = workshopId;
item.WorkingHours.EmployeeId = item.EmployeeId;
mandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(item.EmployeeId, workshopId,
item.Separation.ContractStartGr, item.Separation.ContractEndGr, item.WorkingHours, getContractsData.Data.WorkshopHolidayWorking,
isStaticCheckout, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute);
#endregion
if (contract.EmployeeId == 9659)
mandatoryCompute.SumTime44 = "48 - 24";
var officialHoliday = mandatoryCompute.OfficialHoliday;
var Friday = int.Parse(mandatoryCompute.NumberOfFriday);
var fridayStartToEnd = mandatoryCompute.FridayStartToEnd;
var totalHoursH = mandatoryCompute.TotalHoursesH;
var totalHoursM = mandatoryCompute.TotalHoursesM;
var dayliWage = mandatoryCompute.SalaryCompute.MoneyToDouble();
var consumableItemDouble = mandatoryCompute.ConsumableItems.MoneyToDouble();
var housingAllowanceDouble = mandatoryCompute.HousingAllowance.MoneyToDouble();
var familyAllowanceDouble = mandatoryCompute.FamilyAllowance.MoneyToDouble();
var marriedAllowanceDouble = mandatoryCompute.MarriedAllowance.MoneyToDouble();
//اضافه کاری
var overTimePay = _yearlySalaryRepository.GetOverTimeWorking(dayliWage,
mandatoryCompute.OverTimeWorkH, mandatoryCompute.OverTimeWorkM);
//شبکاری
var overNightPay = _yearlySalaryRepository.GetOverNightWorking(dayliWage,
mandatoryCompute.OverNightWorkH, mandatoryCompute.OverNightWorkM, mandatoryCompute.SumTime44,
officialHoliday, Friday, item.Separation.ContractStartGr, item.Separation.ContractEndGr, totalHoursH,
totalHoursM);
//سنوات
var yearsPay = _yearlySalaryRepository.Years(item.Separation.ContractStartGr, item.Separation.LeftWorkDate,
item.Separation.ContractEndGr,
dayliWage, item.YearsOption, item.Separation.HasLeft, item.Separation.StartWorkDate, contract.ContractStartGr,
contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, getContractsData.Data.IsOldContract);
//عیدی
#region BonusesPay
var bunosesPay = _yearlySalaryRepository.Bunoses(item.Separation.ContarctStart, item.Separation.LeftWorkDate,
item.Separation.ContractStartGr, item.Separation.ContractEndGr,
dayliWage, item.BonusesOption, item.Separation.HasLeft, item.Separation.StartWorkDate,
contract.ContractStartGr,
contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, getContractsData.Data.IsOldContract);
//اگر تصفیه حساب پاک شده برای عیدی یا سنوات وجود داشت
if (bunosesPay.NotCompleted || yearsPay.NotCompleted)
{
List<BunosesAndYearsPayStatus> lostCheckoutsDates = new List<BunosesAndYearsPayStatus>();
if ((bunosesPay.NotCompleted && yearsPay.NotCompleted) || (bunosesPay.NotCompleted && !yearsPay.NotCompleted))
lostCheckoutsDates = bunosesPay.BunosesStatusList;
if (!bunosesPay.NotCompleted && yearsPay.NotCompleted)
lostCheckoutsDates = yearsPay.BunosesStatusList;
foreach (var found in lostCheckoutsDates)
{
ComputingViewModel foundMandatoryCompute = new ComputingViewModel();
var foundContract = _contractRepository.GetContractByStartEnd(found.ContractStart,
found.ContractEnd, contract.WorkshopIds, contract.EmployeeId);
if (foundContract.Id > 0)
{
var foundWorkingHours = _workingHoursTempRepository.GetByContractIdConvertToShiftwork4(foundContract.Id);
foundWorkingHours.ContractStartGr = found.ContractStart;
foundWorkingHours.ContractEndGr = found.ContractEnd;
foundWorkingHours.ContarctStart = found.ContractStart.ToFarsi();
foundWorkingHours.ContractEnd = found.ContractEnd.ToFarsi();
foundWorkingHours.GetWorkDate = foundContract.GetWorkDate;
foundWorkingHours.GetWorkDateHide = foundContract.GetWorkDate;
foundWorkingHours.WorkshopId = contract.WorkshopIds;
foundWorkingHours.EmployeeId = contract.EmployeeId;
bool foundHasRollCall = await _rollCallEmployeeRepository.HasRollCallRecord(item.EmployeeId, workshopId, found.ContractStart, found.ContractEnd);
if (getContractsData.Data.IsStaticCheckout)
foundHasRollCall = false;
foundMandatoryCompute = await _rollCallMandatoryRepository.MandatoryCompute(contract.EmployeeId,
contract.WorkshopIds,
found.ContractStart, found.ContractEnd, foundWorkingHours, getContractsData.Data.WorkshopHolidayWorking, foundHasRollCall, getContractsData.Data.RotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute);
var MontlyYearsBunos =
_yearlySalaryRepository.GetMontlyBunosYears(foundMandatoryCompute.weeklyTime, found.ContractStart, found.ContractEnd,
foundMandatoryCompute.SalaryCompute.MoneyToDouble(), foundMandatoryCompute.SumTime44, foundMandatoryCompute.OfficialHoliday,
int.Parse(foundMandatoryCompute.NumberOfFriday), foundMandatoryCompute.TotalHolidayAndNotH, foundMandatoryCompute.TotalHolidayAndNotM,
foundMandatoryCompute.Basic, foundMandatoryCompute.FridayStartToEnd, foundMandatoryCompute.DayliFeeComplete, hasRollCall, getContractsData.Data.WorkshopHolidayWorking, item.WorkingHours.ShiftWork);
double foundMontlySalary = MontlyYearsBunos.MontlyWage + MontlyYearsBunos.BasicYears;
int foundTotaldays = Convert.ToInt32(MontlyYearsBunos.SumOfWorkingDay);
double foundDayliWage = foundMontlySalary / foundTotaldays;
if (bunosesPay.NotCompleted)
{
double foundBonuses = ((foundDayliWage * 60) / 365) * foundTotaldays;
bunosesPay.Bunoses += foundBonuses;
bunosesPay.TotalDayCompute += foundTotaldays;
}
if (yearsPay.NotCompleted)
{
double foundBonuses = ((foundDayliWage * 30) / 365) * foundTotaldays;
yearsPay.YearsPay += foundBonuses;
yearsPay.TotalDayCompute += foundTotaldays;
}
}
}
}
#endregion
//مزد مرخصی جدید
var leavePayNew = _yearlySalaryRepository.LeavePay(item.Separation.ContarctStart,
item.Separation.LeftWorkDate, item.Separation.ContractStartGr, item.Separation.ContractEndGr,
dayliWage, item.ComputeOption, item.Separation.HasLeft, item.Separation.StartWorkDate,
contract.ContractStartGr,
contract.ContractEndGr, contract.WorkshopIds, contract.EmployeeId, fridayStartToEnd,
officialHoliday, totalHoursH, totalHoursM, consumableItemDouble, housingAllowanceDouble,
familyAllowanceDouble, marriedAllowanceDouble, getContractsData.Data.IsOldContract);
#region Insurance
double insuranceShare = 0;
//اگر پرسنل داری شروع بکار بیمه بود
var insuranceEmployeeDataItem =
insuranceEmployeeData.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId);
//اگر لیست بیمه برای پرسنل ساخته شده بود
var insuranceListDataWithDetails =
insuranceListData.FirstOrDefault(x => x.EmployeeId == contract.EmployeeId);
if (insuranceListDataWithDetails != null)
{
insuranceShare = insuranceListDataWithDetails.InsuranceShare;
}
else
{
if (insuranceEmployeeDataItem != null && insuranceEmployeeDataItem.StartWorkDateGr <= item.Separation.ContractEndGr)
{
var workingDays = Tools.GetEmployeeInsuranceWorkingDays(insuranceEmployeeDataItem.StartWorkDateGr, item.Separation.LeftWorkDate, startDateGr, endDateGr, insuranceEmployeeDataItem.EmployeeId);
var leftWorkFa = workingDays.hasLeftWorkInMonth ? item.Separation.LeftWorkDate.ToFarsi() : "";
//به دست آوردن دستمزد روزانه با توجه به اینکه کارگاه مشاغل مقطوع است یا خیر
double dailyWage = 0;
if (getContractsData.Data.FixedSalary)
{
var res = _insuranceListApplication.GetDailyWageFixedSalary(year, getContractsData.Data.WorkshopId, insuranceEmployeeDataItem.EmployeeId, startDateGr,
endDateGr, insuranceEmployeeDataItem.JobId, getContractsData.Data.Population, getContractsData.Data.InsuranceJobId);
dailyWage = res ?? 0;
}
else
{
var res = _insuranceListApplication.ComputeDailyWage(yearlysaleries.DayliWage, insuranceEmployeeDataItem.EmployeeId, getContractsData.Data.WorkshopId, year);
dailyWage = res;
}
//بدست آوردن پایه سنوات
var baseYears = _insuranceListRepository.GetEmployeeInsuranceBaseYear(insuranceEmployeeDataItem.EmployeeId, getContractsData.Data.WorkshopId,
workingDays.countWorkingDays, startDateGr, endDateGr, workingDays.startWork, workingDays.endWork, workingDays.hasLeftWorkInMonth);
//جمع مزد روزانه و پایه سنوات
var dailyWagePlusBaseYears = dailyWage + baseYears.baseYear;
//دستمزد ماهانه با محاسبه پایه سنوات
var monthlySalary = Tools.GetRoundDoubleValue(dailyWagePlusBaseYears * workingDays.countWorkingDays);
//حق تاهل
var marriedAllowanceForInsurance = item.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0;
//محاسبه مزایای ماهانه
var monthlyBenefits = _insuranceListApplication.GetMonthlyBenefits(endOfMonth, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marriedAllowanceForInsurance, workingDays.countWorkingDays, getContractsData.Data.TypeOfInsuranceSend, insuranceEmployeeDataItem.JobId, insuranceEmployeeDataItem.EmployeeId, insuranceEmployeeDataItem.IncludeStatus);
if (getContractsData.Data.HasInsuranceCheckoutOverTime)
{
monthlyBenefits = Tools.GetRoundDoubleValue(monthlyBenefits += overTimePay);
}
//محاسبه جمع مزایای مشمول و دستمزد ماهانه
var benefitsIncludedContinuous = monthlyBenefits + monthlySalary;
//محاسبه حق بیمه سهم بیمه شده
insuranceShare = (benefitsIncludedContinuous * 7) / 100;
}
}
#endregion
#region ResultToSave
var syear = Convert.ToInt32(item.ContractStart.Substring(0, 4));
var smonth = Convert.ToInt32(item.ContractStart.Substring(5, 2));
string monthfarsiName = (item.ContractStart.Substring(5, 2)).ToFarsiMonthByNumber();
var yearShamsi = item.ContractStart.Substring(0, 4);
var dayliWageDouble = mandatoryCompute.SalaryCompute.MoneyToDouble();
// کمک هزینه اقلام
var consumableItem = mandatoryCompute.ConsumableItems.MoneyToDouble();
//حق اولاد
var familyAllowance = mandatoryCompute.FamilyAllowance.MoneyToDouble();
//کمک هزینه مسکن
var housingAllowance = mandatoryCompute.HousingAllowance.MoneyToDouble();
//حق تاهل
var marriedAllowance = mandatoryCompute.MarriedAllowance.MoneyToDouble();
#region Salary
var totalDays = (item.Separation.ContractEndGr - item.Separation.ContractStartGr).TotalDays + 1;
//حقوق ماهانه
var monthlyWage = mandatoryCompute.DailySalaryAffected * totalDays;
//پایه سنوات
var bacicYears = mandatoryCompute.BaseYearAffected * totalDays;
#endregion
//سنوات
var years = yearsPay.YearsPay;
//عیدی و پاداش
var bunos = bunosesPay.Bunoses;
//فاطمه احمدژاد === موقت عیدی و پاداش و سنوات حساب نشه
if (item.EmployeeId == 45104 && getContractsData.Data.WorkshopId == 315)
{
years = 0;
bunos = 0;
}
//تعداد زروز های فیش
var sumOfWorkingDays = $"{totalDays}";
//مبلغ جمعه کاری
double fridayPay = 0;
if (Friday > 0)
{
var fridayPercent = dayliWageDouble * 40 / 100;
//فوق العاده جمعه کاری
fridayPay = fridayPercent * Friday;
}
//حق بیمه سهم کارگر
#region InsuranceDeduction
double insuranceDeduction = 0;
bool hasInsuranceShareTheSameAsList = false;
var inshuranceShareRound = Tools.GetRoundDoubleValue(insuranceShare);
if (inshuranceShareRound == 0)
{
var insuranceOverTime = getContractsData.Data.HasInsuranceCheckoutOverTime ? overTimePay : 0;
insuranceDeduction = (monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + insuranceOverTime) * 7 / 100;
}
else
{
insuranceDeduction = inshuranceShareRound;
hasInsuranceShareTheSameAsList = true;
}
#endregion
//مقادیر - روز - تعداد - ساعت
#region Values
//مدت شب کاری
var overNightWorkValue =
$"{Convert.ToInt32(mandatoryCompute.OverNightWorkH):00}:{Convert.ToInt32(mandatoryCompute.OverNightWorkM):00}";
//تعداد جمعه کاری
var fridayWorkValue = $"{Friday}";
//نوع نوبت کاری
var rotatingShiftValue = mandatoryCompute.RotatingShiftValue;
// تعداد سال های سنوات
var totalDayOfYearsCompute = yearsPay.YearsPay > 0 ? $"{yearsPay.TotalDayCompute}" : "0";
//تعداد روز های عیدی و پاداش
var totalDayOfBunosesCompute = bunosesPay.Bunoses > 0 ? $"{bunosesPay.TotalDayCompute}" : "0";
//مدت اضافه کارس
var overTimeWorkValue =
$"{Convert.ToInt32(mandatoryCompute.OverTimeWorkH):00}:{Convert.ToInt32(mandatoryCompute.OverTimeWorkM):00}";
#endregion
//کسر اضافه کار از غیبت یا بلعکس
#region OverTimeAndAbsencSubtraction
var absenceDeduction = abcenseDeductionCompute ? leavePayNew.AbsenceDeduction : 0;
if (overTimePay > 0 && absenceDeduction > 0)
{
if (absenceDeduction >= overTimePay)
{
absenceDeduction -= overTimePay;
overTimePay = 0;
overTimeWorkValue = "00:00";
}
else
{
overTimePay -= absenceDeduction;
absenceDeduction = 0;
}
}
#endregion
//مساعده
#region SalaryAid
var salaryAids =
_rollCallMandatoryRepository.SalaryAidsForCheckout(contract.EmployeeId, contract.WorkshopIds, startDateGr, endDateGr)
.Select(x => new CheckoutSalaryAid(x.Amount, x.SalaryAidDateTimeGe, x.SalaryAidDateTimeFa, x.CalculationDateTimeGe, x.CalculationDateTimeFa, x.Id)).ToList();
var salaryAidDeduction = salaryAids.Sum(x => x.Amount.MoneyToDouble());
#endregion
//اقساط وام
#region LoanInstallment
var loanInstallments = _rollCallMandatoryRepository.LoanInstallmentForCheckout(contract.EmployeeId, contract.WorkshopIds,
item.Separation.ContractStartGr, item.Separation.HasLeft ? DateTime.MaxValue : item.Separation.ContractEndGr)
.Select(x =>
new CheckoutLoanInstallment(x.Amount, x.Month, x.Year, x.IsActive, x.RemainingAmount, x.LoanAmount, x.Id)).ToList();
var installmentDeduction = loanInstallments.Sum(x => x.AmountForMonth.MoneyToDouble());
#endregion
//پاداش
#region Reward
var rewards = new List<CheckoutReward>();
double rewardPay = 0;
if (getContractsData.Data.RewardComputeOnCheckout)
{
rewards = _rollCallMandatoryRepository.RewardForCheckout(contract.EmployeeId, contract.WorkshopIds, startDateGr, endDateGr)
.Select(x => new CheckoutReward(x.Amount, x.AmountDouble, x.GrantDateFa, x.GrantDateGr, x.Description, x.Title, x.Id)).ToList();
rewardPay = rewards.Sum(x => x.AmountDouble);
}
#endregion
//جدول حضورغیاب پرسنل
#region CheckoutRollCall
//کارکرد واقعی - محاسبات شامل مرخصی افزوده شده
var totalWorkingTimeSpan = mandatoryCompute.TotalWorkingTimeSpan;
//ساعت استراحت
var totalBreakTimeSpan = mandatoryCompute.TotalBreakTimeSpan;
// ساعت حضور - بدون مرخصی افزده شده
var totalPresentTimeSpan = mandatoryCompute.TotalPresentTimeSpan;
//مدت مرخصی استحقاقی
var totalPaidLeave = mandatoryCompute.TotalPaidLeave;
//مدت مرخصی استعلاجی
var totalSickLeave = mandatoryCompute.TotalSickLeave;
var firstDayOfMonth = startDateGr;
var firstDayOfCurrentMonth = new DateTime(syear, smonth, 1, new PersianCalendar());
LeaveSearchModel sickLeaveSearch = new LeaveSearchModel()
{
EmployeeId = contract.EmployeeId,
WorkshopId = contract.WorkshopIds,
StartLeaveGr = item.Separation.ContractStartGr,
EndLeaveGr = item.Separation.ContractEndGr,
IsAccepted = true,
};
var leaves = _leaveApplication.search(sickLeaveSearch);
firstDayOfMonth.AddMonthsFa(1, out var lastDayOfCurrentMonth);
lastDayOfCurrentMonth = lastDayOfCurrentMonth.AddDays(-1);
int dateRange = (int)(lastDayOfCurrentMonth - firstDayOfCurrentMonth).TotalDays + 1;
var holidays = _holidayItemApplication.Search(new HolidayItemSearchModel()
{
HolidayYear = item.Separation.ContractStartGr.ToFarsiYear()
});
//all the dates from start to end, to be compared with present days to get absent dates
var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => firstDayOfCurrentMonth.AddDays(offset).Date).ToList();
var absentRecords = completeDaysList
.ExceptBy(mandatoryCompute.GroupedRollCalls.Select(x => x.CreationDate.Date), y => y.Date)
.Select(x =>
{
var leave = leaves.FirstOrDefault(y =>
y.EmployeeId == contract.EmployeeId && y.EndLeaveGr.Date >= x.Date && y.StartLeaveGr.Date <= x.Date);
var isHoliday = holidays.Any(y => y.HolidaydateGr == x.Date);
var isFriday = x.Date.DayOfWeek == DayOfWeek.Friday;
var isNormalWorkingDay = isHoliday == false && isFriday == false;
return new CheckoutDailyRollCallViewModel()
{
StartDate1 = null,
EndDate1 = null,
DateTimeGr = x.Date,
DayOfWeek = x.Date.DayOfWeek.ToString(),
RollCallDateFa = x.Date.ToFarsi(),
LeaveType = leave != null ? leave.LeaveType : "",
IsAbsent = leave == null && isNormalWorkingDay
};
});
var presentDays = mandatoryCompute.GroupedRollCalls.Select(x =>
{
var orderedRollcalls = x.ShiftList.OrderBy(y => y.Start);
var rollCallTimeSpanPerDay = x.SumOneDaySpan;
TimeSpan breakTimePerDay = x.BreakTime;
return new CheckoutDailyRollCallViewModel()
{
StartDate1 = orderedRollcalls.FirstOrDefault().Start.ToString("HH:mm"),
EndDate1 = orderedRollcalls.FirstOrDefault().EndWithOutResTime.ToString("HH:mm"),
StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.Start.ToString("HH:mm") ?? "",
EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndWithOutResTime.ToString("HH:mm") ?? "",
TotalhourseSpan = rollCallTimeSpanPerDay,
BreakTimeTimeSpan = breakTimePerDay,
DayOfWeek = x.CreationDate.DayOfWeek.DayOfWeeKToPersian(),
RollCallDateFa = x.CreationDate.Date.ToFarsi(),
DateTimeGr = x.CreationDate.Date,
IsSliced = x.ShiftList.Count() > 2,
IsAbsent = false
};
});
presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel
{
StartDate1 = x.StartDate1,
EndDate1 = x.EndDate1,
EndDate2 = x.EndDate2,
StartDate2 = x.StartDate2,
TotalWorkingHours = $"{(int)(x.TotalhourseSpan.TotalHours)}:{x.TotalhourseSpan.Minutes:00}",
BreakTimeString = $"{(int)(x.BreakTimeTimeSpan.TotalHours)}:{x.BreakTimeTimeSpan.Minutes:00}",
TotalhourseSpan = x.TotalhourseSpan,
BreakTimeTimeSpan = x.BreakTimeTimeSpan,
DayOfWeek = x.DayOfWeek,
RollCallDateFa = x.RollCallDateFa,
DateTimeGr = x.DateTimeGr,
IsSliced = x.IsSliced,
IsAbsent = false
});
var result = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList();
result.ForEach(x =>
{
x.IsHoliday = holidays.Any(y => x.DateTimeGr.Date == y.HolidaydateGr.Date);
x.IsFriday = x.DateTimeGr.DayOfWeek == DayOfWeek.Friday;
});
var checkoutRollCallDays = result.Select(x => new CheckoutRollCallDay(x.DateTimeGr,
x.StartDate1, x.EndDate1, x.StartDate2, x.EndDate2,
x.BreakTimeTimeSpan, x.IsSliced, x.TotalhourseSpan, x.IsAbsent, x.IsFriday, x.IsHoliday, x.LeaveType))
.ToList();
double mandatoryHours = _mandatoryHoursApplication.GetMandatoryHoursByYearAndMonth(syear, smonth);
int mandatoryWholeHours = (int)mandatoryHours;
int mandatoryMinutes = (int)((mandatoryHours - mandatoryWholeHours) * 60);
var totalMandatoryHours = TimeSpan.FromHours(mandatoryWholeHours).Add(TimeSpan.FromMinutes(mandatoryMinutes));
var checkoutRollCall = new CheckoutRollCall(totalMandatoryHours, totalPresentTimeSpan, totalBreakTimeSpan,
totalWorkingTimeSpan, totalPaidLeave, totalSickLeave, checkoutRollCallDays);
#endregion
//مقادیر پرداخت نهایی - مطالبات - کسورات
#region TotalPayment
var shiftPay = contract.WorkshopIds == 552 && hasRollCall ? 0 : mandatoryCompute.ShiftPay;
var totalClaimsDouble = monthlyWage + bacicYears + consumableItem + housingAllowance + marriedAllowance + overTimePay +
overNightPay + familyAllowance + bunos + years + leavePayNew.LeavPay + fridayPay + shiftPay + rewardPay;
var totalDeductionDouble = insuranceDeduction + absenceDeduction + installmentDeduction + salaryAidDeduction;
//مطالبات
var totalClaims = totalClaimsDouble.ToMoney();
//کسورات
var totalDeductions = totalDeductionDouble.ToMoney();
//مبلغ قابل پرداخت
var totalPayment = totalClaimsDouble - totalDeductionDouble;
#endregion
#region CreateCheckoutModel
var checkout = new Checkout(item.EmployeeFullName, item.FathersName, item.NationalCode
, item.DateOfBirth, item.EmployeeId, getContractsData.Data.WorkshopName, getContractsData.Data.WorkshopId, item.ContractNo, item.Separation.ContractStartGr, item.Separation.ContractEndGr, monthfarsiName, yearShamsi,
item.ContractId, item.WorkingHours.WorknigHoursId, monthlyWage, bacicYears, consumableItem, housingAllowance
, overTimePay, overNightPay, fridayPay, 0, shiftPay, familyAllowance, bunos, years, leavePayNew.LeavPay, insuranceDeduction, 0, installmentDeduction, salaryAidDeduction, absenceDeduction, sumOfWorkingDays,
getContractsData.Data.ArchiveCode, item.PersonnelCode, totalClaims, totalDeductions, totalPayment, "0", marriedAllowance, leavePayNew.LeaveCheckout, leavePayNew.CreditLeaves, leavePayNew.AbsencePeriod, leavePayNew.AverageHoursPerDay, hasRollCall, overTimeWorkValue, overNightWorkValue
, fridayWorkValue, rotatingShiftValue, "0", leavePayNew.TotalDayOfLeaveCompute, totalDayOfYearsCompute, totalDayOfBunosesCompute,
loanInstallments, salaryAids, checkoutRollCall, mandatoryCompute.EmployeeMandatoryHours, hasInsuranceShareTheSameAsList, rewards, rewardPay);
#endregion
#endregion
#region SaveToDb
var saveToDb = await _checkoutRepository.CreateCheckout(checkout);
if (!saveToDb)
{
createFailedCount += 1;
createFailedList.Add(item.EmployeeFullName);
}
else
{
createSuccessCount += 1;
}
#endregion
}
catch (Exception)
{
createFailedCount += 1;
createFailedList.Add(item.EmployeeFullName);
}
var percent = (successProcess / (double)countList) * 100;
// await signalR.SendAsync("showStatus", countList, createFailedCount, createSuccessCount, (int)percent, createFailedList);
await signalR.SendAsync("all", countList);
await signalR.SendAsync("failed", createFailedCount);
await signalR.SendAsync("Success", createSuccessCount);
await signalR.SendAsync("percent", (int)percent);
await signalR.SendAsync("failedList", createFailedList);
successProcess += 1;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("================================================================== ");
Console.WriteLine("======================================== Counter " + successProcess + " ================== ");
Console.WriteLine("================================================================== ");
Console.ResetColor();
}
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("after GetData To mandatoryCompute" + timer.Elapsed);
Console.ResetColor();
return op.Succcedded();
}
#endregion

View File

@@ -90,7 +90,7 @@ namespace CompanyManagment.Application
public bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd)
{
return _rollCallEmployeeRepository.HasRollCallRecord(employeeId, workshopId, contractStart, contractEnd);
return _rollCallEmployeeRepository.HasRollCallRecord(employeeId, workshopId, contractStart, contractEnd).GetAwaiter().GetResult();
}
public List<RollCallEmployeeStatusViewModel> GetActiveByWorkshopIdInDate(long workshopId, DateTime startDateGr, DateTime endDateGr)

View File

@@ -24,7 +24,7 @@ public class RollCallMandatoryApplication : IRollCallMandatoryApplication
public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout, bool rotatingShiftCompute, double dailyWageUnAffected, bool totalLeaveCompute)
{
return _rollCallMandatoryRepository.MandatoryCompute(employeeId,workshopId, contractStart, contractEnd, command, holidayWorking, isStaticCheckout, rotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute);
return _rollCallMandatoryRepository.MandatoryCompute(employeeId,workshopId, contractStart, contractEnd, command, holidayWorking, isStaticCheckout, rotatingShiftCompute, dailyWageUnAffected, totalLeaveCompute).GetAwaiter().GetResult();
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using _0_Framework.Application;
using _0_Framework.Application;
using _0_Framework.InfraStructure;
using Company.Domain.RollCallEmployeeAgg;
using Company.Domain.RollCallEmployeeStatusAgg;
@@ -13,6 +8,12 @@ using CompanyManagment.App.Contracts.RollCallEmployee;
using CompanyManagment.App.Contracts.RollCallEmployeeStatus;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace CompanyManagment.EFCore.Repository;
@@ -39,7 +40,7 @@ public class RollCallEmployeeRepository : RepositoryBase<long, RollCallEmployee>
}
public bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd)
public async Task<bool> HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd)
{
//موقت
// دادمهرگستر 11 *
@@ -89,8 +90,8 @@ public class RollCallEmployeeRepository : RepositoryBase<long, RollCallEmployee>
//if (rollCallEmployee == null)
// return false;
var rollCallEmployee = _context.RollCallEmployees.Include(xs => xs.EmployeesStatus)
.FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId);
var rollCallEmployee =await _context.RollCallEmployees.Include(xs => xs.EmployeesStatus)
.FirstOrDefaultAsync(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId);
//اگر تنظیمات حضور غیاب نداشت
if (rollCallEmployee == null)
return false;
@@ -99,8 +100,8 @@ public class RollCallEmployeeRepository : RepositoryBase<long, RollCallEmployee>
if (!rollCallEmployee.EmployeesStatus.Any())
return false;
var leftWork =
_context.LeftWorkList.FirstOrDefault(x =>
var leftWork = await
_context.LeftWorkList.FirstOrDefaultAsync(x =>
x.StartWorkDate <= contractEnd.Date && x.LeftWorkDate > contractStart);
if (leftWork == null)
return false;

View File

@@ -65,7 +65,7 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
#region OfficialChckout
public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart,
public async Task<ComputingViewModel> MandatoryCompute(long employeeId, long workshopId, DateTime contractStart,
DateTime contractEnd,
CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout, bool rotatingShiftCompute,
double dailyWageUnAffected, bool totalLeaveCompute)
@@ -86,7 +86,7 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
int TotalContractDays = (int)(contractEnd - contractStart).TotalDays + 1;
int fridays = 0;
int holiday = _context.HolidayItems.Count(x => x.Holidaydate >= contractStart && x.Holidaydate <= contractEnd);
int holiday =await _context.HolidayItems.CountAsync(x => x.Holidaydate >= contractStart && x.Holidaydate <= contractEnd);
;
for (var gDate = contractStart; gDate <= contractEnd; gDate = gDate.AddDays(1))
{
@@ -117,8 +117,8 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
#region breakTime
BaseCustomizeEntity settings = _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery()
.Include(x => x.CustomizeWorkshopGroupSettings).FirstOrDefault(x =>
BaseCustomizeEntity settings =await _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery()
.Include(x => x.CustomizeWorkshopGroupSettings).FirstOrDefaultAsync(x =>
x.WorkshopId == workshopId && x.EmployeeId == employeeId);
//اگر ساعت استراحت پرسنل وجود نداشت صفر است
var breakTimeEntity = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime;
@@ -196,7 +196,7 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
}
else
{
rollCallResult = _context.RollCalls.Where(x =>
rollCallResult =await _context.RollCalls.Where(x =>
x.EmployeeId == employeeId && x.WorkshopId == workshopId &&
x.StartDate.Value.Date >= contractStart.Date &&
x.StartDate.Value.Date <= contractEnd.Date && x.EndDate != null).Select(x => new RollCallViewModel()
@@ -206,7 +206,7 @@ public class RollCallMandatoryRepository : RepositoryBase<long, RollCall>, IRoll
ShiftSpan = (x.EndDate.Value - x.StartDate.Value),
CreationDate = x.ShiftDate,
BreakTimeSpan = x.BreakTimeSpan
}).ToList();
}).ToListAsync();
groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.Date).Select(x =>
{

View File

@@ -2789,7 +2789,7 @@ public class YearlySalaryRepository : RepositoryBase<long, YearlySalary>, IYearl
private (bool hasRollCall, double WorkingTotalHours) GetTotalWorkingHoursIfHasRollCall(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd)
{
bool hasRollCall = _rollCallEmployeeRepository.HasRollCallRecord(employeeId, workshopId,
contractStart, contractEnd);
contractStart, contractEnd).GetAwaiter().GetResult();
double totalWorkingHours = 0;
if (!hasRollCall)
return (false, 0);

View File

@@ -6,6 +6,7 @@ using CompanyManagment.App.Contracts.Workshop;
using CompanyManagment.App.Contracts.Workshop.DTOs;
using Microsoft.AspNetCore.Mvc;
using NuGet.Packaging.Signing;
using NuGet.Protocol;
using ServiceHost.BaseControllers;
using WorkFlow.Application.Contracts.WorkFlow;
@@ -108,16 +109,84 @@ public class CheckoutController : AdminBaseController
[HttpGet("GetContractsToCreateCheckout")]
public async Task<OperationResult<List<ContractsListToCreateCheckoutDto>>> GetContractsToCreateCheckout(long workshopId, string year, string month, long employeeId)
{
var result =await _checkoutApplication.GetContractToCreateCheckout(workshopId, year, month, employeeId);
if (!result.IsSuccedded)
return result;
var hasWorkFlow =await _workFlowApplication.HasWorkFlow(workshopId, year, month);
//var hasWorkFlow =await _workFlowApplication.HasWorkFlow(workshopId, year, month);
if (hasWorkFlow)
return new OperationResult<List<ContractsListToCreateCheckoutDto>>().Failed(
"این کارگاه به دلیل داشتن کارپوشه مجاز به ایجاد تصفیه حساب نمی باشد");
//if (hasWorkFlow)
// return new OperationResult<List<ContractsListToCreateCheckoutDto>>().Failed(
// "این کارگاه به دلیل داشتن کارپوشه مجاز به ایجاد تصفیه حساب نمی باشد");
return result;
}
/// <summary>
/// ایجاد فیش حقوقی
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
[HttpPost]
public async Task<ActionResult<OperationResult>> CreateCheckout([FromBody] CreateCheckoutDto command)
{
var op = new OperationResult();
//var ids = new
// List<long>()
// {
// 283652, 290314, 290315, 290316, 290317, 290318, 290319, 290320, 290321, 290322, 290323, 290324, 290325,
// 290326, 290327, 290328, 290329, 290330, 290331, 290332, 290333, 290334, 290335, 290336, 290337, 290338,
// 290339, 290340, 290341, 290342, 290343, 290344, 290345, 290346, 290347, 290348, 290349, 290350, 290351,
// 290352, 290353, 290354, 290355, 290356, 290357, 290358, 290359, 290360, 290361, 290362, 290363, 290364,
// 290365, 290366, 290367, 290368, 290369, 290370, 290371, 290372, 290373, 290374, 290375, 290376, 290377,
// 290378, 290379, 290380, 290381, 290382, 290383, 290384, 290385, 290386, 290387, 290388, 290389, 290390,
// 290391, 290392, 290393, 290394, 290395, 290396, 290397, 290398, 290399, 290400, 290401, 290402, 290403,
// 290404, 290405, 290406, 290407, 290408, 290409, 290410, 290411, 290412, 290413, 290414, 290415, 290416,
// 290417, 290418, 290419, 290420, 290421, 290422, 290423, 290424, 290425, 290426, 290427, 290428, 290429,
// 290430, 290431, 290432, 290433, 290434, 290435, 290436, 290437, 290438, 290439, 290440, 290441, 290442,
// 290443, 290444, 290445, 290446, 290447, 290448, 290449, 290450, 290451, 290452, 290453, 290454, 290455,
// 290456, 290457, 290458, 290459, 290460, 290461, 290462, 290463, 290464, 290465, 290466, 290467, 290468,
// 290469, 290470, 290471, 290472, 290473, 290474, 290475, 290476, 290477, 290478, 290479, 290480, 290481,
// 290482, 290483, 290484, 290485, 290486, 290487, 290488, 290489, 290490, 290491, 290492, 290493, 290494,
// 290495, 290496, 290497, 290498, 290499, 290500, 290501, 290502, 290503, 290504, 290505, 290506, 290507,
// 290508, 290509, 290510, 290511, 290512, 290513, 290514, 290515, 290516, 290517, 290518, 290519, 290520,
// 290521, 290522, 290523, 290524, 290525, 290526, 290527, 290528, 290529, 290530, 290531, 290532, 290533,
// 290534, 290535, 290536, 290537, 290538, 290539, 290540, 290541, 290542, 290543, 290544, 290545, 290546,
// 290547, 290548, 290549, 290550, 290551, 290552, 290553, 290554, 290555, 290556, 290557, 290558, 290559,
// 290560, 290561, 290562, 290563, 290564, 290565, 290566, 290567, 290568, 290569, 290570, 290571, 290572,
// 290573, 290574, 290575, 290576, 290577, 290578, 290579, 290580, 290581, 290582, 290583, 290584, 290585,
// 299612, 290587, 290588
// };
//command.Ids = new List<long>(){ 290449 };
if (!string.IsNullOrWhiteSpace(command.year) && string.IsNullOrWhiteSpace(command.Month))
return op.Failed("ماه را انتخاب کنید");
if (string.IsNullOrWhiteSpace(command.year) && !string.IsNullOrWhiteSpace(command.Month))
return op.Failed("سال را انتخاب کنید");
if (string.IsNullOrWhiteSpace(command.year) && string.IsNullOrWhiteSpace(command.Month))
{
var today = DateTime.Now;
var FaToday = today.ToFarsi();
var convertedYear = FaToday.Substring(0, 4);
var convertedMonth = FaToday.Substring(5, 2);
command.year = convertedYear;
command.Month = convertedMonth;
}
if (command.WorkshopId == 0)
return op.Failed("کارگاه انتخاب نشده است");
if (command.Ids.Count == 0)
return op.Failed("هیچ موردی انتخاب نشده است");
var result = await _checkoutApplication.CreateCheckoutApi(command.Ids, command.year, command.Month, command.WorkshopId);
return result;
}
@@ -125,3 +194,12 @@ public class CheckoutController : AdminBaseController
}
public class CreateCheckoutDto
{
public List<long> Ids { get; set; }
public string year { get; set; }
public string Month { get; set; }
public long WorkshopId { get; set; }
}

View File

@@ -38,6 +38,7 @@ using Company.Domain.InsuranceListAgg;
using CompanyManagment.App.Contracts.InsuranceList;
using CompanyManagment.EFCore.Repository;
using System.Linq;
using CompanyManagment.App.Contracts.Hubs;
namespace ServiceHost.Areas.Admin.Pages.Company.Checkouts;
@@ -7853,6 +7854,8 @@ public class IndexModel : PageModel
}
#endregion
}

View File

@@ -1,18 +0,0 @@
using Microsoft.AspNetCore.SignalR;
namespace ServiceHost.Hubs
{
public class CheckoutHub : Hub
{
public async Task send(long id)
{
await Groups.AddToGroupAsync(Context.ConnectionId, GetGroupName(id));
}
public static string GetGroupName(long id)
{
return $"group-Checkout-{id}";
}
}
}