Agregado helper para transporte + limpieza

This commit is contained in:
Alejandro Tasistro 2025-03-17 17:28:54 -03:00
parent 085d72b4f8
commit e598e1496b
2 changed files with 29 additions and 68 deletions

View file

@ -0,0 +1,19 @@
<?php
namespace App\Helpers;
class TransporteHelper
{
const COSTO_TRANSPORTE = 15;
const MONTO_TRANSPORTE = 500;
public static function cantidadTransporte($monto)
{
return ceil($monto / self::MONTO_TRANSPORTE);
}
public static function totalTransporte($monto)
{
return self::cantidadTransporte($monto) * self::COSTO_TRANSPORTE;
}
}

View file

@ -2,7 +2,7 @@
namespace App;
use League\Csv\Reader;
use App\Helpers\TransporteHelper;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Log;
@ -43,7 +43,12 @@ class Subpedido extends Model
public function total()
{
return $this->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,67 +94,12 @@ 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);
}
//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();
return TransporteHelper::cantidadTransporte($this->totalCentralesQuePaganTransporte());
}
//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.
@ -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;