initial commit

This commit is contained in:
2026-07-21 14:14:44 +07:00
commit fa7dbb970d
1359 changed files with 104110 additions and 0 deletions
@@ -0,0 +1,60 @@
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class CreateSalesQuotationRequest
{
public DateTime? QuotationDate { get; set; }
public Data.Enums.SalesQuotationStatus QuotationStatus { get; set; }
public string? Description { get; set; }
public string? CustomerId { get; set; }
public string? TaxId { get; set; }
}
public class CreateSalesQuotationResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
}
public record CreateSalesQuotationCommand(CreateSalesQuotationRequest Data) : IRequest<CreateSalesQuotationResponse>;
public class CreateSalesQuotationHandler : IRequestHandler<CreateSalesQuotationCommand, CreateSalesQuotationResponse>
{
private readonly AppDbContext _context;
public CreateSalesQuotationHandler(AppDbContext context) => _context = context;
public async Task<CreateSalesQuotationResponse> Handle(CreateSalesQuotationCommand request, CancellationToken cancellationToken)
{
var entityName = nameof(Data.Entities.SalesQuotation);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"SQ/{{Year}}/{{Month}}/",
ct: cancellationToken
);
var entity = new Data.Entities.SalesQuotation
{
AutoNumber = autoNo,
QuotationDate = request.Data.QuotationDate,
QuotationStatus = request.Data.QuotationStatus,
Description = request.Data.Description,
CustomerId = request.Data.CustomerId,
TaxId = request.Data.TaxId,
BeforeTaxAmount = 0,
TaxAmount = 0,
AfterTaxAmount = 0
};
_context.SalesQuotation.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateSalesQuotationResponse
{
Id = entity.Id,
AutoNumber = entity.AutoNumber
};
}
}
@@ -0,0 +1,45 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Indotalent.Shared.Utils;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class CreateSalesQuotationItemRequest
{
public string? SalesQuotationId { get; set; }
public string? ProductId { get; set; }
public string? Summary { get; set; }
public decimal? UnitPrice { get; set; }
public double? Quantity { get; set; }
}
public record CreateSalesQuotationItemCommand(CreateSalesQuotationItemRequest Data) : IRequest<bool>;
public class CreateSalesQuotationItemHandler : IRequestHandler<CreateSalesQuotationItemCommand, bool>
{
private readonly AppDbContext _context;
public CreateSalesQuotationItemHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(CreateSalesQuotationItemCommand request, CancellationToken cancellationToken)
{
var entity = new Data.Entities.SalesQuotationItem
{
SalesQuotationId = request.Data.SalesQuotationId,
ProductId = request.Data.ProductId,
Summary = request.Data.Summary,
UnitPrice = request.Data.UnitPrice ?? 0,
Quantity = request.Data.Quantity ?? 0,
Total = (request.Data.UnitPrice ?? 0) * (decimal)(request.Data.Quantity ?? 0)
};
_context.SalesQuotationItem.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
if (!string.IsNullOrEmpty(request.Data.SalesQuotationId))
{
SalesQuotationHelper.Recalculate(_context, request.Data.SalesQuotationId);
}
return true;
}
}
@@ -0,0 +1,12 @@
using FluentValidation;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class CreateSalesQuotationValidator : AbstractValidator<CreateSalesQuotationRequest>
{
public CreateSalesQuotationValidator()
{
RuleFor(x => x.QuotationDate).NotEmpty().WithMessage("Date is required");
RuleFor(x => x.CustomerId).NotEmpty().WithMessage("Customer is required");
}
}
@@ -0,0 +1,25 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public record DeleteSalesQuotationByIdCommand(string Id) : IRequest<bool>;
public class DeleteSalesQuotationByIdHandler : IRequestHandler<DeleteSalesQuotationByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteSalesQuotationByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteSalesQuotationByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.SalesQuotation
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
if (entity == null) return false;
_context.SalesQuotation.Remove(entity);
await _context.SaveChangesAsync(cancellationToken);
return true;
}
}
@@ -0,0 +1,34 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Shared.Utils;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public record DeleteSalesQuotationItemCommand(string Id) : IRequest<bool>;
public class DeleteSalesQuotationItemHandler : IRequestHandler<DeleteSalesQuotationItemCommand, bool>
{
private readonly AppDbContext _context;
public DeleteSalesQuotationItemHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteSalesQuotationItemCommand request, CancellationToken cancellationToken)
{
var entity = await _context.SalesQuotationItem
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
if (entity == null) return false;
var quotationId = entity.SalesQuotationId;
_context.SalesQuotationItem.Remove(entity);
await _context.SaveChangesAsync(cancellationToken);
if (!string.IsNullOrEmpty(quotationId))
{
SalesQuotationHelper.Recalculate(_context, quotationId);
}
return true;
}
}
@@ -0,0 +1,116 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class SalesQuotationItemResponse
{
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 GetSalesQuotationByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public DateTime? QuotationDate { get; set; }
public Data.Enums.SalesQuotationStatus QuotationStatus { get; set; }
public string? Description { get; set; }
public string? CustomerId { get; set; }
public string? CustomerName { get; set; }
public string? CustomerStreet { get; set; }
public string? CustomerCity { get; set; }
public string? CustomerState { get; set; }
public string? CustomerZipCode { get; set; }
public string? CustomerPhone { get; set; }
public string? CustomerEmail { get; set; }
public string? CompanyName { get; set; }
public string? CompanyStreet { get; set; }
public string? CompanyCity { get; set; }
public string? CompanyState { get; set; }
public string? CompanyZipCode { get; set; }
public string? CompanyPhone { get; set; }
public string? CompanyEmail { get; set; }
public string? CurrencySymbol { get; set; }
public string? TaxId { get; set; }
public decimal? BeforeTaxAmount { get; set; }
public decimal? TaxAmount { get; set; }
public decimal? AfterTaxAmount { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
public List<SalesQuotationItemResponse> Items { get; set; } = new();
}
public record GetSalesQuotationByIdQuery(string Id) : IRequest<GetSalesQuotationByIdResponse?>;
public class GetSalesQuotationByIdHandler : IRequestHandler<GetSalesQuotationByIdQuery, GetSalesQuotationByIdResponse?>
{
private readonly AppDbContext _context;
public GetSalesQuotationByIdHandler(AppDbContext context) => _context = context;
public async Task<GetSalesQuotationByIdResponse?> Handle(GetSalesQuotationByIdQuery request, CancellationToken cancellationToken)
{
var company = await _context.Company
.AsNoTracking()
.Include(x => x.Currency)
.OrderByDescending(x => x.IsDefault)
.FirstOrDefaultAsync(cancellationToken);
return await _context.SalesQuotation
.AsNoTracking()
.Include(x => x.Customer)
.Include(x => x.SalesQuotationItemList)
.ThenInclude(x => x.Product)
.Where(x => x.Id == request.Id)
.Select(x => new GetSalesQuotationByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
QuotationDate = x.QuotationDate,
QuotationStatus = x.QuotationStatus,
Description = x.Description,
CustomerId = x.CustomerId,
CustomerName = x.Customer!.Name,
CustomerStreet = x.Customer!.Street,
CustomerCity = x.Customer!.City,
CustomerState = x.Customer!.State,
CustomerZipCode = x.Customer!.ZipCode,
CustomerPhone = x.Customer!.PhoneNumber,
CustomerEmail = x.Customer!.EmailAddress,
CompanyName = company != null ? company.Name : string.Empty,
CompanyStreet = company != null ? company.StreetAddress : string.Empty,
CompanyCity = company != null ? company.City : string.Empty,
CompanyState = company != null ? company.StateProvince : string.Empty,
CompanyZipCode = company != null ? company.ZipCode : string.Empty,
CompanyPhone = company != null ? company.Phone : string.Empty,
CompanyEmail = company != null ? company.Email : string.Empty,
CurrencySymbol = company != null && company.Currency != null ? company.Currency.Symbol : "IDR",
TaxId = x.TaxId,
BeforeTaxAmount = x.BeforeTaxAmount,
TaxAmount = x.TaxAmount,
AfterTaxAmount = x.AfterTaxAmount,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy,
Items = x.SalesQuotationItemList.Select(i => new SalesQuotationItemResponse
{
Id = i.Id,
ProductId = i.ProductId,
ProductName = i.Product!.Name,
Summary = i.Summary,
UnitPrice = i.UnitPrice,
Quantity = i.Quantity,
Total = i.Total
}).ToList()
}).FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,40 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class GetSalesQuotationListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public DateTime? QuotationDate { get; set; }
public string? CustomerName { get; set; }
public decimal? AfterTaxAmount { get; set; }
public Data.Enums.SalesQuotationStatus QuotationStatus { get; set; }
}
public record GetSalesQuotationListQuery() : IRequest<List<GetSalesQuotationListResponse>>;
public class GetSalesQuotationListHandler : IRequestHandler<GetSalesQuotationListQuery, List<GetSalesQuotationListResponse>>
{
private readonly AppDbContext _context;
public GetSalesQuotationListHandler(AppDbContext context) => _context = context;
public async Task<List<GetSalesQuotationListResponse>> Handle(GetSalesQuotationListQuery request, CancellationToken cancellationToken)
{
return await _context.SalesQuotation
.AsNoTracking()
.Include(x => x.Customer)
.OrderByDescending(x => x.CreatedAt)
.Select(x => new GetSalesQuotationListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
QuotationDate = x.QuotationDate,
CustomerName = x.Customer!.Name,
AfterTaxAmount = x.AfterTaxAmount,
QuotationStatus = x.QuotationStatus
}).ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,77 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Data.Enums;
using Indotalent.ConfigBackEnd.Extensions;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class SalesQuotationLookupResponse
{
public List<LookupItem> Customers { get; set; } = new();
public List<LookupItem> Taxes { get; set; } = new();
public List<LookupItem> Products { 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 GetSalesQuotationLookupQuery() : IRequest<SalesQuotationLookupResponse>;
public class GetSalesQuotationLookupHandler : IRequestHandler<GetSalesQuotationLookupQuery, SalesQuotationLookupResponse>
{
private readonly AppDbContext _context;
public GetSalesQuotationLookupHandler(AppDbContext context) => _context = context;
public async Task<SalesQuotationLookupResponse> Handle(GetSalesQuotationLookupQuery request, CancellationToken cancellationToken)
{
var response = new SalesQuotationLookupResponse();
response.Customers = await _context.Customer.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem
{
Id = x.Id,
Name = x.Name
})
.ToListAsync(cancellationToken);
response.Taxes = await _context.Tax.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem
{
Id = x.Id,
Name = x.Name
})
.ToListAsync(cancellationToken);
response.Products = await _context.Product.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new LookupItem
{
Id = x.Id,
Name = x.Name
})
.ToListAsync(cancellationToken);
response.Statuses = Enum.GetValues(typeof(SalesQuotationStatus))
.Cast<SalesQuotationStatus>()
.Select(x => new LookupStatusItem
{
Value = (int)x,
Name = x.GetDescription()
}).ToList();
return response;
}
}
@@ -0,0 +1,55 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Shared.Utils;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class UpdateSalesQuotationRequest
{
public string? Id { get; set; }
public DateTime? QuotationDate { get; set; }
public Data.Enums.SalesQuotationStatus QuotationStatus { get; set; }
public string? AutoNumber { get; set; }
public string? Description { get; set; }
public string? CustomerId { get; set; }
public string? TaxId { get; set; }
public decimal? BeforeTaxAmount { get; set; }
public decimal? TaxAmount { get; set; }
public decimal? AfterTaxAmount { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record UpdateSalesQuotationCommand(UpdateSalesQuotationRequest Data) : IRequest<bool>;
public class UpdateSalesQuotationHandler : IRequestHandler<UpdateSalesQuotationCommand, bool>
{
private readonly AppDbContext _context;
public UpdateSalesQuotationHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(UpdateSalesQuotationCommand request, CancellationToken cancellationToken)
{
var entity = await _context.SalesQuotation
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
entity.QuotationDate = request.Data.QuotationDate;
entity.QuotationStatus = request.Data.QuotationStatus;
entity.Description = request.Data.Description;
entity.CustomerId = request.Data.CustomerId;
entity.TaxId = request.Data.TaxId;
await _context.SaveChangesAsync(cancellationToken);
if (!string.IsNullOrEmpty(entity.Id))
{
SalesQuotationHelper.Recalculate(_context, entity.Id);
}
return true;
}
}
@@ -0,0 +1,46 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Indotalent.Shared.Utils;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class UpdateSalesQuotationItemRequest
{
public string? Id { get; set; }
public string? ProductId { get; set; }
public string? Summary { get; set; }
public decimal? UnitPrice { get; set; }
public double? Quantity { get; set; }
}
public record UpdateSalesQuotationItemCommand(UpdateSalesQuotationItemRequest Data) : IRequest<bool>;
public class UpdateSalesQuotationItemHandler : IRequestHandler<UpdateSalesQuotationItemCommand, bool>
{
private readonly AppDbContext _context;
public UpdateSalesQuotationItemHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(UpdateSalesQuotationItemCommand request, CancellationToken cancellationToken)
{
var entity = await _context.SalesQuotationItem
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
entity.ProductId = request.Data.ProductId;
entity.Summary = request.Data.Summary;
entity.UnitPrice = request.Data.UnitPrice ?? 0;
entity.Quantity = request.Data.Quantity ?? 0;
entity.Total = (request.Data.UnitPrice ?? 0) * (decimal)(request.Data.Quantity ?? 0);
await _context.SaveChangesAsync(cancellationToken);
if (!string.IsNullOrEmpty(entity.SalesQuotationId))
{
SalesQuotationHelper.Recalculate(_context, entity.SalesQuotationId);
}
return true;
}
}
@@ -0,0 +1,12 @@
using FluentValidation;
namespace Indotalent.Features.Sales.SalesQuotation.Cqrs;
public class UpdateSalesQuotationValidator : AbstractValidator<UpdateSalesQuotationRequest>
{
public UpdateSalesQuotationValidator()
{
RuleFor(x => x.Id).NotEmpty();
RuleFor(x => x.CustomerId).NotEmpty().WithMessage("Customer is required");
}
}