'required', 'note' => 'nullable', ]; } public function validationAttributes(): array { return [ 'newStock' => 'stok baru', 'note' => 'keterangan', ]; } public function setAdjustment(string $itemId, string $type, string $name, int $stock): void { $this->itemId = $itemId; $this->type = $type; $this->name = $name; $this->oldStock = formatCurrencyNumber($stock); $this->newStock = formatCurrencyNumber($stock); $this->note = null; } public function save(Warehouse $warehouse): void { $this->validate(); $newStockValue = (int) str_replace(['.', ','], '', (string) $this->newStock); $oldStockValue = (int) str_replace(['.', ','], '', (string) $this->oldStock); $typeId = explode('_', $this->itemId); $type = $typeId[0]; $id = $typeId[1]; $relation = match ($type) { 'perfume' => 'perfumes', 'product' => 'products', 'bottle' => 'bottles', default => null, }; if (! $relation) { return; } $item = $warehouse->{$relation}()->find($id); if (! $item) { return; } $warehouse->{$relation}()->updateExistingPivot($id, [ 'stock' => $newStockValue, ]); // Log the activity StockActivityLogService::logWarehouse( logName: 'adjustment', event: 'update', description: "Penyesuaian manual untuk {$this->name}: berubah dari {$oldStockValue} menjadi {$newStockValue}. Catatan: ".($this->note ?? '-'), performedOn: $item, warehouse: $warehouse, quantityChange: $newStockValue - $oldStockValue, previousStock: $oldStockValue, newStock: $newStockValue, extraProperties: [ 'note' => $this->note, 'adjustment_type' => 'manual', ] ); } }