Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let datesHelper = require('../utils/dates-helper')
  2.     , PASSPORT_TYPES = require('../utils/passport-types')
  3.     , format = require('../utils/format')
  4.     , PRODUCT_TYPES = require('../utils/product-types').formData
  5.     ;
  6.  
  7. const FUND_STATUS_CAPTIONS = require('../utils/doc-statuses').fundStatusCaptions;
  8.  
  9. function rename(obj) {
  10.     if (typeof obj !== 'object')
  11.         return obj;
  12.  
  13.     for (let key in obj) {
  14.         if (key.indexOf('.') !== -1) {
  15.             let keyArr = key.split('.');
  16.             let newKey = keyArr[0];
  17.             let nextKey = keyArr.slice(1).join('.');
  18.  
  19.             if (!obj[newKey] || typeof obj[newKey] !== 'object')
  20.                 obj[newKey] = {};
  21.  
  22.             obj[newKey][nextKey] = obj[key];
  23.             delete obj[key];
  24.             key = newKey;
  25.         }
  26.         if (typeof obj[key] === 'object') {
  27.             obj[key] = rename(obj[key]);
  28.         }
  29.     }
  30.  
  31.     return obj;
  32. }
  33.  
  34. function merge() {
  35.     let result = {};
  36.     if (arguments[0] instanceof Array) {
  37.         result = [];
  38.     }
  39.  
  40.     for (let i = 0; i < arguments.length; ++i) {
  41.         let obj = arguments[i];
  42.         if (typeof obj !== 'object')
  43.             continue;
  44.  
  45.         for (let key in obj) {
  46.             if (obj[key] !== null && typeof obj[key] === 'object') {
  47.                 if (!result[key]) {
  48.                     if (obj[key] instanceof Array) {
  49.                         result[key] = [];
  50.                     } else {
  51.                         result[key] = {};
  52.                     }
  53.                 }
  54.  
  55.                 result[key] = merge(result[key], obj[key]);
  56.             } else {
  57.                 result[key] = obj[key];
  58.             }
  59.         }
  60.     }
  61.  
  62.     return result;
  63. }
  64.  
  65. function setActiveCheckboxes(formData, postData, keys, formDataHack) {
  66.     formData = Object.assign({}, formData);
  67.     if (!keys || !postData) {
  68.         return formData;
  69.     }
  70.     if (!Array.isArray(keys)) {
  71.         keys = [keys];
  72.     }
  73.     for (let key of keys) {
  74.         if (!formData[key] || !postData[key]) {
  75.             continue;
  76.         }
  77.         for (let formItem of formData[key]) {
  78.             delete formItem.active;
  79.             if (formItem._id) {
  80.                 if (Array.isArray(postData[key])) {
  81.                     if (postData[key].indexOf(formItem._id) !== -1) {
  82.                         formItem.active = formDataHack ? "true" : true;
  83.                     }
  84.                 } else {
  85.                     if (postData[key] == formItem._id) {
  86.                         formItem.active = formDataHack ? "true" : true;
  87.                     }
  88.                 }
  89.             }
  90.             if (formItem.id) {
  91.                 if (Array.isArray(postData[key])) {
  92.                     if (postData[key].indexOf(formItem.id) !== -1) {
  93.                         formItem.active = formDataHack ? "true" : true;
  94.                     }
  95.                 } else {
  96.                     if (postData[key] == formItem.id) {
  97.                         formItem.active = formDataHack ? "true" : true;
  98.                     }
  99.                 }
  100.             }
  101.         }
  102.     }
  103.  
  104.     return formData;
  105. }
  106.  
  107. function copyObjectsArray (arr) {
  108.     let result = [];
  109.     for (let item of arr) {
  110.         if (typeof item == 'object' && !Array.isArray(item)) {
  111.             result.push(Object.assign({}, item));
  112.         } else {
  113.             result.push(item);
  114.         }
  115.     }
  116.  
  117.     return result;
  118. }
  119.  
  120. function user(user, post, formData) {
  121.     if (post) {
  122.         user = merge(user, post);
  123.     }
  124.  
  125.     formData.passportType = [
  126.         { id: 'RF_PASSPORT', caption: 'Паспорт гражданина РФ' }
  127.     ];
  128.     formData.macroSegment = [
  129.         { id: 'Retail', caption: 'Retail' },
  130.         { id: 'VIP', caption: 'VIP' }
  131.     ]
  132.  
  133.     user.macroSegment = !Array.isArray(user.macroSegment) ? [ user.macroSegment ] : user.macroSegment;
  134.     user.macroSegment = user.macroSegment.filter((item) => { return !!item });
  135.  
  136.     formData = setActiveCheckboxes(formData, user, ['roles', 'rules', 'macroSegment']);
  137.     if (post) {
  138.         if (post.isPersonalManager) {
  139.             user.isPersonalManager = handleCheckbox(post.isPersonalManager);
  140.         }
  141.         if (post.sendCredentialsLink) {
  142.             user.sendCredentialsLink = handleCheckbox(post.sendCredentialsLink);
  143.         }
  144.     }
  145.  
  146.     return {
  147.         user: user,
  148.         formData: formData
  149.     };
  150. }
  151.  
  152. function role(role, post, formData) {
  153.     if (post) {
  154.         role = merge(role, post);
  155.     }
  156.  
  157.     formData.parentEntityTypes = formData.parentEntityTypes || [
  158.         {
  159.             _id: 'management-company',
  160.             caption: 'УК'
  161.         }, {
  162.             _id: 'agent',
  163.             caption: 'Агент'
  164.         }, {
  165.             _id: 'app-point',
  166.             caption: 'ППЗ'
  167.         }/*, {
  168.             _id: 'work-station',
  169.             caption: 'РМ'
  170.         }*/
  171.     ]
  172.  
  173.     formData = setActiveCheckboxes(formData, post, ['rules', 'parentEntityTypes']);
  174.     if (post.isCompanyStaff) {
  175.         role.isCompanyStaff = handleCheckbox(role.isCompanyStaff);
  176.     }
  177.     if (post.isAgentAdmin) {
  178.         role.isAgentAdmin = handleCheckbox(role.isAgentAdmin);
  179.     }
  180.     if (post.isAdmin) {
  181.         role.isAdmin = handleCheckbox(role.isAdmin);
  182.     }
  183.     if (post.isClientManagerShareFunds) {
  184.         role.isClientManagerShareFunds = handleCheckbox(role.isClientManagerShareFunds);
  185.     }
  186.     if (post.isClientManagerTrustContracts) {
  187.         role.isClientManagerTrustContracts = handleCheckbox(role.isClientManagerTrustContracts);
  188.     }
  189.     if (post.isParentEntityFixed) {
  190.         role.isParentEntityFixed = handleCheckbox(role.isParentEntityFixed);
  191.     }
  192.     if (post.isJournalObserver) {
  193.         role.isJournalObserver = handleCheckbox(role.isJournalObserver);
  194.     }
  195.  
  196.     return {
  197.         role: role,
  198.         formData: formData
  199.     };
  200. }
  201.  
  202. function handleCheckbox(val) {
  203.     if (val && typeof val == 'object' && val !== null) {
  204.         val = true;
  205.     } else {
  206.         val = !!+val;
  207.     }
  208.  
  209.     return val ? 1 : 0;
  210. }
  211.  
  212. function entityAgent(data) {
  213.     let result = {
  214.         formData: {},
  215.         item: data
  216.     };
  217.  
  218.     result.formData.addressFactObj = {
  219.         country: [
  220.             { id: '', caption: 'Выберите из списка' },
  221.             { id: 'РФ', caption: 'РФ' },
  222.             { id: 'США', caption: 'США' },
  223.             { id: 'other', caption: 'Иное государство' }
  224.         ]
  225.     };
  226.     result.formData.addressRegistrationObj = {
  227.         country: [
  228.             { id: '', caption: 'Выберите из списка' },
  229.             { id: 'РФ', caption: 'РФ' },
  230.             { id: 'США', caption: 'США' },
  231.             { id: 'other', caption: 'Иное государство' }
  232.         ]
  233.     };
  234.     result.formData.allowedRegistrationMethods = [
  235.         { id: 'bypassword', caption: 'Логин-пароль' },
  236.         { id: 'byesia', caption: 'Госуслуги' }
  237.     ];
  238.     result.formData.productTypes = PRODUCT_TYPES.map((item) => { return Object.assign({}, item) });
  239.  
  240.     if (typeof result.item.appPointCodeLength == 'number') {
  241.         result.item.appPointCodeLength = result.item.appPointCodeLength.toString();
  242.     }
  243.     if (typeof result.item.trustContractsAppPointCodeLength == 'number') {
  244.         result.item.trustContractsAppPointCodeLength = result.item.trustContractsAppPointCodeLength.toString();
  245.     }
  246.     if (typeof result.item.workStationCodeLength == 'number') {
  247.         result.item.workStationCodeLength = result.item.workStationCodeLength.toString();
  248.     }
  249.     if (typeof result.item.trustContractsWorkStationCodeLength == 'number') {
  250.         result.item.trustContractsWorkStationCodeLength = result.item.trustContractsWorkStationCodeLength.toString();
  251.     }
  252.  
  253.     if (data) {
  254.         result.formData = setActiveCheckboxes(result.formData, result.item, ['productTypes', 'allowedRegistrationMethods']);
  255.         if (data.addressRegistrationObj) {
  256.             result.formData.addressRegistrationObj = setActiveCheckboxes(result.formData.addressRegistrationObj, result.item.addressRegistrationObj, ['country']);
  257.             result.item.addressRegistrationObj.noStreet = handleCheckbox(result.item.addressRegistrationObj.noStreet);
  258.         }
  259.         if (data.addressFactObj) {
  260.             result.formData.addressFactObj = setActiveCheckboxes(result.formData.addressFactObj, result.item.addressFactObj, ['country']);
  261.             result.item.addressFactObj.noStreet = handleCheckbox(result.item.addressFactObj.noStreet);
  262.         }
  263.         result.item.isTwoFactorAuthEnabled = handleCheckbox(result.item.isTwoFactorAuthEnabled);
  264.         result.item.isSeparateEDMExists = handleCheckbox(result.item.isSeparateEDMExists);
  265.     }
  266.  
  267.     return result;
  268. }
  269.  
  270. function entityMC(data) {
  271.     let result = {
  272.         formData: {},
  273.         item: data
  274.     };
  275.  
  276.     return result;
  277. }
  278.  
  279. function entityAP(data, formData) {
  280.     let result = {
  281.         formData: {},
  282.         item: data
  283.     };
  284.  
  285.     result.formData.productTypes = PRODUCT_TYPES.map((item) => { return Object.assign({}, item) });
  286.     if (!formData || !formData.parentItem || !Array.isArray(formData.parentItem.productTypes)) {
  287.         result.formData.productTypes = [];
  288.     } else {
  289.         result.formData.productTypes = result.formData.productTypes.filter((item) => { return formData.parentItem.productTypes.indexOf(item.id) !== -1 });
  290.     }
  291.  
  292.     result.formData.addressFactObj = {
  293.         country: [
  294.             { id: '', caption: 'Выберите из списка' },
  295.             { id: 'РФ', caption: 'РФ' },
  296.             { id: 'США', caption: 'США' },
  297.             { id: 'other', caption: 'Иное государство' }
  298.         ]
  299.     };
  300.  
  301.     if (data) {
  302.         result.formData = setActiveCheckboxes(result.formData, result.item, ['productTypes']);
  303.         if (data.addressFactObj) {
  304.             result.formData.addressFactObj = setActiveCheckboxes(result.formData.addressFactObj, result.item.addressFactObj, ['country']);
  305.             result.item.addressFactObj.noStreet = handleCheckbox(result.item.addressFactObj.noStreet);
  306.         }
  307.     }
  308.  
  309.     return result;
  310. }
  311.  
  312. function entityWS(data) {
  313.     let result = {
  314.         formData: {},
  315.         item: data
  316.     };
  317.  
  318.     return result;
  319. }
  320.  
  321. function entity(data, post, formData /* TODO: remove ? */, errors) {
  322.     if (post) {
  323.         data = merge(data, post);
  324.     }
  325.  
  326.     let result;
  327.     if (data.type == 'management-company') {
  328.         result = entityMC(data);
  329.     } else if (data.type == 'agent') {
  330.         result = entityAgent(data);
  331.     } else if (data.type == 'app-point') {
  332.         result = entityAP(data, formData);
  333.     } else if (data.type == 'work-station') {
  334.         result = entityWS(data);
  335.     } else {
  336.         return false;
  337.         //throw new Error('Unknown entity type: ' + data.type);
  338.     }
  339.  
  340.     return result;
  341. }
  342.  
  343. function client(data, post, formData /* TODO: remove ? */, errors) {
  344.     if (data) {
  345.         if (!data.bank) {
  346.             data.bank = {};
  347.         }
  348.         if (!data.bankUSD) {
  349.             data.bankUSD = {};
  350.         }
  351.         if (!data.bankEUR) {
  352.             data.bankEUR = {};
  353.         }
  354.  
  355.         if (!data.bank.recipient) {
  356.             data.bank.recipient = data.identity.surname + ' ' + data.identity.name + ' ' + data.identity.patronymic;
  357.             data.bank.recipient = data.bank.recipient.trim();
  358.         }
  359.         if (!data.bankUSD.recipient) {
  360.             data.bankUSD.recipient = data.identity.surname + ' ' + data.identity.name + ' ' + data.identity.patronymic;
  361.             data.bankUSD.recipient = data.bankUSD.recipient.trim();
  362.         }
  363.         if (!data.bankEUR.recipient) {
  364.             data.bankEUR.recipient = data.identity.surname + ' ' + data.identity.name + ' ' + data.identity.patronymic;
  365.             data.bankEUR.recipient = data.bankEUR.recipient.trim();
  366.         }
  367.     }
  368.  
  369.     if (post) {
  370.         data = merge(data, post);
  371.     }
  372.  
  373.     let result = {
  374.         formData: {},
  375.         client: data //TODO: client => item ?
  376.     };
  377.  
  378.     let multipleIdentityFields = ["sourceOfFunds", "citizenship"];
  379.  
  380.     let passportTypes = [];
  381.     for (let docType in PASSPORT_TYPES) {
  382.         passportTypes.push({
  383.             id: docType, caption: PASSPORT_TYPES[docType]
  384.         });
  385.     }
  386.     result.formData.passportType = copyObjectsArray(passportTypes);
  387.     result.formData.citizenship = [
  388.         { id: 'РФ', caption: 'РФ' },
  389.         { id: 'США', caption: 'США' },
  390.         { id: 'other', caption: 'Иное государство' },
  391.         { id: 'Лицо без гражданства', caption: 'Лицо без гражданства' }
  392.     ];
  393.     result.formData.birthCountry = [
  394.         { id: '', caption: 'Выберите из списка' },
  395.         { id: 'США', caption: 'США' },
  396.         { id: 'РФ', caption: 'РФ' },
  397.         { id: 'other', caption: 'Иное государство' }
  398.     ];
  399.     result.formData.addressFactObj = {
  400.         country: [
  401.             { id: '', caption: 'Выберите из списка' },
  402.             { id: 'РФ', caption: 'РФ' },
  403.             { id: 'США', caption: 'США' },
  404.             { id: 'other', caption: 'Иное государство' }
  405.         ]
  406.     };
  407.     result.formData.addressRegistrationObj = {
  408.         country: [
  409.             { id: '', caption: 'Выберите из списка' },
  410.             { id: 'РФ', caption: 'РФ' },
  411.             { id: 'США', caption: 'США' },
  412.             { id: 'other', caption: 'Иное государство' }
  413.         ]
  414.     };
  415.     result.formData.addressPostalObj = {
  416.         country: [
  417.             { id: '', caption: 'Выберите из списка' },
  418.             { id: 'РФ', caption: 'РФ' },
  419.             { id: 'США', caption: 'США' },
  420.             { id: 'other', caption: 'Иное государство' }
  421.         ]
  422.     };
  423.     result.formData.goal = [
  424.         { id: '', caption: 'Выберите из списка' },
  425.         { id: 'Инвестирование личных сбережений', caption: 'Инвестирование личных сбережений' },
  426.         { id: 'goal_add', caption: 'Иное (указать)' }
  427.     ];
  428.     result.formData.pdl = {};
  429.     result.formData.pdl.relationDegree = [
  430.         { id: '', caption: 'Выберите из списка' },
  431.         { id: 'Супруг(а)', caption: 'Супруг(а)' },
  432.         { id: 'Родитель / усыновитель', caption: 'Родитель / усыновитель' },
  433.         { id: 'Опекун / попечитель', caption: 'Опекун / попечитель' },
  434.         { id: 'Ребенок (в т.ч. усыновленный)', caption: 'Ребенок (в т.ч. усыновленный)' },
  435.         { id: 'Брат / сестра', caption: 'Брат / сестра' },
  436.         { id: 'Дедушка / бабушка', caption: 'Дедушка / бабушка' },
  437.         { id: 'Внук / внучка', caption: 'Внук / внучка' },
  438.         { id: 'relationDegree_add', caption: 'Иное (указать)' }
  439.     ];
  440.     result.formData.beneficialOwner = [
  441.         { id: 'none', caption: 'Отсутствует' },
  442.         { id: 'confirmed', caption: 'Наличие бенефициарного владельца подтверждается физ.лицом' }
  443.     ];
  444.     result.formData.beneficiary = [
  445.         { id: 'Физ. лицо действует к собственной выгоде', caption: 'Физ. лицо действует к собственной выгоде' },
  446.         { id: 'Иное лицо', caption: 'Иное лицо' }
  447.     ];
  448.     result.formData.economicActivities = [
  449.         { id: 'Получение дохода', caption: 'Получение дохода' },
  450.         { id: 'economicActivities_add', caption: 'Иное' }
  451.     ];
  452.     result.formData.financialPosition = [
  453.         { id: 'Отсутствуют проблемы с исполнением финансовых обязательств', caption: 'Отсутствуют проблемы с исполнением финансовых обязательств' },
  454.         { id: 'financialPosition_add', caption: 'Иное' }
  455.     ];
  456.     result.formData.businessReputation = [
  457.         { id: 'none', caption: 'Отсутствуют' },
  458.         { id: 'confirmed', caption: 'Рекомендации прилагаются' }
  459.     ];
  460.     result.formData.sourceOfFunds = [
  461.         { id: 'Заработная плата', caption: 'Заработная плата' },
  462.         { id: 'Продажа имущества', caption: 'Продажа имущества' },
  463.         { id: 'Дивиденды', caption: 'Дивиденды' },
  464.         { id: 'Доходы от предпринимательской деятельности', caption: 'Доходы от предпринимательской деятельности' },
  465.         { id: 'Пенсия', caption: 'Пенсия' },
  466.         { id: 'Наследство', caption: 'Наследство' },
  467.         { id: 'Личные сбережения', caption: 'Личные сбережения' },
  468.         { id: 'sourceOfFunds_add', caption: 'Иные источники' }
  469.     ];
  470.     result.formData.types = [
  471.         { id: 'client', caption: 'Клиент' },
  472.         { id: 'representative', caption: 'Представитель' }
  473.     ];
  474.     result.formData.residence = [
  475.         { id: 'empty', caption: 'Выберите из списка, если есть' },
  476.         { id: 'США', caption: 'США' },
  477.         { id: 'other', caption: 'Иное государство' }
  478.     ];
  479.     result.formData.birthCountry = [
  480.         { id: '', caption: 'Выберите из списка' },
  481.         { id: 'РФ', caption: 'РФ' },
  482.         { id: 'США', caption: 'США' },
  483.         { id: 'other', caption: 'Иное государство' }
  484.     ];
  485.     result.formData.phoneCode = [
  486.         { id: '+7', caption: '+7' },
  487.         { id: '+1', caption: '+1' },
  488.         { id: '+20', caption: '+20' },
  489.         { id: '+212', caption: '+212' },
  490.         { id: '+213', caption: '+213' }
  491.     ];
  492.    
  493.     result.formData.bankAbroad = {
  494.         countries: [
  495.             { id: 'Австралия', caption: 'Австралия' },
  496.             { id: 'Австрия', caption: 'Австрия' },
  497.             { id: 'Андорра', caption: 'Андорра' },
  498.             { id: 'Аргентина', caption: 'Аргентина' },
  499.             { id: 'Бельгия', caption: 'Бельгия' },
  500.             { id: 'Болгария', caption: 'Болгария' },
  501.             { id: 'Бразилия', caption: 'Бразилия' },
  502.             { id: 'Великобритания', caption: 'Великобритания' },
  503.             { id: 'Венгрия', caption: 'Венгрия' },
  504.             { id: 'Германия', caption: 'Германия' },
  505.             { id: 'Гернси', caption: 'Гернси' },
  506.             { id: 'Гибралтар', caption: 'Гибралтар' },
  507.             { id: 'Гренландия', caption: 'Гренландия' },
  508.             { id: 'Греция', caption: 'Греция' },
  509.             { id: 'Дания', caption: 'Дания' },
  510.             { id: 'Джерси', caption: 'Джерси' },
  511.             { id: 'Индия', caption: 'Индия' },
  512.             { id: 'Индонезия', caption: 'Индонезия' },
  513.             { id: 'Ирландия', caption: 'Ирландия' },
  514.             { id: 'Исландия', caption: 'Исландия' },
  515.             { id: 'Испания', caption: 'Испания' },
  516.             { id: 'Италия', caption: 'Италия'},
  517.             { id: 'Китай', caption: 'Китай' },
  518.             { id: 'Колумбия', caption: 'Колумбия' },
  519.             { id: 'Корея', caption: 'Корея' },
  520.             { id: 'Литва', caption: 'Литва' },
  521.             { id: 'Лихтенштейн', caption: 'Лихтенштейн' },
  522.             { id: 'Люксембург', caption: 'Люксембург' },
  523.             { id: 'Маврикий', caption: 'Маврикий' },
  524.             { id: 'Малайзия', caption: 'Малайзия' },
  525.             { id: 'Мальта', caption: 'Мальта' },
  526.             { id: 'Мексика', caption: 'Мексика' },
  527.             { id: 'Нидерланды', caption: 'Нидерланды' },
  528.             { id: 'Новая Зеландия', caption: 'Новая Зеландия' },
  529.             { id: 'Норвегия', caption: 'Норвегия' },
  530.             { id: 'Остров Мэн', caption: 'Остров Мэн' },
  531.             { id: 'Пакистан', caption: 'Пакистан' },
  532.             { id: 'Польша', caption: 'Польша' },
  533.             { id: 'Португалия', caption: 'Португалия' },
  534.             { id: 'Республика Словакия', caption: 'Республика Словакия' },
  535.             { id: 'Сан Марино', caption: 'Сан Марино' },
  536.             { id: 'Саудовская Аравия', caption: 'Саудовская Аравия' },
  537.             { id: 'Сейшелы', caption: 'Сейшелы' },
  538.             { id: 'Сингапур', caption: 'Сингапур' },
  539.             { id: 'Словения', caption: 'Словения' },
  540.             { id: 'Уругвай', caption: 'Уругвай' },
  541.             { id: 'Фарерские острова', caption: 'Фарерские острова' },
  542.             { id: 'Финляндия', caption: 'Финляндия' },
  543.             { id: 'Франция', caption: 'Франция' },
  544.             { id: 'Хорватия', caption: 'Хорватия' },
  545.             { id: 'Чешская республика', caption: 'Чешская республика' },
  546.             { id: 'Чили', caption: 'Чили' },
  547.             { id: 'Швейцария', caption: 'Швейцария' },
  548.             { id: 'Швеция', caption: 'Швеция' },
  549.             { id: 'Эстония', caption: 'Эстония' },
  550.             { id: 'ЮАР', caption: 'ЮАР' },
  551.             { id: 'Япония', caption: 'Япония' },
  552.             { id: 'other', caption: 'Иное государство' }
  553.         ]
  554.     };
  555.     result.formData.taxResidence = [
  556.         { id: '', caption: 'Выберите из списка' },
  557.         { id: 'РФ', caption: 'РФ' },
  558.         { id: 'Австралия', caption: 'Австралия' },
  559.         { id: 'Австрия', caption: 'Австрия' },
  560.         { id: 'Андорра', caption: 'Андорра' },
  561.         { id: 'Аргентина', caption: 'Аргентина' },
  562.         { id: 'Бельгия', caption: 'Бельгия' },
  563.         { id: 'Болгария', caption: 'Болгария' },
  564.         { id: 'Бразилия', caption: 'Бразилия' },
  565.         { id: 'Великобритания', caption: 'Великобритания' },
  566.         { id: 'Венгрия', caption: 'Венгрия' },
  567.         { id: 'Германия', caption: 'Германия' },
  568.         { id: 'Гернси', caption: 'Гернси' },
  569.         { id: 'Гибралтар', caption: 'Гибралтар' },
  570.         { id: 'Гренландия', caption: 'Гренландия' },
  571.         { id: 'Греция', caption: 'Греция' },
  572.         { id: 'Дания', caption: 'Дания' },
  573.         { id: 'Джерси', caption: 'Джерси' },
  574.         { id: 'Индия', caption: 'Индия' },
  575.         { id: 'Индонезия', caption: 'Индонезия' },
  576.         { id: 'Ирландия', caption: 'Ирландия' },
  577.         { id: 'Исландия', caption: 'Исландия' },
  578.         { id: 'Испания', caption: 'Испания' },
  579.         { id: 'Италия', caption: 'Италия'},
  580.         { id: 'Китай', caption: 'Китай' },
  581.         { id: 'Колумбия', caption: 'Колумбия' },
  582.         { id: 'Корея', caption: 'Корея' },
  583.         { id: 'Литва', caption: 'Литва' },
  584.         { id: 'Лихтенштейн', caption: 'Лихтенштейн' },
  585.         { id: 'Люксембург', caption: 'Люксембург' },
  586.         { id: 'Маврикий', caption: 'Маврикий' },
  587.         { id: 'Малайзия', caption: 'Малайзия' },
  588.         { id: 'Мальта', caption: 'Мальта' },
  589.         { id: 'Мексика', caption: 'Мексика' },
  590.         { id: 'Нидерланды', caption: 'Нидерланды' },
  591.         { id: 'Новая Зеландия', caption: 'Новая Зеландия' },
  592.         { id: 'Норвегия', caption: 'Норвегия' },
  593.         { id: 'Остров Мэн', caption: 'Остров Мэн' },
  594.         { id: 'Пакистан', caption: 'Пакистан' },
  595.         { id: 'Польша', caption: 'Польша' },
  596.         { id: 'Португалия', caption: 'Португалия' },
  597.         { id: 'Республика Словакия', caption: 'Республика Словакия' },
  598.         { id: 'Сан Марино', caption: 'Сан Марино' },
  599.         { id: 'Саудовская Аравия', caption: 'Саудовская Аравия' },
  600.         { id: 'Сейшелы', caption: 'Сейшелы' },
  601.         { id: 'Сингапур', caption: 'Сингапур' },
  602.         { id: 'Словения', caption: 'Словения' },
  603.         { id: 'США', caption: 'США' },
  604.         { id: 'Уругвай', caption: 'Уругвай' },
  605.         { id: 'Фарерские острова', caption: 'Фарерские острова' },
  606.         { id: 'Финляндия', caption: 'Финляндия' },
  607.         { id: 'Франция', caption: 'Франция' },
  608.         { id: 'Хорватия', caption: 'Хорватия' },
  609.         { id: 'Чешская республика', caption: 'Чешская республика' },
  610.         { id: 'Чили', caption: 'Чили' },
  611.         { id: 'Швейцария', caption: 'Швейцария' },
  612.         { id: 'Швеция', caption: 'Швеция' },
  613.         { id: 'Эстония', caption: 'Эстония' },
  614.         { id: 'ЮАР', caption: 'ЮАР' },
  615.         { id: 'Япония', caption: 'Япония' },
  616.         { id: 'other', caption: 'Иное государство' }
  617.     ];
  618.     result.formData.segment = [
  619.         { id: '', caption: 'Выберите из списка' },
  620.         { id: 'Mass retail', caption: 'Mass retail' },
  621.         { id: 'Premium', caption: 'Premium' },
  622.         { id: 'VIP', caption: 'VIP' }
  623.     ];
  624.  
  625.     if (data) {
  626.         if (post && post.identity) {
  627.             for (let field of multipleIdentityFields) {
  628.                 if (Array.isArray(post.identity[field])) {
  629.                     let pos = post.identity[field].indexOf("");
  630.                     if (pos !== -1) {
  631.                         result.client.identity[field] = [].concat(post.identity[field].slice(0, pos), post.identity[field].slice(pos + 1));
  632.                     }
  633.                 }
  634.             }
  635.         }
  636.  
  637.         result.formData = setActiveCheckboxes(result.formData, result.client.identity, ['passportType', 'citizenship', 'birthCountry', 'goal', 'russianBankAccount', 'taxResidence', 'beneficialOwner', 'beneficiary', 'sourceOfFunds', 'economicActivities', 'financialPosition', 'businessReputation']);
  638.         result.formData.addressFactObj = setActiveCheckboxes(result.formData.addressFactObj, result.client.identity.addressFactObj, ['country']);
  639.         if (data.identity.addressRegistrationObj) {
  640.             result.formData.addressRegistrationObj = setActiveCheckboxes(result.formData.addressRegistrationObj, result.client.identity.addressRegistrationObj, ['country']);
  641.         }
  642.         /*if (data.identity.addressPostalObj) {
  643.             result.formData.addressPostalObj = setActiveCheckboxes(result.formData.addressPostalObj, result.client.identity.addressPostalObj, ['country']);
  644.         }*/
  645.         result.formData.pdl = setActiveCheckboxes(result.formData.pdl, result.client.identity.pdl, ['check', 'relationDegree']);
  646.         result.formData = setActiveCheckboxes(result.formData, result.client.identity, ['types']);
  647.         result.formData = setActiveCheckboxes(result.formData, result.client, ['phoneCode', 'residence', 'segment']);
  648.  
  649.         if (result.client.identity.agree) {
  650.             result.client.identity.agree = handleCheckbox(result.client.identity.agree);
  651.         }
  652.  
  653.         if (result.client.identity.addressFactObj) {
  654.             result.client.identity.addressFactObj.noStreet = handleCheckbox(result.client.identity.addressFactObj.noStreet);
  655.         }
  656.         if (result.client.identity.addressRegistrationObj) {
  657.             result.client.identity.addressRegistrationObj.noStreet = handleCheckbox(result.client.identity.addressRegistrationObj.noStreet);
  658.         }
  659.         /*if (result.client.identity.addressPostalObj) {
  660.             result.client.identity.addressPostalObj.noStreet = handleCheckbox(result.client.identity.addressPostalObj.noStreet);
  661.         }*/
  662.        
  663.         result.client.identity.noPreviousPassports = handleCheckbox(result.client.identity.noPreviousPassports);
  664.         result.client.identity.addressFactSimilar = handleCheckbox(result.client.identity.addressFactSimilar);
  665.         //result.client.identity.addressPostalSimilar = handleCheckbox(result.client.identity.addressPostalSimilar);
  666.         //result.client.identity.taxResidenceRFOnly = handleCheckbox(result.client.identity.taxResidenceRFOnly);
  667.         result.client.identity.russianBankAccount = handleCheckbox(result.client.identity.russianBankAccount);
  668.  
  669.         //if (result.client.sendLinkToEmail) {
  670.             result.client.sendLinkToEmail = handleCheckbox(result.client.sendLinkToEmail);
  671.         //}
  672.         if (data.bankAbroad) {
  673.             result.client.bankAbroad.check = handleCheckbox(result.client.bankAbroad.check);
  674.             if (result.client.bankAbroad.countries) {
  675.                 result.formData.bankAbroad = setActiveCheckboxes(result.formData.bankAbroad, result.client.bankAbroad, ['countries']);
  676.             }
  677.         }
  678.         if (data.ip) {
  679.             result.client.ip.check = handleCheckbox(result.client.ip.check);
  680.             if (data.ip.licenses) {
  681.                 result.client.ip.licenses.check = handleCheckbox(result.client.ip.licenses.check);
  682.             }
  683.         }
  684.  
  685.  
  686.         if (result.client.identity.pdl !== undefined && result.client.identity.pdl !== null && typeof result.client.identity.pdl == 'object') {
  687.             result.client.identity.pdl.isForeign = handleCheckbox(result.client.identity.pdl.isForeign);
  688.             result.client.identity.pdl.isInternational = handleCheckbox(result.client.identity.pdl.isInternational);
  689.             result.client.identity.pdl.isRussian = handleCheckbox(result.client.identity.pdl.isRussian);
  690.             result.client.identity.pdl.isRelative = handleCheckbox(result.client.identity.pdl.isRelative);
  691.    
  692.             /*
  693.             if (!result.client.identity.pdl.check) {
  694.                 result.client.identity.pdl = null;
  695.             }
  696.             */
  697.             if (result.client.identity.pdl) {
  698.                 /*
  699.                 if (result.client.identity.pdl.who) {
  700.                     result.client.identity.pdl['whoIs' + format.upperFirst(result.client.identity.pdl.who)] = 1;
  701.                 }
  702.                 */
  703.                 /*if (user.identity.pdl.relationDegree !== null && typeof user.identity.pdl.check == 'object') {
  704.                     user.identity.pdl['whoIs' + format.upperFirst(user.identity.pdl.who)] = true;
  705.                 }*/
  706.                 /*
  707.                 if (result.client.identity.pdl && result.client.identity.pdl.relationDegree) {
  708.                     for (let i = 0; i < result.formData.pdl.relationDegree.length; ++i) {
  709.                         if (result.client.identity.pdl.relationDegree == result.formData.pdl.relationDegree[i].id) {
  710.                             result.formData.pdl.relationDegree[i].active = 1;
  711.                         }
  712.                     }
  713.                 }
  714.                 */
  715.             }
  716.         }
  717.  
  718.        
  719.         if (result.client.identity.previousPassports) {
  720.             for (let index in result.client.identity.previousPassports) {
  721.                 result.client.identity.previousPassports[index].index = index;
  722.                 if (errors && errors.identity && errors.identity.previousPassports && errors.identity.previousPassports[index]) {
  723.                     result.client.identity.previousPassports[index].error = errors.identity.previousPassports[index];
  724.                 }
  725.                 if (datesHelper.parseDateSmart(result.client.identity.previousPassports[index].issueDate)) {
  726.                     result.client.identity.previousPassports[index].issueDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.identity.previousPassports[index].issueDate));
  727.                 }
  728.             }
  729.         }
  730.        
  731.         if (result.client.representative && result.client.representative.principals) {
  732.             for (let index in result.client.representative.principals) {
  733.                 result.client.representative.principals[index].index = index;
  734.                 result.client.representative.principals[index].form = setActiveCheckboxes({ passportType: copyObjectsArray(passportTypes) }, result.client.representative.principals[index], ['passportType'], true);
  735.                 if (errors && errors.representative && errors.representative.principals && errors.representative.principals[index]) {
  736.                     result.client.representative.principals[index].error = errors.representative.principals[index];
  737.                 }
  738.                 if (datesHelper.parseDateSmart(result.client.representative.principals[index].issueDate)) {
  739.                     result.client.representative.principals[index].issueDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.representative.principals[index].issueDate));
  740.                 }
  741.                 if (datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyIssueDate)) {
  742.                     result.client.representative.principals[index].attorneyIssueDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyIssueDate));
  743.                 }
  744.                 if (datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyStartDate)) {
  745.                     result.client.representative.principals[index].attorneyStartDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyStartDate));
  746.                 }
  747.                 if (datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyExpiryDate)) {
  748.                     result.client.representative.principals[index].attorneyExpiryDate = datesHelper.getDate(datesHelper.parseDateSmart(result.client.representative.principals[index].attorneyExpiryDate));
  749.                 }
  750.                 result.client.representative.principals[index].attorneyWithoutExpiryDate = handleCheckbox(result.client.representative.principals[index].attorneyWithoutExpiryDate);
  751.             }
  752.         }
  753.  
  754.         if (datesHelper.parseDateSmart(data.identity.issueDate)) {
  755.             data.identity.issueDate = datesHelper.getDate(datesHelper.parseDateSmart(data.identity.issueDate));
  756.         }
  757.         if (datesHelper.parseDateSmart(data.identity.birthDate)) {
  758.             data.identity.birthDate = datesHelper.getDate(datesHelper.parseDateSmart(data.identity.birthDate));
  759.         }
  760.  
  761.         if (data.migration) {
  762.             if (datesHelper.parseDateSmart(data.migration.startDate)) {
  763.                 data.migration.startDate = datesHelper.getDate(datesHelper.parseDateSmart(data.migration.startDate));
  764.             }
  765.             if (datesHelper.parseDateSmart(data.migration.endDate)) {
  766.                 data.migration.endDate = datesHelper.getDate(datesHelper.parseDateSmart(data.migration.endDate));
  767.             }
  768.         }
  769.  
  770.         if (data.rightDoc) {
  771.             if (datesHelper.parseDateSmart(data.rightDoc.startDate)) {
  772.                 data.rightDoc.startDate = datesHelper.getDate(datesHelper.parseDateSmart(data.rightDoc.startDate));
  773.             }
  774.             if (datesHelper.parseDateSmart(data.rightDoc.endDate)) {
  775.                 data.rightDoc.endDate = datesHelper.getDate(datesHelper.parseDateSmart(data.rightDoc.endDate));
  776.             }
  777.         }
  778.     }
  779.  
  780.     return result;
  781. }
  782.  
  783. function bank(client, post) {
  784.     if (post) {
  785.         client = merge(client, post);
  786.     }
  787.  
  788.     if (post) {
  789.         if (post.identity.agree) {
  790.             client.identity.agree = handleCheckbox(post.identity.agree);
  791.         }
  792.     }
  793.  
  794.     return {
  795.         client: client
  796.     };
  797. }
  798.  
  799. function terrorist(data, post, formData) {
  800.     formData = formData || {};
  801.  
  802.     if (post) {
  803.         data = merge(data, post);
  804.     }
  805.  
  806.     return {
  807.         terrorist: data,
  808.         formData: formData
  809.     };
  810. }
  811.  
  812. function iccntrib(data, post, formData) {
  813.     formData = formData || {};
  814.  
  815.     if (post) {
  816.         data = merge(data, post);
  817.     }
  818.  
  819.     if (datesHelper.parseDateSmart(data.birthDate)) {
  820.         data.birthDate = datesHelper.getDate(datesHelper.parseDateSmart(data.birthDate));
  821.     }
  822.  
  823.     return {
  824.         iccntrib: data,
  825.         formData: formData
  826.     };
  827. }
  828.  
  829. function message(data, post, formData) {
  830.     formData = formData || {};
  831.  
  832.     if (post) {
  833.         data = merge(data, post);
  834.     }
  835.  
  836.     if (data) {
  837.         if (datesHelper.parseDateSmart(data.dateTime)) {
  838.             data.dateTime = datesHelper.getDateTime(datesHelper.parseDateSmart(data.dateTime));
  839.         }
  840.         data.isPopup = handleCheckbox(data.isPopup);
  841.     }
  842.  
  843.     return {
  844.         message: data,
  845.         formData: formData
  846.     };
  847. }
  848.  
  849. function report(data, post, formData) {
  850.     formData = formData || {};
  851.  
  852.     if (post) {
  853.         data = merge(data, post);
  854.     }
  855.  
  856.     if (data.fund) {
  857.         formData.funds = setActiveCheckboxes(formData, data, ['fund']);
  858.     }
  859.  
  860.     return {
  861.         report: data,
  862.         formData: formData
  863.     };
  864. }
  865.  
  866. function fund(data, post, formData) {
  867.     formData = formData || {};
  868.  
  869.     if (post) {
  870.         data = merge(data, post);
  871.     }
  872.  
  873.     if (FUND_STATUS_CAPTIONS[data.status]) {
  874.         data.statusStr = FUND_STATUS_CAPTIONS[data.status];
  875.     }
  876.     if (datesHelper.parseDateSmart(data.stopReceivingFundsDate)) {
  877.         data.stopReceivingFundsDate = datesHelper.getDate(datesHelper.parseDateSmart(data.stopReceivingFundsDate));
  878.     }
  879.     if (datesHelper.parseDateSmart(data.formationFromDate)) {
  880.         data.formationFromDate = datesHelper.getDate(datesHelper.parseDateSmart(data.formationFromDate));
  881.     }
  882.     if (datesHelper.parseDateSmart(data.formationToDate)) {
  883.         data.formationToDate = datesHelper.getDate(datesHelper.parseDateSmart(data.formationToDate));
  884.     }
  885.     if (datesHelper.parseDateSmart(data.startInvestingDate)) {
  886.         data.startInvestingDate = datesHelper.getDate(datesHelper.parseDateSmart(data.startInvestingDate));
  887.     }
  888.     if (datesHelper.parseDateSmart(data.endDate)) {
  889.         data.endDate = datesHelper.getDate(datesHelper.parseDateSmart(data.endDate));
  890.     }
  891.     if (datesHelper.parseDateSmart(data.stopReceivingFundsDelayedDate)) {
  892.         data.stopReceivingFundsDelayedDate = datesHelper.getDate(datesHelper.parseDateSmart(data.stopReceivingFundsDelayedDate));
  893.     }
  894.     if (datesHelper.parseDateSmart(data.startInvestingDelayedDate)) {
  895.         data.startInvestingDelayedDate = datesHelper.getDate(datesHelper.parseDateSmart(data.startInvestingDelayedDate));
  896.     }
  897.     if (datesHelper.parseDateSmart(data.endDelayedDate)) {
  898.         data.endDelayedDate = datesHelper.getDate(datesHelper.parseDateSmart(data.endDelayedDate));
  899.     }
  900.  
  901.     return {
  902.         fund: data,
  903.         formData: formData
  904.     };
  905. }
  906.  
  907. function reserveNumbers(data, post, formData) {
  908.     formData = formData || {};
  909.  
  910.     if (post) {
  911.         data = merge(data, post);
  912.     }
  913.  
  914.     if (data) {
  915.         formData = setActiveCheckboxes(formData, data, ['fundShareId', 'type']);
  916.     }
  917.  
  918.     return {
  919.         item: data,
  920.         formData: formData
  921.     };
  922. }
  923.  
  924. function clientFormFooter(data, post, formData, errors) {
  925.     formData = formData || {};
  926.     formData.beneficialOwner = [
  927.         { id: 'positive', caption: 'Положительное' },
  928.         { id: 'negative', caption: 'Отрицательное' }
  929.     ];
  930.     formData.financialPosition = [
  931.         { id: 'positive', caption: 'Удовлетворительное' },
  932.         { id: 'negative', caption: 'Отрицательное' },
  933.         { id: 'unavailable', caption: 'Не определено' }
  934.     ];
  935.     formData.businessReputation = [
  936.         { id: 'positive', caption: 'Положительная' },
  937.         { id: 'negative', caption: 'Отрицательная' },
  938.         { id: 'unavailable', caption: 'Не определена' }
  939.     ];
  940.     formData.businessReputation = [
  941.         { id: 'positive', caption: 'Положительное' },
  942.         { id: 'negative', caption: 'Отрицательное' },
  943.         { id: 'unavailable', caption: 'Не определено' }
  944.     ];
  945.     formData.isTerroristCheck = [
  946.         { id: 'false', caption: 'Отсутствие информации' },
  947.         { id: 'true', caption: 'Наличие информации' },
  948.     ];
  949.     formData.riskLevel = [
  950.         { id: 'low', caption: 'Низкий' },
  951.         { id: 'high', caption: 'Высокий' },
  952.     ];
  953.     formData.isRiskLevelChanged = [
  954.         { id: 'false', caption: 'Нет' },
  955.         { id: 'true', caption: 'Да' },
  956.     ];
  957.  
  958.     if (post) {
  959.         data = merge(data, post);
  960.     }
  961.  
  962.     if (data) {
  963.        
  964.     }
  965.  
  966.     if (datesHelper.parseDateSmart(data.relationshipStartDate)) {
  967.         data.relationshipStartDate = datesHelper.getDate(datesHelper.parseDateSmart(data.relationshipStartDate));
  968.     }
  969.     if (datesHelper.parseDateSmart(data.relationshipEndDate)) {
  970.         data.relationshipEndDate = datesHelper.getDate(datesHelper.parseDateSmart(data.relationshipEndDate));
  971.     }
  972.     if (datesHelper.parseDateSmart(data.terroristsListDate)) {
  973.         data.terroristsListDate = datesHelper.getDate(datesHelper.parseDateSmart(data.terroristsListDate));
  974.     }
  975.     if (Array.isArray(data.formUpdateDates)) {
  976.         for (let index = 0; index < data.formUpdateDates.length; ++index) {
  977.             let value = data.formUpdateDates[index];
  978.             if (value && datesHelper.parseDateSmart(value)) {
  979.                 value = datesHelper.getDate(datesHelper.parseDateSmart(value));
  980.             }
  981.             let item = {
  982.                 value: value,
  983.                 index: index
  984.             };
  985.             if (errors && errors.formUpdateDates && errors.formUpdateDates[index]) {
  986.                 item.error = errors.formUpdateDates[index];
  987.             }
  988.             data.formUpdateDates[index] = item;
  989.         }
  990.     }
  991.     if (Array.isArray(data.terroristCheckDates)) {
  992.         for (let index = 0; index < data.terroristCheckDates.length; ++index) {
  993.             let value = data.terroristCheckDates[index];
  994.             if (value && datesHelper.parseDateSmart(value)) {
  995.                 value = datesHelper.getDate(datesHelper.parseDateSmart(value));
  996.             }
  997.             let item = {
  998.                 value: value,
  999.                 index: index
  1000.             };
  1001.             if (errors && errors.terroristCheckDates && errors.terroristCheckDates[index]) {
  1002.                 item.error = errors.terroristCheckDates[index];
  1003.             }
  1004.             data.terroristCheckDates[index] = item;
  1005.         }
  1006.     }
  1007.  
  1008.     if (data.clientAcceptedBy && typeof data.clientAcceptedBy == 'object') {
  1009.         if (datesHelper.parseDateSmart(data.clientAcceptedBy.date)) {
  1010.             data.clientAcceptedBy.date = datesHelper.getDate(datesHelper.parseDateSmart(data.clientAcceptedBy.date));
  1011.         }
  1012.     }
  1013.    
  1014.     if (data.clientUpdatedBy && typeof data.clientUpdatedBy == 'object') {
  1015.         if (datesHelper.parseDateSmart(data.clientUpdatedBy.date)) {
  1016.             data.clientUpdatedBy.date = datesHelper.getDate(datesHelper.parseDateSmart(data.clientUpdatedBy.date));
  1017.         }
  1018.     }
  1019.    
  1020.     formData = setActiveCheckboxes(formData, data, ['beneficialOwner', 'financialPosition', 'businessReputation', 'isTerroristCheck', 'riskLevel', 'isRiskLevelChanged']);
  1021.  
  1022.     return {
  1023.         item: data,
  1024.         formData: formData
  1025.     };
  1026. }
  1027.  
  1028. module.exports.handleCheckbox = handleCheckbox;
  1029. module.exports.rename = rename;
  1030. module.exports.merge = merge;
  1031. module.exports.user = user;
  1032. module.exports.role = role;
  1033. module.exports.entity = entity;
  1034. module.exports.client = client;
  1035. module.exports.bank = bank;
  1036. module.exports.terrorist = terrorist;
  1037. module.exports.iccntrib = iccntrib;
  1038. module.exports.message = message;
  1039. module.exports.report = report;
  1040. module.exports.fund = fund;
  1041. module.exports.reserveNumbers = reserveNumbers;
  1042. module.exports.clientFormFooter = clientFormFooter;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement