IMMREX7
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class PurchaseOrder extends Model {
protected $primaryKey = 'idPurchaseOrder';
protected $table = 'purchase_orders';
protected $fillable = ['idSchool', 'idFinancialYear', 'idSupplier', 'deliveryAddress', 'poNo', 'purchaseDate', 'reference',
'purchasePreference', 'subTotal', 'discountTotal', 'adjustment', 'totalAmount', 'termConditions', 'notes'];
public function details() {
return $this->hasMany(PurchaseOrderDetail::class, 'idPurchaseOrder', 'idPurchaseOrder');
}
public function supplier() {
return $this->belongsTo(Supplier::class, 'idSupplier', 'idSupplier');
}
public function setPurchaseDateAttribute($date) {
if (strlen($date) > 0)
$this->attributes['purchaseDate'] = Carbon::createFromFormat('d-m-Y', $date);
else
$this->attributes['purchaseDate'] = null;
}
public function getPurchaseDateAttribute($date) {
if ($date && $date != '0000-00-00' && $date != 'null')
return Carbon::parse($date)->format('d-m-Y');
return '';
}
}
Copyright © 2021 -