forked from nathalie/pedi2
Agregado helper para transporte + limpieza
This commit is contained in:
parent
085d72b4f8
commit
e598e1496b
2 changed files with 29 additions and 68 deletions
19
app/Helpers/TransporteHelper.php
Normal file
19
app/Helpers/TransporteHelper.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use League\Csv\Reader;
|
use App\Helpers\TransporteHelper;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Log;
|
use Log;
|
||||||
|
@ -43,7 +43,12 @@ class Subpedido extends Model
|
||||||
|
|
||||||
public function total()
|
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()
|
public function totalBarrial()
|
||||||
|
@ -63,7 +68,7 @@ class Subpedido extends Model
|
||||||
|
|
||||||
public function totalCentralesQueNoPaganTransporte()
|
public function totalCentralesQueNoPaganTransporte()
|
||||||
{
|
{
|
||||||
$total = DB::table('producto_subpedido')
|
return DB::table('producto_subpedido')
|
||||||
->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id')
|
->join('productos', 'producto_subpedido.producto_id', '=', 'productos.id')
|
||||||
->where('producto_subpedido.subpedido_id', $this->id)
|
->where('producto_subpedido.subpedido_id', $this->id)
|
||||||
->where('productos.nombre', 'not like', '%barrial%')
|
->where('productos.nombre', 'not like', '%barrial%')
|
||||||
|
@ -73,7 +78,6 @@ class Subpedido extends Model
|
||||||
})
|
})
|
||||||
->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total')
|
->selectRaw('SUM(productos.precio * producto_subpedido.cantidad) as total')
|
||||||
->value('total');
|
->value('total');
|
||||||
return $total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function totalCentralesQuePaganTransporte()
|
public function totalCentralesQuePaganTransporte()
|
||||||
|
@ -90,69 +94,14 @@ class Subpedido extends Model
|
||||||
|
|
||||||
public function totalTransporte()
|
public function totalTransporte()
|
||||||
{
|
{
|
||||||
return $this->cantidadTransporte() * Subpedido::COSTO_TRANSPORTE;
|
return TransporteHelper::totalTransporte($this->totalCentralesQuePaganTransporte());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cantidadTransporte()
|
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.
|
//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) {
|
public function syncProducto(Producto $producto, Int $cantidad, string $notas) {
|
||||||
if ($cantidad){
|
if ($cantidad){
|
||||||
|
@ -180,13 +129,6 @@ class Subpedido extends Model
|
||||||
return $view->render();
|
return $view->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDevoluciones() {
|
|
||||||
return $this->devoluciones_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNotasDevoluciones() {
|
|
||||||
return $this->devoluciones_notas;
|
|
||||||
}
|
|
||||||
public function syncDevoluciones(float $total, string $notas) {
|
public function syncDevoluciones(float $total, string $notas) {
|
||||||
$this->devoluciones_total = $total;
|
$this->devoluciones_total = $total;
|
||||||
$this->devoluciones_notas = $notas;
|
$this->devoluciones_notas = $notas;
|
||||||
|
|
Loading…
Add table
Reference in a new issue