@7365admin1/layer-common 4.97.1-staging.733 → 4.97.1-staging.735

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.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * DV-1787: shared wording for checkouts (stock issued for a work order / to come back by a date),
3
+ * used by the Checked out list, My Stock and a work order's Issued items.
4
+ */
5
+
6
+ /** A return date is a calendar day saved as midnight UTC: the same day as a local Date, wherever the browser is. */
7
+ export function returnDayKey(d: string): Date {
8
+ const [y, m, day] = String(d).slice(0, 10).split("-").map(Number);
9
+ return new Date(y, m - 1, day);
10
+ }
11
+
12
+ type TChip = { text: string; color: string; icon: string; info: string };
13
+
14
+ const ENDED: Record<string, TChip> = {
15
+ returned: { text: "Returned", color: "success", icon: "mdi-check", info: "Back in the store. Nothing more to do." },
16
+ written_off: {
17
+ text: "Written off",
18
+ color: "grey",
19
+ icon: "mdi-close-circle-outline",
20
+ info: "Written off (lost, damaged, spoilt or used up). It is not coming back to the store.",
21
+ },
22
+ used: { text: "Used", color: "grey", icon: "mdi-check", info: "Used up on the job, so it is not coming back to the store." },
23
+ handed_over: {
24
+ text: "Handed over",
25
+ color: "grey",
26
+ icon: "mdi-account-switch-outline",
27
+ info: "Passed to a colleague. They have it now: see their row for its status.",
28
+ },
29
+ closed: { text: "Closed", color: "grey", icon: "mdi-check", info: "Closed: it is no longer out with anyone." },
30
+ };
31
+
32
+ /** Out / Due today / Overdue N days, or how it ended - with `info`, what the status means (hover). */
33
+ export function checkoutChip(c: { status: string; overdue?: boolean; daysOverdue?: number; returnDate?: string | null }): TChip {
34
+ if (c.status !== "out") return ENDED[c.status] ?? ENDED.closed;
35
+ if (c.overdue) {
36
+ const n = c.daysOverdue ?? 0;
37
+ return {
38
+ text: `Overdue ${n} ${n === 1 ? "day" : "days"}`,
39
+ color: "error",
40
+ icon: "mdi-alarm",
41
+ info: "Past its return date and still not returned. The person and the store keepers get a reminder every day until it comes back.",
42
+ };
43
+ }
44
+ const today = new Date().toLocaleDateString("en-CA", { timeZone: "Asia/Singapore" });
45
+ if (c.returnDate && String(c.returnDate).slice(0, 10) === today) {
46
+ return { text: "Due today", color: "warning", icon: "mdi-clock-outline", info: "Must be back in the store today. From tomorrow it shows as overdue." };
47
+ }
48
+ return c.returnDate
49
+ ? {
50
+ text: "Not returned yet",
51
+ color: "info",
52
+ icon: "mdi-arrow-top-right",
53
+ info: "Still with the person. The return date has not come yet, so it is not overdue.",
54
+ }
55
+ : {
56
+ text: "Out",
57
+ color: "info",
58
+ icon: "mdi-arrow-top-right",
59
+ info: "With the person, for the work order. No return date was set, so it is never overdue. It closes when returned, used up, written off or handed over.",
60
+ };
61
+ }
62
+
63
+ /** "Return asked": the holder asked to return it; a store keeper accepts it when they have it. */
64
+ export const RETURN_ASKED_INFO = "The person asked to return it. It stays with them until a store keeper accepts the return.";