Files
Backend-Api/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/PrintAllCheckoutTemporary.cshtml.cs
2025-01-20 17:31:03 +03:30

303 lines
10 KiB
C#

using _0_Framework.Application;
using CompanyManagment.App.Contracts.CustomizeCheckout;
using CompanyManagment.App.Contracts.Workshop;
using CompanyManagment.App.Contracts.YearlySalary;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Security.Claims;
using System.Text.RegularExpressions;
using _0_Framework.Excel.Checkout;
using CompanyManagment.App.Contracts.EmployeeBankInformation;
namespace ServiceHost.Areas.Client.Pages.Company.CustomizeCheckout
{
public class PrintAllCheckoutTemporaryModel : PageModel
{
private readonly IWorkshopApplication _workshopApplication;
private readonly IYearlySalaryApplication _yearlySalaryApplication;
private readonly IPasswordHasher _passwordHasher;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ICustomizeCheckoutTempApplication _customizeCheckoutTempApplication;
private readonly IEmployeeBankInformationApplication _employeeBankInformationApplication;
public long WorkshopId;
private readonly long _workshopId;
public int YearFa;
public int MonthFa;
//by pooya
public List<CustomizeCheckoutViewModel> GroupPrintList;
public CustomizeChekoutDividedPrintViewModel DividList;
public int StartPrint;
public int EndPrint;
public List<long> printIdList;
public CustomizeCheckoutBatchPrintViewModel sendIds;
public PrintAllCheckoutTemporaryModel(IPasswordHasher passwordHasher, IHttpContextAccessor httpContextAccessor, IWorkshopApplication workshopApplication, IYearlySalaryApplication yearlySalaryApplication, ICustomizeCheckoutTempApplication customizeCheckoutTempApplication, IEmployeeBankInformationApplication employeeBankInformationApplication)
{
_passwordHasher = passwordHasher;
_httpContextAccessor = httpContextAccessor;
_workshopApplication = workshopApplication;
_yearlySalaryApplication = yearlySalaryApplication;
_customizeCheckoutTempApplication = customizeCheckoutTempApplication;
_employeeBankInformationApplication = employeeBankInformationApplication;
var workshopHash = _httpContextAccessor.HttpContext?.User.FindFirstValue("WorkshopSlug");
_workshopId = _passwordHasher.SlugDecrypt(workshopHash);
}
public void OnGet(string idlist)
{
var ids = idlist.ExtractNumbers();
var resultList = new List<CustomizeCheckoutBatchPrintViewModel>();
var res = _customizeCheckoutTempApplication.PrintAll(_workshopId, ids);
var printCounter = ids.Count();
if (printCounter <= 25)
{
GroupPrintList = res;
var addToList = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Select(x => x.Id).ToList(),
StartPrint = 1,
EndPrint = printCounter,
};
resultList.Add(addToList);
var finalResult = new CustomizeChekoutDividedPrintViewModel()
{
CustomizeCheckoutGroupPrintViewModels = resultList,
ButtonCounter = resultList.Count,
};
DividList = finalResult;
}
else
{
var divide20 = printCounter / 20;
var multiple = printCounter - (divide20 * 20);
if (multiple == 0)
{
for (int i = 1; i <= printCounter; i += 20)
{
var start = i;
var end = i + 19;
if (i == 1)
{
GroupPrintList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).ToList();
var addToList = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).Select(x => x.Id).ToList(),
StartPrint = start,
EndPrint = end,
};
resultList.Add(addToList);
}
else
{
var addToList = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).Select(x => x.Id).ToList(),
StartPrint = start,
EndPrint = end,
};
resultList.Add(addToList);
}
}
var finalResult = new CustomizeChekoutDividedPrintViewModel()
{
CustomizeCheckoutGroupPrintViewModels = resultList,
ButtonCounter = resultList.Count,
};
DividList = finalResult;
}
else if (multiple <= 5)
{
int endOfround = 0;
for (int i = 1; i <= printCounter - 26; i += 20)
{
var start = i;
var end = i + 19;
if (i == 1)
{
GroupPrintList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).ToList();
endOfround = end;
var addToList = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).Select(x => x.Id).ToList(),
StartPrint = start,
EndPrint = end,
};
resultList.Add(addToList);
}
else
{
var addToList = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).Select(x => x.Id).ToList(),
StartPrint = start,
EndPrint = end,
};
endOfround = end;
resultList.Add(addToList);
}
}
var count = res.Where(x => x.PrintCounter > endOfround).ToList();
var addLastPart = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Where(x => x.PrintCounter > endOfround).Select(x => x.Id).ToList(),
StartPrint = count.Select(x => x.PrintCounter).FirstOrDefault(),
EndPrint = count.Select(x => x.PrintCounter).LastOrDefault(),
};
resultList.Add(addLastPart);
var finalResult = new CustomizeChekoutDividedPrintViewModel()
{
CustomizeCheckoutGroupPrintViewModels = resultList,
ButtonCounter = resultList.Count,
};
DividList = finalResult;
}
else if (multiple > 5)
{
int endOfround = 0;
var pcounter = multiple + 1;
for (int i = 1; i <= printCounter - pcounter; i += 20)
{
var start = i;
var end = i + 19;
if (i == 1)
{
GroupPrintList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).ToList();
endOfround = end;
var addToList = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).Select(x => x.Id).ToList(),
StartPrint = start,
EndPrint = end,
};
resultList.Add(addToList);
}
else
{
var addToList = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Where(x => x.PrintCounter >= start && x.PrintCounter <= end).Select(x => x.Id).ToList(),
StartPrint = start,
EndPrint = end,
};
endOfround = end;
resultList.Add(addToList);
}
}
var count = res.Where(x => x.PrintCounter > endOfround).ToList();
var addLastPart = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutIdList = res.Where(x => x.PrintCounter > endOfround).Select(x => x.Id).ToList(),
StartPrint = count.Select(x => x.PrintCounter).FirstOrDefault(),
EndPrint = count.Select(x => x.PrintCounter).LastOrDefault(),
};
resultList.Add(addLastPart);
var finalResult = new CustomizeChekoutDividedPrintViewModel()
{
CustomizeCheckoutGroupPrintViewModels = resultList,
ButtonCounter = resultList.Count,
};
DividList = finalResult;
}
}
}
public IActionResult OnGetPrintAll(CustomizeCheckoutBatchPrintViewModel sendIds)
{
var res = _customizeCheckoutTempApplication.PrintAll(_workshopId, sendIds.CustomizeCheckoutIdList);
var result = new CustomizeCheckoutBatchPrintViewModel()
{
CustomizeCheckoutViewModels = res,
};
return Partial("PrintAllTemporary", result);
}
public IActionResult OnGetDownloadExcelAll(string idList)
{
var ids = idList.ExtractNumbers();
var res = _customizeCheckoutTempApplication.PrintAll(_workshopId, ids);
var bankInformation = _employeeBankInformationApplication.GetAllByWorkshopId(_workshopId);
var customizeCheckoutTempExcelViewModels = res.Select(x =>
{
var employeeBankInformation = bankInformation.FirstOrDefault(b => b.EmployeeId == x.EmployeeId)?.BankInformation.FirstOrDefault();
return new CustomizeCheckoutTempExcelViewModel()
{
EmployeeId = x.EmployeeId,
Month = x.Month,
Year = x.Year,
PersonnelCode = x.PersonnelCode,
MonthlySalary = x.MonthlySalary,
BaseYearsPay = x.BaseYearsPay,
OvertimePay = x.OvertimePay,
NightworkPay = x.NightworkPay,
FridayPay = x.FridayPay,
ShiftPay = x.ShiftPay,
FamilyAllowance = x.FamilyAllowance,
BonusesPay = x.BonusesPay,
LeavePay = x.LeavePay,
InsuranceDeduction = x.InsuranceDeduction,
TaxDeducation = x.TaxDeducation,
InstallmentDeduction = x.InstallmentDeduction,
SalaryAidDeduction = x.SalaryAidDeduction,
AbsenceDeduction = x.AbsenceDeduction,
TotalClaims = x.TotalClaims,
TotalDeductions = x.TotalDeductions,
TotalPayment = x.TotalPayment,
RewardPay = x.RewardPay,
MarriedAllowance = x.MarriedAllowance,
SumOfWorkingDays = x.SumOfWorkingDays,
NationalCode = x.NationalCode,
EmployeeFName = x.EmployeeFName,
EmployeeLName = x.EmployeeLName,
EarlyExitDeduction = x.EarlyExitDeduction,
LateToWorkDeduction = x.LateToWorkDeduction,
FineDeduction = x.FineDeduction,
BankAccountNumber = employeeBankInformation?.BankAccountNumber,
CardNumber = employeeBankInformation?.CardNumber,
ShebaNumber = employeeBankInformation?.ShebaNumber
};
}).ToList();
var excelBytes = CustomizeCheckoutExcelGenerator.GenerateCheckoutTempExcelInfo(customizeCheckoutTempExcelViewModels, []);
return File(excelBytes,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"گزارش تجمیعی فیش حقوقی غیر رسمی موقت.xlsx");
}
}
}