feature/columna-totales #4
4 changed files with 27 additions and 22 deletions
|
@ -66,19 +66,16 @@ class Barrio extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
public function totalATransferir() : float {
|
public function totalATransferir() : float {
|
||||||
return $this->totalNoBarriales() + $this->totalBonosDeTransporte();
|
return $this->totalProductosConTransporte() + $this->totalBonosDeTransporte();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function totalBonosDeTransporte() : int {
|
public function totalBonosDeTransporte() : int {
|
||||||
return TransporteUtils::calcularTotal($this->totalNoBarriales());
|
return TransporteUtils::calcularTotal($this->totalProductosConTransporte());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function totalNoBarriales() {
|
public function totalProductosConTransporte(): float
|
||||||
return $this->totalProductosIf(['barrial' => false]);
|
{
|
||||||
}
|
return $this->totalProductosIf(fn($p) => $p->pagaTransporte());
|
||||||
|
|
||||||
public function totalBarriales() {
|
|
||||||
return $this->totalProductosIf(['barrial' => true]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function totalProductosIf($predicado) : float {
|
private function totalProductosIf($predicado) : float {
|
||||||
|
@ -110,6 +107,7 @@ class Barrio extends Model
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function armarColumnaTotales() : array {
|
private function armarColumnaTotales() : array {
|
||||||
|
@ -117,18 +115,18 @@ class Barrio extends Model
|
||||||
$filasVaciasAgregadas = false;
|
$filasVaciasAgregadas = false;
|
||||||
$productos = $this->productosPedidos()->where(['barrial' => false])->get();
|
$productos = $this->productosPedidos()->where(['barrial' => false])->get();
|
||||||
|
|
||||||
foreach (Categoria::orderBy('id')->get() as $keyC => $categoria) {
|
foreach (Categoria::orderBy('id')->get() as $categoria) {
|
||||||
if ($categoria->productos()->where(['barrial' => false])->count() == 0)
|
if ($categoria->productos()->where(['barrial' => false])->count() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$columnaProductos[] = ['nombre' => $categoria->nombre, 'cantidad' => null];
|
$columnaProductos[] = ['nombre' => $categoria->nombre, 'cantidad' => null];
|
||||||
|
|
||||||
if ($categoria->nombre == 'TRANSPORTE, BONOS Y FINANCIAMIENTO SORORO')
|
if ($categoria->nombre == 'TRANSPORTE, BONOS Y FINANCIAMIENTO SORORO')
|
||||||
$columnaProductos[] = ['nombre' => 'Bono de Transporte', 'cantidad' => $this->totalBonosDeTransporte()];
|
$columnaProductos[] = ['nombre' => 'Bono de Transporte', 'cantidad' => TransporteUtils::cantidad($this->totalProductosConTransporte())];
|
||||||
else if ($categoria->nombre == 'PRODUCTOS DE GESTIÓN MENSTRUAL')
|
if ($categoria->nombre == 'PRODUCTOS DE GESTIÓN MENSTRUAL')
|
||||||
$columnaProductos[] = ['nombre' => '¿Cuántas copas quieren y pueden comprar en el grupo?', 'cantidad' => null];
|
$columnaProductos[] = ['nombre' => '¿Cuántas copas quieren y pueden comprar en el grupo?', 'cantidad' => null];
|
||||||
|
|
||||||
foreach ($categoria->productos()->orderBy('id')->get() as $keyP => $producto) {
|
foreach ($categoria->productos()->orderBy('id')->get() as $producto) {
|
||||||
if ($producto->precio == 0 && !$filasVaciasAgregadas) {
|
if ($producto->precio == 0 && !$filasVaciasAgregadas) {
|
||||||
$columnaProductos[] = ['nombre' => '¿Cuántas copas quieren adquirir a través del financiamiento sororo?', 'cantidad' => null];
|
$columnaProductos[] = ['nombre' => '¿Cuántas copas quieren adquirir a través del financiamiento sororo?', 'cantidad' => null];
|
||||||
$filasVaciasAgregadas = true;
|
$filasVaciasAgregadas = true;
|
||||||
|
@ -141,6 +139,6 @@ class Barrio extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
private function cantidadPedida($productoId, $productos) {
|
private function cantidadPedida($productoId, $productos) {
|
||||||
return $productos->first(fn($p) => $p->id == $productoId)->cantidad ?? 0;
|
return $productos->find($productoId)->cantidad ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Models;
|
||||||
|
|
||||||
use App\Utils\TransporteUtils;
|
use App\Utils\TransporteUtils;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
@ -45,12 +46,13 @@ class Pedido extends Model
|
||||||
return $this->belongsToMany(Producto::class)->withPivot(['cantidad']);
|
return $this->belongsToMany(Producto::class)->withPivot(['cantidad']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function productosConTransporte() {
|
public function productosConTransporte() : Collection
|
||||||
return $this->productos()->where(['bono' => false, 'barrial' => false])->get();
|
{
|
||||||
|
return $this->productos()->where(fn($p) => $p->pagaTransporte())->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function agregarProducto(Producto $producto, int $cantidad) : Producto {
|
public function agregarProducto(Producto $producto, int $cantidad) : Producto {
|
||||||
$productoEnChismosa = $this->productos()->where('id', $producto->id)->first();
|
$productoEnChismosa = $this->productos()->find($producto->id);
|
||||||
if ($productoEnChismosa) {
|
if ($productoEnChismosa) {
|
||||||
$productoEnChismosa->pivot->cantidad += $cantidad;
|
$productoEnChismosa->pivot->cantidad += $cantidad;
|
||||||
if ($productoEnChismosa->pivot->cantidad != 0)
|
if ($productoEnChismosa->pivot->cantidad != 0)
|
||||||
|
@ -60,7 +62,7 @@ class Pedido extends Model
|
||||||
return $productoEnChismosa;
|
return $productoEnChismosa;
|
||||||
} else {
|
} else {
|
||||||
$this->productos()->attach($producto, ['cantidad' => $cantidad]);
|
$this->productos()->attach($producto, ['cantidad' => $cantidad]);
|
||||||
return $this->productos()->where('id', $producto->id)->first();
|
return $this->productos()->find($producto->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,4 +48,9 @@ class Producto extends Model
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Barrio::class);
|
return $this->belongsTo(Barrio::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pagaTransporte() : bool
|
||||||
|
{
|
||||||
|
return !$this->bono && !$this->barrial;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ class TransporteUtils
|
||||||
public const COSTO_TRANSPORTE = 15;
|
public const COSTO_TRANSPORTE = 15;
|
||||||
public const DIVISOR_TRANSPORTE = 500;
|
public const DIVISOR_TRANSPORTE = 500;
|
||||||
|
|
||||||
private static function cantidad(float $total) : int {
|
public static function cantidad(float $total) : int {
|
||||||
if ($total)
|
if ($total)
|
||||||
return 1 + floor($total / TransporteUtils::DIVISOR_TRANSPORTE);
|
return 1 + floor($total / TransporteUtils::DIVISOR_TRANSPORTE);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue