parfum/app/Livewire/Studio/Stock/Purchase/Create.php
Yoga Pangestu 293dd7d1fd refactor: restructure stock management components and update routes
- Removed legacy stock management components including PurchaseForm, RestockForm, StockOpnameForm, and StockTransferForm.
- Updated routes to reflect new structure under 'studio.stock' namespace for better organization.
- Adjusted view files for stock management to align with the new routing and component structure.
- Modified action routes in the ViewServiceProvider to ensure proper access control and navigation.
- Cleaned up related test files to remove references to deleted components.
2026-01-09 21:57:06 +07:00

79 lines
2.2 KiB
PHP

<?php
namespace App\Livewire\Studio\Stock\Purchase;
use App\Livewire\Forms\Studio\Stock\PurchaseForm;
use App\Models\Bottle;
use App\Models\Perfume;
use App\Models\Product;
use App\Models\Warehouse as WarehouseModel;
use App\Traits\Authorization\WithAuthorization;
use App\Traits\Components\WithConfirmation;
use App\Traits\Components\WithToast;
use App\Traits\Purchase\WithAddItem;
use App\Traits\Purchase\WithCalculateTotal;
use App\Traits\Purchase\WithDeleteItem;
use App\Traits\Purchase\WithPurchaseItems;
use App\Traits\Purchase\WithUpdateItem;
use App\Traits\Utilities\WithUpdatedData;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Title('Tambah Belanja')]
class Create extends Component
{
use WithAddItem, WithAuthorization, WithCalculateTotal, WithConfirmation, WithDeleteItem, WithPurchaseItems, WithToast, WithUpdatedData, WithUpdateItem;
public PurchaseForm $form;
public array $warehouses = [];
public array $perfumes = [];
public array $products = [];
public array $bottles = [];
public $purchaseItems;
public function mount(): void
{
$this->warehouses = WarehouseModel::orderBy('name')->pluck('name', 'id')->toArray();
$this->perfumes = Perfume::orderBy('name')->pluck('name', 'id')->toArray();
$this->bottles = Bottle::orderBy('name')->pluck('name', 'id')->toArray();
$this->products = Product::orderBy('name')->pluck('name', 'id')->toArray();
$this->purchaseItems = $this->loadPurchaseItems();
$this->form->total = $this->getTotal();
}
public function save(): void
{
$this->canOrAbort('create purchase');
if ($this->purchaseItems->isEmpty()) {
$this->toast('Keranjang tidak boleh kosong.', 'Gagal', 'danger');
return;
}
$this->form->store();
$this->redirectRoute('studio.stock.purchase.index', [
'notification' => 'Belanja berhasil ditambahkan.',
], navigate: true);
}
public function render(): View
{
return view('livewire.studio.stock.purchase.form', [
'pageTitle' => 'Tambah Belanja',
]);
}
}