Merge branch 'Feature/salary-aid/client-api'
This commit is contained in:
@@ -8,7 +8,6 @@ public class CreateSalaryAidViewModel
|
||||
public long WorkshopId { get; set; }
|
||||
public string Amount { get; set; }
|
||||
public string SalaryDateTime { get; set; }
|
||||
public string CalculationDateTime { get; set; }
|
||||
public string NationalCode { get; set; }
|
||||
public int CalculationMonth { get; set; }
|
||||
public int CalculationYear { get; set; }
|
||||
|
||||
@@ -8,7 +8,7 @@ public class SalaryAidGroupedByDateViewModel
|
||||
public string YearFa { get; set; }
|
||||
public int Month { get; set; }
|
||||
public int Year { get; set; }
|
||||
public List<SalaryAidGroupedByDateViewModelItems> SalaryAidViewModels { get; set; }
|
||||
public List<SalaryAidGroupedByDateViewModelItems> Items { get; set; }
|
||||
public string TotalAmount { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ public class SalaryAidGroupedByEmployeeViewModel
|
||||
{
|
||||
public string EmployeeName { get; set; }
|
||||
public long EmployeeId { get; set; }
|
||||
public List<SalaryAidGroupedByEmployeeViewModelItems> SalaryAidViewModels { get; set; }
|
||||
public List<SalaryAidGroupedByEmployeeViewModelItems> Items { get; set; }
|
||||
public string TotalAmount { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.SalaryAid;
|
||||
public class SalaryAidSearchViewModel
|
||||
public class SalaryAidSearchViewModel:PaginationRequest
|
||||
{
|
||||
public string StartDate { get; set; }
|
||||
public string EndDate { get; set; }
|
||||
public long EmployeeId { get; set; }
|
||||
public long WorkshopId { get; set; }
|
||||
public int PageIndex { get; set; }
|
||||
public bool ShowAsGrouped { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using _0_Framework.Application;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.SalaryAid;
|
||||
|
||||
@@ -7,7 +8,7 @@ public class SalaryAidsGroupedViewModel
|
||||
{
|
||||
public List<SalaryAidGroupedByEmployeeViewModel> GroupedByEmployee { get; set; }
|
||||
public List<SalaryAidGroupedByDateViewModel> GroupedByDate { get; set; }
|
||||
public List<SalaryAidViewModel> SalaryAidListViewModels { get; set; }
|
||||
public PagedResult<SalaryAidViewModel> List { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ public class SalaryAidRepository : RepositoryBase<long, SalaryAid>, ISalaryAidRe
|
||||
{
|
||||
YearFa = x.Key.YearFa,
|
||||
MonthFa = x.Key.MonthFa,
|
||||
SalaryAidViewModels = x.Select(s => new SalaryAidGroupedByDateViewModelItems()
|
||||
Items = x.Select(s => new SalaryAidGroupedByDateViewModelItems()
|
||||
{
|
||||
Amount = s.Amount,
|
||||
EmployeeName = s.EmployeeFullName,
|
||||
@@ -175,7 +175,7 @@ public class SalaryAidRepository : RepositoryBase<long, SalaryAid>, ISalaryAidRe
|
||||
EmployeeId = x.Key,
|
||||
TotalAmount = x.Sum(s => s.Amount).ToMoney(),
|
||||
EmployeeName = employees.FirstOrDefault(e => e.id == x.Key).FullName,
|
||||
SalaryAidViewModels = x.Select(s => new SalaryAidGroupedByEmployeeViewModelItems()
|
||||
Items = x.Select(s => new SalaryAidGroupedByEmployeeViewModelItems()
|
||||
{
|
||||
Amount = s.Amount.ToMoney(),
|
||||
Id = s.id,
|
||||
@@ -197,22 +197,27 @@ public class SalaryAidRepository : RepositoryBase<long, SalaryAid>, ISalaryAidRe
|
||||
query = query.Where(x => x.SalaryAidDateTime >= startDate && x.SalaryAidDateTime <= endDate);
|
||||
}
|
||||
|
||||
result.SalaryAidListViewModels = query.OrderByDescending(x => x.SalaryAidDateTime).Skip(searchModel.PageIndex).Take(30).ToList().Select(
|
||||
x => new SalaryAidViewModel()
|
||||
{
|
||||
Amount = x.Amount.ToMoney(),
|
||||
CreationDate = x.CreationDate.ToFarsi(),
|
||||
Id = x.id,
|
||||
EmployeeId = x.EmployeeId,
|
||||
SalaryAidDateTimeFa = x.SalaryAidDateTime.ToFarsi(),
|
||||
SalaryAidDateTimeGe = x.SalaryAidDateTime,
|
||||
WorkshopId = x.WorkshopId,
|
||||
YearFa = x.SalaryAidDateTime.ToFarsi().Substring(0, 4),
|
||||
MonthFa = x.SalaryAidDateTime.ToFarsi().Substring(5, 2),
|
||||
PersonnelCode = personnelCodes.FirstOrDefault(p => p.EmployeeId == x.EmployeeId).PersonnelCode.ToString(),
|
||||
EmployeeFullName = employees.FirstOrDefault(e => e.id == x.EmployeeId).FullName,
|
||||
AmountDouble = x.Amount,
|
||||
}).ToList();
|
||||
result.List = new PagedResult<SalaryAidViewModel>()
|
||||
{
|
||||
TotalCount = query.Count(),
|
||||
List = query.OrderByDescending(x => x.SalaryAidDateTime).ApplyPagination(searchModel.PageIndex,searchModel.PageSize).ToList()
|
||||
.Select(x => new SalaryAidViewModel()
|
||||
{
|
||||
Amount = x.Amount.ToMoney(),
|
||||
CreationDate = x.CreationDate.ToFarsi(),
|
||||
Id = x.id,
|
||||
EmployeeId = x.EmployeeId,
|
||||
SalaryAidDateTimeFa = x.SalaryAidDateTime.ToFarsi(),
|
||||
SalaryAidDateTimeGe = x.SalaryAidDateTime,
|
||||
WorkshopId = x.WorkshopId,
|
||||
YearFa = x.SalaryAidDateTime.ToFarsi().Substring(0, 4),
|
||||
MonthFa = x.SalaryAidDateTime.ToFarsi().Substring(5, 2),
|
||||
PersonnelCode = personnelCodes.FirstOrDefault(p => p.EmployeeId == x.EmployeeId).PersonnelCode
|
||||
.ToString(),
|
||||
EmployeeFullName = employees.FirstOrDefault(e => e.id == x.EmployeeId).FullName,
|
||||
AmountDouble = x.Amount,
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
138
ServiceHost/Areas/Client/Controllers/SalaryAidController.cs
Normal file
138
ServiceHost/Areas/Client/Controllers/SalaryAidController.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using _0_Framework.Application;
|
||||
using CompanyManagement.Infrastructure.Excel.SalaryAid;
|
||||
using CompanyManagment.App.Contracts.SalaryAid;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Build.Evaluation;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Client.Controllers;
|
||||
|
||||
public class SalaryAidController:ClientBaseController
|
||||
{
|
||||
private readonly ISalaryAidApplication _salaryAidApplication;
|
||||
private readonly long _workshopId;
|
||||
private readonly SalaryAidImportExcel _salaryAidImportExcel;
|
||||
|
||||
public SalaryAidController(ISalaryAidApplication salaryAidApplication,IAuthHelper authHelper, SalaryAidImportExcel salaryAidImportExcel)
|
||||
{
|
||||
_salaryAidApplication = salaryAidApplication;
|
||||
_salaryAidImportExcel = salaryAidImportExcel;
|
||||
_workshopId = authHelper.GetWorkshopId();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult<SalaryAidsGroupedViewModel> GetList([FromQuery]SalaryAidSearchViewModel searchModel)
|
||||
{
|
||||
searchModel.WorkshopId = _workshopId;
|
||||
var result = _salaryAidApplication.GetSearchListAsGrouped(searchModel);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult<OperationResult> Create([FromBody]CreateSalaryAidRequest request)
|
||||
{
|
||||
var command = new CreateSalaryAidViewModel()
|
||||
{
|
||||
Amount = request.Amount.ToMoney(),
|
||||
CalculationMonth = request.CalculationMonth,
|
||||
CalculationYear = request.CalculationYear,
|
||||
EmployeeIds = request.EmployeeIds,
|
||||
WorkshopId = _workshopId,
|
||||
SalaryDateTime = request.SalaryDateTime,
|
||||
|
||||
};
|
||||
var result = _salaryAidApplication.Create(command);
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public ActionResult<OperationResult> Edit([FromBody]EditSalaryAidRequest request)
|
||||
{
|
||||
var command = new EditSalaryAidViewModel()
|
||||
{
|
||||
Id = request.Id,
|
||||
Amount = request.Amount.ToMoney(),
|
||||
CalculationMonth = request.CalculationMonth,
|
||||
CalculationYear = request.CalculationYear,
|
||||
SalaryDateTime = request.SalaryDateTime,
|
||||
WorkshopId = _workshopId,
|
||||
};
|
||||
var result = _salaryAidApplication.Edit(command);
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public ActionResult<EditSalaryAidRequest> EditDetails(long id)
|
||||
{
|
||||
var data = _salaryAidApplication.GetDetails(id);
|
||||
var res = new EditSalaryAidRequest()
|
||||
{
|
||||
Id = data.Id,
|
||||
Amount = data.Amount.MoneyToDouble(),
|
||||
CalculationMonth = data.CalculationMonth,
|
||||
CalculationYear = data.CalculationYear,
|
||||
SalaryDateTime = data.SalaryDateTime,
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpDelete("{id:long}")]
|
||||
public ActionResult<OperationResult> Delete(long id)
|
||||
{
|
||||
var result = _salaryAidApplication.Remove(id);
|
||||
return result;
|
||||
}
|
||||
[HttpPost("validate-excel")]
|
||||
public ActionResult<ExcelValidation<SalaryAidImportData>> ValidateExcel([FromForm]ValidateExcelRequest request)
|
||||
{
|
||||
var validation = _salaryAidImportExcel.ReadAndValidateExcel(request.Excel, _workshopId);
|
||||
|
||||
return validation;
|
||||
}
|
||||
[HttpPost("create-from-excel")]
|
||||
public async Task<ActionResult<OperationResult>> 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 class ValidateExcelRequest
|
||||
{
|
||||
public IFormFile Excel { get; set; }
|
||||
}
|
||||
|
||||
public class EditSalaryAidRequest
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public long EmployeeId { get; set; }
|
||||
public double Amount { get; set; }
|
||||
public string SalaryDateTime { get; set; }
|
||||
public int CalculationMonth { get; set; }
|
||||
public int CalculationYear { get; set; }
|
||||
}
|
||||
|
||||
public class CreateSalaryAidRequest
|
||||
{
|
||||
public List<long> EmployeeIds { get; set; }
|
||||
public double Amount { get; set; }
|
||||
public string SalaryDateTime { get; set; }
|
||||
public int CalculationMonth { get; set; }
|
||||
public int CalculationYear { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user