22. 통계 까지

This commit is contained in:
choibk 2025-12-07 13:20:38 +09:00
parent a26047d608
commit d895fc3226
4 changed files with 86 additions and 1 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\Request;
class statsController extends Controller
{
public function index()
{
$title = '통계';
// 총 상품 수량
$totalQuantity = Product::sum('quantity');
// 총 상품 종류
$productCount = Product::count();
// 수량이 10 미만인 상품 목록
$products = Product::where('quantity', '<', 10)->get();
return view ('stats.index', compact('title', 'totalQuantity', 'productCount', 'products'));
}
}

View File

@ -18,7 +18,7 @@
</li>
<li class="nav-item">
<a class="nav-link" href="#">통계</a>
<a class="nav-link" href="{{ route('stats') }}">통계</a>
</li>
{{-- 로그아웃 버튼 --}}

View File

@ -0,0 +1,57 @@
@extends('layout')
@section('main')
<div class="py-4">
<h2 class="mb-4 text-center">📊 재고 통계</h2>
<div class="row mb-4">
<div class="col-md-6 mb-3">
<div class="card shadow-sm border-start border-4 border-primary">
<div class="card-body">
<h5 class="card-title"> 상품 수량</h5>
<p class="display-5 fw-bold text-primary mb-0">{{ $totalQuantity }}</p>
</div>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="card shadow-sm border-start border-4 border-primary">
<div class="card-body">
<h5 class="card-title"> 상품 종류</h5>
<p class="display-5 fw-bold text-primary mb-0">{{ $productCount }}</p>
</div>
</div>
</div>
</div>
<div class="card shadow-sm">
<div class="card-header bg-white">
<h5 class="mb-0">⚠️ 재고 부족 상품 (10 미만)</h5>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th>상품명</th>
<th>SKU</th>
<th>수량</th>
</tr>
</thead>
<tbody>
@forelse($products as $product)
<tr>
<td>{{ $product->name }}</td>
<td>{{ $product->sku }}</td>
<td><span class="badge bg-warning text-dark">{{ $product->quantity}}</span></td>
</tr>
@empty
<tr>
<td colspan="3" class="text-center text-muted"> 모든 상품의 재고가 충분합니다. </td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
@endsection

View File

@ -2,6 +2,7 @@
use App\Http\Controllers\LoginController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\statsController;
use App\Http\Controllers\StockLogController;
use App\Http\Middleware\Authenticate;
use Illuminate\Support\Facades\Route;
@ -54,3 +55,7 @@ Route::post('/stock/input/{id}', [StockLogController::class, 'store'])
// 입출고 이력
Route::get('/stock}', [StockLogController::class, 'index'])
->name('stock.list');
// 통계
Route::get('/stats}', [statsController::class, 'index'])
->name('stats');