initial commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class CreateTransferInRequest
|
||||
{
|
||||
public DateTime? TransferReceiveDate { get; set; }
|
||||
public Data.Enums.TransferStatus Status { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? TransferOutId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateTransferInResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
}
|
||||
|
||||
public record CreateTransferInCommand(CreateTransferInRequest Data) : IRequest<CreateTransferInResponse>;
|
||||
|
||||
public class CreateTransferInHandler : IRequestHandler<CreateTransferInCommand, CreateTransferInResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public CreateTransferInHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateTransferInResponse> Handle(CreateTransferInCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.TransferIn);
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.TransferIn
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
TransferReceiveDate = request.Data.TransferReceiveDate,
|
||||
Status = request.Data.Status,
|
||||
Description = request.Data.Description,
|
||||
TransferOutId = request.Data.TransferOutId
|
||||
};
|
||||
|
||||
_context.TransferIn.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateTransferInResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
AutoNumber = entity.AutoNumber
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class CreateTransferInItemRequest
|
||||
{
|
||||
public string? TransferInId { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public double? Movement { get; set; }
|
||||
}
|
||||
|
||||
public record CreateTransferInItemCommand(CreateTransferInItemRequest Data) : IRequest<bool>;
|
||||
|
||||
public class CreateTransferInItemHandler : IRequestHandler<CreateTransferInItemCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public CreateTransferInItemHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(CreateTransferInItemCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var master = await _context.TransferIn
|
||||
.AsNoTracking()
|
||||
.Include(x => x.TransferOut)
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.TransferInId, cancellationToken);
|
||||
|
||||
if (master == null || master.TransferOut == null) return false;
|
||||
|
||||
var ivtEntityName = nameof(Data.Entities.InventoryTransaction);
|
||||
var autoNoIVT = await _context.GenerateAutoNumberAsync(
|
||||
entityName: ivtEntityName,
|
||||
prefixTemplate: $"{ivtEntityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.InventoryTransaction
|
||||
{
|
||||
ModuleId = master.Id,
|
||||
ModuleName = nameof(Data.Entities.TransferIn),
|
||||
ModuleCode = "TO-IN",
|
||||
ModuleNumber = master.AutoNumber,
|
||||
MovementDate = master.TransferReceiveDate!.Value,
|
||||
Status = (Data.Enums.InventoryTransactionStatus)master.Status,
|
||||
AutoNumber = autoNoIVT,
|
||||
WarehouseId = master.TransferOut.WarehouseToId,
|
||||
ProductId = request.Data.ProductId,
|
||||
Movement = request.Data.Movement
|
||||
};
|
||||
|
||||
_context.CalculateInvenTrans(entity);
|
||||
_context.InventoryTransaction.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class CreateTransferInValidator : AbstractValidator<CreateTransferInRequest>
|
||||
{
|
||||
public CreateTransferInValidator()
|
||||
{
|
||||
RuleFor(x => x.TransferReceiveDate).NotEmpty().WithMessage("Receive Date is required");
|
||||
RuleFor(x => x.TransferOutId).NotEmpty().WithMessage("Transfer Out reference is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public record DeleteTransferInByIdCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteTransferInByIdHandler : IRequestHandler<DeleteTransferInByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public DeleteTransferInByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteTransferInByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.TransferIn
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
var items = await _context.InventoryTransaction
|
||||
.Where(x => x.ModuleId == request.Id && x.ModuleName == nameof(Data.Entities.TransferIn))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
_context.InventoryTransaction.RemoveRange(items);
|
||||
_context.TransferIn.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public record DeleteTransferInItemCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteTransferInItemHandler : IRequestHandler<DeleteTransferInItemCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public DeleteTransferInItemHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteTransferInItemCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.InventoryTransaction
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.InventoryTransaction.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class TransferInItemResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public double? Movement { get; set; }
|
||||
}
|
||||
|
||||
public class GetTransferInByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public DateTime? TransferReceiveDate { get; set; }
|
||||
public Data.Enums.TransferStatus Status { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? TransferOutId { get; set; }
|
||||
public string? TransferOutNumber { get; set; }
|
||||
public string? WarehouseToName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
public List<TransferInItemResponse> Items { get; set; } = new();
|
||||
}
|
||||
|
||||
public record GetTransferInByIdQuery(string Id) : IRequest<GetTransferInByIdResponse?>;
|
||||
|
||||
public class GetTransferInByIdHandler : IRequestHandler<GetTransferInByIdQuery, GetTransferInByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetTransferInByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetTransferInByIdResponse?> Handle(GetTransferInByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var master = await _context.TransferIn
|
||||
.AsNoTracking()
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x!.WarehouseTo)
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (master == null) return null;
|
||||
|
||||
var items = await _context.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Product)
|
||||
.Where(x => x.ModuleId == request.Id && x.ModuleName == nameof(Data.Entities.TransferIn))
|
||||
.Select(x => new TransferInItemResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
ProductId = x.ProductId,
|
||||
ProductName = x.Product!.Name,
|
||||
Movement = x.Movement
|
||||
}).ToListAsync(cancellationToken);
|
||||
|
||||
return new GetTransferInByIdResponse
|
||||
{
|
||||
Id = master.Id,
|
||||
AutoNumber = master.AutoNumber,
|
||||
TransferReceiveDate = master.TransferReceiveDate,
|
||||
Status = master.Status,
|
||||
Description = master.Description,
|
||||
TransferOutId = master.TransferOutId,
|
||||
TransferOutNumber = master.TransferOut?.AutoNumber,
|
||||
WarehouseToName = master.TransferOut?.WarehouseTo?.Name,
|
||||
CreatedAt = master.CreatedAt,
|
||||
CreatedBy = master.CreatedBy,
|
||||
UpdatedAt = master.UpdatedAt,
|
||||
UpdatedBy = master.UpdatedBy,
|
||||
Items = items
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class GetTransferInListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public DateTime? TransferReceiveDate { get; set; }
|
||||
public string? TransferOutNumber { get; set; }
|
||||
public string? WarehouseToName { get; set; }
|
||||
public Data.Enums.TransferStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public record GetTransferInListQuery() : IRequest<List<GetTransferInListResponse>>;
|
||||
|
||||
public class GetTransferInListHandler : IRequestHandler<GetTransferInListQuery, List<GetTransferInListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetTransferInListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetTransferInListResponse>> Handle(GetTransferInListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.TransferIn
|
||||
.AsNoTracking()
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x!.WarehouseTo)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetTransferInListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
TransferReceiveDate = x.TransferReceiveDate,
|
||||
TransferOutNumber = x.TransferOut!.AutoNumber,
|
||||
WarehouseToName = x.TransferOut!.WarehouseTo!.Name,
|
||||
Status = x.Status
|
||||
}).ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class TransferInLookupResponse
|
||||
{
|
||||
public List<LookupItem> TransferOuts { 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 GetTransferInLookupQuery() : IRequest<TransferInLookupResponse>;
|
||||
|
||||
public class GetTransferInLookupHandler : IRequestHandler<GetTransferInLookupQuery, TransferInLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetTransferInLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<TransferInLookupResponse> Handle(GetTransferInLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new TransferInLookupResponse();
|
||||
|
||||
response.TransferOuts = await _context.TransferOut.AsNoTracking()
|
||||
.Where(x => x.Status >= TransferStatus.Confirmed)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.AutoNumber })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Products = await _context.Product.AsNoTracking()
|
||||
.Where(x => x.Physical == true)
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Statuses = Enum.GetValues(typeof(TransferStatus))
|
||||
.Cast<TransferStatus>()
|
||||
.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;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class UpdateTransferInRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public DateTime? TransferReceiveDate { get; set; }
|
||||
public Data.Enums.TransferStatus Status { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? TransferOutId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateTransferInCommand(UpdateTransferInRequest Data) : IRequest<bool>;
|
||||
|
||||
public class UpdateTransferInHandler : IRequestHandler<UpdateTransferInCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public UpdateTransferInHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(UpdateTransferInCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.TransferIn
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
entity.TransferReceiveDate = request.Data.TransferReceiveDate;
|
||||
entity.Status = request.Data.Status;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.TransferOutId = request.Data.TransferOutId;
|
||||
|
||||
var details = await _context.InventoryTransaction
|
||||
.Where(x => x.ModuleId == entity.Id && x.ModuleName == nameof(Data.Entities.TransferIn))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
foreach (var item in details)
|
||||
{
|
||||
item.MovementDate = entity.TransferReceiveDate ?? DateTime.Now;
|
||||
item.Status = (Data.Enums.InventoryTransactionStatus)entity.Status;
|
||||
item.ModuleNumber = entity.AutoNumber;
|
||||
_context.CalculateInvenTrans(item);
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class UpdateTransferInItemRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public double? Movement { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateTransferInItemCommand(UpdateTransferInItemRequest Data) : IRequest<bool>;
|
||||
|
||||
public class UpdateTransferInItemHandler : IRequestHandler<UpdateTransferInItemCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public UpdateTransferInItemHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(UpdateTransferInItemCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.InventoryTransaction
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
entity.ProductId = request.Data.ProductId;
|
||||
entity.Movement = request.Data.Movement;
|
||||
|
||||
_context.CalculateInvenTrans(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Indotalent.Features.Inventory.TransferIn.Cqrs;
|
||||
|
||||
public class UpdateTransferInValidator : AbstractValidator<UpdateTransferInRequest>
|
||||
{
|
||||
public UpdateTransferInValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.TransferReceiveDate).NotEmpty().WithMessage("Receive Date is required");
|
||||
RuleFor(x => x.TransferOutId).NotEmpty().WithMessage("Transfer Out reference is required");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user