- Added activity logging functionality to multiple models including CuttingMaterial, Employee, Invoice, and more. - Implemented `getActivitylogOptions` method to configure logging behavior. - Updated composer dependencies to include `spatie/laravel-activitylog`. - Created a custom Activity model extending Spatie's Activity model. - Added configuration file for activity logging settings.
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\ProductStockQuality;
|
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Spatie\Activitylog\Support\LogOptions;
|
|
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
|
|
|
#[Appends(['stock_quality_label'])]
|
|
#[Guarded(['id'])]
|
|
class StokOpnameItem extends Model
|
|
{
|
|
use HasFactory, LogsActivity;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'stock_quality' => ProductStockQuality::class,
|
|
'system_stock' => 'integer',
|
|
'physical_stock' => 'integer',
|
|
'difference' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logAll()
|
|
->logOnlyDirty()
|
|
->dontLogEmptyChanges();
|
|
}
|
|
|
|
protected function stockQualityLabel(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->stock_quality->label(),
|
|
);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function good(Builder $query): void
|
|
{
|
|
$query->where('stock_quality', ProductStockQuality::GOOD);
|
|
}
|
|
|
|
#[Scope]
|
|
protected function reject(Builder $query): void
|
|
{
|
|
$query->where('stock_quality', ProductStockQuality::REJECT);
|
|
}
|
|
|
|
public function productVariant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ProductVariant::class);
|
|
}
|
|
|
|
public function stokOpname(): BelongsTo
|
|
{
|
|
return $this->belongsTo(StokOpname::class);
|
|
}
|
|
}
|