@shisyamo4131/air-guard-v2-schemas 1.3.1-dev.21 → 1.3.1-dev.23
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 +1 -1
- package/src/Billing.js +78 -7
- package/src/Customer.js +40 -0
package/package.json
CHANGED
package/src/Billing.js
CHANGED
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @prop {string} customerId - customer document id
|
|
8
8
|
* @prop {string} siteId - site document id
|
|
9
|
-
* @prop {
|
|
10
|
-
* @prop {Date}
|
|
11
|
-
* @prop {Date} paymentDueDate - payment due date
|
|
9
|
+
* @prop {Date} billingDateAt - billing date
|
|
10
|
+
* @prop {Date} paymentDueDateAt - payment due date
|
|
12
11
|
*
|
|
13
12
|
* @prop {Array} paymentRecords - payment records (not implemented yet)
|
|
14
13
|
*
|
|
@@ -17,10 +16,14 @@
|
|
|
17
16
|
* @prop {Object} adjustment - adjustment
|
|
18
17
|
* @prop {string} remarks - remarks
|
|
19
18
|
*
|
|
19
|
+
* @prop {string} billingMonth - billing month (YYYY-MM format) (read-only)
|
|
20
|
+
* @prop {Date} billingDate - billing date (YYYY-MM-DD format) (read-only)
|
|
21
|
+
* @prop {string} paymentDueMonth - payment due month (YYYY-MM format) (read-only)
|
|
22
|
+
* @prop {Date} paymentDueDate - payment due date (YYYY-MM-DD format) (read-only)
|
|
20
23
|
* @prop {number} subtotal - subtotal (excluding tax) (computed-readonly)
|
|
21
24
|
* @prop {number} taxAmount - tax amount (computed-readonly)
|
|
22
25
|
* @prop {number} totalAmount - total amount (including tax) (computed-readonly)
|
|
23
|
-
* @prop {Array<Object>}
|
|
26
|
+
* @prop {Array<Object>} summary - summary for display (computed-readonly)
|
|
24
27
|
*****************************************************************************/
|
|
25
28
|
|
|
26
29
|
import FireModel from "@shisyamo4131/air-firebase-v2";
|
|
@@ -37,8 +40,7 @@ const STATUS = {
|
|
|
37
40
|
const classProps = {
|
|
38
41
|
customerId: defField("customerId", { required: true }),
|
|
39
42
|
siteId: defField("siteId", { required: true }),
|
|
40
|
-
|
|
41
|
-
billingDateAt: defField("dateAt"),
|
|
43
|
+
billingDateAt: defField("dateAt", { required: true }),
|
|
42
44
|
paymentDueDateAt: defField("dateAt"),
|
|
43
45
|
|
|
44
46
|
// 入金管理用配列(現時点では未使用 将来の拡張用)
|
|
@@ -66,6 +68,75 @@ export default class Billing extends FireModel {
|
|
|
66
68
|
afterInitialize(item = {}) {
|
|
67
69
|
super.afterInitialize(item);
|
|
68
70
|
|
|
71
|
+
// billingDate (YYYY-MM-DD) と billingMonth (YYYY-MM) の計算用プロパティを定義
|
|
72
|
+
Object.defineProperties(this, {
|
|
73
|
+
billingDate: {
|
|
74
|
+
configurable: true,
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get() {
|
|
77
|
+
if (!this.billingDateAt) return null;
|
|
78
|
+
const jstDate = new Date(
|
|
79
|
+
this.billingDateAt.getTime() + 9 * 60 * 60 * 1000
|
|
80
|
+
); /* JST補正 */
|
|
81
|
+
const year = jstDate.getUTCFullYear();
|
|
82
|
+
const month = jstDate.getUTCMonth() + 1;
|
|
83
|
+
const day = jstDate.getUTCDate();
|
|
84
|
+
return `${year}-${String(month).padStart(2, "0")}-${String(
|
|
85
|
+
day
|
|
86
|
+
).padStart(2, "0")}`;
|
|
87
|
+
},
|
|
88
|
+
set(v) {},
|
|
89
|
+
},
|
|
90
|
+
billingMonth: {
|
|
91
|
+
configurable: true,
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get() {
|
|
94
|
+
if (!this.billingDateAt) return null;
|
|
95
|
+
const jstDate = new Date(
|
|
96
|
+
this.billingDateAt.getTime() + 9 * 60 * 60 * 1000
|
|
97
|
+
); /* JST補正 */
|
|
98
|
+
const year = jstDate.getUTCFullYear();
|
|
99
|
+
const month = jstDate.getUTCMonth() + 1;
|
|
100
|
+
return `${year}-${String(month).padStart(2, "0")}`;
|
|
101
|
+
},
|
|
102
|
+
set(v) {},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
Object.defineProperties(this, {
|
|
107
|
+
paymentDueDate: {
|
|
108
|
+
configurable: true,
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get() {
|
|
111
|
+
if (!this.paymentDueDateAt) return null;
|
|
112
|
+
const jstDate = new Date(
|
|
113
|
+
this.paymentDueDateAt.getTime() + 9 * 60 * 60 * 1000
|
|
114
|
+
); /* JST補正 */
|
|
115
|
+
const year = jstDate.getUTCFullYear();
|
|
116
|
+
const month = jstDate.getUTCMonth() + 1;
|
|
117
|
+
const day = jstDate.getUTCDate();
|
|
118
|
+
return `${year}-${String(month).padStart(2, "0")}-${String(
|
|
119
|
+
day
|
|
120
|
+
).padStart(2, "0")}`;
|
|
121
|
+
},
|
|
122
|
+
set(v) {},
|
|
123
|
+
},
|
|
124
|
+
paymentDueMonth: {
|
|
125
|
+
configurable: true,
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get() {
|
|
128
|
+
if (!this.paymentDueDateAt) return null;
|
|
129
|
+
const jstDate = new Date(
|
|
130
|
+
this.paymentDueDateAt.getTime() + 9 * 60 * 60 * 1000
|
|
131
|
+
); /* JST補正 */
|
|
132
|
+
const year = jstDate.getUTCFullYear();
|
|
133
|
+
const month = jstDate.getUTCMonth() + 1;
|
|
134
|
+
return `${year}-${String(month).padStart(2, "0")}`;
|
|
135
|
+
},
|
|
136
|
+
set(v) {},
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
69
140
|
// 小計(税抜)を計算
|
|
70
141
|
Object.defineProperty(this, "subtotal", {
|
|
71
142
|
get() {
|
|
@@ -100,7 +171,7 @@ export default class Billing extends FireModel {
|
|
|
100
171
|
});
|
|
101
172
|
|
|
102
173
|
// 表示用の明細サマリーを生成
|
|
103
|
-
Object.defineProperty(this, "
|
|
174
|
+
Object.defineProperty(this, "summary", {
|
|
104
175
|
get() {
|
|
105
176
|
return this.operationResults.map((item) => ({
|
|
106
177
|
operationResultId: item.docId,
|
package/src/Customer.js
CHANGED
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
* @static
|
|
30
30
|
* @prop {string} STATUS_ACTIVE - constant for active contract status
|
|
31
31
|
* @prop {string} STATUS_TERMINATED - constant for terminated contract status
|
|
32
|
+
*
|
|
33
|
+
* @method getPaymentDueAt
|
|
34
|
+
* @param {Date} baseDate - base date in UTC (JST - 9 hours)
|
|
35
|
+
* @returns {Date} payment due date in UTC (JST - 9 hours)
|
|
32
36
|
*****************************************************************************/
|
|
33
37
|
import FireModel from "@shisyamo4131/air-firebase-v2";
|
|
34
38
|
import { defField } from "./parts/fieldDefinitions.js";
|
|
@@ -99,6 +103,42 @@ export default class Customer extends FireModel {
|
|
|
99
103
|
prefecture: defAccessor("prefecture"),
|
|
100
104
|
});
|
|
101
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 支払期日を計算する
|
|
109
|
+
* @param {Date} baseDate - 基準日(JSTから9時間引いたUTC表現)
|
|
110
|
+
* @returns {Date} 支払期日(JSTから9時間引いたUTC表現)
|
|
111
|
+
*/
|
|
112
|
+
getPaymentDueAt(baseDate) {
|
|
113
|
+
// UTC → JST に変換(+9時間)
|
|
114
|
+
const jstDate = new Date(baseDate.getTime() + 9 * 60 * 60 * 1000);
|
|
115
|
+
|
|
116
|
+
// UTCメソッドでJST相当の年月を取得
|
|
117
|
+
const year = jstDate.getUTCFullYear();
|
|
118
|
+
const month = jstDate.getUTCMonth();
|
|
119
|
+
|
|
120
|
+
// paymentMonth分加算した年月を計算
|
|
121
|
+
const targetMonth = month + this.paymentMonth;
|
|
122
|
+
const targetYear = year + Math.floor(targetMonth / 12);
|
|
123
|
+
const finalMonth = targetMonth % 12;
|
|
124
|
+
|
|
125
|
+
let dueDate;
|
|
126
|
+
if (this.paymentDate === CutoffDate.VALUES.END_OF_MONTH) {
|
|
127
|
+
// 月末の場合
|
|
128
|
+
dueDate = new Date(Date.UTC(targetYear, finalMonth + 1, 0));
|
|
129
|
+
} else {
|
|
130
|
+
// 指定日の場合
|
|
131
|
+
dueDate = new Date(Date.UTC(targetYear, finalMonth, this.paymentDate));
|
|
132
|
+
|
|
133
|
+
// 指定日が存在しない場合は月末にする
|
|
134
|
+
if (dueDate.getUTCMonth() !== finalMonth) {
|
|
135
|
+
dueDate = new Date(Date.UTC(targetYear, finalMonth + 1, 0));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// JST → UTC に変換(-9時間)
|
|
140
|
+
return new Date(dueDate.getTime() - 9 * 60 * 60 * 1000);
|
|
141
|
+
}
|
|
102
142
|
}
|
|
103
143
|
|
|
104
144
|
/*****************************************************************************
|