@shisyamo4131/air-guard-v2-schemas 1.3.0 → 1.3.1-dev.10

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.0",
3
+ "version": "1.3.1-dev.10",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -33,7 +33,10 @@
33
33
  "access": "public"
34
34
  },
35
35
  "scripts": {
36
- "test": "echo \"Error: no test specified\" && exit 1"
36
+ "dev:publish": "npm version prerelease --preid=dev && npm publish --tag dev",
37
+ "release:patch": "npm version patch && npm publish",
38
+ "release:minor": "npm version minor && npm publish",
39
+ "release:major": "npm version major && npm publish"
37
40
  },
38
41
  "peerDependencies": {
39
42
  "@shisyamo4131/air-firebase-v2": "^1.0.0"
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
  * ---------------------------------------------------------------------------
package/src/Billing.js CHANGED
@@ -9,16 +9,18 @@
9
9
  * @prop {string} billingMonth - billing month (YYYY-MM format)
10
10
  * @prop {Date} billingDate - billing date
11
11
  * @prop {Date} paymentDueDate - payment due date
12
+ *
13
+ * @prop {Array} paymentRecords - payment records (not implemented yet)
14
+ *
12
15
  * @prop {string} status - status (DRAFT/CONFIRMED/PAID/CANCELLED)
13
- * @prop {Array<OperationResult>} items - operation result items (raw data)
16
+ * @prop {Array<OperationResult>} operationResults - operation result documents.
14
17
  * @prop {Object} adjustment - adjustment
15
18
  * @prop {string} remarks - remarks
16
- * @prop {Object} pdfInfo - PDF information
17
19
  *
18
- * @computed {number} subtotal - subtotal (excluding tax)
19
- * @computed {number} taxAmount - tax amount
20
- * @computed {number} totalAmount - total amount (including tax)
21
- * @computed {Array<Object>} itemsSummary - billing items summary for display
20
+ * @prop {number} subtotal - subtotal (excluding tax) (computed-readonly)
21
+ * @prop {number} taxAmount - tax amount (computed-readonly)
22
+ * @prop {number} totalAmount - total amount (including tax) (computed-readonly)
23
+ * @prop {Array<Object>} itemsSummary - billing items summary for display (computed-readonly)
22
24
  *****************************************************************************/
23
25
 
24
26
  import FireModel from "@shisyamo4131/air-firebase-v2";
@@ -36,29 +38,21 @@ const classProps = {
36
38
  customerId: defField("customerId", { required: true }),
37
39
  siteId: defField("siteId", { required: true }),
38
40
  billingMonth: defField("oneLine", { required: true }),
39
- billingDate: defField("date"),
40
- paymentDueDate: defField("date"),
41
- status: defField("oneLine", { default: STATUS.DRAFT }),
41
+ billingDateAt: defField("date"),
42
+ paymentDueDateAt: defField("date"),
42
43
 
43
- // OperationResult の生データを配列で保持
44
- items: defField("array", { customClass: OperationResult }),
44
+ // 入金管理用配列(現時点では未使用 将来の拡張用)
45
+ paymentRecords: defField("array", { default: [] }), // Not implemented yet
45
46
 
47
+ status: defField("oneLine", { default: STATUS.DRAFT }),
48
+ operationResults: defField("array", { customClass: OperationResult }),
46
49
  adjustment: defField("object", {
47
50
  default: {
48
51
  amount: 0,
49
52
  description: "",
50
53
  },
51
54
  }),
52
-
53
55
  remarks: defField("multipleLine"),
54
-
55
- pdfInfo: defField("object", {
56
- default: {
57
- url: null,
58
- generatedAt: null,
59
- version: 1,
60
- },
61
- }),
62
56
  };
63
57
 
64
58
  export default class Billing extends FireModel {
@@ -75,13 +69,14 @@ export default class Billing extends FireModel {
75
69
  // 小計(税抜)を計算
76
70
  Object.defineProperty(this, "subtotal", {
77
71
  get() {
78
- const itemsTotal = this.items.reduce((sum, item) => {
72
+ const itemsTotal = this.operationResults.reduce((sum, item) => {
79
73
  return sum + (item.salesAmount || 0);
80
74
  }, 0);
81
75
  return itemsTotal + (this.adjustment?.amount || 0);
82
76
  },
83
77
  set() {},
84
78
  enumerable: true,
79
+ configurable: true,
85
80
  });
86
81
 
87
82
  // 消費税額を計算
@@ -91,6 +86,7 @@ export default class Billing extends FireModel {
91
86
  },
92
87
  set() {},
93
88
  enumerable: true,
89
+ configurable: true,
94
90
  });
95
91
 
96
92
  // 合計金額(税込)を計算
@@ -100,12 +96,13 @@ export default class Billing extends FireModel {
100
96
  },
101
97
  set() {},
102
98
  enumerable: true,
99
+ configurable: true,
103
100
  });
104
101
 
105
102
  // 表示用の明細サマリーを生成
106
103
  Object.defineProperty(this, "itemsSummary", {
107
104
  get() {
108
- return this.items.map((item) => ({
105
+ return this.operationResults.map((item) => ({
109
106
  operationResultId: item.docId,
110
107
  workDate: item.dateAt,
111
108
  shiftType: item.shiftType,
@@ -134,6 +131,7 @@ export default class Billing extends FireModel {
134
131
  },
135
132
  set() {},
136
133
  enumerable: true,
134
+ configurable: true,
137
135
  });
138
136
  }
139
137
 
package/src/Customer.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /*****************************************************************************
2
- * Customer ver 1.0.0
2
+ * Customer ver 1.1.0
3
3
  * @author shisyamo4131
4
4
  *
5
5
  * @description Customer model.
6
+ *
6
7
  * @hasMany Sites - related sites associated with the customer
7
8
  *
8
9
  * @prop {string} code - customer code
@@ -17,6 +18,8 @@
17
18
  * @prop {string} tel - telephone number
18
19
  * @prop {string} fax - fax number
19
20
  * @prop {string} contractStatus - contract status
21
+ * @prop {number} paymentMonth - payment site in months
22
+ * @prop {string} paymentDate - payment site date
20
23
  * @prop {string} remarks - additional remarks
21
24
  *
22
25
  * @readonly
@@ -31,6 +34,7 @@ import FireModel from "@shisyamo4131/air-firebase-v2";
31
34
  import { defField } from "./parts/fieldDefinitions.js";
32
35
  import { defAccessor } from "./parts/accessorDefinitions.js";
33
36
  import { VALUES } from "./constants/contract-status.js";
37
+ import CutoffDate from "./utils/CutoffDate.js";
34
38
 
35
39
  const classProps = {
36
40
  code: defField("code", { label: "取引先コード" }),
@@ -45,6 +49,21 @@ const classProps = {
45
49
  tel: defField("tel", { colsDefinition: { cols: 12, sm: 6 } }),
46
50
  fax: defField("fax", { colsDefinition: { cols: 12, sm: 6 } }),
47
51
  contractStatus: defField("contractStatus", { required: true }),
52
+ paymentMonth: defField("number", {
53
+ default: 1,
54
+ label: "入金サイト(月数)",
55
+ required: true,
56
+ }),
57
+ paymentDate: defField("select", {
58
+ label: "入金サイト(日付)",
59
+ default: CutoffDate.VALUES.END_OF_MONTH,
60
+ required: true,
61
+ component: {
62
+ attrs: {
63
+ items: CutoffDate.OPTIONS,
64
+ },
65
+ },
66
+ }),
48
67
  remarks: defField("multipleLine", { label: "備考" }),
49
68
  };
50
69
 
@@ -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,104 +10,106 @@
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
- * @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)
13
+ *
14
+ * @prop {string} siteId - Site document ID (trigger property)
30
15
  * - 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)
16
+ * @prop {Date} dateAt - Date of operation (placement date) (trigger property)
52
17
  * - 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)
18
+ * - Used to determine `dayType`.
19
+ * - When `dateAt` changes, `billingDateAt` is also updated based on `agreement.cutoffDate`.
20
+ * @prop {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
21
+ * @prop {string} shiftType - `DAY` or `NIGHT` (trigger property)
55
22
  * - 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
23
+ * @prop {string} startTime - Start time (HH:MM format)
24
+ * @prop {boolean} isStartNextDay - Next day start flag
58
25
  * - `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)
26
+ * @prop {string} endTime - End time (HH:MM format)
27
+ * @prop {number} breakMinutes - Break time (minutes)
28
+ * @prop {number} regulationWorkMinutes - Regulation work minutes (trigger property)
62
29
  * - Indicates the maximum working time treated as regular working hours.
63
30
  * - 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)
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`
87
40
  * - Getter: Returns concatenated array of employees and outsourcers
88
41
  * - 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)
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)
92
66
  * - Returns a string in the format YYYY-MM-DD based on `dateAt`.
93
- * @computed {Date} startAt - Start date and time (Date object) (read-only)
67
+ * @prop {Date} startAt - Start date and time (Date object) (read-only)
94
68
  * - Returns a Date object with `startTime` set based on `dateAt`.
95
69
  * - If `isStartNextDay` is true, add 1 day.
96
- * @computed {Date} endAt - End date and time (Date object) (read-only)
70
+ * @prop {Date} endAt - End date and time (Date object) (read-only)
97
71
  * - Returns a Date object with `endTime` set based on `dateAt`.
98
72
  * - If `isStartNextDay` is true, add 1 day.
99
73
  * - 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)
74
+ * @prop {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
101
75
  * - `true` if `startTime` is later than `endTime`
102
- * @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)
103
77
  * - Calculated as the difference between `endAt` and `startAt` minus `breakMinutes`
104
- * @computed {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
78
+ * @prop {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
105
79
  * - The portion of `totalWorkMinutes` that is considered within the contract's `regulationWorkMinutes`.
106
- * @computed {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
80
+ * @prop {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
107
81
  * - Calculated as `totalWorkMinutes` minus `regulationWorkMinutes`
108
- * ---------------------------------------------------------------------------
109
- * @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
+ *
110
113
  * @getter {string} groupKey - Combines `siteId`, `shiftType`, and `date` to indicate operation grouping (read-only)
111
114
  * @getter {boolean} isEmployeesChanged - Indicates whether the employees have changed (read-only)
112
115
  * - Returns true if the employee IDs have changed compared to `_beforeData`
@@ -118,8 +121,6 @@
118
121
  * - Workers that exist in `_beforeData` but not in current data
119
122
  * @getter {Array<OperationResultDetail>} updatedWorkers - An array of workers that have been updated (read-only)
120
123
  * - 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
124
  * @getter {number} startHour - Start hour (0-23) (read-only)
124
125
  * - Extracted from `startTime`.
125
126
  * @getter {number} startMinute - Start minute (0-59) (read-only)
@@ -128,53 +129,51 @@
128
129
  * - Extracted from `endTime`.
129
130
  * @getter {number} endMinute - End minute (0-59) (read-only)
130
131
  * - Extracted from `endTime`.
131
- * ---------------------------------------------------------------------------
132
- * @inherited - The following methods are inherited from OperationResult:
133
- * @method {function} beforeDelete - Override method to prevent deletion with siteOperationScheduleId
132
+ *
133
+ * @method beforeDelete - Override method to prevent deletion with siteOperationScheduleId
134
134
  * - Prevents deletion if the instance has `siteOperationScheduleId`.
135
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)
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)
139
139
  * - @param {Object} options - Options for adding a worker
140
140
  * - @param {string} options.id - The worker ID (employeeId or outsourcerId)
141
141
  * - @param {boolean} [options.isEmployee=true] - Whether the worker is an employee
142
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)
143
+ * @method moveWorker - Moves the position of a worker (employee or outsourcer)
144
144
  * - @param {Object} options - Options for changing worker position
145
145
  * - @param {number} options.oldIndex - The original index
146
146
  * - @param {number} options.newIndex - The new index
147
147
  * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
148
- * @method {function} changeWorker - Changes the details of a worker
148
+ * @method changeWorker - Changes the details of a worker
149
149
  * - @param {Object} newWorker - New worker object
150
- * @method {function} removeWorker - Removes a worker (employee or outsourcer)
150
+ * @method removeWorker - Removes a worker (employee or outsourcer)
151
151
  * - @param {Object} options - Options for removing a worker
152
152
  * - @param {string} options.workerId - The ID of the employee or outsourcer
153
153
  * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
154
- * @method {function} setSiteIdCallback - Callback method called when `siteId` is set
154
+ * @method setSiteIdCallback - Callback method called when `siteId` is set
155
155
  * - Override this method in subclasses to add custom behavior when `siteId` changes.
156
156
  * - By default, does nothing.
157
157
  * - @param {string} v - The new `siteId` value
158
- * @method {function} setShiftTypeCallback - Callback method called when `shiftType` is set
158
+ * @method setShiftTypeCallback - Callback method called when `shiftType` is set
159
159
  * - Override this method in subclasses to add custom behavior when `shiftType` changes.
160
160
  * - By default, does nothing.
161
161
  * - @param {string} v - The new `shiftType` value
162
- * @method {function} setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
162
+ * @method setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
163
163
  * - Override this method in subclasses to add custom behavior when `regulationWorkMinutes` changes.
164
164
  * - By default, does nothing.
165
165
  * - @param {number} v - The new `regulationWorkMinutes` value
166
+ *
166
167
  * @static
167
168
  * @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
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.
178
177
  *****************************************************************************/
179
178
  import OperationResult from "./OperationResult.js";
180
179
 
@@ -1,69 +1,22 @@
1
1
  /*****************************************************************************
2
- * OperationResult Model ver 1.0.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`.
8
9
  * - Provides comprehensive billing calculations including statistics, sales amounts, and tax.
9
10
  * - Supports both daily and hourly billing with adjusted quantities.
10
- * ---------------------------------------------------------------------------
11
- * @prop {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
12
- * - If this OperationResult was created from a SiteOperationSchedule, this property holds that ID.
13
- * - If this property is set, the instance cannot be deleted.
14
- * @prop {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
15
- * @prop {number} adjustedQuantityBase - Adjusted quantity for base workers
16
- * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
17
- * @prop {number} adjustedOvertimeBase - Adjusted overtime for base workers
18
- * - Overtime used for billing base workers when `useAdjustedQuantity` is true.
19
- * @prop {number} adjustedQuantityQualified - Adjusted quantity for qualified workers
20
- * - Quantity used for billing qualified workers when `useAdjustedQuantity` is true.
21
- * @prop {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
22
- * - Overtime used for billing qualified workers when `useAdjustedQuantity` is true.
23
- * @prop {Date} billingDateAt - Billing date
24
- * ---------------------------------------------------------------------------
25
- * @computed {Object} statistics - Statistics of workers (read-only)
26
- * - Contains counts and total work minutes for base and qualified workers, including OJT breakdowns.
27
- * - Structure: { base: {...}, qualified: {...}, total: {...} }
28
- * - Each category contains: quantity, regularTimeWorkMinutes, overtimeWorkMinutes, totalWorkMinutes, breakMinutes
29
- * - Each category also has an 'ojt' subcategory with the same structure.
30
- * @computed {Object} sales - Sales amounts (read-only)
31
- * - Contains sales calculations for base and qualified workers, including overtime breakdowns.
32
- * - Structure: { base: {...}, qualified: {...} }
33
- * - Each category contains: unitPrice, quantity, regularAmount, overtimeUnitPrice, overtimeMinutes, overtimeAmount, total
34
- * - Calculations respect `useAdjustedQuantity`, `billingUnitType`, and `includeBreakInBilling` settings.
35
- * @computed {number} salesAmount - Total sales amount (read-only)
36
- * - Sum of sales amounts for base and qualified workers with rounding applied.
37
- * @computed {number} tax - Calculated tax amount (read-only)
38
- * - Calculated using the `Tax` utility based on `salesAmount` and `date`.
39
- * @computed {number} billingAmount - Total billing amount including tax (read-only)
40
- * - Sum of `salesAmount` and `tax`.
41
- * ---------------------------------------------------------------------------
42
- * @inherited - The following properties are inherited from Operation:
11
+ * - Automatically updates `billingDateAt` based on `dateAt` and `cutoffDate`.
12
+ * - Introduces a lock mechanism (`isLocked`) to prevent edits when necessary.
13
+ *
43
14
  * @prop {string} siteId - Site document ID (trigger property)
44
15
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
45
- * @prop {number} requiredPersonnel - Required number of personnel
46
- * @prop {boolean} qualificationRequired - Qualification required flag
47
- * @prop {string} workDescription - Work description
48
- * @prop {string} remarks - Remarks
49
- * @prop {Array<OperationResultDetail>} employees - Assigned employees
50
- * - Array of `OperationResultDetail` instances representing assigned employees
51
- * @prop {Array<OperationResultDetail>} outsourcers - Assigned outsourcers
52
- * - Array of `OperationResultDetail` instances representing assigned outsourcers
53
- * ---------------------------------------------------------------------------
54
- * @inherited - The following properties are inherited from Agreement (via Operation):
55
- * @prop {number} unitPriceBase - Base unit price (JPY)
56
- * @prop {number} overtimeUnitPriceBase - Overtime unit price (JPY/hour)
57
- * @prop {number} unitPriceQualified - Qualified unit price (JPY)
58
- * @prop {number} overtimeUnitPriceQualified - Qualified overtime unit price (JPY/hour)
59
- * @prop {string} billingUnitType - Billing unit type
60
- * @prop {boolean} includeBreakInBilling - Whether to include break time in billing if `billingUnitType` is `PER_HOUR`.
61
- * @prop {number} cutoffDate - Cutoff date value from CutoffDate.VALUES
62
- * - The cutoff date for billing, using values defined in the CutoffDate utility class.
63
- * ---------------------------------------------------------------------------
64
- * @inherited - The following properties are inherited from WorkingResult (via Operation):
65
16
  * @prop {Date} dateAt - Date of operation (placement date) (trigger property)
66
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`.
67
20
  * @prop {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
68
21
  * @prop {string} shiftType - `DAY` or `NIGHT` (trigger property)
69
22
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
@@ -75,38 +28,87 @@
75
28
  * @prop {number} regulationWorkMinutes - Regulation work minutes (trigger property)
76
29
  * - Indicates the maximum working time treated as regular working hours.
77
30
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
78
- * ---------------------------------------------------------------------------
79
- * @inherited - The following computed properties are inherited from Operation:
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`
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`
87
40
  * - Getter: Returns concatenated array of employees and outsourcers
88
41
  * - Setter: Splits array into employees and outsourcers based on `isEmployee` property
89
- * ---------------------------------------------------------------------------
90
- * @inherited - The following computed properties are inherited from WorkingResult (via Operation):
91
- * @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)
92
65
  * - Returns a string in the format YYYY-MM-DD based on `dateAt`.
93
- * @computed {Date} startAt - Start date and time (Date object) (read-only)
66
+ * @prop {Date} startAt - Start date and time (Date object) (read-only)
94
67
  * - Returns a Date object with `startTime` set based on `dateAt`.
95
68
  * - If `isStartNextDay` is true, add 1 day.
96
- * @computed {Date} endAt - End date and time (Date object) (read-only)
69
+ * @prop {Date} endAt - End date and time (Date object) (read-only)
97
70
  * - Returns a Date object with `endTime` set based on `dateAt`.
98
71
  * - If `isStartNextDay` is true, add 1 day.
99
72
  * - 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)
73
+ * @prop {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
101
74
  * - `true` if `startTime` is later than `endTime`
102
- * @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)
103
76
  * - Calculated as the difference between `endAt` and `startAt` minus `breakMinutes`
104
- * @computed {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
77
+ * @prop {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
105
78
  * - The portion of `totalWorkMinutes` that is considered within the contract's `regulationWorkMinutes`.
106
- * @computed {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
79
+ * @prop {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
107
80
  * - Calculated as `totalWorkMinutes` minus `regulationWorkMinutes`
108
- * ---------------------------------------------------------------------------
109
- * @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
+ *
110
112
  * @getter {string} groupKey - Combines `siteId`, `shiftType`, and `date` to indicate operation grouping (read-only)
111
113
  * @getter {boolean} isEmployeesChanged - Indicates whether the employees have changed (read-only)
112
114
  * - Returns true if the employee IDs have changed compared to `_beforeData`
@@ -118,8 +120,6 @@
118
120
  * - Workers that exist in `_beforeData` but not in current data
119
121
  * @getter {Array<OperationResultDetail>} updatedWorkers - An array of workers that have been updated (read-only)
120
122
  * - Workers whose `startTime`, `isStartNextDay`, `endTime`, `breakMinutes`, `isQualified`, or `isOjt` have changed
121
- * ---------------------------------------------------------------------------
122
- * @inherited - The following getter properties are inherited from WorkingResult (via Operation):
123
123
  * @getter {number} startHour - Start hour (0-23) (read-only)
124
124
  * - Extracted from `startTime`.
125
125
  * @getter {number} startMinute - Start minute (0-59) (read-only)
@@ -128,52 +128,49 @@
128
128
  * - Extracted from `endTime`.
129
129
  * @getter {number} endMinute - End minute (0-59) (read-only)
130
130
  * - Extracted from `endTime`.
131
- * ---------------------------------------------------------------------------
132
- * @method {function} beforeDelete - Override method to prevent deletion with siteOperationScheduleId
131
+ *
132
+ * @method beforeDelete - Override method to prevent deletion with siteOperationScheduleId
133
133
  * - Prevents deletion if the instance has `siteOperationScheduleId`.
134
134
  * - Throws an error if deletion is attempted on an instance created from SiteOperationSchedule.
135
- * ---------------------------------------------------------------------------
136
- * @inherited - The following methods are inherited from Operation:
137
- * @method {function} addWorker - Adds a new worker (employee or outsourcer)
135
+ * @method refreshBillingDateAt - Refresh billingDateAt based on dateAt and cutoffDate
136
+ * - Updates `billingDateAt` based on the current `dateAt` and `cutoffDate` values.
137
+ * @method addWorker - Adds a new worker (employee or outsourcer)
138
138
  * - @param {Object} options - Options for adding a worker
139
139
  * - @param {string} options.id - The worker ID (employeeId or outsourcerId)
140
140
  * - @param {boolean} [options.isEmployee=true] - Whether the worker is an employee
141
141
  * - @param {number} [index=0] - Insertion position. If -1, adds to the end
142
- * @method {function} moveWorker - Moves the position of a worker (employee or outsourcer)
142
+ * @method moveWorker - Moves the position of a worker (employee or outsourcer)
143
143
  * - @param {Object} options - Options for changing worker position
144
144
  * - @param {number} options.oldIndex - The original index
145
145
  * - @param {number} options.newIndex - The new index
146
146
  * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
147
- * @method {function} changeWorker - Changes the details of a worker
147
+ * @method changeWorker - Changes the details of a worker
148
148
  * - @param {Object} newWorker - New worker object
149
- * @method {function} removeWorker - Removes a worker (employee or outsourcer)
149
+ * @method removeWorker - Removes a worker (employee or outsourcer)
150
150
  * - @param {Object} options - Options for removing a worker
151
151
  * - @param {string} options.workerId - The ID of the employee or outsourcer
152
152
  * - @param {boolean} [options.isEmployee=true] - True for employee, false for outsourcer
153
- * @method {function} setSiteIdCallback - Callback method called when `siteId` is set
153
+ * @method setSiteIdCallback - Callback method called when `siteId` is set
154
154
  * - Override this method in subclasses to add custom behavior when `siteId` changes.
155
155
  * - By default, does nothing.
156
156
  * - @param {string} v - The new `siteId` value
157
- * @method {function} setShiftTypeCallback - Callback method called when `shiftType` is set
157
+ * @method setShiftTypeCallback - Callback method called when `shiftType` is set
158
158
  * - Override this method in subclasses to add custom behavior when `shiftType` changes.
159
159
  * - By default, does nothing.
160
160
  * - @param {string} v - The new `shiftType` value
161
- * @method {function} setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
161
+ * @method setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
162
162
  * - Override this method in subclasses to add custom behavior when `regulationWorkMinutes` changes.
163
163
  * - By default, does nothing.
164
164
  * - @param {number} v - The new `regulationWorkMinutes` value
165
+ *
165
166
  * @static
166
167
  * @method groupKeyDivider
167
- * Returns an array dividing the key into siteId, shiftType, and date.
168
- * @param {Object|string} key - The combined key string or object
169
- * @returns {Array<string>} - Array containing [siteId, shiftType, date]
170
- * @throws {Error} - If the key is invalid.
171
- * ---------------------------------------------------------------------------
172
- * @inherited - The following method is inherited from WorkingResult (via Operation):
173
- * @method {function} setDateAtCallback - Callback method called when `dateAt` is set
174
- * - Override this method in subclasses to add custom behavior when `dateAt` changes.
175
- * - By default, updates `dayType` based on the new `dateAt` value and synchronizes to workers.
176
- * - @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.
177
174
  *****************************************************************************/
178
175
  import Operation from "./Operation.js";
179
176
  import Agreement from "./Agreement.js";
@@ -187,7 +184,6 @@ import CutoffDate from "./utils/CutoffDate.js";
187
184
 
188
185
  const classProps = {
189
186
  ...Operation.classProps,
190
- ...Agreement.classProps,
191
187
  siteOperationScheduleId: defField("oneLine", { hidden: true }),
192
188
  useAdjustedQuantity: defField("check", {
193
189
  label: "調整数量を使用",
@@ -209,11 +205,25 @@ const classProps = {
209
205
  label: "資格残業(調整)",
210
206
  default: 0,
211
207
  }),
212
- billingDateAt: defField("dateAt", { label: "請求日付", required: true }),
208
+ billingDateAt: defField("dateAt", { label: "請求日付" }),
213
209
  employees: defField("array", { customClass: OperationResultDetail }),
214
210
  outsourcers: defField("array", {
215
211
  customClass: OperationResultDetail,
216
212
  }),
213
+ isLocked: defField("check", {
214
+ label: "実績確定",
215
+ default: false,
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",
217
227
  };
218
228
 
219
229
  export default class OperationResult extends Operation {
@@ -235,20 +245,8 @@ export default class OperationResult extends Operation {
235
245
  super.afterInitialize();
236
246
 
237
247
  /** Computed properties */
238
- let _cutoffDate = this.cutoffDate;
248
+ let _agreement = this.agreement;
239
249
  Object.defineProperties(this, {
240
- cutoffDate: {
241
- configurable: true,
242
- enumerable: true,
243
- get() {
244
- return _cutoffDate;
245
- },
246
- set(v) {
247
- _cutoffDate = v;
248
- // Update billingDateAt when cutoffDate changes
249
- this.refreshBillingDateAt();
250
- },
251
- },
252
250
  statistics: {
253
251
  configurable: true,
254
252
  enumerable: true,
@@ -324,22 +322,9 @@ export default class OperationResult extends Operation {
324
322
  return createInitialValues();
325
323
  }
326
324
 
327
- const unitPrice = isQualified
328
- ? this.unitPriceQualified || 0
329
- : this.unitPriceBase || 0;
330
- const overtimeUnitPrice = isQualified
331
- ? this.overtimeUnitPriceQualified || 0
332
- : this.overtimeUnitPriceBase || 0;
333
- const isPerHour =
334
- this.billingUnitType === BILLING_UNIT_TYPE_PER_HOUR;
335
-
336
325
  const result = createInitialValues();
337
326
 
338
- // 基本情報の設定
339
- result.unitPrice = unitPrice;
340
- result.overtimeUnitPrice = overtimeUnitPrice;
341
-
342
- // 調整値の使用判定
327
+ // agreementの有無に関わらず数量と残業時間を計算
343
328
  if (this.useAdjustedQuantity) {
344
329
  result.quantity = isQualified
345
330
  ? this.adjustedQuantityQualified || 0
@@ -348,35 +333,45 @@ export default class OperationResult extends Operation {
348
333
  ? this.adjustedOvertimeQualified || 0
349
334
  : this.adjustedOvertimeBase || 0;
350
335
  } else {
351
- // result.quantity = isPerHour
352
- // ? (categoryStats.totalWorkMinutes || 0) / 60
353
- // : categoryStats.quantity || 0;
354
- // result.overtimeMinutes = categoryStats.overtimeWorkMinutes || 0;
336
+ // agreementがある場合のみbillingUnitTypeとincludeBreakInBillingを使用
337
+ const isPerHour =
338
+ this.agreement?.billingUnitType === BILLING_UNIT_TYPE_PER_HOUR;
339
+
355
340
  if (isPerHour) {
356
341
  // 時間単位請求の場合
357
342
  let totalMinutes = categoryStats.totalWorkMinutes || 0;
358
343
 
359
344
  // 休憩時間を請求に含める場合は休憩時間を追加
360
- if (this.includeBreakInBilling) {
345
+ if (this.agreement?.includeBreakInBilling) {
361
346
  totalMinutes += categoryStats.breakMinutes || 0;
362
347
  }
363
348
 
364
349
  result.quantity = totalMinutes / 60;
365
350
  } else {
366
- // 日単位請求の場合(休憩時間は関係なし)
351
+ // 日単位請求の場合(休憩時間は関係なし)
367
352
  result.quantity = categoryStats.quantity || 0;
368
353
  }
369
354
  result.overtimeMinutes = categoryStats.overtimeWorkMinutes || 0;
370
355
  }
371
356
 
372
- // 金額計算(RoundSettingを適用)
373
- result.regularAmount = RoundSetting.apply(
374
- result.quantity * unitPrice
375
- );
376
- result.overtimeAmount = RoundSetting.apply(
377
- (result.overtimeMinutes * overtimeUnitPrice) / 60
378
- );
379
- 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
+ }
380
375
 
381
376
  return result;
382
377
  };
@@ -421,39 +416,134 @@ export default class OperationResult extends Operation {
421
416
  },
422
417
  set(v) {},
423
418
  },
419
+ billingMonth: {
420
+ configurable: true,
421
+ enumerable: true,
422
+ get() {
423
+ if (!this.billingDateAt) return null;
424
+ const jstDate = new Date(
425
+ this.billingDateAt.getTime() + 9 * 60 * 60 * 1000
426
+ ); /* JST補正 */
427
+ const year = jstDate.getUTCFullYear();
428
+ const month = jstDate.getUTCMonth() + 1;
429
+ return `${year}-${String(month).padStart(2, "0")}`;
430
+ },
431
+ set(v) {},
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
+ },
424
467
  });
425
468
  }
426
469
 
470
+ /**
471
+ * Refresh billingDateAt based on dateAt and cutoffDate
472
+ * @returns {void}
473
+ */
427
474
  refreshBillingDateAt() {
428
475
  if (!this.dateAt) {
429
476
  this.billingDateAt = null;
430
477
  return;
431
478
  }
432
- 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) {
433
484
  this.billingDateAt = null;
434
485
  return;
435
486
  }
436
487
  this.billingDateAt = CutoffDate.calculateBillingDateAt(
437
488
  this.dateAt,
438
- this.cutoffDate
489
+ this.agreement.cutoffDate
439
490
  );
440
491
  }
441
492
 
493
+ /**
494
+ * Override `setDateAtCallback` to refresh billingDateAt
495
+ * @param {Date} v
496
+ */
442
497
  setDateAtCallback(v) {
443
498
  super.setDateAtCallback(v);
444
499
  this.refreshBillingDateAt();
445
500
  }
446
501
 
447
502
  /**
448
- * Override `beforeDelete`.
449
- * - 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>}
506
+ */
507
+ async create(options = {}) {
508
+ if (this.allowEmptyAgreement && !this.billingDateAt) {
509
+ throw new Error(
510
+ "[OperationResult] Billing date is required when 'allowEmptyAgreement' is true."
511
+ );
512
+ }
513
+ return await super.create(options);
514
+ }
515
+
516
+ /**
517
+ * Override update method to prevent editing if isLocked is true
518
+ * - Also validate billingDateAt when allowEmptyAgreement is true
519
+ * @param {*} options
520
+ * @returns {Promise<void>}
521
+ */
522
+ async update(options = {}) {
523
+ if (this.isLocked) {
524
+ throw new Error(
525
+ "[OperationResult] This OperationResult is locked and cannot be edited."
526
+ );
527
+ }
528
+ if (this.allowEmptyAgreement && !this.billingDateAt) {
529
+ throw new Error(
530
+ "[OperationResult] Billing date is required when 'allowEmptyAgreement' is true."
531
+ );
532
+ }
533
+ return await super.update(options);
534
+ }
535
+
536
+ /**
537
+ * Override delete method to prevent deletion if isLocked is true
538
+ * @param {*} options
539
+ * @returns {Promise<void>}
450
540
  */
451
- async beforeDelete() {
452
- await super.beforeDelete();
453
- if (this.siteOperationScheduleId) {
541
+ async delete(options = {}) {
542
+ if (this.isLocked) {
454
543
  throw new Error(
455
- "この稼働実績は現場稼働予定から作成されているため、削除できません。"
544
+ "[OperationResult] This OperationResult is locked and cannot be deleted."
456
545
  );
457
546
  }
547
+ return await super.delete(options);
458
548
  }
459
549
  }