@lodashventure/medusa-parcel-shipping 0.4.5 → 0.4.7
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/.medusa/server/src/admin/index.js +9 -459
- package/.medusa/server/src/admin/index.mjs +10 -460
- package/.medusa/server/src/index.js +2 -7
- package/.medusa/server/src/modules/parcel-shipping/migrations/Migration20251106000000.js +42 -0
- package/package.json +25 -26
- package/.medusa/server/src/api/admin/documents/document-packing-slip-settings/route.js +0 -65
- package/.medusa/server/src/api/admin/documents/packing-slip/preview/route.js +0 -47
- package/.medusa/server/src/api/admin/documents/packing-slip/route.js +0 -105
- package/.medusa/server/src/links/index.js +0 -9
- package/.medusa/server/src/links/packing-slip-order.js +0 -13
- package/.medusa/server/src/modules/documents/index.js +0 -24
- package/.medusa/server/src/modules/documents/models/document-invoice.js +0 -20
- package/.medusa/server/src/modules/documents/models/document-packing-slip-settings.js +0 -29
- package/.medusa/server/src/modules/documents/models/document-packing-slip.js +0 -32
- package/.medusa/server/src/modules/documents/models/document-settings.js +0 -32
- package/.medusa/server/src/modules/documents/models/index.js +0 -15
- package/.medusa/server/src/modules/documents/service.js +0 -226
- package/.medusa/server/src/modules/documents/services/generators/invoice-generator.js +0 -73
- package/.medusa/server/src/modules/documents/services/generators/packing-slip-generator.js +0 -73
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/basic-logo.js +0 -55
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/basic.js +0 -52
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/customer-info.js +0 -69
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/header-for-logo.js +0 -32
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/header-logo.js +0 -29
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/header.js +0 -35
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/hr.js +0 -23
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/invoice-info.js +0 -35
- package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/table.js +0 -97
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/basic.js +0 -52
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/customer-info-small.js +0 -69
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/customer-info.js +0 -65
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/header-small.js +0 -37
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/header.js +0 -37
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/hr.js +0 -32
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/table-items-small.js +0 -44
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/table-items.js +0 -44
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/table-order-info-small.js +0 -35
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/table-order-info.js +0 -36
- package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/small.js +0 -53
- package/.medusa/server/src/modules/documents/types/api.js +0 -14
- package/.medusa/server/src/modules/documents/types/constants.js +0 -17
- package/.medusa/server/src/modules/documents/types/dto.js +0 -14
- package/.medusa/server/src/modules/documents/types/template-kind.js +0 -25
- package/.medusa/server/src/modules/documents/utils/currency.js +0 -25
- package/.medusa/server/src/workflows/assign-packing-slip.js +0 -35
- package/.medusa/server/src/workflows/index.js +0 -9
|
@@ -1,232 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
-
const react = require("react");
|
|
4
|
-
const ui = require("@medusajs/ui");
|
|
5
3
|
const adminSdk = require("@medusajs/admin-sdk");
|
|
6
|
-
const
|
|
4
|
+
const ui = require("@medusajs/ui");
|
|
5
|
+
const react = require("react");
|
|
7
6
|
const lucideReact = require("lucide-react");
|
|
7
|
+
const icons = require("@medusajs/icons");
|
|
8
8
|
require("@medusajs/admin-shared");
|
|
9
|
-
const OrderPackingSlipWidget = ({ data }) => {
|
|
10
|
-
const [packingSlip, setPackingSlip] = react.useState(null);
|
|
11
|
-
const [loading, setLoading] = react.useState(true);
|
|
12
|
-
const [generating, setGenerating] = react.useState(false);
|
|
13
|
-
const [error, setError] = react.useState(null);
|
|
14
|
-
const order = data;
|
|
15
|
-
react.useEffect(() => {
|
|
16
|
-
fetchPackingSlip();
|
|
17
|
-
}, [order.id]);
|
|
18
|
-
const fetchPackingSlip = async () => {
|
|
19
|
-
setLoading(true);
|
|
20
|
-
setError(null);
|
|
21
|
-
try {
|
|
22
|
-
const response = await fetch(
|
|
23
|
-
`/admin/documents/packing-slip?orderId=${order.id}`,
|
|
24
|
-
{
|
|
25
|
-
credentials: "include"
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
if (!response.ok) {
|
|
29
|
-
throw new Error("Failed to fetch packing slip");
|
|
30
|
-
}
|
|
31
|
-
const data2 = await response.json();
|
|
32
|
-
setPackingSlip(data2.packingSlip || null);
|
|
33
|
-
} catch (err) {
|
|
34
|
-
console.error("Error fetching packing slip:", err);
|
|
35
|
-
setError(err.message);
|
|
36
|
-
} finally {
|
|
37
|
-
setLoading(false);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const generatePackingSlip = async () => {
|
|
41
|
-
setGenerating(true);
|
|
42
|
-
setError(null);
|
|
43
|
-
try {
|
|
44
|
-
const response = await fetch("/admin/documents/packing-slip", {
|
|
45
|
-
method: "POST",
|
|
46
|
-
headers: {
|
|
47
|
-
"Content-Type": "application/json"
|
|
48
|
-
},
|
|
49
|
-
credentials: "include",
|
|
50
|
-
body: JSON.stringify({
|
|
51
|
-
order_id: order.id
|
|
52
|
-
})
|
|
53
|
-
});
|
|
54
|
-
if (!response.ok) {
|
|
55
|
-
const errorData = await response.json().catch(() => ({
|
|
56
|
-
message: `HTTP ${response.status}: ${response.statusText}`
|
|
57
|
-
}));
|
|
58
|
-
throw new Error(errorData.message || "Failed to generate packing slip");
|
|
59
|
-
}
|
|
60
|
-
const data2 = await response.json();
|
|
61
|
-
setPackingSlip(data2.packingSlip);
|
|
62
|
-
ui.toast.success("สร้างใบแพ็คสินค้าสำเร็จ", {
|
|
63
|
-
description: `หมายเลขเอกสาร: ${data2.packingSlip.number}`
|
|
64
|
-
});
|
|
65
|
-
} catch (err) {
|
|
66
|
-
setError(err.message);
|
|
67
|
-
ui.toast.error("เกิดข้อผิดพลาด", {
|
|
68
|
-
description: err.message
|
|
69
|
-
});
|
|
70
|
-
} finally {
|
|
71
|
-
setGenerating(false);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const downloadPackingSlip = async () => {
|
|
75
|
-
var _a;
|
|
76
|
-
try {
|
|
77
|
-
const response = await fetch(
|
|
78
|
-
`/admin/documents/packing-slip?orderId=${order.id}&includeBuffer=true`,
|
|
79
|
-
{
|
|
80
|
-
credentials: "include"
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
if (!response.ok) {
|
|
84
|
-
throw new Error("Failed to fetch packing slip");
|
|
85
|
-
}
|
|
86
|
-
const data2 = await response.json();
|
|
87
|
-
if ((_a = data2.packingSlip) == null ? void 0 : _a.pdfBase64) {
|
|
88
|
-
const byteCharacters = atob(data2.packingSlip.pdfBase64);
|
|
89
|
-
const byteNumbers = new Array(byteCharacters.length);
|
|
90
|
-
for (let i = 0; i < byteCharacters.length; i++) {
|
|
91
|
-
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
92
|
-
}
|
|
93
|
-
const byteArray = new Uint8Array(byteNumbers);
|
|
94
|
-
const blob = new Blob([byteArray], { type: "application/pdf" });
|
|
95
|
-
const url = window.URL.createObjectURL(blob);
|
|
96
|
-
const link = document.createElement("a");
|
|
97
|
-
link.href = url;
|
|
98
|
-
link.download = `packing-slip-${data2.packingSlip.number}.pdf`;
|
|
99
|
-
document.body.appendChild(link);
|
|
100
|
-
link.click();
|
|
101
|
-
document.body.removeChild(link);
|
|
102
|
-
window.URL.revokeObjectURL(url);
|
|
103
|
-
ui.toast.success("ดาวน์โหลดสำเร็จ");
|
|
104
|
-
} else {
|
|
105
|
-
throw new Error("PDF data not available");
|
|
106
|
-
}
|
|
107
|
-
} catch (err) {
|
|
108
|
-
ui.toast.error("เกิดข้อผิดพลาดในการดาวน์โหลด", {
|
|
109
|
-
description: err.message
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const formatDateTime = (dateString) => {
|
|
114
|
-
const date = new Date(dateString);
|
|
115
|
-
return new Intl.DateTimeFormat("th-TH", {
|
|
116
|
-
year: "numeric",
|
|
117
|
-
month: "short",
|
|
118
|
-
day: "numeric",
|
|
119
|
-
hour: "2-digit",
|
|
120
|
-
minute: "2-digit"
|
|
121
|
-
}).format(date);
|
|
122
|
-
};
|
|
123
|
-
if (loading) {
|
|
124
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
125
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
126
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.DocumentText, { className: "text-ui-fg-subtle" }),
|
|
127
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "ใบแพ็คสินค้า" })
|
|
128
|
-
] }) }),
|
|
129
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "กำลังโหลด..." }) })
|
|
130
|
-
] });
|
|
131
|
-
}
|
|
132
|
-
if (error && !packingSlip) {
|
|
133
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
134
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
135
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.DocumentText, { className: "text-ui-fg-subtle" }),
|
|
136
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "ใบแพ็คสินค้า" })
|
|
137
|
-
] }) }),
|
|
138
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-red-500", children: error }) })
|
|
139
|
-
] });
|
|
140
|
-
}
|
|
141
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
142
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {}),
|
|
143
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
144
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
145
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
146
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.DocumentText, { className: "text-ui-fg-subtle" }),
|
|
147
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "ใบแพ็คสินค้า" }),
|
|
148
|
-
packingSlip && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "green", size: "small", children: "สร้างแล้ว" })
|
|
149
|
-
] }),
|
|
150
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
151
|
-
packingSlip && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
152
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
153
|
-
ui.Button,
|
|
154
|
-
{
|
|
155
|
-
size: "small",
|
|
156
|
-
variant: "transparent",
|
|
157
|
-
onClick: fetchPackingSlip,
|
|
158
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RefreshCw, { size: 16 })
|
|
159
|
-
}
|
|
160
|
-
),
|
|
161
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
162
|
-
ui.Button,
|
|
163
|
-
{
|
|
164
|
-
size: "small",
|
|
165
|
-
variant: "secondary",
|
|
166
|
-
onClick: downloadPackingSlip,
|
|
167
|
-
children: [
|
|
168
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { size: 16 }),
|
|
169
|
-
"ดาวน์โหลด"
|
|
170
|
-
]
|
|
171
|
-
}
|
|
172
|
-
)
|
|
173
|
-
] }),
|
|
174
|
-
!packingSlip && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
175
|
-
ui.Button,
|
|
176
|
-
{
|
|
177
|
-
size: "small",
|
|
178
|
-
onClick: generatePackingSlip,
|
|
179
|
-
isLoading: generating,
|
|
180
|
-
children: [
|
|
181
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { size: 16 }),
|
|
182
|
-
"สร้างใบแพ็คสินค้า"
|
|
183
|
-
]
|
|
184
|
-
}
|
|
185
|
-
)
|
|
186
|
-
] })
|
|
187
|
-
] }),
|
|
188
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: packingSlip ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
189
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
190
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
191
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle", children: "หมายเลขเอกสาร" }),
|
|
192
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "font-mono", children: packingSlip.number })
|
|
193
|
-
] }),
|
|
194
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
195
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle", children: "สร้างเมื่อ" }),
|
|
196
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: formatDateTime(packingSlip.created_at) })
|
|
197
|
-
] })
|
|
198
|
-
] }),
|
|
199
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-4 border-t", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "xsmall", className: "text-ui-fg-muted", children: [
|
|
200
|
-
"Document ID: ",
|
|
201
|
-
packingSlip.id
|
|
202
|
-
] }) }),
|
|
203
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pt-4 border-t", children: [
|
|
204
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
205
|
-
ui.Button,
|
|
206
|
-
{
|
|
207
|
-
size: "small",
|
|
208
|
-
variant: "secondary",
|
|
209
|
-
onClick: generatePackingSlip,
|
|
210
|
-
isLoading: generating,
|
|
211
|
-
children: [
|
|
212
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.RefreshCw, { size: 16 }),
|
|
213
|
-
"สร้างใหม่"
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
),
|
|
217
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-muted mt-2", children: "การสร้างใหม่จะแทนที่ใบแพ็คสินค้าเดิม" })
|
|
218
|
-
] })
|
|
219
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center py-8 text-center", children: [
|
|
220
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.DocumentText, { className: "text-ui-fg-muted mb-4" }),
|
|
221
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle mb-2", children: "ยังไม่มีใบแพ็คสินค้าสำหรับคำสั่งซื้อนี้" }),
|
|
222
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-muted mb-4", children: "คลิกปุ่มด้านบนเพื่อสร้างใบแพ็คสินค้า" })
|
|
223
|
-
] }) })
|
|
224
|
-
] })
|
|
225
|
-
] });
|
|
226
|
-
};
|
|
227
|
-
adminSdk.defineWidgetConfig({
|
|
228
|
-
zone: "order.details.after"
|
|
229
|
-
});
|
|
230
9
|
const OrderShippingQuoteWidget = ({ data }) => {
|
|
231
10
|
const [quote, setQuote] = react.useState(null);
|
|
232
11
|
const [loading, setLoading] = react.useState(false);
|
|
@@ -874,7 +653,7 @@ const AreasPage = () => {
|
|
|
874
653
|
/* @__PURE__ */ jsxRuntime.jsx(ServiceAreasTable, {})
|
|
875
654
|
] }) });
|
|
876
655
|
};
|
|
877
|
-
const config$
|
|
656
|
+
const config$3 = adminSdk.defineRouteConfig({
|
|
878
657
|
icon: icons.MapPin,
|
|
879
658
|
label: "พื้นที่บริการ"
|
|
880
659
|
});
|
|
@@ -1282,7 +1061,7 @@ const BoxesPage = () => {
|
|
|
1282
1061
|
/* @__PURE__ */ jsxRuntime.jsx(ParcelBoxesTable, {})
|
|
1283
1062
|
] }) });
|
|
1284
1063
|
};
|
|
1285
|
-
const config$
|
|
1064
|
+
const config$2 = adminSdk.defineRouteConfig({
|
|
1286
1065
|
icon: icons.ArchiveBox,
|
|
1287
1066
|
label: "กล่องพัสดุ"
|
|
1288
1067
|
});
|
|
@@ -1725,225 +1504,10 @@ const MaterialCostsPage = () => {
|
|
|
1725
1504
|
/* @__PURE__ */ jsxRuntime.jsx(MaterialCostsTable, {})
|
|
1726
1505
|
] }) });
|
|
1727
1506
|
};
|
|
1728
|
-
const config$
|
|
1507
|
+
const config$1 = adminSdk.defineRouteConfig({
|
|
1729
1508
|
icon: icons.CurrencyDollarSolid,
|
|
1730
1509
|
label: "ต้นทุนวัสดุ"
|
|
1731
1510
|
});
|
|
1732
|
-
const PackingSlipSettingsPage = () => {
|
|
1733
|
-
const [settings, setSettings] = react.useState(null);
|
|
1734
|
-
const [loading, setLoading] = react.useState(true);
|
|
1735
|
-
const [saving, setSaving] = react.useState(false);
|
|
1736
|
-
const [formatNumber, setFormatNumber] = react.useState("");
|
|
1737
|
-
const [forcedNumber, setForcedNumber] = react.useState("");
|
|
1738
|
-
const [template, setTemplate] = react.useState("BASIC");
|
|
1739
|
-
react.useEffect(() => {
|
|
1740
|
-
fetchSettings();
|
|
1741
|
-
}, []);
|
|
1742
|
-
const fetchSettings = async () => {
|
|
1743
|
-
setLoading(true);
|
|
1744
|
-
try {
|
|
1745
|
-
const response = await fetch(
|
|
1746
|
-
"/admin/documents/document-packing-slip-settings",
|
|
1747
|
-
{
|
|
1748
|
-
credentials: "include"
|
|
1749
|
-
}
|
|
1750
|
-
);
|
|
1751
|
-
if (!response.ok) {
|
|
1752
|
-
throw new Error("Failed to fetch settings");
|
|
1753
|
-
}
|
|
1754
|
-
const data = await response.json();
|
|
1755
|
-
if (data.settings) {
|
|
1756
|
-
setSettings(data.settings);
|
|
1757
|
-
setFormatNumber(data.settings.formatNumber || "");
|
|
1758
|
-
setForcedNumber(data.settings.forcedNumber || "");
|
|
1759
|
-
setTemplate(data.settings.template || "BASIC");
|
|
1760
|
-
}
|
|
1761
|
-
} catch (err) {
|
|
1762
|
-
ui.toast.error("เกิดข้อผิดพลาด", {
|
|
1763
|
-
description: err.message
|
|
1764
|
-
});
|
|
1765
|
-
} finally {
|
|
1766
|
-
setLoading(false);
|
|
1767
|
-
}
|
|
1768
|
-
};
|
|
1769
|
-
const handleSave = async () => {
|
|
1770
|
-
setSaving(true);
|
|
1771
|
-
try {
|
|
1772
|
-
const response = await fetch(
|
|
1773
|
-
"/admin/documents/document-packing-slip-settings",
|
|
1774
|
-
{
|
|
1775
|
-
method: "POST",
|
|
1776
|
-
headers: {
|
|
1777
|
-
"Content-Type": "application/json"
|
|
1778
|
-
},
|
|
1779
|
-
credentials: "include",
|
|
1780
|
-
body: JSON.stringify({
|
|
1781
|
-
formatNumber: formatNumber || void 0,
|
|
1782
|
-
forcedNumber: forcedNumber || void 0,
|
|
1783
|
-
template
|
|
1784
|
-
})
|
|
1785
|
-
}
|
|
1786
|
-
);
|
|
1787
|
-
if (!response.ok) {
|
|
1788
|
-
const errorData = await response.json().catch(() => ({
|
|
1789
|
-
message: `HTTP ${response.status}: ${response.statusText}`
|
|
1790
|
-
}));
|
|
1791
|
-
throw new Error(errorData.message || "Failed to save settings");
|
|
1792
|
-
}
|
|
1793
|
-
const data = await response.json();
|
|
1794
|
-
setSettings(data.settings);
|
|
1795
|
-
ui.toast.success("บันทึกสำเร็จ", {
|
|
1796
|
-
description: "ตั้งค่าใบแพ็คสินค้าได้รับการบันทึกแล้ว"
|
|
1797
|
-
});
|
|
1798
|
-
} catch (err) {
|
|
1799
|
-
ui.toast.error("เกิดข้อผิดพลาดในการบันทึก", {
|
|
1800
|
-
description: err.message
|
|
1801
|
-
});
|
|
1802
|
-
} finally {
|
|
1803
|
-
setSaving(false);
|
|
1804
|
-
}
|
|
1805
|
-
};
|
|
1806
|
-
const handlePreview = async () => {
|
|
1807
|
-
var _a;
|
|
1808
|
-
try {
|
|
1809
|
-
const response = await fetch(
|
|
1810
|
-
`/admin/documents/packing-slip/preview?template=${template}`,
|
|
1811
|
-
{
|
|
1812
|
-
credentials: "include"
|
|
1813
|
-
}
|
|
1814
|
-
);
|
|
1815
|
-
if (!response.ok) {
|
|
1816
|
-
const errorData = await response.json().catch(() => ({
|
|
1817
|
-
message: `HTTP ${response.status}: ${response.statusText}`
|
|
1818
|
-
}));
|
|
1819
|
-
throw new Error(errorData.message || "Failed to generate preview");
|
|
1820
|
-
}
|
|
1821
|
-
const data = await response.json();
|
|
1822
|
-
if ((_a = data.packingSlip) == null ? void 0 : _a.pdfBase64) {
|
|
1823
|
-
const byteCharacters = atob(data.packingSlip.pdfBase64);
|
|
1824
|
-
const byteNumbers = new Array(byteCharacters.length);
|
|
1825
|
-
for (let i = 0; i < byteCharacters.length; i++) {
|
|
1826
|
-
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
1827
|
-
}
|
|
1828
|
-
const byteArray = new Uint8Array(byteNumbers);
|
|
1829
|
-
const blob = new Blob([byteArray], { type: "application/pdf" });
|
|
1830
|
-
const url = window.URL.createObjectURL(blob);
|
|
1831
|
-
window.open(url, "_blank");
|
|
1832
|
-
ui.toast.success("เปิดตัวอย่างในแท็บใหม่");
|
|
1833
|
-
} else {
|
|
1834
|
-
throw new Error("PDF data not available");
|
|
1835
|
-
}
|
|
1836
|
-
} catch (err) {
|
|
1837
|
-
ui.toast.error("เกิดข้อผิดพลาดในการแสดงตัวอย่าง", {
|
|
1838
|
-
description: err.message
|
|
1839
|
-
});
|
|
1840
|
-
}
|
|
1841
|
-
};
|
|
1842
|
-
if (loading) {
|
|
1843
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
|
|
1844
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "ตั้งค่าใบแพ็คสินค้า" }),
|
|
1845
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "กำลังโหลด..." })
|
|
1846
|
-
] }) });
|
|
1847
|
-
}
|
|
1848
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1849
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Toaster, {}),
|
|
1850
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
1851
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1852
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "ตั้งค่าใบแพ็คสินค้า" }),
|
|
1853
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle mt-1", children: "กำหนดรูปแบบและเทมเพลตสำหรับใบแพ็คสินค้า" })
|
|
1854
|
-
] }) }),
|
|
1855
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-6", children: [
|
|
1856
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
1857
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "template", weight: "plus", children: "เทมเพลต" }),
|
|
1858
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { value: template, onValueChange: setTemplate, children: [
|
|
1859
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "template", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
1860
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
1861
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "BASIC", children: "Basic - ใบแพ็คมาตรฐาน" }),
|
|
1862
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "BASIC_SMALL", children: "Basic Small - ใบแพ็คขนาดเล็ก" })
|
|
1863
|
-
] })
|
|
1864
|
-
] }),
|
|
1865
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "เลือกรูปแบบเทมเพลตสำหรับใบแพ็คสินค้า" }),
|
|
1866
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1867
|
-
ui.Button,
|
|
1868
|
-
{
|
|
1869
|
-
size: "small",
|
|
1870
|
-
variant: "secondary",
|
|
1871
|
-
onClick: handlePreview,
|
|
1872
|
-
className: "mt-2 w-fit",
|
|
1873
|
-
children: [
|
|
1874
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { size: 16 }),
|
|
1875
|
-
"ดูตัวอย่างเทมเพลต"
|
|
1876
|
-
]
|
|
1877
|
-
}
|
|
1878
|
-
)
|
|
1879
|
-
] }),
|
|
1880
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
1881
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "formatNumber", weight: "plus", children: "รูปแบบหมายเลขเอกสาร" }),
|
|
1882
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1883
|
-
ui.Input,
|
|
1884
|
-
{
|
|
1885
|
-
id: "formatNumber",
|
|
1886
|
-
placeholder: "เช่น PS-{YYYY}-{0000}",
|
|
1887
|
-
value: formatNumber,
|
|
1888
|
-
onChange: (e) => setFormatNumber(e.target.value)
|
|
1889
|
-
}
|
|
1890
|
-
),
|
|
1891
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
1892
|
-
"กำหนดรูปแบบหมายเลขใบแพ็คสินค้า ใช้ ",
|
|
1893
|
-
"{YYYY}",
|
|
1894
|
-
" สำหรับปี และ",
|
|
1895
|
-
" ",
|
|
1896
|
-
"{0000}",
|
|
1897
|
-
" สำหรับเลขที่เอกสาร"
|
|
1898
|
-
] })
|
|
1899
|
-
] }),
|
|
1900
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-2", children: [
|
|
1901
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "forcedNumber", weight: "plus", children: "กำหนดหมายเลขเริ่มต้น" }),
|
|
1902
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1903
|
-
ui.Input,
|
|
1904
|
-
{
|
|
1905
|
-
id: "forcedNumber",
|
|
1906
|
-
type: "number",
|
|
1907
|
-
placeholder: "เช่น 1",
|
|
1908
|
-
value: forcedNumber,
|
|
1909
|
-
onChange: (e) => setForcedNumber(e.target.value)
|
|
1910
|
-
}
|
|
1911
|
-
),
|
|
1912
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "กำหนดหมายเลขเริ่มต้นสำหรับเอกสารใหม่ (ถ้าไม่ระบุจะนับต่อจากเอกสารล่าสุด)" })
|
|
1913
|
-
] }),
|
|
1914
|
-
settings && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border p-4 bg-ui-bg-subtle", children: [
|
|
1915
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", size: "small", className: "mb-2", children: "ข้อมูลการตั้งค่าปัจจุบัน" }),
|
|
1916
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-2 text-sm text-ui-fg-subtle", children: [
|
|
1917
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: "อัปเดตล่าสุด:" }),
|
|
1918
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: new Date(settings.updated_at).toLocaleString("th-TH") }),
|
|
1919
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: "สร้างเมื่อ:" }),
|
|
1920
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { children: new Date(settings.created_at).toLocaleString("th-TH") })
|
|
1921
|
-
] })
|
|
1922
|
-
] }),
|
|
1923
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border p-4", children: [
|
|
1924
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", size: "small", className: "mb-2", children: "ตัวอย่างหมายเลขเอกสาร" }),
|
|
1925
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-mono text-lg", children: formatNumber ? formatNumber.replace("{YYYY}", (/* @__PURE__ */ new Date()).getFullYear().toString()).replace("{0000}", (forcedNumber || "1").padStart(4, "0")) : "ยังไม่ได้กำหนดรูปแบบ" })
|
|
1926
|
-
] }),
|
|
1927
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2 justify-end", children: [
|
|
1928
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1929
|
-
ui.Button,
|
|
1930
|
-
{
|
|
1931
|
-
variant: "secondary",
|
|
1932
|
-
onClick: fetchSettings,
|
|
1933
|
-
disabled: saving,
|
|
1934
|
-
children: "รีเซ็ต"
|
|
1935
|
-
}
|
|
1936
|
-
),
|
|
1937
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: handleSave, isLoading: saving, children: "บันทึกการตั้งค่า" })
|
|
1938
|
-
] })
|
|
1939
|
-
] })
|
|
1940
|
-
] }) })
|
|
1941
|
-
] });
|
|
1942
|
-
};
|
|
1943
|
-
const config$1 = adminSdk.defineRouteConfig({
|
|
1944
|
-
icon: icons.DocumentText,
|
|
1945
|
-
label: "ตั้งค่าใบแพ็คสินค้า"
|
|
1946
|
-
});
|
|
1947
1511
|
const CARRIER_TYPES$1 = [
|
|
1948
1512
|
{ value: "COMPANY_FLEET", label: "บริษัทรถส่งของ (Messenger)" },
|
|
1949
1513
|
{ value: "COMPANY_TRUCK", label: "รถบริษัท (Same Day)" },
|
|
@@ -2432,10 +1996,6 @@ const config = adminSdk.defineRouteConfig({
|
|
|
2432
1996
|
label: "อัตราค่าขนส่ง"
|
|
2433
1997
|
});
|
|
2434
1998
|
const widgetModule = { widgets: [
|
|
2435
|
-
{
|
|
2436
|
-
Component: OrderPackingSlipWidget,
|
|
2437
|
-
zone: ["order.details.after"]
|
|
2438
|
-
},
|
|
2439
1999
|
{
|
|
2440
2000
|
Component: OrderShippingQuoteWidget,
|
|
2441
2001
|
zone: ["order.details.after"]
|
|
@@ -2455,10 +2015,6 @@ const routeModule = {
|
|
|
2455
2015
|
Component: MaterialCostsPage,
|
|
2456
2016
|
path: "/material-costs"
|
|
2457
2017
|
},
|
|
2458
|
-
{
|
|
2459
|
-
Component: PackingSlipSettingsPage,
|
|
2460
|
-
path: "/packing-slip-settings"
|
|
2461
|
-
},
|
|
2462
2018
|
{
|
|
2463
2019
|
Component: RatesPage,
|
|
2464
2020
|
path: "/rates"
|
|
@@ -2467,28 +2023,22 @@ const routeModule = {
|
|
|
2467
2023
|
};
|
|
2468
2024
|
const menuItemModule = {
|
|
2469
2025
|
menuItems: [
|
|
2470
|
-
{
|
|
2471
|
-
label: config$4.label,
|
|
2472
|
-
icon: config$4.icon,
|
|
2473
|
-
path: "/areas",
|
|
2474
|
-
nested: void 0
|
|
2475
|
-
},
|
|
2476
2026
|
{
|
|
2477
2027
|
label: config$3.label,
|
|
2478
2028
|
icon: config$3.icon,
|
|
2479
|
-
path: "/
|
|
2029
|
+
path: "/areas",
|
|
2480
2030
|
nested: void 0
|
|
2481
2031
|
},
|
|
2482
2032
|
{
|
|
2483
2033
|
label: config$2.label,
|
|
2484
2034
|
icon: config$2.icon,
|
|
2485
|
-
path: "/
|
|
2035
|
+
path: "/boxes",
|
|
2486
2036
|
nested: void 0
|
|
2487
2037
|
},
|
|
2488
2038
|
{
|
|
2489
2039
|
label: config$1.label,
|
|
2490
2040
|
icon: config$1.icon,
|
|
2491
|
-
path: "/
|
|
2041
|
+
path: "/material-costs",
|
|
2492
2042
|
nested: void 0
|
|
2493
2043
|
},
|
|
2494
2044
|
{
|