b992d07689
- Created `SupplierPayment` and `SupplierPaymentGRN` models for managing supplier payments and their allocations. - Implemented API endpoints for listing and creating supplier payments. - Developed frontend components for displaying and recording supplier payments, including a dialog for payment creation. - Integrated GRN allocations into the payment creation process, ensuring total allocations match the payment amount. - Added pagination and loading states for the payments list.
44 lines
1.8 KiB
C#
44 lines
1.8 KiB
C#
using Distribution.Data;
|
|
using Distribution.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Features.SupplierPayment;
|
|
|
|
public class SupplierPaymentRepository(AppDBContext context) : ISupplierPaymentRepository
|
|
{
|
|
public async Task<Models.SupplierPayment?> GetByIdAsync(Guid id) =>
|
|
await context.SupplierPayments
|
|
.Include(p => p.ChequePage)
|
|
.Include(p => p.Allocations)
|
|
.FirstOrDefaultAsync(p => p.Id == id);
|
|
|
|
public async Task<List<Models.SupplierPayment>> ListBySupplierAsync(Guid supplierId, int page, int pageSize) =>
|
|
await context.SupplierPayments
|
|
.Include(p => p.ChequePage)
|
|
.Include(p => p.Allocations)
|
|
.Where(p => p.FK_SupplierId == supplierId && p.IsActive)
|
|
.OrderByDescending(p => p.PaidAt)
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToListAsync();
|
|
|
|
public async Task<int> CountBySupplierAsync(Guid supplierId) =>
|
|
await context.SupplierPayments
|
|
.CountAsync(p => p.FK_SupplierId == supplierId && p.IsActive);
|
|
|
|
public async Task AddAsync(Models.SupplierPayment payment) =>
|
|
await context.SupplierPayments.AddAsync(payment);
|
|
|
|
public async Task<decimal> GetAllocatedTotalForGrnAsync(Guid goodsReceiptId) =>
|
|
await context.SupplierPaymentGRNs
|
|
.Where(a => a.FK_GoodsReceiptId == goodsReceiptId
|
|
&& a.IsActive
|
|
&& a.SupplierPayment!.IsActive)
|
|
.SumAsync(a => (decimal?)a.AllocatedAmount) ?? 0m;
|
|
|
|
public async Task<Models.GoodsReceipt?> GetGrnWithItemsAsync(Guid goodsReceiptId) =>
|
|
await context.GoodsReceipts
|
|
.Include(g => g.Items)
|
|
.FirstOrDefaultAsync(g => g.Id == goodsReceiptId && g.IsActive);
|
|
}
|