Agregadas nuevas funciones para calcular total de pedidos
This commit is contained in:
parent
d4bffd1df8
commit
584cebb902
1 changed files with 73 additions and 3 deletions
|
@ -10,6 +10,7 @@ use App\Filtros\FiltroDeSubpedido;
|
|||
|
||||
class Subpedido extends Model
|
||||
{
|
||||
const COSTO_TRANSPORTE = 15;
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre', 'devoluciones_total', 'devoluciones_notas'];
|
||||
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue