@shisyamo4131/air-guard-v2-schemas 1.0.0

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.
Files changed (38) hide show
  1. package/index.js +15 -0
  2. package/package.json +44 -0
  3. package/src/Agreement.js +262 -0
  4. package/src/ArrangementNotification.js +505 -0
  5. package/src/Billing.js +159 -0
  6. package/src/Company.js +176 -0
  7. package/src/Customer.js +98 -0
  8. package/src/Employee.js +201 -0
  9. package/src/Operation.js +779 -0
  10. package/src/OperationBilling.js +193 -0
  11. package/src/OperationDetail.js +147 -0
  12. package/src/OperationResult.js +437 -0
  13. package/src/OperationResultDetail.js +72 -0
  14. package/src/Outsourcer.js +46 -0
  15. package/src/RoundSetting.js +123 -0
  16. package/src/Site.js +192 -0
  17. package/src/SiteOperationSchedule.js +503 -0
  18. package/src/SiteOperationScheduleDetail.js +99 -0
  19. package/src/SiteOrder.js +62 -0
  20. package/src/Tax.js +39 -0
  21. package/src/User.js +41 -0
  22. package/src/WorkingResult.js +297 -0
  23. package/src/apis/index.js +9 -0
  24. package/src/constants/arrangement-notification-status.js +68 -0
  25. package/src/constants/billing-unit-type.js +15 -0
  26. package/src/constants/contract-status.js +15 -0
  27. package/src/constants/day-type.js +44 -0
  28. package/src/constants/employment-status.js +15 -0
  29. package/src/constants/gender.js +11 -0
  30. package/src/constants/index.js +9 -0
  31. package/src/constants/prefectures.js +56 -0
  32. package/src/constants/shift-type.js +20 -0
  33. package/src/constants/site-status.js +15 -0
  34. package/src/parts/accessorDefinitions.js +109 -0
  35. package/src/parts/fieldDefinitions.js +642 -0
  36. package/src/utils/ContextualError.js +49 -0
  37. package/src/utils/CutoffDate.js +223 -0
  38. package/src/utils/index.js +48 -0
