initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public class CreatePaymentDisburseRequest
|
||||
{
|
||||
public string? BillId { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
public string? PaymentMethodId { get; set; }
|
||||
public decimal? PaymentAmount { get; set; }
|
||||
public Data.Enums.PaymentDisburseStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class CreatePaymentDisburseResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
}
|
||||
|
||||
public record CreatePaymentDisburseCommand(CreatePaymentDisburseRequest Data) : IRequest<CreatePaymentDisburseResponse>;
|
||||
|
||||
public class CreatePaymentDisburseHandler : IRequestHandler<CreatePaymentDisburseCommand, CreatePaymentDisburseResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public CreatePaymentDisburseHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreatePaymentDisburseResponse> Handle(CreatePaymentDisburseCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.PaymentDisburse);
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"DISB/{{Year}}/{{Month}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.PaymentDisburse
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
BillId = request.Data.BillId,
|
||||
Description = request.Data.Description,
|
||||
PaymentDate = request.Data.PaymentDate,
|
||||
PaymentMethodId = request.Data.PaymentMethodId,
|
||||
PaymentAmount = request.Data.PaymentAmount ?? 0,
|
||||
Status = request.Data.Status
|
||||
};
|
||||
|
||||
_context.PaymentDisburse.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreatePaymentDisburseResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
AutoNumber = entity.AutoNumber
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public class CreatePaymentDisburseValidator : AbstractValidator<CreatePaymentDisburseRequest>
|
||||
{
|
||||
public CreatePaymentDisburseValidator()
|
||||
{
|
||||
RuleFor(x => x.BillId).NotEmpty().WithMessage("Bill reference is required");
|
||||
RuleFor(x => x.PaymentDate).NotEmpty().WithMessage("Payment date is required");
|
||||
RuleFor(x => x.PaymentMethodId).NotEmpty().WithMessage("Payment method is required");
|
||||
RuleFor(x => x.PaymentAmount).GreaterThan(0).WithMessage("Amount must be greater than 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public record DeletePaymentDisburseByIdCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeletePaymentDisburseByIdHandler : IRequestHandler<DeletePaymentDisburseByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public DeletePaymentDisburseByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeletePaymentDisburseByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.PaymentDisburse
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.PaymentDisburse.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public record GetBillDetailForPaymentQuery(string BillId) : IRequest<GetPaymentDisburseByIdResponse?>;
|
||||
|
||||
public class GetBillDetailForPaymentHandler : IRequestHandler<GetBillDetailForPaymentQuery, GetPaymentDisburseByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetBillDetailForPaymentHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetPaymentDisburseByIdResponse?> Handle(GetBillDetailForPaymentQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var bill = await _context.Bill
|
||||
.AsNoTracking()
|
||||
.Include(x => x.PurchaseOrder)
|
||||
.ThenInclude(po => po!.Vendor)
|
||||
.Include(x => x.PurchaseOrder)
|
||||
.ThenInclude(po => po!.PurchaseOrderItemList)
|
||||
.ThenInclude(pi => pi.Product)
|
||||
.FirstOrDefaultAsync(x => x.Id == request.BillId, cancellationToken);
|
||||
|
||||
if (bill == null) return null;
|
||||
|
||||
var purchaseOrder = bill.PurchaseOrder;
|
||||
|
||||
return new GetPaymentDisburseByIdResponse
|
||||
{
|
||||
BillId = bill.Id,
|
||||
BillNumber = bill.AutoNumber,
|
||||
VendorName = purchaseOrder?.Vendor?.Name,
|
||||
VendorStreet = purchaseOrder?.Vendor?.Street,
|
||||
VendorCity = purchaseOrder?.Vendor?.City,
|
||||
PurchaseOrderBeforeTaxAmount = purchaseOrder?.BeforeTaxAmount ?? 0,
|
||||
PurchaseOrderTaxAmount = purchaseOrder?.TaxAmount ?? 0,
|
||||
PurchaseOrderAfterTaxAmount = purchaseOrder?.AfterTaxAmount ?? 0,
|
||||
PaymentAmount = purchaseOrder?.AfterTaxAmount ?? 0,
|
||||
Items = purchaseOrder?.PurchaseOrderItemList.Select(x => new PaymentDisburseItemResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
ProductId = x.ProductId,
|
||||
ProductName = x.Product?.Name,
|
||||
Summary = x.Summary,
|
||||
UnitPrice = x.UnitPrice ?? 0,
|
||||
Quantity = x.Quantity ?? 0,
|
||||
Total = x.Total ?? 0
|
||||
}).ToList() ?? new()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public class PaymentDisburseItemResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
public double Quantity { get; set; }
|
||||
public decimal Total { get; set; }
|
||||
}
|
||||
|
||||
public class GetPaymentDisburseByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? BillId { get; set; }
|
||||
public string? BillNumber { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
public string? PaymentMethodId { get; set; }
|
||||
public string? PaymentMethodName { get; set; }
|
||||
public decimal PaymentAmount { get; set; }
|
||||
public Data.Enums.PaymentDisburseStatus Status { get; set; }
|
||||
public string? VendorName { get; set; }
|
||||
public string? VendorStreet { get; set; }
|
||||
public string? VendorCity { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CompanyStreet { get; set; }
|
||||
public string? CompanyCity { get; set; }
|
||||
public string? CurrencySymbol { get; set; }
|
||||
public decimal PurchaseOrderBeforeTaxAmount { get; set; }
|
||||
public decimal PurchaseOrderTaxAmount { get; set; }
|
||||
public decimal PurchaseOrderAfterTaxAmount { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
public List<PaymentDisburseItemResponse> Items { get; set; } = new();
|
||||
}
|
||||
|
||||
public record GetPaymentDisburseByIdQuery(string Id) : IRequest<GetPaymentDisburseByIdResponse?>;
|
||||
|
||||
public class GetPaymentDisburseByIdHandler : IRequestHandler<GetPaymentDisburseByIdQuery, GetPaymentDisburseByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetPaymentDisburseByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetPaymentDisburseByIdResponse?> Handle(GetPaymentDisburseByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var company = await _context.Company
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Currency)
|
||||
.OrderByDescending(x => x.IsDefault)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
var payment = await _context.PaymentDisburse
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Bill)
|
||||
.ThenInclude(b => b!.PurchaseOrder)
|
||||
.ThenInclude(po => po!.Vendor)
|
||||
.Include(x => x.Bill)
|
||||
.ThenInclude(b => b!.PurchaseOrder)
|
||||
.ThenInclude(po => po!.PurchaseOrderItemList)
|
||||
.ThenInclude(pi => pi.Product)
|
||||
.Include(x => x.PaymentMethod)
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (payment == null) return null;
|
||||
|
||||
var purchaseOrder = payment.Bill?.PurchaseOrder;
|
||||
|
||||
return new GetPaymentDisburseByIdResponse
|
||||
{
|
||||
Id = payment.Id,
|
||||
AutoNumber = payment.AutoNumber,
|
||||
BillId = payment.BillId,
|
||||
BillNumber = payment.Bill?.AutoNumber,
|
||||
Description = payment.Description,
|
||||
PaymentDate = payment.PaymentDate,
|
||||
PaymentMethodId = payment.PaymentMethodId,
|
||||
PaymentMethodName = payment.PaymentMethod?.Name,
|
||||
PaymentAmount = payment.PaymentAmount ?? 0,
|
||||
Status = payment.Status,
|
||||
VendorName = purchaseOrder?.Vendor?.Name,
|
||||
VendorStreet = purchaseOrder?.Vendor?.Street,
|
||||
VendorCity = purchaseOrder?.Vendor?.City,
|
||||
CompanyName = company?.Name,
|
||||
CompanyStreet = company?.StreetAddress,
|
||||
CompanyCity = company?.City,
|
||||
CurrencySymbol = company?.Currency?.Symbol ?? "IDR",
|
||||
PurchaseOrderBeforeTaxAmount = purchaseOrder?.BeforeTaxAmount ?? 0,
|
||||
PurchaseOrderTaxAmount = purchaseOrder?.TaxAmount ?? 0,
|
||||
PurchaseOrderAfterTaxAmount = purchaseOrder?.AfterTaxAmount ?? 0,
|
||||
CreatedAt = payment.CreatedAt,
|
||||
CreatedBy = payment.CreatedBy,
|
||||
UpdatedAt = payment.UpdatedAt,
|
||||
UpdatedBy = payment.UpdatedBy,
|
||||
Items = purchaseOrder?.PurchaseOrderItemList.Select(x => new PaymentDisburseItemResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
ProductId = x.ProductId,
|
||||
ProductName = x.Product?.Name,
|
||||
Summary = x.Summary,
|
||||
UnitPrice = x.UnitPrice ?? 0,
|
||||
Quantity = x.Quantity ?? 0,
|
||||
Total = x.Total ?? 0
|
||||
}).ToList() ?? new()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public class GetPaymentDisburseListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
public string? BillNumber { get; set; }
|
||||
public string? VendorName { get; set; }
|
||||
public decimal PaymentAmount { get; set; }
|
||||
public Data.Enums.PaymentDisburseStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public record GetPaymentDisburseListQuery() : IRequest<List<GetPaymentDisburseListResponse>>;
|
||||
|
||||
public class GetPaymentDisburseListHandler : IRequestHandler<GetPaymentDisburseListQuery, List<GetPaymentDisburseListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetPaymentDisburseListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetPaymentDisburseListResponse>> Handle(GetPaymentDisburseListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.PaymentDisburse
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Bill)
|
||||
.ThenInclude(b => b!.PurchaseOrder)
|
||||
.ThenInclude(po => po!.Vendor)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetPaymentDisburseListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
PaymentDate = x.PaymentDate,
|
||||
BillNumber = x.Bill!.AutoNumber,
|
||||
VendorName = x.Bill!.PurchaseOrder!.Vendor!.Name,
|
||||
PaymentAmount = x.PaymentAmount ?? 0,
|
||||
Status = x.Status
|
||||
}).ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public class PaymentDisburseLookupResponse
|
||||
{
|
||||
public List<LookupItem> Bills { get; set; } = new();
|
||||
public List<LookupItem> PaymentMethods { get; set; } = new();
|
||||
public List<LookupStatusItem> Statuses { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public class LookupStatusItem
|
||||
{
|
||||
public int Value { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record GetPaymentDisburseLookupQuery() : IRequest<PaymentDisburseLookupResponse>;
|
||||
|
||||
public class GetPaymentDisburseLookupHandler : IRequestHandler<GetPaymentDisburseLookupQuery, PaymentDisburseLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetPaymentDisburseLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<PaymentDisburseLookupResponse> Handle(GetPaymentDisburseLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new PaymentDisburseLookupResponse();
|
||||
|
||||
response.Bills = await _context.Bill.AsNoTracking()
|
||||
.Where(x => x.BillStatus == BillStatus.Confirmed)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.AutoNumber })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.PaymentMethods = await _context.PaymentMethod.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Statuses = Enum.GetValues(typeof(PaymentDisburseStatus))
|
||||
.Cast<PaymentDisburseStatus>()
|
||||
.Select(x => new LookupStatusItem
|
||||
{
|
||||
Value = (int)x,
|
||||
Name = x.GetDescription()
|
||||
}).ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public class UpdatePaymentDisburseRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? BillId { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
public string? PaymentMethodId { get; set; }
|
||||
public decimal? PaymentAmount { get; set; }
|
||||
public Data.Enums.PaymentDisburseStatus Status { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record UpdatePaymentDisburseCommand(UpdatePaymentDisburseRequest Data) : IRequest<bool>;
|
||||
|
||||
public class UpdatePaymentDisburseHandler : IRequestHandler<UpdatePaymentDisburseCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public UpdatePaymentDisburseHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(UpdatePaymentDisburseCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.PaymentDisburse
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
entity.BillId = request.Data.BillId;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.PaymentDate = request.Data.PaymentDate;
|
||||
entity.PaymentMethodId = request.Data.PaymentMethodId;
|
||||
entity.PaymentAmount = request.Data.PaymentAmount ?? 0;
|
||||
entity.Status = request.Data.Status;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Indotalent.Features.Purchase.PaymentDisburse.Cqrs;
|
||||
|
||||
public class UpdatePaymentDisburseValidator : AbstractValidator<UpdatePaymentDisburseRequest>
|
||||
{
|
||||
public UpdatePaymentDisburseValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.BillId).NotEmpty().WithMessage("Bill reference is required");
|
||||
RuleFor(x => x.PaymentDate).NotEmpty().WithMessage("Payment date is required");
|
||||
RuleFor(x => x.PaymentAmount).GreaterThan(0).WithMessage("Amount must be greater than 0");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user