hl-core 0.0.7 → 0.0.8-beta.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.
Files changed (65) hide show
  1. package/.prettierrc +2 -1
  2. package/api/index.ts +548 -0
  3. package/api/interceptors.ts +38 -0
  4. package/components/Button/Btn.vue +57 -0
  5. package/components/Button/BtnIcon.vue +47 -0
  6. package/components/Button/ScrollButtons.vue +6 -0
  7. package/components/Button/SortArrow.vue +21 -0
  8. package/components/Complex/Content.vue +5 -0
  9. package/components/Complex/ContentBlock.vue +5 -0
  10. package/components/Complex/Page.vue +43 -0
  11. package/components/Dialog/Dialog.vue +76 -0
  12. package/components/Dialog/FamilyDialog.vue +39 -0
  13. package/components/Form/FormBlock.vue +114 -0
  14. package/components/Form/FormSection.vue +18 -0
  15. package/components/Form/FormTextSection.vue +20 -0
  16. package/components/Form/FormToggle.vue +52 -0
  17. package/components/Form/ProductConditionsBlock.vue +68 -0
  18. package/components/Input/Datepicker.vue +41 -0
  19. package/components/Input/EmptyFormField.vue +5 -0
  20. package/components/Input/FileInput.vue +71 -0
  21. package/components/Input/FormInput.vue +174 -0
  22. package/components/Input/PanelInput.vue +133 -0
  23. package/components/Input/RoundedInput.vue +143 -0
  24. package/components/Layout/Drawer.vue +45 -0
  25. package/components/Layout/Header.vue +48 -0
  26. package/components/Layout/Loader.vue +35 -0
  27. package/components/Layout/SettingsPanel.vue +48 -0
  28. package/components/List/ListEmpty.vue +22 -0
  29. package/components/Menu/MenuNav.vue +108 -0
  30. package/components/Menu/MenuNavItem.vue +37 -0
  31. package/components/Pages/Anketa.vue +341 -0
  32. package/components/Pages/Auth.vue +91 -0
  33. package/components/Pages/Documents.vue +108 -0
  34. package/components/Pages/MemberForm.vue +1148 -0
  35. package/components/Pages/ProductAgreement.vue +18 -0
  36. package/components/Pages/ProductConditions.vue +436 -0
  37. package/components/Panel/PanelHandler.vue +231 -0
  38. package/components/Panel/PanelItem.vue +5 -0
  39. package/components/Panel/PanelSelectItem.vue +20 -0
  40. package/components/Transitions/FadeTransition.vue +5 -0
  41. package/components/Transitions/SlideTransition.vue +5 -0
  42. package/composables/axios.ts +11 -0
  43. package/composables/classes.ts +1129 -0
  44. package/composables/constants.ts +66 -0
  45. package/composables/index.ts +168 -2
  46. package/composables/styles.ts +47 -8
  47. package/layouts/clear.vue +3 -0
  48. package/layouts/default.vue +75 -0
  49. package/layouts/full.vue +6 -0
  50. package/nuxt.config.ts +31 -5
  51. package/package.json +24 -10
  52. package/pages/500.vue +85 -0
  53. package/plugins/helperFunctionsPlugins.ts +17 -2
  54. package/plugins/storePlugin.ts +6 -7
  55. package/plugins/vuetifyPlugin.ts +10 -0
  56. package/store/data.store.js +2484 -6
  57. package/store/form.store.ts +8 -0
  58. package/store/member.store.ts +291 -0
  59. package/store/messages.ts +162 -38
  60. package/store/rules.js +29 -38
  61. package/tailwind.config.js +10 -0
  62. package/types/index.ts +303 -0
  63. package/app.vue +0 -3
  64. package/components/Button/GreenBtn.vue +0 -33
  65. package/store/app.store.js +0 -12
@@ -2,27 +2,2505 @@ import { defineStore } from 'pinia';
2
2
  import { t } from './messages';
3
3
  import { rules } from './rules';
4
4
  import { Toast, Types, Positions, ToastOptions } from './toast';
5
+ import { isValidGUID, yearEnding, jwtDecode, ErrorHandler, getKeyWithPattern, getNumber, getAgeByBirthDate } from '../composables';
6
+ import { DataStoreClass, Contragent } from '../composables/classes';
7
+ import { ApiClass } from '@/api';
8
+ import { useFormStore } from './form.store';
5
9
 