@@ -0,0 +1,223 @@
1
+ /*****************************************************************************
2
+ * CutoffDate Utility Class ver 1.0.0
3
+ * @author shisyamo4131
4
+ * ---------------------------------------------------------------------------
5
+ * A utility class for managing cutoff date calculations and definitions.
6
+ * - Provides constants for cutoff date values
7
+ * - Provides options for UI selection components
8
+ * - Provides static methods for cutoff date calculations
9
+ * ---------------------------------------------------------------------------
10
+ * @static {Object} VALUES - Cutoff date constant values
11
+ * @static {Array} OPTIONS - Options for selection components
12
+ * @static {function} calculateActualCutoffDay - Calculate actual cutoff day for given year/month
13
+ * @static {function} calculateBillingPeriod - Calculate billing period for given date and cutoff
14
+ * @static {function} calculateCutoffDate - Calculate cutoff date as Date object for given sales date
15
+ * @static {function} calculateCutoffDateString - Calculate cutoff date as string (YYYY-MM-DD) for given sales date
16
+ * @static {function} getDisplayText - Get display text for cutoff date value
17
+ * @static {function} isValidCutoffDate - Validate cutoff date value
18
+ *****************************************************************************/
19
+
20
+ export default class CutoffDate {
21
+ /**
22
+ * Cutoff date constant values
23
+ */
24
+ static VALUES = Object.freeze({
25
+ DAY_5: 5,
26
+ DAY_10: 10,
27
+ DAY_15: 15,
28
+ DAY_20: 20,
29
+ DAY_25: 25,
30
+ END_OF_MONTH: 0,
31
+ });
32
+
33
+ /**
34
+ * Options for selection components
35
+ */
36
+ static OPTIONS = [
37
+ { title: "5日", value: CutoffDate.VALUES.DAY_5 },
38
+ { title: "10日", value: CutoffDate.VALUES.DAY_10 },
39
+ { title: "15日", value: CutoffDate.VALUES.DAY_15 },
40
+ { title: "20日", value: CutoffDate.VALUES.DAY_20 },
41
+ { title: "25日", value: CutoffDate.VALUES.DAY_25 },
42
+ { title: "月末", value: CutoffDate.VALUES.END_OF_MONTH },
43
+ ];
44
+
45
+ /**
46
+ * Calculate actual cutoff day for given year and month
47
+ * @param {number} year - Target year
48
+ * @param {number} month - Target month (0-based: 0=January, 11=December)
49
+ * @param {number} cutoffDateValue - Cutoff date value from VALUES
50
+ * @returns {number} Actual cutoff day
51
+ * @example
52
+ * // Get cutoff day for February 2024 with month-end setting
53
+ * const cutoffDay = CutoffDate.calculateActualCutoffDay(2024, 1, CutoffDate.VALUES.END_OF_MONTH);
54
+ * // Returns 29 (leap year)
55
+ */
56
+ static calculateActualCutoffDay(year, month, cutoffDateValue) {
57
+ if (cutoffDateValue === CutoffDate.VALUES.END_OF_MONTH) {
58
+ // Get last day of the month
59
+ return new Date(year, month + 1, 0).getDate();
60
+ }
61
+ return cutoffDateValue;
62
+ }
63
+
64
+ /**
65
+ * Calculate billing period for given date and cutoff setting
66
+ * @param {Date} targetDate - Target date
67
+ * @param {number} cutoffDateValue - Cutoff date value from VALUES
68
+ * @returns {Object} Billing period object
69
+ * @property {Date} periodStart - Period start date
70
+ * @property {Date} periodEnd - Period end date
71
+ * @property {string} periodLabel - Period label (YYYY-MM format)
72
+ * @example
73
+ * // Calculate billing period for March 15, 2024 with 10th cutoff
74
+ * const period = CutoffDate.calculateBillingPeriod(new Date(2024, 2, 15), CutoffDate.VALUES.DAY_10);
75
+ * // Returns period from March 11 to April 10
76
+ */
77
+ static calculateBillingPeriod(targetDate, cutoffDateValue) {
78
+ const year = targetDate.getFullYear();
79
+ const month = targetDate.getMonth();
80
+ const day = targetDate.getDate();
81
+
82
+ // Calculate cutoff day for current month
83
+ const currentCutoffDay = CutoffDate.calculateActualCutoffDay(
84
+ year,
85
+ month,
86
+ cutoffDateValue
87
+ );
88
+
89
+ let periodStart, periodEnd, periodLabel;
90
+
91
+ if (day <= currentCutoffDay) {
92
+ // Target date is within current month's billing period
93
+ // Period: Previous month's cutoff + 1 to current month's cutoff
94
+ const prevMonth = month - 1;
95
+ const prevYear = prevMonth < 0 ? year - 1 : year;
96
+ const normalizedPrevMonth = prevMonth < 0 ? 11 : prevMonth;
97
+
98
+ const prevCutoffDay = CutoffDate.calculateActualCutoffDay(
99
+ prevYear,
100
+ normalizedPrevMonth,
101
+ cutoffDateValue
102
+ );
103
+
104
+ periodStart = new Date(prevYear, normalizedPrevMonth, prevCutoffDay + 1);
105
+ periodEnd = new Date(year, month, currentCutoffDay);
106
+ periodLabel = `${year}-${String(month + 1).padStart(2, "0")}`;
107
+ } else {
108
+ // Target date is within next month's billing period
109
+ // Period: Current month's cutoff + 1 to next month's cutoff
110
+ const nextMonth = month + 1;
111
+ const nextYear = nextMonth > 11 ? year + 1 : year;
112
+ const normalizedNextMonth = nextMonth > 11 ? 0 : nextMonth;
113
+
114
+ const nextCutoffDay = CutoffDate.calculateActualCutoffDay(
115
+ nextYear,
116
+ normalizedNextMonth,
117
+ cutoffDateValue
118
+ );
119
+
120
+ periodStart = new Date(year, month, currentCutoffDay + 1);
121
+ periodEnd = new Date(nextYear, normalizedNextMonth, nextCutoffDay);
122
+ periodLabel = `${nextYear}-${String(normalizedNextMonth + 1).padStart(
123
+ 2,
124
+ "0"
125
+ )}`;
126
+ }
127
+
128
+ return {
129
+ periodStart,
130
+ periodEnd,
131
+ periodLabel,
132
+ };
133
+ }
134
+
135
+ /**
136
+ * Get display text for cutoff date value
137
+ * @param {number} cutoffDateValue - Cutoff date value from VALUES
138
+ * @returns {string} Display text
139
+ * @example
140
+ * const displayText = CutoffDate.getDisplayText(CutoffDate.VALUES.DAY_10);
141
+ * // Returns "10日"
142
+ */
143
+ static getDisplayText(cutoffDateValue) {
144
+ const option = CutoffDate.OPTIONS.find(
145
+ (opt) => opt.value === cutoffDateValue
146
+ );
147
+ return option ? option.title : "";
148
+ }
149
+
150
+ /**
151
+ * Validate cutoff date value
152
+ * @param {number} cutoffDateValue - Cutoff date value to validate
153
+ * @returns {boolean} True if valid
154
+ */
155
+ static isValidCutoffDate(cutoffDateValue) {
156
+ return Object.values(CutoffDate.VALUES).includes(cutoffDateValue);
157
+ }
158
+
159
+ /**
160
+ * Calculate the cutoff date as Date object for given sales date and cutoff setting
161
+ * @param {Date} salesDate - Sales date
162
+ * @param {number} cutoffDateValue - Cutoff date value from VALUES
163
+ * @returns {Date} Cutoff date as Date object
164
+ * @example
165
+ * // Sales on March 15, 2024 with 10th cutoff
166
+ * const cutoffDate = CutoffDate.calculateCutoffDate(new Date(2024, 2, 15), CutoffDate.VALUES.DAY_10);
167
+ * // Returns Date object for 2024-04-10
168
+ *
169
+ * // Sales on March 5, 2024 with 10th cutoff
170
+ * const cutoffDate = CutoffDate.calculateCutoffDate(new Date(2024, 2, 5), CutoffDate.VALUES.DAY_10);
171
+ * // Returns Date object for 2024-03-10
172
+ */
173
+ static calculateCutoffDate(salesDate, cutoffDateValue) {
174
+ const year = salesDate.getFullYear();
175
+ const month = salesDate.getMonth();
176
+ const day = salesDate.getDate();
177
+
178
+ // Calculate cutoff day for current month
179
+ const currentCutoffDay = CutoffDate.calculateActualCutoffDay(
180
+ year,
181
+ month,
182
+ cutoffDateValue
183
+ );
184
+
185
+ if (day <= currentCutoffDay) {
186
+ // Sales date is within current month's billing period
187
+ // Cutoff date is current month's cutoff day
188
+ return new Date(year, month, currentCutoffDay);
189
+ } else {
190
+ // Sales date is within next month's billing period
191
+ // Cutoff date is next month's cutoff day
192
+ const nextMonth = month + 1;
193
+ const nextYear = nextMonth > 11 ? year + 1 : year;
194
+ const normalizedNextMonth = nextMonth > 11 ? 0 : nextMonth;
195
+
196
+ const nextCutoffDay = CutoffDate.calculateActualCutoffDay(
197
+ nextYear,
198
+ normalizedNextMonth,
199
+ cutoffDateValue
200
+ );
201
+
202
+ return new Date(nextYear, normalizedNextMonth, nextCutoffDay);
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Calculate the cutoff date string (YYYY-MM-DD) for given sales date and cutoff setting
208
+ * @param {Date} salesDate - Sales date
209
+ * @param {number} cutoffDateValue - Cutoff date value from VALUES
210
+ * @returns {string} Cutoff date in YYYY-MM-DD format
211
+ * @example
212
+ * // Sales on March 15, 2024 with 10th cutoff
213
+ * const cutoffDateString = CutoffDate.calculateCutoffDateString(new Date(2024, 2, 15), CutoffDate.VALUES.DAY_10);
214
+ * // Returns "2024-04-10"
215
+ */
216
+ static calculateCutoffDateString(salesDate, cutoffDateValue) {
217
+ const cutoffDate = CutoffDate.calculateCutoffDate(
218
+ salesDate,
219
+ cutoffDateValue
220
+ );
221
+ return cutoffDate.toISOString().split("T")[0];
222
+ }
223
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Utility function to get a Date object at a specific time.
3
+ * This function takes a date and a time string in HH:MM format,
4
+ * and returns a Date object with the specified time set.
5
+ * @param {string|Date} date The date to set the time on. Can be a string or a Date object.
6
+ * If not provided, the current date is used.
7
+ * @param {string} time The time to set in HH:MM format.
8
+ * If not provided, defaults to 00:00 (midnight).
9
+ * @param {number} [dateOffset=0] Optional offset in days to apply to the date.
10
+ * @returns {Date} A Date object with the specified date and time.
11
+ * @throws {Error} If the date is not a string or Date, or if the time is not a string in HH:MM format.
12
+ * @throws {Error} If the time format is invalid.
13
+ */
14
+ export function getDateAt(date, time, dateOffset = 0) {
15
+ // If date is not null/undefined and is not a string or Date, throw an error
16
+ if (date != null && !(typeof date === "string" || date instanceof Date)) {
17
+ throw new Error(
18
+ `[getDateAt] Invalid date type. Expected string or Date, got ${typeof date}`
19
+ );
20
+ }
21
+
22
+ // If time is not null and is not a string, throw an error
23
+ if (time != null && typeof time !== "string") {
24
+ throw new Error(
25
+ `[getDateAt] Invalid time type. Expected string, got ${typeof time}`
26
+ );
27
+ }
28
+
29
+ // If time is provided, split it into hours and minutes
30
+ // If time is not provided, default to 0 hours and 0 minutes
31
+ const [hour, minute] = time ? time.split(":").map(Number) : [0, 0];
32
+ if (isNaN(hour) || isNaN(minute)) {
33
+ throw new Error(
34
+ `[getDateAt] Invalid time format. Expected HH:MM, got ${time}`
35
+ );
36
+ }
37
+
38
+ // If date is not provided, use the current date
39
+ const result = new Date(date || Date.now());
40
+
41
+ // Set the hours and minutes
42
+ result.setHours(hour, minute, 0, 0);
43
+
44
+ result.setDate(result.getDate() + dateOffset);
45
+ return result;
46
+ }
47
+
48
+ export { ContextualError } from "./ContextualError.js";