- 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.
65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
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(['formatted_amount', 'formatted_paid_at'])]
|
|
#[Guarded(['id'])]
|
|
class EmployeeAdvancePayment extends Model
|
|
{
|
|
use HasFactory, LogsActivity;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'amount' => 'integer',
|
|
'paid_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logAll()
|
|
->logOnlyDirty()
|
|
->dontLogEmptyChanges();
|
|
}
|
|
|
|
protected function formattedAmount(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => 'Rp '.number_format($this->amount, 0, ',', '.'),
|
|
);
|
|
}
|
|
|
|
protected function formattedPaidAt(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->paid_at?->translatedFormat('l, d F Y H:i'),
|
|
);
|
|
}
|
|
|
|
public function employeeAdvance(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EmployeeAdvance::class);
|
|
}
|
|
|
|
public function paidBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'paid_by_id');
|
|
}
|
|
|
|
public function cashTransaction(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CashTransaction::class);
|
|
}
|
|
}
|