Add cheque and entry mode details to payments
This commit is contained in:
@@ -5,6 +5,9 @@ namespace Distribution.Features.Payment;
|
|||||||
public record CreatePaymentRequest(
|
public record CreatePaymentRequest(
|
||||||
decimal Amount,
|
decimal Amount,
|
||||||
PaymentMethod Method,
|
PaymentMethod Method,
|
||||||
|
EntryMode EntryMode = EntryMode.RealTime,
|
||||||
|
string? ChequeNumber = null,
|
||||||
|
DateTime? ChequeDate = null,
|
||||||
Guid? CollectedByUserId = null);
|
Guid? CollectedByUserId = null);
|
||||||
|
|
||||||
public record PaymentResponse(
|
public record PaymentResponse(
|
||||||
@@ -12,6 +15,10 @@ public record PaymentResponse(
|
|||||||
Guid InvoiceId,
|
Guid InvoiceId,
|
||||||
decimal Amount,
|
decimal Amount,
|
||||||
PaymentMethod Method,
|
PaymentMethod Method,
|
||||||
|
EntryMode EntryMode,
|
||||||
|
string? ChequeNumber,
|
||||||
|
DateTime? ChequeDate,
|
||||||
DateTime CollectedAt,
|
DateTime CollectedAt,
|
||||||
Guid CollectedBy,
|
Guid CollectedBy,
|
||||||
|
Guid? RecordedBy,
|
||||||
DateTime CreatedAt);
|
DateTime CreatedAt);
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ public class PaymentService(
|
|||||||
ICurrentUserService currentUser)
|
ICurrentUserService currentUser)
|
||||||
{
|
{
|
||||||
private static PaymentResponse ToResponse(Models.Payment p) =>
|
private static PaymentResponse ToResponse(Models.Payment p) =>
|
||||||
new(p.Id, p.FK_InvoiceId, p.Amount, p.Method, p.CollectedAt, p.CollectedBy, p.CreatedAt);
|
new(p.Id, p.FK_InvoiceId, p.Amount, p.Method, p.EntryMode, p.ChequeNumber, p.ChequeDate,
|
||||||
|
p.CollectedAt, p.CollectedBy, p.RecordedBy, p.CreatedAt);
|
||||||
|
|
||||||
public async Task<List<PaymentResponse>?> GetByInvoiceIdAsync(Guid invoiceId)
|
public async Task<List<PaymentResponse>?> GetByInvoiceIdAsync(Guid invoiceId)
|
||||||
{
|
{
|
||||||
@@ -30,16 +31,28 @@ public class PaymentService(
|
|||||||
if (invoice.Status == InvoiceStatus.Finalized)
|
if (invoice.Status == InvoiceStatus.Finalized)
|
||||||
throw new InvalidOperationException("Cannot record a payment against a finalized invoice");
|
throw new InvalidOperationException("Cannot record a payment against a finalized invoice");
|
||||||
|
|
||||||
var userId = currentUser.UserId ?? request.CollectedByUserId
|
if (request.Method == PaymentMethod.Cheque &&
|
||||||
|
(string.IsNullOrWhiteSpace(request.ChequeNumber) || request.ChequeDate is null))
|
||||||
|
throw new InvalidOperationException("ChequeNumber and ChequeDate are required when Method is Cheque");
|
||||||
|
|
||||||
|
var recorderId = currentUser.UserId ?? request.CollectedByUserId
|
||||||
?? throw new InvalidOperationException("CollectedByUserId is required while auth is unavailable");
|
?? throw new InvalidOperationException("CollectedByUserId is required while auth is unavailable");
|
||||||
|
var collectedBy = request.CollectedByUserId ?? recorderId;
|
||||||
|
var recordedBy = request.EntryMode == EntryMode.DayEndManual && collectedBy != recorderId
|
||||||
|
? recorderId
|
||||||
|
: (Guid?)null;
|
||||||
|
|
||||||
var payment = new Models.Payment
|
var payment = new Models.Payment
|
||||||
{
|
{
|
||||||
FK_InvoiceId = invoiceId,
|
FK_InvoiceId = invoiceId,
|
||||||
Amount = request.Amount,
|
Amount = request.Amount,
|
||||||
Method = request.Method,
|
Method = request.Method,
|
||||||
|
EntryMode = request.EntryMode,
|
||||||
|
ChequeNumber = request.Method == PaymentMethod.Cheque ? request.ChequeNumber : null,
|
||||||
|
ChequeDate = request.Method == PaymentMethod.Cheque ? request.ChequeDate : null,
|
||||||
CollectedAt = DateTime.Now,
|
CollectedAt = DateTime.Now,
|
||||||
CollectedBy = userId
|
CollectedBy = collectedBy,
|
||||||
|
RecordedBy = recordedBy
|
||||||
};
|
};
|
||||||
|
|
||||||
await uow.BeginAsync(ct);
|
await uow.BeginAsync(ct);
|
||||||
|
|||||||
Reference in New Issue
Block a user