From 584cebb9020b538debaa0a9c77234dd7835f3338 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 17 Mar 2025 16:49:43 -0300 Subject: [PATCH 01/16] Agregadas nuevas funciones para calcular total de pedidos --- app/Subpedido.php | 76 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/app/Subpedido.php b/app/Subpedido.php index 62eccb1..f1c9bbc 100644 --- a/app/Subpedido.php +++ b/app/Subpedido.php @@ -10,7 +10,8 @@ use App\Filtros\FiltroDeSubpedido; class Subpedido extends Model { - public $timestamps = false; + const COSTO_TRANSPORTE = 15; + public $timestamps = false; protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre', 'devoluciones_total', 'devoluciones_notas']; public function productos() @@ -40,10 +41,72 @@ class Subpedido extends Model return $filtros->aplicar($query); } + public function total() + { + return ceil($this->totalBarrial() + $this->totalCentral()); + } + + public function totalBarrial() + { + return DB::table('producto_subpedido') + ->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id') + ->where('producto_subpedido.subpedido_id', $this->id) + ->where('productos.nombre', 'like', '%barrial%') + ->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total') + ->value('total'); + } + + public function totalCentral() + { + return $this->totalCentralesQueNoPaganTransporte() + $this->totalCentralesQuePaganTransporte() + $this->totalTransporte(); + } + + public function totalCentralesQueNoPaganTransporte() + { + $total = DB::table('producto_subpedido') + ->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id') + ->where('producto_subpedido.subpedido_id', $this->id) + ->where('productos.nombre', 'not like', '%barrial%') + ->where(function ($query) { + $query->where('productos.categoria', 'like', '%SUBSIDIADO%') + ->orWhere('productos.bono', true); + }) + ->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total') + ->value('total'); + return $total; + } + + public function totalCentralesQuePaganTransporte() + { + return DB::table('producto_subpedido') + ->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id') + ->where('producto_subpedido.subpedido_id', $this->id) + ->where('productos.nombre', 'not like', '%barrial%') + ->where('productos.bono', false) + ->where('productos.categoria', 'not like', '%SUBSIDIADO%') + ->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total') + ->value('total'); + } + + public function totalTransporte() + { + return $this->cantidadTransporte() * Subpedido::COSTO_TRANSPORTE; + } + + public function cantidadTransporte() + { + return ceil($this->totalCentralesQuePaganTransporte()/500); + } + //Subtotal de dinero de productos del pedido, sin bonos ni transporte public function totalSinBonos() { - return $this->productosSinBonos()->sum('total'); + return DB::table('producto_subpedido') + ->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id') + ->where('producto_subpedido.subpedido_id', $this->id) + ->where('productos.bono', false) + ->selectRaw('CEILING(SUM(productos.precio * producto_subpedido.cantidad)) as total') + ->value('total'); } public function totalParaTransporte() { @@ -59,7 +122,14 @@ class Subpedido extends Model //Cantidad de bonos de transporte public function cantidadBDT() { - return ceil($this->totalParaTransporte() / 500); + $total = DB::table('producto_subpedido') + ->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id') + ->where('producto_subpedido.subpedido_id', $this->id) + ->where('productos.bono', false) + ->where('productos.categoria', 'not like', '%SUBSIDIADO%') + ->selectRaw('CEILING(SUM(productos.precio * producto_subpedido.cantidad)) as total') + ->value('total'); + return ceil($total/500); } //Subtotal de dinero de bonos de transporte From 2a5c215f40dc2388c2d875091669443fd2df7566 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 17 Mar 2025 17:01:59 -0300 Subject: [PATCH 02/16] Restando devoluciones al total --- app/Subpedido.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Subpedido.php b/app/Subpedido.php index f1c9bbc..832c2e1 100644 --- a/app/Subpedido.php +++ b/app/Subpedido.php @@ -43,7 +43,7 @@ class Subpedido extends Model public function total() { - return ceil($this->totalBarrial() + $this->totalCentral()); + return $this->totalBarrial() + $this->totalCentral() - $this->devoluciones_total; } public function totalBarrial() From c54a0b361f8cf0857911a93814d2458a3a182ed4 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 17 Mar 2025 17:02:49 -0300 Subject: [PATCH 03/16] Cambios en totales --- app/Http/Resources/SubpedidoResource.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Http/Resources/SubpedidoResource.php b/app/Http/Resources/SubpedidoResource.php index 3108eb5..5c59018 100644 --- a/app/Http/Resources/SubpedidoResource.php +++ b/app/Http/Resources/SubpedidoResource.php @@ -14,19 +14,18 @@ class SubpedidoResource extends JsonResource */ public function toArray($request) { + $total = $this->total(); return [ 'id' => $this->id, 'nombre' => $this->nombre, - 'subtotal_productos' => number_format($this->totalSinBonos(),0), - 'subtotal_bonos' => number_format($this->getSubtotalBonos(),0), - 'bonos_de_transporte' => $this->cantidadBDT(), - 'subtotal_bonos_de_transporte' => number_format($this->getSubtotalBDT(),0), - 'total' => number_format($this->getTotal(),0), - 'total_menos_devoluciones' => number_format($this->getTotalMenosDevoluciones(),0), 'grupo_de_compra' => $this->grupoDeCompra, 'productos' => $this->productos, 'aprobado' => (bool) $this->aprobado, - 'devoluciones_total' => (double) $this->devoluciones_total, + 'total' => $total, + 'total_transporte' => $this->totalTransporte(), + 'cantidad_transporte' => number_format($this->cantidadTransporte(),0), + 'total_menos_devoluciones' => $total - $this->devoluciones_total, + 'devoluciones_total' => $this->devoluciones_total, 'devoluciones_notas' => $this->devoluciones_notas ]; } From 085d72b4f88ce25b927c810ab110cc1920e0501b Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 17 Mar 2025 17:15:08 -0300 Subject: [PATCH 04/16] Actualizado a nuevo resource --- resources/js/components/admin/FilaPedido.vue | 2 +- resources/js/components/pedidos/Chismosa.vue | 8 ++++---- resources/js/components/pedidos/ChismosaDropdown.vue | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/js/components/admin/FilaPedido.vue b/resources/js/components/admin/FilaPedido.vue index 70c30e0..0cde589 100644 --- a/resources/js/components/admin/FilaPedido.vue +++ b/resources/js/components/admin/FilaPedido.vue @@ -1,7 +1,7 @@