parfum/app/Livewire/Studio/Catalog/Bottle/Audit.php
2025-11-01 16:40:17 +07:00

56 lines
1.7 KiB
PHP

<?php
namespace App\Livewire\Studio\Catalog\Bottle;
use App\Enums\AuditStockStatus;
use App\Models\Bottle;
use App\Models\Outlet;
use Livewire\Attributes\Title;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;
#[Title('Audit')]
class Audit extends Component
{
public string $label;
public array $activityLogs = [];
public function mount(Outlet $outlet, Bottle $bottle)
{
$this->label = $bottle->name;
$this->activityLogs = Activity::where('subject_type', get_class($bottle))
->where('subject_id', $bottle->id)
->where('properties->outlet_id', $outlet->id)
->latest()
->get()
->map(function (Activity $activity) use ($outlet) {
return [
'log_name' => $activity->log_name,
'created_at' => $activity->created_at,
'outlet' => $outlet->name,
'event' => [
'label' => $activity->event,
'color' => AuditStockStatus::from($activity->event)->color(),
],
'new_stock' => currency($activity->properties['new_stock']),
'previous_stock' => currency($activity->properties['previous_stock']),
'quantity_change' => currency($activity->properties['quantity_change']),
'user' => $activity->causer?->profile?->full_name,
'description' => $activity->description,
];
})
->toArray();
}
public function render()
{
return view('components.partials.audit', [
'pageTitle' => 'Audit '.$this->label,
'module' => 'bottle',
]);
}
}