hl-core 0.0.8-beta.9 → 0.0.9-beta.1

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