diff --git a/backend/models/stock.go b/backend/models/stock.go index e5fcc67..e5551bf 100644 --- a/backend/models/stock.go +++ b/backend/models/stock.go @@ -5,13 +5,13 @@ import ( ) type StockMovement struct { - ID uint `json:"id" gorm:"primaryKey"` - ItemID uint `json:"item_id"` - Item Item `json:"item" gorm:"foreignKey:ItemID"` - Type string `json:"type"` - Quantity float64 `json:"quantity"` - Reason string `json:"reason" gorm:"not null"` - OrderID *uint `json:"order_id"` - Comment string `json:"comment"` - CreatedAt time.Time + ID uint `json:"id" gorm:"primaryKey"` + ItemID uint `json:"item_id"` + Item Item `json:"item" gorm:"foreignKey:ItemID"` + Type string `json:"type"` + Quantity float64 `json:"quantity"` + Reason string `json:"reason" gorm:"not null"` + OrderID *uint `json:"order_id"` + Comment string `json:"comment"` + CreatedAt time.Time `json:"created_at"` } diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index 9743829..fbf987d 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -65,4 +65,8 @@ export const updateOrderStatus = (id, data) => export const registerAdmin = (data) => axios.post(`${API_URL}/admin/register`, data); -export const stockIn = (data) => axios.post(`${API_URL}/admin/stock/in`, data) +export const stockIn = (data) => axios.post(`${API_URL}/admin/stock/in`, data); +export const stockOut = (data) => + axios.post(`${API_URL}/admin/stock/out`, data); +export const getStockMovements = () => + axios.get(`${API_URL}/admin/stock/movements`); diff --git a/frontend/src/components/AdminStock.jsx b/frontend/src/components/AdminStock.jsx new file mode 100644 index 0000000..780689a --- /dev/null +++ b/frontend/src/components/AdminStock.jsx @@ -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
Загрузка...
; + + return ( +Движений нет
+ ) : ( +| Дата | +Товар | +Тип | +Количество | +Причина | +Комментарий | +
|---|---|---|---|---|---|
| + {new Date(m.created_at).toLocaleDateString("ru-RU")} + | +{m.item?.name} | ++ + {m.type === "in" ? "Приход" : "Уход"} + + | ++ {m.quantity} {m.item?.unit} + | ++ {REASON_LABELS[m.reason] || m.reason} + | ++ {m.comment || "-"} + | +
Раздел сотрудников — в разработке
)}