@shisyamo4131/air-guard-v2-schemas 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +15 -0
- package/package.json +44 -0
- package/src/Agreement.js +262 -0
- package/src/ArrangementNotification.js +505 -0
- package/src/Billing.js +159 -0
- package/src/Company.js +176 -0
- package/src/Customer.js +98 -0
- package/src/Employee.js +201 -0
- package/src/Operation.js +779 -0
- package/src/OperationBilling.js +193 -0
- package/src/OperationDetail.js +147 -0
- package/src/OperationResult.js +437 -0
- package/src/OperationResultDetail.js +72 -0
- package/src/Outsourcer.js +46 -0
- package/src/RoundSetting.js +123 -0
- package/src/Site.js +192 -0
- package/src/SiteOperationSchedule.js +503 -0
- package/src/SiteOperationScheduleDetail.js +99 -0
- package/src/SiteOrder.js +62 -0
- package/src/Tax.js +39 -0
- package/src/User.js +41 -0
- package/src/WorkingResult.js +297 -0
- package/src/apis/index.js +9 -0
- package/src/constants/arrangement-notification-status.js +68 -0
- package/src/constants/billing-unit-type.js +15 -0
- package/src/constants/contract-status.js +15 -0
- package/src/constants/day-type.js +44 -0
- package/src/constants/employment-status.js +15 -0
- package/src/constants/gender.js +11 -0
- package/src/constants/index.js +9 -0
- package/src/constants/prefectures.js +56 -0
- package/src/constants/shift-type.js +20 -0
- package/src/constants/site-status.js +15 -0
- package/src/parts/accessorDefinitions.js +109 -0
- package/src/parts/fieldDefinitions.js +642 -0
- package/src/utils/ContextualError.js +49 -0
- package/src/utils/CutoffDate.js +223 -0
- package/src/utils/index.js +48 -0
package/src/Site.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/Site.js
|
|
3
|
+
* @author shisyamo4131
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { default as FireModel } from "@shisyamo4131/air-firebase-v2";
|
|
7
|
+
import { defField } from "./parts/fieldDefinitions.js";
|
|
8
|
+
import { defAccessor } from "./parts/accessorDefinitions.js";
|
|
9
|
+
import { CustomerMinimal } from "./Customer.js";
|
|
10
|
+
import { fetchDocsApi } from "./apis/index.js";
|
|
11
|
+
import Agreement from "./Agreement.js";
|
|
12
|
+
import { VALUES } from "./constants/site-status.js";
|
|
13
|
+
|
|
14
|
+
const classProps = {
|
|
15
|
+
code: defField("code", { label: "現場コード" }),
|
|
16
|
+
name: defField("name", {
|
|
17
|
+
label: "現場名",
|
|
18
|
+
length: 40,
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
nameKana: defField("nameKana", {
|
|
22
|
+
label: "現場名(カナ)",
|
|
23
|
+
length: 60,
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
zipcode: defField("zipcode"),
|
|
27
|
+
prefCode: defField("prefCode", { required: true }),
|
|
28
|
+
city: defField("city", { required: true }),
|
|
29
|
+
address: defField("address", { required: true }),
|
|
30
|
+
building: defField("building"),
|
|
31
|
+
location: defField("location"),
|
|
32
|
+
customer: defField("customer", {
|
|
33
|
+
required: true,
|
|
34
|
+
customClass: CustomerMinimal,
|
|
35
|
+
component: {
|
|
36
|
+
attrs: {
|
|
37
|
+
api: () => fetchDocsApi(CustomerMinimal),
|
|
38
|
+
noFilter: true,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
remarks: defField("multipleLine", { label: "備考" }),
|
|
43
|
+
agreements: defField("array", { label: "取極め", customClass: Agreement }),
|
|
44
|
+
status: defField("siteStatus", { required: true }),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/*****************************************************************************
|
|
48
|
+
* @props {string} code - Site code.
|
|
49
|
+
* @props {string} name - Site name.
|
|
50
|
+
* @props {string} nameKana - Site name in Kana.
|
|
51
|
+
* @props {string} zipcode - Postal code.
|
|
52
|
+
* @props {string} prefCode - Prefecture code.
|
|
53
|
+
* @props {string} city - City name.
|
|
54
|
+
* @props {string} address - Address details.
|
|
55
|
+
* @props {string} building - Building name.
|
|
56
|
+
* @props {object} location - Geographical location.
|
|
57
|
+
* @props {object} customer - Associated customer (CustomerMinimal).
|
|
58
|
+
* @props {string} remarks - Additional remarks.
|
|
59
|
+
* @props {array} agreements - List of agreements (Agreement).
|
|
60
|
+
* - Enhanced with custom methods: `add()`, `change()`, `remove()`
|
|
61
|
+
* @props {string} status - Site status.
|
|
62
|
+
*
|
|
63
|
+
* @computed {string} customerId - ID of the associated customer (read-only)
|
|
64
|
+
* @computed {string} fullAddress - Full address combining prefecture, city, and address (read-only)
|
|
65
|
+
* @computed {string} prefecture - Prefecture name derived from `prefCode` (read-only)
|
|
66
|
+
*
|
|
67
|
+
* @function getAgreement
|
|
68
|
+
* Gets applicable agreement based on date, dayType, and shiftType.
|
|
69
|
+
* @param {Object} args - Arguments object.
|
|
70
|
+
* @param {string} args.date - Date in YYYY-MM-DD format.
|
|
71
|
+
* @param {string} args.dayType - Day type (e.g., "WEEKDAY", "SATURDAY").
|
|
72
|
+
* @param {string} args.shiftType - Shift type (e.g., "DAY", "NIGHT").
|
|
73
|
+
* @returns {Agreement|null} - Matching agreement or null if not found.
|
|
74
|
+
*
|
|
75
|
+
* @memberof agreements
|
|
76
|
+
* @function add
|
|
77
|
+
* Adds Agreement instance to agreements array.
|
|
78
|
+
* @param {Agreement} agreement - Agreement instance to add.
|
|
79
|
+
* @throws {Error} If argument is not an Agreement instance.
|
|
80
|
+
*
|
|
81
|
+
* @memberof agreements
|
|
82
|
+
* @function change
|
|
83
|
+
* Replaces existing agreement by key matching.
|
|
84
|
+
* @param {Agreement} newAgreement - New Agreement instance to replace existing one.
|
|
85
|
+
* @throws {Error} If argument is not an Agreement instance or if agreement not found.
|
|
86
|
+
*
|
|
87
|
+
* @memberof agreements
|
|
88
|
+
* @function remove
|
|
89
|
+
* Removes agreement from array by key matching.
|
|
90
|
+
* @param {Agreement} agreement - Agreement instance to remove.
|
|
91
|
+
* @throws {Error} If agreement not found.
|
|
92
|
+
*****************************************************************************/
|
|
93
|
+
export default class Site extends FireModel {
|
|
94
|
+
static className = "現場";
|
|
95
|
+
static collectionPath = "Sites";
|
|
96
|
+
static useAutonumber = false;
|
|
97
|
+
static logicalDelete = true;
|
|
98
|
+
static classProps = classProps;
|
|
99
|
+
static tokenFields = ["name", "nameKana"];
|
|
100
|
+
static hasMany = [
|
|
101
|
+
{
|
|
102
|
+
collectionPath: "SiteOperationSchedules",
|
|
103
|
+
field: "siteId",
|
|
104
|
+
condition: "==",
|
|
105
|
+
type: "collection",
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
static headers = [
|
|
110
|
+
{ title: "code", key: "code", value: "code" },
|
|
111
|
+
{ title: "現場名", key: "name", value: "name" },
|
|
112
|
+
{ title: "取引先名", key: "customer.name", value: "customer.name" },
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
static STATUS_ACTIVE = VALUES.ACTIVE.value;
|
|
116
|
+
static STATUS_TERMINATED = VALUES.TERMINATED.value;
|
|
117
|
+
|
|
118
|
+
afterInitialize(item = {}) {
|
|
119
|
+
super.afterInitialize(item);
|
|
120
|
+
|
|
121
|
+
Object.defineProperties(this, {
|
|
122
|
+
customerId: defAccessor("customerId"),
|
|
123
|
+
fullAddress: defAccessor("fullAddress"),
|
|
124
|
+
prefecture: defAccessor("prefecture"),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const self = this;
|
|
128
|
+
Object.defineProperties(this.agreements, {
|
|
129
|
+
add: {
|
|
130
|
+
value: function (agreement) {
|
|
131
|
+
if (!(agreement instanceof Agreement)) {
|
|
132
|
+
throw new Error("Argument must be an instance of Agreement");
|
|
133
|
+
}
|
|
134
|
+
self.agreements.push(agreement);
|
|
135
|
+
},
|
|
136
|
+
writable: false,
|
|
137
|
+
enumerable: false,
|
|
138
|
+
},
|
|
139
|
+
change: {
|
|
140
|
+
value: function (newAgreement) {
|
|
141
|
+
if (!(newAgreement instanceof Agreement)) {
|
|
142
|
+
throw new Error("Argument must be an instance of Agreement");
|
|
143
|
+
}
|
|
144
|
+
const index = self.agreements.findIndex(
|
|
145
|
+
(agr) => agr.key === newAgreement._beforeData.key
|
|
146
|
+
);
|
|
147
|
+
if (index !== -1) {
|
|
148
|
+
self.agreements[index] = newAgreement;
|
|
149
|
+
} else {
|
|
150
|
+
throw new Error("Agreement not found");
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
writable: false,
|
|
154
|
+
enumerable: false,
|
|
155
|
+
},
|
|
156
|
+
remove: {
|
|
157
|
+
value: function (agreement) {
|
|
158
|
+
const index = self.agreements.findIndex(
|
|
159
|
+
(agr) => agr.key === agreement._beforeData.key
|
|
160
|
+
);
|
|
161
|
+
if (index !== -1) {
|
|
162
|
+
self.agreements.splice(index, 1);
|
|
163
|
+
} else {
|
|
164
|
+
throw new Error("Agreement not found");
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Returns the applicable agreement based on the given date, dayType, and shiftType.
|
|
173
|
+
* Filters agreements by dayType and shiftType, sorts them by startDate in descending order,
|
|
174
|
+
* and returns the first agreement where date is less than or equal to the given date.
|
|
175
|
+
* If no such agreement exists, returns null.
|
|
176
|
+
* @param {Object} args - The arguments object.
|
|
177
|
+
* @param {String} args.date - The date (in YYYY-MM-DD format) to check against agreement start dates.
|
|
178
|
+
* @param {String} args.dayType - The type of day (e.g., weekday, weekend) to filter agreements.
|
|
179
|
+
* @param {String} args.shiftType - The type of shift (e.g., morning, evening) to filter agreements.
|
|
180
|
+
* @returns {Object|null} - The matching agreement object or null if not found.
|
|
181
|
+
*/
|
|
182
|
+
getAgreement(args = {}) {
|
|
183
|
+
const { date, dayType, shiftType } = args;
|
|
184
|
+
if (!date || !dayType || !shiftType) return null;
|
|
185
|
+
return (
|
|
186
|
+
this.agreements
|
|
187
|
+
.filter((agr) => agr.dayType === dayType && agr.shiftType === shiftType)
|
|
188
|
+
.sort((a, b) => b.date.localeCompare(a.date))
|
|
189
|
+
.find((agr) => agr.date <= date) || null
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|