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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisyamo4131/air-guard-v2-schemas",
3
- "version": "1.2.1",
3
+ "version": "1.3.1-dev.0",
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
@@ -234,6 +234,34 @@ export default class Agreement extends WorkingResult {
234
234
  static classProps = classProps;
235
235
  static headers = headers;
236
236
 
237
+ /**
238
+ * Returns an object containing price-related properties.
239
+ * This accessor is useful for synchronizing price details when creating `OperationResult` instance
240
+ * from a `SiteOperationSchedule`.
241
+ * - Includes `regulationWorkMinutes`.
242
+ * @returns {Object} An object with price-related properties.
243
+ * @property {number} cutoffDate - Cutoff date
244
+ * @property {number} regulationWorkMinutes - Regulation work minutes
245
+ * @property {number} unitPriceBase - Base unit price
246
+ * @property {number} overtimeUnitPriceBase - Overtime base unit price
247
+ * @property {number} unitPriceQualified - Qualified unit price
248
+ * @property {number} overtimeUnitPriceQualified - Overtime qualified unit price
249
+ * @property {string} billingUnitType - Billing unit type
250
+ * @property {boolean} includeBreakInBilling - Whether to include break time in billing
251
+ */
252
+ get billingInfo() {
253
+ return {
254
+ cutoffDate: this.cutoffDate,
255
+ regulationWorkMinutes: this.regulationWorkMinutes,
256
+ unitPriceBase: this.unitPriceBase,
257
+ overtimeUnitPriceBase: this.overtimeUnitPriceBase,
258
+ unitPriceQualified: this.unitPriceQualified,
259
+ overtimeUnitPriceQualified: this.overtimeUnitPriceQualified,
260
+ billingUnitType: this.billingUnitType,
261
+ includeBreakInBilling: this.includeBreakInBilling,
262
+ };
263
+ }
264
+
237
265
  /**
238
266
  * Returns an object containing price-related properties.
239
267
  * This accessor is useful for synchronizing price details when creating `OperationResult` instance
@@ -249,6 +277,9 @@ export default class Agreement extends WorkingResult {
249
277
  * @property {boolean} includeBreakInBilling - Whether to include break time in billing
250
278
  */
251
279
  get prices() {
280
+ console.warn(
281
+ "`Agreement.prices` is deprecated. Use `Agreement.billingInfo` instead."
282
+ );
252
283
  return {
253
284
  regulationWorkMinutes: this.regulationWorkMinutes,
254
285
  unitPriceBase: this.unitPriceBase,
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
 
@@ -11,54 +11,57 @@
11
11
  * is not implemented, as billing records are typically generated through the OperationResult class.
12
12
  * ---------------------------------------------------------------------------
13
13
  * @inherited - The following properties are inherited from OperationResult:
14
- * @props {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
14
+ * @prop {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
15
15
  * - If this OperationBilling was created from a SiteOperationSchedule, this property holds that ID.
16
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
17
+ * @prop {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
18
+ * @prop {number} adjustedQuantityBase - Adjusted quantity for base workers
19
19
  * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
20
- * @props {number} adjustedOvertimeBase - Adjusted overtime for base workers
20
+ * @prop {number} adjustedOvertimeBase - Adjusted overtime for base workers
21
21
  * - Overtime used for billing base workers when `useAdjustedQuantity` is true.
22
- * @props {number} adjustedQuantityQualified - Adjusted quantity for qualified workers
22
+ * @prop {number} adjustedQuantityQualified - Adjusted quantity for qualified workers
23
23
  * - Quantity used for billing qualified workers when `useAdjustedQuantity` is true.
24
- * @props {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
24
+ * @prop {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
25
25
  * - Overtime used for billing qualified workers when `useAdjustedQuantity` is true.
26
- * @props {Date} billingDateAt - Billing date
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.
27
30
  * ---------------------------------------------------------------------------
28
31
  * @inherited - The following properties are inherited from Operation (via OperationResult):
29
- * @props {string} siteId - Site document ID (trigger property)
32
+ * @prop {string} siteId - Site document ID (trigger property)
30
33
  * - 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
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
36
39
  * - Array of `OperationResultDetail` instances representing assigned employees
37
- * @props {Array<OperationResultDetail>} outsourcers - Assigned outsourcers
40
+ * @prop {Array<OperationResultDetail>} outsourcers - Assigned outsourcers
38
41
  * - Array of `OperationResultDetail` instances representing assigned outsourcers
39
42
  * ---------------------------------------------------------------------------
40
43
  * @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
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
48
51
  * - The cutoff date for billing, using values defined in the CutoffDate utility class.
49
52
  * ---------------------------------------------------------------------------
50
53
  * @inherited - The following properties are inherited from WorkingResult (via OperationResult):
51
- * @props {Date} dateAt - Date of operation (placement date) (trigger property)
54
+ * @prop {Date} dateAt - Date of operation (placement date) (trigger property)
52
55
  * - 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)
56
+ * @prop {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
57
+ * @prop {string} shiftType - `DAY` or `NIGHT` (trigger property)
55
58
  * - 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
59
+ * @prop {string} startTime - Start time (HH:MM format)
60
+ * @prop {boolean} isStartNextDay - Next day start flag
58
61
  * - `true` if the actual work starts the day after the placement date `dateAt`
59
- * @props {string} endTime - End time (HH:MM format)
60
- * @props {number} breakMinutes - Break time (minutes)
61
- * @props {number} regulationWorkMinutes - Regulation work minutes (trigger property)
62
+ * @prop {string} endTime - End time (HH:MM format)
63
+ * @prop {number} breakMinutes - Break time (minutes)
64
+ * @prop {number} regulationWorkMinutes - Regulation work minutes (trigger property)
62
65
  * - Indicates the maximum working time treated as regular working hours.
63
66
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
64
67
  * ---------------------------------------------------------------------------
@@ -1,5 +1,5 @@
1
1
  /*****************************************************************************
2
- * OperationResult Model ver 1.0.0
2
+ * OperationResult Model ver 1.1.0
3
3
  * @author shisyamo4131
4
4
  * ---------------------------------------------------------------------------
5
5
  * - Extends Operation class to represent the result of an operation.
@@ -7,6 +7,8 @@
7
7
  * - Prevents deletion if the instance has `siteOperationScheduleId`.
8
8
  * - Provides comprehensive billing calculations including statistics, sales amounts, and tax.
9
9
  * - Supports both daily and hourly billing with adjusted quantities.
10
+ * - Automatically updates `billingDateAt` based on `dateAt` and `cutoffDate`.
11
+ * - Introduces a lock mechanism (`isLocked`) to prevent edits when necessary.
10
12
  * ---------------------------------------------------------------------------
11
13
  * @prop {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
12
14
  * - If this OperationResult was created from a SiteOperationSchedule, this property holds that ID.
@@ -21,6 +23,9 @@
21
23
  * @prop {number} adjustedOvertimeQualified - Adjusted overtime for qualified workers
22
24
  * - Overtime used for billing qualified workers when `useAdjustedQuantity` is true.
23
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.
24
29
  * ---------------------------------------------------------------------------
25
30
  * @computed {Object} statistics - Statistics of workers (read-only)
26
31
  * - Contains counts and total work minutes for base and qualified workers, including OJT breakdowns.
@@ -38,6 +43,7 @@
38
43
  * - Calculated using the `Tax` utility based on `salesAmount` and `date`.
39
44
  * @computed {number} billingAmount - Total billing amount including tax (read-only)
40
45
  * - Sum of `salesAmount` and `tax`.
46
+ * @computed {string} billingMonth - Billing month in YYYY-MM format (read-only)
41
47
  * ---------------------------------------------------------------------------
42
48
  * @inherited - The following properties are inherited from Operation:
43
49
  * @prop {string} siteId - Site document ID (trigger property)
@@ -60,10 +66,14 @@
60
66
  * @prop {boolean} includeBreakInBilling - Whether to include break time in billing if `billingUnitType` is `PER_HOUR`.
61
67
  * @prop {number} cutoffDate - Cutoff date value from CutoffDate.VALUES
62
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.
63
71
  * ---------------------------------------------------------------------------
64
72
  * @inherited - The following properties are inherited from WorkingResult (via Operation):
65
73
  * @prop {Date} dateAt - Date of operation (placement date) (trigger property)
66
74
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
75
+ * - Used to determine `dayType`.
76
+ * - When `dateAt` changes, `billingDateAt` is also updated based on `cutoffDate`.
67
77
  * @prop {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
68
78
  * @prop {string} shiftType - `DAY` or `NIGHT` (trigger property)
69
79
  * - Automatically synchronizes to all `employees` and `outsourcers` when changed.
@@ -132,6 +142,8 @@
132
142
  * @method {function} beforeDelete - Override method to prevent deletion with siteOperationScheduleId
133
143
  * - Prevents deletion if the instance has `siteOperationScheduleId`.
134
144
  * - Throws an error if deletion is attempted on an instance created from SiteOperationSchedule.
145
+ * @method {function} refreshBillingDateAt - Refresh billingDateAt based on dateAt and cutoffDate
146
+ * - Updates `billingDateAt` based on the current `dateAt` and `cutoffDate` values.
135
147
  * ---------------------------------------------------------------------------
136
148
  * @inherited - The following methods are inherited from Operation:
137
149
  * @method {function} addWorker - Adds a new worker (employee or outsourcer)
@@ -214,6 +226,10 @@ const classProps = {
214
226
  outsourcers: defField("array", {
215
227
  customClass: OperationResultDetail,
216
228
  }),
229
+ isLocked: defField("check", {
230
+ label: "ロック",
231
+ default: false,
232
+ }),
217
233
  };
218
234
 
219
235
  export default class OperationResult extends Operation {
@@ -246,12 +262,7 @@ export default class OperationResult extends Operation {
246
262
  set(v) {
247
263
  _cutoffDate = v;
248
264
  // Update billingDateAt when cutoffDate changes
249
- if (this.dateAt) {
250
- this.billingDateAt = CutoffDate.calculateBillingDateAt(
251
- this.dateAt,
252
- this.cutoffDate
253
- );
254
- }
265
+ this.refreshBillingDateAt();
255
266
  },
256
267
  },
257
268
  statistics: {
@@ -426,13 +437,49 @@ export default class OperationResult extends Operation {
426
437
  },
427
438
  set(v) {},
428
439
  },
440
+ billingMonth: {
441
+ configurable: true,
442
+ enumerable: true,
443
+ get() {
444
+ if (!this.billingDateAt) return null;
445
+ const jstDate = new Date(
446
+ this.billingDateAt.getTime() + 9 * 60 * 60 * 1000
447
+ ); /* JST補正 */
448
+ const year = jstDate.getUTCFullYear();
449
+ const month = jstDate.getUTCMonth() + 1;
450
+ return `${year}-${String(month).padStart(2, "0")}`;
451
+ },
452
+ set(v) {},
453
+ },
429
454
  });
430
455
  }
431
456
 
457
+ /**
458
+ * Refresh billingDateAt based on dateAt and cutoffDate
459
+ * @returns {void}
460
+ */
461
+ refreshBillingDateAt() {
462
+ if (!this.dateAt) {
463
+ this.billingDateAt = null;
464
+ return;
465
+ }
466
+ if (this.cutoffDate !== 0 && !this.cutoffDate) {
467
+ this.billingDateAt = null;
468
+ return;
469
+ }
470
+ this.billingDateAt = CutoffDate.calculateBillingDateAt(
471
+ this.dateAt,
472
+ this.cutoffDate
473
+ );
474
+ }
475
+
476
+ /**
477
+ * Override `setDateAtCallback` to refresh billingDateAt
478
+ * @param {Date} v
479
+ */
432
480
  setDateAtCallback(v) {
433
481
  super.setDateAtCallback(v);
434
- if (!this.cutoffDate) return;
435
- this.billingDateAt = CutoffDate.calculateBillingDateAt(v, this.cutoffDate);
482
+ this.refreshBillingDateAt();
436
483
  }
437
484
 
438
485
  /**
@@ -447,4 +494,32 @@ export default class OperationResult extends Operation {
447
494
  );
448
495
  }
449
496
  }
497
+
498
+ /**
499
+ * Override update method to prevent editing if isLocked is true
500
+ * @param {*} options
501
+ * @returns {Promise<void>}
502
+ */
503
+ async update(options = {}) {
504
+ if (this.isLocked) {
505
+ throw new Error(
506
+ "[OperationResult] This OperationResult is locked and cannot be edited."
507
+ );
508
+ }
509
+ return super.update(options);
510
+ }
511
+
512
+ /**
513
+ * Override delete method to prevent deletion if isLocked is true
514
+ * @param {*} options
515
+ * @returns {Promise<void>}
516
+ */
517
+ async delete(options = {}) {
518
+ if (this.isLocked) {
519
+ throw new Error(
520
+ "[OperationResult] This OperationResult is locked and cannot be deleted."
521
+ );
522
+ }
523
+ return super.delete(options);
524
+ }
450
525
  }