Compare commits

..

No commits in common. "4c9ef3f782368ab2980c24495d709499a5a56247" and "59428f04b8207bf1004d4dd50bbec2e1d7fb9153" have entirely different histories.

3 changed files with 3 additions and 29 deletions

View file

@ -33,17 +33,14 @@ class Barrio extends Model
return $this->hasMany(Pedido::class);
}
function crearPedido(string $nombre) : Pedido {
return $this->pedidos()->create(['name' => $name]);
}
function pedidosConfirmados() {
return $this->pedidos()->where('confirmed',true);
}
private function calcularTotalConfirmados(Closure $closure = null) : float {
private function calcularTotalConfirmados($closure = null) : float {
if (!$closure)
$closure = fn($p) => $p->totalChismosa();
return $this->pedidosConfirmados()->sum($closure);
}
@ -52,9 +49,7 @@ class Barrio extends Model
}
function totalNoBarriales() : float {
return $this->calcularTotalConfirmados(
fn($p) => $p->total($p->productosNoBarriales())
);
return $this->calcularTotalConfirmados(fn($p) => $p->total($p->productosNoBarriales()));
}
function totalTransporte() : float {

View file

@ -96,24 +96,4 @@ class Pedido extends Model
function totalChismosa() : float {
return $this->total() + $this->totalTransporte();
}
function toggleConfirm() : bool {
$this->confirmed = !$this->confirmed;
$this->save();
return $this->confirmed;
}
function agregarProducto(Producto $producto, int $cantidad) {
$productoEnChismosa = $this->productos()->where('id', $producto->id)->first();
if ($productoEnChismosa) {
$productoEnChismosa->pivot->cantidad += $cantidad;
$productoEnChismosa->save();
} else {
$this->productos()->attach($producto, ['cantidad' => $cantidad]);
}
}
function quitarProducto(Producto $producto) {
$this->productos()->detach($producto);
}
}

View file

@ -18,7 +18,6 @@ return new class extends Migration
$table->unsignedBigInteger('barrio_id');
$table->timestamps();
$table->foreign('barrio_id')->references('id')->on('barrios');
$table->unique(['barrio_id','name']);
});
}