Agregado total sin devoluciones a resource de grupo de compra

This commit is contained in:
Alejandro Tasistro 2025-05-26 17:25:35 -03:00
parent d0ce8e8e23
commit 439f69a30c
4 changed files with 16 additions and 4 deletions

View file

@ -43,6 +43,14 @@ class GrupoDeCompra extends Model
return $total;
}
public function totalSinDevoluciones() {
$total = 0;
foreach ($this->pedidosAprobados() as $subpedido) {
$total = $total + $subpedido->totalSinDevoluciones();
}
return $total;
}
public function totalBarrial()
{
$total = 0;

View file

@ -21,6 +21,7 @@ class GrupoDeCompraResource extends JsonResource
'devoluciones_habilitadas' => $this->devoluciones_habilitadas,
'pedidos' => SubpedidoResource::collection($this->subpedidos),
'total_a_recaudar' => number_format($this->totalARecaudar(),2),
'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2),
'total_barrial' => number_format($this->totalBarrial(),2),
'total_devoluciones' => number_format($this->totalDevoluciones(),2),
'total_a_transferir' => number_format($this->totalATransferir(),2),

View file

@ -24,7 +24,7 @@
</tr>
<tr>
<th>Total a recaudar:</th>
<td class="has-text-right">$ {{ total_a_recaudar }}</td>
<td class="has-text-right">$ {{ devoluciones_habilitadas ? total_a_recaudar : total_sin_devoluciones }}</td>
</tr>
<tr>
<th>Total bonos barriales:</th>
@ -62,6 +62,7 @@ export default {
"devoluciones_habilitadas",
"pedidos",
"total_a_recaudar",
"total_sin_devoluciones",
"total_barrial",
"total_devoluciones",
"cantidad_transporte",

View file

@ -7,6 +7,7 @@ const state = {
devoluciones_habilitadas: null,
pedidos: null,
total_a_recaudar: null,
total_sin_devoluciones: null,
total_barrial: null,
total_devoluciones: null,
total_a_transferir: null,
@ -22,6 +23,7 @@ const mutations = {
state.devoluciones_habilitadas = grupo_de_compra.devoluciones_habilitadas;
state.pedidos = grupo_de_compra.pedidos;
state.total_a_recaudar = grupo_de_compra.total_a_recaudar;
state.total_sin_devoluciones = grupo_de_compra.total_sin_devoluciones;
state.total_barrial = grupo_de_compra.total_barrial;
state.total_devoluciones = grupo_de_compra.total_devoluciones;
state.total_a_transferir = grupo_de_compra.total_a_transferir;
@ -56,16 +58,16 @@ const getters = {
return state.lastFetch !== null;
},
hayPedidos() {
return getters.grupoDeCompraDefinido() && state.pedidos.length > 0;
return state.pedidos?.length > 0;
},
pedidosAprobados() {
return getters.grupoDeCompraDefinido() ? state.pedidos.filter(p => p.aprobado) : [];
return state.pedidos?.filter(p => p.aprobado) ?? [];
},
hayAprobados() {
return getters.pedidosAprobados().length !== 0;
},
getPedido() {
return (pedido_id) => state.pedidos.find(p => p.id === pedido_id);
return (pedido_id) => state.pedidos?.find(p => p.id === pedido_id);
},
getCaracteristica() {
return (caracteristica) => state[`${caracteristica}_habilitadas`];