feat: add front page stock movements

This commit is contained in:
2026-06-26 17:53:21 +03:00
parent 1423451713
commit e55b421ed7
4 changed files with 102 additions and 11 deletions
+84
View File
@@ -0,0 +1,84 @@
import { useState, useEffect } from "react";
import { getStockMovements } from "../api/index";
const REASON_LABELS = {
purchase: "Закупка",
order: "Продажа",
writeoff: "Списание",
correction: "Корректировка",
};
export default function AdminStock() {
const [movements, setMovements] = useState([]);
const [loading, setLoading] = useState(true);
const loadMovements = () => {
getStockMovements()
.then((res) => {
setMovements(res.data);
})
.catch(() => { })
.finally(() => setLoading(false));
};
useEffect(() => {
loadMovements();
}, []);
if (loading) return <p className="text-white">Загрузка...</p>;
return (
<div>
<h2 className="text-xl font-medium text-white md-4">История движения</h2>
{movements.length === 0 ? (
<p className="text-white">Движений нет</p>
) : (
<div className="overflow-x-auto">
<table className="w-full text-sm text-left">
<thead className="text-white/50 uppercase text-xs border-b border-white/10">
<tr>
<th className="py-3 pr-4">Дата</th>
<th className="py-3 pr-4">Товар</th>
<th className="py-3 pr-4">Тип</th>
<th className="py-3 pr-4">Количество</th>
<th className="py-3 pr-4">Причина</th>
<th className="py-3 pr-4">Комментарий</th>
</tr>
</thead>
<tbody>
{movements.map((m) => (
<tr
className="border-b border-white/5 hover:bg-white/5"
key={m.id}
>
<td className="py-3 pr-4 text-whtie/70 whitespace-nowrap">
{new Date(m.created_at).toLocaleDateString("ru-RU")}
</td>
<td className="py-3 pr-4 text-white">{m.item?.name}</td>
<td className="py-3 pr-4">
<span
className={
m.type === "in" ? "text-green-400" : "text-red-400"
}
>
{m.type === "in" ? "Приход" : "Уход"}
</span>
</td>
<td className="py-3 pr-4 text-white">
{m.quantity} {m.item?.unit}
</td>
<td className="py-3 pr-4 text-white/70">
{REASON_LABELS[m.reason] || m.reason}
</td>
<td className="py-3 pr-4 text-white/50">
{m.comment || "-"}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
);
}