- 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.
83 lines
2.6 KiB
PHP
83 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Master\RawMaterial;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Master\RawMaterial\RawMaterialRequest;
|
|
use App\Http\Requests\PaginatedRequest;
|
|
use App\Models\RawMaterial;
|
|
use App\Services\Admin\Master\RawMaterial\RawMaterialService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class RawMaterialController extends Controller
|
|
{
|
|
public function __construct(
|
|
private RawMaterialService $service,
|
|
) {}
|
|
|
|
public function index(PaginatedRequest $request): Response
|
|
{
|
|
return Inertia::render('admin/master/raw-material/index', [
|
|
'rawMaterials' => $this->service->paginated(
|
|
...$request->validatedWithDefaults(),
|
|
filters: $request->only(['is_active', 'stock']),
|
|
),
|
|
'filters' => $request->only(['is_active', 'stock']),
|
|
]);
|
|
}
|
|
|
|
public function create(): Response
|
|
{
|
|
return Inertia::render('admin/master/raw-material/create');
|
|
}
|
|
|
|
public function store(RawMaterialRequest $request): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->store($request->validated()),
|
|
'Bahan baku berhasil ditambahkan.',
|
|
'admin.master.raw-materials.index',
|
|
'admin.master.raw-materials.create'
|
|
);
|
|
}
|
|
|
|
public function edit(RawMaterial $rawMaterial): Response
|
|
{
|
|
return Inertia::render('admin/master/raw-material/edit', [
|
|
'rawMaterial' => $this->service->getForEdit($rawMaterial),
|
|
]);
|
|
}
|
|
|
|
public function update(RawMaterialRequest $request, RawMaterial $rawMaterial): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->update($rawMaterial, $request->validated()),
|
|
'Bahan baku berhasil diperbarui.',
|
|
'admin.master.raw-materials.index',
|
|
'admin.master.raw-materials.edit',
|
|
['rawMaterial' => $rawMaterial]
|
|
);
|
|
}
|
|
|
|
public function destroy(RawMaterial $rawMaterial): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->destroy($rawMaterial),
|
|
'Bahan baku berhasil dihapus.',
|
|
'admin.master.raw-materials.index'
|
|
);
|
|
}
|
|
|
|
public function toggleStatus(RawMaterial $rawMaterial): RedirectResponse
|
|
{
|
|
$this->service->toggleStatus($rawMaterial);
|
|
$status = $rawMaterial->fresh()->is_active ? 'Aktif' : 'Non Aktif';
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => "Status bahan baku berhasil diubah menjadi {$status}."]);
|
|
|
|
return back();
|
|
}
|
|
}
|