From 97503afe14c30e53b712217af379c99092e1808b Mon Sep 17 00:00:00 2001 From: merelendor Date: Thu, 5 Oct 2023 15:49:11 +0300 Subject: [PATCH] deals EDO sign updates --- actions/signActions.js | 26 ++- components/DealsStatus/SingleDeal.js | 2 +- components/EDOSign/index.js | 199 +++++++++++------- lib/CRMRequest/index.js | 72 +++++++ lib/CRMRequestGet/index.js | 27 ++- .../sign/{document.js => document/create.js} | 19 +- pages/api/contract/sign/document/download.js | 21 ++ 7 files changed, 265 insertions(+), 101 deletions(-) create mode 100644 lib/CRMRequest/index.js rename pages/api/contract/sign/{document.js => document/create.js} (52%) create mode 100644 pages/api/contract/sign/document/download.js diff --git a/actions/signActions.js b/actions/signActions.js index ecf097b..bee93fa 100644 --- a/actions/signActions.js +++ b/actions/signActions.js @@ -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); }); }); diff --git a/components/DealsStatus/SingleDeal.js b/components/DealsStatus/SingleDeal.js index c67bfd9..01fc454 100644 --- a/components/DealsStatus/SingleDeal.js +++ b/components/DealsStatus/SingleDeal.js @@ -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, }); } diff --git a/components/EDOSign/index.js b/components/EDOSign/index.js index 86b0c8f..8809413 100644 --- a/components/EDOSign/index.js +++ b/components/EDOSign/index.js @@ -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

Подписание через ЭДО

-
- { documents.map((document, index) => - ( -
-
-

- { document.name } от { moment(document.date).format("DD.MM.YYYY") } - { document.type !== undefined && ({ document.type }) } -

-
-
- { document.loading ? ( - <> - { loading && ( - - ) } - - ) : ( - <> - { document.error ? ( - <> -
- { document.message } - - ) : ( - <> - { document.attorney && ( - <> -
-
- !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 } + /> +
+ + ) } + { document.completed && ( + <> +
+ { document.entity_id !== undefined && ( + <> + + + + ) } + + ) } + + ) } + + ) } +
+
+ )) } +
+ ) } +
{if (e.key === 'Enter') e.preventDefault() }}>