Merge branch 'Feature/loan/client-api'

This commit is contained in:
2026-02-06 18:29:45 +03:30
4 changed files with 83 additions and 16 deletions

View File

@@ -21,6 +21,6 @@ public class LoanGroupedViewModel
{
public List<LoanGroupedByDateViewModel> GroupedByDate { get; set; }
public List<LoanGroupedByEmployeeViewModel>GroupedByEmployee { get; set; }
public List<LoanViewModel> LoanListViewModel { get; set; }
public PagedResult<LoanViewModel> LoanListViewModel { get; set; }
}

View File

@@ -16,5 +16,6 @@ public class LoanSearchViewModel
public string EndDate { get; set; }
public int PageIndex { get; set; }
public int PageSize { get; set; } = 30;
public bool ShowAsGrouped { get; set; }
}

View File

@@ -171,12 +171,17 @@ public class LoanRepository : RepositoryBase<long, Loan>, ILoanRepository
query = query.Where(x => x.StartInstallmentPayment >= startDate && x.StartInstallmentPayment <= endDate);
}
result.LoanListViewModel = query.OrderByDescending(x => x.StartInstallmentPayment).Skip(searchModel.PageIndex)
result.LoanListViewModel = new PagedResult<LoanViewModel>()
{
TotalCount = query.Count(),
List = query.OrderByDescending(x => x.StartInstallmentPayment)
.ApplyPagination(searchModel.PageIndex, searchModel.PageSize)
.Take(30).ToList()
.Select(x => new LoanViewModel()
{
EmployeeFullName = employees.FirstOrDefault(e => e.id == x.EmployeeId).FullName,
PersonnelCode = personnelCodes.FirstOrDefault(p => p.EmployeeId == x.EmployeeId).PersonnelCode.ToString(),
PersonnelCode = personnelCodes.FirstOrDefault(p => p.EmployeeId == x.EmployeeId).PersonnelCode
.ToString(),
Amount = x.Amount.ToMoney(),
AmountPerMonth = x.AmountPerMonth.ToMoney(),
StartDateTime = x.StartInstallmentPayment.ToFarsi(),
@@ -186,7 +191,9 @@ public class LoanRepository : RepositoryBase<long, Loan>, ILoanRepository
EmployeeId = x.EmployeeId,
YearFa = pc.GetYear(x.StartInstallmentPayment).ToString(),
}).ToList();
}).ToList()
};
return result;
}

View File

@@ -0,0 +1,59 @@
using _0_Framework.Application;
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
using CompanyManagment.App.Contracts.Loan;
using Microsoft.AspNetCore.Mvc;
using ServiceHost.BaseControllers;
namespace ServiceHost.Areas.Client.Controllers;
public class LoanController: ClientBaseController
{
private readonly ILoanApplication _loanApplication;
private readonly long _workshopId;
public LoanController(ILoanApplication loanApplication, IAuthHelper authHelper)
{
_loanApplication = loanApplication;
_workshopId= authHelper.GetWorkshopId();
}
[HttpGet]
public ActionResult<LoanGroupedViewModel> GetList(LoanSearchViewModel searchModel)
{
searchModel.WorkshopId = _workshopId;
var loans = _loanApplication.GetSearchListAsGrouped(searchModel);
return loans;
}
[HttpGet("{id}")]
public async Task<ActionResult<LoanDetailsViewModel>> GetDetails(long id)
{
var loan = await _loanApplication.GetDetails(id);
return loan;
}
[HttpPost]
public ActionResult<OperationResult> Create([FromBody] CreateLoanViewModel command)
{
var result = _loanApplication.Create(command);
return result;
}
[HttpGet("create/installments")]
public ActionResult<List<LoanInstallmentViewModel>> CalculateLoanInstallment(string amount,
int installmentCount, string loanStartDate, bool getRounded)
{
var installments =
_loanApplication.CalculateLoanInstallment(amount, installmentCount, loanStartDate, getRounded);
return installments;
}
[HttpDelete("{id}")]
public ActionResult<OperationResult> Remove(long id)
{
var result = _loanApplication.Remove(id);
return result;
}
}