@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,193 @@
1
+ /*****************************************************************************
2
+ * OperationBilling Model ver 1.0.0
3
+ * @author shisyamo4131
4
+ * ---------------------------------------------------------------------------
5
+ * - Extends OperationResult class to represent the billing of an operation.
6
+ * - This class provides the same functionality as OperationResult but with a different semantic meaning
7
+ * focused on billing operations rather than general operation results.
8
+ * - All properties, computed values, and methods are inherited from OperationResult.
9
+ * - The `className` is set to "稼働請求" (Operation Billing) to distinguish it from OperationResult.
10
+ * - The `create` method is overridden to indicate that creation of OperationBilling instances
11
+ * is not implemented, as billing records are typically generated through the OperationResult class.
12
+ * ---------------------------------------------------------------------------
13
+ * @inherited - The following properties are inherited from OperationResult:
14
+ * @props {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
15
+ * - If this OperationBilling was created from a SiteOperationSchedule, this property holds that ID.
16
+ * - If this property is set, the instance cannot be deleted.
17
+ * @props {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
18
+ * @props {number} adjustedQuantityBase - Adjusted quantity for base workers
19
+ * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
20
+ * @props {number} adjustedOvertimeBase - Adjusted overtime for base workers
21
+ * - Overtime used for billing base workers when `useAdjustedQuantity` is true.
22
+ * @props {number} adjustedQuantityQualified - Adjusted quantity for qualified workers
23
+ * - Quantity used for billing qualified workers when `useAdjustedQuantity` is true.
24
+ * @props {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
25
+ * - Overtime used for billing qualified workers when `useAdjustedQuantity` is true.
26
+ * @props {Date} billingDateAt - Billing date
27
+ * ---------------------------------------------------------------------------
28
+ * @inherited - The following properties are inherited from Operation (via OperationResult):
29
+ * @props {string} siteId - Site document ID (trigger property)
30
+ * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
31
+ * @props {number} requiredPersonnel - Required number of personnel
32
+ * @props {boolean} qualificationRequired - Qualification required flag
33
+ * @props {string} workDescription - Work description
34
+ * @props {string} remarks - Remarks
35
+ * @props {Array<OperationResultDetail>} employees - Assigned employees
36
+ * - Array of `OperationResultDetail` instances representing assigned employees
37
+ * @props {Array<OperationResultDetail>} outsourcers - Assigned outsourcers
38
+ * - Array of `OperationResultDetail` instances representing assigned outsourcers
39
+ * ---------------------------------------------------------------------------
40
+ * @inherited - The following properties are inherited from Agreement (via OperationResult):
41
+ * @props {number} unitPriceBase - Base unit price (JPY)
42
+ * @props {number} overtimeUnitPriceBase - Overtime unit price (JPY/hour)
43
+ * @props {number} unitPriceQualified - Qualified unit price (JPY)
44
+ * @props {number} overtimeUnitPriceQualified - Qualified overtime unit price (JPY/hour)
45
+ * @props {string} billingUnitType - Billing unit type
46
+ * @props {boolean} includeBreakInBilling - Whether to include break time in billing if `billingUnitType` is `PER_HOUR`.
47
+ * @props {number} cutoffDate - Cutoff date value from CutoffDate.VALUES
48
+ * - The cutoff date for billing, using values defined in the CutoffDate utility class.
49
+ * ---------------------------------------------------------------------------
50
+ * @inherited - The following properties are inherited from WorkingResult (via OperationResult):
51
+ * @props {Date} dateAt - Date of operation (placement date) (trigger property)
52
+ * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
53
+ * @props {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
54
+ * @props {string} shiftType - `DAY` or `NIGHT` (trigger property)
55
+ * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
56
+ * @props {string} startTime - Start time (HH:MM format)
57
+ * @props {boolean} isStartNextDay - Next day start flag
58
+ * - `true` if the actual work starts the day after the placement date `dateAt`
59
+ * @props {string} endTime - End time (HH:MM format)
60
+ * @props {number} breakMinutes - Break time (minutes)
61
+ * @props {number} regulationWorkMinutes - Regulation work minutes (trigger property)
62
+ * - Indicates the maximum working time treated as regular working hours.
63
+ * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
64
+ * ---------------------------------------------------------------------------
65
+ * @inherited - The following computed properties are inherited from OperationResult:
66
+ * @computed {Object} statistics - Statistics of workers (read-only)
67
+ * - Contains counts and total work minutes for base and qualified workers, including OJT breakdowns.
68
+ * - Structure: { base: {...}, qualified: {...}, total: {...} }
69
+ * @computed {Object} sales - Sales amounts (read-only)
70
+ * - Contains sales calculations for base and qualified workers, including overtime breakdowns.
71
+ * - Structure: { base: {...}, qualified: {...} }
72
+ * @computed {number} salesAmount - Total sales amount (read-only)
73
+ * - Sum of sales amounts for base and qualified workers with rounding applied.
74
+ * @computed {number} tax - Calculated tax amount (read-only)
75
+ * - Calculated using the `Tax` utility based on `salesAmount` and `date`.
76
+ * @computed {number} billingAmount - Total billing amount including tax (read-only)
77
+ * - Sum of `salesAmount` and `tax`.
78
+ * ---------------------------------------------------------------------------
79
+ * @inherited - The following computed properties are inherited from Operation (via OperationResult):
80
+ * @computed {Array<string>} employeeIds - Array of employee IDs from `employees` (read-only)
81
+ * @computed {Array<string>} outsourcerIds - Array of outsourcer IDs from `outsourcers` (read-only)
82
+ * @computed {number} employeesCount - Count of assigned employees (read-only)
83
+ * @computed {number} outsourcersCount - Count of assigned outsourcers (sum of amounts) (read-only)
84
+ * @computed {boolean} isPersonnelShortage - Indicates if there is a shortage of personnel (read-only)
85
+ * - `true` if the sum of `employeesCount` and `outsourcersCount` is less than `requiredPersonnel`
86
+ * @computed {Array<OperationResultDetail>} workers - Combined array of `employees` and `outsourcers` (read-only)
87
+ * - Getter: Returns concatenated array of employees and outsourcers
88
+ * - Setter: Splits array into employees and outsourcers based on `isEmployee` property
89
+ * ---------------------------------------------------------------------------
90
+ * @inherited - The following computed properties are inherited from WorkingResult (via OperationResult):
91
+ * @computed {string} date - Date string in YYYY-MM-DD format based on `dateAt` (read-only)
92
+ * - Returns a string in the format YYYY-MM-DD based on `dateAt`.
93
+ * @computed {Date} startAt - Start date and time (Date object) (read-only)
94
+ * - Returns a Date object with `startTime` set based on `dateAt`.
95
+ * - If `isStartNextDay` is true, add 1 day.
96
+ * @computed {Date} endAt - End date and time (Date object) (read-only)
97
+ * - Returns a Date object with `endTime` set based on `dateAt`.
98
+ * - If `isStartNextDay` is true, add 1 day.
99
+ * - If `isSpansNextDay` is true, add 1 day.
100
+ * @computed {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
101
+ * - `true` if `startTime` is later than `endTime`
102
+ * @computed {number} totalWorkMinutes - Total working time in minutes (excluding break time) (read-only)
103
+ * - Calculated as the difference between `endAt` and `startAt` minus `breakMinutes`
104
+ * @computed {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
105
+ * - The portion of `totalWorkMinutes` that is considered within the contract's `regulationWorkMinutes`.
106
+ * @computed {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
107
+ * - Calculated as `totalWorkMinutes` minus `regulationWorkMinutes`
108
+ * ---------------------------------------------------------------------------
109
+ * @inherited - The following getter properties are inherited from Operation (via OperationResult):
110
+ * @getter {string} groupKey - Combines `siteId`, `shiftType`, and `date` to indicate operation grouping (read-only)
111
+ * @getter {boolean} isEmployeesChanged - Indicates whether the employees have changed (read-only)
112
+ * - Returns true if the employee IDs have changed compared to `_beforeData`
113
+ * @getter {boolean} isOutsourcersChanged - Indicates whether the outsourcers have changed (read-only)
114
+ * - Returns true if the outsourcer IDs have changed compared to `_beforeData`
115
+ * @getter {Array<OperationResultDetail>} addedWorkers - An array of workers that have been added (read-only)
116
+ * - Workers that exist in current data but not in `_beforeData`
117
+ * @getter {Array<OperationResultDetail>} removedWorkers - An array of workers that have been removed (read-only)
118
+ * - Workers that exist in `_beforeData` but not in current data
119
+ * @getter {Array<OperationResultDetail>} updatedWorkers - An array of workers that have been updated (read-only)
120
+ * - Workers whose `startTime`, `isStartNextDay`, `endTime`, `breakMinutes`, `isQualified`, or `isOjt` have changed
121
+ * ---------------------------------------------------------------------------
122
+ * @inherited - The following getter properties are inherited from WorkingResult (via OperationResult):
123
+ * @getter {number} startHour - Start hour (0-23) (read-only)
124
+ * - Extracted from `startTime`.
125
+ * @getter {number} startMinute - Start minute (0-59) (read-only)
126
+ * - Extracted from `startTime`.
127
+ * @getter {number} endHour - End hour (0-23) (read-only)
128
+ * - Extracted from `endTime`.
129
+ * @getter {number} endMinute - End minute (0-59) (read-only)
130
+ * - Extracted from `endTime`.
131
+ * ---------------------------------------------------------------------------
132
+ * @inherited - The following methods are inherited from OperationResult:
133
+ * @method {function} beforeDelete - Override method to prevent deletion with siteOperationScheduleId
134
+ * - Prevents deletion if the instance has `siteOperationScheduleId`.
135
+ * - Throws an error if deletion is attempted on an instance created from SiteOperationSchedule.
136
+ * ---------------------------------------------------------------------------
137
+ * @inherited - The following methods are inherited from Operation (via OperationResult):
138
+ * @method {function} addWorker - Adds a new worker (employee or outsourcer)
139
+ * - @param {Object} options - Options for adding a worker
140
+ * - @param {string} options.id - The worker ID (employeeId or outsourcerId)
141
+ * - @param {boolean} [options.isEmployee=true] - Whether the worker is an employee
142
+ * - @param {number} [index=0] - Insertion position. If -1, adds to the end
143
+ * @method {function} moveWorker - Moves the position of a worker (employee or outsourcer)
144
+ * - @param {Object} options - Options for changing worker position
145
+ * - @param {number} options.oldIndex - The original index
146
+ * - @param {number} options.newIndex - The new index
147
+ * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
148
+ * @method {function} changeWorker - Changes the details of a worker
149
+ * - @param {Object} newWorker - New worker object
150
+ * @method {function} removeWorker - Removes a worker (employee or outsourcer)
151
+ * - @param {Object} options - Options for removing a worker
152
+ * - @param {string} options.workerId - The ID of the employee or outsourcer
153
+ * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
154
+ * @method {function} setSiteIdCallback - Callback method called when `siteId` is set
155
+ * - Override this method in subclasses to add custom behavior when `siteId` changes.
156
+ * - By default, does nothing.
157
+ * - @param {string} v - The new `siteId` value
158
+ * @method {function} setShiftTypeCallback - Callback method called when `shiftType` is set
159
+ * - Override this method in subclasses to add custom behavior when `shiftType` changes.
160
+ * - By default, does nothing.
161
+ * - @param {string} v - The new `shiftType` value
162
+ * @method {function} setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
163
+ * - Override this method in subclasses to add custom behavior when `regulationWorkMinutes` changes.
164
+ * - By default, does nothing.
165
+ * - @param {number} v - The new `regulationWorkMinutes` value
166
+ * @static
167
+ * @method groupKeyDivider
168
+ * Returns an array dividing the key into siteId, shiftType, and date.
169
+ * @param {Object|string} key - The combined key string or object
170
+ * @returns {Array<string>} - Array containing [siteId, shiftType, date]
171
+ * @throws {Error} - If the key is invalid.
172
+ * ---------------------------------------------------------------------------
173
+ * @inherited - The following method is inherited from WorkingResult (via OperationResult):
174
+ * @method {function} setDateAtCallback - Callback method called when `dateAt` is set
175
+ * - Override this method in subclasses to add custom behavior when `dateAt` changes.
176
+ * - By default, updates `dayType` based on the new `dateAt` value and synchronizes to workers.
177
+ * - @param {Date} v - The new `dateAt` value
178
+ *****************************************************************************/
179
+ import OperationResult from "./OperationResult.js";
180
+
181
+ export default class OperationBilling extends OperationResult {
182
+ static className = "稼働請求";
183
+
184
+ static headers = [
185
+ { title: "日付", key: "dateAt" },
186
+ { title: "現場", key: "siteId", value: "siteId" },
187
+ { title: "売上金額", key: "salesAmount", value: "salesAmount" },
188
+ ];
189
+
190
+ async create() {
191
+ return Promise.reject(new Error("[OperationBilling.js] Not implemented."));
192
+ }
193
+ }
@@ -0,0 +1,147 @@
1
+ /*****************************************************************************
2
+ * OperationDetail Model ver 1.0.0
3
+ * @author shisyamo4131
4
+ * ---------------------------------------------------------------------------
5
+ * - Base class for SiteOperationScheduleDetail and OperationResultDetail.
6
+ * - Extends WorkingResult class, inheriting all working time calculation functionality
7
+ * - This class is intended to be inherited by other classes so, it cannot be instantiated directly.
8
+ * - Employee or Outsourcer document ID is stored in the id property.
9
+ * This is useful for specifying as a key for tables.
10
+ * - `amount` property is always fixed at 1 (reserved for future extension).
11
+ * - `startTime` and `endTime` are managed as strings in HH:MM format.
12
+ * - `isEmployee` property distinguishes between Employee and Outsourcer.
13
+ * - `employeeId` and `outsourcerId` properties can be used to get each ID (null if not applicable).
14
+ * --------------------------------------------------------------------------
15
+ * @props {string} id - Employee or Outsourcer document ID
16
+ * @props {number} index - Identifier index for Outsourcer (always 0 for Employee)
17
+ * @props {boolean} isEmployee - Employee flag (true: Employee, false: Outsourcer)
18
+ * @props {number} amount - Number of placements (always fixed at 1)
19
+ * @props {string} siteId - Site ID
20
+ * @props {boolean} isQualified - Qualified flag
21
+ * @props {boolean} isOjt - OJT flag
22
+ * --------------------------------------------------------------------------
23
+ * @computed {string} workerId - Worker ID (read-only)
24
+ * - For Employee, it's the same as `id`, for Outsourcer, it's a concatenation of `id` and `index` with ':'
25
+ * @computed {string|null} employeeId - Employee ID (null if not applicable) (read-only)
26
+ * @computed {string|null} outsourcerId - Outsourcer ID (null if not applicable) (read-only)
27
+ * --------------------------------------------------------------------------
28
+ * @inherited - The following properties are inherited from WorkingResult:
29
+ * @props {Date} dateAt - Placement date (trigger property)
30
+ * @props {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
31
+ * @props {string} shiftType - `DAY` or `NIGHT`
32
+ * @props {string} startTime - Start time (HH:MM format)
33
+ * @props {boolean} isStartNextDay - Next day start flag
34
+ * @props {string} endTime - End time (HH:MM format)
35
+ * @props {number} breakMinutes - Break time (minutes)
36
+ * @props {number} regulationWorkMinutes - Regulation work minutes
37
+ * --------------------------------------------------------------------------
38
+ * @inherited - The following computed properties are inherited from WorkingResult:
39
+ * @computed {string} key - Unique key combining `date`, `dayType`, and `shiftType` (read-only)
40
+ * @computed {string} date - Date string in YYYY-MM-DD format based on `dateAt` (read-only)
41
+ * @computed {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
42
+ * @computed {Date} startAt - Start date and time (Date object) (read-only)
43
+ * @computed {Date} endAt - End date and time (Date object) (read-only)
44
+ * @computed {number} totalWorkMinutes - Total working time in minutes (excluding break time) (read-only)
45
+ * @computed {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
46
+ * @computed {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
47
+ * - Calculated as `totalWorkMinutes` minus `regulationWorkMinutes`
48
+ * - Overtime work is not negative; the minimum is 0.
49
+ * --------------------------------------------------------------------------
50
+ * @inherited - The following getter properties are inherited from WorkingResult:
51
+ * @getter {number} startHour - Start hour (0-23) (read-only)
52
+ * - Extracted from `startTime`.
53
+ * @getter {number} startMinute - Start minute (0-59) (read-only)
54
+ * - Extracted from `startTime`.
55
+ * @getter {number} endHour - End hour (0-23) (read-only)
56
+ * - Extracted from `endTime`.
57
+ * @getter {number} endMinute - End minute (0-59) (read-only)
58
+ * - Extracted from `endTime`.
59
+ * ---------------------------------------------------------------------------
60
+ * @inherited - The following method is inherited from WorkingResult:
61
+ * @method {function} setDateAtCallback - Callback method called when `dateAt` is set
62
+ * - Override this method in subclasses to add custom behavior when `dateAt` changes.
63
+ * - By default, updates `dayType` based on the new `dateAt` value.
64
+ * - @param {Date} v - The new `dateAt` value
65
+ *****************************************************************************/
66
+ import { defField } from "./parts/fieldDefinitions.js";
67
+ import WorkingResult from "./WorkingResult.js";
68
+
69
+ const classProps = {
70
+ id: defField("oneLine", { default: "" }),
71
+ index: defField("number", { default: 0 }),
72
+ isEmployee: defField("check", { default: true, required: true }),
73
+ amount: defField("number", { default: 1, required: true, hidden: true }),
74
+ siteId: defField("oneLine", { required: true }),
75
+ ...WorkingResult.classProps, // Inherited from WorkingResult.js
76
+ isQualified: defField("check", { label: "資格者" }),
77
+ isOjt: defField("check", { label: "OJT" }),
78
+ };
79
+
80
+ /**
81
+ * Wrapper to define computed properties.
82
+ * @param {*} obj
83
+ * @param {*} properties
84
+ */
85
+ function defineComputedProperties(obj, properties) {
86
+ const descriptors = {};
87
+ for (const [key, descriptor] of Object.entries(properties)) {
88
+ descriptors[key] = {
89
+ configurable: true,
90
+ enumerable: true,
91
+ ...descriptor,
92
+ };
93
+ }
94
+ Object.defineProperties(obj, descriptors);
95
+ }
96
+
97
+ export default class OperationDetail extends WorkingResult {
98
+ static className = "稼働明細ベース";
99
+ static collectionPath = "OperationDetails";
100
+ static useAutonumber = false;
101
+ static logicalDelete = false;
102
+ static classProps = classProps;
103
+
104
+ /**
105
+ * Constructor
106
+ * - Prevent direct instantiation of OperationDetail class.
107
+ * @param {*} item
108
+ */
109
+ constructor(item = {}) {
110
+ if (new.target === OperationDetail) {
111
+ throw new Error(
112
+ `OperationDetail is an abstract class and cannot be instantiated directly.`
113
+ );
114
+ }
115
+ super(item);
116
+ }
117
+
118
+ /**
119
+ * afterInitialize
120
+ * @param {*} item
121
+ */
122
+ afterInitialize(item = {}) {
123
+ super.afterInitialize(item);
124
+
125
+ /** Define computed properties */
126
+ defineComputedProperties(this, {
127
+ workerId: {
128
+ get() {
129
+ return this.isEmployee ? this.id : `${this.id}:${this.index}`;
130
+ },
131
+ set() {},
132
+ },
133
+ employeeId: {
134
+ get() {
135
+ return this.isEmployee ? this.id : null;
136
+ },
137
+ set() {},
138
+ },
139
+ outsourcerId: {
140
+ get() {
141
+ return !this.isEmployee ? this.id : null;
142
+ },
143
+ set() {},
144
+ },
145
+ });
146
+ }
147
+ }