58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
use App\Enums\RecordStatusEnum;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class Invoice extends BaseModel
|
|
{
|
|
public $timestamps = false;
|
|
use HasFactory;
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'invoices';
|
|
|
|
protected $fillable = ['invoice_code', 'sample_id', 'total', 'discount','discount_type', 'gross_total', 'deposit', 'bank_deposit', 'balance',
|
|
'pay_type', 'invoice_date', 'invoice_note', 'bank_name', 'transaction_ref', 'lab_id', 'is_hide_discount', 'first_paid_date','exchange_rate', BaseModel::CREATED_AT_FIELD, BaseModel::CREATED_BY_FIELD,
|
|
BaseModel::UPDATED_AT_FIELD, BaseModel::UPDATED_BY_FIELD, BaseModel::RECORD_STATUS_FIELD
|
|
];
|
|
|
|
protected $hidden = [BaseModel::CREATED_AT_FIELD, BaseModel::CREATED_BY_FIELD, BaseModel::UPDATED_AT_FIELD, BaseModel::UPDATED_BY_FIELD, BaseModel::RECORD_STATUS_FIELD];
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
}
|
|
|
|
public function lab(){
|
|
return $this->belongsTo(Laboratory::class, 'lab_id','id');
|
|
}
|
|
|
|
public function sample(){
|
|
return $this->belongsTo(Sample::class, 'sample_id','id');
|
|
}
|
|
|
|
public function invoiceDetail(){
|
|
return $this->hasMany(InvoiceDetail::class, 'invoice_id', 'id')->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE);
|
|
}
|
|
|
|
public function repayments(){
|
|
return $this->hasMany(Repayment::class, 'invoice_id', 'id')->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE);
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function modifier()
|
|
{
|
|
return $this->belongsTo(User::class, 'updated_by');
|
|
}
|
|
|
|
|
|
}
|