64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Restaurant\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class PurchaseItem extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'restaurant_id',
|
|
'purchase_id',
|
|
'ingredient_id',
|
|
'food_variant_id',
|
|
'quantity',
|
|
'unit_price',
|
|
'total_cost',
|
|
'tax_amount',
|
|
'discount_amount',
|
|
'batch_no',
|
|
'expiry_date',
|
|
'received_quantity',
|
|
'wastage_quantity',
|
|
'returned_quantity',
|
|
'status',
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted_at',
|
|
];
|
|
|
|
public const TABLE_NAME = 'purchase_items';
|
|
|
|
protected $table = self::TABLE_NAME;
|
|
|
|
protected $casts = [
|
|
'expiry_date' => 'date:Y-m-d',
|
|
];
|
|
|
|
// 🔗 Relationships
|
|
public function purchase(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Purchase::class, 'purchase_id');
|
|
}
|
|
|
|
public function ingredient(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Ingredient::class, 'ingredient_id')->with('unit');
|
|
}
|
|
|
|
public function variant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(FoodVariant::class, 'food_variant_id');
|
|
}
|
|
|
|
public function returns(): HasMany
|
|
{
|
|
return $this->hasMany(PurchaseReturn::class, 'purchase_item_id', 'id');
|
|
}
|
|
}
|