deal paper sign with mailing

This commit is contained in:
merelendor 2023-10-23 10:49:38 +03:00
parent ffa61d9619
commit f945f95a24
6 changed files with 234 additions and 77 deletions

View File

@ -180,6 +180,47 @@ export const signGetFileContractProject = (payload) =>
console.error("ACTION", "sign", "signGetFileContractProject()", "ERROR");
console.error(error);
reject(error.data);
});
});
}
export const signUploadPaperDocument = (contract_number, deal_id, files) =>
{
console.log({ contract_number, files });
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/upload`;
return new Promise((resolve, reject) =>
{
let data = new FormData();
data.append('contract_number', contract_number);
data.append('deal_id', deal_id);
for(let i in files)
{
data.append('files', files[i]);
}
axios.post(url, data, {
headers: {
"Content-Type": "multipart/form-data",
},
withCredentials: true,
})
.then((response) =>
{
if(parseInt(process.env.LOG, 10) === 1) { console.log("ACTION", "sign", "signUploadPaperDocument()", "response", response.data); }
setTimeout(() =>
{
resolve();
}, 2000);
})
.catch((error) =>
{
console.error("ACTION", "sign", "signUploadPaperDocument()", "ERROR");
console.error(error);
reject(error.data);
});
});

View File

@ -5,8 +5,9 @@ import { SpinnerCircular } from "spinners-react";
import { concatSeries } from "async";
import { eachSeries } from 'async';
import Select from 'react-select';
import Dropzone from 'react-dropzone';
import { createEDOProject, docEDOCancel, signCheckCreatePrintForm, signDownloadFile, signGetGUIDEntity, signGetWMDoc, docEDOSign, docEDOStatus, docEDOConnect } from "../../../actions";
import { docEDOCancel, signCheckCreatePrintForm, signGetGUIDEntity, signGetWMDoc, docEDOStatus, getFile, signGetFileContractProject, signUploadPaperDocument } from "../../../actions";
export default class DealContractsSignPaper extends React.Component
{
@ -60,9 +61,20 @@ export default class DealContractsSignPaper extends React.Component
for(let i in documents)
{
console.log({ fin: documents[i] });
if(!documents[i].completed)
completed = false;
break;
if(documents[i].error)
{
console.log(11111);
continue;
}
else
{
if(!documents[i].completed)
{
console.log(22222);
completed = false;
break;
}
}
}
return completed;
@ -84,37 +96,17 @@ export default class DealContractsSignPaper extends React.Component
{
callback();
}
else if(document.signing)
if(document.uploading)
{
await this._updateDocs(document.index, { loading: true, });
const status_result = await docEDOStatus({ contract_number: document.id });
if(status_result.status === 3)
{
await this._updateDocs(document.index, { loading: false, signing: false, ready: false, completed: true, });
}
else
{
await this._updateDocs(document.index, { loading: false, signing: true, ready: false, });
}
callback();
}
else if(document.ready)
{
callback();
/*
console.log({ document })
await this._updateDocs(document.index, { loading: true, });
const status_result = await docEDOStatus({ contract_number: document.id });
console.log({ status_result });
if(status_result.status > 0)
{
const sign_result = await docEDOSign({ edoid: status_result.edoid });
}
await this._updateDocs(document.index, { loading: false, signing: true, ready: false, error: false, });
callback();
*/
}
else
{
@ -150,8 +142,6 @@ export default class DealContractsSignPaper extends React.Component
});
console.log({ wmdoc_result });
const connect_result = await docEDOConnect({ contract_number: document.id });
await this._updateDocs(document.index, {
entity_id: get_guid_entity_result.entityid,
ready: true,
@ -162,7 +152,12 @@ export default class DealContractsSignPaper extends React.Component
}
else
{
await this._updateDocs(document.index, { loading: false, error: true, ready: true, message: "Возникла ошибка при создании документа для подписания." });
await this._updateDocs(document.index, {
loading: false,
error: true,
ready: true,
message: create_print_form_result.message !== undefined && create_print_form_result.message !== null ? create_print_form_result.message : "Возникла ошибка при создании документа для подписания.",
});
callback();
}
}
@ -174,7 +169,7 @@ export default class DealContractsSignPaper extends React.Component
}
else
{
this.setState({ loading: false });
this.setState({ loading: false, finished: false, });
}
});
});
@ -201,19 +196,23 @@ export default class DealContractsSignPaper extends React.Component
}
}
_handle_onDownloadFile = (index, entity_id, name) =>
_handle_onDownloadFile = (index) =>
{
console.log("_handle_onDownloadFile", { index, entity_id });
const { documents } = this.state;
this.setState({ loading: true, disabled: true, }, async () =>
{
await this._updateDocs(index, { loading: true });
const wmdoc_result = await signDownloadFile({
payload: { entity_name: "evo_contract", entity_id, sign_type: "EDO", evo_id: "144", },
filename: `ЛК ЭВОЛЮЦИЯ ${ name }.pdf`,
const link_result = await signGetFileContractProject({
contract_number: documents[index].id,
});
await this._updateDocs(index, { loading: false, disabled: false, });
console.log("_handle_onDownloadFile", { link_result });
await getFile({ id: link_result.url, filename: `ЛК ЭВОЛЮЦИЯ ${ documents[index].id }.${ link_result.extension }` });
await this._updateDocs(index, { loading: false, disabled: false, ready: false, uploading: true, });
this.setState({ loading: false, disabled: false, });
});
}
@ -225,7 +224,7 @@ export default class DealContractsSignPaper extends React.Component
this.setState({ loading: true, disabled: true }, async () =>
{
await docEDOCancel({ contract_number: documents[index].id, doc_type_id: "144" });
await docEDOCancel({ contract_number: documents[index].id, doc_type_id: "60" });
const docs = [ ...this.state.documents ];
docs.splice(index, 1);
@ -256,29 +255,33 @@ export default class DealContractsSignPaper extends React.Component
onCancel(clean);
}
_handle_onCheckEDOStatus = async (index) =>
_handle_onUploadFile = async (files, index) =>
{
const { documents } = this.state;
const { deal_id } = this.props;
console.log("_handle_onUploadFile", { files, index });
await this._updateDocs(index, { loading: true });
this.setState({ loading: true, disabled: true }, async () =>
{
const status_result = await docEDOStatus({ contract_number: document.id });
console.log({ status_result });
await signUploadPaperDocument(documents[index].id, deal_id, files);
await this._updateDocs(index, { loading: false, uploading: false, completed: true, });
if(status_result.status === 3)
if(this._checkDocumentsCompleted())
{
await this._updateDocs(index, { loading: false, disabled: false, signing: false, completed: true, });
this.setState({ loading: false, disabled: false, finished: true, });
}
else
{
await this._updateDocs(index, { loading: false, disabled: false, signing: true, completed: false, });
this.setState({ loading: false, disabled: false, finished: false, });
}
});
}
_handle_onGoToEDO = () =>
_handle_onCancelUpload = async (index) =>
{
await this._updateDocs(index, { ready: true, uploading: false, });
}
render()
@ -320,34 +323,31 @@ export default class DealContractsSignPaper extends React.Component
</>
) : (
<>
{ document.upload && (
<>
<div className="status_icon await"></div>
<div className="edo_sign_status_attorney_select">
UPLOAD
</div>
</>
) }
{ document.ready && (
<>
<div className="status_icon success"></div>
{ document.entity_id !== undefined && (
<>
<button className="button" disabled={ disabled } onClick={ () => this._handle_onDownloadFile(index, document.entity_id, document.name) }>Посмотреть проект договора</button>
<button className="button" disabled={ disabled } onClick={ () => this._handle_onDownloadFile(index) }>Посмотреть проект договора</button>
<button className="button" disabled={ disabled } onClick={ () => this._handle_onCancelFile(index) }>Отменить подписание</button>
</>
) }
</>
) }
{ document.signing && (
{ document.uploading && (
<>
<div className="status_icon success"></div>
<div className="status_title">
<i>Идет процесс подписания</i>
</div>
<div className="status_icon await"></div>
{ document.entity_id !== undefined && (
<>
<button className="button" disabled={ disabled } onClick={ () => this._handle_onCheckEDOStatus(index) }>Проверить статус</button>
<>
<Dropzone onDrop={ (acceptedFiles) => this._handle_onUploadFile(acceptedFiles, index) } maxFiles={ 10 }>
{ ({getRootProps, getInputProps}) => (
<div { ...getRootProps() }>
<button className="button" disabled={ disabled }>Загрузить скан подписанного документа</button>
<input { ...getInputProps() } />
</div>
) }
</Dropzone>
<button className="button" disabled={ disabled } onClick={ () => this._handle_onCancelUpload(index) }>Отменить загрузку</button>
</>
) }
</>
@ -356,11 +356,8 @@ export default class DealContractsSignPaper extends React.Component
<>
<div className="status_icon success"></div>
<div className="status_title">
<i>Договор подписан со стороны "ЛК Эволюция"</i>
<i>Договор отправлен вашему менеджеру "ЛК Эволюция"</i>
</div>
{ document.entity_id !== undefined && (
<button className="button" disabled={ disabled } onClick={ () => this._handle_onGoToEDO(index) }>Перейти в ЭДО</button>
) }
</>
) }
</>
@ -375,15 +372,11 @@ export default class DealContractsSignPaper extends React.Component
<form ref={ this.ref_form } onSubmit={ this._handle_onFormSubmit } onKeyDown={(e) => {if (e.key === 'Enter') e.preventDefault() }}>
<div className="form_field" style={{ display: "flex", justifyContent: "space-between" }}>
<button className="button button-blue" onClick={ this._handle_onCancel }>Отменить</button>
{ finished ? (
<button type="submit" className="button button-blue">Завершить</button>
) : (
<button type="submit" className="button button-blue">
{ loading ? (
<SpinnerCircular size={24} thickness={100} speed={100} color="rgba(255, 255, 255, 1)" secondaryColor="rgba(255, 255, 255, 0.5)" style={{ marginTop: "4px" }}/>
) : "Продолжить" }
</button>
) }
<button type="submit" className="button button-blue" disabled={ finished ? false : true }>
{ loading ? (
<SpinnerCircular size={24} thickness={100} speed={100} color="rgba(255, 255, 255, 1)" secondaryColor="rgba(255, 255, 255, 0.5)" style={{ marginTop: "4px" }}/>
) : "Продолжить" }
</button>
</div>
</form>
</div>

View File

@ -177,6 +177,7 @@ export default class LeasingRegistration extends Step
_render_preparedContracts = () =>
{
const { dealSelected } = this.props;
const { edo, paper, checked } = this.state;
//const checked = this.state.checked.prepared_contracts;
@ -198,7 +199,8 @@ export default class LeasingRegistration extends Step
if(paper)
{
return (
<DealContractsSignPaper
<DealContractsSignPaper
deal_id={ dealSelected }
documents={ this._getDocuments() }
onCancel={ this._handle_onCancelPaper }
onFinish={ this._handle_onFinishPaper }

View File

@ -35,6 +35,7 @@
"next-with-less": "^1.0.1",
"nextjs-cors": "^2.1.0",
"node-fetch": "^3.3.1",
"nodemailer": "^6.9.7",
"numeral": "^2.0.6",
"pdf-lib": "^1.17.1",
"pluralize-ru": "^1.0.1",

View File

@ -0,0 +1,115 @@
import fs from 'fs';
import axios from 'axios';
import { Cookies } from 'react-cookie';
import cookie from 'cookie';
import moment from 'moment';
import jwt from 'jsonwebtoken';
import Redis from 'ioredis';
import md5 from 'md5';
import { inspect } from 'util';
import multer from 'multer';
import nodemailer from "nodemailer";
import { cors } from '../../../../../lib/cors';
const transporter = nodemailer.createTransport({
host: process.env.EMAIL_HOSTNAME,
port: 465,
secure: true,
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASSWORD,
},
});
console.log({ host: process.env.EMAIL_HOSTNAME, user: process.env.EMAIL_USERNAME, pass: process.env.EMAIL_PASSWORD });
const storage = multer.memoryStorage();
const upload = multer({ storage: storage, limits: { fileSize: 1024 * 1024 * 300 } });
export default async function handler(req, res)
{
console.log("\n\n", "API", "SIGN", "/document/upload");
await cors(req, res);
return new Promise(async (resolve) =>
{
if(req.headers.cookie !== undefined)
{
const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : "");
if(cookies.jwt !== undefined && cookies.jwt !== null)
{
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 });
upload.array("files", 10)(req, {}, (err) =>
{
const { contract_number, deal_id, } = req.body;
const { files } = req;
const attachments = [];
for(let i in files)
{
attachments.push({
filename: Buffer.from(files[i].originalname, 'latin1').toString('utf8'),
content: files[i].buffer,
});
}
axios.get(`${ process.env.CRM_API_HOST }/lk/Account/GetCompanyInfo/`, {
params: {
acc_number: client_jwt_decoded.acc_number,
},
headers: {
"Authorization": `Bearer ${ crm_jwt }`,
}
})
.then(async (crm_response) =>
{
console.log({ crm_response: crm_response.data });
const { manager_email } = crm_response.data;
if(manager_email !== undefined && manager_email !== null && manager_email !== "")
{
const mail_result = await transporter.sendMail({
from: '"Devone" <devone@quickcode.ru>',
to: "aepifanov@evoleasing.ru",
subject: `Скан договора №${ contract_number } для сделки №${ deal_id }`,
text: `Клиентом загружен скан договора №${ contract_number } для сделки №${ deal_id }`,
attachments,
});
console.log({ mail_result });
}
res.status(200).send();
resolve();
})
.catch((crm_error) =>
{
console.error({ crm_error: crm_error.data });
res.status(500).send();
resolve();
})
});
}
else
{
res.status(403).send();
resolve();
}
}
else
{
res.status(403).send();
resolve();
}
});
}
export const config = {
api: {
bodyParser: false
}
}

View File

@ -4816,6 +4816,11 @@ node-releases@^1.1.71:
resolved "https://registry.npmjs.org/node-releases/-/node-releases-1.1.77.tgz"
integrity sha512-rB1DUFUNAN4Gn9keO2K1efO35IDK7yKHCdCaIMvFO7yUYmmZYeDjnGKle26G4rwj+LKRQpjyUUvMkPglwGCYNQ==
nodemailer@^6.9.7:
version "6.9.7"
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.9.7.tgz#ec2f488f62ba1558e7b19239b62778df4a5c4397"
integrity sha512-rUtR77ksqex/eZRLmQ21LKVH5nAAsVicAtAYudK7JgwenEDZ0UIQ1adUGqErz7sMkWYxWTTU1aeP2Jga6WQyJw==
normalize-path@^2.0.0, normalize-path@^2.0.1:
version "2.1.1"
resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz"