20. 입출고이력 까지
This commit is contained in:
parent
786e6e283e
commit
c6edbf93dd
@ -9,7 +9,18 @@ use Illuminate\Http\Request;
|
||||
|
||||
class StockLogController extends Controller
|
||||
{
|
||||
public function Input(Request $request, $id)
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = (int) $request->input('per_page', 20); // 페이지에 표시 할 목록의 수
|
||||
$title = '입출고 이력';
|
||||
// Eager Loading 으로 N + 1 문제 해결
|
||||
$logs = StockLog::with(['product:id,name,sku'])
|
||||
->latestFirst()
|
||||
->paginate($perPage);
|
||||
return view('stock_log.list',compact('title','logs'));
|
||||
}
|
||||
|
||||
public function input(Request $request, $id)
|
||||
{
|
||||
// queryString action 의 default value 는 in 으로 한다.
|
||||
$action = $request->query('action','in');
|
||||
|
||||
@ -8,7 +8,20 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
class StockLog extends Model
|
||||
{
|
||||
protected $table = 'stock_logs';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'change_amount' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function scopeLatestFirst($qurey)
|
||||
{
|
||||
return $qurey->orderByDesc('created_at')->orderByDesc('id');
|
||||
}
|
||||
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">입출고 이력</a>
|
||||
<a class="nav-link" href="{{ route('stock.list') }}">입출고 이력</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
|
||||
40
resources/views/stock_log/list.blade.php
Normal file
40
resources/views/stock_log/list.blade.php
Normal file
@ -0,0 +1,40 @@
|
||||
@extends('layout')
|
||||
|
||||
@section('main')
|
||||
<div class="py-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h2 class="mb-0">📋 입출고 이력</h2>
|
||||
<a href="product_form.php" class="btn btn-primary">+ 상품 추가</a>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>일시</th>
|
||||
<th>상품(SKU)</th>
|
||||
<th>입출고</th>
|
||||
<th>수량</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($logs as $log)
|
||||
<tr>
|
||||
<td>{{ $log->created_at->format('Y-m-d H:i') }}</td>
|
||||
<td>{{ ($log->product?->name ?? '삭제된 상품') }} ({{ $log->product?->sku ?? '-'}})</td>
|
||||
<td>{{ $log->change_type }}</td>
|
||||
<td>{{ $log->change_amount }} 개</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-center mt-4">
|
||||
{{ $logs->links() }}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@ -51,4 +51,6 @@ Route::get('/stock/input/{id}', [StockLogController::class, 'input'])
|
||||
Route::post('/stock/input/{id}', [StockLogController::class, 'store'])
|
||||
->name('stock.store');
|
||||
|
||||
|
||||
// 입출고 이력
|
||||
Route::get('/stock}', [StockLogController::class, 'index'])
|
||||
->name('stock.list');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user