6
10
  export const useDataStore = defineStore('data', {
7
11
  state: () => ({
12
+ ...new DataStoreClass(),
8
13
  t: t,
9
14
  rules: rules,
10
15
  toast: Toast,
11
16
  toastTypes: Types,
12
17
  toastPositions: Positions,
18
+ isValidGUID: isValidGUID,
19
+ router: useRouter(),
20
+ formStore: useFormStore(),
21
+ contragent: useContragentStore(),
22
+ api: new ApiClass(),
23
+ yearEnding: year => yearEnding(year, constants.yearTitles, constants.yearCases),
24
+ currentDate: () => new Date(Date.now() - new Date().getTimezoneOffset() * 60 * 1000).toISOString().slice(0, -1),
13
25
  showToaster: (type, msg, timeout) =>
14
26
  Toast.useToast()(msg, {
15
27
  ...ToastOptions,
16
28
  type: Types[type.toUpperCase()],
17
- timeout:
18
- typeof timeout === ('number' || 'boolean')
19
- ? timeout
20
- : ToastOptions.timeout,
29
+ timeout: type === 'error' ? 6000 : typeof timeout === 'number' ? timeout : ToastOptions.timeout,
21
30
  }),
22
31
  }),
32
+ getters: {
33
+ isEFO: state => state.product === 'efo',
34
+ isBaiterek: state => state.product === 'baiterek',
35
+ isBolashak: state => state.product === 'bolashak',
36
+ isMycar: state => state.product === 'mycar',
37
+ isLifetrip: state => state.product === 'lifetrip',
38
+ isLiferenta: state => state.product === 'liferenta',
39
+ isPension: state => state.product === 'pension',
40
+ isGons: state => state.product === 'gons',
41
+ isEveryFormDisabled: state => Object.values(state.formStore.isDisabled).every(i => i === true),
42
+ },
23
43
  actions: {
24
- async loginUser(...data) {
25
- console.log(...data);
44
+ isIframe() {
45
+ try {
46
+ return window.self !== window.top;
47
+ } catch (err) {
48
+ return true;
49
+ }
50
+ },
51
+ sendToParent(action, value) {
52
+ window.parent.postMessage({ action: action, value: value }, '*');
53
+ },
54
+ getChildIframe() {
55
+ return document.getElementById('product-iframe');
56
+ },
57
+ sendToChild(action, value) {
58
+ const childFrame = this.getChildIframe();
59
+ if (childFrame && childFrame.contentWindow && childFrame.contentWindow.postMessage) {
60
+ childFrame.contentWindow.postMessage({ action: action, value: value }, '*');
61
+ }
62
+ },
63
+ copyToClipboard(text) {
64
+ if (typeof text === 'string' || typeof text === 'number') {
65
+ if (this.isEFO) {
66
+ navigator.clipboard.writeText(text);
67
+ } else {
68
+ this.sendToParent(constants.postActions.clipboard, text);
69
+ }
70
+ this.showToaster('success', this.t('toaster.copied'));
71
+ } else {
72
+ this.showToaster('error', this.t('toaster.noUrl'));
73
+ }
74
+ },
75
+ getFilesByIIN(iin) {
76
+ return iin ? this.formStore.signedDocumentList.filter(file => file.iin === iin && file.fileTypeName === 'Удостоверение личности') : null;
77
+ },
78
+ async getNewAccessToken() {
79
+ try {
80
+ const data = {
81
+ accessToken: localStorage.getItem('accessToken'),
82
+ refreshToken: localStorage.getItem('refreshToken'),
83
+ };
84
+ const response = await this.api.getNewAccessToken(data);
85
+ this.accessToken = response.accessToken;
86
+ this.refreshToken = response.refreshToken;
87
+ localStorage.setItem('accessToken', this.accessToken);
88
+ localStorage.setItem('refreshToken', this.refreshToken);
89
+ } catch (err) {
90
+ console.error(err);
91
+ }
92
+ },
93
+ async loginUser(login, password, numAttempt) {
94
+ try {
95
+ const token = localStorage.getItem('accessToken') || null;
96
+ if (token && isValidToken(token)) {
97
+ this.accessToken = token;
98
+ this.getUserRoles();
99
+ } else {
100
+ const response = await this.api.loginUser({
101
+ login: login,
102
+ password: password,
103
+ numAttempt: numAttempt,
104
+ });
105
+
106
+ this.accessToken = response.accessToken;
107
+ this.refreshToken = response.refreshToken;
108
+ this.getUserRoles();
109
+ }
110
+ if (this.controls.onAuth) {
111
+ const hasPermission =
112
+ this.isInitiator() ||
113
+ this.isUnderwriter() ||
114
+ this.isAdmin() ||
115
+ this.isCompliance() ||
116
+ this.isAnalyst() ||
117
+ this.isUpk() ||
118
+ this.isFinanceCenter() ||
119
+ this.isSupervisor() ||
120
+ this.isSupport();
121
+ if (hasPermission) {
122
+ localStorage.setItem('accessToken', this.accessToken);
123
+ localStorage.setItem('refreshToken', this.refreshToken);
124
+ } else {
125
+ this.showToaster('error', this.t('toaster.noProductPermission'), 5000);
126
+ this.accessToken = null;
127
+ this.refreshToken = null;
128
+ }
129
+ } else {
130
+ localStorage.setItem('accessToken', this.accessToken);
131
+ localStorage.setItem('refreshToken', this.refreshToken);
132
+ }
133
+ } catch (err) {
134
+ ErrorHandler(err);
135
+ }
136
+ },
137
+ getUserRoles() {
138
+ if (this.accessToken && this.user.roles.length === 0) {
139
+ const decoded = jwtDecode(this.accessToken);
140
+ this.user.id = decoded.sub;
141
+ this.user.fullName = `${decoded.lastName} ${decoded.firstName} ${decoded.middleName ? decoded.middleName : ''}`;
142
+ const key = getKeyWithPattern(decoded, 'role');
143
+ if (key) {
144
+ const roles = decoded[key];
145
+ if (typeof roles === constants.types.string) {
146
+ this.user.roles.push(roles);
147
+ } else if (typeof roles === constants.types.array) {
148
+ this.user.roles = roles;
149
+ }
150
+ }
151
+ }
152
+ },
153
+ isRole(whichRole) {
154
+ if (this.user.roles.length === 0) {
155
+ this.getUserRoles();
156
+ }
157
+ const isRole = this.user.roles.find(i => i === whichRole);
158
+ return !!isRole;
159
+ },
160
+ isInitiator() {
161
+ return this.isManager() || this.isAgent() || this.isAgentMycar() || this.isManagerHalykBank() || this.isServiceManager();
162
+ },
163
+ isManager() {
164
+ return this.isRole(constants.roles.manager);
165
+ },
166
+ isCompliance() {
167
+ return this.isRole(constants.roles.compliance);
168
+ },
169
+ isAdmin() {
170
+ return this.isRole(constants.roles.admin);
171
+ },
172
+ isAgent() {
173
+ return this.isRole(constants.roles.agent);
174
+ },
175
+ isManagerHalykBank() {
176
+ return this.isRole(constants.roles.managerHalykBank);
177
+ },
178
+ isServiceManager() {
179
+ return this.isRole(constants.roles.serviceManager);
180
+ },
181
+ isUnderwriter() {
182
+ return this.isRole(constants.roles.underwriter);
183
+ },
184
+ isAgentMycar() {
185
+ return this.isRole(constants.roles.agentMycar);
186
+ },
187
+ isAnalyst() {
188
+ return this.isRole(constants.roles.analyst);
189
+ },
190
+ isUpk() {
191
+ return this.isRole(constants.roles.upk);
192
+ },
193
+ isDrn() {
194
+ return this.isRole(constants.roles.drn);
195
+ },
196
+ isSupport() {
197
+ return this.isRole(constants.roles.support);
198
+ },
199
+ isFinanceCenter() {
200
+ return this.isRole(constants.roles.financeCenter);
201
+ },
202
+ isSupervisor() {
203
+ return this.isRole(constants.roles.supervisor);
204
+ },
205
+ isProcessEditable(statusCode) {
206
+ return !!constants.editableStatuses.find(status => status === statusCode);
207
+ },
208
+ isTask() {
209
+ return this.formStore.applicationData.processInstanceId !== 0 && this.formStore.applicationData.isTask;
210
+ },
211
+ async resetSelected(route) {
212
+ this.settings.open = false;
213
+ this.panel.open = false;
214
+ this.panelAction = null;
215
+ this.menu.selectedItem = new MenuItem();
216
+ if (route && route.name) {
217
+ await this.router.replace({ name: route.name });
218
+ }
219
+ },
220
+ async logoutUser() {
221
+ this.isLoading = true;
222
+ try {
223
+ const whichProduct = this.product;
224
+ const token = localStorage.getItem('accessToken') || null;
225
+ if (token) {
226
+ this.$reset();
227
+ this.formStore.$reset();
228
+ localStorage.clear();
229
+
230
+ if (whichProduct === 'efo') {
231
+ await this.router.push({ name: 'Auth' });
232
+ } else {
233
+ this.sendToParent(constants.postActions.toAuth, null);
234
+ }
235
+ }
236
+ } catch (err) {
237
+ console.log(err);
238
+ }
239
+ this.isLoading = false;
240
+ },
241
+ async getFile(file, mode = 'view', fileType = 'pdf') {
242
+ try {
243
+ this.isLoading = true;
244
+ await this.api.getFile(file.id).then(response => {
245
+ if (!['pdf', 'docx'].includes(fileType)) {
246
+ const blob = new Blob([response], { type: `image/${fileType}` });
247
+ const url = window.URL.createObjectURL(blob);
248
+ const link = document.createElement('a');
249
+ link.href = url;
250
+ if (mode === 'view') {
251
+ setTimeout(() => {
252
+ window.open(url, '_blank', `width=${screen.width},height=${screen.height},top=70`);
253
+ });
254
+ } else {
255
+ link.setAttribute('download', file.fileName);
256
+ document.body.appendChild(link);
257
+ link.click();
258
+ }
259
+ } else {
260
+ const blob = new Blob([response], {
261
+ type: `application/${fileType}`,
262
+ });
263
+ const url = window.URL.createObjectURL(blob);
264
+ const link = document.createElement('a');
265
+ link.href = url;
266
+ if (mode === 'view') {
267
+ setTimeout(() => {
268
+ window.open(url, '_blank', `right=100`);
269
+ });
270
+ } else {
271
+ link.setAttribute('download', file.fileName);
272
+ document.body.appendChild(link);
273
+ link.click();
274
+ }
275
+ }
276
+ });
277
+ } catch (err) {
278
+ ErrorHandler(err);
279
+ } finally {
280
+ this.isLoading = false;
281
+ }
282
+ },
283
+ async deleteFile(data) {
284
+ try {
285
+ await this.api.deleteFile(data);
286
+ this.showToaster('success', this.t('toaster.fileWasDeleted'), 3000);
287
+ } catch (err) {
288
+ this.showToaster('error', err.response.data, 2000);
289
+ }
290
+ },
291
+ async uploadFiles(data, load = false) {
292
+ try {
293
+ if (load) {
294
+ this.isLoading = true;
295
+ }
296
+ await this.api.uploadFiles(data);
297
+ return true;
298
+ } catch (err) {
299
+ return ErrorHandler(err);
300
+ } finally {
301
+ if (load) {
302
+ this.isLoading = false;
303
+ }
304
+ }
305
+ },
306
+ async getContragent(member, whichForm, whichIndex, load = true) {
307
+ if (load) {
308
+ this.isLoading = true;
309
+ }
310
+ try {
311
+ let response;
312
+ let queryData = {
313
+ firstName: '',
314
+ lastName: '',
315
+ middleName: '',
316
+ };
317
+ queryData.iin = member.iin.replace(/-/g, '');
318
+ response = await this.api.getContragent(queryData);
319
+ if (response.totalItems > 0) {
320
+ if (response.totalItems.length === 1) {
321
+ await this.serializeContragentData(whichForm, response.items[0], whichIndex);
322
+ } else {
323
+ const sortedByRegistrationDate = response.items.sort((left, right) => new Date(right.registrationDate) - new Date(left.registrationDate));
324
+ await this.serializeContragentData(whichForm, sortedByRegistrationDate[0], whichIndex);
325
+ }
326
+ member.gotFromInsis = true;
327
+ } else {
328
+ this.userNotFound = true;
329
+ }
330
+ } catch (err) {
331
+ console.log(err);
332
+ }
333
+ if (load) {
334
+ this.isLoading = false;
335
+ }
336
+ },
337
+ async getContragentById(id, whichForm, onlyGet = true, whichIndex = null) {
338
+ if (onlyGet) {
339
+ this.isLoading = true;
340
+ }
341
+ try {
342
+ if (this.isMycar && this.isAgentMycar() && whichForm === this.formStore.beneficiaryFormKey) {
343
+ await this.serializeContragentData(whichForm, this.formStore.applicationData.beneficiaryApp[0], whichIndex);
344
+ this.isLoading = false;
345
+ return;
346
+ }
347
+ const response = await this.api.getContragentById(id);
348
+ if (response.totalItems > 0) {
349
+ await this.serializeContragentData(whichForm, response.items[0], whichIndex);
350
+ } else {
351
+ this.isLoading = false;
352
+ return false;
353
+ }
354
+ } catch (err) {
355
+ console.log(err);
356
+ }
357
+ if (onlyGet) {
358
+ this.isLoading = false;
359
+ }
360
+ },
361
+ async serializeContragentData(whichForm, contragent, whichIndex = null) {
362
+ const [{ value: data }, { value: contacts }, { value: documents }, { value: address }] = await Promise.allSettled([
363
+ this.api.getContrAgentData(contragent.id),
364
+ this.api.getContrAgentContacts(contragent.id),
365
+ this.api.getContrAgentDocuments(contragent.id),
366
+ this.api.getContrAgentAddress(contragent.id),
367
+ ]);
368
+ if (whichIndex === null) {
369
+ this.formStore[whichForm].response = {
370
+ contragent: contragent,
371
+ };
372
+ if (data && data.length) {
373
+ this.formStore[whichForm].response.questionnaires = data;
374
+ }
375
+ if (contacts && contacts.length) {
376
+ this.formStore[whichForm].response.contacts = contacts;
377
+ }
378
+ if (documents && documents.length) {
379
+ this.formStore[whichForm].response.documents = documents;
380
+ }
381
+ if (address && address.length) {
382
+ this.formStore[whichForm].response.addresses = address;
383
+ }
384
+ }
385
+ if (whichIndex !== null) {
386
+ this.formStore[whichForm][whichIndex].response = {
387
+ contragent: contragent,
388
+ };
389
+ if (data && data.length) {
390
+ this.formStore[whichForm][whichIndex].response.questionnaires = data;
391
+ }
392
+ if (contacts && contacts.length) {
393
+ this.formStore[whichForm][whichIndex].response.contacts = contacts;
394
+ }
395
+ if (documents && documents.length) {
396
+ this.formStore[whichForm][whichIndex].response.documents = documents;
397
+ }
398
+ if (address && address.length) {
399
+ this.formStore[whichForm][whichIndex].response.addresses = address;
400
+ }
401
+ }
402
+ this.parseContragent(
403
+ whichForm,
404
+ {
405
+ personalData: contragent,
406
+ documents: documents,
407
+ contacts: contacts,
408
+ data: data,
409
+ address: address,
410
+ },
411
+ whichIndex,
412
+ );
413
+ },
414
+ async searchContragent(iin) {
415
+ this.isLoading = true;
416
+ try {
417
+ let queryData = {
418
+ iin: iin.replace(/-/g, ''),
419
+ firstName: '',
420
+ lastName: '',
421
+ middleName: '',
422
+ };
423
+ const response = await this.api.getContragent(queryData);
424
+ if (response.totalItems > 0) {
425
+ this.contragentList = response.items;
426
+ } else {
427
+ this.contragentList = [];
428
+ }
429
+ } catch (err) {
430
+ console.log(err);
431
+ this.contragentList = [];
432
+ }
433
+ this.isLoading = false;
434
+ },
435
+ parseContragent(whichForm, user, whichIndex = null) {
436
+ if (whichIndex === null) {
437
+ // Save User Personal Data
438
+ this.formStore[whichForm].verifyType = user.personalData.verifyType;
439
+ this.formStore[whichForm].verifyDate = user.personalData.verifyDate;
440
+ this.formStore[whichForm].iin = reformatIin(user.personalData.iin);
441
+ this.formStore[whichForm].age = user.personalData.age;
442
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')));
443
+ this.formStore[whichForm].birthPlace = country && Object.keys(country).length ? country : new Value();
444
+ this.formStore[whichForm].gender = this.gender.find(i => i.nameRu === user.personalData.genderName);
445
+ this.formStore[whichForm].gender.id = user.personalData.gender;
446
+ this.formStore[whichForm].birthDate = reformatDate(user.personalData.birthDate);
447
+ this.formStore[whichForm].genderName = user.personalData.genderName;
448
+ this.formStore[whichForm].lastName = user.personalData.lastName;
449
+ this.formStore[whichForm].longName = user.personalData.longName;
450
+ this.formStore[whichForm].middleName = user.personalData.middleName ? user.personalData.middleName : '';
451
+ this.formStore[whichForm].firstName = user.personalData.firstName;
452
+ this.formStore[whichForm].id = user.personalData.id;
453
+ this.formStore[whichForm].type = user.personalData.type;
454
+ this.formStore[whichForm].registrationDate = user.personalData.registrationDate;
455
+ // Save User Documents Data
456
+ if ('documents' in user && user.documents.length) {
457
+ const documentType = this.documentTypes.find(i => i.ids === user.documents[0].type);
458
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu === user.documents[0].issuerNameRu);
459
+ this.formStore[whichForm].documentType = documentType ? documentType : new Value();
460
+ this.formStore[whichForm].documentNumber = user.documents[0].number;
461
+ this.formStore[whichForm].documentIssuers = documentIssuer ? documentIssuer : new Value();
462
+ this.formStore[whichForm].documentDate = reformatDate(user.documents[0].issueDate);
463
+ this.formStore[whichForm].documentExpire = reformatDate(user.documents[0].expireDate);
464
+ }
465
+ // Document detail (residency, economy code, etc..)
466
+ if ('data' in user && user.data.length) {
467
+ user.data.forEach(dataObject => {
468
+ this.searchFromList(whichForm, dataObject);
469
+ });
470
+ }
471
+ if ('address' in user && user.address.length) {
472
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.address.countryName, 'i')));
473
+ const province = this.states.find(i => i.ids === user.address[0].stateCode);
474
+ const localityType = this.localityTypes.find(i => i.nameRu === user.address[0].cityTypeName);
475
+ const city = this.cities.find(i => !!user.address[0].cityName && i.nameRu === user.address[0].cityName.replace('г.', ''));
476
+ const region = this.regions.find(i => !!user.address[0].regionCode && i.ids == user.address[0].regionCode);
477
+ this.formStore[whichForm].registrationCountry = country ? country : new Value();
478
+ this.formStore[whichForm].registrationStreet = user.address[0].streetName;
479
+ this.formStore[whichForm].registrationCity = city ? city : new Value();
480
+ this.formStore[whichForm].registrationNumberApartment = user.address[0].apartmentNumber;
481
+ this.formStore[whichForm].registrationNumberHouse = user.address[0].blockNumber;
482
+ this.formStore[whichForm].registrationProvince = province ? province : new Value();
483
+ this.formStore[whichForm].registrationRegionType = localityType ? localityType : new Value();
484
+ this.formStore[whichForm].registrationRegion = region ? region : new Value();
485
+ this.formStore[whichForm].registrationQuarter = user.address[0].kvartal;
486
+ this.formStore[whichForm].registrationMicroDistrict = user.address[0].microRaion;
487
+ }
488
+ if ('contacts' in user && user.contacts.length) {
489
+ user.contacts.forEach(contact => {
490
+ if (contact.type === 'EMAIL' && contact.value) {
491
+ this.formStore[whichForm].email = contact.value;
492
+ }
493
+ if (contact.type === 'MOBILE' && contact.value) {
494
+ let phoneNumber = contact.value.substring(1);
495
+ this.formStore[whichForm].phoneNumber = `+7 (${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
496
+ }
497
+ if (contact.type === 'HOME' && contact.value) {
498
+ let homePhone = contact.value.substring(1);
499
+ this.formStore[whichForm].homePhone = `+7 (${homePhone.slice(0, 3)}) ${homePhone.slice(3, 6)} ${homePhone.slice(6, 8)} ${homePhone.slice(8)}`;
500
+ }
501
+ });
502
+ }
503
+ }
504
+ if (whichIndex !== null) {
505
+ // Save User Personal Data
506
+ this.formStore[whichForm][whichIndex].iin = reformatIin(user.personalData.iin);
507
+ this.formStore[whichForm][whichIndex].verifyType = user.personalData.verifyType;
508
+ this.formStore[whichForm][whichIndex].verifyDate = user.personalData.verifyDate;
509
+ this.formStore[whichForm][whichIndex].age = user.personalData.age;
510
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.personalData.birthPlace, 'i')));
511
+ this.formStore[whichForm][whichIndex].birthPlace = country && Object.keys(country).length ? country : new Value();
512
+ this.formStore[whichForm][whichIndex].gender = this.gender.find(i => i.nameRu === user.personalData.genderName);
513
+ this.formStore[whichForm][whichIndex].gender.id = user.personalData.gender;
514
+ this.formStore[whichForm][whichIndex].birthDate = reformatDate(user.personalData.birthDate);
515
+ this.formStore[whichForm][whichIndex].genderName = user.personalData.genderName;
516
+ this.formStore[whichForm][whichIndex].lastName = user.personalData.lastName;
517
+ this.formStore[whichForm][whichIndex].longName = user.personalData.longName;
518
+ this.formStore[whichForm][whichIndex].middleName = user.personalData.middleName ? user.personalData.middleName : '';
519
+ this.formStore[whichForm][whichIndex].firstName = user.personalData.firstName;
520
+ this.formStore[whichForm][whichIndex].id = user.personalData.id;
521
+ this.formStore[whichForm][whichIndex].type = user.personalData.type;
522
+ this.formStore[whichForm][whichIndex].registrationDate = user.personalData.registrationDate;
523
+ // Save User Documents Data
524
+ if ('documents' in user && user.documents.length) {
525
+ const documentType = this.documentTypes.find(i => i.ids === user.documents[0].type);
526
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu === user.documents[0].issuerNameRu);
527
+ this.formStore[whichForm][whichIndex].documentType = documentType ? documentType : new Value();
528
+ this.formStore[whichForm][whichIndex].documentNumber = user.documents[0].number;
529
+ this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer ? documentIssuer : new Value();
530
+ this.formStore[whichForm][whichIndex].documentDate = reformatDate(user.documents[0].issueDate);
531
+ this.formStore[whichForm][whichIndex].documentExpire = reformatDate(user.documents[0].expireDate);
532
+ }
533
+ // Document detail (residency, economy code, etc..)
534
+ if ('data' in user && user.data.length) {
535
+ user.data.forEach(dataObject => {
536
+ this.searchFromList(whichForm, dataObject, whichIndex);
537
+ });
538
+ }
539
+ if ('address' in user && user.address.length) {
540
+ const country = this.countries.find(i => i.nameRu?.match(new RegExp(user.address.countryName, 'i')));
541
+ const province = this.states.find(i => i.ids === user.address[0].stateCode);
542
+ const localityType = this.localityTypes.find(i => i.nameRu === user.address[0].cityTypeName);
543
+ const city = this.cities.find(i => !!user.address[0].cityName && i.nameRu === user.address[0].cityName.replace('г.', ''));
544
+ const region = this.regions.find(i => !!user.address[0].regionCode && i.ids == user.address[0].regionCode);
545
+ this.formStore[whichForm][whichIndex].registrationCountry = country ? country : new Value();
546
+ this.formStore[whichForm][whichIndex].registrationStreet = user.address[0].streetName;
547
+ this.formStore[whichForm][whichIndex].registrationCity = city ? city : new Value();
548
+ this.formStore[whichForm][whichIndex].registrationNumberApartment = user.address[0].apartmentNumber;
549
+ this.formStore[whichForm][whichIndex].registrationNumberHouse = user.address[0].blockNumber;
550
+ this.formStore[whichForm][whichIndex].registrationProvince = province ? province : new Value();
551
+ this.formStore[whichForm][whichIndex].registrationRegionType = localityType ? localityType : new Value();
552
+ this.formStore[whichForm][whichIndex].registrationRegion = region ? region : new Value();
553
+ this.formStore[whichForm][whichIndex].registrationQuarter = user.address[0].kvartal;
554
+ this.formStore[whichForm][whichIndex].registrationMicroDistrict = user.address[0].microRaion;
555
+ }
556
+ if ('contacts' in user && user.contacts.length) {
557
+ user.contacts.forEach(contact => {
558
+ if (contact.type === 'EMAIL' && contact.value) {
559
+ this.formStore[whichForm][whichIndex].email = contact.value;
560
+ }
561
+ if (contact.type === 'MOBILE' && contact.value) {
562
+ let phoneNumber = contact.value.substring(1);
563
+ this.formStore[whichForm][whichIndex].phoneNumber = `+7 (${phoneNumber.slice(0, 3)}) ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
564
+ }
565
+ if (contact.type === 'HOME' && contact.value) {
566
+ let homePhone = contact.value.substring(1);
567
+ this.formStore[whichForm][whichIndex].homePhone = `+7 (${homePhone.slice(0, 3)}) ${homePhone.slice(3, 6)} ${homePhone.slice(6, 8)} ${homePhone.slice(8)}`;
568
+ }
569
+ });
570
+ }
571
+ }
572
+ },
573
+ async alreadyInInsis(iin, firstName, lastName, middleName) {
574
+ try {
575
+ const queryData = {
576
+ iin: iin.replaceAll('-', ''),
577
+ firstName: !!firstName ? firstName : '',
578
+ lastName: !!lastName ? lastName : '',
579
+ middleName: !!middleName ? middleName : '',
580
+ };
581
+ const contragent = await this.api.getContragent(queryData);
582
+ if (contragent.totalItems > 0) {
583
+ if (contragent.totalItems.length === 1) {
584
+ return contragent.items[0].id;
585
+ } else {
586
+ const sortedByRegistrationDate = contragent.items.sort((left, right) => new Date(right.registrationDate) - new Date(left.registrationDate));
587
+ return sortedByRegistrationDate[0].id;
588
+ }
589
+ } else {
590
+ return false;
591
+ }
592
+ } catch (err) {
593
+ console.log(err);
594
+ return false;
595
+ }
596
+ },
597
+ async saveContragent(user, whichForm, whichIndex, onlySaveAction = true) {
598
+ this.isLoading = !onlySaveAction;
599
+ const hasInsisId = await this.alreadyInInsis(user.iin, user.firstName, user.lastName, user.middleName);
600
+ if (hasInsisId !== false) {
601
+ user.id = hasInsisId;
602
+ const [{ value: data }, { value: contacts }, { value: documents }, { value: address }] = await Promise.allSettled([
603
+ this.api.getContrAgentData(user.id),
604
+ this.api.getContrAgentContacts(user.id),
605
+ this.api.getContrAgentDocuments(user.id),
606
+ this.api.getContrAgentAddress(user.id),
607
+ ]);
608
+ user.response = {};
609
+ if (data && data.length) {
610
+ user.response.questionnaires = data;
611
+ }
612
+ if (contacts && contacts.length) {
613
+ user.response.contacts = contacts;
614
+ }
615
+ if (documents && documents.length) {
616
+ user.response.documents = documents;
617
+ }
618
+ if (address && address.length) {
619
+ user.response.addresses = address;
620
+ }
621
+ }
622
+ try {
623
+ // ! SaveContragent -> Contragent
624
+ let contragentData = {
625
+ id: user.id,
626
+ type: user.type,
627
+ iin: user.iin.replace(/-/g, ''),
628
+ longName: user.longName !== null ? user.longName : user.lastName + user.firstName + user.middleName ? user.middleName : '',
629
+ lastName: user.lastName,
630
+ firstName: user.firstName,
631
+ middleName: user.middleName ? user.middleName : '',
632
+ birthDate: user.getDateByKey('birthDate'),
633
+ gender: user.gender.id,
634
+ genderName: user.genderName ? user.genderName : user.gender.nameRu,
635
+ birthPlace: user.birthPlace.nameRu,
636
+ age: user.age,
637
+ registrationDate: user.registrationDate,
638
+ verifyType: user.verifyType,
639
+ verifyDate: user.verifyDate,
640
+ };
641
+ // ! SaveContragent -> Questionnaires
642
+ let questionnaires = (({ economySectorCode, countryOfCitizenship, countryOfTaxResidency, signOfResidency }) => ({
643
+ economySectorCode,
644
+ countryOfCitizenship,
645
+ countryOfTaxResidency,
646
+ signOfResidency,
647
+ }))(user);
648
+ let questionariesData = Object.values(questionnaires).map(question => {
649
+ let questName = '';
650
+ let questionId = parseInt(question.ids).toString();
651
+ if (questionId === '500003') {
652
+ questName = 'Код сектора экономики';
653
+ } else if (questionId === '500011') {
654
+ questName = 'Признак резидентства';
655
+ } else if (questionId === '500012') {
656
+ questName = 'Страна гражданства';
657
+ } else if (questionId === '500014') {
658
+ questName = 'Страна налогового резиденства';
659
+ }
660
+ return {
661
+ id: 'response' in user && 'questionnaires' in user.response ? user.response.questionnaires?.find(i => i.questId == questionId).id : question.id,
662
+ contragentId: user.id,
663
+ questAnswer: question.ids,
664
+ questId: questionId,
665
+ questAnswerName: question.nameRu,
666
+ questName: questName,
667
+ };
668
+ });
669
+ if (user.countryOfTaxResidency.ids !== '500014.3') {
670
+ user.addTaxResidency = new Value();
671
+ }
672
+ const addTaxResidency = 'response' in user && 'questionnaires' in user.response && user.response.questionnaires.find(i => i.questId === '507777');
673
+ if (user.addTaxResidency.nameRu !== null) {
674
+ questionariesData.push({
675
+ id: addTaxResidency ? addTaxResidency.id : 0,
676
+ contragentId: user.id,
677
+ questAnswer: user.addTaxResidency.ids,
678
+ questAnswerName: user.addTaxResidency.nameRu,
679
+ questName: 'Указать если налоговое резиденство выбрано другое',
680
+ questId: '507777',
681
+ });
682
+ } else {
683
+ if (addTaxResidency && addTaxResidency.questAnswer !== null) {
684
+ questionariesData.push({
685
+ id: addTaxResidency.id,
686
+ contragentId: user.id,
687
+ questAnswer: null,
688
+ questAnswerName: null,
689
+ questName: 'Указать если налоговое резиденство выбрано другое',
690
+ questId: '507777',
691
+ });
692
+ }
693
+ }
694
+
695
+ // ! SaveContragent -> Contacts
696
+ let contactsData = [];
697
+ if (user.phoneNumber !== '' && user.phoneNumber !== null) {
698
+ contactsData.push({
699
+ contragentId: user.id,
700
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'MOBILE').id : 0,
701
+ newValue: '',
702
+ note: '',
703
+ primaryFlag: 'Y',
704
+ type: 'MOBILE',
705
+ typeName: 'Сотовый телефон',
706
+ value: formatPhone(user.phoneNumber),
707
+ verifyType: user.otpTokenId ? 'BMG' : 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'MOBILE').verifyType : null,
708
+ verifyDate: user.otpTokenId
709
+ ? this.currentDate()
710
+ : 'response' in user && 'contacts' in user.response
711
+ ? user.response.contacts.find(i => i.type === 'MOBILE').verifyDate
712
+ : null,
713
+ });
714
+ }
715
+ if (user.email !== '' && user.email !== null) {
716
+ contactsData.push({
717
+ contragentId: user.id,
718
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'EMAIL').id : 0,
719
+ newValue: '',
720
+ note: '',
721
+ primaryFlag: 'N',
722
+ type: 'EMAIL',
723
+ typeName: 'E-Mail',
724
+ value: user.email ? user.email : 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'EMAIL').value : '',
725
+ });
726
+ }
727
+ if (user.homePhone !== '' && user.homePhone !== null) {
728
+ contactsData.push({
729
+ contragentId: user.id,
730
+ id: 'response' in user && 'contacts' in user.response ? user.response.contacts.find(i => i.type === 'HOME').id : 0,
731
+ newValue: '',
732
+ note: '',
733
+ primaryFlag: 'N',
734
+ type: 'HOME',
735
+ typeName: 'Домашний телефон',
736
+ value: user.homePhone
737
+ ? formatPhone(user.homePhone)
738
+ : 'response' in user && 'contacts' in user.response
739
+ ? user.response.contacts.find(i => i.type === 'HOME').value
740
+ : '',
741
+ });
742
+ }
743
+
744
+ // ! SaveContragent -> Documents
745
+ let documentsData = [];
746
+ documentsData.push({
747
+ contragentId: user.id,
748
+ id: 'response' in user && 'documents' in user.response ? user.response.documents[0].id : 0,
749
+ description: null,
750
+ expireDate: user.getDateByKey('documentExpire'),
751
+ issueDate: user.getDateByKey('documentDate'),
752
+ issuerId: Number(user.documentIssuers.ids),
753
+ issuerName: user.documentIssuers.nameKz,
754
+ issuerNameRu: user.documentIssuers.nameRu,
755
+ note: null,
756
+ number: user.documentNumber,
757
+ type: user.documentType.ids,
758
+ typeName: user.documentType.nameRu,
759
+ serial: null,
760
+ verifyType: user.verifyType,
761
+ verifyDate: user.verifyDate,
762
+ });
763
+
764
+ // ! SaveContragent -> Addresses
765
+ let addressData = [];
766
+ addressData.push({
767
+ id: 'response' in user && 'addresses' in user.response ? user.response.addresses[0].id : 0,
768
+ contragentId: user.id,
769
+ countryCode: user.birthPlace.ids,
770
+ countryName: user.birthPlace.nameRu,
771
+ stateCode: user.registrationProvince.ids,
772
+ stateName: user.registrationProvince.nameRu,
773
+ cityCode: user.registrationCity.code,
774
+ cityName: user.registrationCity.nameRu,
775
+ regionCode: user.registrationRegion.ids,
776
+ regionName: user.registrationRegion.nameRu,
777
+ streetName: user.registrationStreet,
778
+ kvartal: user.registrationQuarter,
779
+ microRaion: user.registrationMicroDistrict,
780
+ cityTypeId: Number(user.registrationRegionType.ids),
781
+ cityTypeName: user.registrationRegionType.nameRu,
782
+ blockNumber: user.registrationNumberHouse,
783
+ apartmentNumber: user.registrationNumberApartment,
784
+ address: `${user.birthPlace.nameRu}, ${user.registrationRegionType.nameRu} ${user.registrationCity.nameRu}, ул. ${user.registrationStreet}, д. ${user.registrationNumberHouse} кв. ${user.registrationNumberApartment}`,
785
+ type: 'H',
786
+ });
787
+
788
+ const data = {
789
+ contragent: contragentData,
790
+ questionaries: questionariesData,
791
+ contacts: contactsData,
792
+ documents: documentsData,
793
+ addresses: addressData,
794
+ };
795
+
796
+ const personId = await this.api.saveContragent(data);
797
+ if (personId) {
798
+ await this.getContragentById(personId, whichForm, false, whichIndex);
799
+ user.otpTokenId = null;
800
+ }
801
+ } catch (err) {
802
+ this.isLoading = false;
803
+ return ErrorHandler(err);
804
+ }
805
+ if (onlySaveAction) {
806
+ this.isLoading = false;
807
+ }
808
+ return true;
809
+ },
810
+ async saveMember(member, whichMember, memberFromApplicaiton) {
811
+ let data = {};
812
+ try {
813
+ data = {
814
+ processInstanceId: this.formStore.applicationData.processInstanceId,
815
+ insisId: member.id,
816
+ iin: member.iin.replace(/-/g, ''),
817
+ longName: member.longName,
818
+ isIpdl: member.signOfIPDL.nameRu == 'Да' ? true : false,
819
+ isTerror: member.isTerror,
820
+ isIpdlCompliance: null,
821
+ isTerrorCompliance: null,
822
+ };
823
+ data.id = memberFromApplicaiton && memberFromApplicaiton.id ? memberFromApplicaiton.id : null;
824
+ if (whichMember === 'Client') {
825
+ data.isInsured = this.formStore.isPolicyholderInsured;
826
+ data.isActOwnBehalf = this.formStore.isActOwnBehalf;
827
+ data.profession = member.job;
828
+ data.position = member.jobPosition;
829
+ data.jobName = member.jobPlace;
830
+ data.familyStatusId = member.familyStatus.id;
831
+ }
832
+ if (whichMember === 'Spokesman') {
833
+ if (!!memberFromApplicaiton && memberFromApplicaiton.iin !== data.iin) {
834
+ delete data.id;
835
+ await this.api.deleteMember('Spokesman', this.formStore.applicationData.processInstanceId);
836
+ }
837
+ data.migrationCard = member.migrationCard;
838
+ const migrationCardIssueDate = formatDate(member.migrationCardIssueDate);
839
+ if (migrationCardIssueDate) data.migrationCardIssueDate = migrationCardIssueDate.toISOString();
840
+ const migrationCardExpireDate = formatDate(member.migrationCardExpireDate);
841
+ if (migrationCardExpireDate) data.migrationCardExpireDate = migrationCardExpireDate.toISOString();
842
+ data.confirmDocType = member.confirmDocType;
843
+ data.confirmDocNumber = member.confirmDocNumber;
844
+ const confirmDocIssueDate = formatDate(member.confirmDocIssueDate);
845
+ if (confirmDocIssueDate) data.confirmDocIssueDate = confirmDocIssueDate.toISOString();
846
+ const confirmDocExpireDate = formatDate(member.confirmDocExpireDate);
847
+ if (confirmDocExpireDate) data.confirmDocExpireDate = confirmDocExpireDate.toISOString();
848
+ data.clientLongName = this.formStore.applicationData.clientApp.longName;
849
+ data.notaryLongName = member.notaryLongName;
850
+ data.notaryLicenseNumber = member.notaryLicenseNumber;
851
+ const notaryLicenseDate = formatDate(member.notaryLicenseDate);
852
+ if (notaryLicenseDate) data.notaryLicenseDate = notaryLicenseDate.toISOString();
853
+ data.notaryLicenseIssuer = member.notaryLicenseIssuer;
854
+ data.jurLongName = member.jurLongName;
855
+ data.fullNameRod = member.fullNameRod;
856
+ data.confirmDocTypeKz = member.confirmDocTypeKz;
857
+ data.confirmDocTypeRod = member.confirmDocTypeRod;
858
+ data.isNotary = member.isNotary;
859
+ }
860
+ if (whichMember === 'Insured') {
861
+ if (
862
+ this.formStore.applicationData &&
863
+ this.formStore.applicationData.insuredApp &&
864
+ this.formStore.applicationData.insuredApp.length &&
865
+ this.formStore.applicationData.insuredApp.every(i => i.iin !== data.iin) &&
866
+ data.id !== null
867
+ ) {
868
+ await this.api.deleteMember('Insured', data.id);
869
+ delete data.id;
870
+ }
871
+ data.isDisability = this.formStore.isPolicyholderInsured ? false : member.isDisability.nameRu == 'Да';
872
+ data.disabilityGroupId = data.isDisability ? member.disabilityGroupId.id : null;
873
+ data.profession = member.job;
874
+ data.position = member.jobPosition;
875
+ data.jobName = member.jobPlace;
876
+ data.familyStatusId = member.familyStatus.id;
877
+ }
878
+ if (whichMember === 'Beneficiary') {
879
+ if (
880
+ this.formStore.applicationData &&
881
+ this.formStore.applicationData.beneficiaryApp &&
882
+ this.formStore.applicationData.beneficiaryApp.length &&
883
+ this.formStore.applicationData.beneficiaryApp.every(i => i.iin !== data.iin) &&
884
+ data.id !== null
885
+ ) {
886
+ await this.api.deleteMember('Beneficiary', data.id);
887
+ delete data.id;
888
+ }
889
+ data.familyStatusId = member.familyStatus.id == 0 ? null : member.familyStatus.id;
890
+ data.percentage = Number(member.percentageOfPayoutAmount);
891
+ data.relationId = member.relationDegree.ids;
892
+ data.relationName = member.relationDegree.nameRu;
893
+ }
894
+ if (whichMember === 'BeneficialOwner') {
895
+ if (data.id === 0) {
896
+ data.id = null;
897
+ }
898
+ if (
899
+ this.formStore.applicationData &&
900
+ this.formStore.applicationData.beneficialOwnerApp &&
901
+ this.formStore.applicationData.beneficialOwnerApp.length &&
902
+ this.formStore.applicationData.beneficialOwnerApp.every(i => i.iin !== data.iin) &&
903
+ data.id !== null
904
+ ) {
905
+ await this.api.deleteMember('BeneficialOwner', data.id);
906
+ delete data.id;
907
+ }
908
+ data.familyStatusId = member.familyStatus.id;
909
+ }
910
+ await this.api.setMember(whichMember, data);
911
+ return true;
912
+ } catch (err) {
913
+ return ErrorHandler(err, err.response?.data?.errors && Object.values(err.response?.data?.errors).join(' -> '));
914
+ }
915
+ },
916
+ searchFromList(whichForm, searchIt, whichIndex = null) {
917
+ const getQuestionariesData = () => {
918
+ switch (searchIt.questId) {
919
+ case '500003':
920
+ return [this.economySectorCode, 'economySectorCode'];
921
+ case '500011':
922
+ return [this.residents, 'signOfResidency'];
923
+ case '500012':
924
+ return [this.citizenshipCountries, 'countryOfCitizenship'];
925
+ case '500014':
926
+ return [this.taxCountries, 'countryOfTaxResidency'];
927
+ case '507777':
928
+ return [this.addTaxCountries, 'addTaxResidency'];
929
+ case '500147':
930
+ return [[]];
931
+ case '500148':
932
+ return [[]];
933
+ }
934
+ };
935
+
936
+ const [searchFrom, whichField] = getQuestionariesData();
937
+ if (searchFrom && searchFrom.length) {
938
+ const result = searchFrom.find(i => i.ids === searchIt.questAnswer);
939
+ if (whichIndex === null) {
940
+ this.formStore[whichForm][whichField] = result ? result : new Value();
941
+ } else {
942
+ this.formStore[whichForm][whichIndex][whichField] = result ? result : new Value();
943
+ }
944
+ }
945
+ },
946
+ async setSurvey(data) {
947
+ try {
948
+ this.isLoading = true;
949
+ const anketaToken = await this.api.setSurvey(data);
950
+ this.showToaster('success', this.t('toaster.successSaved'), 2000);
951
+ return anketaToken;
952
+ } catch (error) {
953
+ return ErrorHandler(err);
954
+ } finally {
955
+ this.isLoading = false;
956
+ }
957
+ },
958
+ async getFromApi(whichField, whichRequest, parameter, reset = false) {
959
+ const storageValue = JSON.parse(localStorage.getItem(whichField) || 'null');
960
+ const currentHour = new Date().getHours();
961
+
962
+ const getDataCondition = () => {
963
+ if (!storageValue) return true;
964
+ const hasHourKey = 'hour' in storageValue;
965
+ const hasModeKey = 'mode' in storageValue;
966
+ const hasValueKey = 'value' in storageValue;
967
+ if (storageValue && (hasHourKey === false || hasModeKey === false || hasValueKey === false)) return true;
968
+ if (storageValue && (storageValue.hour !== currentHour || storageValue.mode !== import.meta.env.MODE || storageValue.value.length === 0)) return true;
969
+ };
970
+ if (!!getDataCondition() || reset === true) {
971
+ this[whichField] = [];
972
+ try {
973
+ const response = await this.api[whichRequest](parameter);
974
+ if (response) {
975
+ localStorage.setItem(
976
+ whichField,
977
+ JSON.stringify({
978
+ value: response,
979
+ hour: currentHour,
980
+ mode: import.meta.env.MODE,
981
+ }),
982
+ );
983
+ this[whichField] = response;
984
+ }
985
+ } catch (err) {
986
+ console.log(err);
987
+ }
988
+ } else {
989
+ this[whichField] = storageValue.value;
990
+ }
991
+
992
+ return this[whichField];
993
+ },
994
+ async getCountries() {
995
+ return await this.getFromApi('countries', 'getCountries');
996
+ },
997
+ async getCitizenshipCountries() {
998
+ return await this.getFromApi('citizenshipCountries', 'getCitizenshipCountries');
999
+ },
1000
+ async getTaxCountries() {
1001
+ return await this.getFromApi('taxCountries', 'getTaxCountries');
1002
+ },
1003
+ async getAdditionalTaxCountries() {
1004
+ return await this.getFromApi('addTaxCountries', 'getAdditionalTaxCountries');
1005
+ },
1006
+ async getStates(key, member) {
1007
+ await this.getFromApi('states', 'getStates');
1008
+ if (key && member[key] && member[key].ids !== null) {
1009
+ return this.states.filter(i => i.code === member[key].ids);
1010
+ }
1011
+ return this.states;
1012
+ },
1013
+ async getRegions(key, member) {
1014
+ await this.getFromApi('regions', 'getRegions');
1015
+ if (key && member[key] && member[key].ids !== null) {
1016
+ return this.regions.filter(i => i.code === member[key].ids);
1017
+ }
1018
+ if (member.registrationProvince.ids !== null) {
1019
+ return this.regions.filter(i => i.code === member.registrationProvince.ids);
1020
+ } else {
1021
+ return this.regions;
1022
+ }
1023
+ },
1024
+ async getCities(key, member) {
1025
+ await this.getFromApi('cities', 'getCities');
1026
+ if (key && member[key] && member[key].ids !== null) {
1027
+ return this.cities.filter(i => i.code === member[key].ids);
1028
+ }
1029
+ if (member.registrationProvince.ids !== null) {
1030
+ return this.cities.filter(i => i.code === member.registrationProvince.ids);
1031
+ } else {
1032
+ return this.cities;
1033
+ }
1034
+ },
1035
+ async getLocalityTypes() {
1036
+ return await this.getFromApi('localityTypes', 'getLocalityTypes');
1037
+ },
1038
+ async getDocumentTypes() {
1039
+ const document_list = await this.getFromApi('documentTypes', 'getDocumentTypes');
1040
+ await this.getDicFileTypeList();
1041
+ return document_list.filter(doc => {
1042
+ for (const dic of this.dicFileTypeList) {
1043
+ if (doc.nameRu === dic.nameRu) {
1044
+ return doc;
1045
+ }
1046
+ }
1047
+ });
1048
+ },
1049
+ async getDicFileTypeList() {
1050
+ try {
1051
+ if (this.dicFileTypeList.length) {
1052
+ return this.dicFileTypeList;
1053
+ } else {
1054
+ this.dicFileTypeList = await this.api.getDicFileTypeList();
1055
+ return this.dicFileTypeList;
1056
+ }
1057
+ } catch (err) {
1058
+ console.log(err.response.data);
1059
+ }
1060
+ },
1061
+ async getDocumentIssuers() {
1062
+ return await this.getFromApi('documentIssuers', 'getDocumentIssuers');
1063
+ },
1064
+ async getResidents() {
1065
+ return await this.getFromApi('residents', 'getResidents');
1066
+ },
1067
+ async getSectorCodeList() {
1068
+ await this.getFromApi('economySectorCode', 'getSectorCode');
1069
+ return this.economySectorCode;
1070
+ },
1071
+ async getFamilyStatuses() {
1072
+ return await this.getFromApi('familyStatuses', 'getFamilyStatuses');
1073
+ },
1074
+ async getRelationTypes() {
1075
+ // TODO Remove this & add filtering in openPanel method
1076
+ await this.getFromApi('relations', 'getRelationTypes');
1077
+ const filteredRelations = this.relations.filter(i => Number(i.ids) >= 6 && Number(i.ids) <= 15);
1078
+ const otherRelations = this.relations.filter(i => Number(i.ids) < 6 || Number(i.ids) > 15);
1079
+ return [...filteredRelations, ...otherRelations];
1080
+ },
1081
+ async getProcessIndexRate() {
1082
+ const response = await this.getFromApi('processIndexRate', 'getProcessIndexRate', this.processCode);
1083
+ return response ? response : [];
1084
+ },
1085
+ async getProcessCoverTypeSum(type) {
1086
+ return await this.getFromApi('processCoverTypeSum', 'getProcessCoverTypeSum', type);
1087
+ },
1088
+ async getProcessPaymentPeriod() {
1089
+ return await this.getFromApi('processPaymentPeriod', 'getProcessPaymentPeriod', this.processCode);
1090
+ },
1091
+ async getQuestionRefs(id) {
1092
+ return await this.getFromApi('questionRefs', 'getQuestionRefs', id, true);
1093
+ },
1094
+ async getProcessTariff() {
1095
+ return await this.getFromApi('processTariff', 'getProcessTariff');
1096
+ },
1097
+ async getAdditionalInsuranceTermsAnswers(questionId) {
1098
+ try {
1099
+ const answers = await this.api.getAdditionalInsuranceTermsAnswers(this.processCode, questionId);
1100
+ return answers;
1101
+ } catch (err) {
1102
+ console.log(err);
1103
+ }
1104
+ },
1105
+ async getQuestionList(surveyType, processInstanceId, insuredId, baseField, secondaryField) {
1106
+ if (!this.formStore[baseField] || (this.formStore[baseField] && !this.formStore[baseField].length)) {
1107
+ try {
1108
+ const [{ value: baseQuestions }, { value: secondaryQuestions }] = await Promise.allSettled([
1109
+ this.api.getQuestionList(surveyType, processInstanceId, insuredId),
1110
+ this.api.getQuestionListSecond(`${surveyType}second`, processInstanceId, insuredId),
1111
+ ]);
1112
+ this.formStore[baseField] = baseQuestions;
1113
+ this.formStore[secondaryField] = secondaryQuestions;
1114
+ } catch (err) {
1115
+ console.log(err);
1116
+ }
1117
+ }
1118
+ return this.formStore[baseField];
1119
+ },
1120
+ getNumberWithSpaces(n) {
1121
+ return n === null ? null : Number((typeof n === 'string' ? n : n.toFixed().toString()).replace(/[^0-9]+/g, '')).toLocaleString('ru');
1122
+ },
1123
+ async getTaskList(search = '', groupCode = 'Work', onlyGet = false, needToReturn = false, key = 'dateCreated', processInstanceId = null, byOneProcess = null) {
1124
+ if (onlyGet === false) {
1125
+ this.isLoading = true;
1126
+ }
1127
+ try {
1128
+ const column = this.isColumnAsc[key] === null ? 'dateCreated' : key;
1129
+ const direction = this.isColumnAsc[key] === null ? 'desc' : this.isColumnAsc[key] === true ? 'asc' : 'desc';
1130
+ const query = {
1131
+ pageIndex: processInstanceId === null ? this.historyPageIndex - 1 : 0,
1132
+ pageSize: this.historyPageSize,
1133
+ search: search ? search.replace(/-/g, '') : '',
1134
+ column: column,
1135
+ direction: direction,
1136
+ groupCode: groupCode,
1137
+ processCodes: Object.values(constants.products),
1138
+ };
1139
+ if (byOneProcess !== null) {
1140
+ delete query.processCodes;
1141
+ query.processCode = byOneProcess;
1142
+ }
1143
+ const taskList = await this.api.getTaskList(processInstanceId === null ? query : { ...query, processInstanceId: processInstanceId });
1144
+ if (needToReturn) {
1145
+ this.isLoading = false;
1146
+ return taskList.items;
1147
+ } else {
1148
+ this.taskList = taskList.items;
1149
+ this.historyTotalItems = taskList.totalItems;
1150
+ }
1151
+ } catch (err) {
1152
+ this.showToaster('error', err?.response?.data, 2000);
1153
+ console.log(err);
1154
+ } finally {
1155
+ this.isLoading = false;
1156
+ }
1157
+ if (onlyGet === false) {
1158
+ this.isLoading = false;
1159
+ }
1160
+ },
1161
+ async getProcessHistoryList(id) {
1162
+ try {
1163
+ const processHistory = await this.api.getProcessHistory(id);
1164
+ if (processHistory.length > 0) {
1165
+ return processHistory;
1166
+ } else {
1167
+ return [];
1168
+ }
1169
+ } catch (err) {
1170
+ console.log(err);
1171
+ }
1172
+ },
1173
+ async getProcessHistory(id) {
1174
+ this.isLoading = true;
1175
+ try {
1176
+ const processHistory = await this.api.getProcessHistory(id);
1177
+ if (processHistory.length > 0) {
1178
+ this.processHistory = processHistory.reverse();
1179
+ } else {
1180
+ this.processHistory = [];
1181
+ }
1182
+ } catch (err) {
1183
+ console.log(err);
1184
+ }
1185
+ this.isLoading = false;
1186
+ },
1187
+ findObject(from, key, searchKey) {
1188
+ const found = this[from].find(i => i[key] == searchKey);
1189
+ return found || new Value();
1190
+ },
1191
+ async getAllFormsData() {
1192
+ await Promise.allSettled([
1193
+ this.getCountries(),
1194
+ this.getCitizenshipCountries(),
1195
+ this.getTaxCountries(),
1196
+ this.getAdditionalTaxCountries(),
1197
+ this.getStates(),
1198
+ this.getRegions(),
1199
+ this.getCities(),
1200
+ this.getLocalityTypes(),
1201
+ this.getDocumentTypes(),
1202
+ this.getDocumentIssuers(),
1203
+ this.getResidents(),
1204
+ this.getSectorCodeList(),
1205
+ this.getFamilyStatuses(),
1206
+ this.getRelationTypes(),
1207
+ this.getProcessIndexRate(),
1208
+ this.getProcessTariff(),
1209
+ this.getProcessPaymentPeriod(),
1210
+ ]);
1211
+ },
1212
+ async getUserGroups() {
1213
+ try {
1214
+ this.isLoading = true;
1215
+ this.userGroups = await this.api.getUserGroups();
1216
+ } catch (err) {
1217
+ console.log(err);
1218
+ } finally {
1219
+ this.isLoading = false;
1220
+ }
1221
+ },
1222
+ async getProcessList() {
1223
+ this.isLoading = true;
1224
+ try {
1225
+ const processList = await this.api.getProcessList();
1226
+ if (this.processList === null) {
1227
+ this.processList = processList;
1228
+ }
1229
+ } catch (err) {
1230
+ console.log(err);
1231
+ }
1232
+ this.isLoading = false;
1233
+ },
1234
+ sortTaskList(key) {
1235
+ if (this.taskList.length !== 0) {
1236
+ if (key in this.isColumnAsc) {
1237
+ if (this.isColumnAsc[key] === true) {
1238
+ this.isColumnAsc = { ...InitialColumns() };
1239
+ this.isColumnAsc[key] = false;
1240
+ return;
1241
+ }
1242
+ if (this.isColumnAsc[key] === false) {
1243
+ this.isColumnAsc = { ...InitialColumns() };
1244
+ this.isColumnAsc[key] = null;
1245
+ return;
1246
+ }
1247
+ if (this.isColumnAsc[key] === null) {
1248
+ this.isColumnAsc = { ...InitialColumns() };
1249
+ this.isColumnAsc[key] = true;
1250
+ return;
1251
+ }
1252
+ }
1253
+ }
1254
+ },
1255
+ async searchAgentByName(name) {
1256
+ try {
1257
+ this.isLoading = true;
1258
+ this.AgentDataList = await this.api.searchAgentByName(name);
1259
+ if (!this.AgentDataList.length) {
1260
+ this.showToaster('error', this.t('toaster.notFound'), 1500);
1261
+ }
1262
+ } catch (err) {
1263
+ console.log(err);
1264
+ } finally {
1265
+ this.isLoading = false;
1266
+ }
1267
+ },
1268
+ async setINSISWorkData() {
1269
+ const data = {
1270
+ id: this.formStore.applicationData.insisWorkDataApp.id,
1271
+ processInstanceId: this.formStore.applicationData.processInstanceId,
1272
+ agentId: this.formStore.AgentData.agentId,
1273
+ agentName: this.formStore.AgentData.fullName,
1274
+ salesChannel: this.formStore.applicationData.insisWorkDataApp.salesChannel,
1275
+ salesChannelName: this.formStore.applicationData.insisWorkDataApp.salesChannelName,
1276
+ insrType: this.formStore.applicationData.insisWorkDataApp.insrType,
1277
+ saleChanellPolicy: this.formStore.SaleChanellPolicy.ids,
1278
+ saleChanellPolicyName: this.formStore.SaleChanellPolicy.nameRu,
1279
+ regionPolicy: this.formStore.RegionPolicy.ids,
1280
+ regionPolicyName: this.formStore.RegionPolicy.nameRu,
1281
+ managerPolicy: this.formStore.ManagerPolicy.ids,
1282
+ managerPolicyName: this.formStore.ManagerPolicy.nameRu,
1283
+ insuranceProgramType: this.formStore.applicationData.insisWorkDataApp.insuranceProgramType,
1284
+ };
1285
+ try {
1286
+ this.isLoading = true;
1287
+ await this.api.setINSISWorkData(data);
1288
+ } catch (err) {
1289
+ console.log(err);
1290
+ } finally {
1291
+ this.isLoading = false;
1292
+ }
1293
+ },
1294
+ async filterManagerByRegion(dictName, filterName) {
1295
+ try {
1296
+ this.isLoading = true;
1297
+ this[`${dictName}List`] = await this.api.filterManagerByRegion(dictName, filterName);
1298
+ } catch (err) {
1299
+ console.log(err);
1300
+ } finally {
1301
+ this.isLoading = false;
1302
+ }
1303
+ },
1304
+ async getUnderwritingCouncilData(id) {
1305
+ try {
1306
+ const response = await this.api.getUnderwritingCouncilData(id);
1307
+ this.formStore.affilationResolution.id = response.underwritingCouncilAppDto.id;
1308
+ this.formStore.affilationResolution.date = response.underwritingCouncilAppDto.date ? reformatDate(response.underwritingCouncilAppDto.date) : null;
1309
+ this.formStore.affilationResolution.number = response.underwritingCouncilAppDto.number ? response.underwritingCouncilAppDto.number : null;
1310
+ } catch (err) {
1311
+ console.log(err);
1312
+ }
1313
+ },
1314
+ async setConfirmation() {
1315
+ const data = {
1316
+ id: this.formStore.affilationResolution.id,
1317
+ processInstanceId: this.formStore.affilationResolution.processInstanceId,
1318
+ number: this.formStore.affilationResolution.number,
1319
+ date: formatDate(this.formStore.affilationResolution.date)?.toISOString(),
1320
+ };
1321
+ try {
1322
+ this.isLoading = true;
1323
+ await this.api.setConfirmation(data);
1324
+ this.showToaster('success', this.t('toaster.successSaved'));
1325
+ return true;
1326
+ } catch (err) {
1327
+ this.showToaster('error', this.t('toaster.error'));
1328
+ return false;
1329
+ } finally {
1330
+ this.isLoading = false;
1331
+ }
1332
+ },
1333
+ async sendUnderwritingCouncilTask(data) {
1334
+ try {
1335
+ this.isLoading = true;
1336
+ await this.api.sendUnderwritingCouncilTask(data);
1337
+ this.showToaster('success', this.t('toaster.successOperation'), 5000);
1338
+ return true;
1339
+ } catch (err) {
1340
+ console.log(err);
1341
+ this.showToaster('error', this.t('toaster.error'), 5000);
1342
+ return false;
1343
+ } finally {
1344
+ this.isLoading = false;
1345
+ }
1346
+ },
1347
+ async definedAnswers(filter, whichSurvey, value = null, index = null) {
1348
+ if (!this.formStore.definedAnswersId[whichSurvey].hasOwnProperty(filter)) {
1349
+ this.formStore.definedAnswersId[whichSurvey][filter] = await this.api.definedAnswers(filter);
1350
+ }
1351
+ if (value !== null && this.formStore.definedAnswersId[whichSurvey][filter].length) {
1352
+ const answer = this.formStore.definedAnswersId[whichSurvey][filter].find(answer => answer.nameRu === value);
1353
+ this.formStore[whichSurvey].body[index].first.answerId = answer.ids;
1354
+ }
1355
+ return this.formStore.definedAnswersId[whichSurvey];
1356
+ },
1357
+ async getPaymentTable(id) {
1358
+ try {
1359
+ const paymentResultTable = await this.api.calculatePremuim(id);
1360
+ if (paymentResultTable.length > 0) {
1361
+ this.paymentResultTable = paymentResultTable;
1362
+ } else {
1363
+ this.paymentResultTable = [];
1364
+ }
1365
+ } catch (err) {
1366
+ console.log(err);
1367
+ }
1368
+ },
1369
+ async getDefaultCalculationData(showLoader = false) {
1370
+ this.isLoading = showLoader;
1371
+ try {
1372
+ const calculationData = await this.api.getDefaultCalculationData();
1373
+ return calculationData;
1374
+ } catch (err) {
1375
+ ErrorHandler(err);
1376
+ } finally {
1377
+ this.isLoading = false;
1378
+ }
1379
+ },
1380
+ async calculateWithoutApplication(showLoader = false) {
1381
+ this.isLoading = showLoader;
1382
+ try {
1383
+ const calculationData = {
1384
+ signDate: formatDate(this.formStore.productConditionsForm.signDate)?.toISOString(),
1385
+ birthDate: formatDate(this.formStore.productConditionsForm.birthDate)?.toISOString(),
1386
+ gender: this.formStore.productConditionsForm.gender.id,
1387
+ amount: getNumber(this.formStore.productConditionsForm.requestedSumInsured),
1388
+ premium: getNumber(this.formStore.productConditionsForm.insurancePremiumPerMonth),
1389
+ coverPeriod: this.formStore.productConditionsForm.coverPeriod,
1390
+ payPeriod: this.formStore.productConditionsForm.coverPeriod,
1391
+ indexRateId: this.formStore.productConditionsForm.processIndexRate?.id
1392
+ ? this.formStore.productConditionsForm.processIndexRate.id
1393
+ : this.processIndexRate.find(i => i.code === '0')?.id,
1394
+ paymentPeriodId: this.formStore.productConditionsForm.paymentPeriod.id,
1395
+ addCovers: this.formStore.additionalInsuranceTermsWithout,
1396
+ };
1397
+ const calculationResponse = await this.api.calculateWithoutApplication(calculationData);
1398
+ this.formStore.productConditionsForm.requestedSumInsured = this.getNumberWithSpaces(calculationResponse.amount);
1399
+ this.formStore.productConditionsForm.insurancePremiumPerMonth = this.getNumberWithSpaces(calculationResponse.premium);
1400
+ this.formStore.additionalInsuranceTermsWithout = calculationResponse.addCovers;
1401
+ this.showToaster('success', this.t('toaster.calculated'), 1000);
1402
+ } catch (err) {
1403
+ ErrorHandler(err);
1404
+ } finally {
1405
+ this.isLoading = false;
1406
+ return !!this.formStore.productConditionsForm.requestedSumInsured && !!this.formStore.productConditionsForm.insurancePremiumPerMonth;
1407
+ }
1408
+ },
1409
+ async calculate(taskId) {
1410
+ this.isLoading = true;
1411
+ try {
1412
+ let form1 = {
1413
+ baiterekApp: null,
1414
+ policyAppDto: {
1415
+ id: this.formStore.applicationData.policyAppDto.id,
1416
+ processInstanceId: this.formStore.applicationData.policyAppDto.processInstanceId,
1417
+ policyId: null,
1418
+ policyNumber: null,
1419
+ contractDate: this.currentDate(),
1420
+ amount: this.formStore.productConditionsForm.requestedSumInsured != null ? Number(this.formStore.productConditionsForm.requestedSumInsured.replace(/\s/g, '')) : null,
1421
+ premium:
1422
+ this.formStore.productConditionsForm.insurancePremiumPerMonth != null
1423
+ ? Number(this.formStore.productConditionsForm.insurancePremiumPerMonth.replace(/\s/g, ''))
1424
+ : null,
1425
+ isSpokesman: this.formStore.hasRepresentative,
1426
+ coverPeriod: this.formStore.productConditionsForm.coverPeriod,
1427
+ payPeriod: this.formStore.productConditionsForm.coverPeriod,
1428
+ annualIncome: this.formStore.productConditionsForm.annualIncome ? Number(this.formStore.productConditionsForm.annualIncome.replace(/\s/g, '')) : null,
1429
+ indexRateId: this.formStore.productConditionsForm.processIndexRate?.id
1430
+ ? this.formStore.productConditionsForm.processIndexRate.id
1431
+ : this.processIndexRate.find(i => i.code === '0')?.id,
1432
+ paymentPeriodId: this.formStore.productConditionsForm.paymentPeriod.id,
1433
+ lifeMultiply: formatProcents(this.formStore.productConditionsForm.lifeMultiply),
1434
+ lifeAdditive: formatProcents(this.formStore.productConditionsForm.lifeAdditive),
1435
+ adbMultiply: formatProcents(this.formStore.productConditionsForm.adbMultiply),
1436
+ adbAdditive: formatProcents(this.formStore.productConditionsForm.adbAdditive),
1437
+ disabilityMultiply: formatProcents(this.formStore.productConditionsForm.disabilityMultiply),
1438
+ disabilityAdditive: formatProcents(this.formStore.productConditionsForm.adbAdditive),
1439
+ riskGroup: this.formStore.productConditionsForm.riskGroup?.id ? this.formStore.productConditionsForm.riskGroup.id : 1,
1440
+ },
1441
+ addCoversDto: this.formStore.additionalInsuranceTerms,
1442
+ };
1443
+
1444
+ try {
1445
+ let id = this.formStore.applicationData.processInstanceId;
1446
+
1447
+ await this.api.setApplication(form1);
1448
+ let result;
1449
+ try {
1450
+ result = await this.api.getCalculation(id);
1451
+ } catch (err) {
1452
+ ErrorHandler(err);
1453
+ }
1454
+
1455
+ const applicationData = await this.api.getApplicationData(taskId);
1456
+ this.formStore.applicationData = applicationData;
1457
+ this.formStore.additionalInsuranceTerms = this.formStore.applicationData.addCoverDto;
1458
+ if (this.formStore.productConditionsForm.insurancePremiumPerMonth != null) {
1459
+ this.formStore.productConditionsForm.requestedSumInsured = this.getNumberWithSpaces(result);
1460
+ } else {
1461
+ this.formStore.productConditionsForm.insurancePremiumPerMonth = this.getNumberWithSpaces(result);
1462
+ }
1463
+ this.showToaster('success', this.t('toaster.calculated'), 1000);
1464
+ } catch (err) {
1465
+ ErrorHandler(err);
1466
+ }
1467
+ } catch (err) {
1468
+ ErrorHandler(err);
1469
+ }
1470
+ this.isLoading = false;
1471
+ },
1472
+ async startApplication(member) {
1473
+ try {
1474
+ const data = {
1475
+ clientId: member.id,
1476
+ iin: member.iin.replace(/-/g, ''),
1477
+ longName: member.longName,
1478
+ processCode: this.processCode,
1479
+ policyId: 0,
1480
+ };
1481
+ const response = await this.api.startApplication(data);
1482
+ this.sendToParent(constants.postActions.applicationCreated, response.processInstanceId);
1483
+ return response.processInstanceId;
1484
+ } catch (err) {
1485
+ return ErrorHandler(err);
1486
+ }
1487
+ },
1488
+ async getApplicationData(taskId, onlyGet = true, setMembersField = true, fetchMembers = true, setProductConditions = true) {
1489
+ if (onlyGet) {
1490
+ this.isLoading = true;
1491
+ }
1492
+ try {
1493
+ const applicationData = await this.api.getApplicationData(taskId);
1494
+ if (this.processCode !== applicationData.processCode) {
1495
+ this.isLoading = false;
1496
+ this.sendToParent(constants.postActions.toHomePage, this.t('toaster.noSuchProduct'));
1497
+ return;
1498
+ }
1499
+ this.formStore.applicationData = applicationData;
1500
+ this.formStore.additionalInsuranceTerms = applicationData.addCoverDto;
1501
+
1502
+ this.formStore.canBeClaimed = await this.api.isClaimTask(taskId);
1503
+ this.formStore.applicationTaskId = taskId;
1504
+ this.formStore.RegionPolicy.nameRu = applicationData.insisWorkDataApp.regionPolicyName;
1505
+ this.formStore.RegionPolicy.ids = applicationData.insisWorkDataApp.regionPolicy;
1506
+ this.formStore.ManagerPolicy.nameRu = applicationData.insisWorkDataApp.managerPolicyName;
1507
+ this.formStore.ManagerPolicy.ids = applicationData.insisWorkDataApp.managerPolicy;
1508
+ this.formStore.SaleChanellPolicy.nameRu = applicationData.insisWorkDataApp.saleChanellPolicyName;
1509
+ this.formStore.SaleChanellPolicy.ids = applicationData.insisWorkDataApp.saleChanellPolicy;
1510
+
1511
+ this.formStore.AgentData.fullName = applicationData.insisWorkDataApp.agentName;
1512
+ this.formStore.AgentData.agentId = applicationData.insisWorkDataApp.agentId;
1513
+
1514
+ const clientData = applicationData.clientApp;
1515
+ const insuredData = applicationData.insuredApp;
1516
+ const spokesmanData = applicationData.spokesmanApp;
1517
+ const beneficiaryData = applicationData.beneficiaryApp;
1518
+ const beneficialOwnerData = applicationData.beneficialOwnerApp;
1519
+
1520
+ this.formStore.isPolicyholderInsured = clientData.isInsured;
1521
+ this.formStore.isActOwnBehalf = clientData.isActOwnBehalf;
1522
+ this.formStore.hasRepresentative = !!applicationData.spokesmanApp;
1523
+
1524
+ const beneficiaryPolicyholderIndex = beneficiaryData.findIndex(i => i.insisId === clientData.insisId);
1525
+ this.formStore.isPolicyholderBeneficiary = beneficiaryPolicyholderIndex !== -1;
1526
+
1527
+ if (fetchMembers) {
1528
+ let allMembers = [
1529
+ {
1530
+ ...clientData,
1531
+ key: this.formStore.policyholderFormKey,
1532
+ index: null,
1533
+ },
1534
+ ];
1535
+
1536
+ if (spokesmanData) {
1537
+ allMembers.push({
1538
+ ...spokesmanData,
1539
+ key: this.formStore.policyholdersRepresentativeFormKey,
1540
+ index: null,
1541
+ });
1542
+ }
1543
+
1544
+ if (insuredData && insuredData.length) {
1545
+ insuredData.forEach((member, index) => {
1546
+ const inStore = this.formStore.insuredForm.find(each => each.id == member.insisId);
1547
+ if (!inStore) {
1548
+ member.key = this.formStore.insuredFormKey;
1549
+ member.index = index;
1550
+ allMembers.push(member);
1551
+ if (this.formStore.insuredForm.length - 1 < index) {
1552
+ this.formStore.insuredForm.push(new InsuredForm());
1553
+ }
1554
+ }
1555
+ });
1556
+ }
1557
+ if (beneficiaryData && beneficiaryData.length) {
1558
+ beneficiaryData.forEach((member, index) => {
1559
+ const inStore = this.formStore.beneficiaryForm.find(each => each.id == member.insisId);
1560
+ if (!inStore) {
1561
+ member.key = this.formStore.beneficiaryFormKey;
1562
+ member.index = index;
1563
+ allMembers.push(member);
1564
+ if (this.formStore.beneficiaryForm.length - 1 < index) {
1565
+ this.formStore.beneficiaryForm.push(new BeneficiaryForm());
1566
+ }
1567
+ }
1568
+ });
1569
+ }
1570
+ if (beneficialOwnerData && beneficialOwnerData.length) {
1571
+ beneficialOwnerData.forEach((member, index) => {
1572
+ const inStore = this.formStore.beneficialOwnerForm.find(each => each.id == member.insisId);
1573
+ if (!inStore) {
1574
+ member.key = this.formStore.beneficialOwnerFormKey;
1575
+ member.index = index;
1576
+ allMembers.push(member);
1577
+ if (this.formStore.beneficialOwnerForm.length - 1 < index) {
1578
+ this.formStore.beneficialOwnerForm.push(new BeneficialOwnerForm());
1579
+ }
1580
+ }
1581
+ });
1582
+ }
1583
+
1584
+ await Promise.allSettled(
1585
+ allMembers.map(async member => {
1586
+ await this.getContragentById(member.insisId, member.key, false, member.index);
1587
+ }),
1588
+ );
1589
+ }
1590
+
1591
+ if (setMembersField) {
1592
+ this.setMembersField(this.formStore.policyholderFormKey, 'clientApp');
1593
+ if (insuredData && insuredData.length) {
1594
+ insuredData.forEach((each, index) => {
1595
+ this.setMembersFieldIndex(this.formStore.insuredFormKey, 'insuredApp', index);
1596
+ });
1597
+ }
1598
+
1599
+ if (beneficiaryData && beneficiaryData.length) {
1600
+ beneficiaryData.forEach((each, index) => {
1601
+ this.setMembersFieldIndex(this.formStore.beneficiaryFormKey, 'beneficiaryApp', index);
1602
+ const relationDegree = this.relations.find(i => i.ids == each.relationId);
1603
+ this.formStore.beneficiaryForm[index].relationDegree = relationDegree ? relationDegree : new Value();
1604
+ this.formStore.beneficiaryForm[index].percentageOfPayoutAmount = each.percentage;
1605
+ });
1606
+ }
1607
+
1608
+ if (beneficialOwnerData && beneficialOwnerData.length) {
1609
+ beneficialOwnerData.forEach((each, index) => {
1610
+ this.setMembersFieldIndex(this.formStore.beneficialOwnerFormKey, 'beneficialOwnerApp', index);
1611
+ });
1612
+ }
1613
+
1614
+ if (!!spokesmanData) {
1615
+ this.formStore.policyholdersRepresentativeForm.signOfIPDL = spokesmanData.isIpdl ? this.ipdl[1] : this.ipdl[2];
1616
+ this.formStore.policyholdersRepresentativeForm.migrationCard = spokesmanData.migrationCard;
1617
+ this.formStore.policyholdersRepresentativeForm.migrationCardIssueDate = reformatDate(spokesmanData.migrationCardIssueDate);
1618
+ this.formStore.policyholdersRepresentativeForm.migrationCardExpireDate = reformatDate(spokesmanData.migrationCardExpireDate);
1619
+ this.formStore.policyholdersRepresentativeForm.confirmDocType = spokesmanData.confirmDocType;
1620
+ this.formStore.policyholdersRepresentativeForm.confirmDocNumber = spokesmanData.confirmDocNumber;
1621
+ this.formStore.policyholdersRepresentativeForm.confirmDocIssueDate = reformatDate(spokesmanData.confirmDocIssueDate);
1622
+ this.formStore.policyholdersRepresentativeForm.confirmDocExpireDate = reformatDate(spokesmanData.confirmDocExpireDate);
1623
+ this.formStore.policyholdersRepresentativeForm.notaryLongName = spokesmanData.notaryLongName;
1624
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseNumber = spokesmanData.notaryLicenseNumber;
1625
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseDate = reformatDate(spokesmanData.notaryLicenseDate);
1626
+ this.formStore.policyholdersRepresentativeForm.notaryLicenseIssuer = spokesmanData.notaryLicenseIssuer;
1627
+ this.formStore.policyholdersRepresentativeForm.jurLongName = spokesmanData.jurLongName;
1628
+ this.formStore.policyholdersRepresentativeForm.fullNameRod = spokesmanData.fullNameRod;
1629
+ this.formStore.policyholdersRepresentativeForm.confirmDocTypeKz = spokesmanData.confirmDocTypeKz;
1630
+ this.formStore.policyholdersRepresentativeForm.confirmDocTypeRod = spokesmanData.confirmDocTypeRod;
1631
+ this.formStore.policyholdersRepresentativeForm.isNotary = spokesmanData.isNotary;
1632
+ }
1633
+ }
1634
+ if (setProductConditions) {
1635
+ this.formStore.productConditionsForm.coverPeriod = applicationData.policyAppDto.coverPeriod;
1636
+ this.formStore.productConditionsForm.payPeriod = applicationData.policyAppDto.payPeriod;
1637
+ // this.formStore.productConditionsForm.annualIncome = applicationData.policyAppDto.annualIncome?.toString();
1638
+ this.formStore.productConditionsForm.lifeMultiply = parseProcents(applicationData.policyAppDto.lifeMultiply);
1639
+ this.formStore.productConditionsForm.lifeAdditive = parseProcents(applicationData.policyAppDto.lifeAdditive);
1640
+ this.formStore.productConditionsForm.adbMultiply = parseProcents(applicationData.policyAppDto.adbMultiply);
1641
+ this.formStore.productConditionsForm.adbAdditive = parseProcents(applicationData.policyAppDto.adbAdditive);
1642
+ this.formStore.productConditionsForm.disabilityMultiply = parseProcents(applicationData.policyAppDto.disabilityMultiply);
1643
+ this.formStore.productConditionsForm.disabilityAdditive = parseProcents(applicationData.policyAppDto.disabilityAdditive);
1644
+
1645
+ let processIndexRate = this.processIndexRate.find(item => item.id == applicationData.policyAppDto.indexRateId);
1646
+ this.formStore.productConditionsForm.processIndexRate = processIndexRate ? processIndexRate : this.processIndexRate.find(item => item.code === '0');
1647
+
1648
+ let paymentPeriod = this.processPaymentPeriod.find(item => item.id == applicationData.policyAppDto.paymentPeriodId);
1649
+ this.formStore.productConditionsForm.paymentPeriod = paymentPeriod ? paymentPeriod : new Value();
1650
+
1651
+ this.formStore.productConditionsForm.requestedSumInsured = this.getNumberWithSpaces(
1652
+ applicationData.policyAppDto.amount === null ? null : applicationData.policyAppDto.amount,
1653
+ );
1654
+ this.formStore.productConditionsForm.insurancePremiumPerMonth = this.getNumberWithSpaces(
1655
+ applicationData.policyAppDto.premium === null ? null : applicationData.policyAppDto.premium,
1656
+ );
1657
+
1658
+ let riskGroup = this.riskGroup.find(item => {
1659
+ if (applicationData.policyAppDto.riskGroup == 0) {
1660
+ return true;
1661
+ }
1662
+ return item.id == applicationData.policyAppDto.riskGroup;
1663
+ });
1664
+ this.formStore.productConditionsForm.riskGroup = riskGroup ? riskGroup : this.riskGroup.find(item => item.id == 1);
1665
+ }
1666
+ } catch (err) {
1667
+ console.log(err);
1668
+ if ('response' in err) {
1669
+ this.sendToParent(constants.postActions.toHomePage, err.response.data);
1670
+ this.isLoading = false;
1671
+ return false;
1672
+ }
1673
+ }
1674
+ if (onlyGet) {
1675
+ this.isLoading = false;
1676
+ }
1677
+ },
1678
+ async setApplication() {
1679
+ try {
1680
+ await this.api.setApplication(this.formStore.applicationData);
1681
+ } catch (err) {
1682
+ console.log(err);
1683
+ }
1684
+ },
1685
+ async deleteTask(taskId) {
1686
+ this.isLoading = true;
1687
+ try {
1688
+ const data = {
1689
+ taskId: taskId,
1690
+ decision: 'rejectclient',
1691
+ comment: 'Клиент отказался',
1692
+ };
1693
+ await this.api.sendTask(data);
1694
+ this.showToaster('success', this.t('toaster.applicationDeleted'), 2000);
1695
+ } catch (err) {
1696
+ this.isLoading = false;
1697
+ return ErrorHandler(err);
1698
+ }
1699
+ this.isLoading = false;
1700
+ },
1701
+ async sendTask(taskId, decision, comment = null) {
1702
+ this.isLoading = true;
1703
+ try {
1704
+ const data = {
1705
+ taskId: taskId,
1706
+ decision: decision,
1707
+ };
1708
+ await this.api.sendTask(comment === null ? data : { ...data, comment: comment });
1709
+ this.showToaster('success', this.t('toaster.successOperation'), 3000);
1710
+ this.isLoading = false;
1711
+ return true;
1712
+ } catch (err) {
1713
+ this.isLoading = false;
1714
+ return ErrorHandler(err);
1715
+ }
1716
+ },
1717
+ async handleTask(action, taskId, comment) {
1718
+ if (action && Object.keys(constants.actions).includes(action)) {
1719
+ switch (action) {
1720
+ case constants.actions.claim: {
1721
+ try {
1722
+ this.isLoading = true;
1723
+ await this.api.claimTask(this.formStore.applicationTaskId);
1724
+ await this.getApplicationData(taskId, false, false, false);
1725
+ this.showToaster('success', this.t('toaster.successOperation'), 3000);
1726
+ } catch (err) {
1727
+ ErrorHandler(err);
1728
+ }
1729
+ }
1730
+ case constants.actions.reject:
1731
+ case constants.actions.return:
1732
+ case constants.actions.rejectclient:
1733
+ case constants.actions.accept: {
1734
+ try {
1735
+ const sended = await this.sendTask(taskId, action, comment);
1736
+ if (!sended) return;
1737
+ this.formStore.$reset();
1738
+ if (this.isEFO) {
1739
+ await this.router.push({ name: 'Insurance-Product' });
1740
+ } else {
1741
+ this.sendToParent(constants.postActions.toHomePage, this.t('toaster.successOperation') + 'SUCCESS');
1742
+ }
1743
+ } catch (err) {
1744
+ ErrorHandler(err);
1745
+ }
1746
+ }
1747
+ }
1748
+ } else {
1749
+ console.error('No handleTask action');
1750
+ }
1751
+ },
1752
+ async getInvoiceData(processInstanceId) {
1753
+ try {
1754
+ const response = await this.api.getInvoiceData(processInstanceId);
1755
+ if (response) {
1756
+ return response;
1757
+ } else {
1758
+ return false;
1759
+ }
1760
+ } catch (err) {
1761
+ return false;
1762
+ }
1763
+ },
1764
+ async createInvoice() {
1765
+ try {
1766
+ const created = await this.api.createInvoice(this.formStore.applicationData.processInstanceId, this.formStore.applicationData.policyAppDto.premium);
1767
+ return !!created;
1768
+ } catch (err) {
1769
+ this.isLoading = false;
1770
+ }
1771
+ },
1772
+ async sendToEpay() {
1773
+ try {
1774
+ const response = await this.api.sendToEpay(this.formStore.applicationData.processInstanceId);
1775
+ if (response) {
1776
+ return response;
1777
+ }
1778
+ } catch (err) {
1779
+ console.log(err);
1780
+ }
1781
+ },
1782
+ setMembersField(whichForm, whichMember) {
1783
+ this.formStore[whichForm].familyStatus = this.findObject('familyStatuses', 'id', this.formStore.applicationData[whichMember].familyStatusId);
1784
+ this.formStore[whichForm].signOfIPDL = this.findObject(
1785
+ 'ipdl',
1786
+ 'nameRu',
1787
+ this.formStore.applicationData[whichMember].isIpdl === null ? null : this.formStore.applicationData[whichMember].isIpdl == true ? 'Да' : 'Нет',
1788
+ );
1789
+ if (!!this.formStore.applicationData[whichMember].profession) this.formStore[whichForm].job = this.formStore.applicationData[whichMember].profession;
1790
+ if (!!this.formStore.applicationData[whichMember].position) this.formStore[whichForm].jobPosition = this.formStore.applicationData[whichMember].position;
1791
+ if (!!this.formStore.applicationData[whichMember].jobName) this.formStore[whichForm].jobPlace = this.formStore.applicationData[whichMember].jobName;
1792
+ },
1793
+ setMembersFieldIndex(whichForm, whichMember, index) {
1794
+ if ('familyStatus' in this.formStore[whichForm][index]) {
1795
+ this.formStore[whichForm][index].familyStatus = this.findObject('familyStatuses', 'id', this.formStore.applicationData[whichMember][index].familyStatusId);
1796
+ }
1797
+ if ('signOfIPDL' in this.formStore[whichForm][index]) {
1798
+ this.formStore[whichForm][index].signOfIPDL = this.findObject(
1799
+ 'ipdl',
1800
+ 'nameRu',
1801
+ this.formStore.applicationData[whichMember][index].isIpdl === null ? null : this.formStore.applicationData[whichMember][index].isIpdl == true ? 'Да' : 'Нет',
1802
+ );
1803
+ }
1804
+ if ('job' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].profession) {
1805
+ this.formStore[whichForm][index].job = this.formStore.applicationData[whichMember][index].profession;
1806
+ }
1807
+ if ('jobPosition' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].position) {
1808
+ this.formStore[whichForm][index].jobPosition = this.formStore.applicationData[whichMember][index].position;
1809
+ }
1810
+ if ('jobPlace' in this.formStore[whichForm][index] && !!this.formStore.applicationData[whichMember][index].jobName) {
1811
+ this.formStore[whichForm][index].jobPlace = this.formStore.applicationData[whichMember][index].jobName;
1812
+ }
1813
+ },
1814
+ findObject(from, key, searchKey) {
1815
+ const found = this[from].find(i => i[key] == searchKey);
1816
+ return found || new Value();
1817
+ },
1818
+ async signDocument() {
1819
+ try {
1820
+ if (this.formStore.signUrls.length) {
1821
+ return this.formStore.signUrls;
1822
+ }
1823
+ const data = [
1824
+ { processInstanceId: this.formStore.applicationData.processInstanceId, name: 'Agreement', format: 'pdf' },
1825
+ { processInstanceId: this.formStore.applicationData.processInstanceId, name: 'Statement', format: 'pdf' },
1826
+ ];
1827
+ const result = await this.api.signDocument(data);
1828
+ this.formStore.signUrls = result;
1829
+ return this.formStore.signUrls;
1830
+ } catch (err) {
1831
+ ErrorHandler(err);
1832
+ }
1833
+ },
1834
+ async sendSMS(type, phoneNumber, text) {
1835
+ if (!type || !phoneNumber || !text) return;
1836
+ const smsData = {
1837
+ iin: this.formStore.applicationData.clientApp.iin,
1838
+ phoneNumber: formatPhone(phoneNumber),
1839
+ processInstanceId: this.formStore.applicationData.processInstanceId,
1840
+ text: text,
1841
+ type: type,
1842
+ };
1843
+ try {
1844
+ this.isLoading = true;
1845
+ await this.api.sendSms(smsData);
1846
+ this.showToaster('success', this.t('toaster.smsSendSuccessfully'), 3000);
1847
+ } catch (err) {
1848
+ ErrorHandler(err);
1849
+ } finally {
1850
+ this.isLoading = false;
1851
+ }
1852
+ },
1853
+ sanitize(text) {
1854
+ if (text) {
1855
+ return text
1856
+ .replace(/\r?\n|\r/g, '')
1857
+ .replace(/\\/g, '')
1858
+ .replace(/"/g, '');
1859
+ }
1860
+ },
1861
+ async getSignedDocList(processInstanceId) {
1862
+ if (processInstanceId !== 0) {
1863
+ try {
1864
+ this.formStore.signedDocumentList = await this.api.getSignedDocList({
1865
+ processInstanceId: processInstanceId,
1866
+ });
1867
+ } catch (err) {
1868
+ console.log(err);
1869
+ }
1870
+ }
1871
+ },
1872
+ setFormsDisabled(isDisabled) {
1873
+ Object.keys(this.formStore.isDisabled).forEach(key => {
1874
+ this.formStore.isDisabled[key] = !!isDisabled;
1875
+ });
1876
+ },
1877
+ async reCalculate(processInstanceId, recalculationData, taskId, whichSum) {
1878
+ this.isLoading = true;
1879
+ try {
1880
+ const data = {
1881
+ processInstanceId: processInstanceId,
1882
+ ...recalculationData,
1883
+ };
1884
+ const recalculatedValue = await this.api.reCalculate(data);
1885
+ if (!!recalculatedValue) {
1886
+ await this.getApplicationData(taskId, false, false, false);
1887
+ this.showToaster(
1888
+ 'success',
1889
+ `${this.t('toaster.successRecalculation')}. ${whichSum == 'insurancePremiumPerMonth' ? 'Страховая премия' : 'Страховая сумма'}: ${this.getNumberWithSpaces(
1890
+ recalculatedValue,
1891
+ )}₸`,
1892
+ 4000,
1893
+ );
1894
+ }
1895
+ } catch (err) {
1896
+ ErrorHandler(err);
1897
+ }
1898
+ this.isLoading = false;
1899
+ },
1900
+ async getValidateClientESBD(data) {
1901
+ try {
1902
+ return await this.api.getValidateClientESBD(data);
1903
+ } catch (err) {
1904
+ this.isLoading = false;
1905
+ return ErrorHandler(err);
1906
+ }
1907
+ },
1908
+ validateMultipleMembers(localKey, applicationKey, text) {
1909
+ if (this.formStore[localKey].length === this.formStore.applicationData[applicationKey].length) {
1910
+ if (this.formStore[localKey].length !== 0 && this.formStore.applicationData[applicationKey].length !== 0) {
1911
+ const localMembers = [...this.formStore[localKey]].sort((a, b) => a.id - b.id);
1912
+ const applicationMembers = [...this.formStore.applicationData[applicationKey]].sort((a, b) => a.insisId - b.insisId);
1913
+ if (localMembers.every((each, index) => applicationMembers[index].insisId === each.id && applicationMembers[index].iin === each.iin.replace(/-/g, '')) === false) {
1914
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', text), 3000);
1915
+ return false;
1916
+ }
1917
+ if (localKey === this.formStore.beneficiaryFormKey) {
1918
+ const sumOfPercentage = localMembers.reduce((sum, member) => {
1919
+ return sum + Number(member.percentageOfPayoutAmount);
1920
+ }, 0);
1921
+ if (sumOfPercentage !== 100) {
1922
+ this.showToaster('error', this.t('toaster.errorSumOrPercentage'), 3000);
1923
+ return false;
1924
+ }
1925
+ }
1926
+ }
1927
+ } else {
1928
+ if (this.formStore[localKey].some(i => i.iin !== null)) {
1929
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', text), 3000);
1930
+ return false;
1931
+ }
1932
+ if (this.formStore.applicationData[applicationKey].length !== 0) {
1933
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', text), 3000);
1934
+ return false;
1935
+ } else {
1936
+ if (this.formStore[localKey][0].iin !== null) {
1937
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', text), 3000);
1938
+ return false;
1939
+ }
1940
+ }
1941
+ }
1942
+ return true;
1943
+ },
1944
+ async validateAllMembers(taskId, localCheck = false) {
1945
+ if (taskId === '0') {
1946
+ this.showToaster('error', this.t('toaster.needToRunStatement'), 2000);
1947
+ return false;
1948
+ }
1949
+ if (this.formStore.policyholderForm.id !== this.formStore.applicationData.clientApp.insisId) {
1950
+ this.showToaster('error', this.t('toaster.notSavedMember').replace('{text}', 'страхователя'), 3000);
1951
+ return false;
1952
+ }
1953
+ if (!this.isGons) {
1954
+ if (this.validateMultipleMembers(this.formStore.insuredFormKey, 'insuredApp', 'застрахованных') === false) {
1955
+ return false;
1956
+ }
1957
+ }
1958
+ if (this.validateMultipleMembers(this.formStore.beneficiaryFormKey, 'beneficiaryApp', 'выгодоприобретателей') === false) {
1959
+ return false;
1960
+ }
1961
+ if (!this.isGons) {
1962
+ if (this.formStore.isActOwnBehalf === false) {
1963
+ if (this.validateMultipleMembers(this.formStore.beneficialOwnerFormKey, 'beneficialOwnerApp', 'бенефициарных собственников') === false) {
1964
+ return false;
1965
+ }
1966
+ }
1967
+ }
1968
+ if (!this.isGons) {
1969
+ if (this.formStore.hasRepresentative) {
1970
+ if (this.formStore.applicationData.spokesmanApp && this.formStore.policyholdersRepresentativeForm.id !== this.formStore.applicationData.spokesmanApp.insisId) {
1971
+ this.showToaster(
1972
+ 'error',
1973
+ this.t('toaster.notSavedMember', {
1974
+ text: 'представителя страхователя',
1975
+ }),
1976
+ 3000,
1977
+ );
1978
+ return false;
1979
+ }
1980
+ }
1981
+ }
1982
+ if (!this.isGons) {
1983
+ const areValid = this.formStore.SaleChanellPolicy.nameRu && this.formStore.RegionPolicy.nameRu && this.formStore.ManagerPolicy.nameRu && this.formStore.AgentData.fullName;
1984
+ if (areValid) {
1985
+ await this.setINSISWorkData();
1986
+ } else {
1987
+ this.isLoading = false;
1988
+ this.showToaster('error', this.t('toaster.attachManagerError'), 3000);
1989
+ return false;
1990
+ }
1991
+ }
1992
+ if (localCheck === false) {
1993
+ try {
1994
+ if (!this.isGons) {
1995
+ if (this.formStore.isActOwnBehalf === true && this.formStore.applicationData.beneficialOwnerApp.length !== 0) {
1996
+ await Promise.allSettled(
1997
+ this.formStore.applicationData.beneficialOwnerApp.map(async member => {
1998
+ await this.api.deleteMember('BeneficialOwner', member.id);
1999
+ }),
2000
+ );
2001
+ }
2002
+ }
2003
+ await this.getApplicationData(taskId, false);
2004
+ } catch (err) {
2005
+ console.log(err);
2006
+ this.showToaster('error', err, 5000);
2007
+ return false;
2008
+ }
2009
+ }
2010
+
2011
+ return true;
2012
+ },
2013
+ validateAnketa(whichSurvey) {
2014
+ const list = this.formStore[whichSurvey].body;
2015
+ if (!list || (list && list.length === 0)) return false;
2016
+ let notAnswered = 0;
2017
+ for (let x = 0; x < list.length; x++) {
2018
+ if ((list[x].first.definedAnswers === 'N' && !list[x].first.answerText) || (list[x].first.definedAnswers === 'Y' && !list[x].first.answerName)) {
2019
+ notAnswered = notAnswered + 1;
2020
+ }
2021
+ }
2022
+ return notAnswered === 0;
2023
+ },
2024
+ async validateAllForms(taskId) {
2025
+ this.isLoading = true;
2026
+ const areMembersValid = await this.validateAllMembers(taskId);
2027
+ if (areMembersValid) {
2028
+ if (!!this.formStore.productConditionsForm.insurancePremiumPerMonth && !!this.formStore.productConditionsForm.requestedSumInsured) {
2029
+ const hasCritical = this.formStore.additionalInsuranceTerms?.find(cover => cover.coverTypeName === 'Критическое заболевание Застрахованного');
2030
+ if (hasCritical && hasCritical.coverSumName !== 'не включено') {
2031
+ await Promise.allSettled([
2032
+ this.getQuestionList(
2033
+ 'health',
2034
+ this.formStore.applicationData.processInstanceId,
2035
+ this.formStore.applicationData.insuredApp[0].id,
2036
+ 'surveyByHealthBase',
2037
+ 'surveyByHealthSecond',
2038
+ ),
2039
+ this.getQuestionList(
2040
+ 'critical',
2041
+ this.formStore.applicationData.processInstanceId,
2042
+ this.formStore.applicationData.insuredApp[0].id,
2043
+ 'surveyByCriticalBase',
2044
+ 'surveyByCriticalSecond',
2045
+ ),
2046
+ ]);
2047
+ await Promise.allSettled([
2048
+ ...this.formStore.surveyByHealthBase.body.map(async question => {
2049
+ await this.definedAnswers(question.first.id, 'surveyByHealthBase');
2050
+ }),
2051
+ ...this.formStore.surveyByCriticalBase.body.map(async question => {
2052
+ await this.definedAnswers(question.first.id, 'surveyByCriticalBase');
2053
+ }),
2054
+ ]);
2055
+ } else {
2056
+ await Promise.allSettled([
2057
+ this.getQuestionList(
2058
+ 'health',
2059
+ this.formStore.applicationData.processInstanceId,
2060
+ this.formStore.applicationData.insuredApp[0].id,
2061
+ 'surveyByHealthBase',
2062
+ 'surveyByHealthSecond',
2063
+ ),
2064
+ ]);
2065
+ await Promise.allSettled(
2066
+ this.formStore.surveyByHealthBase.body.map(async question => {
2067
+ await this.definedAnswers(question.first.id, 'surveyByHealthBase');
2068
+ }),
2069
+ );
2070
+ }
2071
+
2072
+ if (this.validateAnketa('surveyByHealthBase')) {
2073
+ let hasCriticalAndItsValid = null;
2074
+ if (hasCritical && hasCritical.coverSumName !== 'не включено') {
2075
+ if (this.validateAnketa('surveyByCriticalBase')) {
2076
+ hasCriticalAndItsValid = true;
2077
+ } else {
2078
+ hasCriticalAndItsValid = false;
2079
+ this.showToaster('error', this.t('toaster.emptyCriticalAnketa'), 3000);
2080
+ }
2081
+ } else {
2082
+ hasCriticalAndItsValid = null;
2083
+ }
2084
+ if (hasCriticalAndItsValid === true || hasCriticalAndItsValid === null) {
2085
+ this.isLoading = false;
2086
+ return true;
2087
+ }
2088
+ } else {
2089
+ this.showToaster('error', this.t('toaster.emptyHealthAnketa'), 3000);
2090
+ }
2091
+ } else {
2092
+ this.showToaster('error', this.t('toaster.emptyProductConditions'), 3000);
2093
+ }
2094
+ return false;
2095
+ }
2096
+ this.isLoading = false;
2097
+ return false;
2098
+ },
2099
+ async getFamilyInfo(iin, phoneNumber) {
2100
+ this.isLoading = true;
2101
+ try {
2102
+ const familyResponse = await this.api.getFamilyInfo({ iin: iin.replace(/-/g, ''), phoneNumber: formatPhone(phoneNumber) });
2103
+ if (familyResponse.status === 'soap:Server') {
2104
+ this.showToaster('error', `${familyResponse.statusName}. Отправьте запрос через некоторое время`, 5000);
2105
+ this.isLoading = false;
2106
+ return;
2107
+ }
2108
+ if (familyResponse.status === 'PENDING') {
2109
+ this.showToaster('success', this.t('toaster.waitForClient'), 5000);
2110
+ this.isLoading = false;
2111
+ return;
2112
+ }
2113
+ if (constants.gbdErrors.find(i => i === familyResponse.status)) {
2114
+ if (familyResponse.status === 'TIMEOUT') {
2115
+ this.showToaster('success', `${familyResponse.statusName}. Отправьте запрос еще раз`, 5000);
2116
+ } else {
2117
+ this.showToaster('error', familyResponse.statusName, 5000);
2118
+ }
2119
+ this.isLoading = false;
2120
+ return;
2121
+ }
2122
+ if (familyResponse.infoList && familyResponse.infoList.birthInfos && familyResponse.infoList.birthInfos.length) {
2123
+ const filteredBirthInfos = familyResponse.infoList.birthInfos.filter(member => {
2124
+ const filterAge = (() => {
2125
+ if (this.isBolashak) return 15;
2126
+ })();
2127
+ const baseCondition = !!member.childBirthDate && typeof member.childLifeStatus === 'number' && member.childLifeStatus === 0;
2128
+ return typeof filterAge === 'number' ? baseCondition && getAgeByBirthDate(member.childBirthDate) <= filterAge : baseCondition;
2129
+ });
2130
+ if (filteredBirthInfos && filteredBirthInfos.length) {
2131
+ this.formStore.birthInfos = filteredBirthInfos;
2132
+ this.showToaster('success', this.t('toaster.pickFamilyMember'), 3000);
2133
+ } else {
2134
+ this.formStore.birthInfos = [];
2135
+ this.showToaster('error', this.t('toaster.notFound'), 3000);
2136
+ }
2137
+ } else {
2138
+ this.formStore.birthInfos = [];
2139
+ this.showToaster('error', this.t('toaster.notFound'), 3000);
2140
+ }
2141
+ } catch (err) {
2142
+ ErrorHandler(err);
2143
+ } finally {
2144
+ this.isLoading = false;
2145
+ }
2146
+ },
2147
+ async getContragentFromGBDFL(iin, phoneNumber, whichForm, whichIndex) {
2148
+ this.isLoading = true;
2149
+ try {
2150
+ const data = {
2151
+ iin: iin.replace(/-/g, ''),
2152
+ phoneNumber: formatPhone(phoneNumber),
2153
+ };
2154
+ const gbdResponse = await this.api.getContragentFromGBDFL(data);
2155
+ if (gbdResponse.status === 'soap:Server') {
2156
+ this.showToaster('error', `${gbdResponse.statusName}. Отправьте запрос через некоторое время`, 5000);
2157
+ this.isLoading = false;
2158
+ return;
2159
+ }
2160
+ if (gbdResponse.status === 'PENDING') {
2161
+ this.showToaster('success', this.t('toaster.waitForClient'), 5000);
2162
+ this.isLoading = false;
2163
+ return;
2164
+ }
2165
+ if (constants.gbdErrors.find(i => i === gbdResponse.status)) {
2166
+ if (gbdResponse.status === 'TIMEOUT') {
2167
+ this.showToaster('success', `${gbdResponse.statusName}. Отправьте запрос еще раз`, 5000);
2168
+ } else {
2169
+ this.showToaster('success', gbdResponse.statusName, 5000);
2170
+ }
2171
+ this.isLoading = false;
2172
+ return;
2173
+ }
2174
+ const { person } = parseXML(gbdResponse.content, true, 'person');
2175
+ const { responseInfo } = parseXML(gbdResponse.content, true, 'responseInfo');
2176
+ if (typeof whichIndex !== 'number') {
2177
+ if (this.formStore[whichForm].gosPersonData !== null && this.formStore[whichForm].gosPersonData.iin !== iin.replace(/-/g, '')) {
2178
+ this.formStore[whichForm].resetMember(false);
2179
+ }
2180
+ this.formStore[whichForm].gosPersonData = person;
2181
+ } else {
2182
+ if (this.formStore[whichForm][whichIndex].gosPersonData !== null && this.formStore[whichForm][whichIndex].gosPersonData.iin !== iin.replace(/-/g, '')) {
2183
+ this.formStore[whichForm][whichIndex].resetMember(false);
2184
+ }
2185
+ this.formStore[whichForm][whichIndex].gosPersonData = person;
2186
+ }
2187
+
2188
+ await this.getContragent(typeof whichIndex === 'number' ? this.formStore[whichForm][whichIndex] : this.formStore[whichForm], whichForm, whichIndex, false);
2189
+ if (typeof whichIndex !== 'number') {
2190
+ this.formStore[whichForm].verifyDate = responseInfo.responseDate;
2191
+ this.formStore[whichForm].verifyType = 'GBDFL';
2192
+ } else {
2193
+ this.formStore[whichForm][whichIndex].verifyDate = responseInfo.responseDate;
2194
+ this.formStore[whichForm][whichIndex].verifyType = 'GBDFL';
2195
+ }
2196
+ await this.saveInStoreUserGBDFL(person, whichForm, whichIndex);
2197
+ } catch (err) {
2198
+ ErrorHandler(err);
2199
+ }
2200
+ this.isLoading = false;
2201
+ },
2202
+ async saveInStoreUserGBDFL(person, whichForm, whichIndex = null) {
2203
+ if (whichIndex === null) {
2204
+ this.formStore[whichForm].firstName = person.name;
2205
+ this.formStore[whichForm].lastName = person.surname;
2206
+ this.formStore[whichForm].middleName = person.patronymic ? person.patronymic : '';
2207
+ this.formStore[whichForm].longName = `${person.surname} ${person.name} ${person.patronymic ? person.patronymic : ''}`;
2208
+ this.formStore[whichForm].birthDate = reformatDate(person.birthDate);
2209
+ this.formStore[whichForm].genderName = person.gender.nameRu;
2210
+
2211
+ const gender = this.gender.find(i => i.id == person.gender.code);
2212
+ if (gender) this.formStore[whichForm].gender = gender;
2213
+
2214
+ const birthPlace = this.countries.find(i => i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')));
2215
+ if (birthPlace) this.formStore[whichForm].birthPlace = birthPlace;
2216
+
2217
+ const countryOfCitizenship = this.citizenshipCountries.find(i => i.nameRu.match(new RegExp(person.citizenship.nameRu, 'i')));
2218
+ if (countryOfCitizenship) this.formStore[whichForm].countryOfCitizenship = countryOfCitizenship;
2219
+
2220
+ const regCountry = this.countries.find(i => i.nameRu.match(new RegExp(person.regAddress.country.nameRu, 'i')));
2221
+ if (regCountry) this.formStore[whichForm].registrationCountry = regCountry;
2222
+
2223
+ const regProvince = this.states.find(i => i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')));
2224
+ if (regProvince) this.formStore[whichForm].registrationProvince = regProvince;
2225
+
2226
+ if ('city' in person.regAddress && !!person.regAddress.city) {
2227
+ if (person.regAddress.city.includes(', ')) {
2228
+ const personCities = person.regAddress.city.split(', ');
2229
+ for (let i = 0; i < personCities.length; ++i) {
2230
+ const possibleCity = this.cities.find(i => i.nameRu.includes(personCities[i]));
2231
+ if (possibleCity) {
2232
+ this.formStore[whichForm].registrationCity = possibleCity;
2233
+ break;
2234
+ }
2235
+ }
2236
+ if (this.formStore[whichForm].registrationCity.nameRu === null) {
2237
+ for (let i = 0; i < personCities.length; ++i) {
2238
+ const possibleRegion = this.regions.find(i => i.nameRu.includes(personCities[i]));
2239
+ if (possibleRegion) {
2240
+ this.formStore[whichForm].registrationRegion = possibleRegion;
2241
+ break;
2242
+ }
2243
+ }
2244
+ }
2245
+ } else {
2246
+ const regCity = this.cities.find(i => i.nameRu.match(new RegExp(person.regAddress.city, 'i')));
2247
+ if (regCity) this.formStore[whichForm].registrationCity = regCity;
2248
+
2249
+ if (this.formStore[whichForm].registrationCity.nameRu === null) {
2250
+ const regRegion = this.regions.find(i => i.nameRu.match(new RegExp(person.regAddress.city), 'i'));
2251
+ if (regRegion) this.formStore[whichForm].registrationRegion = regRegion;
2252
+ }
2253
+ }
2254
+ }
2255
+
2256
+ if (this.formStore[whichForm].registrationCity.nameRu === null && this.formStore[whichForm].registrationRegion.nameRu === null) {
2257
+ const regCity = this.cities.find(
2258
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu, 'i')) || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2259
+ );
2260
+ if (regCity) {
2261
+ this.formStore[whichForm].registrationCity = regCity;
2262
+ const regType = this.localityTypes.find(i => i.nameRu === 'город');
2263
+ if (regType) this.formStore[whichForm].registrationRegionType = regType;
2264
+ } else {
2265
+ const regRegion = this.regions.find(
2266
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu), 'i') || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2267
+ );
2268
+ if (regRegion) {
2269
+ this.formStore[whichForm].registrationRegion = regRegion;
2270
+ const regType = this.localityTypes.find(i => (i.nameRu === i.nameRu) === 'село' || i.nameRu === 'поселок');
2271
+ if (regType) this.formStore[whichForm].registrationRegionType = regType;
2272
+ }
2273
+ }
2274
+ }
2275
+
2276
+ if (person.regAddress.street.includes(', ')) {
2277
+ const personAddress = person.regAddress.street.split(', ');
2278
+ const microDistrict = personAddress.find(i => i.match(new RegExp('микрорайон', 'i')));
2279
+ const quarter = personAddress.find(i => i.match(new RegExp('квартал', 'i')));
2280
+ const street = personAddress.find(i => i.match(new RegExp('улица', 'i')));
2281
+ if (microDistrict) this.formStore[whichForm].registrationMicroDistrict = microDistrict;
2282
+ if (quarter) this.formStore[whichForm].registrationQuarter = quarter;
2283
+ if (street) this.formStore[whichForm].registrationStreet = street;
2284
+ } else {
2285
+ if (person.regAddress.street) this.formStore[whichForm].registrationStreet = person.regAddress.street;
2286
+ }
2287
+ if (person.regAddress.building) this.formStore[whichForm].registrationNumberHouse = person.regAddress.building;
2288
+ if (person.regAddress.flat) this.formStore[whichForm].registrationNumberApartment = person.regAddress.flat;
2289
+
2290
+ // TODO Доработать логику и для остальных
2291
+ if ('length' in person.documents.document) {
2292
+ const validDocument = person.documents.document.find(i => new Date(i.endDate) > new Date(Date.now()) && i.status.code === '00' && i.type.code === '002');
2293
+ if (validDocument) {
2294
+ const documentType = this.documentTypes.find(i => i.ids === '1UDL');
2295
+ if (documentType) this.formStore[whichForm].documentType = documentType;
2296
+
2297
+ this.formStore[whichForm].documentNumber = validDocument.number;
2298
+ this.formStore[whichForm].documentExpire = reformatDate(validDocument.endDate);
2299
+ this.formStore[whichForm].documentDate = reformatDate(validDocument.beginDate);
2300
+ this.formStore[whichForm].documentNumber = validDocument.number;
2301
+
2302
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2303
+ if (documentIssuer) this.formStore[whichForm].documentIssuers = documentIssuer;
2304
+ }
2305
+ } else {
2306
+ const documentType =
2307
+ person.documents.document.type.nameRu === 'УДОСТОВЕРЕНИЕ РК'
2308
+ ? this.documentTypes.find(i => i.ids === '1UDL')
2309
+ : this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2310
+ ? this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2311
+ : new Value();
2312
+ if (documentType) this.formStore[whichForm].documentType = documentType;
2313
+
2314
+ const documentNumber = person.documents.document.number;
2315
+ if (documentNumber) this.formStore[whichForm].documentNumber = documentNumber;
2316
+
2317
+ const documentDate = person.documents.document.beginDate;
2318
+ if (documentDate) this.formStore[whichForm].documentDate = reformatDate(documentDate);
2319
+
2320
+ const documentExpire = person.documents.document.endDate;
2321
+ if (documentExpire) this.formStore[whichForm].documentExpire = reformatDate(documentExpire);
2322
+
2323
+ // TODO уточнить
2324
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2325
+ if (documentIssuer) this.formStore[whichForm].documentIssuers = documentIssuer;
2326
+ }
2327
+ const economySectorCode = this.economySectorCode.find(i => i.ids === '500003.9');
2328
+ if (economySectorCode) this.formStore[whichForm].economySectorCode = economySectorCode;
2329
+ } else {
2330
+ this.formStore[whichForm][whichIndex].firstName = person.name;
2331
+ this.formStore[whichForm][whichIndex].lastName = person.surname;
2332
+ this.formStore[whichForm][whichIndex].middleName = person.patronymic ? person.patronymic : '';
2333
+ this.formStore[whichForm][whichIndex].longName = `${person.surname} ${person.name} ${person.patronymic ? person.patronymic : ''}`;
2334
+ this.formStore[whichForm][whichIndex].birthDate = reformatDate(person.birthDate);
2335
+ this.formStore[whichForm][whichIndex].genderName = person.gender.nameRu;
2336
+
2337
+ const gender = this.gender.find(i => i.id == person.gender.code);
2338
+ if (gender) this.formStore[whichForm][whichIndex].gender = gender;
2339
+
2340
+ const birthPlace = this.countries.find(i => i.nameRu.match(new RegExp(person.birthPlace.country.nameRu, 'i')));
2341
+ if (birthPlace) this.formStore[whichForm][whichIndex].birthPlace = birthPlace;
2342
+
2343
+ const countryOfCitizenship = this.citizenshipCountries.find(i => i.nameRu.match(new RegExp(person.citizenship.nameRu, 'i')));
2344
+ if (countryOfCitizenship) this.formStore[whichForm][whichIndex].countryOfCitizenship = countryOfCitizenship;
2345
+
2346
+ const regCountry = this.countries.find(i => i.nameRu.match(new RegExp(person.regAddress.country.nameRu, 'i')));
2347
+ if (regCountry) this.formStore[whichForm][whichIndex].registrationCountry = regCountry;
2348
+
2349
+ const regProvince = this.states.find(i => i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')));
2350
+ if (regProvince) this.formStore[whichForm][whichIndex].registrationProvince = regProvince;
2351
+
2352
+ if ('city' in person.regAddress && !!person.regAddress.city) {
2353
+ if (person.regAddress.city.includes(', ')) {
2354
+ const personCities = person.regAddress.city.split(', ');
2355
+ for (let i = 0; i < personCities.length; ++i) {
2356
+ const possibleCity = this.cities.find(i => i.nameRu.includes(personCities[i]));
2357
+ if (possibleCity) {
2358
+ this.formStore[whichForm][whichIndex].registrationCity = possibleCity;
2359
+ break;
2360
+ }
2361
+ }
2362
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null) {
2363
+ for (let i = 0; i < personCities.length; ++i) {
2364
+ const possibleRegion = this.regions.find(i => i.nameRu.includes(personCities[i]));
2365
+ if (possibleRegion) {
2366
+ this.formStore[whichForm][whichIndex].registrationRegion = possibleRegion;
2367
+ break;
2368
+ }
2369
+ }
2370
+ }
2371
+ } else {
2372
+ const regCity = this.cities.find(i => i.nameRu.match(new RegExp(person.regAddress.city, 'i')));
2373
+ if (regCity) this.formStore[whichForm][whichIndex].registrationCity = regCity;
2374
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null) {
2375
+ const regRegion = this.regions.find(i => i.nameRu.match(new RegExp(person.regAddress.city), 'i'));
2376
+ if (regRegion) this.formStore[whichForm][whichIndex].registrationRegion = regRegion;
2377
+ }
2378
+ }
2379
+ }
2380
+
2381
+ if (this.formStore[whichForm][whichIndex].registrationCity.nameRu === null && this.formStore[whichForm][whichIndex].registrationRegion.nameRu === null) {
2382
+ const regCity = this.cities.find(
2383
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu, 'i')) || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2384
+ );
2385
+ if (regCity) {
2386
+ this.formStore[whichForm][whichIndex].registrationCity = regCity;
2387
+ const regType = this.localityTypes.find(i => i.nameRu === 'город');
2388
+ if (regType) this.formStore[whichForm][whichIndex].registrationRegionType = regType;
2389
+ } else {
2390
+ const regRegion = this.regions.find(
2391
+ i => i.nameRu.match(new RegExp(person.regAddress.region.nameRu), 'i') || i.nameRu.match(new RegExp(person.regAddress.district.nameRu, 'i')),
2392
+ );
2393
+ if (regRegion) {
2394
+ this.formStore[whichForm][whichIndex].registrationRegion = regRegion;
2395
+ const regType = this.localityTypes.find(i => (i.nameRu === i.nameRu) === 'село' || i.nameRu === 'поселок');
2396
+ if (regType) this.formStore[whichForm][whichIndex].registrationRegionType = regType;
2397
+ }
2398
+ }
2399
+ }
2400
+
2401
+ if (person.regAddress.street.includes(', ')) {
2402
+ const personAddress = person.regAddress.street.split(', ');
2403
+ const microDistrict = personAddress.find(i => i.match(new RegExp('микрорайон', 'i')));
2404
+ const quarter = personAddress.find(i => i.match(new RegExp('квартал', 'i')));
2405
+ const street = personAddress.find(i => i.match(new RegExp('улица', 'i')));
2406
+ if (microDistrict) this.formStore[whichForm][whichIndex].registrationMicroDistrict = microDistrict;
2407
+ if (quarter) this.formStore[whichForm][whichIndex].registrationQuarter = quarter;
2408
+ if (street) this.formStore[whichForm][whichIndex].registrationStreet = street;
2409
+ } else {
2410
+ if (person.regAddress.street) this.formStore[whichForm][whichIndex].registrationStreet = person.regAddress.street;
2411
+ }
2412
+ if (person.regAddress.building) this.formStore[whichForm][whichIndex].registrationNumberHouse = person.regAddress.building;
2413
+ if (person.regAddress.flat) this.formStore[whichForm][whichIndex].registrationNumberApartment = person.regAddress.flat;
2414
+
2415
+ // TODO Доработать логику и для остальных
2416
+ if ('length' in person.documents.document) {
2417
+ const validDocument = person.documents.document.find(i => new Date(i.endDate) > new Date(Date.now()) && i.status.code === '00' && i.type.code === '002');
2418
+ if (validDocument) {
2419
+ const documentType = this.documentTypes.find(i => i.ids === '1UDL');
2420
+ if (documentType) this.formStore[whichForm][whichIndex].documentType = documentType;
2421
+ this.formStore[whichForm][whichIndex].documentNumber = validDocument.number;
2422
+ this.formStore[whichForm][whichIndex].documentExpire = reformatDate(validDocument.endDate);
2423
+ this.formStore[whichForm][whichIndex].documentDate = reformatDate(validDocument.beginDate);
2424
+ this.formStore[whichForm][whichIndex].documentNumber = validDocument.number;
2425
+
2426
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2427
+ if (documentIssuer) this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer;
2428
+ }
2429
+ } else {
2430
+ const documentType =
2431
+ person.documents.document.type.nameRu === 'УДОСТОВЕРЕНИЕ РК'
2432
+ ? this.documentTypes.find(i => i.ids === '1UDL')
2433
+ : this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2434
+ ? this.documentTypes.find(i => i.nameRu.match(new RegExp(person.documents.document.type.nameRu, 'i')))
2435
+ : new Value();
2436
+ if (documentType) this.formStore[whichForm][whichIndex].documentType = documentType;
2437
+
2438
+ const documentNumber = person.documents.document.number;
2439
+ if (documentNumber) this.formStore[whichForm][whichIndex].documentNumber = documentNumber;
2440
+
2441
+ const documentDate = person.documents.document.beginDate;
2442
+ if (documentDate) this.formStore[whichForm][whichIndex].documentDate = reformatDate(documentDate);
2443
+
2444
+ const documentExpire = person.documents.document.endDate;
2445
+ if (documentExpire) this.formStore[whichForm][whichIndex].documentExpire = reformatDate(documentExpire);
2446
+
2447
+ // TODO уточнить
2448
+ const documentIssuer = this.documentIssuers.find(i => i.nameRu.match(new RegExp('МВД РК', 'i')));
2449
+ if (documentIssuer) this.formStore[whichForm][whichIndex].documentIssuers = documentIssuer;
2450
+ }
2451
+ const economySectorCode = this.economySectorCode.find(i => i.ids === '500003.9');
2452
+ if (economySectorCode) this.formStore[whichForm][whichIndex].economySectorCode = economySectorCode;
2453
+ }
2454
+ },
2455
+ hasJobSection(whichForm) {
2456
+ switch (whichForm) {
2457
+ case this.formStore.beneficiaryFormKey:
2458
+ case this.formStore.beneficialOwnerFormKey:
2459
+ case this.formStore.policyholdersRepresentativeFormKey:
2460
+ return false;
2461
+ default:
2462
+ return true;
2463
+ }
2464
+ },
2465
+ hasBirthSection(whichForm) {
2466
+ if (this.isGons) return false;
2467
+ switch (whichForm) {
2468
+ case this.formStore.beneficiaryFormKey:
2469
+ return false;
2470
+ default:
2471
+ return true;
2472
+ }
2473
+ },
2474
+ hasPlaceSection(whichForm) {
2475
+ switch (whichForm) {
2476
+ default:
2477
+ return true;
2478
+ }
2479
+ },
2480
+ hasDocumentSection(whichForm) {
2481
+ switch (whichForm) {
2482
+ default:
2483
+ return true;
2484
+ }
2485
+ },
2486
+ hasContactSection(whichForm) {
2487
+ if (this.isGons) return false;
2488
+ switch (whichForm) {
2489
+ default:
2490
+ return true;
2491
+ }
26
2492
  },
27
2493
  },
28
2494
  });
2495
+
2496
+ export const useContragentStore = defineStore('contragent', {
2497
+ state: () => ({
2498
+ ...new Contragent(),
2499
+ formatDate: new Contragent().formatDate,
2500
+ getDateByKey: new Contragent().getDateByKey,
2501
+ getBirthDate: new Contragent().getBirthDate,
2502
+ getDocumentExpireDate: new Contragent().getDocumentExpireDate,
2503
+ getDocumentDate: new Contragent().getDocumentDate,
2504
+ getAgeByBirthDate: new Contragent().getAgeByBirthDate,
2505
+ }),
2506
+ });