Files
ERP_Distribution/Distribution/Features/SupplierPayment/SupplierPaymentRepository.cs
T
Kalana B. Thilakarathna b992d07689 feat: add supplier payment and allocation models, API, and frontend components
- 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.
2026-10-19 21:36:01 +05:30

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);
}