@tomei/rental 0.11.4 → 0.12.2
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/.husky/commit-msg +0 -0
- package/.husky/pre-commit +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -17
- package/dist/src/components/agreement/agreement.d.ts +17 -17
- package/dist/src/components/agreement/agreement.js +49 -49
- package/dist/src/components/agreement/agreement.js.map +1 -1
- package/dist/src/components/agreement/agreement.repository.d.ts +8 -8
- package/dist/src/components/agreement/agreement.repository.js +66 -66
- package/dist/src/components/agreement/agreement.repository.js.map +1 -1
- package/dist/src/components/booking/booking.d.ts +46 -45
- package/dist/src/components/booking/booking.js +313 -271
- package/dist/src/components/booking/booking.js.map +1 -1
- package/dist/src/components/booking/booking.repository.d.ts +8 -8
- package/dist/src/components/booking/booking.repository.js +66 -66
- package/dist/src/components/booking/booking.repository.js.map +1 -1
- package/dist/src/components/joint-hirer/joint-hirer.d.ts +23 -23
- package/dist/src/components/joint-hirer/joint-hirer.js +105 -105
- package/dist/src/components/joint-hirer/joint-hirer.js.map +1 -1
- package/dist/src/components/joint-hirer/joint-hirer.repository.d.ts +8 -8
- package/dist/src/components/joint-hirer/joint-hirer.repository.js +66 -66
- package/dist/src/components/joint-hirer/joint-hirer.repository.js.map +1 -1
- package/dist/src/components/rental/rental.d.ts +59 -59
- package/dist/src/components/rental/rental.js +603 -603
- package/dist/src/components/rental/rental.js.map +1 -1
- package/dist/src/components/rental/rental.repository.d.ts +8 -8
- package/dist/src/components/rental/rental.repository.js +66 -66
- package/dist/src/components/rental/rental.repository.js.map +1 -1
- package/dist/src/components/rental-price/rental-price.d.ts +18 -18
- package/dist/src/components/rental-price/rental-price.js +78 -78
- package/dist/src/components/rental-price/rental-price.js.map +1 -1
- package/dist/src/components/rental-price/rental-price.repository.d.ts +8 -8
- package/dist/src/components/rental-price/rental-price.repository.js +66 -66
- package/dist/src/components/rental-price/rental-price.repository.js.map +1 -1
- package/dist/src/database.d.ts +4 -4
- package/dist/src/database.js +24 -25
- package/dist/src/database.js.map +1 -1
- package/dist/src/enum/account-type.enum.d.ts +4 -4
- package/dist/src/enum/account-type.enum.js +8 -8
- package/dist/src/enum/account-type.enum.js.map +1 -1
- package/dist/src/enum/aggrement-status.enum.d.ts +5 -5
- package/dist/src/enum/aggrement-status.enum.js +9 -9
- package/dist/src/enum/aggrement-status.enum.js.map +1 -1
- package/dist/src/enum/booking.enum.d.ts +5 -5
- package/dist/src/enum/booking.enum.js +9 -9
- package/dist/src/enum/booking.enum.js.map +1 -1
- package/dist/src/enum/index.d.ts +5 -5
- package/dist/src/enum/index.js +11 -11
- package/dist/src/enum/rental-status.enum.d.ts +9 -9
- package/dist/src/enum/rental-status.enum.js +13 -13
- package/dist/src/enum/rental-status.enum.js.map +1 -1
- package/dist/src/index.d.ts +15 -15
- package/dist/src/index.js +42 -42
- package/dist/src/interfaces/agreement-attr.interface.d.ts +7 -7
- package/dist/src/interfaces/agreement-attr.interface.js +2 -2
- package/dist/src/interfaces/booking-attr.interface.d.ts +18 -18
- package/dist/src/interfaces/booking-attr.interface.js +2 -2
- package/dist/src/interfaces/booking-find-all-search-attr.interface.d.ts +12 -12
- package/dist/src/interfaces/booking-find-all-search-attr.interface.js +2 -2
- package/dist/src/interfaces/index.d.ts +7 -7
- package/dist/src/interfaces/index.js +2 -2
- package/dist/src/interfaces/joint-hirer-attr.interface.d.ts +10 -10
- package/dist/src/interfaces/joint-hirer-attr.interface.js +2 -2
- package/dist/src/interfaces/rental-attr.interface.d.ts +24 -24
- package/dist/src/interfaces/rental-attr.interface.js +2 -2
- package/dist/src/interfaces/rental-find-all-search-attr.interface.d.ts +10 -10
- package/dist/src/interfaces/rental-find-all-search-attr.interface.js +2 -2
- package/dist/src/interfaces/rental-price-attr.interface.d.ts +7 -7
- package/dist/src/interfaces/rental-price-attr.interface.js +2 -2
- package/dist/src/models/agreement.entity.d.ts +10 -10
- package/dist/src/models/agreement.entity.js +59 -59
- package/dist/src/models/agreement.entity.js.map +1 -1
- package/dist/src/models/booking.entity.d.ts +21 -21
- package/dist/src/models/booking.entity.js +127 -127
- package/dist/src/models/booking.entity.js.map +1 -1
- package/dist/src/models/index.d.ts +6 -6
- package/dist/src/models/index.js +13 -13
- package/dist/src/models/joint-hirer.entity.d.ts +13 -13
- package/dist/src/models/joint-hirer.entity.js +78 -78
- package/dist/src/models/joint-hirer.entity.js.map +1 -1
- package/dist/src/models/rental-price.entity.d.ts +8 -8
- package/dist/src/models/rental-price.entity.js +58 -58
- package/dist/src/models/rental-price.entity.js.map +1 -1
- package/dist/src/models/rental.entity.d.ts +29 -29
- package/dist/src/models/rental.entity.js +159 -159
- package/dist/src/models/rental.entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.mjs +37 -0
- package/migrations/booking-table-migration.js +1 -1
- package/migrations/joint-hirer-table-migration.js +1 -1
- package/migrations/rental-aggrement-table-migration.js +1 -1
- package/migrations/rental-price-table-migration.js +1 -1
- package/migrations/rental-table-migrations.js +1 -1
- package/package.json +33 -30
- package/src/components/booking/booking.ts +94 -1
- package/src/components/joint-hirer/joint-hirer.ts +1 -1
- package/src/components/rental/rental.ts +7 -10
- package/.eslintignore +0 -1
|
@@ -1,409 +1,409 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Rental = void 0;
|
|
13
|
-
const rental_status_enum_1 = require("../../enum/rental-status.enum");
|
|
14
|
-
const rental_repository_1 = require("./rental.repository");
|
|
15
|
-
const general_1 = require("@tomei/general");
|
|
16
|
-
const config_1 = require("@tomei/config");
|
|
17
|
-
const sequelize_1 = require("sequelize");
|
|
18
|
-
const activity_history_1 = require("@tomei/activity-history");
|
|
19
|
-
const joint_hirer_entity_1 = require("../../models/joint-hirer.entity");
|
|
20
|
-
const agreement_repository_1 = require("../agreement/agreement.repository");
|
|
21
|
-
const rentalDb = require("../../database");
|
|
22
|
-
const rental_entity_1 = require("../../models/rental.entity");
|
|
23
|
-
const joint_hirer_repository_1 = require("../joint-hirer/joint-hirer.repository");
|
|
24
|
-
const models_1 = require("../../models");
|
|
25
|
-
const agreement_1 = require("../agreement/agreement");
|
|
26
|
-
const aggrement_status_enum_1 = require("../../enum/aggrement-status.enum");
|
|
27
|
-
class Rental extends general_1.ObjectBase {
|
|
28
|
-
get RentalId() {
|
|
29
|
-
return this.ObjectId;
|
|
30
|
-
}
|
|
31
|
-
set RentalId(value) {
|
|
32
|
-
this.ObjectId = value;
|
|
33
|
-
}
|
|
34
|
-
get Status() {
|
|
35
|
-
return this._Status;
|
|
36
|
-
}
|
|
37
|
-
get EscheatmentYN() {
|
|
38
|
-
return this._EscheatmentYN;
|
|
39
|
-
}
|
|
40
|
-
get CreatedById() {
|
|
41
|
-
return this._CreatedById;
|
|
42
|
-
}
|
|
43
|
-
get CreatedAt() {
|
|
44
|
-
return this._CreatedAt;
|
|
45
|
-
}
|
|
46
|
-
get UpdatedById() {
|
|
47
|
-
return this._UpdatedById;
|
|
48
|
-
}
|
|
49
|
-
get UpdatedAt() {
|
|
50
|
-
return this._UpdatedAt;
|
|
51
|
-
}
|
|
52
|
-
setTerminated() {
|
|
53
|
-
this._Status = rental_status_enum_1.RentalStatusEnum.TERMINATED;
|
|
54
|
-
}
|
|
55
|
-
constructor(rentalAttr) {
|
|
56
|
-
super();
|
|
57
|
-
this.ObjectType = 'Rental';
|
|
58
|
-
this.JointHirers = [];
|
|
59
|
-
this._EscheatmentYN = 'N';
|
|
60
|
-
if (rentalAttr) {
|
|
61
|
-
this.RentalId = rentalAttr.RentalId;
|
|
62
|
-
this.CustomerId = rentalAttr.CustomerId;
|
|
63
|
-
this.CustomerType = rentalAttr.CustomerType;
|
|
64
|
-
this.ItemId = rentalAttr.ItemId;
|
|
65
|
-
this.ItemType = rentalAttr.ItemType;
|
|
66
|
-
this.PriceId = rentalAttr.PriceId;
|
|
67
|
-
this.StartDateTime = rentalAttr.StartDateTime;
|
|
68
|
-
this.EndDateTime = rentalAttr.EndDateTime;
|
|
69
|
-
this.CancelRemarks = rentalAttr.CancelRemarks;
|
|
70
|
-
this.TerminateRemarks = rentalAttr.TerminateRemarks;
|
|
71
|
-
this.AgreementNo = rentalAttr.AgreementNo;
|
|
72
|
-
this.AccountType = rentalAttr.AccountType;
|
|
73
|
-
this._Status = rentalAttr.Status;
|
|
74
|
-
this._EscheatmentYN = rentalAttr.EscheatmentYN;
|
|
75
|
-
this._CreatedById = rentalAttr.CreatedById;
|
|
76
|
-
this._CreatedAt = rentalAttr.CreatedAt;
|
|
77
|
-
this._UpdatedById = rentalAttr.UpdatedById;
|
|
78
|
-
this._UpdatedAt = rentalAttr.UpdatedAt;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
static init(dbTransaction, rentalId) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
try {
|
|
84
|
-
if (rentalId) {
|
|
85
|
-
const rental = yield Rental._Repo.findByPk(rentalId, dbTransaction);
|
|
86
|
-
if (rental) {
|
|
87
|
-
return new Rental(rental);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg00', 'Rental Not Found');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return new Rental();
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg00', 'Failed To Initialize Price');
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
create(rentalPrice, loginUser, jointHirers, dbTransaction) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
try {
|
|
103
|
-
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
104
|
-
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - Create');
|
|
105
|
-
if (!isPrivileged) {
|
|
106
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - Create' privilege.");
|
|
107
|
-
}
|
|
108
|
-
const isItemAvailable = yield Rental.isItemAvailable(this.ItemId, this.ItemType, this.StartDateTime, this.EndDateTime, dbTransaction);
|
|
109
|
-
if (!isItemAvailable) {
|
|
110
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg02', 'Rental Item is not available at current date.');
|
|
111
|
-
}
|
|
112
|
-
yield Rental._AgreementRepo.create({
|
|
113
|
-
AgreementNo: this.AgreementNo,
|
|
114
|
-
Status: 'Not Generated',
|
|
115
|
-
}, {
|
|
116
|
-
transaction: dbTransaction,
|
|
117
|
-
});
|
|
118
|
-
if (!rentalPrice.PriceId) {
|
|
119
|
-
const rentalPriceData = yield rentalPrice.create(loginUser, dbTransaction);
|
|
120
|
-
this.PriceId = rentalPriceData.PriceId;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
this.PriceId = rentalPrice.PriceId;
|
|
124
|
-
}
|
|
125
|
-
this.RentalId = this.createId();
|
|
126
|
-
this._Status = rental_status_enum_1.RentalStatusEnum.PENDING_SIGNING;
|
|
127
|
-
this._CreatedById = loginUser.ObjectId;
|
|
128
|
-
this._UpdatedById = loginUser.ObjectId;
|
|
129
|
-
this._CreatedAt = new Date();
|
|
130
|
-
this._UpdatedAt = new Date();
|
|
131
|
-
const data = {
|
|
132
|
-
RentalId: this.RentalId,
|
|
133
|
-
CustomerId: this.CustomerId,
|
|
134
|
-
CustomerType: this.CustomerType,
|
|
135
|
-
ItemId: this.ItemId,
|
|
136
|
-
ItemType: this.ItemType,
|
|
137
|
-
PriceId: this.PriceId,
|
|
138
|
-
StartDateTime: this.StartDateTime,
|
|
139
|
-
EndDateTime: this.EndDateTime,
|
|
140
|
-
CancelRemarks: this.CancelRemarks,
|
|
141
|
-
TerminateRemarks: this.TerminateRemarks,
|
|
142
|
-
AgreementNo: this.AgreementNo,
|
|
143
|
-
AccountType: this.AccountType,
|
|
144
|
-
Status: this.Status,
|
|
145
|
-
EscheatmentYN: this.EscheatmentYN,
|
|
146
|
-
CreatedById: this.CreatedById,
|
|
147
|
-
CreatedAt: this.CreatedAt,
|
|
148
|
-
UpdatedById: this.UpdatedById,
|
|
149
|
-
UpdatedAt: this.UpdatedAt,
|
|
150
|
-
};
|
|
151
|
-
yield Rental._Repo.create(data, {
|
|
152
|
-
transaction: dbTransaction,
|
|
153
|
-
});
|
|
154
|
-
if (jointHirers) {
|
|
155
|
-
for (let i = 0; i < jointHirers.length; i++) {
|
|
156
|
-
jointHirers[i].RentalId = this.RentalId;
|
|
157
|
-
yield jointHirers[i].create(loginUser, dbTransaction);
|
|
158
|
-
this.JointHirers.push(jointHirers[i]);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const activity = new activity_history_1.Activity();
|
|
162
|
-
activity.ActivityId = activity.createId();
|
|
163
|
-
activity.Action = activity_history_1.ActionEnum.
|
|
164
|
-
activity.Description = 'Add Rental';
|
|
165
|
-
activity.EntityType = 'Rental';
|
|
166
|
-
activity.EntityId = this.RentalId;
|
|
167
|
-
activity.EntityValueBefore = JSON.stringify({});
|
|
168
|
-
activity.EntityValueAfter = JSON.stringify(data);
|
|
169
|
-
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
170
|
-
return this;
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
throw error;
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
static isItemAvailable(itemId, itemType, startDateTime, endDateTime, dbTransaction) {
|
|
178
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
try {
|
|
180
|
-
const item = yield Rental._Repo.findOne({
|
|
181
|
-
where: {
|
|
182
|
-
ItemId: itemId,
|
|
183
|
-
ItemType: itemType,
|
|
184
|
-
StartDateTime: {
|
|
185
|
-
[sequelize_1.Op.lte]: endDateTime,
|
|
186
|
-
},
|
|
187
|
-
EndDateTime: {
|
|
188
|
-
[sequelize_1.Op.gte]: startDateTime,
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
transaction: dbTransaction,
|
|
192
|
-
});
|
|
193
|
-
if (item) {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
throw error;
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
static findAll(loginUser, dbTransaction, page, row, search) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
try {
|
|
209
|
-
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
210
|
-
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - View');
|
|
211
|
-
if (!isPrivileged) {
|
|
212
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
213
|
-
}
|
|
214
|
-
const queryObj = {};
|
|
215
|
-
let options = {
|
|
216
|
-
transaction: dbTransaction,
|
|
217
|
-
order: [['CreatedAt', 'DESC']],
|
|
218
|
-
};
|
|
219
|
-
if (page && row) {
|
|
220
|
-
options = Object.assign(Object.assign({}, options), { limit: row, offset: row * (page - 1) });
|
|
221
|
-
}
|
|
222
|
-
if (search) {
|
|
223
|
-
Object.entries(search).forEach(([key, value]) => {
|
|
224
|
-
if (key === 'StartDateTime') {
|
|
225
|
-
queryObj[key] = {
|
|
226
|
-
[sequelize_1.Op.gte]: value,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
else if (key === 'EndDateTime') {
|
|
230
|
-
queryObj[key] = {
|
|
231
|
-
[sequelize_1.Op.lte]: value,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
else if (key === 'CustomerId') {
|
|
235
|
-
queryObj[key] = {
|
|
236
|
-
[sequelize_1.Op.substring]: value,
|
|
237
|
-
};
|
|
238
|
-
options.include = [
|
|
239
|
-
{
|
|
240
|
-
model: joint_hirer_entity_1.JointHirerModel,
|
|
241
|
-
required: false,
|
|
242
|
-
where: {
|
|
243
|
-
CustomerId: {
|
|
244
|
-
[sequelize_1.Op.substring]: value,
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
];
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
queryObj[key] = {
|
|
252
|
-
[sequelize_1.Op.substring]: value,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
if (((_a = options === null || options === void 0 ? void 0 : options.include) === null || _a === void 0 ? void 0 : _a.length) > 1) {
|
|
257
|
-
options.include.push({
|
|
258
|
-
model: models_1.AgreementModel,
|
|
259
|
-
required: false,
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
options.include = [
|
|
264
|
-
{
|
|
265
|
-
model: models_1.AgreementModel,
|
|
266
|
-
required: false,
|
|
267
|
-
},
|
|
268
|
-
];
|
|
269
|
-
}
|
|
270
|
-
options = Object.assign(Object.assign({}, options), { where: queryObj });
|
|
271
|
-
}
|
|
272
|
-
return yield Rental._Repo.findAndCountAll(options);
|
|
273
|
-
}
|
|
274
|
-
catch (err) {
|
|
275
|
-
throw err;
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
static checkActiveByItemId(loginUser, itemId, itemType, dbTransaction) {
|
|
280
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
-
try {
|
|
282
|
-
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
283
|
-
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - View');
|
|
284
|
-
if (!isPrivileged) {
|
|
285
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
286
|
-
}
|
|
287
|
-
const queryObj = {
|
|
288
|
-
ItemId: itemId,
|
|
289
|
-
ItemType: itemType,
|
|
290
|
-
Status: rental_status_enum_1.RentalStatusEnum.ACTIVE,
|
|
291
|
-
};
|
|
292
|
-
const options = {
|
|
293
|
-
transaction: dbTransaction,
|
|
294
|
-
where: queryObj,
|
|
295
|
-
};
|
|
296
|
-
const rental = yield Rental._Repo.findOne(options);
|
|
297
|
-
if (rental) {
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
catch (err) {
|
|
305
|
-
throw err;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
setStartDateTime(startDateTime) {
|
|
310
|
-
const startDateTimeObject = new Date(startDateTime);
|
|
311
|
-
startDateTimeObject.setHours(0, 0, 0, 0);
|
|
312
|
-
if (startDateTimeObject < new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
313
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg02', 'StartDateTime cannot be a past datetime.');
|
|
314
|
-
}
|
|
315
|
-
if (this.EndDateTime && startDateTimeObject > this.EndDateTime) {
|
|
316
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg03', 'StartDateTime cannot be more than EndDateTime.');
|
|
317
|
-
}
|
|
318
|
-
if (startDateTimeObject > new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
319
|
-
this._Status = rental_status_enum_1.RentalStatusEnum.RESERVED;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
this._Status = rental_status_enum_1.RentalStatusEnum.ACTIVE;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
periodEndProcess(loginUser, dbTransaction, stockInventory) {
|
|
326
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
-
try {
|
|
328
|
-
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
329
|
-
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental – PeriodEndProcess');
|
|
330
|
-
if (!isPrivileged) {
|
|
331
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg04', "You do not have 'Rental - PeriodEndProcess' privilege.");
|
|
332
|
-
}
|
|
333
|
-
if (this.AgreementNo === undefined || this.AgreementNo === null) {
|
|
334
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg05', 'Rental must be existing rental.');
|
|
335
|
-
}
|
|
336
|
-
if (this.EndDateTime === new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
337
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg06', 'Rental period is not ending today.');
|
|
338
|
-
}
|
|
339
|
-
yield stockInventory.setAvailable(loginUser, dbTransaction);
|
|
340
|
-
const entityValueBefore = {
|
|
341
|
-
RentalId: this.RentalId,
|
|
342
|
-
CustomerId: this.CustomerId,
|
|
343
|
-
CustomerType: this.CustomerType,
|
|
344
|
-
ItemId: this.ItemId,
|
|
345
|
-
ItemType: this.ItemType,
|
|
346
|
-
PriceId: this.PriceId,
|
|
347
|
-
StartDateTime: this.StartDateTime,
|
|
348
|
-
EndDateTime: this.EndDateTime,
|
|
349
|
-
CancelRemarks: this.CancelRemarks,
|
|
350
|
-
TerminateRemarks: this.TerminateRemarks,
|
|
351
|
-
AgreementNo: this.AgreementNo,
|
|
352
|
-
AccountType: this.AccountType,
|
|
353
|
-
Status: this.Status,
|
|
354
|
-
EscheatmentYN: this.EscheatmentYN,
|
|
355
|
-
CreatedById: this.CreatedById,
|
|
356
|
-
CreatedAt: this.CreatedAt,
|
|
357
|
-
UpdatedById: this.UpdatedById,
|
|
358
|
-
UpdatedAt: this.UpdatedAt,
|
|
359
|
-
};
|
|
360
|
-
this.setTerminated();
|
|
361
|
-
this._UpdatedById = loginUser.ObjectId;
|
|
362
|
-
this._UpdatedAt = new Date();
|
|
363
|
-
const entityValueAfter = {
|
|
364
|
-
RentalId: this.RentalId,
|
|
365
|
-
CustomerId: this.CustomerId,
|
|
366
|
-
CustomerType: this.CustomerType,
|
|
367
|
-
ItemId: this.ItemId,
|
|
368
|
-
ItemType: this.ItemType,
|
|
369
|
-
PriceId: this.PriceId,
|
|
370
|
-
StartDateTime: this.StartDateTime,
|
|
371
|
-
EndDateTime: this.EndDateTime,
|
|
372
|
-
CancelRemarks: this.CancelRemarks,
|
|
373
|
-
TerminateRemarks: this.TerminateRemarks,
|
|
374
|
-
AgreementNo: this.AgreementNo,
|
|
375
|
-
AccountType: this.AccountType,
|
|
376
|
-
Status: this.Status,
|
|
377
|
-
EscheatmentYN: this.EscheatmentYN,
|
|
378
|
-
CreatedById: this.CreatedById,
|
|
379
|
-
CreatedAt: this.CreatedAt,
|
|
380
|
-
UpdatedById: this.UpdatedById,
|
|
381
|
-
UpdatedAt: this.UpdatedAt,
|
|
382
|
-
};
|
|
383
|
-
const activity = new activity_history_1.Activity();
|
|
384
|
-
activity.ActivityId = activity.createId();
|
|
385
|
-
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
386
|
-
activity.Description = 'Set Rental as Terminated';
|
|
387
|
-
activity.EntityType = 'Rental';
|
|
388
|
-
activity.EntityId = this.RentalId;
|
|
389
|
-
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
390
|
-
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
391
|
-
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
392
|
-
return this;
|
|
393
|
-
}
|
|
394
|
-
catch (err) {
|
|
395
|
-
throw err;
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
getCustomerActiveRentals(loginUser, dbTransaction, CustomerId) {
|
|
400
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
401
|
-
try {
|
|
402
|
-
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
403
|
-
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_VIEW');
|
|
404
|
-
if (!isPrivileged) {
|
|
405
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
406
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Rental = void 0;
|
|
13
|
+
const rental_status_enum_1 = require("../../enum/rental-status.enum");
|
|
14
|
+
const rental_repository_1 = require("./rental.repository");
|
|
15
|
+
const general_1 = require("@tomei/general");
|
|
16
|
+
const config_1 = require("@tomei/config");
|
|
17
|
+
const sequelize_1 = require("sequelize");
|
|
18
|
+
const activity_history_1 = require("@tomei/activity-history");
|
|
19
|
+
const joint_hirer_entity_1 = require("../../models/joint-hirer.entity");
|
|
20
|
+
const agreement_repository_1 = require("../agreement/agreement.repository");
|
|
21
|
+
const rentalDb = require("../../database");
|
|
22
|
+
const rental_entity_1 = require("../../models/rental.entity");
|
|
23
|
+
const joint_hirer_repository_1 = require("../joint-hirer/joint-hirer.repository");
|
|
24
|
+
const models_1 = require("../../models");
|
|
25
|
+
const agreement_1 = require("../agreement/agreement");
|
|
26
|
+
const aggrement_status_enum_1 = require("../../enum/aggrement-status.enum");
|
|
27
|
+
class Rental extends general_1.ObjectBase {
|
|
28
|
+
get RentalId() {
|
|
29
|
+
return this.ObjectId;
|
|
30
|
+
}
|
|
31
|
+
set RentalId(value) {
|
|
32
|
+
this.ObjectId = value;
|
|
33
|
+
}
|
|
34
|
+
get Status() {
|
|
35
|
+
return this._Status;
|
|
36
|
+
}
|
|
37
|
+
get EscheatmentYN() {
|
|
38
|
+
return this._EscheatmentYN;
|
|
39
|
+
}
|
|
40
|
+
get CreatedById() {
|
|
41
|
+
return this._CreatedById;
|
|
42
|
+
}
|
|
43
|
+
get CreatedAt() {
|
|
44
|
+
return this._CreatedAt;
|
|
45
|
+
}
|
|
46
|
+
get UpdatedById() {
|
|
47
|
+
return this._UpdatedById;
|
|
48
|
+
}
|
|
49
|
+
get UpdatedAt() {
|
|
50
|
+
return this._UpdatedAt;
|
|
51
|
+
}
|
|
52
|
+
setTerminated() {
|
|
53
|
+
this._Status = rental_status_enum_1.RentalStatusEnum.TERMINATED;
|
|
54
|
+
}
|
|
55
|
+
constructor(rentalAttr) {
|
|
56
|
+
super();
|
|
57
|
+
this.ObjectType = 'Rental';
|
|
58
|
+
this.JointHirers = [];
|
|
59
|
+
this._EscheatmentYN = 'N';
|
|
60
|
+
if (rentalAttr) {
|
|
61
|
+
this.RentalId = rentalAttr.RentalId;
|
|
62
|
+
this.CustomerId = rentalAttr.CustomerId;
|
|
63
|
+
this.CustomerType = rentalAttr.CustomerType;
|
|
64
|
+
this.ItemId = rentalAttr.ItemId;
|
|
65
|
+
this.ItemType = rentalAttr.ItemType;
|
|
66
|
+
this.PriceId = rentalAttr.PriceId;
|
|
67
|
+
this.StartDateTime = rentalAttr.StartDateTime;
|
|
68
|
+
this.EndDateTime = rentalAttr.EndDateTime;
|
|
69
|
+
this.CancelRemarks = rentalAttr.CancelRemarks;
|
|
70
|
+
this.TerminateRemarks = rentalAttr.TerminateRemarks;
|
|
71
|
+
this.AgreementNo = rentalAttr.AgreementNo;
|
|
72
|
+
this.AccountType = rentalAttr.AccountType;
|
|
73
|
+
this._Status = rentalAttr.Status;
|
|
74
|
+
this._EscheatmentYN = rentalAttr.EscheatmentYN;
|
|
75
|
+
this._CreatedById = rentalAttr.CreatedById;
|
|
76
|
+
this._CreatedAt = rentalAttr.CreatedAt;
|
|
77
|
+
this._UpdatedById = rentalAttr.UpdatedById;
|
|
78
|
+
this._UpdatedAt = rentalAttr.UpdatedAt;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
static init(dbTransaction, rentalId) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
try {
|
|
84
|
+
if (rentalId) {
|
|
85
|
+
const rental = yield Rental._Repo.findByPk(rentalId, dbTransaction);
|
|
86
|
+
if (rental) {
|
|
87
|
+
return new Rental(rental);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg00', 'Rental Not Found');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return new Rental();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg00', 'Failed To Initialize Price');
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
create(rentalPrice, loginUser, jointHirers, dbTransaction) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
try {
|
|
103
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
104
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - Create');
|
|
105
|
+
if (!isPrivileged) {
|
|
106
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - Create' privilege.");
|
|
107
|
+
}
|
|
108
|
+
const isItemAvailable = yield Rental.isItemAvailable(this.ItemId, this.ItemType, this.StartDateTime, this.EndDateTime, dbTransaction);
|
|
109
|
+
if (!isItemAvailable) {
|
|
110
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg02', 'Rental Item is not available at current date.');
|
|
111
|
+
}
|
|
112
|
+
yield Rental._AgreementRepo.create({
|
|
113
|
+
AgreementNo: this.AgreementNo,
|
|
114
|
+
Status: 'Not Generated',
|
|
115
|
+
}, {
|
|
116
|
+
transaction: dbTransaction,
|
|
117
|
+
});
|
|
118
|
+
if (!rentalPrice.PriceId) {
|
|
119
|
+
const rentalPriceData = yield rentalPrice.create(loginUser, dbTransaction);
|
|
120
|
+
this.PriceId = rentalPriceData.PriceId;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.PriceId = rentalPrice.PriceId;
|
|
124
|
+
}
|
|
125
|
+
this.RentalId = this.createId();
|
|
126
|
+
this._Status = rental_status_enum_1.RentalStatusEnum.PENDING_SIGNING;
|
|
127
|
+
this._CreatedById = loginUser.ObjectId;
|
|
128
|
+
this._UpdatedById = loginUser.ObjectId;
|
|
129
|
+
this._CreatedAt = new Date();
|
|
130
|
+
this._UpdatedAt = new Date();
|
|
131
|
+
const data = {
|
|
132
|
+
RentalId: this.RentalId,
|
|
133
|
+
CustomerId: this.CustomerId,
|
|
134
|
+
CustomerType: this.CustomerType,
|
|
135
|
+
ItemId: this.ItemId,
|
|
136
|
+
ItemType: this.ItemType,
|
|
137
|
+
PriceId: this.PriceId,
|
|
138
|
+
StartDateTime: this.StartDateTime,
|
|
139
|
+
EndDateTime: this.EndDateTime,
|
|
140
|
+
CancelRemarks: this.CancelRemarks,
|
|
141
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
142
|
+
AgreementNo: this.AgreementNo,
|
|
143
|
+
AccountType: this.AccountType,
|
|
144
|
+
Status: this.Status,
|
|
145
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
146
|
+
CreatedById: this.CreatedById,
|
|
147
|
+
CreatedAt: this.CreatedAt,
|
|
148
|
+
UpdatedById: this.UpdatedById,
|
|
149
|
+
UpdatedAt: this.UpdatedAt,
|
|
150
|
+
};
|
|
151
|
+
yield Rental._Repo.create(data, {
|
|
152
|
+
transaction: dbTransaction,
|
|
153
|
+
});
|
|
154
|
+
if (jointHirers) {
|
|
155
|
+
for (let i = 0; i < jointHirers.length; i++) {
|
|
156
|
+
jointHirers[i].RentalId = this.RentalId;
|
|
157
|
+
yield jointHirers[i].create(loginUser, dbTransaction);
|
|
158
|
+
this.JointHirers.push(jointHirers[i]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const activity = new activity_history_1.Activity();
|
|
162
|
+
activity.ActivityId = activity.createId();
|
|
163
|
+
activity.Action = activity_history_1.ActionEnum.CREATE;
|
|
164
|
+
activity.Description = 'Add Rental';
|
|
165
|
+
activity.EntityType = 'Rental';
|
|
166
|
+
activity.EntityId = this.RentalId;
|
|
167
|
+
activity.EntityValueBefore = JSON.stringify({});
|
|
168
|
+
activity.EntityValueAfter = JSON.stringify(data);
|
|
169
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
static isItemAvailable(itemId, itemType, startDateTime, endDateTime, dbTransaction) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
try {
|
|
180
|
+
const item = yield Rental._Repo.findOne({
|
|
181
|
+
where: {
|
|
182
|
+
ItemId: itemId,
|
|
183
|
+
ItemType: itemType,
|
|
184
|
+
StartDateTime: {
|
|
185
|
+
[sequelize_1.Op.lte]: endDateTime,
|
|
186
|
+
},
|
|
187
|
+
EndDateTime: {
|
|
188
|
+
[sequelize_1.Op.gte]: startDateTime,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
transaction: dbTransaction,
|
|
192
|
+
});
|
|
193
|
+
if (item) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
static findAll(loginUser, dbTransaction, page, row, search) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
var _a;
|
|
208
|
+
try {
|
|
209
|
+
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
210
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - View');
|
|
211
|
+
if (!isPrivileged) {
|
|
212
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
213
|
+
}
|
|
214
|
+
const queryObj = {};
|
|
215
|
+
let options = {
|
|
216
|
+
transaction: dbTransaction,
|
|
217
|
+
order: [['CreatedAt', 'DESC']],
|
|
218
|
+
};
|
|
219
|
+
if (page && row) {
|
|
220
|
+
options = Object.assign(Object.assign({}, options), { limit: row, offset: row * (page - 1) });
|
|
221
|
+
}
|
|
222
|
+
if (search) {
|
|
223
|
+
Object.entries(search).forEach(([key, value]) => {
|
|
224
|
+
if (key === 'StartDateTime') {
|
|
225
|
+
queryObj[key] = {
|
|
226
|
+
[sequelize_1.Op.gte]: value,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
else if (key === 'EndDateTime') {
|
|
230
|
+
queryObj[key] = {
|
|
231
|
+
[sequelize_1.Op.lte]: value,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
else if (key === 'CustomerId') {
|
|
235
|
+
queryObj[key] = {
|
|
236
|
+
[sequelize_1.Op.substring]: value,
|
|
237
|
+
};
|
|
238
|
+
options.include = [
|
|
239
|
+
{
|
|
240
|
+
model: joint_hirer_entity_1.JointHirerModel,
|
|
241
|
+
required: false,
|
|
242
|
+
where: {
|
|
243
|
+
CustomerId: {
|
|
244
|
+
[sequelize_1.Op.substring]: value,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
queryObj[key] = {
|
|
252
|
+
[sequelize_1.Op.substring]: value,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
if (((_a = options === null || options === void 0 ? void 0 : options.include) === null || _a === void 0 ? void 0 : _a.length) > 1) {
|
|
257
|
+
options.include.push({
|
|
258
|
+
model: models_1.AgreementModel,
|
|
259
|
+
required: false,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
options.include = [
|
|
264
|
+
{
|
|
265
|
+
model: models_1.AgreementModel,
|
|
266
|
+
required: false,
|
|
267
|
+
},
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
options = Object.assign(Object.assign({}, options), { where: queryObj });
|
|
271
|
+
}
|
|
272
|
+
return yield Rental._Repo.findAndCountAll(options);
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
throw err;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
static checkActiveByItemId(loginUser, itemId, itemType, dbTransaction) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
try {
|
|
282
|
+
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
283
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental - View');
|
|
284
|
+
if (!isPrivileged) {
|
|
285
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
286
|
+
}
|
|
287
|
+
const queryObj = {
|
|
288
|
+
ItemId: itemId,
|
|
289
|
+
ItemType: itemType,
|
|
290
|
+
Status: rental_status_enum_1.RentalStatusEnum.ACTIVE,
|
|
291
|
+
};
|
|
292
|
+
const options = {
|
|
293
|
+
transaction: dbTransaction,
|
|
294
|
+
where: queryObj,
|
|
295
|
+
};
|
|
296
|
+
const rental = yield Rental._Repo.findOne(options);
|
|
297
|
+
if (rental) {
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
setStartDateTime(startDateTime) {
|
|
310
|
+
const startDateTimeObject = new Date(startDateTime);
|
|
311
|
+
startDateTimeObject.setHours(0, 0, 0, 0);
|
|
312
|
+
if (startDateTimeObject < new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
313
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg02', 'StartDateTime cannot be a past datetime.');
|
|
314
|
+
}
|
|
315
|
+
if (this.EndDateTime && startDateTimeObject > this.EndDateTime) {
|
|
316
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg03', 'StartDateTime cannot be more than EndDateTime.');
|
|
317
|
+
}
|
|
318
|
+
if (startDateTimeObject > new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
319
|
+
this._Status = rental_status_enum_1.RentalStatusEnum.RESERVED;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
this._Status = rental_status_enum_1.RentalStatusEnum.ACTIVE;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
periodEndProcess(loginUser, dbTransaction, stockInventory) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
+
try {
|
|
328
|
+
const systemCode = yield config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
329
|
+
const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Rental – PeriodEndProcess');
|
|
330
|
+
if (!isPrivileged) {
|
|
331
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg04', "You do not have 'Rental - PeriodEndProcess' privilege.");
|
|
332
|
+
}
|
|
333
|
+
if (this.AgreementNo === undefined || this.AgreementNo === null) {
|
|
334
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg05', 'Rental must be existing rental.');
|
|
335
|
+
}
|
|
336
|
+
if (this.EndDateTime === new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
337
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg06', 'Rental period is not ending today.');
|
|
338
|
+
}
|
|
339
|
+
yield stockInventory.setAvailable(loginUser, dbTransaction);
|
|
340
|
+
const entityValueBefore = {
|
|
341
|
+
RentalId: this.RentalId,
|
|
342
|
+
CustomerId: this.CustomerId,
|
|
343
|
+
CustomerType: this.CustomerType,
|
|
344
|
+
ItemId: this.ItemId,
|
|
345
|
+
ItemType: this.ItemType,
|
|
346
|
+
PriceId: this.PriceId,
|
|
347
|
+
StartDateTime: this.StartDateTime,
|
|
348
|
+
EndDateTime: this.EndDateTime,
|
|
349
|
+
CancelRemarks: this.CancelRemarks,
|
|
350
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
351
|
+
AgreementNo: this.AgreementNo,
|
|
352
|
+
AccountType: this.AccountType,
|
|
353
|
+
Status: this.Status,
|
|
354
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
355
|
+
CreatedById: this.CreatedById,
|
|
356
|
+
CreatedAt: this.CreatedAt,
|
|
357
|
+
UpdatedById: this.UpdatedById,
|
|
358
|
+
UpdatedAt: this.UpdatedAt,
|
|
359
|
+
};
|
|
360
|
+
this.setTerminated();
|
|
361
|
+
this._UpdatedById = loginUser.ObjectId;
|
|
362
|
+
this._UpdatedAt = new Date();
|
|
363
|
+
const entityValueAfter = {
|
|
364
|
+
RentalId: this.RentalId,
|
|
365
|
+
CustomerId: this.CustomerId,
|
|
366
|
+
CustomerType: this.CustomerType,
|
|
367
|
+
ItemId: this.ItemId,
|
|
368
|
+
ItemType: this.ItemType,
|
|
369
|
+
PriceId: this.PriceId,
|
|
370
|
+
StartDateTime: this.StartDateTime,
|
|
371
|
+
EndDateTime: this.EndDateTime,
|
|
372
|
+
CancelRemarks: this.CancelRemarks,
|
|
373
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
374
|
+
AgreementNo: this.AgreementNo,
|
|
375
|
+
AccountType: this.AccountType,
|
|
376
|
+
Status: this.Status,
|
|
377
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
378
|
+
CreatedById: this.CreatedById,
|
|
379
|
+
CreatedAt: this.CreatedAt,
|
|
380
|
+
UpdatedById: this.UpdatedById,
|
|
381
|
+
UpdatedAt: this.UpdatedAt,
|
|
382
|
+
};
|
|
383
|
+
const activity = new activity_history_1.Activity();
|
|
384
|
+
activity.ActivityId = activity.createId();
|
|
385
|
+
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
386
|
+
activity.Description = 'Set Rental as Terminated';
|
|
387
|
+
activity.EntityType = 'Rental';
|
|
388
|
+
activity.EntityId = this.RentalId;
|
|
389
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
390
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
391
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
394
|
+
catch (err) {
|
|
395
|
+
throw err;
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
getCustomerActiveRentals(loginUser, dbTransaction, CustomerId) {
|
|
400
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
401
|
+
try {
|
|
402
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
403
|
+
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_VIEW');
|
|
404
|
+
if (!isPrivileged) {
|
|
405
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
406
|
+
}
|
|
407
407
|
const query = `
|
|
408
408
|
SELECT
|
|
409
409
|
r.*
|
|
@@ -419,201 +419,201 @@ class Rental extends general_1.ObjectBase {
|
|
|
419
419
|
)
|
|
420
420
|
GROUP BY
|
|
421
421
|
r.RentalId
|
|
422
|
-
`;
|
|
423
|
-
const db = rentalDb.getConnection();
|
|
424
|
-
const result = yield db.query(query, {
|
|
425
|
-
type: sequelize_1.QueryTypes.SELECT,
|
|
426
|
-
transaction: dbTransaction,
|
|
427
|
-
model: rental_entity_1.RentalModel,
|
|
428
|
-
mapToModel: true,
|
|
429
|
-
});
|
|
430
|
-
const records = result.map((record) => {
|
|
431
|
-
return {
|
|
432
|
-
RentalId: record.RentalId,
|
|
433
|
-
CustomerId: record.CustomerId,
|
|
434
|
-
CustomerType: record.CustomerType,
|
|
435
|
-
ItemId: record.ItemId,
|
|
436
|
-
ItemType: record.ItemType,
|
|
437
|
-
PriceId: record.PriceId,
|
|
438
|
-
StartDateTime: record.StartDateTime,
|
|
439
|
-
EndDateTime: record.EndDateTime,
|
|
440
|
-
CancelRemarks: record.CancelRemarks,
|
|
441
|
-
TerminateRemarks: record.TerminateRemarks,
|
|
442
|
-
AgreementNo: record.AgreementNo,
|
|
443
|
-
AccountType: record.AccountType,
|
|
444
|
-
Status: record.Status,
|
|
445
|
-
EscheatmentYN: record.EscheatmentYN,
|
|
446
|
-
CreatedById: record.CreatedById,
|
|
447
|
-
CreatedAt: record.CreatedAt,
|
|
448
|
-
UpdatedById: record.UpdatedById,
|
|
449
|
-
UpdatedAt: record.UpdatedAt,
|
|
450
|
-
};
|
|
451
|
-
});
|
|
452
|
-
return records;
|
|
453
|
-
}
|
|
454
|
-
catch (error) {
|
|
455
|
-
throw error;
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
getCustomerIds(loginUser, dbTransaction) {
|
|
460
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
461
|
-
try {
|
|
462
|
-
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
463
|
-
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_VIEW');
|
|
464
|
-
if (!isPrivileged) {
|
|
465
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
466
|
-
}
|
|
467
|
-
if (!this.RentalId) {
|
|
468
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', 'RentalId is missing');
|
|
469
|
-
}
|
|
470
|
-
const options = {
|
|
471
|
-
where: {
|
|
472
|
-
RentalId: this.RentalId,
|
|
473
|
-
},
|
|
474
|
-
transaction: dbTransaction,
|
|
475
|
-
};
|
|
476
|
-
const joinHirers = yield Rental._JointHirerRepo.findAll(options);
|
|
477
|
-
const customerIds = [this.CustomerId];
|
|
478
|
-
for (let i = 0; i < joinHirers.length; i++) {
|
|
479
|
-
const jointHirer = joinHirers[i];
|
|
480
|
-
customerIds.push(jointHirer.CustomerId);
|
|
481
|
-
}
|
|
482
|
-
return customerIds;
|
|
483
|
-
}
|
|
484
|
-
catch (error) {
|
|
485
|
-
throw error;
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
signAgreement(loginUser, dbTransaction) {
|
|
490
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
-
try {
|
|
492
|
-
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
493
|
-
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_SIGN');
|
|
494
|
-
if (!isPrivileged) {
|
|
495
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'RENTAL_SIGN' privilege.");
|
|
496
|
-
}
|
|
497
|
-
const agreement = yield agreement_1.Agreement.init(this.AgreementNo, dbTransaction);
|
|
498
|
-
if (this.Status !== rental_status_enum_1.RentalStatusEnum.PENDING_SIGNING &&
|
|
499
|
-
agreement.Status !== aggrement_status_enum_1.AggrementStatusEnum.GENERATED) {
|
|
500
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', 'Rental is not ready to be signed yet.');
|
|
501
|
-
}
|
|
502
|
-
const entityValueAgreementBefore = {
|
|
503
|
-
AgreementNo: agreement.AgreementNo,
|
|
504
|
-
Status: agreement.Status,
|
|
505
|
-
DateSigned: agreement.DateSigned,
|
|
506
|
-
};
|
|
507
|
-
const payload = {
|
|
508
|
-
DateSigned: new Date(),
|
|
509
|
-
Status: aggrement_status_enum_1.AggrementStatusEnum.SIGNED,
|
|
510
|
-
};
|
|
511
|
-
yield Rental._AgreementRepo.update(payload, {
|
|
512
|
-
where: {
|
|
513
|
-
AgreementNo: this.AgreementNo,
|
|
514
|
-
},
|
|
515
|
-
transaction: dbTransaction,
|
|
516
|
-
});
|
|
517
|
-
const entityValueAgreementAfter = Object.assign({ entityValueAgreementBefore }, payload);
|
|
518
|
-
const activity = new activity_history_1.Activity();
|
|
519
|
-
activity.ActivityId = activity.createId();
|
|
520
|
-
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
521
|
-
activity.Description = 'Update agreement';
|
|
522
|
-
activity.EntityType = 'RentalAgreement';
|
|
523
|
-
activity.EntityId = this.AgreementNo;
|
|
524
|
-
activity.EntityValueBefore = JSON.stringify(entityValueAgreementBefore);
|
|
525
|
-
activity.EntityValueAfter = JSON.stringify(entityValueAgreementAfter);
|
|
526
|
-
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
527
|
-
const entityValueRentalBefore = {
|
|
528
|
-
RentalId: this.RentalId,
|
|
529
|
-
CustomerId: this.CustomerId,
|
|
530
|
-
CustomerType: this.CustomerType,
|
|
531
|
-
ItemId: this.ItemId,
|
|
532
|
-
ItemType: this.ItemType,
|
|
533
|
-
PriceId: this.PriceId,
|
|
534
|
-
StartDateTime: this.StartDateTime,
|
|
535
|
-
EndDateTime: this.EndDateTime,
|
|
536
|
-
CancelRemarks: this.CancelRemarks,
|
|
537
|
-
TerminateRemarks: this.TerminateRemarks,
|
|
538
|
-
AgreementNo: this.AgreementNo,
|
|
539
|
-
AccountType: this.AccountType,
|
|
540
|
-
Status: this.Status,
|
|
541
|
-
EscheatmentYN: this.EscheatmentYN,
|
|
542
|
-
CreatedById: this.CreatedById,
|
|
543
|
-
CreatedAt: this.CreatedAt,
|
|
544
|
-
UpdatedById: this.UpdatedById,
|
|
545
|
-
UpdatedAt: this.UpdatedAt,
|
|
546
|
-
};
|
|
547
|
-
const payloadRental = {
|
|
548
|
-
Status: rental_status_enum_1.RentalStatusEnum.PENDING_KEY_COLLECTION,
|
|
549
|
-
UpdatedById: loginUser.ObjectId,
|
|
550
|
-
UpdatedAt: new Date(),
|
|
551
|
-
};
|
|
552
|
-
yield Rental._Repo.update(payloadRental, {
|
|
553
|
-
where: {
|
|
554
|
-
RentalId: this.RentalId,
|
|
555
|
-
},
|
|
556
|
-
transaction: dbTransaction,
|
|
557
|
-
});
|
|
558
|
-
const entityValueRentalAfter = Object.assign({ entityValueRentalBefore }, payloadRental);
|
|
559
|
-
const rentalActivity = new activity_history_1.Activity();
|
|
560
|
-
rentalActivity.ActivityId = activity.createId();
|
|
561
|
-
rentalActivity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
562
|
-
rentalActivity.Description = 'Sign rental agreement';
|
|
563
|
-
rentalActivity.EntityType = 'Rental';
|
|
564
|
-
rentalActivity.EntityId = this.RentalId;
|
|
565
|
-
rentalActivity.EntityValueBefore = JSON.stringify(entityValueRentalBefore);
|
|
566
|
-
rentalActivity.EntityValueAfter = JSON.stringify(entityValueRentalAfter);
|
|
567
|
-
yield rentalActivity.create(loginUser.ObjectId, dbTransaction);
|
|
568
|
-
}
|
|
569
|
-
catch (error) {
|
|
570
|
-
throw error;
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
generateAgreement(loginUser, dbTransaction, MediaId) {
|
|
575
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
576
|
-
try {
|
|
577
|
-
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
578
|
-
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_AGREEMENT_CREATE');
|
|
579
|
-
if (!isPrivileged) {
|
|
580
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'RENTAL_AGREEMENT_CREATE' privilege.");
|
|
581
|
-
}
|
|
582
|
-
const agreement = yield agreement_1.Agreement.init(this.AgreementNo, dbTransaction);
|
|
583
|
-
if (!MediaId) {
|
|
584
|
-
throw new general_1.ClassError('Rental', 'RentalErrMsg0X', 'MediaId is required.');
|
|
585
|
-
}
|
|
586
|
-
const EntityValueBefore = agreement;
|
|
587
|
-
agreement.Status = aggrement_status_enum_1.AggrementStatusEnum.GENERATED;
|
|
588
|
-
agreement.MediaId = MediaId;
|
|
589
|
-
yield Rental._AgreementRepo.update({
|
|
590
|
-
Status: agreement.Status,
|
|
591
|
-
MediaId: agreement.MediaId,
|
|
592
|
-
}, {
|
|
593
|
-
where: {
|
|
594
|
-
AgreementNo: this.AgreementNo,
|
|
595
|
-
},
|
|
596
|
-
transaction: dbTransaction,
|
|
597
|
-
});
|
|
598
|
-
const EntityValueAfter = agreement;
|
|
599
|
-
const activity = new activity_history_1.Activity();
|
|
600
|
-
activity.ActivityId = activity.createId();
|
|
601
|
-
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
602
|
-
activity.Description = 'Generate agreement.';
|
|
603
|
-
activity.EntityType = 'RentalAgreement';
|
|
604
|
-
activity.EntityId = this.AgreementNo;
|
|
605
|
-
activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
|
|
606
|
-
activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
|
|
607
|
-
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
608
|
-
}
|
|
609
|
-
catch (error) {
|
|
610
|
-
throw error;
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
exports.Rental = Rental;
|
|
616
|
-
Rental._Repo = new rental_repository_1.RentalRepository();
|
|
617
|
-
Rental._AgreementRepo = new agreement_repository_1.AgreementRepository();
|
|
618
|
-
Rental._JointHirerRepo = new joint_hirer_repository_1.JointHirerRepository();
|
|
422
|
+
`;
|
|
423
|
+
const db = rentalDb.getConnection();
|
|
424
|
+
const result = yield db.query(query, {
|
|
425
|
+
type: sequelize_1.QueryTypes.SELECT,
|
|
426
|
+
transaction: dbTransaction,
|
|
427
|
+
model: rental_entity_1.RentalModel,
|
|
428
|
+
mapToModel: true,
|
|
429
|
+
});
|
|
430
|
+
const records = result.map((record) => {
|
|
431
|
+
return {
|
|
432
|
+
RentalId: record.RentalId,
|
|
433
|
+
CustomerId: record.CustomerId,
|
|
434
|
+
CustomerType: record.CustomerType,
|
|
435
|
+
ItemId: record.ItemId,
|
|
436
|
+
ItemType: record.ItemType,
|
|
437
|
+
PriceId: record.PriceId,
|
|
438
|
+
StartDateTime: record.StartDateTime,
|
|
439
|
+
EndDateTime: record.EndDateTime,
|
|
440
|
+
CancelRemarks: record.CancelRemarks,
|
|
441
|
+
TerminateRemarks: record.TerminateRemarks,
|
|
442
|
+
AgreementNo: record.AgreementNo,
|
|
443
|
+
AccountType: record.AccountType,
|
|
444
|
+
Status: record.Status,
|
|
445
|
+
EscheatmentYN: record.EscheatmentYN,
|
|
446
|
+
CreatedById: record.CreatedById,
|
|
447
|
+
CreatedAt: record.CreatedAt,
|
|
448
|
+
UpdatedById: record.UpdatedById,
|
|
449
|
+
UpdatedAt: record.UpdatedAt,
|
|
450
|
+
};
|
|
451
|
+
});
|
|
452
|
+
return records;
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
455
|
+
throw error;
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
getCustomerIds(loginUser, dbTransaction) {
|
|
460
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
461
|
+
try {
|
|
462
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
463
|
+
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_VIEW');
|
|
464
|
+
if (!isPrivileged) {
|
|
465
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'Rental - View' privilege.");
|
|
466
|
+
}
|
|
467
|
+
if (!this.RentalId) {
|
|
468
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', 'RentalId is missing');
|
|
469
|
+
}
|
|
470
|
+
const options = {
|
|
471
|
+
where: {
|
|
472
|
+
RentalId: this.RentalId,
|
|
473
|
+
},
|
|
474
|
+
transaction: dbTransaction,
|
|
475
|
+
};
|
|
476
|
+
const joinHirers = yield Rental._JointHirerRepo.findAll(options);
|
|
477
|
+
const customerIds = [this.CustomerId];
|
|
478
|
+
for (let i = 0; i < joinHirers.length; i++) {
|
|
479
|
+
const jointHirer = joinHirers[i];
|
|
480
|
+
customerIds.push(jointHirer.CustomerId);
|
|
481
|
+
}
|
|
482
|
+
return customerIds;
|
|
483
|
+
}
|
|
484
|
+
catch (error) {
|
|
485
|
+
throw error;
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
signAgreement(loginUser, dbTransaction) {
|
|
490
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
+
try {
|
|
492
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
493
|
+
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_SIGN');
|
|
494
|
+
if (!isPrivileged) {
|
|
495
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'RENTAL_SIGN' privilege.");
|
|
496
|
+
}
|
|
497
|
+
const agreement = yield agreement_1.Agreement.init(this.AgreementNo, dbTransaction);
|
|
498
|
+
if (this.Status !== rental_status_enum_1.RentalStatusEnum.PENDING_SIGNING &&
|
|
499
|
+
agreement.Status !== aggrement_status_enum_1.AggrementStatusEnum.GENERATED) {
|
|
500
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', 'Rental is not ready to be signed yet.');
|
|
501
|
+
}
|
|
502
|
+
const entityValueAgreementBefore = {
|
|
503
|
+
AgreementNo: agreement.AgreementNo,
|
|
504
|
+
Status: agreement.Status,
|
|
505
|
+
DateSigned: agreement.DateSigned,
|
|
506
|
+
};
|
|
507
|
+
const payload = {
|
|
508
|
+
DateSigned: new Date(),
|
|
509
|
+
Status: aggrement_status_enum_1.AggrementStatusEnum.SIGNED,
|
|
510
|
+
};
|
|
511
|
+
yield Rental._AgreementRepo.update(payload, {
|
|
512
|
+
where: {
|
|
513
|
+
AgreementNo: this.AgreementNo,
|
|
514
|
+
},
|
|
515
|
+
transaction: dbTransaction,
|
|
516
|
+
});
|
|
517
|
+
const entityValueAgreementAfter = Object.assign({ entityValueAgreementBefore }, payload);
|
|
518
|
+
const activity = new activity_history_1.Activity();
|
|
519
|
+
activity.ActivityId = activity.createId();
|
|
520
|
+
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
521
|
+
activity.Description = 'Update agreement';
|
|
522
|
+
activity.EntityType = 'RentalAgreement';
|
|
523
|
+
activity.EntityId = this.AgreementNo;
|
|
524
|
+
activity.EntityValueBefore = JSON.stringify(entityValueAgreementBefore);
|
|
525
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAgreementAfter);
|
|
526
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
527
|
+
const entityValueRentalBefore = {
|
|
528
|
+
RentalId: this.RentalId,
|
|
529
|
+
CustomerId: this.CustomerId,
|
|
530
|
+
CustomerType: this.CustomerType,
|
|
531
|
+
ItemId: this.ItemId,
|
|
532
|
+
ItemType: this.ItemType,
|
|
533
|
+
PriceId: this.PriceId,
|
|
534
|
+
StartDateTime: this.StartDateTime,
|
|
535
|
+
EndDateTime: this.EndDateTime,
|
|
536
|
+
CancelRemarks: this.CancelRemarks,
|
|
537
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
538
|
+
AgreementNo: this.AgreementNo,
|
|
539
|
+
AccountType: this.AccountType,
|
|
540
|
+
Status: this.Status,
|
|
541
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
542
|
+
CreatedById: this.CreatedById,
|
|
543
|
+
CreatedAt: this.CreatedAt,
|
|
544
|
+
UpdatedById: this.UpdatedById,
|
|
545
|
+
UpdatedAt: this.UpdatedAt,
|
|
546
|
+
};
|
|
547
|
+
const payloadRental = {
|
|
548
|
+
Status: rental_status_enum_1.RentalStatusEnum.PENDING_KEY_COLLECTION,
|
|
549
|
+
UpdatedById: loginUser.ObjectId,
|
|
550
|
+
UpdatedAt: new Date(),
|
|
551
|
+
};
|
|
552
|
+
yield Rental._Repo.update(payloadRental, {
|
|
553
|
+
where: {
|
|
554
|
+
RentalId: this.RentalId,
|
|
555
|
+
},
|
|
556
|
+
transaction: dbTransaction,
|
|
557
|
+
});
|
|
558
|
+
const entityValueRentalAfter = Object.assign({ entityValueRentalBefore }, payloadRental);
|
|
559
|
+
const rentalActivity = new activity_history_1.Activity();
|
|
560
|
+
rentalActivity.ActivityId = activity.createId();
|
|
561
|
+
rentalActivity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
562
|
+
rentalActivity.Description = 'Sign rental agreement';
|
|
563
|
+
rentalActivity.EntityType = 'Rental';
|
|
564
|
+
rentalActivity.EntityId = this.RentalId;
|
|
565
|
+
rentalActivity.EntityValueBefore = JSON.stringify(entityValueRentalBefore);
|
|
566
|
+
rentalActivity.EntityValueAfter = JSON.stringify(entityValueRentalAfter);
|
|
567
|
+
yield rentalActivity.create(loginUser.ObjectId, dbTransaction);
|
|
568
|
+
}
|
|
569
|
+
catch (error) {
|
|
570
|
+
throw error;
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
generateAgreement(loginUser, dbTransaction, MediaId) {
|
|
575
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
576
|
+
try {
|
|
577
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
578
|
+
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_AGREEMENT_CREATE');
|
|
579
|
+
if (!isPrivileged) {
|
|
580
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg01', "You do not have 'RENTAL_AGREEMENT_CREATE' privilege.");
|
|
581
|
+
}
|
|
582
|
+
const agreement = yield agreement_1.Agreement.init(this.AgreementNo, dbTransaction);
|
|
583
|
+
if (!MediaId) {
|
|
584
|
+
throw new general_1.ClassError('Rental', 'RentalErrMsg0X', 'MediaId is required.');
|
|
585
|
+
}
|
|
586
|
+
const EntityValueBefore = agreement;
|
|
587
|
+
agreement.Status = aggrement_status_enum_1.AggrementStatusEnum.GENERATED;
|
|
588
|
+
agreement.MediaId = MediaId;
|
|
589
|
+
yield Rental._AgreementRepo.update({
|
|
590
|
+
Status: agreement.Status,
|
|
591
|
+
MediaId: agreement.MediaId,
|
|
592
|
+
}, {
|
|
593
|
+
where: {
|
|
594
|
+
AgreementNo: this.AgreementNo,
|
|
595
|
+
},
|
|
596
|
+
transaction: dbTransaction,
|
|
597
|
+
});
|
|
598
|
+
const EntityValueAfter = agreement;
|
|
599
|
+
const activity = new activity_history_1.Activity();
|
|
600
|
+
activity.ActivityId = activity.createId();
|
|
601
|
+
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
602
|
+
activity.Description = 'Generate agreement.';
|
|
603
|
+
activity.EntityType = 'RentalAgreement';
|
|
604
|
+
activity.EntityId = this.AgreementNo;
|
|
605
|
+
activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
|
|
606
|
+
activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
|
|
607
|
+
yield activity.create(loginUser.ObjectId, dbTransaction);
|
|
608
|
+
}
|
|
609
|
+
catch (error) {
|
|
610
|
+
throw error;
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
exports.Rental = Rental;
|
|
616
|
+
Rental._Repo = new rental_repository_1.RentalRepository();
|
|
617
|
+
Rental._AgreementRepo = new agreement_repository_1.AgreementRepository();
|
|
618
|
+
Rental._JointHirerRepo = new joint_hirer_repository_1.JointHirerRepository();
|
|
619
619
|
//# sourceMappingURL=rental.js.map
|