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