@shisyamo4131/air-guard-v2-schemas 1.3.1-dev.0 → 1.3.1-dev.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisyamo4131/air-guard-v2-schemas",
3
- "version": "1.3.1-dev.0",
3
+ "version": "1.3.1-dev.11",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/Agreement.js CHANGED
@@ -4,13 +4,13 @@
4
4
  * ---------------------------------------------------------------------------
5
5
  * A class to manage agreement details based on WorkingResult.
6
6
  * ---------------------------------------------------------------------------
7
- * @props {number} unitPriceBase - Base unit price (JPY)
8
- * @props {number} overtimeUnitPriceBase - Overtime unit price (JPY/hour)
9
- * @props {number} unitPriceQualified - Qualified unit price (JPY)
10
- * @props {number} overtimeUnitPriceQualified - Qualified overtime unit price (JPY/hour)
11
- * @props {string} billingUnitType - Billing unit type
12
- * @props {boolean} includeBreakInBilling - Whether to include break time in billing if `billingUnitType` is `PER_HOUR`.
13
- * @props {number} cutoffDate - Cutoff date value from CutoffDate.VALUES
7
+ * @prop {number} unitPriceBase - Base unit price (JPY)
8
+ * @prop {number} overtimeUnitPriceBase - Overtime unit price (JPY/hour)
9
+ * @prop {number} unitPriceQualified - Qualified unit price (JPY)
10
+ * @prop {number} overtimeUnitPriceQualified - Qualified overtime unit price (JPY/hour)
11
+ * @prop {string} billingUnitType - Billing unit type
12
+ * @prop {boolean} includeBreakInBilling - Whether to include break time in billing if `billingUnitType` is `PER_HOUR`.
13
+ * @prop {number} cutoffDate - Cutoff date value from CutoffDate.VALUES
14
14
  * - The cutoff date for billing, using values defined in the CutoffDate utility class.
15
15
  * ---------------------------------------------------------------------------
16
16
  * @getter {Object} prices - Object containing price-related properties (read-only)
@@ -20,15 +20,15 @@
20
20
  * unitPriceQualified, overtimeUnitPriceQualified, billingUnitType, includeBreakInBilling
21
21
  * ---------------------------------------------------------------------------
22
22
  * @inherited - The following properties are inherited from WorkingResult:
