feat: add front page stock movements
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user