IMMREX7
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class Invoice extends Model {
protected $primaryKey = 'idInvoice';
protected $table = 'invoices';
protected $fillable = ['idSchool','customerType' ,'idFinancialYear', 'idCustomer','invoiceNo','invoiceDate','reference','salesperson',
'subTotal','discountTotal','adjustment','amountPayable','notes'];
public function details() {
return $this->hasMany(InvoiceDetail::class, 'idInvoice', 'idInvoice');
}
public function setInvoiceDateAttribute($date) {
if (strlen($date) > 0)
$this->attributes['invoiceDate'] = Carbon::createFromFormat('d-m-Y', $date);
else
$this->attributes['invoiceDate'] = null;
}
public function getInvoiceDateAttribute($date) {
if ($date && $date != '0000-00-00' && $date != 'null')
return Carbon::parse($date)->format('d-m-Y');
return '';
}
public function employee() {
return $this->belongsTo(Employee::class, 'idCustomer', 'idEmployee');
}
public function student() {
return $this->belongsTo(AdmEntry::class, 'idCustomer', 'idStudent');
}
public function customer() {
return $this->belongsTo(Customer::class, 'idCustomer', 'idCustomer');
}
}
Copyright © 2021 -