Mantenedor de compras!

This commit is contained in:
2021-07-14 03:58:17 -04:00
parent 4b71bc67aa
commit 0816f37611
9 changed files with 436 additions and 29 deletions

View File

@@ -11,8 +11,17 @@ class Compra extends Model {
use UuidPrimaryKey, SoftDeletes;
protected $table = 'compras';
protected $fillable = [
'id', 'fecha_compra', 'proveedor_id', 'en_arqueo', 'restaurante_id'
];
public function compraIngredientes() {
public static function findOrFail($id) {
$compra = Compra::find($id);
if(!$compra) throw new ModelNotFoundException("compra", $id);
return $compra;
}
public function ingredientes() {
return $this->hasMany(CompraIngrediente::class);
}

View File

@@ -11,6 +11,7 @@ class CompraIngrediente extends Model {
use UuidPrimaryKey, SoftDeletes;
protected $table = 'compra_ingredientes';
protected $fillable = ['id', 'unidades', 'monto_unitario', 'compra_id', 'ingrediente_id'];
public function ingrediente() {
return $this->belongsTo(Ingrediente::class);

View File

@@ -11,6 +11,13 @@ class Factura extends Model {
use UuidPrimaryKey, SoftDeletes;
protected $table = 'facturas';
protected $fillable = ['id', 'numero', 'monto_bruto', 'compra_id'];
public static function findOrFail($id) {
$factura = Factura::find($id);
if(!$factura) throw new ModelNotFoundException("factura", $id);
return $factura;
}
public function compra() {
return $this->belongsTo(Compra::class);

View File

@@ -2,13 +2,6 @@
namespace App\Models;
use App\Models\CanalVenta;
use App\Models\Sector;
use App\Models\ZonaProduccion;
use App\Models\Categoria;
use App\Models\Proveedor;
use App\Models\Ingrediente;
use App\Models\Producto;
use App\Traits\UuidPrimaryKey;
use App\Exceptions\ModelNotFoundException;
use Illuminate\Database\Eloquent\Model;
@@ -60,4 +53,8 @@ class Restaurante extends Model {
public function productos() {
return $this->hasMany(Producto::class, 'restaurante_id');
}
public function compras() {
return $this->hasMany(Compra::class, 'restaurante_id');
}
}