umwd-components 0.1.824 → 0.1.826
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node_modules/color-string/index.js +1 -1
- package/dist/cjs/node_modules/crypto-js/index.js +1 -1
- package/dist/cjs/src/components/e-commerce/products/EditReturnStockForm.js +7 -0
- package/dist/cjs/src/data/loaders/e-commerce/getSingleReturnStock.js +7 -0
- package/dist/cjs/src/index.js +1 -1
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/src/components/e-commerce/products/EditReturnStockForm.js +93 -0
- package/dist/esm/src/data/loaders/e-commerce/getSingleReturnStock.js +21 -0
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/types/components/e-commerce/products/EditReturnStockForm.d.ts +8 -0
- package/dist/esm/types/data/loaders/e-commerce/getSingleReturnStock.d.ts +2 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
9
|
+
import { useActionState, useEffect } from 'react';
|
|
10
|
+
import Paper from '@mui/material/Paper';
|
|
11
|
+
import Box from '@mui/material/Box';
|
|
12
|
+
import Stack from '@mui/material/Stack';
|
|
13
|
+
import Typography from '@mui/material/Typography';
|
|
14
|
+
import { updateProductAction } from '../../../data/actions/e-commerce/product/updateProductAction.js';
|
|
15
|
+
import Grid from '@mui/material/Grid';
|
|
16
|
+
import ReportsDisplay from '../../logistics/report/ReportsDisplay.js';
|
|
17
|
+
import ReportMakingComponent from '../../logistics/report/ReportMakingComponent.js';
|
|
18
|
+
import { useSnackbar } from '../../../context/common/SnackbarContext.js';
|
|
19
|
+
import Table from '@mui/material/Table';
|
|
20
|
+
import TableBody from '@mui/material/TableBody';
|
|
21
|
+
import TableCell from '@mui/material/TableCell';
|
|
22
|
+
import TableContainer from '@mui/material/TableContainer';
|
|
23
|
+
import TableFooter from '@mui/material/TableFooter';
|
|
24
|
+
import TableHead from '@mui/material/TableHead';
|
|
25
|
+
import TableRow from '@mui/material/TableRow';
|
|
26
|
+
import Tooltip from '@mui/material/Tooltip';
|
|
27
|
+
import Button from '@mui/material/Button';
|
|
28
|
+
import { AmountIndicator } from '../../common/AmountIndicator.js';
|
|
29
|
+
|
|
30
|
+
const INITIAL_STATE = {
|
|
31
|
+
zodErrors: null,
|
|
32
|
+
strapiErrors: null,
|
|
33
|
+
data: null,
|
|
34
|
+
message: null,
|
|
35
|
+
severity: null,
|
|
36
|
+
};
|
|
37
|
+
function EditReturnStockForm({ data, revalidateCallback, handleClose, sx, }) {
|
|
38
|
+
const { id, documentId, title, product_number, stock, iros, opoItems, reports, } = data;
|
|
39
|
+
const { handleAddMessage } = useSnackbar();
|
|
40
|
+
// Bind the documentId to the form action following form patterns
|
|
41
|
+
const boundAction = updateProductAction.bind(null, documentId);
|
|
42
|
+
const [formState, formAction] = useActionState(boundAction, INITIAL_STATE);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (formState?.message) {
|
|
45
|
+
handleAddMessage({
|
|
46
|
+
message: formState.message,
|
|
47
|
+
severity: formState.severity || "error",
|
|
48
|
+
});
|
|
49
|
+
if (formState.severity === "success") {
|
|
50
|
+
revalidateCallback && revalidateCallback();
|
|
51
|
+
handleClose && handleClose();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [formState?.message, handleAddMessage, revalidateCallback, handleClose]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (formState?.strapiErrors) {
|
|
57
|
+
handleAddMessage({
|
|
58
|
+
message: formState.strapiErrors.message || "Error updating stock",
|
|
59
|
+
severity: "error",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, [formState?.strapiErrors, handleAddMessage]);
|
|
63
|
+
return (jsxs(Box, { sx: [...(Array.isArray(sx) ? sx : [sx])], children: [jsxs(Grid, { container: true, spacing: 2, children: [jsx(Grid, { size: 12, children: jsx(Typography, { variant: "h6", children: title }) }), jsx(Grid, { size: 12, children: jsxs(TableContainer, { component: Paper, children: [jsx(Typography, { variant: "h6", sx: { pl: 2 }, children: "Incoming return orders" }), jsxs(Table, { size: "small", children: [jsx(TableHead, { children: jsxs(TableRow, { children: [jsx(TableCell, { children: "Number" }), jsx(TableCell, { children: "Order Date" }), jsx(TableCell, { children: "Line Item Number" }), jsx(TableCell, { children: "Ordered Quantity" }), jsx(TableCell, { children: "Received Quantity" }), jsx(TableCell, { children: "Registered Quantity" }), jsx(TableCell, { children: "Released Quantity" })] }) }), jsx(TableBody, { children: Array.isArray(iros) ? (iros.map((iro) => iro.items.map((item) => (jsxs(TableRow, { children: [jsx(TableCell, { children: iro.ipo_number }), jsx(TableCell, { children: iro.order_date }), jsx(TableCell, { children: item.line_item_number }), jsx(TableCell, { children: jsx(AmountIndicator, { value: item.ordered_quantity, maxValue: item.ordered_quantity, color: "primary" }) }), jsx(TableCell, { children: jsx(AmountIndicator, { value: item.received_quantity, maxValue: item.ordered_quantity, color: "primary" }) }), jsx(TableCell, { children: jsx(AmountIndicator, { value: item.registered_quantity, maxValue: item.ordered_quantity, color: "primary" }) }), jsx(TableCell, { children: jsx(AmountIndicator, { value: item.released_quantity, maxValue: item.ordered_quantity, color: "primary" }) })] }, iro.documentId))))) : (jsx(TableRow, { children: jsx(TableCell, { colSpan: 7, align: "center", children: "No incoming orders found." }) })) }), jsx(TableFooter, { children: jsxs(TableRow, { children: [jsx(TableCell, { colSpan: 6, align: "right", children: "Total added to stock:" }), jsx(TableCell, { children: Array.isArray(iros)
|
|
64
|
+
? iros.reduce((total, iro) => total +
|
|
65
|
+
iro.items.reduce((itemTotal, item) => itemTotal + item.released_quantity, 0), 0)
|
|
66
|
+
: 0 })] }) })] }), jsx(Table, { size: "small", children: jsxs(TableBody, { children: [jsxs(TableRow, { children: [jsx(TableCell, { align: "right", children: "Total added to stock:" }), jsx(TableCell, { children: Array.isArray(iros) && iros.length > 0
|
|
67
|
+
? iros.reduce((total, iro) => total +
|
|
68
|
+
iro.items.reduce((itemTotal, item) => itemTotal + item.released_quantity, 0), 0)
|
|
69
|
+
: 0 })] }), jsxs(TableRow, { children: [jsx(TableCell, { align: "right", children: "Corrections:" }), jsx(TableCell, { children: jsx(Tooltip, { title: "Total stock corrections", children: jsx(Typography, { children: reports
|
|
70
|
+
? reports.reduce((total, report) => total + report.quantity, 0)
|
|
71
|
+
: 0 }) }) }), jsx(TableCell, { children: jsx(Tooltip, { title: "Total stock corrections after updating", children: jsx("b", { children: reports
|
|
72
|
+
? reports.reduce((total, report) => total + report.quantity, 0)
|
|
73
|
+
: 0 }) }) })] }), jsxs(TableRow, { children: [jsx(TableCell, { align: "right", children: "Stock:" }), jsx(TableCell, { children: jsx(Tooltip, { title: "Total stock", children: jsx(Typography, { children: (Array.isArray(iros) && iros.length > 0
|
|
74
|
+
? iros.reduce((total, iro) => total +
|
|
75
|
+
iro.items.reduce((itemTotal, item) => itemTotal + item.released_quantity, 0), 0)
|
|
76
|
+
: 0) +
|
|
77
|
+
(reports
|
|
78
|
+
? reports.reduce((total, report) => total + report.quantity, 0)
|
|
79
|
+
: 0) }) }) }), jsx(TableCell, { children: jsx(Tooltip, { title: "Total stock after updating", children: jsx("b", { children: (Array.isArray(iros) && iros.length > 0
|
|
80
|
+
? iros.reduce((total, iro) => total +
|
|
81
|
+
iro.items.reduce((itemTotal, item) => itemTotal + item.released_quantity, 0), 0)
|
|
82
|
+
: 0) +
|
|
83
|
+
(reports
|
|
84
|
+
? reports.reduce((total, report) => total + report.quantity, 0)
|
|
85
|
+
: 0) }) }) })] })] }) })] }) })] }), jsxs("form", { action: formAction, children: [jsx("input", { id: "stock_reports", type: "hidden", name: "stock_reports", value: JSON.stringify(reports) }), jsxs(Grid, { container: true, spacing: 2, children: [jsx(Grid, { size: 12, sx: { mt: 2 }, children: jsxs(Stack, { spacing: 2, children: [jsx(Typography, { variant: "h5", children: "Stock corrections" }), jsx(Typography, { variant: "body2", children: "Here you can report and correct for damages wrong items etc. Do not forget to click the button!" }), jsx(ReportsDisplay, { reports: reports }), jsx(Stack, { direction: "row", justifyContent: "flex-end", children: jsx(ReportMakingComponent, { content: "content", quantity: 0, type: "stock", related: [
|
|
86
|
+
{
|
|
87
|
+
id: id,
|
|
88
|
+
__type: "api::e-commerce.product",
|
|
89
|
+
},
|
|
90
|
+
], revalidateCallback: revalidateCallback, biggerButton: true }) })] }) }), jsx(Grid, { size: 12, children: jsx(Stack, { direction: "row", justifyContent: "flex-end", alignItems: "center", sx: { py: 1 }, children: handleClose && (jsx(Button, { onClick: handleClose, variant: "outlined", children: "Close" })) }) })] })] })] }));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { EditReturnStockForm };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { fetchData } from '../loaders.js';
|
|
9
|
+
import { getStrapiURL } from '../../../lib/utils.js';
|
|
10
|
+
import { unstable_noStore } from 'next/cache';
|
|
11
|
+
|
|
12
|
+
const baseUrl = getStrapiURL();
|
|
13
|
+
// this returns an stock oversight for a returned product
|
|
14
|
+
// it's different from regular stock as it counts iro's (incoming return orders)
|
|
15
|
+
async function getSingleReturnStock(documentId) {
|
|
16
|
+
unstable_noStore();
|
|
17
|
+
const url = new URL(`/api/products/getReturnStock/${documentId}`, baseUrl);
|
|
18
|
+
return await fetchData(url.href);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { getSingleReturnStock };
|
package/dist/esm/src/index.js
CHANGED
|
@@ -153,7 +153,9 @@ export { OPOItemFields } from './components/e-commerce/opo/OPOItemFields.js';
|
|
|
153
153
|
export { default as OpoItemUpdater } from './components/e-commerce/opo/OpoItemUpdater.js';
|
|
154
154
|
export { createOpoAction } from './data/actions/e-commerce/opo/createOpoAction.js';
|
|
155
155
|
export { EditStockForm } from './components/e-commerce/products/EditStockForm.js';
|
|
156
|
+
export { EditReturnStockForm } from './components/e-commerce/products/EditReturnStockForm.js';
|
|
156
157
|
export { getSingleStock } from './data/loaders/e-commerce/getSingleStock.js';
|
|
158
|
+
export { getSingleReturnStock } from './data/loaders/e-commerce/getSingleReturnStock.js';
|
|
157
159
|
export { default as CsvDownloader } from './components/common/csv/CsvDownloader.js';
|
|
158
160
|
export { getProductModel } from './data/loaders/e-commerce/getProductModel.js';
|
|
159
161
|
export { queryAllProducts } from './data/loaders/e-commerce/queryAllProducts.js';
|