initial commit
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
using Application.Common.Extensions;
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferInManager.Commands;
|
||||
|
||||
public class CreateTransferInResult
|
||||
{
|
||||
public TransferIn? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateTransferInRequest : IRequest<CreateTransferInResult>
|
||||
{
|
||||
public DateTime? TransferReceiveDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? TransferOutId { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateTransferInValidator : AbstractValidator<CreateTransferInRequest>
|
||||
{
|
||||
public CreateTransferInValidator()
|
||||
{
|
||||
RuleFor(x => x.TransferReceiveDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.TransferOutId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateTransferInHandler : IRequestHandler<CreateTransferInRequest, CreateTransferInResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferIn> _deliveryOrderRepository;
|
||||
private readonly ICommandRepository<InventoryTransaction> _itemRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public CreateTransferInHandler(
|
||||
ICommandRepository<TransferIn> deliveryOrderRepository,
|
||||
ICommandRepository<InventoryTransaction> itemRepository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_deliveryOrderRepository = deliveryOrderRepository;
|
||||
_itemRepository = itemRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<CreateTransferInResult> Handle(CreateTransferInRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new TransferIn();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(TransferIn), "", "IN");
|
||||
entity.TransferReceiveDate = request.TransferReceiveDate;
|
||||
entity.Status = (TransferStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.TransferOutId = request.TransferOutId;
|
||||
|
||||
await _deliveryOrderRepository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
var items = await _itemRepository
|
||||
.GetQuery()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.ModuleId == entity.TransferOutId && x.ModuleName == nameof(TransferOut))
|
||||
.Include(x => x.Product)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item?.Product?.Physical ?? false)
|
||||
{
|
||||
await _inventoryTransactionService.TransferInCreateInvenTrans(
|
||||
entity.Id,
|
||||
item.ProductId,
|
||||
item.Movement,
|
||||
entity.CreatedById,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return new CreateTransferInResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferInManager.Commands;
|
||||
|
||||
public class DeleteTransferInResult
|
||||
{
|
||||
public TransferIn? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteTransferInRequest : IRequest<DeleteTransferInResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteTransferInValidator : AbstractValidator<DeleteTransferInRequest>
|
||||
{
|
||||
public DeleteTransferInValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteTransferInHandler : IRequestHandler<DeleteTransferInRequest, DeleteTransferInResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferIn> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeleteTransferInHandler(
|
||||
ICommandRepository<TransferIn> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeleteTransferInResult> Handle(DeleteTransferInRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.DeletedById;
|
||||
|
||||
_repository.Delete(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(TransferIn),
|
||||
entity.TransferReceiveDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new DeleteTransferInResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferInManager.Commands;
|
||||
|
||||
public class UpdateTransferInResult
|
||||
{
|
||||
public TransferIn? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateTransferInRequest : IRequest<UpdateTransferInResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public DateTime? TransferReceiveDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? TransferOutId { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateTransferInValidator : AbstractValidator<UpdateTransferInRequest>
|
||||
{
|
||||
public UpdateTransferInValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.TransferReceiveDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.TransferOutId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateTransferInHandler : IRequestHandler<UpdateTransferInRequest, UpdateTransferInResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferIn> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
private readonly ICommandRepository<TransferOut> _transferOutRepository;
|
||||
|
||||
public UpdateTransferInHandler(
|
||||
ICommandRepository<TransferIn> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService,
|
||||
ICommandRepository<TransferOut> transferOutRepository
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
_transferOutRepository = transferOutRepository;
|
||||
}
|
||||
|
||||
public async Task<UpdateTransferInResult> Handle(UpdateTransferInRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.TransferReceiveDate = request.TransferReceiveDate;
|
||||
entity.Status = (TransferStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.TransferOutId = request.TransferOutId;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
var transferOut = await _transferOutRepository.GetAsync(entity.TransferOutId ?? string.Empty, cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(TransferIn),
|
||||
entity.TransferReceiveDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
transferOut?.WarehouseToId,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new UpdateTransferInResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferInManager.Queries;
|
||||
|
||||
public record GetTransferInListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? TransferReceiveDate { get; init; }
|
||||
public TransferStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? TransferOutId { get; init; }
|
||||
public string? TransferOutNumber { get; init; }
|
||||
public string? WarehouseFromName { get; init; }
|
||||
public string? WarehouseToName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInListProfile : Profile
|
||||
{
|
||||
public GetTransferInListProfile()
|
||||
{
|
||||
CreateMap<TransferIn, GetTransferInListDto>()
|
||||
.ForMember(
|
||||
dest => dest.TransferOutNumber,
|
||||
opt => opt.MapFrom(src => src.TransferOut != null ? src.TransferOut.Number : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.WarehouseFromName,
|
||||
opt => opt.MapFrom(src => src.TransferOut!.WarehouseFrom != null ? src.TransferOut.WarehouseFrom.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.WarehouseToName,
|
||||
opt => opt.MapFrom(src => src.TransferOut!.WarehouseTo != null ? src.TransferOut.WarehouseTo.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferInListResult
|
||||
{
|
||||
public List<GetTransferInListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInListRequest : IRequest<GetTransferInListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetTransferInListHandler : IRequestHandler<GetTransferInListRequest, GetTransferInListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetTransferInListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTransferInListResult> Handle(GetTransferInListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.TransferIn
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x.WarehouseFrom)
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x.WarehouseTo)
|
||||
.AsQueryable();
|
||||
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetTransferInListDto>>(entities);
|
||||
|
||||
return new GetTransferInListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferInManager.Queries;
|
||||
|
||||
|
||||
public class GetTransferInSingleProfile : Profile
|
||||
{
|
||||
public GetTransferInSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferInSingleResult
|
||||
{
|
||||
public TransferIn? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInSingleRequest : IRequest<GetTransferInSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInSingleValidator : AbstractValidator<GetTransferInSingleRequest>
|
||||
{
|
||||
public GetTransferInSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferInSingleHandler : IRequestHandler<GetTransferInSingleRequest, GetTransferInSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetTransferInSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTransferInSingleResult> Handle(GetTransferInSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.TransferIn
|
||||
.AsNoTracking()
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x.WarehouseFrom)
|
||||
.Include(x => x.TransferOut)
|
||||
.ThenInclude(x => x.WarehouseTo)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.AsQueryable();
|
||||
|
||||
var data = await queryData.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
|
||||
var queryTransactionList = _context
|
||||
.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.Product)
|
||||
.Include(x => x.Warehouse)
|
||||
.Include(x => x.WarehouseFrom)
|
||||
.Include(x => x.WarehouseTo)
|
||||
.Where(x => x.ModuleId == request.Id && x.ModuleName == nameof(TransferIn))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetTransferInSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferInManager.Queries;
|
||||
|
||||
public record GetTransferInStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInStatusListProfile : Profile
|
||||
{
|
||||
public GetTransferInStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferInStatusListResult
|
||||
{
|
||||
public List<GetTransferInStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferInStatusListRequest : IRequest<GetTransferInStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetTransferInStatusListHandler : IRequestHandler<GetTransferInStatusListRequest, GetTransferInStatusListResult>
|
||||
{
|
||||
|
||||
public GetTransferInStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetTransferInStatusListResult> Handle(GetTransferInStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(TransferStatus))
|
||||
.Cast<TransferStatus>()
|
||||
.Select(status => new GetTransferInStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetTransferInStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user