445 lines
16 KiB
C#
445 lines
16 KiB
C#
using System.Globalization;
|
|
using _0_Framework.Application;
|
|
using CompanyManagment.App.Contracts.CustomizeCheckout;
|
|
using CompanyManagment.App.Contracts.Employee;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using CompanyManagment.App.Contracts.YearlySalary;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using NuGet.Packaging.Signing;
|
|
using System.Security.Claims;
|
|
using System.Security.Cryptography;
|
|
using System.Text.RegularExpressions;
|
|
using _0_Framework.Infrastructure;
|
|
using CompanyManagment.App.Contracts.Bank;
|
|
using System.Linq;
|
|
|
|
namespace ServiceHost.Areas.Client.Pages.Company.CustomizeCheckout;
|
|
|
|
[NeedsPermission(SubAccountPermissionHelper.CustomizeCheckoutListPermissionCode)]
|
|
public class CheckoutUnofficialModel : PageModel
|
|
{
|
|
private readonly ICustomizeCheckoutApplication _customizeCheckoutApplication;
|
|
private readonly IWorkshopApplication _workshopApplication;
|
|
private readonly IEmployeeApplication _employeeApplication;
|
|
private readonly IBankApplication _bankApplication;
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly IPasswordHasher _passwordHasher;
|
|
private readonly IYearlySalaryApplication _yearlySalaryApplication;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
private readonly long _workshopId;
|
|
public string WorkshopFullName;
|
|
public SearchCustomizeCheckout SearchModel;
|
|
public List<string> YearlyList;
|
|
|
|
//by pooya
|
|
public List<CustomizeCheckoutViewModel> GroupPrintList;
|
|
public CustomizeChekoutDividedPrintViewModel DividList;
|
|
public int StartPrint;
|
|
public int EndPrint;
|
|
public List<long> printIdList;
|
|
|
|
public List<CustomizeCheckoutViewModel> CustomizeCheckouts { get; set; }
|
|
|
|
public CheckoutUnofficialModel(ICustomizeCheckoutApplication customizeCheckoutApplication, IAuthHelper authHelper, IPasswordHasher passwordHasher, IHttpContextAccessor httpContextAccessor, IWorkshopApplication workshopApplication, IEmployeeApplication employeeApplication, IYearlySalaryApplication yearlySalaryApplication, IBankApplication bankApplication)
|
|
{
|
|
_customizeCheckoutApplication = customizeCheckoutApplication;
|
|
_authHelper = authHelper;
|
|
_passwordHasher = passwordHasher;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_workshopApplication = workshopApplication;
|
|
_employeeApplication = employeeApplication;
|
|
_yearlySalaryApplication = yearlySalaryApplication;
|
|
_bankApplication = bankApplication;
|
|
|
|
var workshopHash = _httpContextAccessor.HttpContext?.User.FindFirstValue("WorkshopSlug");
|
|
_workshopId = _passwordHasher.SlugDecrypt(workshopHash);
|
|
|
|
if (_workshopId < 1)
|
|
throw new InvalidDataException("اختلال در کارگاه");
|
|
}
|
|
|
|
public IActionResult OnGet(SearchCustomizeCheckout searchModel)
|
|
{
|
|
WorkshopFullName = _workshopApplication.GetWorkshopInfo(_workshopId).WorkshopFullName;
|
|
|
|
searchModel.WorkshopId = _workshopId;
|
|
CustomizeCheckouts = _customizeCheckoutApplication.Search(searchModel);
|
|
|
|
YearlyList = _yearlySalaryApplication.GetYears();
|
|
|
|
SearchModel = new SearchCustomizeCheckout()
|
|
{
|
|
Year = searchModel.Year,
|
|
Month = searchModel.Month,
|
|
SearchStartFa = searchModel.SearchStartFa,
|
|
SearchEndFa = searchModel.SearchEndFa,
|
|
EmployeeId = searchModel.EmployeeId,
|
|
OrderBy = searchModel.OrderBy,
|
|
BankId = searchModel.BankId,
|
|
PageIndex = CustomizeCheckouts.Count()
|
|
};
|
|
|
|
|
|
return Page();
|
|
}
|
|
|
|
//public void OnGet(string idlist)
|
|
//{
|
|
// var ids = ExtractNumbers(idlist);
|
|
// var resultList = new List<CustomizeCheckoutBatchPrintViewModel>();
|
|
|
|
// var res = _customizeCheckoutApplication.PrintAll(_workshopId, ids);
|
|
// //WorkshopId = res.Select(x => x.WorkshopId).FirstOrDefault();
|
|
// 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 = _customizeCheckoutApplication.PrintAll(_workshopId, sendIds.CustomizeCheckoutIdList);
|
|
// var result = new CustomizeCheckoutBatchPrintViewModel()
|
|
// {
|
|
// CustomizeCheckoutViewModels = res,
|
|
// };
|
|
// return Partial("PrintAll", result);
|
|
//}
|
|
|
|
//static List<long> ExtractNumbers(string input)
|
|
//{
|
|
// List<long> numbers = new List<long>();
|
|
// string pattern = @"\d+"; // Matches one or more digits
|
|
|
|
// MatchCollection matches = Regex.Matches(input, pattern);
|
|
|
|
// foreach (Match match in matches)
|
|
// {
|
|
// if (long.TryParse(match.Value, out long number))
|
|
// {
|
|
// numbers.Add(number);
|
|
// }
|
|
// }
|
|
|
|
// return numbers;
|
|
//}
|
|
public IActionResult OnGetCustomizeCheckoutsList(SearchCustomizeCheckout searchModel)
|
|
{
|
|
var permission = _authHelper.GetPermissions();
|
|
string printPermission = permission.Any(x=> x == SubAccountPermissionHelper.PrintCustomizeCheckoutPermissionCode) ? "true" : "false";
|
|
string deletePermission = permission.Any(x => x == SubAccountPermissionHelper.DeleteCustomizeCheckoutPermissionCode) ? "true" : "false";
|
|
|
|
var search = new SearchCustomizeCheckout()
|
|
{
|
|
WorkshopId = _workshopId,
|
|
Year = searchModel.Year,
|
|
Month = searchModel.Month,
|
|
SearchStartFa = searchModel.SearchStartFa,
|
|
SearchEndFa = searchModel.SearchEndFa,
|
|
EmployeeId = searchModel.EmployeeId,
|
|
OrderBy = searchModel.OrderBy,
|
|
PageIndex = searchModel.PageIndex
|
|
};
|
|
|
|
var resultData = _customizeCheckoutApplication.Search(search).ToList();
|
|
|
|
return new JsonResult(new
|
|
{
|
|
success = true,
|
|
data = resultData,
|
|
pageIndex = resultData.Count(),
|
|
printPermission = printPermission,
|
|
deletePermission = deletePermission,
|
|
});
|
|
}
|
|
|
|
public async Task<IActionResult> OnGetEmployeeList()
|
|
{
|
|
var result = await _employeeApplication.WorkedEmployeesInWorkshopSelectList(_workshopId);
|
|
return new JsonResult(new
|
|
{
|
|
success = true,
|
|
data = result
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetCreate()
|
|
{
|
|
PersianCalendar pc = new PersianCalendar();
|
|
DateTime now = DateTime.Now;
|
|
|
|
// رفتن به ماه گذشته
|
|
DateTime lastMonth = pc.AddMonths(now, -1);
|
|
|
|
int year = pc.GetYear(lastMonth);
|
|
int month = pc.GetMonth(lastMonth);
|
|
|
|
var model = new GetCreateCustomizeCheckout()
|
|
{
|
|
Years = _yearlySalaryApplication.GetYears(),
|
|
LastMonth = month.ToString(),
|
|
LastYear =year.ToString()
|
|
};
|
|
|
|
|
|
return Partial("ModalCheckoutUnofficialCreate",model);
|
|
}
|
|
|
|
public IActionResult OnPostCreate(CreateCustomizeCheckoutGroup command)
|
|
{
|
|
command.WorkshopId = _workshopId;
|
|
var result = _customizeCheckoutApplication.GroupCreate(command);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetEmployeesByYearAndMonth(int year, int month)
|
|
{
|
|
var result = _customizeCheckoutApplication.GetWorkshopEmployeesEligibleForCheckoutInDates(_workshopId, year, month);
|
|
if (result.IsSuccedded)
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
data = result.Data
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message
|
|
});
|
|
}
|
|
}
|
|
|
|
public IActionResult OnGetPrintOne(long checkoutId, int yearFa, int monthFa, int index)
|
|
{
|
|
List<long> id = [checkoutId];
|
|
var customizeCheckout= _customizeCheckoutApplication.PrintAll(_workshopId, id);
|
|
var result=customizeCheckout.FirstOrDefault();
|
|
return Partial("PrintOneCheckoutUnofficial", result);
|
|
}
|
|
|
|
public IActionResult OnPostDeleteOne(long checkoutId)
|
|
{
|
|
List<long> id = [checkoutId];
|
|
var result= _customizeCheckoutApplication.GroupRemove(_workshopId,id);
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message
|
|
});
|
|
}
|
|
|
|
public IActionResult OnPostDeleteAll(List<long> checkoutIds)
|
|
{
|
|
// var ids = ExtractNumbers(checkoutIds);
|
|
var result= _customizeCheckoutApplication.GroupRemove(_workshopId,checkoutIds);
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetExcelModal()
|
|
{
|
|
return Partial("ModalExcelSetting");
|
|
}
|
|
|
|
public IActionResult OnGetBankListAjax()
|
|
{
|
|
var resultData = _bankApplication.Search("");
|
|
return new JsonResult(new
|
|
{
|
|
success = true,
|
|
data = resultData,
|
|
});
|
|
}
|
|
}
|
|
|
|
public class GetCreateCustomizeCheckout
|
|
{
|
|
public List<string> Years { get; set; }
|
|
public List<string> Month { get; set; }
|
|
public string LastMonth { get; set; }
|
|
public string LastYear { get; set; }
|
|
} |