23
- * @props {Date} dateAt - Applicable start date (trigger property)
24
- * @props {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
25
- * @props {string} shiftType - Shift type (`DAY`, `NIGHT`)
26
- * @props {string} startTime - Start time (HH:MM format)
27
- * @props {boolean} isStartNextDay - Next day start flag
23
+ * @prop {Date} dateAt - Applicable start date (trigger property)
24
+ * @prop {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
25
+ * @prop {string} shiftType - Shift type (`DAY`, `NIGHT`)
26
+ * @prop {string} startTime - Start time (HH:MM format)
27
+ * @prop {boolean} isStartNextDay - Next day start flag
28
28
  * - `true` if the actual work starts the day after the placement date `dateAt`
29
- * @props {string} endTime - End time (HH:MM format)
30
- * @props {number} breakMinutes - Break time (minutes)
31
- * @props {number} regulationWorkMinutes - Regulation work minutes
29
+ * @prop {string} endTime - End time (HH:MM format)
30
+ * @prop {number} breakMinutes - Break time (minutes)
31
+ * @prop {number} regulationWorkMinutes - Regulation work minutes
32
32
  * - The maximum working time defined by `unitPriceBase` (or `unitPriceQualified`).
33
33
  * - Exceeding this time is considered overtime.
34
34
  * ---------------------------------------------------------------------------
@@ -1,7 +1,8 @@
1
1
  /*****************************************************************************
2
- * OperationBilling Model ver 1.0.0
2
+ * OperationBilling Model
3
+ * @version 1.0.0
3
4
  * @author shisyamo4131
4
- * ---------------------------------------------------------------------------
5
+ *
5
6
  * - Extends OperationResult class to represent the billing of an operation.
6
7
  * - This class provides the same functionality as OperationResult but with a different semantic meaning
7
8
  * focused on billing operations rather than general operation results.
@@ -9,50 +10,13 @@
9
10
  * - The `className` is set to "稼働請求" (Operation Billing) to distinguish it from OperationResult.
10
11
  * - The `create` method is overridden to indicate that creation of OperationBilling instances
11
12
  * is not implemented, as billing records are typically generated through the OperationResult class.
12
- * ---------------------------------------------------------------------------
13
- * @inherited - The following properties are inherited from OperationResult:
14
- * @prop {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
- * @prop {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
18
- * @prop {number} adjustedQuantityBase - Adjusted quantity for base workers
19
- * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
20
- * @prop {number} adjustedOvertimeBase - Adjusted overtime for base workers
21
- * - Overtime used for billing base workers when `useAdjustedQuantity` is true.
22
- * @prop {number} adjustedQuantityQualified - Adjusted quantity for qualified workers
23
- * - Quantity used for billing qualified workers when `useAdjustedQuantity` is true.
24
- * @prop {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
25
- * - Overtime used for billing qualified workers when `useAdjustedQuantity` is true.
26
- * @prop {Date} billingDateAt - Billing date
27
- * - The date used for billing purposes.
28
- * @prop {boolean} isLocked - Lock flag
29
- * - When set to true, the OperationBilling is locked from edits exept for editing as OperationBilling.
30
- * ---------------------------------------------------------------------------
31
- * @inherited - The following properties are inherited from Operation (via OperationResult):
13
+ *
32
14
  * @prop {string} siteId - Site document ID (trigger property)
33
15
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
34
- * @prop {number} requiredPersonnel - Required number of personnel
35
- * @prop {boolean} qualificationRequired - Qualification required flag
36
- * @prop {string} workDescription - Work description
37
- * @prop {string} remarks - Remarks
38
- * @prop {Array<OperationResultDetail>} employees - Assigned employees
39
- * - Array of `OperationResultDetail` instances representing assigned employees
40
- * @prop {Array<OperationResultDetail>} outsourcers - Assigned outsourcers
41
- * - Array of `OperationResultDetail` instances representing assigned outsourcers
42
- * ---------------------------------------------------------------------------
43
- * @inherited - The following properties are inherited from Agreement (via OperationResult):
44
- * @prop {number} unitPriceBase - Base unit price (JPY)
45
- * @prop {number} overtimeUnitPriceBase - Overtime unit price (JPY/hour)
46
- * @prop {number} unitPriceQualified - Qualified unit price (JPY)
47
- * @prop {number} overtimeUnitPriceQualified - Qualified overtime unit price (JPY/hour)
48
- * @prop {string} billingUnitType - Billing unit type
49
- * @prop {boolean} includeBreakInBilling - Whether to include break time in billing if `billingUnitType` is `PER_HOUR`.
50
- * @prop {number} cutoffDate - Cutoff date value from CutoffDate.VALUES
51
- * - The cutoff date for billing, using values defined in the CutoffDate utility class.
52
- * ---------------------------------------------------------------------------
53
- * @inherited - The following properties are inherited from WorkingResult (via OperationResult):
54
16
  * @prop {Date} dateAt - Date of operation (placement date) (trigger property)
55
17
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
18
+ * - Used to determine `dayType`.
19
+ * - When `dateAt` changes, `billingDateAt` is also updated based on `agreement.cutoffDate`.
56
20
  * @prop {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
57
21
  * @prop {string} shiftType - `DAY` or `NIGHT` (trigger property)
58
22
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
@@ -64,52 +28,88 @@
64
28
  * @prop {number} regulationWorkMinutes - Regulation work minutes (trigger property)
65
29
  * - Indicates the maximum working time treated as regular working hours.
66
30
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
67
- * ---------------------------------------------------------------------------
68
- * @inherited - The following computed properties are inherited from OperationResult:
69
- * @computed {Object} statistics - Statistics of workers (read-only)
70
- * - Contains counts and total work minutes for base and qualified workers, including OJT breakdowns.
71
- * - Structure: { base: {...}, qualified: {...}, total: {...} }
72
- * @computed {Object} sales - Sales amounts (read-only)
73
- * - Contains sales calculations for base and qualified workers, including overtime breakdowns.
74
- * - Structure: { base: {...}, qualified: {...} }
75
- * @computed {number} salesAmount - Total sales amount (read-only)
76
- * - Sum of sales amounts for base and qualified workers with rounding applied.
77
- * @computed {number} tax - Calculated tax amount (read-only)
78
- * - Calculated using the `Tax` utility based on `salesAmount` and `date`.
79
- * @computed {number} billingAmount - Total billing amount including tax (read-only)
80
- * - Sum of `salesAmount` and `tax`.
81
- * ---------------------------------------------------------------------------
82
- * @inherited - The following computed properties are inherited from Operation (via OperationResult):
83
- * @computed {Array<string>} employeeIds - Array of employee IDs from `employees` (read-only)
84
- * @computed {Array<string>} outsourcerIds - Array of outsourcer IDs from `outsourcers` (read-only)
85
- * @computed {number} employeesCount - Count of assigned employees (read-only)
86
- * @computed {number} outsourcersCount - Count of assigned outsourcers (sum of amounts) (read-only)
87
- * @computed {boolean} isPersonnelShortage - Indicates if there is a shortage of personnel (read-only)
88
- * - `true` if the sum of `employeesCount` and `outsourcersCount` is less than `requiredPersonnel`
89
- * @computed {Array<OperationResultDetail>} workers - Combined array of `employees` and `outsourcers` (read-only)
31
+ * @prop {number} requiredPersonnel - Required number of personnel
32
+ * @prop {boolean} qualificationRequired - Qualification required flag
33
+ * @prop {string} workDescription - Work description
34
+ * @prop {string} remarks - Remarks
35
+ * @prop {Array<OperationResultDetail>} employees - Assigned employees
36
+ * - Array of `OperationResultDetail` instances representing assigned employees
37
+ * @prop {Array<OperationResultDetail>} outsourcers - Assigned outsourcers
38
+ * - Array of `OperationResultDetail` instances representing assigned outsourcers
39
+ * @prop {Array<OperationResultDetail>} workers - Combined array of `employees` and `outsourcers`
90
40
  * - Getter: Returns concatenated array of employees and outsourcers
91
41
  * - Setter: Splits array into employees and outsourcers based on `isEmployee` property
92
- * ---------------------------------------------------------------------------
93
- * @inherited - The following computed properties are inherited from WorkingResult (via OperationResult):
94
- * @computed {string} date - Date string in YYYY-MM-DD format based on `dateAt` (read-only)
42
+ * @prop {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
43
+ * - If this OperationResult was created from a SiteOperationSchedule, this property holds that ID.
44
+ * - If this property is set, the instance cannot be deleted.
45
+ * @prop {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
46
+ * @prop {number} adjustedQuantityBase - Adjusted quantity for base workers
47
+ * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
48
+ * @prop {number} adjustedOvertimeBase - Adjusted overtime for base workers
49
+ * - Overtime used for billing base workers when `useAdjustedQuantity` is true.
50
+ * @prop {number} adjustedQuantityQualified - Adjusted quantity for qualified workers
51
+ * - Quantity used for billing qualified workers when `useAdjustedQuantity` is true.
52
+ * @prop {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
53
+ * - Overtime used for billing qualified workers when `useAdjustedQuantity` is true.
54
+ * @prop {Date} billingDateAt - Billing date
55
+ * - The date used for billing purposes.
56
+ * @prop {boolean} isLocked - Lock flag
57
+ * - When set to true, the OperationResult is locked from edits exept for editing as OperationBilling.
58
+ * @prop {Agreement|null} agreement - Associated Agreement object
59
+ * - The Agreement instance associated with this OperationResult for pricing and billing information.
60
+ * - When set, it influences billing calculations such as unit prices and billing dates.
61
+ * @prop {boolean} allowEmptyAgreement - Flag to ignore missing Agreement
62
+ * - When set to true, allows the OperationResult to be valid even if no Agreement is associated.
63
+ *
64
+ * @readonly
65
+ * @prop {string} date - Date string in YYYY-MM-DD format based on `dateAt` (read-only)
95
66
  * - Returns a string in the format YYYY-MM-DD based on `dateAt`.
96
- * @computed {Date} startAt - Start date and time (Date object) (read-only)
67
+ * @prop {Date} startAt - Start date and time (Date object) (read-only)
97
68
  * - Returns a Date object with `startTime` set based on `dateAt`.
98
69
  * - If `isStartNextDay` is true, add 1 day.
99
- * @computed {Date} endAt - End date and time (Date object) (read-only)
70
+ * @prop {Date} endAt - End date and time (Date object) (read-only)
100
71
  * - Returns a Date object with `endTime` set based on `dateAt`.
101
72
  * - If `isStartNextDay` is true, add 1 day.
102
73
  * - If `isSpansNextDay` is true, add 1 day.
103
- * @computed {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
74
+ * @prop {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
104
75
  * - `true` if `startTime` is later than `endTime`
105
- * @computed {number} totalWorkMinutes - Total working time in minutes (excluding break time) (read-only)
76
+ * @prop {number} totalWorkMinutes - Total working time in minutes (excluding break time) (read-only)
106
77
  * - Calculated as the difference between `endAt` and `startAt` minus `breakMinutes`
107
- * @computed {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
78
+ * @prop {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
108
79
  * - The portion of `totalWorkMinutes` that is considered within the contract's `regulationWorkMinutes`.
109
- * @computed {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
80
+ * @prop {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
110
81
  * - Calculated as `totalWorkMinutes` minus `regulationWorkMinutes`
111
- * ---------------------------------------------------------------------------
112
- * @inherited - The following getter properties are inherited from Operation (via OperationResult):
82
+ * @prop {boolean} hasAgreement - Indicates if an Agreement is associated (read-only)
83
+ * - `true` if `agreement` is set, otherwise `false`.
84
+ * @prop {string|false} isInvalid - Validation status (read-only)
85
+ * - Returns false if valid.
86
+ * - Returns reason code string if invalid:
87
+ * - `EMPTY_BILLING_DATE`: Billing date is missing.
88
+ * - `EMPTY_AGREEMENT`: Agreement is missing and `allowEmptyAgreement` is false.
89
+ * @prop {Object} statistics - Statistics of workers (read-only)
90
+ * - Contains counts and total work minutes for base and qualified workers, including OJT breakdowns.
91
+ * - Structure: { base: {...}, qualified: {...}, total: {...} }
92
+ * - Each category contains: quantity, regularTimeWorkMinutes, overtimeWorkMinutes, totalWorkMinutes, breakMinutes
93
+ * - Each category also has an 'ojt' subcategory with the same structure.
94
+ * @prop {Object} sales - Sales amounts (read-only)
95
+ * - Contains sales calculations for base and qualified workers, including overtime breakdowns.
96
+ * - Structure: { base: {...}, qualified: {...} }
97
+ * - Each category contains: unitPrice, quantity, regularAmount, overtimeUnitPrice, overtimeMinutes, overtimeAmount, total
98
+ * - Calculations respect `useAdjustedQuantity`, `billingUnitType`, and `includeBreakInBilling` settings.
99
+ * @prop {number} salesAmount - Total sales amount (read-only)
100
+ * - Sum of sales amounts for base and qualified workers with rounding applied.
101
+ * @prop {number} tax - Calculated tax amount (read-only)
102
+ * - Calculated using the `Tax` utility based on `salesAmount` and `date`.
103
+ * @prop {number} billingAmount - Total billing amount including tax (read-only)
104
+ * - Sum of `salesAmount` and `tax`.
105
+ * @prop {string} billingMonth - Billing month in YYYY-MM format (read-only)
106
+ * @prop {Array<string>} employeeIds - Array of employee IDs from `employees` (read-only)
107
+ * @prop {Array<string>} outsourcerIds - Array of outsourcer IDs from `outsourcers` (read-only)
108
+ * @prop {number} employeesCount - Count of assigned employees (read-only)
109
+ * @prop {number} outsourcersCount - Count of assigned outsourcers (sum of amounts) (read-only)
110
+ * @prop {boolean} isPersonnelShortage - Indicates if there is a shortage of personnel (read-only)
111
+ * - `true` if the sum of `employeesCount` and `outsourcersCount` is less than `requiredPersonnel`
112
+ *
113
113
  * @getter {string} groupKey - Combines `siteId`, `shiftType`, and `date` to indicate operation grouping (read-only)
114
114
  * @getter {boolean} isEmployeesChanged - Indicates whether the employees have changed (read-only)
115
115
  * - Returns true if the employee IDs have changed compared to `_beforeData`
@@ -121,8 +121,6 @@
121
121
  * - Workers that exist in `_beforeData` but not in current data
122
122
  * @getter {Array<OperationResultDetail>} updatedWorkers - An array of workers that have been updated (read-only)
123
123
  * - Workers whose `startTime`, `isStartNextDay`, `endTime`, `breakMinutes`, `isQualified`, or `isOjt` have changed
124
- * ---------------------------------------------------------------------------
125
- * @inherited - The following getter properties are inherited from WorkingResult (via OperationResult):
126
124
  * @getter {number} startHour - Start hour (0-23) (read-only)
127
125
  * - Extracted from `startTime`.
128
126
  * @getter {number} startMinute - Start minute (0-59) (read-only)
@@ -131,53 +129,51 @@
131
129
  * - Extracted from `endTime`.
132
130
  * @getter {number} endMinute - End minute (0-59) (read-only)
133
131
  * - Extracted from `endTime`.
134
- * ---------------------------------------------------------------------------
135
- * @inherited - The following methods are inherited from OperationResult:
136
- * @method {function} beforeDelete - Override method to prevent deletion with siteOperationScheduleId
132
+ *
133
+ * @method beforeDelete - Override method to prevent deletion with siteOperationScheduleId
137
134
  * - Prevents deletion if the instance has `siteOperationScheduleId`.
138
135
  * - Throws an error if deletion is attempted on an instance created from SiteOperationSchedule.
139
- * ---------------------------------------------------------------------------
140
- * @inherited - The following methods are inherited from Operation (via OperationResult):
141
- * @method {function} addWorker - Adds a new worker (employee or outsourcer)
136
+ * @method refreshBillingDateAt - Refresh billingDateAt based on dateAt and cutoffDate
137
+ * - Updates `billingDateAt` based on the current `dateAt` and `cutoffDate` values.
138
+ * @method addWorker - Adds a new worker (employee or outsourcer)
142
139
  * - @param {Object} options - Options for adding a worker
143
140
  * - @param {string} options.id - The worker ID (employeeId or outsourcerId)
144
141
  * - @param {boolean} [options.isEmployee=true] - Whether the worker is an employee
145
142
  * - @param {number} [index=0] - Insertion position. If -1, adds to the end
146
- * @method {function} moveWorker - Moves the position of a worker (employee or outsourcer)
143
+ * @method moveWorker - Moves the position of a worker (employee or outsourcer)
147
144
  * - @param {Object} options - Options for changing worker position
148
145
  * - @param {number} options.oldIndex - The original index
149
146
  * - @param {number} options.newIndex - The new index
150
147
  * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
151
- * @method {function} changeWorker - Changes the details of a worker
148
+ * @method changeWorker - Changes the details of a worker
152
149
  * - @param {Object} newWorker - New worker object
153
- * @method {function} removeWorker - Removes a worker (employee or outsourcer)
150
+ * @method removeWorker - Removes a worker (employee or outsourcer)
154
151
  * - @param {Object} options - Options for removing a worker
155
152
  * - @param {string} options.workerId - The ID of the employee or outsourcer
156
153
  * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
157
- * @method {function} setSiteIdCallback - Callback method called when `siteId` is set
154
+ * @method setSiteIdCallback - Callback method called when `siteId` is set
158
155
  * - Override this method in subclasses to add custom behavior when `siteId` changes.
159
156
  * - By default, does nothing.
160
157
  * - @param {string} v - The new `siteId` value
161
- * @method {function} setShiftTypeCallback - Callback method called when `shiftType` is set
158
+ * @method setShiftTypeCallback - Callback method called when `shiftType` is set
162
159
  * - Override this method in subclasses to add custom behavior when `shiftType` changes.
163
160
  * - By default, does nothing.
164
161
  * - @param {string} v - The new `shiftType` value
165
- * @method {function} setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
162
+ * @method setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
166
163
  * - Override this method in subclasses to add custom behavior when `regulationWorkMinutes` changes.
167
164
  * - By default, does nothing.
168
165
  * - @param {number} v - The new `regulationWorkMinutes` value
166
+ *
169
167
  * @static
170
168
  * @method groupKeyDivider
171
- * Returns an array dividing the key into siteId, shiftType, and date.
172
- * @param {Object|string} key - The combined key string or object
173
- * @returns {Array<string>} - Array containing [siteId, shiftType, date]
174
- * @throws {Error} - If the key is invalid.
175
- * ---------------------------------------------------------------------------
176
- * @inherited - The following method is inherited from WorkingResult (via OperationResult):
177
- * @method {function} setDateAtCallback - Callback method called when `dateAt` is set
178
- * - Override this method in subclasses to add custom behavior when `dateAt` changes.
179
- * - By default, updates `dayType` based on the new `dateAt` value and synchronizes to workers.
180
- * - @param {Date} v - The new `dateAt` value
169
+ * - Returns an array dividing the key into siteId, shiftType, and date.
170
+ * - @param {Object|string} key - The combined key string or object
171
+ * - @returns {Array<string>} - Array containing [siteId, shiftType, date]
172
+ * - @throws {Error} - If the key is invalid.
173
+ *
174
+ * @override create - Override create method to indicate not implemented
175
+ * - Creation of OperationBilling instances is not implemented, as billing records are typically
176
+ * generated through the OperationResult class.
181
177
  *****************************************************************************/
182
178
  import OperationResult from "./OperationResult.js";
183
179
 
@@ -1,7 +1,8 @@
1
1
  /*****************************************************************************
2
- * OperationResult Model ver 1.1.0
2
+ * OperationResult Model
3
+ * @version 1.2.0 - 2025-11-19 Add `agreement`, `hasAgreement`, `isValid` properties.
3
4
  * @author shisyamo4131
4
- * ---------------------------------------------------------------------------
5
+ *
5
6
  * - Extends Operation class to represent the result of an operation.
6
7
  * - Also incorporates Agreement class properties for pricing and billing information.
7
8
  * - Prevents deletion if the instance has `siteOperationScheduleId`.
@@ -9,71 +10,13 @@
9
10
  * - Supports both daily and hourly billing with adjusted quantities.
10
11
  * - Automatically updates `billingDateAt` based on `dateAt` and `cutoffDate`.
11
12
  * - Introduces a lock mechanism (`isLocked`) to prevent edits when necessary.
12
- * ---------------------------------------------------------------------------
13
- * @prop {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
14
- * - If this OperationResult was created from a SiteOperationSchedule, this property holds that ID.
15
- * - If this property is set, the instance cannot be deleted.
16
- * @prop {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
17
- * @prop {number} adjustedQuantityBase - Adjusted quantity for base workers
18
- * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
19
- * @prop {number} adjustedOvertimeBase - Adjusted overtime for base workers
20
- * - Overtime used for billing base workers when `useAdjustedQuantity` is true.
21
- * @prop {number} adjustedQuantityQualified - Adjusted quantity for qualified workers
22
- * - Quantity used for billing qualified workers when `useAdjustedQuantity` is true.
23
- * @prop {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
24
- * - Overtime used for billing qualified workers when `useAdjustedQuantity` is true.
25
- * @prop {Date} billingDateAt - Billing date
26
- * - The date used for billing purposes.
27
- * @prop {boolean} isLocked - Lock flag
28
- * - When set to true, the OperationResult is locked from edits exept for editing as OperationBilling.
29
- * ---------------------------------------------------------------------------
30
- * @computed {Object} statistics - Statistics of workers (read-only)
31
- * - Contains counts and total work minutes for base and qualified workers, including OJT breakdowns.
32
- * - Structure: { base: {...}, qualified: {...}, total: {...} }
33
- * - Each category contains: quantity, regularTimeWorkMinutes, overtimeWorkMinutes, totalWorkMinutes, breakMinutes
34
- * - Each category also has an 'ojt' subcategory with the same structure.
35
- * @computed {Object} sales - Sales amounts (read-only)
36
- * - Contains sales calculations for base and qualified workers, including overtime breakdowns.
37
- * - Structure: { base: {...}, qualified: {...} }
38
- * - Each category contains: unitPrice, quantity, regularAmount, overtimeUnitPrice, overtimeMinutes, overtimeAmount, total
39
- * - Calculations respect `useAdjustedQuantity`, `billingUnitType`, and `includeBreakInBilling` settings.
40
- * @computed {number} salesAmount - Total sales amount (read-only)
41
- * - Sum of sales amounts for base and qualified workers with rounding applied.
42
- * @computed {number} tax - Calculated tax amount (read-only)
43
- * - Calculated using the `Tax` utility based on `salesAmount` and `date`.
44
- * @computed {number} billingAmount - Total billing amount including tax (read-only)
45
- * - Sum of `salesAmount` and `tax`.
46
- * @computed {string} billingMonth - Billing month in YYYY-MM format (read-only)
47
- * ---------------------------------------------------------------------------
48
- * @inherited - The following properties are inherited from Operation:
13
+ *
49
14
  * @prop {string} siteId - Site document ID (trigger property)
50
15
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
51
- * @prop {number} requiredPersonnel - Required number of personnel
52
- * @prop {boolean} qualificationRequired - Qualification required flag
53
- * @prop {string} workDescription - Work description
54
- * @prop {string} remarks - Remarks
55
- * @prop {Array<OperationResultDetail>} employees - Assigned employees
56
- * - Array of `OperationResultDetail` instances representing assigned employees
57
- * @prop {Array<OperationResultDetail>} outsourcers - Assigned outsourcers
58
- * - Array of `OperationResultDetail` instances representing assigned outsourcers
59
- * ---------------------------------------------------------------------------
60
- * @inherited - The following properties are inherited from Agreement (via Operation):
61
- * @prop {number} unitPriceBase - Base unit price (JPY)
62
- * @prop {number} overtimeUnitPriceBase - Overtime unit price (JPY/hour)
63
- * @prop {number} unitPriceQualified - Qualified unit price (JPY)
64
- * @prop {number} overtimeUnitPriceQualified - Qualified overtime unit price (JPY/hour)
65
- * @prop {string} billingUnitType - Billing unit type
66
- * @prop {boolean} includeBreakInBilling - Whether to include break time in billing if `billingUnitType` is `PER_HOUR`.
67
- * @prop {number} cutoffDate - Cutoff date value from CutoffDate.VALUES
68
- * - The cutoff date for billing, using values defined in the CutoffDate utility class.
69
- * - Used to calculate `billingDateAt`.
70
- * - When `cutoffDate` or `dateAt` changes, `billingDateAt` is automatically updated.
71
- * ---------------------------------------------------------------------------
72
- * @inherited - The following properties are inherited from WorkingResult (via Operation):
73
16
  * @prop {Date} dateAt - Date of operation (placement date) (trigger property)
74
17
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
75
18
  * - Used to determine `dayType`.
76
- * - When `dateAt` changes, `billingDateAt` is also updated based on `cutoffDate`.
19
+ * - When `dateAt` changes, `billingDateAt` is also updated based on `agreement.cutoffDate`.
77
20
  * @prop {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
78
21
  * @prop {string} shiftType - `DAY` or `NIGHT` (trigger property)
79
22
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
@@ -85,38 +28,87 @@
85
28
  * @prop {number} regulationWorkMinutes - Regulation work minutes (trigger property)
86
29
  * - Indicates the maximum working time treated as regular working hours.
87
30
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
88
- * ---------------------------------------------------------------------------
89
- * @inherited - The following computed properties are inherited from Operation:
90
- * @computed {Array<string>} employeeIds - Array of employee IDs from `employees` (read-only)
91
- * @computed {Array<string>} outsourcerIds - Array of outsourcer IDs from `outsourcers` (read-only)
92
- * @computed {number} employeesCount - Count of assigned employees (read-only)
93
- * @computed {number} outsourcersCount - Count of assigned outsourcers (sum of amounts) (read-only)
94
- * @computed {boolean} isPersonnelShortage - Indicates if there is a shortage of personnel (read-only)
95
- * - `true` if the sum of `employeesCount` and `outsourcersCount` is less than `requiredPersonnel`
96
- * @computed {Array<OperationResultDetail>} workers - Combined array of `employees` and `outsourcers`
31
+ * @prop {number} requiredPersonnel - Required number of personnel
32
+ * @prop {boolean} qualificationRequired - Qualification required flag
33
+ * @prop {string} workDescription - Work description
34
+ * @prop {string} remarks - Remarks
35
+ * @prop {Array<OperationResultDetail>} employees - Assigned employees
36
+ * - Array of `OperationResultDetail` instances representing assigned employees
37
+ * @prop {Array<OperationResultDetail>} outsourcers - Assigned outsourcers
38
+ * - Array of `OperationResultDetail` instances representing assigned outsourcers
39
+ * @prop {Array<OperationResultDetail>} workers - Combined array of `employees` and `outsourcers`
97
40
  * - Getter: Returns concatenated array of employees and outsourcers
98
41
  * - Setter: Splits array into employees and outsourcers based on `isEmployee` property
99
- * ---------------------------------------------------------------------------
100
- * @inherited - The following computed properties are inherited from WorkingResult (via Operation):
101
- * @computed {string} date - Date string in YYYY-MM-DD format based on `dateAt` (read-only)
42
+ * @prop {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
43
+ * - If this OperationResult was created from a SiteOperationSchedule, this property holds that ID.
44
+ * - If this property is set, the instance cannot be deleted.
45
+ * @prop {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
46
+ * @prop {number} adjustedQuantityBase - Adjusted quantity for base workers
47
+ * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
48
+ * @prop {number} adjustedOvertimeBase - Adjusted overtime for base workers
49
+ * - Overtime used for billing base workers when `useAdjustedQuantity` is true.
50
+ * @prop {number} adjustedQuantityQualified - Adjusted quantity for qualified workers
51
+ * - Quantity used for billing qualified workers when `useAdjustedQuantity` is true.
52
+ * @prop {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
53
+ * - Overtime used for billing qualified workers when `useAdjustedQuantity` is true.
54
+ * @prop {Date} billingDateAt - Billing date
55
+ * - The date used for billing purposes.
56
+ * @prop {boolean} isLocked - Lock flag
57
+ * - When set to true, the OperationResult is locked from edits exept for editing as OperationBilling.
58
+ * @prop {Agreement|null} agreement - Associated Agreement object
59
+ * - The Agreement instance associated with this OperationResult for pricing and billing information.
60
+ * - When set, it influences billing calculations such as unit prices and billing dates.
61
+ * @prop {boolean} allowEmptyAgreement - Flag to ignore missing Agreement
62
+ * - When set to true, allows the OperationResult to be valid even if no Agreement is associated.
63
+ * @readonly
64
+ * @prop {string} date - Date string in YYYY-MM-DD format based on `dateAt` (read-only)
102
65
  * - Returns a string in the format YYYY-MM-DD based on `dateAt`.
103
- * @computed {Date} startAt - Start date and time (Date object) (read-only)
66
+ * @prop {Date} startAt - Start date and time (Date object) (read-only)
104
67
  * - Returns a Date object with `startTime` set based on `dateAt`.
105
68
  * - If `isStartNextDay` is true, add 1 day.
106
- * @computed {Date} endAt - End date and time (Date object) (read-only)
69
+ * @prop {Date} endAt - End date and time (Date object) (read-only)
107
70
  * - Returns a Date object with `endTime` set based on `dateAt`.
108
71
  * - If `isStartNextDay` is true, add 1 day.
109
72
  * - If `isSpansNextDay` is true, add 1 day.
110
- * @computed {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
73
+ * @prop {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
111
74
  * - `true` if `startTime` is later than `endTime`
112
- * @computed {number} totalWorkMinutes - Total working time in minutes (excluding break time) (read-only)
75
+ * @prop {number} totalWorkMinutes - Total working time in minutes (excluding break time) (read-only)
113
76
  * - Calculated as the difference between `endAt` and `startAt` minus `breakMinutes`
114
- * @computed {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
77
+ * @prop {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
115
78
  * - The portion of `totalWorkMinutes` that is considered within the contract's `regulationWorkMinutes`.
116
- * @computed {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
79
+ * @prop {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
117
80
  * - Calculated as `totalWorkMinutes` minus `regulationWorkMinutes`
118
- * ---------------------------------------------------------------------------
119
- * @inherited - The following getter properties are inherited from Operation:
81
+ * @prop {boolean} hasAgreement - Indicates if an Agreement is associated (read-only)
82
+ * - `true` if `agreement` is set, otherwise `false`.
83
+ * @prop {string|false} isInvalid - Validation status (read-only)
84
+ * - Returns false if valid.
85
+ * - Returns reason code string if invalid:
86
+ * - `EMPTY_BILLING_DATE`: Billing date is missing.
87
+ * - `EMPTY_AGREEMENT`: Agreement is missing and `allowEmptyAgreement` is false.
88
+ * @prop {Object} statistics - Statistics of workers (read-only)
89
+ * - Contains counts and total work minutes for base and qualified workers, including OJT breakdowns.
90
+ * - Structure: { base: {...}, qualified: {...}, total: {...} }
91
+ * - Each category contains: quantity, regularTimeWorkMinutes, overtimeWorkMinutes, totalWorkMinutes, breakMinutes
92
+ * - Each category also has an 'ojt' subcategory with the same structure.
93
+ * @prop {Object} sales - Sales amounts (read-only)
94
+ * - Contains sales calculations for base and qualified workers, including overtime breakdowns.
95
+ * - Structure: { base: {...}, qualified: {...} }
96
+ * - Each category contains: unitPrice, quantity, regularAmount, overtimeUnitPrice, overtimeMinutes, overtimeAmount, total
97
+ * - Calculations respect `useAdjustedQuantity`, `billingUnitType`, and `includeBreakInBilling` settings.
98
+ * @prop {number} salesAmount - Total sales amount (read-only)
99
+ * - Sum of sales amounts for base and qualified workers with rounding applied.
100
+ * @prop {number} tax - Calculated tax amount (read-only)
101
+ * - Calculated using the `Tax` utility based on `salesAmount` and `date`.
102
+ * @prop {number} billingAmount - Total billing amount including tax (read-only)
103
+ * - Sum of `salesAmount` and `tax`.
104
+ * @prop {string} billingMonth - Billing month in YYYY-MM format (read-only)
105
+ * @prop {Array<string>} employeeIds - Array of employee IDs from `employees` (read-only)
106
+ * @prop {Array<string>} outsourcerIds - Array of outsourcer IDs from `outsourcers` (read-only)
107
+ * @prop {number} employeesCount - Count of assigned employees (read-only)
108
+ * @prop {number} outsourcersCount - Count of assigned outsourcers (sum of amounts) (read-only)
109
+ * @prop {boolean} isPersonnelShortage - Indicates if there is a shortage of personnel (read-only)
110
+ * - `true` if the sum of `employeesCount` and `outsourcersCount` is less than `requiredPersonnel`
111
+ *
120
112
  * @getter {string} groupKey - Combines `siteId`, `shiftType`, and `date` to indicate operation grouping (read-only)
121
113
  * @getter {boolean} isEmployeesChanged - Indicates whether the employees have changed (read-only)
122
114
  * - Returns true if the employee IDs have changed compared to `_beforeData`
@@ -128,8 +120,6 @@
128
120
  * - Workers that exist in `_beforeData` but not in current data
129
121
  * @getter {Array<OperationResultDetail>} updatedWorkers - An array of workers that have been updated (read-only)
130
122
  * - Workers whose `startTime`, `isStartNextDay`, `endTime`, `breakMinutes`, `isQualified`, or `isOjt` have changed
131
- * ---------------------------------------------------------------------------
132
- * @inherited - The following getter properties are inherited from WorkingResult (via Operation):
133
123
  * @getter {number} startHour - Start hour (0-23) (read-only)
134
124
  * - Extracted from `startTime`.
135
125
  * @getter {number} startMinute - Start minute (0-59) (read-only)
@@ -138,54 +128,49 @@
138
128
  * - Extracted from `endTime`.
139
129
  * @getter {number} endMinute - End minute (0-59) (read-only)
140
130
  * - Extracted from `endTime`.
141
- * ---------------------------------------------------------------------------
142
- * @method {function} beforeDelete - Override method to prevent deletion with siteOperationScheduleId
131
+ *
132
+ * @method beforeDelete - Override method to prevent deletion with siteOperationScheduleId
143
133
  * - Prevents deletion if the instance has `siteOperationScheduleId`.
144
134
  * - Throws an error if deletion is attempted on an instance created from SiteOperationSchedule.
145
- * @method {function} refreshBillingDateAt - Refresh billingDateAt based on dateAt and cutoffDate
135
+ * @method refreshBillingDateAt - Refresh billingDateAt based on dateAt and cutoffDate
146
136
  * - Updates `billingDateAt` based on the current `dateAt` and `cutoffDate` values.
147
- * ---------------------------------------------------------------------------
148
- * @inherited - The following methods are inherited from Operation:
149
- * @method {function} addWorker - Adds a new worker (employee or outsourcer)
137
+ * @method addWorker - Adds a new worker (employee or outsourcer)
150
138
  * - @param {Object} options - Options for adding a worker
151
139
  * - @param {string} options.id - The worker ID (employeeId or outsourcerId)
152
140
  * - @param {boolean} [options.isEmployee=true] - Whether the worker is an employee
153
141
  * - @param {number} [index=0] - Insertion position. If -1, adds to the end
154
- * @method {function} moveWorker - Moves the position of a worker (employee or outsourcer)
142
+ * @method moveWorker - Moves the position of a worker (employee or outsourcer)
155
143
  * - @param {Object} options - Options for changing worker position
156
144
  * - @param {number} options.oldIndex - The original index
157
145
  * - @param {number} options.newIndex - The new index
158
146
  * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
159
- * @method {function} changeWorker - Changes the details of a worker
147
+ * @method changeWorker - Changes the details of a worker
160
148
  * - @param {Object} newWorker - New worker object
161
- * @method {function} removeWorker - Removes a worker (employee or outsourcer)
149
+ * @method removeWorker - Removes a worker (employee or outsourcer)
162
150
  * - @param {Object} options - Options for removing a worker
163
151
  * - @param {string} options.workerId - The ID of the employee or outsourcer
164
152
  * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
165
- * @method {function} setSiteIdCallback - Callback method called when `siteId` is set
153
+ * @method setSiteIdCallback - Callback method called when `siteId` is set
166
154
  * - Override this method in subclasses to add custom behavior when `siteId` changes.
167
155
  * - By default, does nothing.
168
156
  * - @param {string} v - The new `siteId` value
169
- * @method {function} setShiftTypeCallback - Callback method called when `shiftType` is set
157
+ * @method setShiftTypeCallback - Callback method called when `shiftType` is set
170
158
  * - Override this method in subclasses to add custom behavior when `shiftType` changes.
171
159
  * - By default, does nothing.
172
160
  * - @param {string} v - The new `shiftType` value
173
- * @method {function} setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
161
+ * @method setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
174
162
  * - Override this method in subclasses to add custom behavior when `regulationWorkMinutes` changes.
175
163
  * - By default, does nothing.
176
164
  * - @param {number} v - The new `regulationWorkMinutes` value
165
+ *
177
166
  * @static
178
167
  * @method groupKeyDivider
179
- * Returns an array dividing the key into siteId, shiftType, and date.
180
- * @param {Object|string} key - The combined key string or object
181
- * @returns {Array<string>} - Array containing [siteId, shiftType, date]
182
- * @throws {Error} - If the key is invalid.
183
- * ---------------------------------------------------------------------------
184
- * @inherited - The following method is inherited from WorkingResult (via Operation):
185
- * @method {function} setDateAtCallback - Callback method called when `dateAt` is set
186
- * - Override this method in subclasses to add custom behavior when `dateAt` changes.
187
- * - By default, updates `dayType` based on the new `dateAt` value and synchronizes to workers.
188
- * - @param {Date} v - The new `dateAt` value
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
+ * @override setDateAtCallback - Updates `billingDateAt` based on the new `dateAt` value.
189
174
  *****************************************************************************/
190
175
  import Operation from "./Operation.js";
191
176
  import Agreement from "./Agreement.js";
@@ -199,7 +184,6 @@ import CutoffDate from "./utils/CutoffDate.js";
199
184
 
200
185
  const classProps = {
201
186
  ...Operation.classProps,
202
- ...Agreement.classProps,
203
187
  siteOperationScheduleId: defField("oneLine", { hidden: true }),
204
188
  useAdjustedQuantity: defField("check", {
205
189
  label: "調整数量を使用",
@@ -221,15 +205,25 @@ const classProps = {
221
205
  label: "資格残業(調整)",
222
206
  default: 0,
223
207
  }),
224
- billingDateAt: defField("dateAt", { label: "請求日付", required: true }),
208
+ billingDateAt: defField("dateAt", { label: "請求日付" }),
225
209
  employees: defField("array", { customClass: OperationResultDetail }),
226
210
  outsourcers: defField("array", {
227
211
  customClass: OperationResultDetail,
228
212
  }),
229
213
  isLocked: defField("check", {
230
- label: "ロック",
214
+ label: "実績確定",
231
215
  default: false,
232
216
  }),
217
+ agreement: defField("object", { label: "取極め", customClass: Agreement }),
218
+ allowEmptyAgreement: defField("check", {
219
+ label: "取極めなしを無視",
220
+ default: false,
221
+ }),
222
+ };
223
+
224
+ const INVALID_REASON = {
225
+ EMPTY_BILLING_DATE: "EMPTY_BILLING_DATE",
226
+ EMPTY_AGREEMENT: "EMPTY_AGREEMENT",
233
227
  };
234
228
 
235
229
  export default class OperationResult extends Operation {
@@ -251,20 +245,8 @@ export default class OperationResult extends Operation {
251
245
  super.afterInitialize();
252
246
 
253
247
  /** Computed properties */
254
- let _cutoffDate = this.cutoffDate;
248
+ let _agreement = this.agreement;
255
249
  Object.defineProperties(this, {
256
- cutoffDate: {
257
- configurable: true,
258
- enumerable: true,
259
- get() {
260
- return _cutoffDate;
261
- },
262
- set(v) {
263
- _cutoffDate = v;
264
- // Update billingDateAt when cutoffDate changes
265
- this.refreshBillingDateAt();
266
- },
267
- },
268
250
  statistics: {
269
251
  configurable: true,
270
252
  enumerable: true,
@@ -340,22 +322,9 @@ export default class OperationResult extends Operation {
340
322
  return createInitialValues();
341
323
  }
342
324
 
343
- const unitPrice = isQualified
344
- ? this.unitPriceQualified || 0
345
- : this.unitPriceBase || 0;
346
- const overtimeUnitPrice = isQualified
347
- ? this.overtimeUnitPriceQualified || 0
348
- : this.overtimeUnitPriceBase || 0;
349
- const isPerHour =
350
- this.billingUnitType === BILLING_UNIT_TYPE_PER_HOUR;
351
-
352
325
  const result = createInitialValues();
353
326
 
354
- // 基本情報の設定
355
- result.unitPrice = unitPrice;
356
- result.overtimeUnitPrice = overtimeUnitPrice;
357
-
358
- // 調整値の使用判定
327
+ // agreementの有無に関わらず数量と残業時間を計算
359
328
  if (this.useAdjustedQuantity) {
360
329
  result.quantity = isQualified
361
330
  ? this.adjustedQuantityQualified || 0
@@ -364,35 +333,45 @@ export default class OperationResult extends Operation {
364
333
  ? this.adjustedOvertimeQualified || 0
365
334
  : this.adjustedOvertimeBase || 0;
366
335
  } else {
367
- // result.quantity = isPerHour
368
- // ? (categoryStats.totalWorkMinutes || 0) / 60
369
- // : categoryStats.quantity || 0;
370
- // result.overtimeMinutes = categoryStats.overtimeWorkMinutes || 0;
336
+ // agreementがある場合のみbillingUnitTypeとincludeBreakInBillingを使用
337
+ const isPerHour =
338
+ this.agreement?.billingUnitType === BILLING_UNIT_TYPE_PER_HOUR;
339
+
371
340
  if (isPerHour) {
372
341
  // 時間単位請求の場合
373
342
  let totalMinutes = categoryStats.totalWorkMinutes || 0;
374
343
 
375
344
  // 休憩時間を請求に含める場合は休憩時間を追加
376
- if (this.includeBreakInBilling) {
345
+ if (this.agreement?.includeBreakInBilling) {
377
346
  totalMinutes += categoryStats.breakMinutes || 0;
378
347
  }
379
348
 
380
349
  result.quantity = totalMinutes / 60;
381
350
  } else {
382
- // 日単位請求の場合(休憩時間は関係なし)
351
+ // 日単位請求の場合(休憩時間は関係なし)
383
352
  result.quantity = categoryStats.quantity || 0;
384
353
  }
385
354
  result.overtimeMinutes = categoryStats.overtimeWorkMinutes || 0;
386
355
  }
387
356
 
388
- // 金額計算(RoundSettingを適用)
389
- result.regularAmount = RoundSetting.apply(
390
- result.quantity * unitPrice
391
- );
392
- result.overtimeAmount = RoundSetting.apply(
393
- (result.overtimeMinutes * overtimeUnitPrice) / 60
394
- );
395
- result.total = result.regularAmount + result.overtimeAmount;
357
+ // agreementがある場合のみ単価と金額を計算
358
+ if (this.agreement) {
359
+ result.unitPrice = isQualified
360
+ ? this.agreement.unitPriceQualified || 0
361
+ : this.agreement.unitPriceBase || 0;
362
+ result.overtimeUnitPrice = isQualified
363
+ ? this.agreement.overtimeUnitPriceQualified || 0
364
+ : this.agreement.overtimeUnitPriceBase || 0;
365
+
366
+ // 金額計算(RoundSettingを適用)
367
+ result.regularAmount = RoundSetting.apply(
368
+ result.quantity * result.unitPrice
369
+ );
370
+ result.overtimeAmount = RoundSetting.apply(
371
+ (result.overtimeMinutes * result.overtimeUnitPrice) / 60
372
+ );
373
+ result.total = result.regularAmount + result.overtimeAmount;
374
+ }
396
375
 
397
376
  return result;
398
377
  };
@@ -451,6 +430,40 @@ export default class OperationResult extends Operation {
451
430
  },
452
431
  set(v) {},
453
432
  },
433
+
434
+ agreement: {
435
+ configurable: true,
436
+ enumerable: true,
437
+ get() {
438
+ return _agreement;
439
+ },
440
+ set(v) {
441
+ _agreement = v;
442
+ this.refreshBillingDateAt();
443
+ },
444
+ },
445
+ hasAgreement: {
446
+ configurable: true,
447
+ enumerable: true,
448
+ get() {
449
+ return this.agreement != null;
450
+ },
451
+ set(v) {},
452
+ },
453
+ isInvalid: {
454
+ configurable: true,
455
+ enumerable: true,
456
+ get() {
457
+ if (!this.agreement && !this.allowEmptyAgreement) {
458
+ return INVALID_REASON.EMPTY_AGREEMENT;
459
+ }
460
+ if (!this.billingDateAt) {
461
+ return INVALID_REASON.EMPTY_BILLING_DATE;
462
+ }
463
+ return false;
464
+ },
465
+ set(v) {},
466
+ },
454
467
  });
455
468
  }
456
469
 
@@ -463,13 +476,17 @@ export default class OperationResult extends Operation {
463
476
  this.billingDateAt = null;
464
477
  return;
465
478
  }
466
- if (this.cutoffDate !== 0 && !this.cutoffDate) {
479
+ if (!this.agreement) {
480
+ this.billingDateAt = null;
481
+ return;
482
+ }
483
+ if (this.agreement.cutoffDate !== 0 && !this.agreement.cutoffDate) {
467
484
  this.billingDateAt = null;
468
485
  return;
469
486
  }
470
487
  this.billingDateAt = CutoffDate.calculateBillingDateAt(
471
488
  this.dateAt,
472
- this.cutoffDate
489
+ this.agreement.cutoffDate
473
490
  );
474
491
  }
475
492
 
@@ -483,20 +500,17 @@ export default class OperationResult extends Operation {
483
500
  }
484
501
 
485
502
  /**
486
- * Override `beforeDelete`.
487
- * - Prevents deletion if the instance has `siteOperationScheduleId`.
503
+ * Override create method to validate billingDateAt when allowEmptyAgreement is true
504
+ * @param {*} options
505
+ * @returns {Promise<DocumentReference>}
488
506
  */
489
- async beforeDelete() {
490
- await super.beforeDelete();
491
- if (this.siteOperationScheduleId) {
492
- throw new Error(
493
- "この稼働実績は現場稼働予定から作成されているため、削除できません。"
494
- );
495
- }
507
+ async create(options = {}) {
508
+ return await super.create(options);
496
509
  }
497
510
 
498
511
  /**
499
512
  * Override update method to prevent editing if isLocked is true
513
+ * - Also validate billingDateAt when allowEmptyAgreement is true
500
514
  * @param {*} options
501
515
  * @returns {Promise<void>}
502
516
  */
@@ -506,7 +520,7 @@ export default class OperationResult extends Operation {
506
520
  "[OperationResult] This OperationResult is locked and cannot be edited."
507
521
  );
508
522
  }
509
- return super.update(options);
523
+ return await super.update(options);
510
524
  }
511
525
 
512
526
  /**
@@ -520,6 +534,6 @@ export default class OperationResult extends Operation {
520
534
  "[OperationResult] This OperationResult is locked and cannot be deleted."
521
535
  );
522
536
  }
523
- return super.delete(options);
537
+ return await super.delete(options);
524
538
  }
525
539
  }