Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let datesHelper = require('../utils/dates-helper')
- , PASSPORT_TYPES = require('../utils/passport-types')
- , format = require('../utils/format')
- , PRODUCT_TYPES = require('../utils/product-types').formData
- ;
- const FUND_STATUS_CAPTIONS = require('../utils/doc-statuses').fundStatusCaptions;
- function rename(obj) {
- if (typeof obj !== 'object')
- return obj;
- for (let key in obj) {
- if (key.indexOf('.') !== -1) {
- let keyArr = key.split('.');
- let newKey = keyArr[0];
- let nextKey = keyArr.slice(1).join('.');
- if (!obj[newKey] || typeof obj[newKey] !== 'object')
- obj[newKey] = {};
- obj[newKey][nextKey] = obj[key];
- delete obj[key];
- key = newKey;
- }
- if (typeof obj[key] === 'object') {
- obj[key] = rename(obj[key]);
- }
- }
- return obj;
- }
- function merge() {
- let result = {};
- if (arguments[0] instanceof Array) {
- result = [];
- }
- for (let i = 0; i < arguments.length; ++i) {
- let obj = arguments[i];
- if (typeof obj !== 'object')
- continue;
- for (let key in obj) {
- if (obj[key] !== null && typeof obj[key] === 'object') {
- if (!result[key]) {
- if (obj[key] instanceof Array) {
- result[key] = [];
- } else {
- result[key] = {};
- }
- }
- result[key] = merge(result[key], obj[key]);
- } else {
- result[key] = obj[key];
- }
- }
- }
- return result;
- }
- function setActiveCheckboxes(formData, postData, keys, formDataHack) {
- formData = Object.assign({}, formData);
- if (!keys || !postData) {
- return formData;
- }
- if (!Array.isArray(keys)) {
- keys = [keys];
- }
- for (let key of keys) {
- if (!formData[key] || !postData[key]) {
- continue;
- }
- for (let formItem of formData[key]) {
- delete formItem.active;
- if (formItem._id) {
- if (Array.isArray(postData[key])) {
- if (postData[key].indexOf(formItem._id) !== -1) {
- formItem.active = formDataHack ? "true" : true;
- }
- } else {
- if (postData[key] == formItem._id) {
- formItem.active = formDataHack ? "true" : true;
- }
- }
- }
- if (formItem.id) {
- if (Array.isArray(postData[key])) {
- if (postData[key].indexOf(formItem.id) !== -1) {
- formItem.active = formDataHack ? "true" : true;
- }
- } else {
- if (postData[key] == formItem.id) {
- formItem.active = formDataHack ? "true" : true;
- }
- }
- }
- }
- }
- return formData;
- }
- function copyObjectsArray (arr) {
- let result = [];
- for (let item of arr) {
- if (typeof item == 'object' && !Array.isArray(item)) {
- result.push(Object.assign({}, item));
- } else {
- result.push(item);
- }
- }
- return result;
- }
- function user(user, post, formData) {
- if (post) {
- user = merge(user, post);
- }
- formData.passportType = [
- { id: 'RF_PASSPORT', caption: 'Паспорт гражданина РФ' }
- ];
- formData.macroSegment = [
- { id: 'Retail', caption: 'Retail' },
- { id: 'VIP', caption: 'VIP' }
- ]
- user.macroSegment = !Array.isArray(user.macroSegment) ? [ user.macroSegment ] : user.macroSegment;
- user.macroSegment = user.macroSegment.filter((item) => { return !!item });
- formData = setActiveCheckboxes(formData, user, ['roles', 'rules', 'macroSegment']);
- if (post) {
- if (post.isPersonalManager) {
- user.isPersonalManager = handleCheckbox(post.isPersonalManager);
- }
- if (post.sendCredentialsLink) {
- user.sendCredentialsLink = handleCheckbox(post.sendCredentialsLink);
- }
- }
- return {
- user: user,
- formData: formData
- };
- }
- function role(role, post, formData) {
- if (post) {
- role = merge(role, post);
- }
- formData.parentEntityTypes = formData.parentEntityTypes || [
- {
- _id: 'management-company',
- caption: 'УК'
- }, {
- _id: 'agent',
- caption: 'Агент'
- }, {
- _id: 'app-point',
- caption: 'ППЗ'
- }/*, {
- _id: 'work-station',
- caption: 'РМ'
- }*/
- ]
- formData = setActiveCheckboxes(formData, post, ['rules', 'parentEntityTypes']);
- if (post.isCompanyStaff) {
- role.isCompanyStaff = handleCheckbox(role.isCompanyStaff);
- }
- if (post.isAgentAdmin) {
- role.isAgentAdmin = handleCheckbox(role.isAgentAdmin);
- }
- if (post.isAdmin) {
- role.isAdmin = handleCheckbox(role.isAdmin);
- }
- if (post.isClientManagerShareFunds) {
- role.isClientManagerShareFunds = handleCheckbox(role.isClientManagerShareFunds);
- }
- if (post.isClientManagerTrustContracts) {
- role.isClientManagerTrustContracts = handleCheckbox(role.isClientManagerTrustContracts);
- }
- if (post.isParentEntityFixed) {
- role.isParentEntityFixed = handleCheckbox(role.isParentEntityFixed);
- }
- if (post.isJournalObserver) {
- role.isJournalObserver = handleCheckbox(role.isJournalObserver);
- }
- return {
- role: role,
- formData: formData
- };
- }
- function handleCheckbox(val) {
- if (val && typeof val == 'object' && val !== null) {
- val = true;
- } else {
- val = !!+val;
- }
- return val ? 1 : 0;
- }
- function entityAgent(data) {
- let result = {
- formData: {},
- item: data
- };
- result.formData.addressFactObj = {
- country: [
- { id: '', caption: 'Выберите из списка' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' }
- ]
- };
- result.formData.addressRegistrationObj = {
- country: [
- { id: '', caption: 'Выберите из списка' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' }
- ]
- };
- result.formData.allowedRegistrationMethods = [
- { id: 'bypassword', caption: 'Логин-пароль' },
- { id: 'byesia', caption: 'Госуслуги' }
- ];
- result.formData.productTypes = PRODUCT_TYPES.map((item) => { return Object.assign({}, item) });
- if (typeof result.item.appPointCodeLength == 'number') {
- result.item.appPointCodeLength = result.item.appPointCodeLength.toString();
- }
- if (typeof result.item.trustContractsAppPointCodeLength == 'number') {
- result.item.trustContractsAppPointCodeLength = result.item.trustContractsAppPointCodeLength.toString();
- }
- if (typeof result.item.workStationCodeLength == 'number') {
- result.item.workStationCodeLength = result.item.workStationCodeLength.toString();
- }
- if (typeof result.item.trustContractsWorkStationCodeLength == 'number') {
- result.item.trustContractsWorkStationCodeLength = result.item.trustContractsWorkStationCodeLength.toString();
- }
- if (data) {
- result.formData = setActiveCheckboxes(result.formData, result.item, ['productTypes', 'allowedRegistrationMethods']);
- if (data.addressRegistrationObj) {
- result.formData.addressRegistrationObj = setActiveCheckboxes(result.formData.addressRegistrationObj, result.item.addressRegistrationObj, ['country']);
- result.item.addressRegistrationObj.noStreet = handleCheckbox(result.item.addressRegistrationObj.noStreet);
- }
- if (data.addressFactObj) {
- result.formData.addressFactObj = setActiveCheckboxes(result.formData.addressFactObj, result.item.addressFactObj, ['country']);
- result.item.addressFactObj.noStreet = handleCheckbox(result.item.addressFactObj.noStreet);
- }
- result.item.isTwoFactorAuthEnabled = handleCheckbox(result.item.isTwoFactorAuthEnabled);
- result.item.isSeparateEDMExists = handleCheckbox(result.item.isSeparateEDMExists);
- }
- return result;
- }
- function entityMC(data) {
- let result = {
- formData: {},
- item: data
- };
- return result;
- }
- function entityAP(data, formData) {
- let result = {
- formData: {},
- item: data
- };
- result.formData.productTypes = PRODUCT_TYPES.map((item) => { return Object.assign({}, item) });
- if (!formData || !formData.parentItem || !Array.isArray(formData.parentItem.productTypes)) {
- result.formData.productTypes = [];
- } else {
- result.formData.productTypes = result.formData.productTypes.filter((item) => { return formData.parentItem.productTypes.indexOf(item.id) !== -1 });
- }
- result.formData.addressFactObj = {
- country: [
- { id: '', caption: 'Выберите из списка' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' }
- ]
- };
- if (data) {
- result.formData = setActiveCheckboxes(result.formData, result.item, ['productTypes']);
- if (data.addressFactObj) {
- result.formData.addressFactObj = setActiveCheckboxes(result.formData.addressFactObj, result.item.addressFactObj, ['country']);
- result.item.addressFactObj.noStreet = handleCheckbox(result.item.addressFactObj.noStreet);
- }
- }
- return result;
- }
- function entityWS(data) {
- let result = {
- formData: {},
- item: data
- };
- return result;
- }
- function entity(data, post, formData /* TODO: remove ? */, errors) {
- if (post) {
- data = merge(data, post);
- }
- let result;
- if (data.type == 'management-company') {
- result = entityMC(data);
- } else if (data.type == 'agent') {
- result = entityAgent(data);
- } else if (data.type == 'app-point') {
- result = entityAP(data, formData);
- } else if (data.type == 'work-station') {
- result = entityWS(data);
- } else {
- return false;
- //throw new Error('Unknown entity type: ' + data.type);
- }
- return result;
- }
- function client(data, post, formData /* TODO: remove ? */, errors) {
- if (data) {
- if (!data.bank) {
- data.bank = {};
- }
- if (!data.bankUSD) {
- data.bankUSD = {};
- }
- if (!data.bankEUR) {
- data.bankEUR = {};
- }
- if (!data.bank.recipient) {
- data.bank.recipient = data.identity.surname + ' ' + data.identity.name + ' ' + data.identity.patronymic;
- data.bank.recipient = data.bank.recipient.trim();
- }
- if (!data.bankUSD.recipient) {
- data.bankUSD.recipient = data.identity.surname + ' ' + data.identity.name + ' ' + data.identity.patronymic;
- data.bankUSD.recipient = data.bankUSD.recipient.trim();
- }
- if (!data.bankEUR.recipient) {
- data.bankEUR.recipient = data.identity.surname + ' ' + data.identity.name + ' ' + data.identity.patronymic;
- data.bankEUR.recipient = data.bankEUR.recipient.trim();
- }
- }
- if (post) {
- data = merge(data, post);
- }
- let result = {
- formData: {},
- client: data //TODO: client => item ?
- };
- let multipleIdentityFields = ["sourceOfFunds", "citizenship"];
- let passportTypes = [];
- for (let docType in PASSPORT_TYPES) {
- passportTypes.push({
- id: docType, caption: PASSPORT_TYPES[docType]
- });
- }
- result.formData.passportType = copyObjectsArray(passportTypes);
- result.formData.citizenship = [
- { id: 'РФ', caption: 'РФ' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' },
- { id: 'Лицо без гражданства', caption: 'Лицо без гражданства' }
- ];
- result.formData.birthCountry = [
- { id: '', caption: 'Выберите из списка' },
- { id: 'США', caption: 'США' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'other', caption: 'Иное государство' }
- ];
- result.formData.addressFactObj = {
- country: [
- { id: '', caption: 'Выберите из списка' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' }
- ]
- };
- result.formData.addressRegistrationObj = {
- country: [
- { id: '', caption: 'Выберите из списка' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' }
- ]
- };
- result.formData.addressPostalObj = {
- country: [
- { id: '', caption: 'Выберите из списка' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' }
- ]
- };
- result.formData.goal = [
- { id: '', caption: 'Выберите из списка' },
- { id: 'Инвестирование личных сбережений', caption: 'Инвестирование личных сбережений' },
- { id: 'goal_add', caption: 'Иное (указать)' }
- ];
- result.formData.pdl = {};
- result.formData.pdl.relationDegree = [
- { id: '', caption: 'Выберите из списка' },
- { id: 'Супруг(а)', caption: 'Супруг(а)' },
- { id: 'Родитель / усыновитель', caption: 'Родитель / усыновитель' },
- { id: 'Опекун / попечитель', caption: 'Опекун / попечитель' },
- { id: 'Ребенок (в т.ч. усыновленный)', caption: 'Ребенок (в т.ч. усыновленный)' },
- { id: 'Брат / сестра', caption: 'Брат / сестра' },
- { id: 'Дедушка / бабушка', caption: 'Дедушка / бабушка' },
- { id: 'Внук / внучка', caption: 'Внук / внучка' },
- { id: 'relationDegree_add', caption: 'Иное (указать)' }
- ];
- result.formData.beneficialOwner = [
- { id: 'none', caption: 'Отсутствует' },
- { id: 'confirmed', caption: 'Наличие бенефициарного владельца подтверждается физ.лицом' }
- ];
- result.formData.beneficiary = [
- { id: 'Физ. лицо действует к собственной выгоде', caption: 'Физ. лицо действует к собственной выгоде' },
- { id: 'Иное лицо', caption: 'Иное лицо' }
- ];
- result.formData.economicActivities = [
- { id: 'Получение дохода', caption: 'Получение дохода' },
- { id: 'economicActivities_add', caption: 'Иное' }
- ];
- result.formData.financialPosition = [
- { id: 'Отсутствуют проблемы с исполнением финансовых обязательств', caption: 'Отсутствуют проблемы с исполнением финансовых обязательств' },
- { id: 'financialPosition_add', caption: 'Иное' }
- ];
- result.formData.businessReputation = [
- { id: 'none', caption: 'Отсутствуют' },
- { id: 'confirmed', caption: 'Рекомендации прилагаются' }
- ];
- result.formData.sourceOfFunds = [
- { id: 'Заработная плата', caption: 'Заработная плата' },
- { id: 'Продажа имущества', caption: 'Продажа имущества' },
- { id: 'Дивиденды', caption: 'Дивиденды' },
- { id: 'Доходы от предпринимательской деятельности', caption: 'Доходы от предпринимательской деятельности' },
- { id: 'Пенсия', caption: 'Пенсия' },
- { id: 'Наследство', caption: 'Наследство' },
- { id: 'Личные сбережения', caption: 'Личные сбережения' },
- { id: 'sourceOfFunds_add', caption: 'Иные источники' }
- ];
- result.formData.types = [
- { id: 'client', caption: 'Клиент' },
- { id: 'representative', caption: 'Представитель' }
- ];
- result.formData.residence = [
- { id: 'empty', caption: 'Выберите из списка, если есть' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' }
- ];
- result.formData.birthCountry = [
- { id: '', caption: 'Выберите из списка' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'США', caption: 'США' },
- { id: 'other', caption: 'Иное государство' }
- ];
- result.formData.phoneCode = [
- { id: '+7', caption: '+7' },
- { id: '+1', caption: '+1' },
- { id: '+20', caption: '+20' },
- { id: '+212', caption: '+212' },
- { id: '+213', caption: '+213' }
- ];
- result.formData.bankAbroad = {
- countries: [
- { id: 'Австралия', caption: 'Австралия' },
- { id: 'Австрия', caption: 'Австрия' },
- { id: 'Андорра', caption: 'Андорра' },
- { id: 'Аргентина', caption: 'Аргентина' },
- { id: 'Бельгия', caption: 'Бельгия' },
- { id: 'Болгария', caption: 'Болгария' },
- { id: 'Бразилия', caption: 'Бразилия' },
- { id: 'Великобритания', caption: 'Великобритания' },
- { id: 'Венгрия', caption: 'Венгрия' },
- { id: 'Германия', caption: 'Германия' },
- { id: 'Гернси', caption: 'Гернси' },
- { id: 'Гибралтар', caption: 'Гибралтар' },
- { id: 'Гренландия', caption: 'Гренландия' },
- { id: 'Греция', caption: 'Греция' },
- { id: 'Дания', caption: 'Дания' },
- { id: 'Джерси', caption: 'Джерси' },
- { id: 'Индия', caption: 'Индия' },
- { id: 'Индонезия', caption: 'Индонезия' },
- { id: 'Ирландия', caption: 'Ирландия' },
- { id: 'Исландия', caption: 'Исландия' },
- { id: 'Испания', caption: 'Испания' },
- { id: 'Италия', caption: 'Италия'},
- { id: 'Китай', caption: 'Китай' },
- { id: 'Колумбия', caption: 'Колумбия' },
- { id: 'Корея', caption: 'Корея' },
- { id: 'Литва', caption: 'Литва' },
- { id: 'Лихтенштейн', caption: 'Лихтенштейн' },
- { id: 'Люксембург', caption: 'Люксембург' },
- { id: 'Маврикий', caption: 'Маврикий' },
- { id: 'Малайзия', caption: 'Малайзия' },
- { id: 'Мальта', caption: 'Мальта' },
- { id: 'Мексика', caption: 'Мексика' },
- { id: 'Нидерланды', caption: 'Нидерланды' },
- { id: 'Новая Зеландия', caption: 'Новая Зеландия' },
- { id: 'Норвегия', caption: 'Норвегия' },
- { id: 'Остров Мэн', caption: 'Остров Мэн' },
- { id: 'Пакистан', caption: 'Пакистан' },
- { id: 'Польша', caption: 'Польша' },
- { id: 'Португалия', caption: 'Португалия' },
- { id: 'Республика Словакия', caption: 'Республика Словакия' },
- { id: 'Сан Марино', caption: 'Сан Марино' },
- { id: 'Саудовская Аравия', caption: 'Саудовская Аравия' },
- { id: 'Сейшелы', caption: 'Сейшелы' },
- { id: 'Сингапур', caption: 'Сингапур' },
- { id: 'Словения', caption: 'Словения' },
- { id: 'Уругвай', caption: 'Уругвай' },
- { id: 'Фарерские острова', caption: 'Фарерские острова' },
- { id: 'Финляндия', caption: 'Финляндия' },
- { id: 'Франция', caption: 'Франция' },
- { id: 'Хорватия', caption: 'Хорватия' },
- { id: 'Чешская республика', caption: 'Чешская республика' },
- { id: 'Чили', caption: 'Чили' },
- { id: 'Швейцария', caption: 'Швейцария' },
- { id: 'Швеция', caption: 'Швеция' },
- { id: 'Эстония', caption: 'Эстония' },
- { id: 'ЮАР', caption: 'ЮАР' },
- { id: 'Япония', caption: 'Япония' },
- { id: 'other', caption: 'Иное государство' }
- ]
- };
- result.formData.taxResidence = [
- { id: '', caption: 'Выберите из списка' },
- { id: 'РФ', caption: 'РФ' },
- { id: 'Австралия', caption: 'Австралия' },
- { id: 'Австрия', caption: 'Австрия' },
- { id: 'Андорра', caption: 'Андорра' },
- { id: 'Аргентина', caption: 'Аргентина' },
- { id: 'Бельгия', caption: 'Бельгия' },
- { id: 'Болгария', caption: 'Болгария' },
- { id: 'Бразилия', caption: 'Бразилия' },
- { id: 'Великобритания', caption: 'Великобритания' },
- { id: 'Венгрия', caption: 'Венгрия' },
- { id: 'Германия', caption: 'Германия' },
- { id: 'Гернси', caption: 'Гернси' },
- { id: 'Гибралтар', caption: 'Гибралтар' },
- { id: 'Гренландия', caption: 'Гренландия' },
- { id: 'Греция', caption: 'Греция' },
- { id: 'Дания', caption: 'Дания' },
- { id: 'Джерси', caption: 'Джерси' },
- { id: 'Индия', caption: 'Индия' },
- { id: 'Индонезия', caption: 'Индонезия' },
- { id: 'Ирландия', caption: 'Ирландия' },
- { id: 'Исландия', caption: 'Исландия' },
- { id: 'Испания', caption: 'Испания' },
- { id: 'Италия', caption: 'Италия'},
- { id: 'Китай', caption: 'Китай' },
- { id: 'Колумбия', caption: 'Колумбия' },
- { id: 'Корея', caption: 'Корея' },
- { id: 'Литва', caption: 'Литва' },
- { id: 'Лихтенштейн', caption: 'Лихтенштейн' },
- { id: 'Люксембург', caption: 'Люксембург' },
- { id: 'Маврикий', caption: 'Маврикий' },
- { id: 'Малайзия', caption: 'Малайзия' },
- { id: 'Мальта', caption: 'Мальта' },
- { id: 'Мексика', caption: 'Мексика' },
- { id: 'Нидерланды', caption: 'Нидерланды' },
- { id: 'Новая Зеландия', caption: 'Новая Зеландия' },
- { id: 'Норвегия', caption: 'Норвегия' },
- { id: 'Остров Мэн', caption: 'Остров Мэн' },
- { id: 'Пакистан', caption: 'Пакистан' },
- { id: 'Польша', caption: 'Польша' },
- { id: 'Португалия', caption: 'Португалия' },
- { id: 'Республика Словакия', caption: 'Республика Словакия' },
- { id: 'Сан Марино', caption: 'Сан Марино' },
- { id: 'Саудовская Аравия', caption: 'Саудовская Аравия' },
- { id: 'Сейшелы', caption: 'Сейшелы' },
- { id: 'Сингапур', caption: 'Сингапур' },
- { id: 'Словения', caption: 'Словения' },
- { id: 'США', caption: 'США' },
- { id: 'Уругвай', caption: 'Уругвай' },
- { id: 'Фарерские острова', caption: 'Фарерские острова' },
- { id: 'Финляндия', caption: 'Финляндия' },
- { id: 'Франция', caption: 'Франция' },
- { id: 'Хорватия', caption: 'Хорватия' },
- { id: 'Чешская республика', caption: 'Чешская республика' },
- { id: 'Чили', caption: 'Чили' },
- { id: 'Швейцария', caption: 'Швейцария' },
- { id: 'Швеция', caption: 'Швеция' },
- { id: 'Эстония', caption: 'Эстония' },
- { id: 'ЮАР', caption: 'ЮАР' },
- { id: 'Япония', caption: 'Япония' },
- { id: 'other', caption: 'Иное государство' }
- ];
- result.formData.segment = [
- { id: '', caption: 'Выберите из списка' },
- { id: 'Mass retail', caption: 'Mass retail' },
- { id: 'Premium', caption: 'Premium' },
- { id: 'VIP', caption: 'VIP' }
- ];
- if (data) {
- if (post && post.identity) {
- for (let field of multipleIdentityFields) {
- if (Array.isArray(post.identity[field])) {
- let pos = post.identity[field].indexOf("");
- if (pos !== -1) {
- result.client.identity[field] = [].concat(post.identity[field].slice(0, pos), post.identity[field].slice(pos + 1));
- }
- }
- }
- }
- result.formData = setActiveCheckboxes(result.formData, result.client.identity, ['passportType', 'citizenship', 'birthCountry', 'goal', 'russianBankAccount', 'taxResidence', 'beneficialOwner', 'beneficiary', 'sourceOfFunds', 'economicActivities', 'financialPosition', 'businessReputation']);
- result.formData.addressFactObj = setActiveCheckboxes(result.formData.addressFactObj, result.client.identity.addressFactObj, ['country']);
- if (data.identity.addressRegistrationObj) {
- result.formData.addressRegistrationObj = setActiveCheckboxes(result.formData.addressRegistrationObj, result.client.identity.addressRegistrationObj, ['country']);
- }
- /*if (data.identity.addressPostalObj) {
- result.formData.addressPostalObj = setActiveCheckboxes(result.formData.addressPostalObj, result.client.identity.addressPostalObj, ['country']);
- }*/
- result.formData.pdl = setActiveCheckboxes(result.formData.pdl, result.client.identity.pdl, ['check', 'relationDegree']);
- result.formData = setActiveCheckboxes(result.formData, result.client.identity, ['types']);
- result.formData = setActiveCheckboxes(result.formData, result.client, ['phoneCode', 'residence', 'segment']);
- if (result.client.identity.agree) {
- result.client.identity.agree = handleCheckbox(result.client.identity.agree);
- }
- if (result.client.identity.addressFactObj) {
- result.client.identity.addressFactObj.noStreet = handleCheckbox(result.client.identity.addressFactObj.noStreet);
- }
- if (result.client.identity.addressRegistrationObj) {
- result.client.identity.addressRegistrationObj.noStreet = handleCheckbox(result.client.identity.addressRegistrationObj.noStreet);
- }
- /*if (result.client.identity.addressPostalObj) {
- result.client.identity.addressPostalObj.noStreet = handleCheckbox(result.client.identity.addressPostalObj.noStreet);
- }*/
- result.client.identity.noPreviousPassports = handleCheckbox(result.client.identity.noPreviousPassports);
- result.client.identity.addressFactSimilar = handleCheckbox(result.client.identity.addressFactSimilar);
- //result.client.identity.addressPostalSimilar = handleCheckbox(result.client.identity.addressPostalSimilar);
- //result.client.identity.taxResidenceRFOnly = handleCheckbox(result.client.identity.taxResidenceRFOnly);
- result.client.identity.russianBankAccount = handleCheckbox(result.client.identity.russianBankAccount);
- //if (result.client.sendLinkToEmail) {
- result.client.sendLinkToEmail = handleCheckbox(result.client.sendLinkToEmail);
- //}
- if (data.bankAbroad) {
- result.client.bankAbroad.check = handleCheckbox(result.client.bankAbroad.check);
- if (result.client.bankAbroad.countries) {
- result.formData.bankAbroad = setActiveCheckboxes(result.formData.bankAbroad, result.client.bankAbroad, ['countries']);
- }
- }
- if (data.ip) {
- result.client.ip.check = handleCheckbox(result.client.ip.check);
- if (data.ip.licenses) {
- result.client.ip.licenses.check = handleCheckbox(result.client.ip.licenses.check);
- }
- }
- if (result.client.identity.pdl !== undefined && result.client.identity.pdl !== null && typeof result.client.identity.pdl == 'object') {
- result.client.identity.pdl.isForeign = handleCheckbox(result.client.identity.pdl.isForeign);
- result.client.identity.pdl.isInternational = handleCheckbox(result.client.identity.pdl.isInternational);
- result.client.identity.pdl.isRussian = handleCheckbox(result.client.identity.pdl.isRussian);
- result.client.identity.pdl.isRelative = handleCheckbox(result.client.identity.pdl.isRelative);
- /*
- if (!result.client.identity.pdl.check) {
- result.client.identity.pdl = null;
- }
- */
- if (result.client.identity.pdl) {
- /*
- if (result.client.identity.pdl.who) {
- result.client.identity.pdl['whoIs' + format.upperFirst(result.client.identity.pdl.who)] = 1;
- }
- */
- /*if (user.identity.pdl.relationDegree !== null && typeof user.identity.pdl.check == 'object') {
- user.identity.pdl['whoIs' + format.upperFirst(user.identity.pdl.who)] = true;
- }*/
- /*
- if (result.client.identity.pdl && result.client.identity.pdl.relationDegree) {
- for (let i = 0; i < result.formData.pdl.relationDegree.length; ++i) {
- if (result.client.identity.pdl.relationDegree == result.formData.pdl.relationDegree[i].id) {
- result.formData.pdl.relationDegree[i].active = 1;
- }
- }
- }
- */
- }
- }
- if (result.client.identity.previousPassports) {
- for (let index in result.client.identity.previousPassports) {
- result.client.identity.previousPassports[index].index = index;
- if (errors && errors.identity && errors.identity.previousPassports && errors.identity.previousPassports[index]) {
- result.client.identity.previousPassports[index].error = errors.identity.previousPassports[index];
- }
- if (datesHelper.parseDateSmart(result.client.identity.previousPassports[index].issueDate)) {
- result.client.identity.previousPassports[index].issueDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.identity.previousPassports[index].issueDate));
- }
- }
- }
- if (result.client.representative && result.client.representative.principals) {
- for (let index in result.client.representative.principals) {
- result.client.representative.principals[index].index = index;
- result.client.representative.principals[index].form = setActiveCheckboxes({ passportType: copyObjectsArray(passportTypes) }, result.client.representative.principals[index], ['passportType'], true);
- if (errors && errors.representative && errors.representative.principals && errors.representative.principals[index]) {
- result.client.representative.principals[index].error = errors.representative.principals[index];
- }
- if (datesHelper.parseDateSmart(result.client.representative.principals[index].issueDate)) {
- result.client.representative.principals[index].issueDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.representative.principals[index].issueDate));
- }
- if (datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyIssueDate)) {
- result.client.representative.principals[index].attorneyIssueDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyIssueDate));
- }
- if (datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyStartDate)) {
- result.client.representative.principals[index].attorneyStartDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyStartDate));
- }
- if (datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyExpiryDate)) {
- result.client.representative.principals[index].attorneyExpiryDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyExpiryDate));
- }
- result.client.representative.principals[index].attorneyWithoutExpiryDate = handleCheckbox(result.client.representative.principals[index].attorneyWithoutExpiryDate);
- }
- }
- if (datesHelper.parseDateSmart(data.identity.issueDate)) {
- data.identity.issueDate = datesHelper.getDate(datesHelper.parseDateSmart(data.identity.issueDate));
- }
- if (datesHelper.parseDateSmart(data.identity.birthDate)) {
- data.identity.birthDate = datesHelper.getDate(datesHelper.parseDateSmart(data.identity.birthDate));
- }
- if (data.migration) {
- if (datesHelper.parseDateSmart(data.migration.startDate)) {
- data.migration.startDate = datesHelper.getDate(datesHelper.parseDateSmart(data.migration.startDate));
- }
- if (datesHelper.parseDateSmart(data.migration.endDate)) {
- data.migration.endDate = datesHelper.getDate(datesHelper.parseDateSmart(data.migration.endDate));
- }
- }
- if (data.rightDoc) {
- if (datesHelper.parseDateSmart(data.rightDoc.startDate)) {
- data.rightDoc.startDate = datesHelper.getDate(datesHelper.parseDateSmart(data.rightDoc.startDate));
- }
- if (datesHelper.parseDateSmart(data.rightDoc.endDate)) {
- data.rightDoc.endDate = datesHelper.getDate(datesHelper.parseDateSmart(data.rightDoc.endDate));
- }
- }
- }
- return result;
- }
- function bank(client, post) {
- if (post) {
- client = merge(client, post);
- }
- if (post) {
- if (post.identity.agree) {
- client.identity.agree = handleCheckbox(post.identity.agree);
- }
- }
- return {
- client: client
- };
- }
- function terrorist(data, post, formData) {
- formData = formData || {};
- if (post) {
- data = merge(data, post);
- }
- return {
- terrorist: data,
- formData: formData
- };
- }
- function iccntrib(data, post, formData) {
- formData = formData || {};
- if (post) {
- data = merge(data, post);
- }
- if (datesHelper.parseDateSmart(data.birthDate)) {
- data.birthDate = datesHelper.getDate(datesHelper.parseDateSmart(data.birthDate));
- }
- return {
- iccntrib: data,
- formData: formData
- };
- }
- function message(data, post, formData) {
- formData = formData || {};
- if (post) {
- data = merge(data, post);
- }
- if (data) {
- if (datesHelper.parseDateSmart(data.dateTime)) {
- data.dateTime = datesHelper.getDateTime(datesHelper.parseDateSmart(data.dateTime));
- }
- data.isPopup = handleCheckbox(data.isPopup);
- }
- return {
- message: data,
- formData: formData
- };
- }
- function report(data, post, formData) {
- formData = formData || {};
- if (post) {
- data = merge(data, post);
- }
- if (data.fund) {
- formData.funds = setActiveCheckboxes(formData, data, ['fund']);
- }
- return {
- report: data,
- formData: formData
- };
- }
- function fund(data, post, formData) {
- formData = formData || {};
- if (post) {
- data = merge(data, post);
- }
- if (FUND_STATUS_CAPTIONS[data.status]) {
- data.statusStr = FUND_STATUS_CAPTIONS[data.status];
- }
- if (datesHelper.parseDateSmart(data.stopReceivingFundsDate)) {
- data.stopReceivingFundsDate = datesHelper.getDate(datesHelper.parseDateSmart(data.stopReceivingFundsDate));
- }
- if (datesHelper.parseDateSmart(data.formationFromDate)) {
- data.formationFromDate = datesHelper.getDate(datesHelper.parseDateSmart(data.formationFromDate));
- }
- if (datesHelper.parseDateSmart(data.formationToDate)) {
- data.formationToDate = datesHelper.getDate(datesHelper.parseDateSmart(data.formationToDate));
- }
- if (datesHelper.parseDateSmart(data.startInvestingDate)) {
- data.startInvestingDate = datesHelper.getDate(datesHelper.parseDateSmart(data.startInvestingDate));
- }
- if (datesHelper.parseDateSmart(data.endDate)) {
- data.endDate = datesHelper.getDate(datesHelper.parseDateSmart(data.endDate));
- }
- if (datesHelper.parseDateSmart(data.stopReceivingFundsDelayedDate)) {
- data.stopReceivingFundsDelayedDate = datesHelper.getDate(datesHelper.parseDateSmart(data.stopReceivingFundsDelayedDate));
- }
- if (datesHelper.parseDateSmart(data.startInvestingDelayedDate)) {
- data.startInvestingDelayedDate = datesHelper.getDate(datesHelper.parseDateSmart(data.startInvestingDelayedDate));
- }
- if (datesHelper.parseDateSmart(data.endDelayedDate)) {
- data.endDelayedDate = datesHelper.getDate(datesHelper.parseDateSmart(data.endDelayedDate));
- }
- return {
- fund: data,
- formData: formData
- };
- }
- function reserveNumbers(data, post, formData) {
- formData = formData || {};
- if (post) {
- data = merge(data, post);
- }
- if (data) {
- formData = setActiveCheckboxes(formData, data, ['fundShareId', 'type']);
- }
- return {
- item: data,
- formData: formData
- };
- }
- function clientFormFooter(data, post, formData, errors) {
- formData = formData || {};
- formData.beneficialOwner = [
- { id: 'positive', caption: 'Положительное' },
- { id: 'negative', caption: 'Отрицательное' }
- ];
- formData.financialPosition = [
- { id: 'positive', caption: 'Удовлетворительное' },
- { id: 'negative', caption: 'Отрицательное' },
- { id: 'unavailable', caption: 'Не определено' }
- ];
- formData.businessReputation = [
- { id: 'positive', caption: 'Положительная' },
- { id: 'negative', caption: 'Отрицательная' },
- { id: 'unavailable', caption: 'Не определена' }
- ];
- formData.businessReputation = [
- { id: 'positive', caption: 'Положительное' },
- { id: 'negative', caption: 'Отрицательное' },
- { id: 'unavailable', caption: 'Не определено' }
- ];
- formData.isTerroristCheck = [
- { id: 'false', caption: 'Отсутствие информации' },
- { id: 'true', caption: 'Наличие информации' },
- ];
- formData.riskLevel = [
- { id: 'low', caption: 'Низкий' },
- { id: 'high', caption: 'Высокий' },
- ];
- formData.isRiskLevelChanged = [
- { id: 'false', caption: 'Нет' },
- { id: 'true', caption: 'Да' },
- ];
- if (post) {
- data = merge(data, post);
- }
- if (data) {
- }
- if (datesHelper.parseDateSmart(data.relationshipStartDate)) {
- data.relationshipStartDate = datesHelper.getDate(datesHelper.parseDateSmart(data.relationshipStartDate));
- }
- if (datesHelper.parseDateSmart(data.relationshipEndDate)) {
- data.relationshipEndDate = datesHelper.getDate(datesHelper.parseDateSmart(data.relationshipEndDate));
- }
- if (datesHelper.parseDateSmart(data.terroristsListDate)) {
- data.terroristsListDate = datesHelper.getDate(datesHelper.parseDateSmart(data.terroristsListDate));
- }
- if (Array.isArray(data.formUpdateDates)) {
- for (let index = 0; index < data.formUpdateDates.length; ++index) {
- let value = data.formUpdateDates[index];
- if (value && datesHelper.parseDateSmart(value)) {
- value = datesHelper.getDate(datesHelper.parseDateSmart(value));
- }
- let item = {
- value: value,
- index: index
- };
- if (errors && errors.formUpdateDates && errors.formUpdateDates[index]) {
- item.error = errors.formUpdateDates[index];
- }
- data.formUpdateDates[index] = item;
- }
- }
- if (Array.isArray(data.terroristCheckDates)) {
- for (let index = 0; index < data.terroristCheckDates.length; ++index) {
- let value = data.terroristCheckDates[index];
- if (value && datesHelper.parseDateSmart(value)) {
- value = datesHelper.getDate(datesHelper.parseDateSmart(value));
- }
- let item = {
- value: value,
- index: index
- };
- if (errors && errors.terroristCheckDates && errors.terroristCheckDates[index]) {
- item.error = errors.terroristCheckDates[index];
- }
- data.terroristCheckDates[index] = item;
- }
- }
- if (data.clientAcceptedBy && typeof data.clientAcceptedBy == 'object') {
- if (datesHelper.parseDateSmart(data.clientAcceptedBy.date)) {
- data.clientAcceptedBy.date = datesHelper.getDate(datesHelper.parseDateSmart(data.clientAcceptedBy.date));
- }
- }
- if (data.clientUpdatedBy && typeof data.clientUpdatedBy == 'object') {
- if (datesHelper.parseDateSmart(data.clientUpdatedBy.date)) {
- data.clientUpdatedBy.date = datesHelper.getDate(datesHelper.parseDateSmart(data.clientUpdatedBy.date));
- }
- }
- formData = setActiveCheckboxes(formData, data, ['beneficialOwner', 'financialPosition', 'businessReputation', 'isTerroristCheck', 'riskLevel', 'isRiskLevelChanged']);
- return {
- item: data,
- formData: formData
- };
- }
- module.exports.handleCheckbox = handleCheckbox;
- module.exports.rename = rename;
- module.exports.merge = merge;
- module.exports.user = user;
- module.exports.role = role;
- module.exports.entity = entity;
- module.exports.client = client;
- module.exports.bank = bank;
- module.exports.terrorist = terrorist;
- module.exports.iccntrib = iccntrib;
- module.exports.message = message;
- module.exports.report = report;
- module.exports.fund = fund;
- module.exports.reserveNumbers = reserveNumbers;
- module.exports.clientFormFooter = clientFormFooter;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement