- Updated CustomerService to simplify getAll method. - Refactored ProductService to utilize HasRoleChecks trait and improved role verification logic. - Enhanced ProductVariantService with new methods for fetching data for restocking and transactions. - Cleaned up RawMaterialService by removing unused methods and improving data retrieval. - Adjusted SupplierService to streamline getAll method. - Refactored RoleService to use Spatie's Role model and improved role filtering logic. - Updated NotificationService to handle role labels more effectively. - Improved StockMutationService by removing redundant paginated method. - Cleaned up various frontend components to directly accept necessary props instead of nested data objects. - Updated tests to reflect changes in service method names and ensure proper notification handling.
118 lines
3.6 KiB
PHP
118 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Master\Product;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Master\Product\ProductRequest;
|
|
use App\Http\Requests\PaginatedRequest;
|
|
use App\Models\Product;
|
|
use App\Services\Admin\Master\CategoryService;
|
|
use App\Services\Admin\Master\Product\ProductService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
public function __construct(
|
|
private ProductService $service,
|
|
private CategoryService $categoryService,
|
|
) {}
|
|
|
|
public function index(PaginatedRequest $request): Response
|
|
{
|
|
return Inertia::render('admin/master/product/index', [
|
|
'products' => $this->service->paginated(
|
|
...$request->validatedWithDefaults(),
|
|
filters: $request->only(['status', 'stock', 'category', 'name']),
|
|
),
|
|
'categories' => $this->categoryService->getAll(),
|
|
'productNames' => $this->service->getNames(),
|
|
'filters' => $request->only(['status', 'stock', 'category', 'name']),
|
|
]);
|
|
}
|
|
|
|
public function create(): Response
|
|
{
|
|
return Inertia::render('admin/master/product/create', [
|
|
'categories' => $this->categoryService->getAll(),
|
|
]);
|
|
}
|
|
|
|
public function store(ProductRequest $request): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->create($request->validated()),
|
|
'Produk berhasil ditambahkan.',
|
|
'admin.master.products.index',
|
|
'admin.master.products.create'
|
|
);
|
|
}
|
|
|
|
public function edit(Product $product): Response
|
|
{
|
|
return Inertia::render('admin/master/product/edit', [
|
|
'product' => $this->service->getForEdit($product),
|
|
'categories' => $this->categoryService->getAll(),
|
|
]);
|
|
}
|
|
|
|
public function update(ProductRequest $request, Product $product): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->update($product, $request->validated()),
|
|
'Produk berhasil diperbarui.',
|
|
'admin.master.products.index',
|
|
'admin.master.products.edit',
|
|
['product' => $product]
|
|
);
|
|
}
|
|
|
|
public function destroy(Product $product): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->delete($product),
|
|
'Produk berhasil dihapus.',
|
|
'admin.master.products.index'
|
|
);
|
|
}
|
|
|
|
public function toggleStatus(Product $product): RedirectResponse
|
|
{
|
|
$this->service->toggleStatus($product);
|
|
$status = $product->fresh()->status;
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => "Status produk berhasil diubah menjadi {$status->label()}."]);
|
|
|
|
return back();
|
|
}
|
|
|
|
public function approve(Product $product): RedirectResponse
|
|
{
|
|
$this->service->approve($product);
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil disetujui.']);
|
|
|
|
return back();
|
|
}
|
|
|
|
public function reject(Product $product): RedirectResponse
|
|
{
|
|
$reason = request()->input('rejection_reason', '');
|
|
$this->service->reject($product, $reason);
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil ditolak.']);
|
|
|
|
return back();
|
|
}
|
|
|
|
public function resubmit(Product $product): RedirectResponse
|
|
{
|
|
$this->service->resubmit($product);
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => 'Produk berhasil diajukan ulang.']);
|
|
|
|
return back();
|
|
}
|
|
}
|