- Introduced StockMutation model and service to handle stock changes. - Created migration for stock_mutations table. - Implemented stock mutation recording in various services (CuttingService, OrderService, PurchaseService, RestockService, RetailStockService). - Added StockHistoryController to manage stock history views. - Developed frontend components for displaying stock history and actions. - Updated routes to include stock history access with appropriate permissions. - Enhanced ProductVariant and RawMaterialPrice models to support stock mutations. - Added RowHistoryAction button for accessing stock history in product and raw material tables.
49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Manage\Stock;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ProductVariant;
|
|
use App\Models\RawMaterialPrice;
|
|
use App\Models\StockMutation;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class StockHistoryController extends Controller
|
|
{
|
|
public function __invoke(Request $request): Response
|
|
{
|
|
$stockableType = $request->string('stockable_type')->toString();
|
|
$stockableId = (int) $request->string('stockable_id')->toString();
|
|
|
|
$modelClass = match ($stockableType) {
|
|
'product-variant' => ProductVariant::class,
|
|
'raw-material-price' => RawMaterialPrice::class,
|
|
default => abort(404, 'Tipe stok tidak valid.'),
|
|
};
|
|
|
|
$stockable = $modelClass::with(
|
|
$stockableType === 'product-variant'
|
|
? ['product', 'stockMutations.user.profile', 'stockMutations.source']
|
|
: ['rawMaterial', 'stockMutations.user.profile', 'stockMutations.source']
|
|
)->findOrFail($stockableId);
|
|
|
|
$mutations = $stockable->stockMutations()
|
|
->with(['user.profile', 'source'])
|
|
->latest()
|
|
->paginate(50);
|
|
|
|
$title = $stockableType === 'product-variant'
|
|
? "{$stockable->product?->name} - {$stockable->name}"
|
|
: "{$stockable->rawMaterial?->name} - {$stockable->variant}";
|
|
|
|
return Inertia::render('admin/manage/stock/History', [
|
|
'title' => $title,
|
|
'stockableType' => $stockableType,
|
|
'stockableId' => $stockable->id,
|
|
'mutations' => $mutations,
|
|
]);
|
|
}
|
|
}
|