hl-core 0.0.7 → 0.0.8-beta.1

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