69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Studio\Master\Warehouse\Audit;
|
|
|
|
use App\Enums\AuditStockStatus;
|
|
use App\Models\Perfume as PerfumeModel;
|
|
use App\Models\Warehouse;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Component;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
|
|
#[Title('Audit')]
|
|
class Perfume extends Component
|
|
{
|
|
public string $label;
|
|
|
|
public Collection $activityLogs;
|
|
|
|
public function mount(Warehouse $warehouse, PerfumeModel $perfume): void
|
|
{
|
|
$this->label = $perfume->name.' di '.$warehouse->name;
|
|
|
|
$this->activityLogs = Activity::where('subject_type', get_class($perfume))
|
|
->where('subject_id', $perfume->id)
|
|
->where('properties->warehouse_id', $warehouse->id)
|
|
->latest()
|
|
->get()
|
|
->map(function (Activity $activity) {
|
|
$status = match ($activity->event) {
|
|
'increase' => AuditStockStatus::INCREASED,
|
|
'decrease' => AuditStockStatus::DECREASED,
|
|
'created' => AuditStockStatus::INCREASED,
|
|
'updated' => AuditStockStatus::UPDATED,
|
|
'deleted' => AuditStockStatus::DELETED,
|
|
default => AuditStockStatus::tryFrom($activity->event),
|
|
};
|
|
|
|
$color = $status?->color() ?? 'gray';
|
|
$label = $status?->label() ?? ucfirst($activity->event);
|
|
|
|
$classes = match ($color) {
|
|
'emerald' => 'bg-emerald-200 text-emerald-800 dark:bg-emerald-800 dark:text-emerald-200',
|
|
'orange' => 'bg-orange-200 text-orange-800 dark:bg-orange-800 dark:text-orange-200',
|
|
'yellow' => 'bg-yellow-200 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-200',
|
|
'red' => 'bg-red-200 text-red-800 dark:bg-red-800 dark:text-red-200',
|
|
default => 'bg-gray-200 text-gray-800 dark:bg-gray-800 dark:text-gray-200',
|
|
};
|
|
|
|
$activity->event = [
|
|
'label' => $label,
|
|
'color' => $color,
|
|
'classes' => $classes,
|
|
];
|
|
|
|
return $activity;
|
|
});
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('components.sections.ui.audit', [
|
|
'pageTitle' => 'Audit '.$this->label,
|
|
'backRoute' => route('studio.master.warehouse.show', ['warehouse' => request()->route('warehouse')]),
|
|
]);
|
|
}
|
|
}
|