-membuat relasi polimorfirk -membuat beberapa trait untuk kebutuhan crud -dan lainnya tentang implementasi fitur ini
77 lines
1.9 KiB
PHP
77 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Studio\Manage\Purchase;
|
|
|
|
use App\Livewire\Forms\Studio\Manage\PurchaseForm;
|
|
use App\Models\Bottle;
|
|
use App\Models\Outlet;
|
|
use App\Models\Perfume;
|
|
use App\Models\Product;
|
|
use App\Models\PurchaseItem;
|
|
use App\Traits\Purchase\WithAddItem;
|
|
use App\Traits\Purchase\WithDeleteItem;
|
|
use App\Traits\Purchase\WithUpdateItem;
|
|
use App\Traits\WithAuthorization;
|
|
use App\Traits\WithConfirmation;
|
|
use App\Traits\WithToast;
|
|
use App\Traits\WithUpdatedData;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Component;
|
|
|
|
#[Title('Tambah Belanja')]
|
|
class Create extends Component
|
|
{
|
|
use WithAddItem, WithAuthorization, WithConfirmation, WithDeleteItem, WithToast, WithUpdatedData, WithUpdateItem;
|
|
|
|
public PurchaseForm $form;
|
|
|
|
public array $outlets = [];
|
|
|
|
public array $perfumes = [];
|
|
|
|
public array $products = [];
|
|
|
|
public array $bottles = [];
|
|
|
|
public function mount()
|
|
{
|
|
$this->outlets = Outlet::pluck('name', 'id')->toArray();
|
|
|
|
$this->perfumes = Perfume::pluck('name', 'id')->toArray();
|
|
|
|
$this->products = Product::pluck('name', 'id')->toArray();
|
|
|
|
$this->bottles = Bottle::pluck('name', 'id')->toArray();
|
|
|
|
$this->form->cartItems = PurchaseItem::whereNull('purchase_id')->get();
|
|
|
|
$this->form->total = currency($this->form->cartItems->sum('total_price'), '');
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
if ($this->form->cartItems->isEmpty()) {
|
|
$this->toast('Keranjang tidak boleh kosong.', 'Gagal', 'danger');
|
|
|
|
return;
|
|
}
|
|
|
|
$this->canOrAbort('create purchase');
|
|
|
|
$this->form->store();
|
|
|
|
$this->dispatch('refreshDatatable');
|
|
|
|
$this->toast('Belanja berhasil ditambahkan.');
|
|
|
|
$this->redirectRoute('studio.manage.purchase.index', navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.studio.manage.purchase.form', [
|
|
'pageTitle' => 'Tambah Belanja',
|
|
]);
|
|
}
|
|
}
|