Merge branch 'questionnaire' of https://github.com/merelendor/evoleasing-account into questionnaire

This commit is contained in:
Denis 2023-04-01 10:47:26 +03:00
commit c6cbd644fe
16 changed files with 557 additions and 100 deletions

View File

@ -3,6 +3,7 @@ import { Cookies } from 'react-cookie';
import Router from 'next/router'; import Router from 'next/router';
import moment from 'moment'; import moment from 'moment';
import { nSQL } from "@nano-sql/core"; import { nSQL } from "@nano-sql/core";
import fileDownload from 'js-file-download';
import * as actionTypes from '../constants/actionTypes'; import * as actionTypes from '../constants/actionTypes';
@ -62,7 +63,7 @@ export const updateQuestionnaire = ({ dispatch, questionnaire }) =>
}); });
} }
export const downloadQuestionnaire = () => export const downloadQuestionnaire = (download = true) =>
{ {
console.log("ACTION", "questionnaireActions", "downloadQuestionnaire()", ); console.log("ACTION", "questionnaireActions", "downloadQuestionnaire()", );
@ -72,21 +73,41 @@ export const downloadQuestionnaire = () =>
{ {
let cookies = new Cookies(); let cookies = new Cookies();
let cookies_list = cookies.getAll(); let cookies_list = cookies.getAll();
console.log("cookies_list", cookies_list); const { questionnaire } = global.store.getState();
axios.post(`${ process.env.NEXT_PUBLIC_INT_API_HOST }/questionnaire/check`, {}, { console.log("questionnaire", questionnaire);
const { main, contacts, signatory_person, founded_persons, head_person, non_profit, } = questionnaire;
const playload = { main, contacts, signatory_person, founded_persons, head_person, non_profit, };
console.log({ playload });
/* axios.post(`${ process.env.NEXT_PUBLIC_INT_API_HOST }/questionnaire/download`, { questionnaire: playload }, {
headers: { headers: {
"Authorization": `Bearer ${ cookies_list.jwt }`, "Authorization": `Bearer ${ cookies_list.jwt }`,
}, },
//withCredentials: true, })
*/
axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/questionnaire/download`, { questionnaire: playload }, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/pdf'
},
responseType: 'arraybuffer',
}) })
.then((response) => .then((response) =>
{ {
console.log("downloadQuestionnaire", "response.data"); if(download)
console.log(response.data); {
console.log("downloaded?"); console.log("downloadQuestionnaire", "response.data");
fileDownload(response.data, response.headers.filename);
resolve();
}
else
{
resolve({ file: response.data, filename: response.headers.filename });
}
//dispatch({ type: actionTypes.SUPPORT_APPEALS, data: { appeals: { list: response.data.appeals, new: response.data.new, } } }); //dispatch({ type: actionTypes.SUPPORT_APPEALS, data: { appeals: { list: response.data.appeals, new: response.data.new, } } });
resolve();
}) })
.catch((error) => .catch((error) =>
{ {

View File

@ -1,9 +1,11 @@
import React from "react"; import React from "react";
import Link from "next/link"; import Link from "next/link";
import { getCertificates, isPluginCryptoProInstalled } from "../../../utils/digital_signature";
import { SpinnerCircular } from "spinners-react"; import { SpinnerCircular } from "spinners-react";
import moment from "moment"; import moment from "moment";
import fileDownload from 'js-file-download';
import { getCertificates, isPluginCryptoProInstalled, generateSignature } from "../../../utils/digital_signature";
import { downloadQuestionnaire } from "../../../actions";
export default class DigitalSignaturesList extends React.Component export default class DigitalSignaturesList extends React.Component
{ {
constructor(props) constructor(props)
@ -73,7 +75,48 @@ export default class DigitalSignaturesList extends React.Component
_sign = () => _sign = () =>
{ {
alert("Подписание ЭЦП и отправка данных"); downloadQuestionnaire(false)
.then(({ file, filename }) =>
{
//let created_at = moment().format('DD-MM-yyyy');
//let filename = `Коммерческое предложение №${this.props.proposal.proposalId} от ${createAt}.docx`
let file_to_sign = new File([ file ], filename);
console.log("this.state", this.state);
console.log("file");
console.log(file);
console.log("file_to_sign");
console.log(file_to_sign);
const now = moment().format("DDMMYYYY_HHmmss");
generateSignature(file_to_sign, this.state.certificate_selected.certificate)
.then(signature => {
console.log("signature");
console.log(signature);
fileDownload(signature, `${ now }_${ filename }.sig`);
fileDownload(file, `${ now }_${ filename }`);
alert("Подписание ЭЦП прошло успешно.");
});
})
.catch((e) =>
{
console.error("exception on sign");
console.error(e);
let errorsText = {
'The action was cancelled by the user. (0x8010006E)': 'Подписание было отменено',
'Key does not exist. (0x8009000D)': 'Сертификата не существует',
'Keyset does not exist (0x80090016)': 'Набор ключей не существует',
'File upload error': 'Ошибка загрузки файла',
'Invalid algorithm specified. (0x80090008)': 'На вашем компьютере не установлена программа «КриптоПро CSP»',
'The card cannot be accessed because the wrong PIN was presented. (0x8010006B)': 'Указанный пароль неверный'
}
let errorText = errorsText[e.message] || 'Ошибка подписания файла';
alert(errorText);
});
} }
render() render()
@ -105,8 +148,8 @@ export default class DigitalSignaturesList extends React.Component
hidden="" hidden=""
id={ `certificate_${ certificate.index }` } id={ `certificate_${ certificate.index }` }
name={ `certificate_${ certificate.index }` } name={ `certificate_${ certificate.index }` }
checked={ certificate_selected === certificate.index ? true : false } checked={ certificate_selected !== undefined && certificate_selected.index === certificate.index ? true : false }
onChange={ () => { this.setState({ certificate_selected: certificate.index }) } } onChange={ () => { this.setState({ certificate_selected: certificate }) } }
/> />
<label htmlFor={ `certificate_${ certificate.index }` }> <label htmlFor={ `certificate_${ certificate.index }` }>
<div className="feed_item user"> <div className="feed_item user">

View File

@ -25,7 +25,7 @@ class Form_2_Contacts extends QuestionnaireForm
loading: false, loading: false,
fact_address: { fact_address: {
name: "", title: "",
fias_id: "", fias_id: "",
}, },
legal_address: { legal_address: {
@ -33,7 +33,7 @@ class Form_2_Contacts extends QuestionnaireForm
fias_id: "", fias_id: "",
}, },
postal_address: { postal_address: {
name: "", title: "",
fias_id: "", fias_id: "",
}, },
}, },
@ -74,7 +74,7 @@ class Form_2_Contacts extends QuestionnaireForm
if(contacts.address_type === "fact") if(contacts.address_type === "fact")
{ {
if(contacts.fact_address.name === "") if(contacts.fact_address.title === "")
{ {
return true; return true;
} }
@ -82,7 +82,7 @@ class Form_2_Contacts extends QuestionnaireForm
if(contacts.address_type === "postal") if(contacts.address_type === "postal")
{ {
if(contacts.postal_address.name === "") if(contacts.postal_address.title === "")
{ {
return true; return true;
} }

View File

@ -65,7 +65,10 @@ class Form_3_Signer extends QuestionnaireForm
issueby: "", issueby: "",
issueby_search_dadata: "", issueby_search_dadata: "",
placebirth: "", placebirth: "",
citizenship_code: "", citizenship: {
title: "",
code: "",
},
registration_address: { registration_address: {
title: "", title: "",
fias_id: "", fias_id: "",
@ -98,7 +101,10 @@ class Form_3_Signer extends QuestionnaireForm
issueby: "", issueby: "",
issueby_search_dadata: "", issueby_search_dadata: "",
placebirth: "", placebirth: "",
citizenship_code: "", citizenship: {
title: "",
code: "",
},
registration_address: { registration_address: {
title: "", title: "",
fias_id: "", fias_id: "",
@ -132,6 +138,24 @@ class Form_3_Signer extends QuestionnaireForm
{ {
} }
_handle_onCitizenshipChange = (name, value) =>
{
console.log("_handle_onCitizenshipChange", value);
let citizenship = undefined;
for(let i in citizenships)
{
if(parseInt(citizenships[i].value, 10) === parseInt(value, 10))
{
citizenship = citizenships[i].label;
}
}
this._handle_onFieldChange(name, {
title: citizenship,
code: value,
});
}
_handle_onFormSubmit = (event) => _handle_onFormSubmit = (event) =>
{ {
event.preventDefault(); event.preventDefault();
@ -226,7 +250,7 @@ class Form_3_Signer extends QuestionnaireForm
"identity_document.icode", "identity_document.icode",
"identity_document.issueby", "identity_document.issueby",
"identity_document.placebirth", "identity_document.placebirth",
"identity_document.citizenship_code", "identity_document.citizenship.code",
"identity_document.registration_address.title", "identity_document.registration_address.title",
]; ];
@ -288,11 +312,11 @@ class Form_3_Signer extends QuestionnaireForm
const { main, head_person, signatory_person } = this.state; const { main, head_person, signatory_person } = this.state;
let head_person_citizenship = undefined; let head_person_citizenship = undefined;
if(head_person.identity_document.citizenship_code !== "") if(head_person.identity_document.citizenship.code !== "")
{ {
for(let i in citizenships) for(let i in citizenships)
{ {
if(parseInt(citizenships[i].value, 10) === parseInt(head_person.identity_document.citizenship_code, 10)) if(parseInt(citizenships[i].value, 10) === parseInt(head_person.identity_document.citizenship.code, 10))
{ {
head_person_citizenship = citizenships[i]; head_person_citizenship = citizenships[i];
} }
@ -300,11 +324,11 @@ class Form_3_Signer extends QuestionnaireForm
} }
let signatory_person_citizenship = undefined; let signatory_person_citizenship = undefined;
if(signatory_person.identity_document.citizenship_code !== "") if(signatory_person.identity_document.citizenship.code !== "")
{ {
for(let i in citizenships) for(let i in citizenships)
{ {
if(parseInt(citizenships[i].value, 10) === parseInt(signatory_person.identity_document.citizenship_code, 10)) if(parseInt(citizenships[i].value, 10) === parseInt(signatory_person.identity_document.citizenship.code, 10))
{ {
signatory_person_citizenship = citizenships[i]; signatory_person_citizenship = citizenships[i];
} }
@ -430,8 +454,8 @@ class Form_3_Signer extends QuestionnaireForm
<div className="form_field"> <div className="form_field">
<label>Гражданство</label> <label>Гражданство</label>
<Select <Select
id="head_person.identity_document.citizenship_code" id="head_person.identity_document.citizenship"
name="head_person.identity_document.citizenship_code" name="head_person.identity_document.citizenship"
options={ citizenships } options={ citizenships }
placeholder="Выберите страну" placeholder="Выберите страну"
noOptionsMessage={ ({ inputValue }) => !inputValue ? noOptionsText :"Ничего не найдено" } noOptionsMessage={ ({ inputValue }) => !inputValue ? noOptionsText :"Ничего не найдено" }
@ -439,7 +463,7 @@ class Form_3_Signer extends QuestionnaireForm
className="autocomlete" className="autocomlete"
classNamePrefix="react-select" classNamePrefix="react-select"
value={ head_person_citizenship } value={ head_person_citizenship }
onChange={ (element) => this._handle_onTextFieldChange("head_person.identity_document.citizenship_code", element.value) } onChange={ (element) => this._handle_onCitizenshipChange(`head_person.identity_document.citizenship`, element.value) }
required={ true } required={ true }
disabled={ checking } disabled={ checking }
/> />
@ -793,8 +817,8 @@ class Form_3_Signer extends QuestionnaireForm
<div className="form_field"> <div className="form_field">
<label>Гражданство</label> <label>Гражданство</label>
<Select <Select
id="signatory_person.identity_document.citizenship_code" id="signatory_person.identity_document.citizenship"
name="signatory_person.identity_document.citizenship_code" name="signatory_person.identity_document.citizenship"
options={ citizenships } options={ citizenships }
placeholder="Выберите страну" placeholder="Выберите страну"
noOptionsMessage={ ({ inputValue }) => !inputValue ? noOptionsText :"Ничего не найдено" } noOptionsMessage={ ({ inputValue }) => !inputValue ? noOptionsText :"Ничего не найдено" }
@ -802,7 +826,7 @@ class Form_3_Signer extends QuestionnaireForm
className="autocomlete" className="autocomlete"
classNamePrefix="react-select" classNamePrefix="react-select"
value={ signatory_person_citizenship } value={ signatory_person_citizenship }
onChange={ (element) => this._handle_onTextFieldChange("signatory_person.identity_document.citizenship_code", element.value) } onChange={ (element) => this._handle_onCitizenshipChange(`signatory_person.identity_document.citizenship`, element.value) }
required={ true } required={ true }
disabled={ checking } disabled={ checking }
/> />

View File

@ -22,17 +22,36 @@ class ShareholderForm extends React.Component
{ {
_handle_onTextFieldChange = this.props._handle_onTextFieldChange; _handle_onTextFieldChange = this.props._handle_onTextFieldChange;
_handle_onCheckboxFieldChange = this.props._handle_onCheckboxFieldChange; _handle_onCheckboxFieldChange = this.props._handle_onCheckboxFieldChange;
_handle_onFieldChange = this.props._handle_onFieldChange;
_handle_onCitizenshipChange = (name, value) =>
{
console.log("_handle_onCitizenshipChange", value);
let citizenship = undefined;
for(let i in citizenships)
{
if(parseInt(citizenships[i].value, 10) === parseInt(value, 10))
{
citizenship = citizenships[i].label;
}
}
this._handle_onFieldChange(name, {
title: citizenship,
code: value,
});
}
render() render()
{ {
const { index, shareholder, checking } = this.props; const { index, shareholder, checking } = this.props;
let citizenship = undefined; let citizenship = undefined;
if(shareholder.identity_document.citizenship_code !== "") if(shareholder.identity_document.citizenship.code !== "")
{ {
for(let i in citizenships) for(let i in citizenships)
{ {
if(parseInt(citizenships[i].value, 10) === parseInt(shareholder.identity_document.citizenship_code, 10)) if(parseInt(citizenships[i].value, 10) === parseInt(shareholder.identity_document.citizenship.code, 10))
{ {
citizenship = citizenships[i]; citizenship = citizenships[i];
} }
@ -207,16 +226,16 @@ class ShareholderForm extends React.Component
<div className="form_field"> <div className="form_field">
<label>Гражданство</label> <label>Гражданство</label>
<Select <Select
id={ `founded_persons[${ index }].identity_document.citizenship_code` } id={ `founded_persons[${ index }].identity_document.citizenship` }
name={ `founded_persons[${ index }].identity_document.citizenship_code` } name={ `founded_persons[${ index }].identity_document.citizenship` }
value={ citizenship } value={ citizenship }
options={ citizenships } options={ [ ...citizenships ] }
placeholder="Выберите страну" placeholder="Выберите страну"
noOptionsMessage={ ({ inputValue }) => !inputValue ? noOptionsText :"Ничего не найдено" } noOptionsMessage={ ({ inputValue }) => !inputValue ? noOptionsText :"Ничего не найдено" }
isSearchable={ true } isSearchable={ true }
className="autocomlete" className="autocomlete"
classNamePrefix="react-select" classNamePrefix="react-select"
onChange={ (element) => this._handle_onTextFieldChange(`founded_persons[${ index }].identity_document.citizenship_code`, element.value) } onChange={ (element) => this._handle_onCitizenshipChange(`founded_persons[${ index }].identity_document.citizenship`, element.value) }
required={ true } required={ true }
disabled={ checking } disabled={ checking }
/> />
@ -380,7 +399,7 @@ class Shareholder extends React.Component
value="1" value="1"
id={ `founded_persons[${ index }].is_beneficial_1` } id={ `founded_persons[${ index }].is_beneficial_1` }
name={ `founded_persons[${ index }].is_beneficial` } name={ `founded_persons[${ index }].is_beneficial` }
checked={ shareholder.is_beneficial ? false : true } checked={ shareholder.is_beneficial ? true : false }
onChange={ (event) => this._handle_onCheckboxFieldChange(event.target.name, parseInt(event.target.value, 10)) } onChange={ (event) => this._handle_onCheckboxFieldChange(event.target.name, parseInt(event.target.value, 10)) }
/> />
<label className="unselectable" htmlFor={ `founded_persons[${ index }].is_beneficial_1` }>Да</label> <label className="unselectable" htmlFor={ `founded_persons[${ index }].is_beneficial_1` }>Да</label>
@ -411,7 +430,39 @@ class Form_4_Shareholders extends QuestionnaireForm
super(props); super(props);
this.state = { this.state = {
founded_persons: [], founded_persons: [],
founded_persons_template: {}, founded_persons_template: {
signatory_id: null,
lastname: "",
firstname: "",
middlename: "",
no_middle_name: false,
jobtitle: "",
telephone: "",
email: "",
founder_from_list: true,
founder_number: 0,
founder_part: "",
is_beneficial: false,
identity_document:
{
doctype: "",
seria: "",
docnumber: "",
issuedate: "",
icode: "",
issueby: "",
issueby_search_dadata: "",
placebirth: "",
citizenship: {
title: "",
code: "",
},
registration_address: {
title: "",
fias_id: "",
}
}
},
loading: false, loading: false,
}; };
} }
@ -420,13 +471,14 @@ class Form_4_Shareholders extends QuestionnaireForm
{ {
return { return {
founded_persons: nextProps.questionnaire.founded_persons, founded_persons: nextProps.questionnaire.founded_persons,
founded_persons_template: nextProps.questionnaire.founded_persons_template,
}; };
} }
componentDidMount() componentDidMount()
{ {
const { founded_persons_template } = this.state; console.log("Form_4_Shareholders", "this.state", this.state);
console.log("Form_4_Shareholders", "global.store.getState()", global.store.getState());
const founded_persons_template = JSON.parse(JSON.stringify(this.state.founded_persons_template));
if(this.state.founded_persons.length === 0) if(this.state.founded_persons.length === 0)
{ {
@ -438,12 +490,16 @@ class Form_4_Shareholders extends QuestionnaireForm
_handle_onAddShareholder = () => _handle_onAddShareholder = () =>
{ {
console.log("_handle_onAddShareholder");
const founded_persons = [ ...this.state.founded_persons ]; const founded_persons = [ ...this.state.founded_persons ];
const { founded_persons_template } = this.state; const founded_persons_template = JSON.parse(JSON.stringify(this.state.founded_persons_template));
console.log("_handle_onAddShareholder", { founded_persons_template });
if(founded_persons.length < 4) if(founded_persons.length < 4)
{ {
founded_persons.push({ ...founded_persons_template }); founded_persons.push(founded_persons_template);
this._updateQuestionnaire({ this._updateQuestionnaire({
founded_persons, founded_persons,
@ -464,11 +520,17 @@ class Form_4_Shareholders extends QuestionnaireForm
_handle_onClearSignatorySelection = (name, values) => _handle_onClearSignatorySelection = (name, values) =>
{ {
this._handle_onFieldChange(name, { ...this.state.founded_persons_template , ...values } ); const founded_persons_template = JSON.parse(JSON.stringify(this.state.founded_persons_template));
const update = { ...founded_persons_template , ...values };
console.log("_handle_onClearSignatorySelection", update);
this._handle_onFieldChange(name, update );
} }
_handle_onChangeSignatorySelection = (name, values) => _handle_onChangeSignatorySelection = (name, values) =>
{ {
console.log("_handle_onChangeSignatorySelection");
console.log(name, values);
this._handle_onFieldChange(name, { ...values } ); this._handle_onFieldChange(name, { ...values } );
} }
@ -502,7 +564,7 @@ class Form_4_Shareholders extends QuestionnaireForm
"identity_document.icode", "identity_document.icode",
"identity_document.issueby", "identity_document.issueby",
"identity_document.placebirth", "identity_document.placebirth",
"identity_document.citizenship_code", "identity_document.citizenship.code",
"identity_document.registration_address.title", "identity_document.registration_address.title",
]; ];
@ -567,6 +629,7 @@ class Form_4_Shareholders extends QuestionnaireForm
address={ address } address={ address }
_handle_onTextFieldChange={ this._handle_onTextFieldChange } _handle_onTextFieldChange={ this._handle_onTextFieldChange }
_handle_onCheckboxFieldChange={ this._handle_onCheckboxFieldChange } _handle_onCheckboxFieldChange={ this._handle_onCheckboxFieldChange }
_handle_onFieldChange={ this._handle_onFieldChange }
removeShareholder={ this._handle_onRemoveShareholder } removeShareholder={ this._handle_onRemoveShareholder }
clearSignatorySelection={ this._handle_onClearSignatorySelection } clearSignatorySelection={ this._handle_onClearSignatorySelection }
changeSignatorySelection={ this._handle_onChangeSignatorySelection } changeSignatorySelection={ this._handle_onChangeSignatorySelection }

View File

@ -37,7 +37,6 @@ class Form_7_Check extends QuestionnaireForm
head_person_files: [], head_person_files: [],
signatory_person: {}, signatory_person: {},
signatory_person_files: [], signatory_person_files: [],
founded_persons_template: {},
founded_persons: [], founded_persons: [],
client_contacts: {}, client_contacts: {},
non_profit: {}, non_profit: {},
@ -55,7 +54,6 @@ class Form_7_Check extends QuestionnaireForm
head_person_files: nextProps.head_person_files, head_person_files: nextProps.head_person_files,
signatory_person: nextProps.signatory_person, signatory_person: nextProps.signatory_person,
signatory_person_files: nextProps.signatory_person_files, signatory_person_files: nextProps.signatory_person_files,
founded_persons_template: nextProps.founded_persons_template,
founded_persons: nextProps.founded_persons, founded_persons: nextProps.founded_persons,
client_contacts: nextProps.client_contacts, client_contacts: nextProps.client_contacts,
non_profit: nextProps.non_profit, non_profit: nextProps.non_profit,

BIN
lib/evo_anketa.pdf Normal file

Binary file not shown.

BIN
lib/evo_anketa_old.pdf Normal file

Binary file not shown.

BIN
lib/noto.ttf Normal file

Binary file not shown.

BIN
lib/roboto.ttf Normal file

Binary file not shown.

View File

@ -93,5 +93,5 @@ module.exports = withImages(withFonts(withLess({
//}, //},
], ],
} }
} },
}))); })));

View File

@ -11,6 +11,7 @@
"dependencies": { "dependencies": {
"@mpth/react-no-ssr": "^1.0.1", "@mpth/react-no-ssr": "^1.0.1",
"@nano-sql/core": "^2.3.7", "@nano-sql/core": "^2.3.7",
"@pdf-lib/fontkit": "^1.1.1",
"async": "^3.2.2", "async": "^3.2.2",
"axios": "^0.24.0", "axios": "^0.24.0",
"cookie": "^0.4.1", "cookie": "^0.4.1",
@ -33,6 +34,7 @@
"nextjs-cors": "^2.1.0", "nextjs-cors": "^2.1.0",
"node-fetch": "^3.3.1", "node-fetch": "^3.3.1",
"numeral": "^2.0.6", "numeral": "^2.0.6",
"pdf-lib": "^1.17.1",
"pluralize-ru": "^1.0.1", "pluralize-ru": "^1.0.1",
"qs": "^6.10.1", "qs": "^6.10.1",
"react": "17.0.2", "react": "17.0.2",

View File

@ -6,12 +6,116 @@ import moment from 'moment';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import { cors } from '../../../lib/cors'; import { cors } from '../../../lib/cors';
import { inspect } from 'util'; import { inspect } from 'util';
import fs from 'fs';
import { PDFDocument } from 'pdf-lib';
import fontkit from '@pdf-lib/fontkit';
const fields = {
main: {
title: { name: "main_title", type: "text", bind: null, },
inn: { name: "main_inn", type: "text", bind: null, },
kpp: { name: "main_kpp", type: "text", bind: null, },
email: { name: "main_email", type: "text", bind: null, },
telephone: { name: "main_telephone", type: "text", bind: null, },
websiteurl: { name: "main_website", type: "text", bind: null, },
financial_loan: { name: "main_financial_loan", type: "text", bind: null, },
individual_executive_oop: { name: "ruler_title", type: "text", bind: null },
individual_executive_inn: { name: "ruler_inn", type: "text", bind: null },
individual_executive_kpp: { name: "ruler_kpp", type: "text", bind: null },
individual_executive_docnum: { name: "ruler_docnum", type: "text", bind: null },
individual_executive_docdate: { name: "ruler_docdate", type: "text", bind: null, date: true },
high_level: { name: "execution_high", type: "text", bind: null, size: 6 },
board_of_directors: { name: "execution_counsil", type: "text", bind: null, size: 6 },
collective_executive: { name: "execution_team", type: "text", bind: null, size: 6 },
individual_executive: { name: "execution_sole", type: "text", bind: null, size: 6 },
other_control: { name: "execution_another", type: "text", bind: null, size: 6 },
},
contacts: {
address_type: { name: "address_type", type: "radio", bind: null },
fact_address: { name: "address_fact", type: "text", bind: null },
postal_address: { name: "address_postal", type: "text", bind: null },
},
head_person: {
fullname: { name: "head_fullname", type: "text", bind: null },
jobtitle: { name: "head_jobtitle", type: "text", bind: null },
evo_assignment_date: { name: "head_date", type: "text", bind: null, date: true },
evo_credentials_dateend: { name: "head_dateend", type: "text", bind: null, date: true },
evo_indefinite: { name: "head_date_infinite", type: "checkbox", bind: null },
telephone: { name: "head_phone", type: "text", bind: null },
email: { name: "head_email", type: "text", bind: null },
},
signatory_person: {
fullname: { name: "signer_fullname", type: "text", bind: null },
jobtitle: { name: "signer_jobtitle", type: "text", bind: null },
signer_rule_basis: { name: "signer_reason", type: "text", bind: null },
docdate: { name: "signer_docdate", type: "text", bind: null, date: true },
docnumber: { name: "signer_docnum", type: "text", bind: null },
telephone: { name: "signer_phone", type: "text", bind: null },
email: { name: "signer_email", type: "text", bind: null },
},
founded_persons:
[
{
fullname: { name: "shareholder_1_fullname", type: "text", bind: null, size: 6 },
personal: { name: "shareholder_1_personal", type: "text", bind: null, size: 6 },
registration: { name: "shareholder_1_registration", type: "text", bind: null, size: 6 },
founder_part: { name: "shareholder_1_part", type: "text", bind: null, size: 6 },
is_beneficial: { name: "shareholder_1_ben", type: "radio", bind: null },
},
{
fullname: { name: "shareholder_2_fullname", type: "text", bind: null, size: 6 },
personal: { name: "shareholder_2_personal", type: "text", bind: null, size: 6 },
registration: { name: "shareholder_2_registration", type: "text", bind: null, size: 6 },
founder_part: { name: "shareholder_2_part", type: "text", bind: null, size: 6 },
is_beneficial: { name: "shareholder_2_ben", type: "radio", bind: null, size: 6 },
},
{
fullname: { name: "shareholder_3_fullname", type: "text", bind: null, size: 6 },
personal: { name: "shareholder_3_personal", type: "text", bind: null, size: 6 },
registration: { name: "shareholder_3_registration", type: "text", bind: null, size: 6 },
founder_part: { name: "shareholder_3_part", type: "text", bind: null, size: 6 },
is_beneficial: { name: "shareholder_3_ben", type: "radio", bind: null },
},
{
fullname: { name: "shareholder_4_fullname", type: "text", bind: null, size: 6 },
personal: { name: "shareholder_4_personal", type: "text", bind: null, size: 6 },
registration: { name: "shareholder_4_registration", type: "text", bind: null, size: 6 },
founder_part: { name: "shareholder_4_part", type: "text", bind: null, size: 6 },
is_beneficial: { name: "shareholder_4_ben", type: "radio", bind: null },
},
],
non_profit: {
fin_source_business: { name: "nko_revenue", type: "checkbox", bind: null },
fin_source_donate: { name: "nko_donation", type: "checkbox", bind: null },
fin_source_fees: { name: "nko_members", type: "checkbox", bind: null },
fin_source_another: { name: "nko_another", type: "checkbox", bind: null },
fin_source_another_description: { name: "nko_another_description", type: "text", bind: null, size: 6 },
foreign_payers: { name: "external", type: "radio", bind: null },
fin_goals_cars: { name: "nko_object_cars", type: "text", bind: null, size: 6 },
fin_goals_trucks: { name: "nko_object_trucks", type: "text", bind: null, size: 6 },
fin_goals_special: { name: "nko_object_special", type: "text", bind: null, size: 6 },
},
};
function good(value)
{
if(value !== undefined && value !== null && value !== "")
{
return true;
}
return false;
}
export default async function handler(req, res) export default async function handler(req, res)
{ {
console.log("API", "questionnaire", "get"); console.log("API", "questionnaire", "get");
console.log(req.body); console.log(req.body);
console.log("-".repeat(50)); console.log("-".repeat(50));
const { questionnaire } = req.body;
await cors(req, res); await cors(req, res);
if(req.headers.cookie !== undefined) if(req.headers.cookie !== undefined)
@ -23,11 +127,196 @@ export default async function handler(req, res)
var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT);
var crm_jwt = jwt.sign({ acc_number: client_jwt_decoded.acc_number }, process.env.JWT_SECRET_CRM, { noTimestamp: true }); var crm_jwt = jwt.sign({ acc_number: client_jwt_decoded.acc_number }, process.env.JWT_SECRET_CRM, { noTimestamp: true });
res.status(200); console.log("API", "download", "__dirname", __dirname);
const formPdfBytes = fs.readFileSync(`${ __dirname }/../../../../../lib/evo_anketa.pdf`);
const fontBytes = fs.readFileSync(`${ __dirname }/../../../../../lib/roboto.ttf`);
const pdfDoc = await PDFDocument.load(formPdfBytes);
pdfDoc.registerFontkit(fontkit);
const formFont = await pdfDoc.embedFont(fontBytes);
// Embed the Mario and emblem images
// Get the form containing all the fields
const form = pdfDoc.getForm();
//form.registerFontkit(fontkit);
for(let group in fields)
{
if(group === "founded_persons")
{
for(let p in questionnaire[group])
{
for(let field in fields[group][p])
{
if(field === "fullname")
{
fields[group][p][field].bind = form.getTextField(fields[group][p][field].name);
if(fields[group][p][field].size !== undefined) { fields[group][p][field].bind.setFontSize(fields[group][p][field].size); }
fields[group][p][field].bind.setText(`${ questionnaire[group][p].lastname.toUpperCase() } ${ questionnaire[group][p].firstname.toUpperCase() }${ good(questionnaire[group][p].middlename) ? ` ${ questionnaire[group][p].middlename.toUpperCase() }` : "" }`);
}
else if(field === "personal")
{
const { citizenship, doctype, seria, docnumber, icode, issueby, issuedate, } = questionnaire[group][p].identity_document;
fields[group][p][field].bind = form.getTextField(fields[group][p][field].name);
if(fields[group][p][field].size !== undefined) { fields[group][p][field].bind.setFontSize(fields[group][p][field].size); }
fields[group][p][field].bind.setText(`Гражданство: ${ citizenship.title }, паспорт ${ seria } ${ docnumber }, выдан \n${ issueby }, ${ icode } ${ moment(issuedate).format("DD.MM.YYYY") }`.toUpperCase());
}
else if(field === "registration")
{
const { registration_address, } = questionnaire[group][p].identity_document;
if(good(registration_address.title))
{
fields[group][p][field].bind = form.getTextField(fields[group][p][field].name);
if(fields[group][p][field].size !== undefined) { fields[group][p][field].bind.setFontSize(fields[group][p][field].size); }
fields[group][p][field].bind.setText(registration_address.title.toUpperCase());
}
}
else
{
if(fields[group][p][field].type === "checkbox")
{
if(questionnaire[group][p][field])
{
fields[group][p][field].bind = form.getCheckBox(fields[group][p][field].name);
fields[group][p][field].bind.check();
}
}
else if(fields[group][p][field].type === "radio")
{
if(questionnaire[group][p][field] !== undefined)
{
fields[group][p][field].bind = form.getRadioGroup(fields[group][p][field].name);
let options = fields[group][p][field].bind.getOptions();
if(questionnaire[group][p][field])
{
fields[group][p][field].bind.select("yes");
}
else
{
fields[group][p][field].bind.select("no");
}
}
}
else
{
if(good(questionnaire[group][p][field]))
{
fields[group][p][field].bind = form.getTextField(fields[group][p][field].name);
if(fields[group][p][field].size !== undefined) { fields[group][p][field].bind.setFontSize(fields[group][p][field].size); }
fields[group][p][field].bind.setText(questionnaire[group][p][field]);
}
}
}
}
}
continue;
}
else
{
for(let field in fields[group])
{
if(field === "fullname")
{
fields[group][field].bind = form.getTextField(fields[group][field].name);
if(fields[group][field].size !== undefined) { fields[group][field].bind.setFontSize(fields[group][field].size); }
fields[group][field].bind.setText(`${ questionnaire[group].lastname.toUpperCase() } ${ questionnaire[group].firstname.toUpperCase() }${ good(questionnaire[group].middlename) ? ` ${ questionnaire[group].middlename.toUpperCase() }` : "" }`);
}
else if(field === "postal_address")
{
if(good(questionnaire[group].postal_address.title))
{
fields[group][field].bind = form.getTextField(fields[group][field].name);
if(fields[group][field].size !== undefined) { fields[group][field].bind.setFontSize(fields[group][field].size); }
fields[group][field].bind.setText(questionnaire[group].postal_address.title.toUpperCase());
}
}
else if(field === "fact_address")
{
if(good(questionnaire[group].fact_address.title))
{
fields[group][field].bind = form.getTextField(fields[group][field].name);
if(fields[group][field].size !== undefined) { fields[group][field].bind.setFontSize(fields[group][field].size); }
fields[group][field].bind.setText(questionnaire[group].fact_address.title.toUpperCase());
}
}
else if(field === "address_type")
{
fields[group][field].bind = form.getRadioGroup(fields[group][field].name);
fields[group][field].bind.select(questionnaire[group].address_type);
}
/*
else if(field === "foreign_payers")
{
pdf_params[fields[group][field]] = questionnaire[group].foreign_payers ? 0 : 1;
}
*/
else
{
if(fields[group][field].type === "checkbox")
{
if(questionnaire[group][field])
{
fields[group][field].bind = form.getCheckBox(fields[group][field].name);
fields[group][field].bind.check();
}
}
else if(fields[group][field].type === "radio")
{
if(questionnaire[group][field] !== undefined)
{
fields[group][field].bind = form.getRadioGroup(fields[group][field].name);
if(questionnaire[group][field])
{
fields[group][field].bind.select("yes");
}
else
{
fields[group][field].bind.select("no");
}
}
}
else
{
if(good(questionnaire[group][field]))
{
fields[group][field].bind = form.getTextField(fields[group][field].name);
if(fields[group][field].size !== undefined) { fields[group][field].bind.setFontSize(fields[group][field].size); }
if(fields[group][field].date)
{
fields[group][field].bind.setText(moment(questionnaire[group][field]).format("DD.MM.YYYY"));
}
else
{
fields[group][field].bind.setText(questionnaire[group][field].toUpperCase());
}
}
}
}
}
}
}
form.updateFieldAppearances(formFont);
const pdfBytes = await pdfDoc.save();
//responseType: 'blob',
//fs.writeFileSync(`${ __dirname }/../../../../../upload/${ client_jwt_decoded.acc_number }_anketa.pdf`, pdfBytes);
//res.setHeader('Content-Type', 'application/pdf');
//res.send(pdfBytes);
console.log("pdfBytes.size", pdfBytes, pdfBytes.byteLength);
res.setHeader("filename", `${ client_jwt_decoded.acc_number }_anketa.pdf`);
res.setHeader('Content-Type', 'application/pdf');
res.send(Buffer.from(pdfBytes));
//res.setHeader('Content-Type', 'application/pdf');
//res.status(200).send(pdfBytes);
} }
else else
{ {
res.status(403); res.status(403).send();
} }
} }
} }

View File

@ -154,11 +154,11 @@ export const defaultState = {
fias_id: "", fias_id: "",
}, },
fact_address: { fact_address: {
name: "", title: "",
fias_id: "", fias_id: "",
}, },
postal_address: { postal_address: {
name: "", title: "",
fias_id: "", fias_id: "",
}, },
}, },
@ -179,7 +179,10 @@ export const defaultState = {
issueby: "", issueby: "",
issueby_search_dadata: "", issueby_search_dadata: "",
placebirth: "", placebirth: "",
citizenship_code: "", citizenship: {
title: "",
code: "",
},
registration_address: { registration_address: {
title: "", title: "",
fias_id: "", fias_id: "",
@ -213,7 +216,10 @@ export const defaultState = {
issueby: "", issueby: "",
issueby_search_dadata: "", issueby_search_dadata: "",
placebirth: "", placebirth: "",
citizenship_code: "", citizenship: {
title: "",
code: "",
},
registration_address: { registration_address: {
title: "", title: "",
fias_id: "", fias_id: "",
@ -221,36 +227,6 @@ export const defaultState = {
} }
}, },
signatory_person_files: [], signatory_person_files: [],
founded_persons_template: {
signatory_id: null,
lastname: "",
firstname: "",
middlename: "",
no_middle_name: false,
jobtitle: "",
telephone: "",
email: "",
founder_from_list: true,
founder_number: 0,
founder_part: "",
is_beneficial: false,
identity_document:
{
doctype: "",
seria: "",
docnumber: "",
issuedate: "",
icode: "",
issueby: "",
issueby_search_dadata: "",
placebirth: "",
citizenship_code: "",
registration_address: {
title: "",
fias_id: "",
}
}
},
founded_persons: [], founded_persons: [],
client_contacts: { client_contacts: {
lastname: "", lastname: "",
@ -278,7 +254,10 @@ export const defaultState = {
issueby: "", issueby: "",
issueby_search_dadata: "", issueby_search_dadata: "",
placebirth: "", placebirth: "",
citizenship_code: "", citizenship: {
title: "",
code: "",
},
registration_address: { registration_address: {
title: "", title: "",
fias_id: "", fias_id: "",

View File

@ -11,23 +11,30 @@ export function isPluginCryptoProInstalled()
{ {
console.log("window.cadesplugin", "AFTER", window.cadesplugin); console.log("window.cadesplugin", "AFTER", window.cadesplugin);
window.cadesplugin.async_spawn(function *(args) if(window.cadesplugin !== undefined)
{ {
try window.cadesplugin.async_spawn(function *(args)
{ {
yield window.cadesplugin try
} {
catch (e) yield window.cadesplugin
{ }
console.error("isPluginCryptoProInstalled"); catch (e)
console.error(e); {
console.error("isPluginCryptoProInstalled");
reject({ message: e }) console.error(e);
return;
} reject({ message: e })
return;
resolve(); }
});
resolve();
});
}
else
{
reject();
}
}, 500); }, 500);
}); });
} }

View File

@ -360,6 +360,27 @@
"@nodelib/fs.scandir" "2.1.5" "@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0" fastq "^1.6.0"
"@pdf-lib/fontkit@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@pdf-lib/fontkit/-/fontkit-1.1.1.tgz#f18473892b65e3253eb73f4569785abd2c03b1e0"
integrity sha512-KjMd7grNapIWS/Dm0gvfHEilSyAmeLvrEGVcqLGi0VYebuqqzTbgF29efCx7tvx+IEbG3zQciRSWl3GkUSvjZg==
dependencies:
pako "^1.0.6"
"@pdf-lib/standard-fonts@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz#8ba691c4421f71662ed07c9a0294b44528af2d7f"
integrity sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA==
dependencies:
pako "^1.0.6"
"@pdf-lib/upng@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@pdf-lib/upng/-/upng-1.0.1.tgz#7dc9c636271aca007a9df4deaf2dd7e7960280cb"
integrity sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ==
dependencies:
pako "^1.0.10"
"@restart/hooks@^0.4.5": "@restart/hooks@^0.4.5":
version "0.4.7" version "0.4.7"
resolved "https://registry.yarnpkg.com/@restart/hooks/-/hooks-0.4.7.tgz#d79ca6472c01ce04389fc73d4a79af1b5e33cd39" resolved "https://registry.yarnpkg.com/@restart/hooks/-/hooks-0.4.7.tgz#d79ca6472c01ce04389fc73d4a79af1b5e33cd39"
@ -3028,7 +3049,7 @@ p-try@^2.0.0:
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6" resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ== integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==
pako@~1.0.5: pako@^1.0.10, pako@^1.0.11, pako@^1.0.6, pako@~1.0.5:
version "1.0.11" version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf" resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw== integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
@ -3107,6 +3128,16 @@ pbkdf2@^3.0.3:
safe-buffer "^5.0.1" safe-buffer "^5.0.1"
sha.js "^2.4.8" sha.js "^2.4.8"
pdf-lib@^1.17.1:
version "1.17.1"
resolved "https://registry.yarnpkg.com/pdf-lib/-/pdf-lib-1.17.1.tgz#9e7dd21261a0c1fb17992580885b39e7d08f451f"
integrity sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw==
dependencies:
"@pdf-lib/standard-fonts" "^1.0.0"
"@pdf-lib/upng" "^1.0.1"
pako "^1.0.11"
tslib "^1.11.1"
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1: picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
version "2.3.1" version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
@ -3932,7 +3963,7 @@ tsconfig-paths@^3.14.1:
minimist "^1.2.6" minimist "^1.2.6"
strip-bom "^3.0.0" strip-bom "^3.0.0"
tslib@^1.8.1: tslib@^1.11.1, tslib@^1.8.1:
version "1.14.1" version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==