hl-core 0.0.8-beta.4 → 0.0.8-beta.40

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