48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class SupplierInvoice extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = ['invoice_number', 'supplier_id', 'purchase_order_id', 'goods_receipt_note_id', 'invoice_date', 'due_date', 'subtotal', 'vat_amount', 'total_amount', 'paid_amount', 'status', 'notes'];
|
|
|
|
protected $casts = [
|
|
'invoice_date' => 'date',
|
|
'due_date' => 'date',
|
|
'subtotal' => 'decimal:2',
|
|
'vat_amount' => 'decimal:2',
|
|
'total_amount' => 'decimal:2',
|
|
'paid_amount' => 'decimal:2',
|
|
];
|
|
|
|
public function supplier()
|
|
{
|
|
return $this->belongsTo(Supplier::class);
|
|
}
|
|
|
|
public function purchaseOrder()
|
|
{
|
|
return $this->belongsTo(PurchaseOrder::class);
|
|
}
|
|
|
|
public function goodsReceiptNote()
|
|
{
|
|
return $this->belongsTo(GoodsReceiptNote::class);
|
|
}
|
|
|
|
public function payments()
|
|
{
|
|
return $this->hasMany(SupplierPayment::class);
|
|
}
|
|
|
|
public function getOutstandingAttribute()
|
|
{
|
|
return $this->total_amount - $this->paid_amount;
|
|
}
|
|
}
|