diff --git a/app/Models/Barrio.php b/app/Models/Barrio.php index fd1a0c7..335505e 100644 --- a/app/Models/Barrio.php +++ b/app/Models/Barrio.php @@ -2,7 +2,8 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Model; class Barrio extends Model diff --git a/app/Models/Caracteristica.php b/app/Models/Caracteristica.php index d978baa..7a8f991 100644 --- a/app/Models/Caracteristica.php +++ b/app/Models/Caracteristica.php @@ -2,7 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Model; class Caracteristica extends Model diff --git a/app/Models/Categoria.php b/app/Models/Categoria.php index 66993d1..fc1258d 100644 --- a/app/Models/Categoria.php +++ b/app/Models/Categoria.php @@ -2,7 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Model; class Categoria extends Model diff --git a/app/Models/Pedido.php b/app/Models/Pedido.php index ae55e70..2396085 100644 --- a/app/Models/Pedido.php +++ b/app/Models/Pedido.php @@ -2,7 +2,8 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Model; class Pedido extends Model @@ -29,6 +30,22 @@ public function barrio(): BelongsTo */ public function productos(): BelongsToMany { - return $this->belongsToMany(Producto::class)->withPivot(['cantidad','total']); + return $this->belongsToMany(Producto::class)->withPivot(['cantidad']); + } + + public function productosSinBonos() { + return $this->productos()->where('bono',0)->all(); + } + + function bonos() { + return $this->productos()->where('bono',1)->all(); + } + + function bonosDeTransporte() : int { + $total = 0; + foreach ($this->productosSinBonos() as $key => $producto) { + $total += $producto->price * $producto->pivot->cantidad; + } + return 1 + ($total / 500); } } diff --git a/app/Models/Producto.php b/app/Models/Producto.php index 07299c3..d170a27 100644 --- a/app/Models/Producto.php +++ b/app/Models/Producto.php @@ -2,7 +2,8 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Model; class Producto extends Model @@ -29,7 +30,7 @@ public function categoria(): BelongsTo */ public function pedidos(): BelongsToMany { - return $this->belongsToMany(Pedido::class)->withPivot(['cantidad','total']); + return $this->belongsToMany(Pedido::class)->withPivot(['cantidad']); } /** diff --git a/app/Models/Region.php b/app/Models/Region.php index 53ddecb..810fa80 100644 --- a/app/Models/Region.php +++ b/app/Models/Region.php @@ -2,7 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Model; class Region extends Model