sourceOutlets = auth()->user()->outlets->pluck('name', 'id')->toArray(); $this->destinationOutlets = Outlet::orderBy('name')->pluck('name', 'id')->toArray(); $this->stockTransferItems = $this->loadStockTransferItems(); } public function updated($property, $value): void { if ($property === 'form.source_outlet_id' || $property === 'form.destination_outlet_id') { $this->loadCreateItems(); } } private function loadCreateItems(): void { $this->reset(['perfumes', 'products', 'bottles']); $this->form->reset( 'perfume_id', 'quantity_perfume', 'product_id', 'quantity_product', 'bottle_id', 'quantity_bottle' ); if (! $this->form->source_outlet_id || ! $this->form->destination_outlet_id) { return; } $sourceOutlet = Outlet::find($this->form->source_outlet_id); if (! $sourceOutlet) { return; } $this->perfumes = $sourceOutlet->perfumes() ->wherePivot('stock', '>', 0) ->orderBy('name') ->get() ->pluck('name', 'id') ->toArray(); $this->products = $sourceOutlet->products() ->wherePivot('stock', '>', 0) ->orderBy('name') ->get() ->pluck('name', 'id') ->toArray(); $this->bottles = $sourceOutlet->bottles() ->wherePivot('stock', '>', 0) ->orderBy('name') ->get() ->pluck('name', 'id') ->toArray(); } public function save(): void { $this->canOrAbort('create stock transfer'); if ($this->stockTransferItems->isEmpty()) { $this->toast('Keranjang transfer stok tidak boleh kosong.', 'Gagal', 'danger'); return; } try { $this->form->store(); } catch (ValidationException $e) { throw $e; } catch (\Exception $e) { $this->toast($e->getMessage(), 'Gagal', 'danger'); return; } $this->redirectRoute('studio.stock.stock_transfer.index', [ 'notification' => 'Transfer stok berhasil diproses.', ], navigate: true); } public function render(): View { return view('livewire.studio.stock.stock-transfer.form', [ 'pageTitle' => 'Tambah Transfer Stok Antar Outlet', ]); } }