@consilioweb/payload-support 0.6.1 → 0.6.2
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/views/BillingView/client.cjs +209 -0
- package/dist/views/BillingView/client.js +204 -0
- package/dist/views/BillingView/index.cjs +34 -0
- package/dist/views/BillingView/index.js +29 -0
- package/dist/views/ChatView/client.cjs +253 -0
- package/dist/views/ChatView/client.js +252 -0
- package/dist/views/ChatView/index.cjs +34 -0
- package/dist/views/ChatView/index.js +29 -0
- package/dist/views/CrmView/client.cjs +233 -0
- package/dist/views/CrmView/client.js +232 -0
- package/dist/views/CrmView/index.cjs +34 -0
- package/dist/views/CrmView/index.js +29 -0
- package/dist/views/EmailTrackingView/client.cjs +159 -0
- package/dist/views/EmailTrackingView/client.js +154 -0
- package/dist/views/EmailTrackingView/index.cjs +34 -0
- package/dist/views/EmailTrackingView/index.js +29 -0
- package/dist/views/ImportConversationView/client.cjs +205 -0
- package/dist/views/ImportConversationView/client.js +204 -0
- package/dist/views/ImportConversationView/index.cjs +34 -0
- package/dist/views/ImportConversationView/index.js +29 -0
- package/dist/views/LogsView/client.cjs +149 -0
- package/dist/views/LogsView/client.js +148 -0
- package/dist/views/LogsView/index.cjs +32 -0
- package/dist/views/LogsView/index.js +27 -0
- package/dist/views/NewTicketView/client.cjs +229 -0
- package/dist/views/NewTicketView/client.js +224 -0
- package/dist/views/NewTicketView/index.cjs +32 -0
- package/dist/views/NewTicketView/index.js +27 -0
- package/dist/views/PendingEmailsView/client.cjs +173 -0
- package/dist/views/PendingEmailsView/client.js +172 -0
- package/dist/views/PendingEmailsView/index.cjs +34 -0
- package/dist/views/PendingEmailsView/index.js +29 -0
- package/dist/views/SupportDashboardView/client.cjs +301 -0
- package/dist/views/SupportDashboardView/client.js +296 -0
- package/dist/views/SupportDashboardView/index.cjs +34 -0
- package/dist/views/SupportDashboardView/index.js +29 -0
- package/dist/views/TicketDetailView/client.cjs +850 -0
- package/dist/views/TicketDetailView/client.js +844 -0
- package/dist/views/TicketDetailView/index.cjs +34 -0
- package/dist/views/TicketDetailView/index.js +29 -0
- package/dist/views/TicketInboxView/client.cjs +299 -0
- package/dist/views/TicketInboxView/client.js +294 -0
- package/dist/views/TicketInboxView/index.cjs +32 -0
- package/dist/views/TicketInboxView/index.js +27 -0
- package/dist/{views.css → views/TicketingSettingsView/TicketingSettings.module.scss} +138 -66
- package/dist/views/TicketingSettingsView/client.cjs +733 -0
- package/dist/views/TicketingSettingsView/client.js +728 -0
- package/dist/views/TicketingSettingsView/index.cjs +34 -0
- package/dist/views/TicketingSettingsView/index.js +29 -0
- package/dist/views/TimeDashboardView/client.cjs +169 -0
- package/dist/views/TimeDashboardView/client.js +164 -0
- package/dist/views/TimeDashboardView/index.cjs +34 -0
- package/dist/views/TimeDashboardView/index.js +29 -0
- package/dist/views/shared/AdminViewHeader.cjs +68 -0
- package/dist/views/shared/AdminViewHeader.js +67 -0
- package/dist/views/shared/ErrorBoundary.cjs +55 -0
- package/dist/views/shared/ErrorBoundary.js +50 -0
- package/dist/views/shared/Skeleton.cjs +77 -0
- package/dist/views/shared/Skeleton.js +72 -0
- package/dist/views/shared/adminTokens.cjs +34 -0
- package/dist/views/shared/adminTokens.js +31 -0
- package/dist/views/shared/config.cjs +44 -0
- package/dist/views/shared/config.js +40 -0
- package/dist/views/shared/index.cjs +58 -0
- package/dist/views/shared/index.js +5 -0
- package/dist/views.cjs +77 -6175
- package/dist/views.d.cts +13 -30
- package/dist/views.d.ts +13 -30
- package/dist/views.js +13 -6165
- package/package.json +1 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var useTranslation = require('../../components/TicketConversation/hooks/useTranslation');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
10
|
+
|
|
11
|
+
function formatDuration(minutes) {
|
|
12
|
+
const h = Math.floor(minutes / 60);
|
|
13
|
+
const m = minutes % 60;
|
|
14
|
+
if (h === 0) return `${m}min`;
|
|
15
|
+
if (m === 0) return `${h}h`;
|
|
16
|
+
return `${h}h ${m}min`;
|
|
17
|
+
}
|
|
18
|
+
function formatAmount(minutes, rate) {
|
|
19
|
+
return (minutes / 60 * rate).toFixed(2);
|
|
20
|
+
}
|
|
21
|
+
function getMonthRange(offset) {
|
|
22
|
+
const now = /* @__PURE__ */ new Date();
|
|
23
|
+
const start = new Date(now.getFullYear(), now.getMonth() + offset, 1);
|
|
24
|
+
const end = new Date(now.getFullYear(), now.getMonth() + offset + 1, 0);
|
|
25
|
+
return { from: start.toISOString().split("T")[0], to: end.toISOString().split("T")[0] };
|
|
26
|
+
}
|
|
27
|
+
function getQuarterRange(offset) {
|
|
28
|
+
const now = /* @__PURE__ */ new Date();
|
|
29
|
+
const q = Math.floor(now.getMonth() / 3) + offset;
|
|
30
|
+
const start = new Date(now.getFullYear(), q * 3, 1);
|
|
31
|
+
const end = new Date(now.getFullYear(), q * 3 + 3, 0);
|
|
32
|
+
return { from: start.toISOString().split("T")[0], to: end.toISOString().split("T")[0] };
|
|
33
|
+
}
|
|
34
|
+
const BillingClient = () => {
|
|
35
|
+
const { t } = useTranslation.useTranslation();
|
|
36
|
+
const [from, setFrom] = React.useState(() => getMonthRange(0).from);
|
|
37
|
+
const [to, setTo] = React.useState(() => getMonthRange(0).to);
|
|
38
|
+
const [projectId, setProjectId] = React.useState("");
|
|
39
|
+
const [rate, setRate] = React.useState(60);
|
|
40
|
+
const [data, setData] = React.useState(null);
|
|
41
|
+
const [loading, setLoading] = React.useState(false);
|
|
42
|
+
const [projects, setProjects] = React.useState([]);
|
|
43
|
+
const [projectsLoaded, setProjectsLoaded] = React.useState(false);
|
|
44
|
+
const [copied, setCopied] = React.useState(false);
|
|
45
|
+
const loadProjects = React.useCallback(async () => {
|
|
46
|
+
if (projectsLoaded) return;
|
|
47
|
+
try {
|
|
48
|
+
const res = await fetch("/api/projects?limit=100&depth=0&sort=name");
|
|
49
|
+
if (res.ok) {
|
|
50
|
+
const json = await res.json();
|
|
51
|
+
setProjects(json.docs?.map((p) => ({ id: p.id, name: p.name })) || []);
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.warn("[support] loadProjects error:", err);
|
|
55
|
+
}
|
|
56
|
+
setProjectsLoaded(true);
|
|
57
|
+
}, [projectsLoaded]);
|
|
58
|
+
React__default.default.useEffect(() => {
|
|
59
|
+
loadProjects();
|
|
60
|
+
}, [loadProjects]);
|
|
61
|
+
const fetchBilling = React.useCallback(async () => {
|
|
62
|
+
setLoading(true);
|
|
63
|
+
try {
|
|
64
|
+
const params = new URLSearchParams({ from, to });
|
|
65
|
+
if (projectId) params.set("projectId", projectId);
|
|
66
|
+
const res = await fetch(`/api/support/billing?${params}`);
|
|
67
|
+
if (res.ok) setData(await res.json());
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.warn("[support] fetchBilling error:", err);
|
|
70
|
+
}
|
|
71
|
+
setLoading(false);
|
|
72
|
+
}, [from, to, projectId]);
|
|
73
|
+
const setPeriod = (range) => {
|
|
74
|
+
setFrom(range.from);
|
|
75
|
+
setTo(range.to);
|
|
76
|
+
};
|
|
77
|
+
const copyRecap = React.useCallback(() => {
|
|
78
|
+
if (!data) return;
|
|
79
|
+
const lines = [`PRE-FACTURATION -- Du ${from} au ${to}`, `Taux horaire : ${rate} EUR/h`, "=".repeat(50)];
|
|
80
|
+
for (const group of data.groups) {
|
|
81
|
+
lines.push("", `PROJET : ${group.project?.name || "Sans projet"}`);
|
|
82
|
+
if (group.client?.company) lines.push(`Client : ${group.client.company}`);
|
|
83
|
+
for (const ticket of group.tickets) {
|
|
84
|
+
lines.push(` ${ticket.ticketNumber} -- ${ticket.subject}`);
|
|
85
|
+
for (const entry of ticket.entries) lines.push(` ${entry.date} | ${formatDuration(entry.duration)} | ${entry.description || "-"}`);
|
|
86
|
+
lines.push(` Sous-total : ${formatDuration(ticket.totalMinutes)} = ${formatAmount(ticket.totalMinutes, rate)} EUR`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
lines.push("", "=".repeat(50), `TOTAL : ${formatDuration(data.grandTotalMinutes)} = ${formatAmount(data.grandTotalMinutes, rate)} EUR`);
|
|
90
|
+
navigator.clipboard.writeText(lines.join("\n"));
|
|
91
|
+
setCopied(true);
|
|
92
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
93
|
+
}, [data, from, to, rate]);
|
|
94
|
+
const S = {
|
|
95
|
+
page: { padding: "20px 30px", maxWidth: 1100, margin: "0 auto" },
|
|
96
|
+
filters: { marginBottom: 20 },
|
|
97
|
+
quickPeriod: { display: "flex", gap: 6, marginBottom: 8 },
|
|
98
|
+
btn: { padding: "6px 12px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 12, cursor: "pointer", background: "var(--theme-elevation-0)", color: "var(--theme-text)" },
|
|
99
|
+
btnPrimary: { padding: "6px 12px", borderRadius: 6, border: "none", fontSize: 12, cursor: "pointer", background: "#2563eb", color: "#fff", fontWeight: 600 },
|
|
100
|
+
filterRow: { display: "flex", gap: 12, alignItems: "flex-end", flexWrap: "wrap" },
|
|
101
|
+
fieldGroup: { display: "flex", flexDirection: "column", gap: 4 },
|
|
102
|
+
label: { fontSize: 11, fontWeight: 600, color: "var(--theme-elevation-500)" },
|
|
103
|
+
input: { padding: "6px 10px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 12, color: "var(--theme-text)", background: "var(--theme-elevation-0)" },
|
|
104
|
+
select: { padding: "6px 10px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 12, color: "var(--theme-text)", background: "var(--theme-elevation-0)" },
|
|
105
|
+
groupCard: { marginBottom: 16, borderRadius: 10, border: "1px solid var(--theme-elevation-150)", overflow: "hidden" },
|
|
106
|
+
groupHeader: { display: "flex", justifyContent: "space-between", padding: "12px 16px", background: "var(--theme-elevation-50)", borderBottom: "1px solid var(--theme-elevation-150)" },
|
|
107
|
+
table: { width: "100%", borderCollapse: "collapse", fontSize: 12 },
|
|
108
|
+
th: { textAlign: "left", padding: "6px 8px", borderBottom: "1px solid var(--theme-elevation-200)", fontSize: 11, color: "var(--theme-elevation-500)" },
|
|
109
|
+
td: { padding: "6px 8px", borderBottom: "1px solid var(--theme-elevation-100)" },
|
|
110
|
+
grandTotal: { padding: 16, borderRadius: 10, border: "2px solid #2563eb", display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 16 }
|
|
111
|
+
};
|
|
112
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.page, children: [
|
|
113
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: 16 }, children: [
|
|
114
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { style: { fontSize: 22, fontWeight: 700, margin: 0 }, children: t("billing.title") }),
|
|
115
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: 13, color: "var(--theme-elevation-500)", margin: "4px 0 0" }, children: t("billing.subtitle") })
|
|
116
|
+
] }),
|
|
117
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.filters, children: [
|
|
118
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.quickPeriod, children: [
|
|
119
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { style: S.btnPrimary, onClick: () => setPeriod(getMonthRange(0)), children: t("billing.filters.thisMonth") }),
|
|
120
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { style: S.btn, onClick: () => setPeriod(getMonthRange(-1)), children: t("billing.filters.lastMonth") }),
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { style: S.btn, onClick: () => setPeriod(getQuarterRange(0)), children: t("billing.filters.thisQuarter") })
|
|
122
|
+
] }),
|
|
123
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.filterRow, children: [
|
|
124
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { style: S.label, children: t("billing.filters.from") }),
|
|
126
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", value: from, onChange: (e) => setFrom(e.target.value), style: S.input })
|
|
127
|
+
] }),
|
|
128
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
|
|
129
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { style: S.label, children: t("billing.filters.to") }),
|
|
130
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", value: to, onChange: (e) => setTo(e.target.value), style: S.input })
|
|
131
|
+
] }),
|
|
132
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
|
|
133
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { style: S.label, children: t("billing.filters.project") }),
|
|
134
|
+
/* @__PURE__ */ jsxRuntime.jsxs("select", { value: projectId, onChange: (e) => setProjectId(e.target.value), style: S.select, children: [
|
|
135
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: t("common.all") }),
|
|
136
|
+
projects.map((p) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: p.id, children: p.name }, p.id))
|
|
137
|
+
] })
|
|
138
|
+
] }),
|
|
139
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { style: S.label, children: t("billing.filters.hourlyRate") }),
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: 4, alignItems: "center" }, children: [
|
|
142
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "number", value: rate, onChange: (e) => setRate(Number(e.target.value)), style: { ...S.input, width: 70 }, min: 0 }),
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: 11 }, children: t("billing.filters.rateUnit") })
|
|
144
|
+
] })
|
|
145
|
+
] }),
|
|
146
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { style: S.btnPrimary, onClick: fetchBilling, disabled: loading, children: loading ? t("billing.filters.loading") : t("billing.filters.load") })
|
|
147
|
+
] })
|
|
148
|
+
] }),
|
|
149
|
+
data && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: data.groups.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: 40, textAlign: "center", color: "#94a3b8" }, children: t("billing.empty") }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
150
|
+
data.groups.map((group, gi) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.groupCard, children: [
|
|
151
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.groupHeader, children: [
|
|
152
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
153
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontWeight: 700 }, children: group.project?.name || "Sans projet" }),
|
|
154
|
+
group.client?.company && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { color: "var(--theme-elevation-500)" }, children: [
|
|
155
|
+
" -- ",
|
|
156
|
+
group.client.company
|
|
157
|
+
] })
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "right" }, children: [
|
|
160
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontWeight: 700 }, children: formatDuration(group.totalMinutes) }),
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { fontSize: 12, color: "#2563eb", fontWeight: 600 }, children: [
|
|
162
|
+
formatAmount(group.totalMinutes, rate),
|
|
163
|
+
" EUR"
|
|
164
|
+
] })
|
|
165
|
+
] })
|
|
166
|
+
] }),
|
|
167
|
+
/* @__PURE__ */ jsxRuntime.jsxs("table", { style: S.table, children: [
|
|
168
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
169
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: S.th, children: t("billing.table.ticketNumber") }),
|
|
170
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: S.th, children: t("billing.table.subject") }),
|
|
171
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: S.th, children: t("billing.table.date") }),
|
|
172
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: S.th, children: t("billing.table.duration") }),
|
|
173
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: S.th, children: t("billing.table.description") }),
|
|
174
|
+
/* @__PURE__ */ jsxRuntime.jsx("th", { style: { ...S.th, textAlign: "right" }, children: t("billing.table.amount") })
|
|
175
|
+
] }) }),
|
|
176
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: group.tickets.map((ticket) => ticket.entries.map((entry, ei) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
177
|
+
ei === 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
178
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: { ...S.td, fontWeight: 600 }, rowSpan: ticket.entries.length, children: /* @__PURE__ */ jsxRuntime.jsx("a", { href: `/admin/support/ticket?id=${ticket.id}`, style: { color: "#2563eb", textDecoration: "none" }, children: ticket.ticketNumber }) }),
|
|
179
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: S.td, rowSpan: ticket.entries.length, children: ticket.subject })
|
|
180
|
+
] }),
|
|
181
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: S.td, children: entry.date }),
|
|
182
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: S.td, children: formatDuration(entry.duration) }),
|
|
183
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { style: S.td, children: entry.description || "-" }),
|
|
184
|
+
/* @__PURE__ */ jsxRuntime.jsxs("td", { style: { ...S.td, textAlign: "right", fontWeight: 600 }, children: [
|
|
185
|
+
formatAmount(entry.duration, rate),
|
|
186
|
+
" EUR"
|
|
187
|
+
] })
|
|
188
|
+
] }, `${ticket.id}-${ei}`))) })
|
|
189
|
+
] })
|
|
190
|
+
] }, gi)),
|
|
191
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.grandTotal, children: [
|
|
192
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
193
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, color: "var(--theme-elevation-500)" }, children: t("billing.totals.billableTicketsPlural", { count: String(data.groups.reduce((s2, g) => s2 + g.tickets.length, 0)) }) }),
|
|
194
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { fontSize: 18, fontWeight: 700 }, children: [
|
|
195
|
+
t("billing.totals.total"),
|
|
196
|
+
" : ",
|
|
197
|
+
formatDuration(data.grandTotalMinutes),
|
|
198
|
+
" = ",
|
|
199
|
+
formatAmount(data.grandTotalMinutes, rate),
|
|
200
|
+
" EUR"
|
|
201
|
+
] })
|
|
202
|
+
] }),
|
|
203
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { style: S.btnPrimary, onClick: copyRecap, children: copied ? t("billing.totals.copiedRecap") : t("billing.totals.copyRecap") })
|
|
204
|
+
] })
|
|
205
|
+
] }) })
|
|
206
|
+
] });
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
exports.BillingClient = BillingClient;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import React, { useState, useCallback } from 'react';
|
|
4
|
+
import { useTranslation } from '../../components/TicketConversation/hooks/useTranslation';
|
|
5
|
+
|
|
6
|
+
function formatDuration(minutes) {
|
|
7
|
+
const h = Math.floor(minutes / 60);
|
|
8
|
+
const m = minutes % 60;
|
|
9
|
+
if (h === 0) return `${m}min`;
|
|
10
|
+
if (m === 0) return `${h}h`;
|
|
11
|
+
return `${h}h ${m}min`;
|
|
12
|
+
}
|
|
13
|
+
function formatAmount(minutes, rate) {
|
|
14
|
+
return (minutes / 60 * rate).toFixed(2);
|
|
15
|
+
}
|
|
16
|
+
function getMonthRange(offset) {
|
|
17
|
+
const now = /* @__PURE__ */ new Date();
|
|
18
|
+
const start = new Date(now.getFullYear(), now.getMonth() + offset, 1);
|
|
19
|
+
const end = new Date(now.getFullYear(), now.getMonth() + offset + 1, 0);
|
|
20
|
+
return { from: start.toISOString().split("T")[0], to: end.toISOString().split("T")[0] };
|
|
21
|
+
}
|
|
22
|
+
function getQuarterRange(offset) {
|
|
23
|
+
const now = /* @__PURE__ */ new Date();
|
|
24
|
+
const q = Math.floor(now.getMonth() / 3) + offset;
|
|
25
|
+
const start = new Date(now.getFullYear(), q * 3, 1);
|
|
26
|
+
const end = new Date(now.getFullYear(), q * 3 + 3, 0);
|
|
27
|
+
return { from: start.toISOString().split("T")[0], to: end.toISOString().split("T")[0] };
|
|
28
|
+
}
|
|
29
|
+
const BillingClient = () => {
|
|
30
|
+
const { t } = useTranslation();
|
|
31
|
+
const [from, setFrom] = useState(() => getMonthRange(0).from);
|
|
32
|
+
const [to, setTo] = useState(() => getMonthRange(0).to);
|
|
33
|
+
const [projectId, setProjectId] = useState("");
|
|
34
|
+
const [rate, setRate] = useState(60);
|
|
35
|
+
const [data, setData] = useState(null);
|
|
36
|
+
const [loading, setLoading] = useState(false);
|
|
37
|
+
const [projects, setProjects] = useState([]);
|
|
38
|
+
const [projectsLoaded, setProjectsLoaded] = useState(false);
|
|
39
|
+
const [copied, setCopied] = useState(false);
|
|
40
|
+
const loadProjects = useCallback(async () => {
|
|
41
|
+
if (projectsLoaded) return;
|
|
42
|
+
try {
|
|
43
|
+
const res = await fetch("/api/projects?limit=100&depth=0&sort=name");
|
|
44
|
+
if (res.ok) {
|
|
45
|
+
const json = await res.json();
|
|
46
|
+
setProjects(json.docs?.map((p) => ({ id: p.id, name: p.name })) || []);
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.warn("[support] loadProjects error:", err);
|
|
50
|
+
}
|
|
51
|
+
setProjectsLoaded(true);
|
|
52
|
+
}, [projectsLoaded]);
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
loadProjects();
|
|
55
|
+
}, [loadProjects]);
|
|
56
|
+
const fetchBilling = useCallback(async () => {
|
|
57
|
+
setLoading(true);
|
|
58
|
+
try {
|
|
59
|
+
const params = new URLSearchParams({ from, to });
|
|
60
|
+
if (projectId) params.set("projectId", projectId);
|
|
61
|
+
const res = await fetch(`/api/support/billing?${params}`);
|
|
62
|
+
if (res.ok) setData(await res.json());
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.warn("[support] fetchBilling error:", err);
|
|
65
|
+
}
|
|
66
|
+
setLoading(false);
|
|
67
|
+
}, [from, to, projectId]);
|
|
68
|
+
const setPeriod = (range) => {
|
|
69
|
+
setFrom(range.from);
|
|
70
|
+
setTo(range.to);
|
|
71
|
+
};
|
|
72
|
+
const copyRecap = useCallback(() => {
|
|
73
|
+
if (!data) return;
|
|
74
|
+
const lines = [`PRE-FACTURATION -- Du ${from} au ${to}`, `Taux horaire : ${rate} EUR/h`, "=".repeat(50)];
|
|
75
|
+
for (const group of data.groups) {
|
|
76
|
+
lines.push("", `PROJET : ${group.project?.name || "Sans projet"}`);
|
|
77
|
+
if (group.client?.company) lines.push(`Client : ${group.client.company}`);
|
|
78
|
+
for (const ticket of group.tickets) {
|
|
79
|
+
lines.push(` ${ticket.ticketNumber} -- ${ticket.subject}`);
|
|
80
|
+
for (const entry of ticket.entries) lines.push(` ${entry.date} | ${formatDuration(entry.duration)} | ${entry.description || "-"}`);
|
|
81
|
+
lines.push(` Sous-total : ${formatDuration(ticket.totalMinutes)} = ${formatAmount(ticket.totalMinutes, rate)} EUR`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
lines.push("", "=".repeat(50), `TOTAL : ${formatDuration(data.grandTotalMinutes)} = ${formatAmount(data.grandTotalMinutes, rate)} EUR`);
|
|
85
|
+
navigator.clipboard.writeText(lines.join("\n"));
|
|
86
|
+
setCopied(true);
|
|
87
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
88
|
+
}, [data, from, to, rate]);
|
|
89
|
+
const S = {
|
|
90
|
+
page: { padding: "20px 30px", maxWidth: 1100, margin: "0 auto" },
|
|
91
|
+
filters: { marginBottom: 20 },
|
|
92
|
+
quickPeriod: { display: "flex", gap: 6, marginBottom: 8 },
|
|
93
|
+
btn: { padding: "6px 12px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 12, cursor: "pointer", background: "var(--theme-elevation-0)", color: "var(--theme-text)" },
|
|
94
|
+
btnPrimary: { padding: "6px 12px", borderRadius: 6, border: "none", fontSize: 12, cursor: "pointer", background: "#2563eb", color: "#fff", fontWeight: 600 },
|
|
95
|
+
filterRow: { display: "flex", gap: 12, alignItems: "flex-end", flexWrap: "wrap" },
|
|
96
|
+
fieldGroup: { display: "flex", flexDirection: "column", gap: 4 },
|
|
97
|
+
label: { fontSize: 11, fontWeight: 600, color: "var(--theme-elevation-500)" },
|
|
98
|
+
input: { padding: "6px 10px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 12, color: "var(--theme-text)", background: "var(--theme-elevation-0)" },
|
|
99
|
+
select: { padding: "6px 10px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 12, color: "var(--theme-text)", background: "var(--theme-elevation-0)" },
|
|
100
|
+
groupCard: { marginBottom: 16, borderRadius: 10, border: "1px solid var(--theme-elevation-150)", overflow: "hidden" },
|
|
101
|
+
groupHeader: { display: "flex", justifyContent: "space-between", padding: "12px 16px", background: "var(--theme-elevation-50)", borderBottom: "1px solid var(--theme-elevation-150)" },
|
|
102
|
+
table: { width: "100%", borderCollapse: "collapse", fontSize: 12 },
|
|
103
|
+
th: { textAlign: "left", padding: "6px 8px", borderBottom: "1px solid var(--theme-elevation-200)", fontSize: 11, color: "var(--theme-elevation-500)" },
|
|
104
|
+
td: { padding: "6px 8px", borderBottom: "1px solid var(--theme-elevation-100)" },
|
|
105
|
+
grandTotal: { padding: 16, borderRadius: 10, border: "2px solid #2563eb", display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 16 }
|
|
106
|
+
};
|
|
107
|
+
return /* @__PURE__ */ jsxs("div", { style: S.page, children: [
|
|
108
|
+
/* @__PURE__ */ jsxs("div", { style: { marginBottom: 16 }, children: [
|
|
109
|
+
/* @__PURE__ */ jsx("h1", { style: { fontSize: 22, fontWeight: 700, margin: 0 }, children: t("billing.title") }),
|
|
110
|
+
/* @__PURE__ */ jsx("p", { style: { fontSize: 13, color: "var(--theme-elevation-500)", margin: "4px 0 0" }, children: t("billing.subtitle") })
|
|
111
|
+
] }),
|
|
112
|
+
/* @__PURE__ */ jsxs("div", { style: S.filters, children: [
|
|
113
|
+
/* @__PURE__ */ jsxs("div", { style: S.quickPeriod, children: [
|
|
114
|
+
/* @__PURE__ */ jsx("button", { style: S.btnPrimary, onClick: () => setPeriod(getMonthRange(0)), children: t("billing.filters.thisMonth") }),
|
|
115
|
+
/* @__PURE__ */ jsx("button", { style: S.btn, onClick: () => setPeriod(getMonthRange(-1)), children: t("billing.filters.lastMonth") }),
|
|
116
|
+
/* @__PURE__ */ jsx("button", { style: S.btn, onClick: () => setPeriod(getQuarterRange(0)), children: t("billing.filters.thisQuarter") })
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ jsxs("div", { style: S.filterRow, children: [
|
|
119
|
+
/* @__PURE__ */ jsxs("div", { style: S.fieldGroup, children: [
|
|
120
|
+
/* @__PURE__ */ jsx("label", { style: S.label, children: t("billing.filters.from") }),
|
|
121
|
+
/* @__PURE__ */ jsx("input", { type: "date", value: from, onChange: (e) => setFrom(e.target.value), style: S.input })
|
|
122
|
+
] }),
|
|
123
|
+
/* @__PURE__ */ jsxs("div", { style: S.fieldGroup, children: [
|
|
124
|
+
/* @__PURE__ */ jsx("label", { style: S.label, children: t("billing.filters.to") }),
|
|
125
|
+
/* @__PURE__ */ jsx("input", { type: "date", value: to, onChange: (e) => setTo(e.target.value), style: S.input })
|
|
126
|
+
] }),
|
|
127
|
+
/* @__PURE__ */ jsxs("div", { style: S.fieldGroup, children: [
|
|
128
|
+
/* @__PURE__ */ jsx("label", { style: S.label, children: t("billing.filters.project") }),
|
|
129
|
+
/* @__PURE__ */ jsxs("select", { value: projectId, onChange: (e) => setProjectId(e.target.value), style: S.select, children: [
|
|
130
|
+
/* @__PURE__ */ jsx("option", { value: "", children: t("common.all") }),
|
|
131
|
+
projects.map((p) => /* @__PURE__ */ jsx("option", { value: p.id, children: p.name }, p.id))
|
|
132
|
+
] })
|
|
133
|
+
] }),
|
|
134
|
+
/* @__PURE__ */ jsxs("div", { style: S.fieldGroup, children: [
|
|
135
|
+
/* @__PURE__ */ jsx("label", { style: S.label, children: t("billing.filters.hourlyRate") }),
|
|
136
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 4, alignItems: "center" }, children: [
|
|
137
|
+
/* @__PURE__ */ jsx("input", { type: "number", value: rate, onChange: (e) => setRate(Number(e.target.value)), style: { ...S.input, width: 70 }, min: 0 }),
|
|
138
|
+
/* @__PURE__ */ jsx("span", { style: { fontSize: 11 }, children: t("billing.filters.rateUnit") })
|
|
139
|
+
] })
|
|
140
|
+
] }),
|
|
141
|
+
/* @__PURE__ */ jsx("button", { style: S.btnPrimary, onClick: fetchBilling, disabled: loading, children: loading ? t("billing.filters.loading") : t("billing.filters.load") })
|
|
142
|
+
] })
|
|
143
|
+
] }),
|
|
144
|
+
data && /* @__PURE__ */ jsx(Fragment, { children: data.groups.length === 0 ? /* @__PURE__ */ jsx("div", { style: { padding: 40, textAlign: "center", color: "#94a3b8" }, children: t("billing.empty") }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
145
|
+
data.groups.map((group, gi) => /* @__PURE__ */ jsxs("div", { style: S.groupCard, children: [
|
|
146
|
+
/* @__PURE__ */ jsxs("div", { style: S.groupHeader, children: [
|
|
147
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
148
|
+
/* @__PURE__ */ jsx("span", { style: { fontWeight: 700 }, children: group.project?.name || "Sans projet" }),
|
|
149
|
+
group.client?.company && /* @__PURE__ */ jsxs("span", { style: { color: "var(--theme-elevation-500)" }, children: [
|
|
150
|
+
" -- ",
|
|
151
|
+
group.client.company
|
|
152
|
+
] })
|
|
153
|
+
] }),
|
|
154
|
+
/* @__PURE__ */ jsxs("div", { style: { textAlign: "right" }, children: [
|
|
155
|
+
/* @__PURE__ */ jsx("div", { style: { fontWeight: 700 }, children: formatDuration(group.totalMinutes) }),
|
|
156
|
+
/* @__PURE__ */ jsxs("div", { style: { fontSize: 12, color: "#2563eb", fontWeight: 600 }, children: [
|
|
157
|
+
formatAmount(group.totalMinutes, rate),
|
|
158
|
+
" EUR"
|
|
159
|
+
] })
|
|
160
|
+
] })
|
|
161
|
+
] }),
|
|
162
|
+
/* @__PURE__ */ jsxs("table", { style: S.table, children: [
|
|
163
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
164
|
+
/* @__PURE__ */ jsx("th", { style: S.th, children: t("billing.table.ticketNumber") }),
|
|
165
|
+
/* @__PURE__ */ jsx("th", { style: S.th, children: t("billing.table.subject") }),
|
|
166
|
+
/* @__PURE__ */ jsx("th", { style: S.th, children: t("billing.table.date") }),
|
|
167
|
+
/* @__PURE__ */ jsx("th", { style: S.th, children: t("billing.table.duration") }),
|
|
168
|
+
/* @__PURE__ */ jsx("th", { style: S.th, children: t("billing.table.description") }),
|
|
169
|
+
/* @__PURE__ */ jsx("th", { style: { ...S.th, textAlign: "right" }, children: t("billing.table.amount") })
|
|
170
|
+
] }) }),
|
|
171
|
+
/* @__PURE__ */ jsx("tbody", { children: group.tickets.map((ticket) => ticket.entries.map((entry, ei) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
172
|
+
ei === 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
173
|
+
/* @__PURE__ */ jsx("td", { style: { ...S.td, fontWeight: 600 }, rowSpan: ticket.entries.length, children: /* @__PURE__ */ jsx("a", { href: `/admin/support/ticket?id=${ticket.id}`, style: { color: "#2563eb", textDecoration: "none" }, children: ticket.ticketNumber }) }),
|
|
174
|
+
/* @__PURE__ */ jsx("td", { style: S.td, rowSpan: ticket.entries.length, children: ticket.subject })
|
|
175
|
+
] }),
|
|
176
|
+
/* @__PURE__ */ jsx("td", { style: S.td, children: entry.date }),
|
|
177
|
+
/* @__PURE__ */ jsx("td", { style: S.td, children: formatDuration(entry.duration) }),
|
|
178
|
+
/* @__PURE__ */ jsx("td", { style: S.td, children: entry.description || "-" }),
|
|
179
|
+
/* @__PURE__ */ jsxs("td", { style: { ...S.td, textAlign: "right", fontWeight: 600 }, children: [
|
|
180
|
+
formatAmount(entry.duration, rate),
|
|
181
|
+
" EUR"
|
|
182
|
+
] })
|
|
183
|
+
] }, `${ticket.id}-${ei}`))) })
|
|
184
|
+
] })
|
|
185
|
+
] }, gi)),
|
|
186
|
+
/* @__PURE__ */ jsxs("div", { style: S.grandTotal, children: [
|
|
187
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
188
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "var(--theme-elevation-500)" }, children: t("billing.totals.billableTicketsPlural", { count: String(data.groups.reduce((s2, g) => s2 + g.tickets.length, 0)) }) }),
|
|
189
|
+
/* @__PURE__ */ jsxs("div", { style: { fontSize: 18, fontWeight: 700 }, children: [
|
|
190
|
+
t("billing.totals.total"),
|
|
191
|
+
" : ",
|
|
192
|
+
formatDuration(data.grandTotalMinutes),
|
|
193
|
+
" = ",
|
|
194
|
+
formatAmount(data.grandTotalMinutes, rate),
|
|
195
|
+
" EUR"
|
|
196
|
+
] })
|
|
197
|
+
] }),
|
|
198
|
+
/* @__PURE__ */ jsx("button", { style: S.btnPrimary, onClick: copyRecap, children: copied ? t("billing.totals.copiedRecap") : t("billing.totals.copyRecap") })
|
|
199
|
+
] })
|
|
200
|
+
] }) })
|
|
201
|
+
] });
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export { BillingClient };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var templates = require('@payloadcms/next/templates');
|
|
7
|
+
var navigation = require('next/navigation');
|
|
8
|
+
var ErrorBoundary = require('../shared/ErrorBoundary');
|
|
9
|
+
var client = require('./client');
|
|
10
|
+
|
|
11
|
+
const BillingView = ({ initPageResult }) => {
|
|
12
|
+
const { req, visibleEntities } = initPageResult;
|
|
13
|
+
if (!req.user) {
|
|
14
|
+
navigation.redirect("/admin/login");
|
|
15
|
+
}
|
|
16
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
17
|
+
templates.DefaultTemplate,
|
|
18
|
+
{
|
|
19
|
+
i18n: req.i18n,
|
|
20
|
+
locale: initPageResult.locale,
|
|
21
|
+
params: {},
|
|
22
|
+
payload: req.payload,
|
|
23
|
+
permissions: initPageResult.permissions,
|
|
24
|
+
searchParams: {},
|
|
25
|
+
user: req.user,
|
|
26
|
+
visibleEntities,
|
|
27
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary.AdminErrorBoundary, { viewName: "BillingView", children: /* @__PURE__ */ jsxRuntime.jsx(client.BillingClient, {}) })
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
var BillingView_default = BillingView;
|
|
32
|
+
|
|
33
|
+
exports.BillingView = BillingView;
|
|
34
|
+
exports.default = BillingView_default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { DefaultTemplate } from '@payloadcms/next/templates';
|
|
3
|
+
import { redirect } from 'next/navigation';
|
|
4
|
+
import { AdminErrorBoundary } from '../shared/ErrorBoundary';
|
|
5
|
+
import { BillingClient } from './client';
|
|
6
|
+
|
|
7
|
+
const BillingView = ({ initPageResult }) => {
|
|
8
|
+
const { req, visibleEntities } = initPageResult;
|
|
9
|
+
if (!req.user) {
|
|
10
|
+
redirect("/admin/login");
|
|
11
|
+
}
|
|
12
|
+
return /* @__PURE__ */ jsx(
|
|
13
|
+
DefaultTemplate,
|
|
14
|
+
{
|
|
15
|
+
i18n: req.i18n,
|
|
16
|
+
locale: initPageResult.locale,
|
|
17
|
+
params: {},
|
|
18
|
+
payload: req.payload,
|
|
19
|
+
permissions: initPageResult.permissions,
|
|
20
|
+
searchParams: {},
|
|
21
|
+
user: req.user,
|
|
22
|
+
visibleEntities,
|
|
23
|
+
children: /* @__PURE__ */ jsx(AdminErrorBoundary, { viewName: "BillingView", children: /* @__PURE__ */ jsx(BillingClient, {}) })
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
var BillingView_default = BillingView;
|
|
28
|
+
|
|
29
|
+
export { BillingView, BillingView_default as default };
|