Skip to content

Commit

Permalink
fix create pedido
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunobento1990 committed Oct 2, 2024
1 parent aa6aa9e commit b0916c6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static IContainer CellTableStyle(IContainer container)
}

// Total de produtos
table.Cell().Element(CellTableStyle).Text($"Total produtos: {movimentacaoDeProdutoRelatorios.Count}")
table.Cell().Element(CellTableStyle).Text($"Total produtos: {movimentacaoDeProdutoRelatorios.Sum(x => x.Quantidade).ConverterPadraoBrasileiro()}")
.Bold().FontSize(8);
for (int i = 0; i < 6; i++) table.Cell(); // Preencher as células vazias restantes
});
Expand Down
14 changes: 6 additions & 8 deletions OpenAdm.Application/Services/MovimentacaoDeProdutosService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public async Task<byte[]> GerarRelatorioAsync(RelatorioMovimentoDeProdutoDto rel
totalCategorias.Add(new RelatorioMovimentoDeProdutoTotalizacaoDto()
{
Descricao = produto.Categoria.Descricao,
Total = 1
Total = item.QuantidadeMovimentada
});
}
else
{
totalCategoria.Total++;
totalCategoria.Total += item.QuantidadeMovimentada;
}

var pesoTamanho = string.Empty;
Expand Down Expand Up @@ -125,17 +125,15 @@ public async Task<byte[]> GerarRelatorioAsync(RelatorioMovimentoDeProdutoDto rel
.GroupBy(p => p.PesoId)
.Select(group => new
{
Peso = group.Key!.Value,
Count = group.Count()
Peso = group.Key!.Value
});

var groupedByTamanhos = movimentacoes
.Where(x => x.TamanhoId != null)
.GroupBy(p => p.TamanhoId)
.Select(group => new
{
Tamanho = group.Key!.Value,
Count = group.Count()
Tamanho = group.Key!.Value
});

foreach (var peso in groupedByPesos)
Expand All @@ -145,7 +143,7 @@ public async Task<byte[]> GerarRelatorioAsync(RelatorioMovimentoDeProdutoDto rel
totalPesos.Add(new RelatorioMovimentoDeProdutoTotalizacaoDto()
{
Descricao = pes,
Total = peso.Count
Total = movimentacoes.Where(x => x.PesoId == peso.Peso).Sum(x => x.QuantidadeMovimentada)
});
}
}
Expand All @@ -157,7 +155,7 @@ public async Task<byte[]> GerarRelatorioAsync(RelatorioMovimentoDeProdutoDto rel
totalTamanhos.Add(new RelatorioMovimentoDeProdutoTotalizacaoDto()
{
Descricao = tama,
Total = tamanho.Count
Total = movimentacoes.Where(x => x.TamanhoId == tamanho.Tamanho).Sum(x => x.QuantidadeMovimentada)
});
}
}
Expand Down
16 changes: 8 additions & 8 deletions OpenAdm.Application/Services/Pedidos/CreatePedidoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public async Task<PedidoViewModel> CreatePedidoAsync(IList<ItemPedidoModel> iten
var produtosIds = itensPedidoModels.Select(x => x.ProdutoId).ToList();
var itensTabelaDePreco = await _itemTabelaDePrecoRepository.GetItensTabelaDePrecoByIdProdutosAsync(produtosIds);

foreach (var itemTabelaDePreco in itensTabelaDePreco)
foreach (var item in itensPedidoModels)
{
var preco = itensPedidoModels
.FirstOrDefault(itemPedido =>
itemPedido.ProdutoId == itemTabelaDePreco.ProdutoId &&
itemPedido.PesoId == itemTabelaDePreco.PesoId &&
itemPedido.TamanhoId == itemTabelaDePreco.TamanhoId)
?? throw new Exception($"Não foi possível localizar o preço do produto: {itemTabelaDePreco.ProdutoId}");
var itemTabela = itensTabelaDePreco
.FirstOrDefault(itemTabelaDePreco =>
itemTabelaDePreco.ProdutoId == item.ProdutoId &&
itemTabelaDePreco.PesoId == item.PesoId &&
itemTabelaDePreco.TamanhoId == item.TamanhoId)
?? throw new Exception($"Não foi possível localizar o preço do produto: {item.ProdutoId}");

if (usuario.IsAtacado && preco.ValorUnitario != itemTabelaDePreco.ValorUnitarioAtacado)
if (usuario.IsAtacado && item.ValorUnitario != itemTabela.ValorUnitarioAtacado)
{
throw new Exception($"Os valores unitários do pedido estão incorretos: usuarioId: {usuario.Id}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task<IList<MovimentacaoDeProduto>> RelatorioAsync(
var query = _parceiroContext
.MovimentacoesDeProdutos
.OrderBy(x => x.DataDeCriacao)
.Where(x => x.DataDeCriacao >= dataInicial && x.DataDeCriacao <= dataFinal);
.Where(x => x.DataDeCriacao.Date >= dataInicial.Date && x.DataDeCriacao.Date <= dataFinal.Date);

if(produtosIds.Count > 0)
{
Expand Down

0 comments on commit b0916c6

Please sign in to comment.