Compare commits
No commits in common. "4c9ef3f782368ab2980c24495d709499a5a56247" and "59428f04b8207bf1004d4dd50bbec2e1d7fb9153" have entirely different histories.
4c9ef3f782
...
59428f04b8
3 changed files with 3 additions and 29 deletions
|
@ -33,17 +33,14 @@ class Barrio extends Model
|
||||||
return $this->hasMany(Pedido::class);
|
return $this->hasMany(Pedido::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
function crearPedido(string $nombre) : Pedido {
|
|
||||||
return $this->pedidos()->create(['name' => $name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pedidosConfirmados() {
|
function pedidosConfirmados() {
|
||||||
return $this->pedidos()->where('confirmed',true);
|
return $this->pedidos()->where('confirmed',true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function calcularTotalConfirmados(Closure $closure = null) : float {
|
private function calcularTotalConfirmados($closure = null) : float {
|
||||||
if (!$closure)
|
if (!$closure)
|
||||||
$closure = fn($p) => $p->totalChismosa();
|
$closure = fn($p) => $p->totalChismosa();
|
||||||
|
|
||||||
return $this->pedidosConfirmados()->sum($closure);
|
return $this->pedidosConfirmados()->sum($closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,9 +49,7 @@ class Barrio extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
function totalNoBarriales() : float {
|
function totalNoBarriales() : float {
|
||||||
return $this->calcularTotalConfirmados(
|
return $this->calcularTotalConfirmados(fn($p) => $p->total($p->productosNoBarriales()));
|
||||||
fn($p) => $p->total($p->productosNoBarriales())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function totalTransporte() : float {
|
function totalTransporte() : float {
|
||||||
|
|
|
@ -96,24 +96,4 @@ class Pedido extends Model
|
||||||
function totalChismosa() : float {
|
function totalChismosa() : float {
|
||||||
return $this->total() + $this->totalTransporte();
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ return new class extends Migration
|
||||||
$table->unsignedBigInteger('barrio_id');
|
$table->unsignedBigInteger('barrio_id');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->foreign('barrio_id')->references('id')->on('barrios');
|
$table->foreign('barrio_id')->references('id')->on('barrios');
|
||||||
$table->unique(['barrio_id','name']);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue