deals EDO sign updates

This commit is contained in:
merelendor 2023-10-05 15:49:11 +03:00
parent 7872d0ec4b
commit 97503afe14
7 changed files with 265 additions and 101 deletions

View File

@ -112,7 +112,7 @@ export const signGetPowerAttorneyClient = ({ contract_number }) =>
export const signGetWMDoc = (payload) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document`;
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/create`;
return new Promise((resolve, reject) =>
{
@ -129,6 +129,30 @@ export const signGetWMDoc = (payload) =>
console.error("ACTION", "sign", "signGetWMDoc()", "ERROR");
console.error(error);
reject(error.data);
});
});
}
export const signDownloadFile = (payload) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/download`;
return new Promise((resolve, reject) =>
{
axios.post(url, payload, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "sign", "signDownloadFile()", "response", response.data);
resolve(response.data);
})
.catch((error) =>
{
console.error("ACTION", "sign", "signDownloadFile()", "ERROR");
console.error(error);
reject(error.data);
});
});

View File

@ -107,7 +107,7 @@ class Offers extends Step
for(let i in checked)
{
offers.push({
quote_numbers: checked[i],
quote_number: checked[i],
agreed: true,
});
}

View File

@ -5,9 +5,10 @@ import { SpinnerCircular } from "spinners-react";
import { concatSeries } from "async";
import { eachSeries } from 'async';
import Select from 'react-select';
import fileDownload from 'js-file-download';
import { createEDOProject, signCheckEDOCreatePrintForm, signCheckPowerAttorneyClient, signGetGUIDEntity, signGetPowerAttorneyClient, signGetWMDoc } from "../../actions";
import { createEDOProject, signCheckEDOCreatePrintForm, signCheckPowerAttorneyClient, signDownloadFile, signGetGUIDEntity, signGetPowerAttorneyClient, signGetWMDoc } from "../../actions";
//import { getDeals, getDealOffers, getDealDocuments, getDealContracts } from "../../actions";
class EDOSign extends React.Component
@ -21,6 +22,7 @@ class EDOSign extends React.Component
documents: [],
operator_selected: {},
statuses: {},
step: 0,
}
}
@ -61,12 +63,10 @@ class EDOSign extends React.Component
});
}
_handle_onFormSubmit = (event) =>
_sign = () =>
{
event.preventDefault();
//const { documents } = this.props;
const { operator_selected } = this.state;
const { operator_selected, step } = this.state;
const documents = [ ...this.state.documents ];
console.log("_handle_onFormSubmit");
@ -177,11 +177,19 @@ class EDOSign extends React.Component
contract_number: document.id,
edo_box: operator_selected.edo_box,
});
const get_guid_entity_result = await signGetGUIDEntity({
contract_number: document.id,
});
const wmdoc_result = await signGetWMDoc({
entity_name: "evo_contract",
entity_id: get_guid_entity_result.entityid,
sign_type: "EDO",
evo_id: "144",
});
console.log({ wmdoc_result });
await this._updateDocs(document.index, {
entity_id: get_guid_entity_result.entityid,
completed: true,
@ -202,7 +210,37 @@ class EDOSign extends React.Component
{
this.setState({ loading: false });
});
})
});
}
_handle_onFormSubmit = (event) =>
{
event.preventDefault();
//const { documents } = this.props;
const { operator_selected, step } = this.state;
const documents = [ ...this.state.documents ];
console.log("_handle_onFormSubmit");
console.log({ documents, operator_selected });
switch(step)
{
case 0:
{
this.setState({ step: 1 }, () =>
{
this._sign();
});
}
break;
case 1:
{
this._sign();
}
break;
}
}
_handle_onSelectOperator = (operator) =>
@ -216,15 +254,16 @@ class EDOSign extends React.Component
this._updateDocs(index, { attorney_selected: attorney });
}
_handle_onDownloadFile = (index, entity_id) =>
_handle_onDownloadFile = (index, entity_id, name) =>
{
console.log("_handle_onDownloadFile", { index, entity_id })
console.log("_handle_onDownloadFile", { index, entity_id });
this.setState({ loading: true }, async () =>
{
await this._updateDocs(index, { loading: true });
const wmdoc_result = await signGetWMDoc({ entity_name: "evo_contract", entity_id, sign_type: "EDO" });
const wmdoc_result = await signDownloadFile({ entity_name: "evo_contract", entity_id, sign_type: "EDO", evo_id: "144", });
console.log({ wmdoc_result });
fileDownload(wmdoc_result, `ЛК ЭВОЛЮЦИЯ ${ name }.pdf`);
await this._updateDocs(index, { loading: false });
});
@ -241,7 +280,7 @@ class EDOSign extends React.Component
render()
{
const { operators, documents, loading, operator_selected } = this.state;
const { step, operators, documents, loading, operator_selected } = this.state;
const { onCancel, } = this.props;
console.log({ operators, documents });
@ -250,72 +289,7 @@ class EDOSign extends React.Component
<div className="docs_list medium-icon">
<p className="list_title">Подписание через ЭДО</p>
</div>
<div className="docs_list medium-icon edo_sign_documents_list">
{ documents.map((document, index) =>
(
<div className="edo_sign_documents_document" key={ index }>
<div className="edo_sign_documents_document_left">
<p className="doc_name i-pdf extension edo_sign_document" data-format={ document.extension }>
{ document.name } от { moment(document.date).format("DD.MM.YYYY") }
{ document.type !== undefined && (<span>{ document.type }</span>) }
</p>
</div>
<div className="edo_sign_documents_document_right">
{ document.loading ? (
<>
{ loading && (
<SpinnerCircular size={ 22 } thickness={ 100 } speed={ 100 } color="rgba(236, 239, 244, 1)" secondaryColor="rgba(28, 1, 169, 1)" />
) }
</>
) : (
<>
{ document.error ? (
<>
<div className="status_icon error"></div>
<i>{ document.message }</i>
</>
) : (
<>
{ document.attorney && (
<>
<div className="status_icon await"></div>
<div className="edo_sign_status_attorney_select">
<Select
id="edo_attorneys_list"
name="edo_attorneys_list"
options={ document.attorneys }
placeholder="Выберите подписанта"
noOptionsMessage={ ({ inputValue }) => !inputValue ? "" :"Ничего не найдено" }
isSearchable={ true }
className="autocomlete autocomlete_with_indicators"
classNamePrefix="react-select"
value={ document.attorney_selected }
onChange={ (element) => { this._handle_onAttorneyChange(document.index, element) } }
required={ true }
/>
</div>
</>
) }
{ document.completed && (
<>
<div className="status_icon success"></div>
{ document.entity_id !== undefined && (
<>
<button className="button" onClick={ () => this._handle_onDownloadFile(index, document.entity_id) }>Посмотреть проект договора</button>
<button className="button" onClick={ () => this._handle_onCancelFile(index, document.entity_id) }>Отменить подписание</button>
</>
) }
</>
) }
</>
) }
</>
) }
</div>
</div>
)) }
</div>
<form ref={ this.ref_form } onSubmit={ this._handle_onFormSubmit } onKeyDown={(e) => {if (e.key === 'Enter') e.preventDefault() }}>
{ step === 0 && (
<div className="form_field edo_list_field">
<label>Выберите оператора для отправки пакета документов</label>
<div className="edo_list_selection">
@ -334,6 +308,75 @@ class EDOSign extends React.Component
)) }
</div>
</div>
) }
{ step === 1 && (
<div className="docs_list medium-icon edo_sign_documents_list">
{ documents.map((document, index) =>
(
<div className="edo_sign_documents_document" key={ index }>
<div className="edo_sign_documents_document_left">
<p className="doc_name i-pdf extension edo_sign_document" data-format={ document.extension }>
{ document.name } от { moment(document.date).format("DD.MM.YYYY") }
{ document.type !== undefined && (<span>{ document.type }</span>) }
</p>
</div>
<div className="edo_sign_documents_document_right">
{ document.loading ? (
<>
{ loading && (
<SpinnerCircular size={ 22 } thickness={ 100 } speed={ 100 } color="rgba(236, 239, 244, 1)" secondaryColor="rgba(28, 1, 169, 1)" />
) }
</>
) : (
<>
{ document.error ? (
<>
<div className="status_icon error"></div>
<i>{ document.message }</i>
</>
) : (
<>
{ document.attorney && (
<>
<div className="status_icon await"></div>
<div className="edo_sign_status_attorney_select">
<Select
id="edo_attorneys_list"
name="edo_attorneys_list"
options={ document.attorneys }
placeholder="Выберите доверенность"
noOptionsMessage={ ({ inputValue }) => !inputValue ? "" :"Ничего не найдено" }
isSearchable={ true }
className="autocomlete autocomlete_with_indicators"
classNamePrefix="react-select"
value={ document.attorney_selected }
onChange={ (element) => { this._handle_onAttorneyChange(document.index, element) } }
required={ true }
/>
</div>
</>
) }
{ document.completed && (
<>
<div className="status_icon success"></div>
{ document.entity_id !== undefined && (
<>
<button className="button" onClick={ () => this._handle_onDownloadFile(index, document.entity_id, document.name) }>Посмотреть проект договора</button>
<button className="button" onClick={ () => this._handle_onCancelFile(index, document.entity_id) }>Отменить подписание</button>
</>
) }
</>
) }
</>
) }
</>
) }
</div>
</div>
)) }
</div>
) }
<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={ onCancel }>Отменить</button>
<button type="submit" className="button button-blue">

72
lib/CRMRequest/index.js Normal file
View File

@ -0,0 +1,72 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import axios from 'axios';
import { Cookies } from 'react-cookie';
import cookie from 'cookie';
import moment from 'moment';
import jwt from 'jsonwebtoken';
import { cors } from '../cors';
import { inspect } from 'util';
export default async function CRMRequest(req, res, path, method, data, log = false)
{
await cors(req, res);
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 });
if(log)
{
console.log("client_jwt_decoded", client_jwt_decoded);
console.log("crm_jwt", crm_jwt);
console.log("path", path);
}
try
{
axios.request({
url: path,
method,
headers: {
"Authorization": `Bearer ${ crm_jwt }`,
"Content-Type": "application/json"
},
data,
})
.then((crm_response) =>
{
if(log)
{
console.log("crm_response for", path);
console.log("payload", payload);
console.log(inspect(crm_response.data, true, null, true));
}
res.status(200).json(crm_response.data);
})
.catch((error) =>
{
console.error(error);
console.error("-".repeat(30), "error.response.data:");
console.error(error.response.data);
res.status(500).json(error.response.data);
});
}
catch(e)
{
console.error(e);
res.status(500).send(e);
}
}
else
{
res.status(403);
}
}
}

View File

@ -7,7 +7,7 @@ import jwt from 'jsonwebtoken';
import { cors } from '../cors';
import { inspect } from 'util';
export default async function CRMRequestGet(req, res, path, params, log = false)
export default async function CRMRequestGet(req, res, path, params, data = undefined, log = false)
{
await cors(req, res);
@ -44,15 +44,26 @@ export default async function CRMRequestGet(req, res, path, params, log = false)
const payload = { ...{ acc_number: client_jwt_decoded.acc_number }, ...params };
const options = {
headers: {
"Authorization": `Bearer ${ crm_jwt }`,
"Content-Type": "application/json"
},
withCredentials: true,
};
if(data !== undefined)
{
options.data = data;
}
else
{
options.params = payload;
}
try
{
await axios.get(path, {
params: payload,
headers: {
"Authorization": `Bearer ${ crm_jwt }`,
},
withCredentials: true,
})
await axios.get(path, options)
.then((crm_response) =>
{
if(log)

View File

@ -1,28 +1,21 @@
import CRMRequestGet from '../../../../lib/CRMRequestGet';
import CRMRequestGet from '../../../../../lib/CRMRequestGet';
export default async function handler(req, res)
{
console.log("API", "SIGN", "/document");
console.log("API", "SIGN", "/document/create");
const { entity_name, entity_id, sign_type } = req.body;
const { entity_name, entity_id, sign_type, evo_id } = req.body;
const payload = {
entityName: entity_name,
entityId: entity_id,
reportCodes: [ "Leas_Contract" ],
inputParameters: [ sign_type ],
createDocument: true,
openFile: false,
documentTypeEvoId: evo_id,
};
console.log({ payload });
if(sign_type === "EDO")
{
payload.documentTypeEvoId = 144;
}
else
{
payload.documentTypeEvoId = 60;
}
await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/File/GetWMDoc`, payload);
await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/File/GetWMDoc`, undefined, JSON.stringify(payload));
}

View File

@ -0,0 +1,21 @@
import CRMRequestGet from '../../../../../lib/CRMRequestGet';
export default async function handler(req, res)
{
console.log("API", "SIGN", "/document/download");
const { entity_name, entity_id, sign_type, evo_id } = req.body;
const payload = {
entityName: entity_name,
entityId: entity_id,
reportCodes: [ "Leas_Contract" ],
inputParameters: [ sign_type ],
createDocument: false,
openFile: true,
documentTypeEvoId: evo_id,
};
console.log({ payload });
await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/File/GetWMDoc`, undefined, JSON.stringify(payload));
}