File manager - Edit - /var/www/payraty/inventory_main/app/Models/Purchase.php
Back
<?php namespace App\Models; use App\Traits\CreatedByRelationship; use App\Traits\CreatedUpdatedBy; use App\Traits\UpdatedByRelationship; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Scopes\OrganisationScope; use Spatie\Activitylog\Traits\LogsActivity; use Spatie\Activitylog\LogOptions; /** * Purchase */ class Purchase extends Model { use HasFactory, CreatedByRelationship, UpdatedByRelationship, CreatedUpdatedBy; use LogsActivity; protected $appends = ['approval_procurement', 'approval_managing_director','create_user']; public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logAll() ->useLogName('Purchase') ->logOnlyDirty() ->setDescriptionForEvent(fn(string $eventName) => "Purchase record ID #{$this->id} has been {$eventName}") ->dontSubmitEmptyLogs(); } protected static function booted() { static::addGlobalScope(new OrganisationScope); // Automatically set the organisation_id before creating the model static::creating(function ($model) { if (auth()->check()) { $model->organisation_id = auth()->user()->organisation_id; } }); } /** * fillable * * @var array */ protected $fillable = [ 'organisation_id', 'purchase_number', 'supplier_id', 'warehouse_id', 'company', 'date', 'notes', 'total', 'status', 'created_by', 'updated_by', 'address_line_1', 'address_line_2', 'country', 'state', 'city', 'zipcode', 'received', 'cancel_date', 'cancel_by', 'cancel_note', 'short_address', 'approval_level1', 'approval_level2', 'approval_level1_by', 'approval_level2_by', 'approval_level1_by_date', 'rejection_note', 'approval_level2_by_date', ]; public const STATUS_REQUESTED = 'requested'; public const STATUS_CANCEL = 'cancel'; public const STATUS_CONFIRMED = 'confirmed'; /** * supplier * * @return void */ public function supplier() { return $this->belongsTo(Supplier::class); } public function getApprovalProcurementAttribute() { return User::find($this->approval_level1_by); } public function getCreateUserAttribute() { return User::find($this->created_by); } public function getApprovalManagingDirectorAttribute() { return User::find($this->approval_level2_by); } /** * warehouse * * @return void */ public function warehouse() { return $this->belongsTo(Warehouse::class); } /** * purchaseItems * * @return void */ public function purchaseItems() { return $this->hasMany(PurchaseItem::class); } /** * systemCountry * * @return void */ public function systemCountry() { return $this->belongsTo(SystemCountry::class, 'country'); } /** * systemState * * @return void */ public function systemState() { return $this->belongsTo(SystemState::class, 'state'); } /** * systemCity * * @return void */ public function systemCity() { return $this->belongsTo(SystemCity::class, 'city'); } /** * purchaseReceives * * @return void */ public function purchaseReceives() { return $this->hasMany(PurchaseReceive::class); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings