From e598e1496ba95caad7c99936fca786e7451c373e Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 17 Mar 2025 17:28:54 -0300 Subject: [PATCH] Agregado helper para transporte + limpieza --- app/Helpers/TransporteHelper.php | 19 ++++++++ app/Subpedido.php | 78 ++++---------------------------- 2 files changed, 29 insertions(+), 68 deletions(-) create mode 100644 app/Helpers/TransporteHelper.php diff --git a/app/Helpers/TransporteHelper.php b/app/Helpers/TransporteHelper.php new file mode 100644 index 0000000..8bfc3de --- /dev/null +++ b/app/Helpers/TransporteHelper.php @@ -0,0 +1,19 @@ +totalBarrial() + $this->totalCentral() - $this->devoluciones_total; + return $this->totalSinDevoluciones() - $this->devoluciones_total; + } + + public function totalSinDevoluciones() + { + return $this->totalBarrial() + $this->totalCentral(); } public function totalBarrial() @@ -63,7 +68,7 @@ class Subpedido extends Model public function totalCentralesQueNoPaganTransporte() { - $total = DB::table('producto_subpedido') + 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%') @@ -73,7 +78,6 @@ class Subpedido extends Model }) ->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total') ->value('total'); - return $total; } public function totalCentralesQuePaganTransporte() @@ -90,69 +94,14 @@ class Subpedido extends Model public function totalTransporte() { - return $this->cantidadTransporte() * Subpedido::COSTO_TRANSPORTE; + return TransporteHelper::totalTransporte($this->totalCentralesQuePaganTransporte()); } public function cantidadTransporte() { - return ceil($this->totalCentralesQuePaganTransporte()/500); + return TransporteHelper::cantidadTransporte($this->totalCentralesQuePaganTransporte()); } - //Subtotal de dinero de productos del pedido, sin bonos ni transporte - public function totalSinBonos() - { - 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() { - $total = 0; - foreach ($this->productos()->get() as $producto) { - if ($producto->pagaTransporte()) { - $total += $producto->precio * $producto->pivot->cantidad; - } - } - return ceil($total); - } - - //Cantidad de bonos de transporte - public function cantidadBDT() - { - $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 - public function getSubtotalBDT() - { - return $this->cantidadBDT() * 15; - } - - //Subtotal de dinero de bonos (MPS, Sororo, etc) - public function getSubtotalBonos() - { - return $this->bonos()->sum('total'); - } - - public function getTotal() - { - return $this->totalSinBonos() + $this->getSubtotalBDT() + $this->getSubtotalBonos(); - } - - public function getTotalMenosDevoluciones() { - return $this->getTotal() - $this->getDevoluciones(); - } - //Actualiza el pedido, agregando o quitando del subpedido según sea necesario. Debe ser llamado desde el controlador de subpedidos, luego de validar que los parámetros $producto y $cantidad son correctos. También calcula el subtotal por producto. public function syncProducto(Producto $producto, Int $cantidad, string $notas) { if ($cantidad){ @@ -180,13 +129,6 @@ class Subpedido extends Model return $view->render(); } - public function getDevoluciones() { - return $this->devoluciones_total; - } - - public function getNotasDevoluciones() { - return $this->devoluciones_notas; - } public function syncDevoluciones(float $total, string $notas) { $this->devoluciones_total = $total; $this->devoluciones_notas = $notas;