45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Product;
|
|
use App\Models\StockLog;
|
|
use Illuminate\Http\Request;
|
|
|
|
class StockLogController extends Controller
|
|
{
|
|
public function Input(Request $request, $id)
|
|
{
|
|
// queryString action 의 default value 는 in 으로 한다.
|
|
$action = $request->query('action','in');
|
|
if(!in_array($action, ['in','out']))
|
|
{
|
|
abort(400, '잘못된 action 값 입니다.');
|
|
}
|
|
$title = ($action == 'in') ? '입고 등록' : '출고 등록';
|
|
// Product 조회 ( or 404)
|
|
$product = Product::findOrFail($id);
|
|
// Blade 뷰에 Product 전달
|
|
return view('stock.input', compact('product', 'title', 'action'));
|
|
}
|
|
|
|
public function Store(Request $request, $id)
|
|
{
|
|
$action = $request->query('action', 'in');
|
|
if(!in_array($action, ['in','out']))
|
|
{
|
|
abort(400, '잘못된 action 값 입니다.');
|
|
}
|
|
$product = Product::findOrFail($id);
|
|
$validated = $request->validate([
|
|
'amount' => ['required', 'integer', 'min:1']
|
|
]);
|
|
StockLog::create([
|
|
'product_id' => $product->id,
|
|
'change_type' => $action,
|
|
'change_amount' => $validated['amount']
|
|
]);
|
|
return redirect()->route('product')->with('success', $action == 'in' ? '입고처리 완료' : '출고처리 완료');
|
|
}
|
|
}
|