272 lines
8.6 KiB
C#
272 lines
8.6 KiB
C#
using _0_Framework.Application;
|
|
using CompanyManagment.App.Contracts.Error;
|
|
using CompanyManagment.App.Contracts.Loan;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using System.Security.Claims;
|
|
using _0_Framework.Infrastructure;
|
|
using Company.Domain.CustomizeCheckoutAgg;
|
|
using CompanyManagement.Infrastructure.Excel.SalaryAid;
|
|
using CompanyManagment.App.Contracts.CustomizeCheckout;
|
|
using CompanyManagment.App.Contracts.SalaryAid;
|
|
using CompanyManagment.App.Contracts.Employee;
|
|
using CompanyManagment.App.Contracts.YearlySalary;
|
|
|
|
namespace ServiceHost.Areas.Client.Pages.Company.SalaryAid
|
|
{
|
|
[Authorize]
|
|
[NeedsPermission(SubAccountPermissionHelper.SalaryAidOperationsPermissionCode)]
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly IPasswordHasher _passwordHasher;
|
|
private readonly ISalaryAidApplication _salaryAidApplication;
|
|
private readonly IEmployeeApplication _employeeApplication;
|
|
private readonly IYearlySalaryApplication _yearlySalaryApplication;
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly ICustomizeCheckoutApplication _customizeCheckoutApplication;
|
|
private readonly SalaryAidImportExcel _salaryAidImportExcel;
|
|
|
|
private readonly long _workshopId;
|
|
public string WorkshopFullName;
|
|
public int PageIndex = 0;
|
|
private readonly ICustomizeCheckoutRepository _customizeCheckoutRepository;
|
|
|
|
public IndexModel(IPasswordHasher passwordHasher, ISalaryAidApplication salaryAidApplication,
|
|
IEmployeeApplication employeeApplication, IHttpContextAccessor contextAccessor, IAuthHelper authHelper, SalaryAidImportExcel salaryAidImportExcel, ICustomizeCheckoutApplication customizeCheckoutApplication, ICustomizeCheckoutRepository customizeCheckoutRepository, IYearlySalaryApplication yearlySalaryApplication)
|
|
{
|
|
_passwordHasher = passwordHasher;
|
|
_salaryAidApplication = salaryAidApplication;
|
|
_employeeApplication = employeeApplication;
|
|
_authHelper = authHelper;
|
|
_salaryAidImportExcel = salaryAidImportExcel;
|
|
_yearlySalaryApplication = yearlySalaryApplication;
|
|
_customizeCheckoutApplication = customizeCheckoutApplication;
|
|
_customizeCheckoutRepository = customizeCheckoutRepository;
|
|
|
|
var workshopHash = _authHelper.GetWorkshopSlug();
|
|
_workshopId = _passwordHasher.SlugDecrypt(workshopHash);
|
|
|
|
if (_workshopId < 1)
|
|
throw new InvalidDataException("اختلال در کارگاه");
|
|
}
|
|
|
|
public IActionResult OnGet()
|
|
{
|
|
WorkshopFullName = _authHelper.GetWorkshopName();
|
|
|
|
return Page();
|
|
}
|
|
|
|
public IActionResult OnGetYearlyList()
|
|
{
|
|
var resultData = _yearlySalaryApplication.GetYears();
|
|
return new JsonResult(new
|
|
{
|
|
success = true,
|
|
data = resultData
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetLoadDataAjax(SalaryAidSearchViewModel searchViewModel)
|
|
{
|
|
searchViewModel.WorkshopId = _workshopId;
|
|
|
|
var result = _salaryAidApplication.GetSearchList(searchViewModel);
|
|
return new JsonResult(new
|
|
{
|
|
success = true,
|
|
data = result,
|
|
pageIndex = result.Count()
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetLoadDataByEmployeeAjax(SalaryAidSearchViewModel searchViewModel)
|
|
{
|
|
searchViewModel.WorkshopId = _workshopId;
|
|
|
|
var result = _salaryAidApplication.GetSearchListAsGrouped(searchViewModel);
|
|
return new JsonResult(new
|
|
{
|
|
success = true,
|
|
data = result,
|
|
});
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetEmployeeList()
|
|
{
|
|
var employees = await _employeeApplication.WorkedEmployeesInWorkshopSelectList(_workshopId);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
success = true,
|
|
data = employees
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetCreate()
|
|
{
|
|
var command = new CreateSalaryAidViewModel();
|
|
return Partial("ModalCreateNewSalaryAid", command);
|
|
}
|
|
|
|
public IActionResult OnPostCreate(CreateSalaryAidViewModel command)
|
|
{
|
|
command.WorkshopId = _workshopId;
|
|
var result = _salaryAidApplication.Create(command);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message,
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetEdit(long id)
|
|
{
|
|
var command = _salaryAidApplication.GetDetails(id);
|
|
return Partial("ModalEditSalaryAid", command);
|
|
}
|
|
|
|
public IActionResult OnPostEdit(EditSalaryAidViewModel command)
|
|
{
|
|
command.WorkshopId = _workshopId;
|
|
var result = _salaryAidApplication.Edit(command);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message,
|
|
});
|
|
}
|
|
|
|
public IActionResult OnPostRemove(long id)
|
|
{
|
|
var result = _salaryAidApplication.Remove(id);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = result.IsSuccedded,
|
|
message = result.Message,
|
|
});
|
|
}
|
|
public IActionResult OnGetImportExcel()
|
|
{
|
|
return Partial("ModalImportExcel");
|
|
}
|
|
|
|
public IActionResult OnGetDownloadExcelTemplate()
|
|
{
|
|
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Excel", "Templates", "SalaryAid", "SA-Template.xlsx");
|
|
var bytes = System.IO.File.ReadAllBytes(filePath);
|
|
return File(bytes,
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
"قالب مساعده.xlsx");
|
|
}
|
|
|
|
public IActionResult OnPostValidateExcel(IFormFile excel)
|
|
{
|
|
var validation = _salaryAidImportExcel.ReadAndValidateExcel(excel, _workshopId);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
IsSuccess = !validation.Errors.Any(),
|
|
data = validation
|
|
});
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostCreateFromExcelData(List<SalaryAidImportData> data)
|
|
{
|
|
var commands = data.Select(x => new CreateSalaryAidViewModel()
|
|
{
|
|
WorkshopId = x.WorkshopId,
|
|
Amount = x.Amount.ToMoney(),
|
|
EmployeeIds = [x.EmployeeId],
|
|
SalaryDateTime = x.SalaryAidDateTime,
|
|
NationalCode = x.NationalCode,
|
|
CalculationMonth = x.calculationMonth,
|
|
CalculationYear = x.calculationYear
|
|
}).ToList();
|
|
OperationResult result = await _salaryAidApplication.CreateRangeAsync(commands);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
result.IsSuccedded,
|
|
result.Message
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetCreateValidation(DateTime dateTime,string employeeIds,long workshopId)
|
|
{
|
|
var extractNumbers = employeeIds.ExtractNumbers();
|
|
|
|
var op = new OperationResult();
|
|
_ = DateTime.Now.Date.AddMonthsFa(-1, out var oneMonthAgoGr);
|
|
|
|
if (oneMonthAgoGr > dateTime)
|
|
{
|
|
var prevCheckouts = _customizeCheckoutRepository.ValidateExistsCheckouts(dateTime,
|
|
oneMonthAgoGr, workshopId, extractNumbers);
|
|
|
|
if (prevCheckouts.CustomizeCheckout || prevCheckouts.Checkout || prevCheckouts.CustomizeCheckoutTemp)
|
|
{
|
|
op.Failed("شما نمیتوانید در تاریخ قبل از یک ماه گذشته که فیش صادر شده باشد مساعده دهید");
|
|
return new JsonResult(new
|
|
{
|
|
op.IsSuccedded,
|
|
op.Message
|
|
});
|
|
}
|
|
}
|
|
|
|
var existsCheckouts = _customizeCheckoutRepository.ValidateExistsCheckouts(dateTime,
|
|
dateTime, workshopId, extractNumbers);
|
|
|
|
if (existsCheckouts.Checkout)
|
|
{
|
|
op.Failed("شما نمیتوانید برای پرسنلی در تاریخی که برای فیش حقوقی رسمی صادر شده است مساعده دهید");
|
|
return new JsonResult(new
|
|
{
|
|
op.IsSuccedded,
|
|
op.Message
|
|
});
|
|
|
|
}
|
|
|
|
op.Succcedded();
|
|
return new JsonResult(new
|
|
{
|
|
op.IsSuccedded,
|
|
op.Message,
|
|
data = existsCheckouts
|
|
});
|
|
|
|
}
|
|
public IActionResult OnGetSearch(SalaryAidSearchViewModel searchModel)
|
|
{
|
|
searchModel.WorkshopId = _workshopId;
|
|
var result = _salaryAidApplication.GetSearchListAsGrouped(searchModel);
|
|
return new JsonResult(new
|
|
{
|
|
data = result
|
|
});
|
|
}
|
|
public IActionResult OnPostCheckoutExists(string calculationDate, string employeeIds)
|
|
{
|
|
var extractNumbers = employeeIds.ExtractNumbers();
|
|
var calculationDateGr = calculationDate.ToGeorgianDateTime();
|
|
|
|
var validateExistsCheckouts =
|
|
_customizeCheckoutApplication.ValidateExistsCheckouts(calculationDateGr, calculationDateGr, _workshopId, extractNumbers);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
checkout = validateExistsCheckouts.Checkout,
|
|
customizeCheckout = validateExistsCheckouts.CustomizeCheckout,
|
|
customizeCheckoutTemp = validateExistsCheckouts.CustomizeCheckoutTemp,
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|