From ec617b315f2c317991e5308ed49c294d2d52f167 Mon Sep 17 00:00:00 2001 From: merelendor Date: Mon, 9 Oct 2023 12:55:40 +0300 Subject: [PATCH] EDO sign on deal finished --- actions/edoActions.js | 134 ++++- actions/fileActions.js | 2 - actions/signActions.js | 37 +- components/DealsStatus/DealsList.js | 3 +- components/DealsStatus/SingleDeal.js | 458 +++++++++++++----- components/DealsStatus/index.js | 11 + components/EDOSign/index.js | 353 ++++++++++---- css/main/style.css | 34 +- css/main/style.less | 46 +- lib/CRMRequestGet/index.js | 31 +- pages/api/contract/agreement.js | 2 +- pages/api/contract/change/calculations.js | 2 +- .../contract/change/graphic/calculation.js | 2 +- pages/api/contract/change/graphic/current.js | 2 +- pages/api/contract/change/options.js | 2 +- pages/api/contract/change/signatories.js | 2 +- pages/api/contract/change/variants.js | 2 +- pages/api/contract/fines.js | 2 +- pages/api/contract/helpcard.js | 2 +- pages/api/contract/index.js | 2 +- pages/api/contract/info.js | 2 +- pages/api/contract/penalties.js | 2 +- pages/api/contract/registration.js | 2 +- pages/api/contract/sign/attorney/check.js | 2 +- pages/api/contract/sign/attorney/get.js | 2 +- pages/api/contract/sign/cancel/check.js | 2 +- pages/api/contract/sign/cancel/index.js | 2 +- pages/api/contract/sign/check.js | 2 +- pages/api/contract/sign/document/connect.js | 18 + pages/api/contract/sign/document/create.js | 6 +- pages/api/contract/sign/document/download.js | 69 ++- pages/api/contract/sign/document/link.js | 18 + pages/api/contract/sign/document/status.js | 18 + pages/api/contract/sign/entity.js | 2 +- pages/api/contract/telematic.js | 2 +- pages/api/deals/contracts.js | 2 +- pages/api/deals/index.js | 2 +- pages/api/deals/offers.js | 2 +- pages/api/edo/cancel.js | 17 + pages/api/edo/invite/send.js | 2 +- pages/api/edo/invites.js | 2 +- pages/api/edo/operators.js | 2 +- pages/api/edo/project.js | 2 +- pages/api/edo/sign.js | 13 + 44 files changed, 1050 insertions(+), 272 deletions(-) create mode 100644 pages/api/contract/sign/document/connect.js create mode 100644 pages/api/contract/sign/document/link.js create mode 100644 pages/api/contract/sign/document/status.js create mode 100644 pages/api/edo/cancel.js create mode 100644 pages/api/edo/sign.js diff --git a/actions/edoActions.js b/actions/edoActions.js index 33a2d74..22b2c31 100644 --- a/actions/edoActions.js +++ b/actions/edoActions.js @@ -161,7 +161,137 @@ export const createEDOProject = (payload) => }); } -export const docEDOConnect = ({ contract_number }) => +export const docEDOSign = (payload) => { + const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/edo/sign`; -} \ No newline at end of file + if(parseInt(process.env.LOG, 10) === 1) + { + console.log("ACTION", "edo", "docEDOSign()", { url }); + } + + return new Promise((resolve, reject) => + { + axios.post(url, payload, { + withCredentials: true, + }) + .then((response) => + { + if(parseInt(process.env.LOG, 10) === 1) + { + console.log("ACTION", "edo", "docEDOSign()", "response", response.data); + } + + resolve(response.data); + }) + .catch((error) => + { + if(parseInt(process.env.LOG, 10) === 1) + { + console.error("ACTION", "edo", "docEDOSign()", "ERROR"); + console.error(error); + } + + reject(error.data); + }); + }); +} + +export const docEDOCancel = ({ contract_number, doc_type_id, }) => +{ + const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/edo/cancel`; + + console.log("ACTION", "edo", "docEDOCancel()", { url }); + + return new Promise((resolve, reject) => + { + axios.post(url, { contract_number, doc_type_id, }, { + withCredentials: true, + }) + .then((response) => + { + console.log("ACTION", "edo", "docEDOCancel()", "response", response.data); + + resolve(response.data); + }) + .catch((error) => + { + console.error("ACTION", "edo", "docEDOCancel()", "ERROR"); + console.error(error); + + reject(error.data); + }); + }); +} + +export const docEDOConnect = (payload) => +{ + const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/connect`; + + if(parseInt(process.env.LOG, 10) === 1) + { + console.log("ACTION", "edo", "docEDOConnect()", { url }); + } + + return new Promise((resolve, reject) => + { + axios.post(url, payload, { + withCredentials: true, + }) + .then((response) => + { + if(parseInt(process.env.LOG, 10) === 1) + { + console.log("ACTION", "edo", "docEDOConnect()", "response", response.data); + } + + resolve(response.data); + }) + .catch((error) => + { + if(parseInt(process.env.LOG, 10) === 1) + { + console.error("ACTION", "edo", "docEDOConnect()", "ERROR"); + console.error(error); + } + + reject(error.data); + }); + }); +} + +export const docEDOStatus = (payload) => +{ + const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/status`; + + if(parseInt(process.env.LOG, 10) === 1) + { + console.log("ACTION", "edo", "docEDOStatus()", { url }); + } + + return new Promise((resolve, reject) => + { + axios.post(url, payload, { + withCredentials: true, + }) + .then((response) => + { + if(parseInt(process.env.LOG, 10) === 1) + { + console.log("ACTION", "edo", "docEDOStatus()", "response", response.data); + } + + resolve(response.data); + }) + .catch((error) => + { + if(parseInt(process.env.LOG, 10) === 1) + { + console.error("ACTION", "edo", "docEDOStatus()", "ERROR"); + console.error(error); + } + + reject(error.data); + }); + }); +} diff --git a/actions/fileActions.js b/actions/fileActions.js index b2c2c62..09044de 100644 --- a/actions/fileActions.js +++ b/actions/fileActions.js @@ -67,8 +67,6 @@ export const getFile = ({ id, filename }) => }) .catch((error) => { - //console.log("error"); - console.error(error); reject(); diff --git a/actions/signActions.js b/actions/signActions.js index bee93fa..fccc1d5 100644 --- a/actions/signActions.js +++ b/actions/signActions.js @@ -4,6 +4,7 @@ import Router from 'next/router'; import moment from 'moment'; import { nSQL } from "@nano-sql/core"; import { concatSeries, eachSeries } from 'async'; +import fileDownload from 'js-file-download'; import * as actionTypes from '../constants/actionTypes'; import * as currentState from '../reducers/initialState'; @@ -134,25 +135,51 @@ export const signGetWMDoc = (payload) => }); } -export const signDownloadFile = (payload) => +export const signDownloadFile = ({ payload, filename }) => { 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, + axios.get(url, { + params: payload, + responseType: 'blob', }) .then((response) => { - console.log("ACTION", "sign", "signDownloadFile()", "response", response.data); - resolve(response.data); + fileDownload(response.data, filename); + resolve(); }) .catch((error) => { console.error("ACTION", "sign", "signDownloadFile()", "ERROR"); console.error(error); + reject(error.data); + }); + }); +} + +export const signGetFileContractProject = (payload) => +{ + const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/document/link`; + + return new Promise((resolve, reject) => + { + axios.post(url, payload, { + withCredentials: true, + }) + .then((response) => + { + if(parseInt(process.env.LOG, 10) === 1) { console.log("ACTION", "sign", "signGetFileContractProject()", "response", response.data); } + + resolve(response.data); + }) + .catch((error) => + { + console.error("ACTION", "sign", "signGetFileContractProject()", "ERROR"); + console.error(error); + reject(error.data); }); }); diff --git a/components/DealsStatus/DealsList.js b/components/DealsStatus/DealsList.js index 7af8901..c7086b1 100644 --- a/components/DealsStatus/DealsList.js +++ b/components/DealsStatus/DealsList.js @@ -39,7 +39,7 @@ export default class DealsList extends React.Component render() { - const { status, deals, questionnaire_status, dealSelected, onCloseDeal, onDealsUpdate } = this.props; + const { status, deals, questionnaire_status, dealSelected, onCloseDeal, onDealsUpdate, onDealContractsUpdate } = this.props; console.log({ deals }); @@ -59,6 +59,7 @@ export default class DealsList extends React.Component questionnaire_status={ questionnaire_status } onCloseDeal={ this._handle_onCloseDeal } onDealsUpdate={ onDealsUpdate } + onDealContractsUpdate={ onDealContractsUpdate } { ...deal } />) } diff --git a/components/DealsStatus/SingleDeal.js b/components/DealsStatus/SingleDeal.js index 01fc454..6de518f 100644 --- a/components/DealsStatus/SingleDeal.js +++ b/components/DealsStatus/SingleDeal.js @@ -1,19 +1,19 @@ -import React from "react" +import React from "react"; import numeral from "numeral"; import moment from "moment"; import { eachLimit } from "async"; - import { SpinnerCircular } from "spinners-react"; + import FileDropzoneDeals from "../FileDropzoneDeals"; import EDOSign from "../../components/EDOSign"; -import { acceptDealOffers, attachDealDocument, removeDealDocument, sendDealDocuments } from "../../actions"; +import { acceptDealOffers, attachDealDocument, docEDOCancel, docEDOStatus, getFile, removeDealDocument, sendDealDocuments, signDownloadFile, signGetFileContractProject } from "../../actions"; class Step extends React.Component { componentDidMount() { - if(this.status.indexOf(this.props.statuscode_id) > -1) + if(this.status === this.props.statuscode_id) { this.setState({ open: true }); } @@ -23,7 +23,7 @@ class Step extends React.Component { if(this.props.statuscode_id !== prevProps.statuscode_id) { - if(this.status.indexOf(this.props.statuscode_id) > -1) + if(this.status === this.props.statuscode_id) { this.setState({ open: true }); } @@ -46,11 +46,11 @@ class Step extends React.Component const { open } = this.state; return ( -
= this.status[ 0 ] ? { position: "relative", } : { position: "relative", cursor: "inherit" }} onClick={ statuscode_id >= this.status[ 0 ] ? this._handle_onSwitch : () => {} }> - { this.status.indexOf(statuscode_id) > -1 && (
)} - +
= this.status ? { position: "relative", } : { position: "relative", cursor: "inherit" }} onClick={ statuscode_id >= this.status ? this._handle_onSwitch : () => {} }> + { this.status === statuscode_id && (
)} +

{ title }

- { statuscode_id >= this.status[ 0 ] && ( + { statuscode_id >= this.status && (
@@ -71,7 +71,7 @@ class Offers extends Step loading: false, checked: [], }; - this.status = [ 100 ]; + this.status = 100; } _handle_onCheckOffer = (quote_number) => @@ -136,7 +136,7 @@ class Offers extends Step { return (
- +
) } @@ -150,7 +150,7 @@ class Offers extends Step const { checked, open, loading } = this.state; return ( -
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}> +
this.status ? "done" : "" }`}>

№ { dealSelected }

@@ -166,10 +166,10 @@ class Offers extends Step - { statuscode_id === 100 && } + - + @@ -178,39 +178,44 @@ class Offers extends Step - { offers.map((offer, offer_index) => ( - - { offer.quote_status ? ( + { offers.map((offer, offer_index) => + { + console.log({ offer }); + + return ( + + { offer.quote_status ? ( + + ) : ( + + )} + + + + + + + - ) : ( - - )} - - - - - - - - - - )) } + + + ) + } ) }
СтоимостьПервый платеж, р.Первый платеж, ₽ Первый платеж, % Марка Модель
+
+ -1 } onChange={ () => { this._handle_onCheckOffer(offer.quote_number) } }/> + +
+
{ offer_index + 1 }{ numeral(offer.price).format(' ., ') } ₽{ numeral(offer.first_payment_rub).format(' ., ') } ₽{ offer.first_payment_perc }%{ offer.brand_name }{ offer.model_name }{ offer.object_count } -
- -1 } onChange={ () => { this._handle_onCheckOffer(offer.quote_number) } }/> - -
-
{ offer_index + 1 }{ numeral(offer.price).format(' ., ') } р.{ numeral(offer.first_payment_rub).format(' ., ') } р.{ offer.first_payment_perc }%{ offer.brand_name }{ offer.model_name }{ offer.object_count } -
-
-
-

- КП - №{ offer.quote_number } -

+
+
+
+

+ КП + №{ offer.quote_number } +

+
-
-
) : ( @@ -233,7 +238,7 @@ class FinancialProgram extends Step this.state = { open: false, }; - this.status = [ 101 ]; + this.status = 101; } render() @@ -242,14 +247,18 @@ class FinancialProgram extends Step const { open } = this.state; return ( -
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}> +
this.status ? "done" : "" }`}>

№ { dealSelected }

{ this._renderHeader("Программа финансирования") }
-

Статусный текст о том что выбирается программа финансированияи

+ { statuscode_id === this.status ? ( +

Идёт подбор оптимальной программы финансирования

+ ) : ( +

Программа финансирования выбрана

+ ) }
@@ -270,14 +279,14 @@ class DocumentsForm extends Step completed: false, loading: true, }; - this.status = [ 102 ]; + this.status = 102; } componentDidUpdate(prevProps, prevState) { if(this.props.statuscode_id !== prevProps.statuscode_id) { - if(this.status.indexOf(this.props.statuscode_id) > -1) + if(this.status === this.props.statuscode_id) { this.setState({ open: true }); } @@ -487,14 +496,18 @@ class DocumentsForm extends Step _renderHeaderButtons = () => { const { open, uploading, completed, loading, } = this.state; + const { statuscode_id } = this.props; if(open && !uploading && !loading && completed) { - return ( -
- -
- ) + if(this.status === statuscode_id) + { + return ( +
+ +
+ ) + } } return null; @@ -506,7 +519,7 @@ class DocumentsForm extends Step const { open, files, uploading, loading } = this.state; return ( -
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}> +
this.status ? "done" : "" }`}>

№ { dealSelected }

@@ -547,21 +560,39 @@ class DocumentsForm extends Step <> ) : ( <> - { documents.map((document, index) => ( -
-
-

{ document.name }:

+ { documents.map((document, index) => + { + console.log({ document }); + return ( +
+
+

{ document.name }:

+
+
+ { document.add ? ( + { this._handle_onAddFile(document.doc_id, file) } } + onDeleteFile={ (file) => this._handle_onDeleteFile(document.doc_id, file) } + /> + ) : ( + <> + { document.check === "Документ принят" ? ( +
+

{ document.check }

+
+ ) : ( +
+

{ document.check }

+
+ ) } + + ) } +
-
- { this._handle_onAddFile(document.doc_id, file) } } - onDeleteFile={ (file) => this._handle_onDeleteFile(document.doc_id, file) } - /> -
-
- )) } + ) + } ) } ) } {/*} @@ -598,7 +629,7 @@ class StatusDocumentsCheck extends Step this.state = { open: false, }; - this.status = [ 103 ]; + this.status = 103; } render() @@ -607,14 +638,18 @@ class StatusDocumentsCheck extends Step const { open } = this.state; return ( -
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}> +
this.status ? "done" : "" }`}>

№ { dealSelected }

{ this._renderHeader("Проверка документов") }
-

Статусный текст о том что выбирается программа финансированияи

+ { statuscode_id === this.status ? ( +

Идёт проверка предоставленных документов

+ ) : ( +

Документы проверены

+ ) }
@@ -631,7 +666,7 @@ class StatusDecisionMaking extends Step this.state = { open: false, }; - this.status = [ 104, 105, ]; + this.status = 104; } render() @@ -639,15 +674,62 @@ class StatusDecisionMaking extends Step const { index, statuscode_id, dealSelected } = this.props; const { open } = this.state; + if(statuscode_id === 105) + { + return null; + } + return ( -
-1 ? "current" : (statuscode_id > this.status[0] && statuscode_id > this.status[1]) ? "done" : "" }`}> +
this.status) ? "done" : "" }`}>

№ { dealSelected }

{ this._renderHeader("Принятие решения по сделке") }
-

Статусный текст о том что выбирается программа финансированияи

+ { this.status === statuscode_id ? ( +

Принятие решение о финансировании

+ ) : ( +

Поздравляем! Принято положительное решение по сделке.

+ ) } +
+
+
+
+ ) + } +} + +class StatusDecisionRefuse extends Step +{ + constructor(props) + { + super(props); + this.state = { + open: false, + }; + this.status = 105; + } + + render() + { + const { index, statuscode_id, dealSelected } = this.props; + const { open } = this.state; + + if(statuscode_id !== this.status) + { + return null; + } + + return ( +
this.status) ? "done" : "" }`}> +

№ { dealSelected }

+ +
+ { this._renderHeader("Требуется изменение параметров") } +
+
+

Продолжение оформления заблокировано

@@ -664,7 +746,7 @@ class StatusPositiveDecision extends Step this.state = { open: false, }; - this.status = [ 106 ]; + this.status = 106; } render() @@ -673,14 +755,18 @@ class StatusPositiveDecision extends Step const { open } = this.state; return ( -
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}> +
this.status ? "done" : "" }`}>

№ { dealSelected }

{ this._renderHeader("Принято положительное решение") }
-

Статусный текст о том что выбирается программа финансированияи

+ { statuscode_id === this.status ? ( +

Идёт подготовка необходимых документов

+ ) : ( +

Документы подготовлены

+ ) }
@@ -689,6 +775,146 @@ class StatusPositiveDecision extends Step } } +class SignPlannedContract extends React.Component +{ + constructor(props) + { + super(props); + this.state = { + loading: true, + loading_download_file: false, + loading_cancel_sign: false, + disabled: false, + status: undefined, + contract_entity_id: undefined, + }; + } + + async componentDidMount() + { + const { contract } = this.props; + console.log("SignPlannedContract", "CDM", { props: this.props }); + + if(contract.sign_type === "EDO") + { + const status_result = await docEDOStatus({ contract_number: contract.name }); + console.log("SignPlannedContract", "CDM", { status_result }); + this.setState({ contract_entity_id: status_result.edoid, status: status_result.status, loading: false }); + } + else + { + this.setState({ loading: false }); + } + } + + _handle_downloadFile = (edo) => + { + console.log("_handle_downloadFile"); + + const { contract } = this.props; + //const { contract_entity_id } = this.state; + + this.setState({ disabled: true, loading_download_file: true }, async () => + { + const link_result = await signGetFileContractProject({ + contract_number: contract.name + }); + + console.log("_downloadFile", { link_result }); + await getFile({ id: link_result.url, filename: `ЛК ЭВОЛЮЦИЯ ${ contract.name }.${ link_result.extension }` }); + this.setState({ disabled: false, loading_download_file: false }); + + /* + const wmdoc_result = await signDownloadFile({ + payload: { entity_name: "evo_contract", entity_id: contract_entity_id, sign_type: edo ? "EDO" : "Paper", evo_id: "144", }, + filename: `ЛК ЭВОЛЮЦИЯ ${ contract.name }.pdf`, + }); + console.log({ wmdoc_result }); + */ + }); + } + + _handle_cancelEDOSign = () => + { + console.log("_handle_cancelEDOSign"); + const { contract, onDealContractsUpdate } = this.props; + + this.setState({ disabled: true, loading_cancel_sign: true }, async () => + { + await docEDOCancel({ contract_number: contract.name, doc_type_id: contract.sign_type === "EDO" ? "144" : "60" }); + setTimeout(() => { + onDealContractsUpdate(); + //this.setState({ disabled: false, loading_cancel_sign: false }); + }, 1000); + }); + } + + _handle_sendToEDO = () => + { + console.log("_handle_sendToEDO"); + } + + _handle_goToEDO = () => + { + console.log("_handle_goToEDO"); + } + + render() + { + const { index, contract, } = this.props; + const { status, loading, disabled, loading_download_file, loading_cancel_sign } = this.state; + + return ( +
+
+ PDF +
+
+

{ contract.name }

+
+ { moment(contract.date).format("DD.MM.YYYY") } + { contract.brand_name } + { contract.model_name } +
+
+ { loading ? ( + + ) : ( + <> + { contract.sign_type === "PAPER" && ( +
+ +
+ ) } + { contract.sign_type === "EDO" && ( +
+ { status < 3 && ( + + ) } + { status < 3 && ( + + )} + { status < 3 && ( + + ) } + { status === 3 && ( + + ) } +
+ ) } + + ) } +
+ ) + } +} + class LeasingRegistration extends Step { constructor(props) @@ -708,7 +934,7 @@ class LeasingRegistration extends Step checked: [], edo: false, }; - this.status = [ 107 ]; + this.status = 107; this.types = [ { title: "Подготовлено", @@ -765,6 +991,28 @@ class LeasingRegistration extends Step }); } + _onEDOCancel = (clean = false) => + { + if(clean) + { + this.setState({ edo: false, checked: [] }); + } + else + { + this.setState({ edo: false }); + } + } + + _onEDOCancel = () => + { + const { onDealContractsUpdate } = this.props; + + this.setState({ edo: false }, () => + { + onDealContractsUpdate(); + }); + } + _getEDODocuments = () => { const contracts = this.props.contracts['prepared_contracts']; @@ -801,7 +1049,8 @@ class LeasingRegistration extends Step return ( this.setState({ edo: false }) } + onCancel={ this._onEDOCancel } + onFinish={ this._onEDOFinish } /> ) } @@ -840,37 +1089,21 @@ class LeasingRegistration extends Step _render_signingPlanContracts = () => { const contracts = this.props.contracts['signing_plan_contracts']; + const { onDealContractsUpdate } = this.props; console.log("_render_signingPlanContracts", { contracts }); return ( -
+
{ contracts.length > 0 ? contracts.map((contract, index) => ( -
-
- PDF -
-
-

{ contract.name }

-
- { moment(contract.date).format("DD.MM.YYYY") } - { contract.brand_name } - { contract.model_name } -
-
- { index === 0 && ( -
- -
- ) } - { index === 1 && ( -
- - -
- ) } -
- )) : ( + + ) + ) : (

Нет договоров

) }
@@ -1017,7 +1250,7 @@ class LeasingRegistration extends Step const { open, edo } = this.state; return ( -
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`} ref={ this.container_ref }> +
this.status ? "done" : "" }`} ref={ this.container_ref }>

№ { dealSelected }

@@ -1030,7 +1263,7 @@ class LeasingRegistration extends Step ) : ( <> { this.types.map((type, index) => ( -
+
{ edo ? ( <> { type.key !== "prepared_contracts" && ( @@ -1062,6 +1295,12 @@ export default class SingleDeal extends React.Component this.leasing_registration_ref = React.createRef(); } + _onDealContractsUpdate = () => + { + const { onDealContractsUpdate, dealSelected } = this.props; + onDealContractsUpdate(dealSelected); + } + render() { const { index, status, deals, dealSelected, onCloseDeal, } = this.props; @@ -1085,8 +1324,9 @@ export default class SingleDeal extends React.Component + - +
Свернуть diff --git a/components/DealsStatus/index.js b/components/DealsStatus/index.js index 671dbd6..3f49c73 100644 --- a/components/DealsStatus/index.js +++ b/components/DealsStatus/index.js @@ -109,6 +109,7 @@ class DealsStatus extends React.Component _onDealsUpdate = () => { + console.log("_onDealsUpdate"); return new Promise((resolve) => { const { dispatch } = this.props; @@ -125,6 +126,14 @@ class DealsStatus extends React.Component }); } + _onDealContractsUpdate = (deal_id) => + { + console.log("_onDealContractsUpdate"); + + const { dispatch } = this.props; + getDealContracts({ dispatch, deal_id, }); + } + _handleModalToggle = (modal) => { if (modal === "current") @@ -176,6 +185,7 @@ class DealsStatus extends React.Component

Статусы сделок

{/*} + { + const { documents } = this.state; + let completed = true; + + for(let i in documents) + { + console.log({ fin: documents[i] }); + if(!documents[i].completed) + completed = false; + break; + } + + return completed; + } + _sign = () => { //const { documents } = this.props; @@ -80,6 +96,38 @@ class EDOSign extends React.Component { callback(); } + else if(document.signing) + { + 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) + { + 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 { console.log({ document }) @@ -106,7 +154,7 @@ class EDOSign extends React.Component await this._updateDocs(document.index, { entity_id: get_guid_entity_result.entityid, - completed: true, + ready: true, loading: false, attorney: false, }); @@ -115,7 +163,7 @@ class EDOSign extends React.Component } else { - const create_print_form_result = await signCheckEDOCreatePrintForm({ contract_number: document.id === "2023_5885" ? "2023_5894" : document.id, sign_type: "EDO" }); + const create_print_form_result = await signCheckEDOCreatePrintForm({ contract_number: document.id, sign_type: "EDO" }); console.log({ create_print_form_result }); const docs = { status: create_print_form_result.status }; @@ -124,7 +172,7 @@ class EDOSign extends React.Component { docs.loading = false; docs.error = true; - docs.completed = true; + docs.ready = true; docs.message = create_print_form_result.message; } @@ -144,14 +192,14 @@ class EDOSign extends React.Component if(get_attorney_client_result === null) { - await this._updateDocs(document.index, { loading: false, error: true, completed: true, message: "Возникла ошибка при создании документа для подписания." }); + await this._updateDocs(document.index, { loading: false, error: true, ready: true, message: "Возникла ошибка при создании документа для подписания." }); callback(); } else { if(get_attorney_client_result.length === null) { - await this._updateDocs(document.index, { loading: false, error: true, completed: true, message: "Не обнаружена доверенность на подписанта. Для продолжения подписания обратитесь к своему персональному менеджеру" }); + await this._updateDocs(document.index, { loading: false, error: true, ready: true, message: "Не обнаружена доверенность на подписанта. Для продолжения подписания обратитесь к своему персональному менеджеру" }); callback(); } else @@ -188,11 +236,13 @@ class EDOSign extends React.Component sign_type: "EDO", evo_id: "144", }); - console.log({ wmdoc_result }); + 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, - completed: true, + ready: true, loading: false, attorney: false, }); @@ -208,7 +258,14 @@ class EDOSign extends React.Component } }, () => { - this.setState({ loading: false }); + if(this._checkDocumentsCompleted()) + { + this.setState({ loading: false, finished: true, }); + } + else + { + this.setState({ loading: false }); + } }); }); } @@ -217,29 +274,36 @@ class EDOSign extends React.Component { event.preventDefault(); - //const { documents } = this.props; - const { operator_selected, step } = this.state; + const { onFinish } = this.props; + const { operator_selected, step, finished } = this.state; const documents = [ ...this.state.documents ]; console.log("_handle_onFormSubmit"); console.log({ documents, operator_selected }); - switch(step) + if(finished) { - case 0: + onFinish(); + } + else + { + switch(step) { - this.setState({ step: 1 }, () => + case 0: + { + this.setState({ step: 1 }, () => + { + this._sign(); + }); + } + break; + + case 1: { this._sign(); - }); + } + break; } - break; - - case 1: - { - this._sign(); - } - break; } } @@ -257,30 +321,86 @@ class EDOSign extends React.Component _handle_onDownloadFile = (index, entity_id, name) => { console.log("_handle_onDownloadFile", { index, entity_id }); - this.setState({ loading: true }, async () => + this.setState({ loading: true, disabled: true, }, async () => { await this._updateDocs(index, { loading: true }); - 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`); + const wmdoc_result = await signDownloadFile({ + payload: { entity_name: "evo_contract", entity_id, sign_type: "EDO", evo_id: "144", }, + filename: `ЛК ЭВОЛЮЦИЯ ${ name }.pdf`, + }); - await this._updateDocs(index, { loading: false }); + await this._updateDocs(index, { loading: false, disabled: false, }); }); } - _handle_onCancelFile = async (index, entity_id) => + _handle_onCancelFile = async (index) => + { + const { onCancel } = this.props; + const { documents } = this.state; + await this._updateDocs(index, { loading: true }); + + this.setState({ loading: true, disabled: true }, async () => + { + await docEDOCancel({ contract_number: documents[index].id, doc_type_id: "144" }); + const docs = [ ...this.state.documents ]; + docs.splice(index, 1); + + if(docs.length > 0) + { + this.setState({ documents: docs, loading: false, disabled: false, }); + } + else + { + onCancel(true); + } + }); + } + + _handle_onCancel = () => + { + const { onCancel } = this.props; + const { documents } = this.state; + + console.log("documents", documents, "LEN", documents.length); + + var clean = false; + if(documents.length === 0) + { + clean = true; + } + + onCancel(clean); + } + + _handle_onCheckEDOStatus = async (index) => { await this._updateDocs(index, { loading: true }); - this.setState({ loading: true }, async () => + + this.setState({ loading: true, disabled: true }, async () => { - await this._updateDocs(index, { loading: true }); + const status_result = await docEDOStatus({ contract_number: document.id }); + console.log({ status_result }); + + if(status_result.status === 3) + { + await this._updateDocs(index, { loading: false, disabled: false, signing: false, completed: true, }); + } + else + { + await this._updateDocs(index, { loading: false, disabled: false, signing: true, completed: false, }); + } }); } + _handle_onGoToEDO = () => + { + + } + render() { - const { step, operators, documents, loading, operator_selected } = this.state; + const { step, operators, documents, loading, disabled, finished, operator_selected } = this.state; const { onCancel, } = this.props; console.log({ operators, documents }); @@ -312,78 +432,109 @@ class EDOSign extends React.Component { step === 1 && (
{ documents.map((document, index) => - ( -
-
-

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

+ { + console.log({ document }); + return ( +
+
+

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

+
+
+ { document.loading ? ( + <> + { loading && ( + + ) } + + ) : ( + <> + { document.error ? ( + <> +
+ { document.message !== undefined && document.message !== null ? 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() }}>
- - + + { finished ? ( + + ) : ( + + ) }
diff --git a/css/main/style.css b/css/main/style.css index 1f6d7c4..7b71043 100644 --- a/css/main/style.css +++ b/css/main/style.css @@ -5328,6 +5328,7 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block .block_body .fines_ .contractStatus_list .list_item div:nth-child(2) p { cursor: pointer; color: var(--text_not_active); + min-width: 120px; } .contractStatus_list .list_item div:nth-child(2):before { content: ""; @@ -5757,7 +5758,6 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block .block_body .fines_ .contractStatus_modal .single_status > div .status_body .wrap.form .block .right { width: 80%; padding-left: 30px; - padding-bottom: 30px; } .contractStatus_modal .single_status > div .status_body .wrap input[type="checkbox"] + label { width: 16px; @@ -6336,6 +6336,12 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block .block_body .fines_ background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z' stroke='%238E94A7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M12 8L12 12' stroke='%238E94A7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M16 12L12 12' stroke='%238E94A7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); border: none !important; } +.edo_sign_documents_document .status_title { + padding: 0px 10px; +} +.edo_sign_documents_document .status_title i { + display: contents; +} .edo_sign_documents_document .edo_sign_documents_document_left { width: 35%; } @@ -6362,3 +6368,29 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block .block_body .fines_ padding-left: 10px; width: 100%; } +.deal_contract_sign_list { + gap: 0px 0px; +} +.deal_contract_sign_item { + padding-top: 15px; + padding-bottom: 15px; + border-top: solid 1px #edeff5; + width: 100%; + display: flex; + flex-direction: row; +} +.deal_contract_sign_item .title { + width: 35%; +} +.deal_contract_sign_item .actions { + width: 65%; + justify-content: space-between; +} +.deal_contract_sign_item:first-child { + border: none; +} +.deal_contracts_group_item { + border-top: solid 1px #edeff5; + padding-top: 10px; + padding-bottom: 20px; +} diff --git a/css/main/style.less b/css/main/style.less index f3aedaf..82bdd89 100644 --- a/css/main/style.less +++ b/css/main/style.less @@ -6030,7 +6030,7 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block { p { cursor: pointer; color: var(--text_not_active); - + min-width: 120px; } &:before { @@ -6565,7 +6565,7 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block { .right { width: 80%; padding-left: 30px; - padding-bottom: 30px; + //padding-bottom: 30px; } } } @@ -7311,6 +7311,14 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block { } } + .status_title { + padding: 0px 10px; + + i { + display: contents; + } + } + .edo_sign_documents_document_left { width: 35%; } @@ -7341,4 +7349,38 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block { .edo_sign_status_attorney_select { padding-left: 10px; width: 100%; +} + +.deal_contract_sign_list { + gap: 0px 0px; +} + +.deal_contract_sign_item { + padding-top: 15px; + padding-bottom: 15px; + border-top: solid 1px #edeff5; + + width: 100%; + display: flex; + flex-direction: row; + + .title { + width: 35%; + } + + .actions { + width: 65%; + justify-content: space-between; + } + + &:first-child { + border: none; + } +} + +.deal_contracts_group_item { + border-top: solid 1px #edeff5; + padding-top: 10px; + padding-bottom: 20px; +// margin-top: 30px; } \ No newline at end of file diff --git a/lib/CRMRequestGet/index.js b/lib/CRMRequestGet/index.js index 853b958..9b17def 100644 --- a/lib/CRMRequestGet/index.js +++ b/lib/CRMRequestGet/index.js @@ -1,13 +1,15 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction +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 { cors } from '../cors'; import { inspect } from 'util'; -export default async function CRMRequestGet(req, res, path, params, data = undefined, log = false) +import { cors } from '../cors'; + +export default async function CRMRequestGet({ req, res, path, params, data = undefined, log = false, headers = {}, options = {} }) { await cors(req, res); @@ -16,19 +18,14 @@ export default async function CRMRequestGet(req, res, path, params, data = undef const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); //console.log("-".repeat(50)); - //console.log("CRMRequestGet", "req.body"); - //console.log(req.body); - if(cookies.jwt !== undefined && cookies.jwt !== null) { //console.log("cookies.jwt"); - //console.log(cookies.jwt); - 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 }); @@ -39,31 +36,29 @@ export default async function CRMRequestGet(req, res, path, params, data = undef } //console.log("path", path); - //console.log("params", { ...client_jwt_decoded, ...params }); - const payload = { ...{ acc_number: client_jwt_decoded.acc_number }, ...params }; - const options = { - headers: { - "Authorization": `Bearer ${ crm_jwt }`, - "Content-Type": "application/json" - }, + const request_options = { + headers: { ...{ "Authorization": `Bearer ${ crm_jwt }` }, ...headers }, withCredentials: true, }; if(data !== undefined) { - options.data = data; + request_options.data = data; } else { - options.params = payload; - } + request_options.params = payload; + } try { - await axios.get(path, options) + console.log({ options, __dirname }); + console.log("{ ...request_options, ...options }", { ...request_options, ...options }); + + await axios.get(path, { ...request_options, ...options }) .then((crm_response) => { if(log) diff --git a/pages/api/contract/agreement.js b/pages/api/contract/agreement.js index 2488b25..c57ad51 100644 --- a/pages/api/contract/agreement.js +++ b/pages/api/contract/agreement.js @@ -2,5 +2,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetDocumentList`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetDocumentList`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/contract/change/calculations.js b/pages/api/contract/change/calculations.js index 642ec3a..06599ea 100644 --- a/pages/api/contract/change/calculations.js +++ b/pages/api/contract/change/calculations.js @@ -3,5 +3,5 @@ import CRMRequestGet from '../../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/add-contract/GetPreCalculations`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/add-contract/GetPreCalculations`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/contract/change/graphic/calculation.js b/pages/api/contract/change/graphic/calculation.js index 0be6cc9..a508611 100644 --- a/pages/api/contract/change/graphic/calculation.js +++ b/pages/api/contract/change/graphic/calculation.js @@ -7,5 +7,5 @@ export default async function handler(req, res) console.log(req.body); console.log("-".repeat(50)); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/add-contract/GetPreCalculationGraph`, { addcontract_number: req.body.calculation }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/add-contract/GetPreCalculationGraph`, params: { addcontract_number: req.body.calculation } }); } \ No newline at end of file diff --git a/pages/api/contract/change/graphic/current.js b/pages/api/contract/change/graphic/current.js index 5f21d36..1877b02 100644 --- a/pages/api/contract/change/graphic/current.js +++ b/pages/api/contract/change/graphic/current.js @@ -7,5 +7,5 @@ export default async function handler(req, res) console.log(req.body); console.log("-".repeat(50)); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/add-contract/GetCurrentGraph`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/add-contract/GetCurrentGraph`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/contract/change/options.js b/pages/api/contract/change/options.js index 974e4f8..401fcac 100644 --- a/pages/api/contract/change/options.js +++ b/pages/api/contract/change/options.js @@ -7,5 +7,5 @@ export default async function handler(req, res) console.log(req.body); console.log("-".repeat(50)); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/add-contract/GetTypeOptions`, { ...{ contract_number: req.body.number }, ...req.body.variants }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/add-contract/GetTypeOptions`, params: { ...{ contract_number: req.body.number }, ...req.body.variants } }); } \ No newline at end of file diff --git a/pages/api/contract/change/signatories.js b/pages/api/contract/change/signatories.js index a4c86cf..794b056 100644 --- a/pages/api/contract/change/signatories.js +++ b/pages/api/contract/change/signatories.js @@ -3,5 +3,5 @@ import CRMRequestGet from '../../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/add-contract/GetSignatories`, {}); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/add-contract/GetSignatories`, params: {} }); } \ No newline at end of file diff --git a/pages/api/contract/change/variants.js b/pages/api/contract/change/variants.js index 4434cdc..fdb4722 100644 --- a/pages/api/contract/change/variants.js +++ b/pages/api/contract/change/variants.js @@ -7,5 +7,5 @@ export default async function handler(req, res) console.log(req.body); console.log("-".repeat(50)); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/add-contract/GetAvaliableGraphChangeTypes`, { ...{ contract_number: req.body.number }, ...req.body.variants }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/add-contract/GetAvaliableGraphChangeTypes`, params: { ...{ contract_number: req.body.number }, ...req.body.variants } }); } \ No newline at end of file diff --git a/pages/api/contract/fines.js b/pages/api/contract/fines.js index 1bf0f94..9b5a539 100644 --- a/pages/api/contract/fines.js +++ b/pages/api/contract/fines.js @@ -2,5 +2,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetFineGIBDDList`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetFineGIBDDList`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/contract/helpcard.js b/pages/api/contract/helpcard.js index b24e9ff..552fac5 100644 --- a/pages/api/contract/helpcard.js +++ b/pages/api/contract/helpcard.js @@ -2,5 +2,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetHelpCard`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetHelpCard`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/contract/index.js b/pages/api/contract/index.js index 6dac597..9203ff0 100644 --- a/pages/api/contract/index.js +++ b/pages/api/contract/index.js @@ -2,5 +2,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetSchedulePayments`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetSchedulePayments`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/contract/info.js b/pages/api/contract/info.js index 4bf0953..f6ac139 100644 --- a/pages/api/contract/info.js +++ b/pages/api/contract/info.js @@ -2,5 +2,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetAddInfoForContract`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetAddInfoForContract`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/contract/penalties.js b/pages/api/contract/penalties.js index 0d366f3..b26f80c 100644 --- a/pages/api/contract/penalties.js +++ b/pages/api/contract/penalties.js @@ -2,5 +2,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetPlannedFines`, { contract_number: req.body.number, planned_date: req.body.date }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetPlannedFines`, params: { contract_number: req.body.number, planned_date: req.body.date } }); } \ No newline at end of file diff --git a/pages/api/contract/registration.js b/pages/api/contract/registration.js index da1243e..de55d23 100644 --- a/pages/api/contract/registration.js +++ b/pages/api/contract/registration.js @@ -2,5 +2,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetRegistration`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetRegistration`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/contract/sign/attorney/check.js b/pages/api/contract/sign/attorney/check.js index ee7487d..b91d39f 100644 --- a/pages/api/contract/sign/attorney/check.js +++ b/pages/api/contract/sign/attorney/check.js @@ -9,5 +9,5 @@ export default async function handler(req, res) contract_number, }; - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/CheckPowerAttorneyClient`, payload); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/CheckPowerAttorneyClient`, params: payload }); } \ No newline at end of file diff --git a/pages/api/contract/sign/attorney/get.js b/pages/api/contract/sign/attorney/get.js index dc128a9..8ef8abc 100644 --- a/pages/api/contract/sign/attorney/get.js +++ b/pages/api/contract/sign/attorney/get.js @@ -9,5 +9,5 @@ export default async function handler(req, res) contract_number, }; - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetPowerAttorneyClient`, payload); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetPowerAttorneyClient`, params: payload }); } \ No newline at end of file diff --git a/pages/api/contract/sign/cancel/check.js b/pages/api/contract/sign/cancel/check.js index 2ebc29f..7a4e134 100644 --- a/pages/api/contract/sign/cancel/check.js +++ b/pages/api/contract/sign/cancel/check.js @@ -18,5 +18,5 @@ export default async function handler(req, res) payload.doc_type_id = 60; } - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/CheckCancelDocument`, payload); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/CheckCancelDocument`, params: payload }); } \ No newline at end of file diff --git a/pages/api/contract/sign/cancel/index.js b/pages/api/contract/sign/cancel/index.js index 97ed5f5..67eea92 100644 --- a/pages/api/contract/sign/cancel/index.js +++ b/pages/api/contract/sign/cancel/index.js @@ -18,5 +18,5 @@ export default async function handler(req, res) payload.doc_type_id = 60; } - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/CancelDocument`, payload); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/CancelDocument`, params: payload }); } \ No newline at end of file diff --git a/pages/api/contract/sign/check.js b/pages/api/contract/sign/check.js index d40d36b..3e778e1 100644 --- a/pages/api/contract/sign/check.js +++ b/pages/api/contract/sign/check.js @@ -10,5 +10,5 @@ export default async function handler(req, res) sign_type }; - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/CheckCreatePrintForm`, payload); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/CheckCreatePrintForm`, params: payload }); } \ No newline at end of file diff --git a/pages/api/contract/sign/document/connect.js b/pages/api/contract/sign/document/connect.js new file mode 100644 index 0000000..604e26d --- /dev/null +++ b/pages/api/contract/sign/document/connect.js @@ -0,0 +1,18 @@ +import CRMRequestGet from '../../../../../lib/CRMRequestGet'; + +export default async function handler(req, res) +{ + console.log("API", "SIGN", "/document/connect"); + + const { contract_number } = req.body; + const payload = { + contract_number + }; + + console.log({ payload }); + + await CRMRequestGet({ req, res, + path: `${ process.env.CRM_API_HOST }/lk/Contract/DocEdoConnect`, + params: payload, + }); +} \ No newline at end of file diff --git a/pages/api/contract/sign/document/create.js b/pages/api/contract/sign/document/create.js index b9a3851..52ae32e 100644 --- a/pages/api/contract/sign/document/create.js +++ b/pages/api/contract/sign/document/create.js @@ -17,5 +17,9 @@ export default async function handler(req, res) console.log({ payload }); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/File/GetWMDoc`, undefined, JSON.stringify(payload)); + await CRMRequestGet({ req, res, + path: `${ process.env.CRM_API_HOST }/File/GetWMDoc`, + data: JSON.stringify(payload), + headers: { "Content-Type": "application/json" }, + }); } \ No newline at end of file diff --git a/pages/api/contract/sign/document/download.js b/pages/api/contract/sign/document/download.js index b7349f3..d55b113 100644 --- a/pages/api/contract/sign/document/download.js +++ b/pages/api/contract/sign/document/download.js @@ -1,10 +1,20 @@ -import CRMRequestGet from '../../../../../lib/CRMRequestGet'; +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 { inspect } from 'util'; + +import { cors } from '../../../../../lib/cors'; export default async function handler(req, res) { console.log("API", "SIGN", "/document/download"); - const { entity_name, entity_id, sign_type, evo_id } = req.body; + await cors(req, res); + + const { entity_name, entity_id, sign_type, evo_id } = req.query; const payload = { entityName: entity_name, entityId: entity_id, @@ -17,5 +27,58 @@ export default async function handler(req, res) console.log({ payload }); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/File/GetWMDoc`, undefined, JSON.stringify(payload)); + 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 }); + + try + { + axios.get(`${ process.env.CRM_API_HOST }/File/GetWMDoc`, { + data: JSON.stringify(payload), + responseType: 'arraybuffer', + headers: { + "Authorization": `Bearer ${ crm_jwt }`, + "Content-Type": "application/json", + }, + }) + .then((crm_response) => + { + res.status(200).send(crm_response.data); + resolve(); + }) + .catch((error) => + { + console.error(error); + console.error(error.data); + + res.status(500).send(error.data); + resolve(); + }); + } + catch(e) + { + console.error(e); + res.status(500).send(e); + resolve(); + } + } + else + { + res.status(403).send(); + resolve(); + } + } + else + { + res.status(403).send(); + resolve(); + } + }); } \ No newline at end of file diff --git a/pages/api/contract/sign/document/link.js b/pages/api/contract/sign/document/link.js new file mode 100644 index 0000000..fa9775f --- /dev/null +++ b/pages/api/contract/sign/document/link.js @@ -0,0 +1,18 @@ +import CRMRequestGet from '../../../../../lib/CRMRequestGet'; + +export default async function handler(req, res) +{ + console.log("API", "SIGN", "/document/link"); + + const { contract_number } = req.body; + const payload = { + contract_number + }; + + console.log({ payload }); + + await CRMRequestGet({ req, res, + path: `${ process.env.CRM_API_HOST }/lk/Contract/GetFileContractProject`, + params: payload, + }); +} \ No newline at end of file diff --git a/pages/api/contract/sign/document/status.js b/pages/api/contract/sign/document/status.js new file mode 100644 index 0000000..573253b --- /dev/null +++ b/pages/api/contract/sign/document/status.js @@ -0,0 +1,18 @@ +import CRMRequestGet from '../../../../../lib/CRMRequestGet'; + +export default async function handler(req, res) +{ + console.log("API", "SIGN", "/document/status"); + + const { contract_number } = req.body; + const payload = { + contract_number + }; + + console.log({ payload }); + + await CRMRequestGet({ req, res, + path: `${ process.env.CRM_API_HOST }/lk/Contract/GetEdoProjectID`, + params: payload, + }); +} \ No newline at end of file diff --git a/pages/api/contract/sign/entity.js b/pages/api/contract/sign/entity.js index d7f7b5a..340efaa 100644 --- a/pages/api/contract/sign/entity.js +++ b/pages/api/contract/sign/entity.js @@ -9,5 +9,5 @@ export default async function handler(req, res) contract_number }; - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetGUIDEntity`, payload); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetGUIDEntity`, params: payload }); } \ No newline at end of file diff --git a/pages/api/contract/telematic.js b/pages/api/contract/telematic.js index e49ea3d..1200320 100644 --- a/pages/api/contract/telematic.js +++ b/pages/api/contract/telematic.js @@ -2,5 +2,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/GetTelematics`, { contract_number: req.body.number }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/GetTelematics`, params: { contract_number: req.body.number } }); } \ No newline at end of file diff --git a/pages/api/deals/contracts.js b/pages/api/deals/contracts.js index 8aae8fd..38f1c72 100644 --- a/pages/api/deals/contracts.js +++ b/pages/api/deals/contracts.js @@ -13,5 +13,5 @@ export default async function handler(req, res) const { deal_id } = req.body; - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/contract`, { ...{ opp_number: deal_id } }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/contract`, params: { ...{ opp_number: deal_id } } }); } \ No newline at end of file diff --git a/pages/api/deals/index.js b/pages/api/deals/index.js index c24e4b3..031af88 100644 --- a/pages/api/deals/index.js +++ b/pages/api/deals/index.js @@ -7,5 +7,5 @@ import CRMRequestGet from '../../../lib/CRMRequestGet'; export default async function handler(req, res) { - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/`, {}); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/`, params: {} }); } \ No newline at end of file diff --git a/pages/api/deals/offers.js b/pages/api/deals/offers.js index 2b40970..5108d1f 100644 --- a/pages/api/deals/offers.js +++ b/pages/api/deals/offers.js @@ -13,5 +13,5 @@ export default async function handler(req, res) const { deal_id } = req.body; - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/quote`, { ...{ opp_number: deal_id } }); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/quote`, params: { ...{ opp_number: deal_id } } }); } \ No newline at end of file diff --git a/pages/api/edo/cancel.js b/pages/api/edo/cancel.js new file mode 100644 index 0000000..415f28b --- /dev/null +++ b/pages/api/edo/cancel.js @@ -0,0 +1,17 @@ +/* +2.8.1 - Метод получения доступных для работы в ЭДО ящиков (lk/Account/GetEdoBox) +*/ +import CRMRequestGet from '../../../lib/CRMRequestGet'; + +export default async function handler(req, res) +{ + console.log("API", "EDO", "/cancel"); + + const { contract_number, doc_type_id, } = req.body; + const payload = { + contract_number, + doc_type_id, + }; + + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/CancelDocument`, params: payload }); +} \ No newline at end of file diff --git a/pages/api/edo/invite/send.js b/pages/api/edo/invite/send.js index ece1b58..147c538 100644 --- a/pages/api/edo/invite/send.js +++ b/pages/api/edo/invite/send.js @@ -8,5 +8,5 @@ export default async function handler(req, res) { console.log("API", "EDO", "/invite/send"); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Account/InviteEdoBox`, {}); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Account/InviteEdoBox`, params: {} }); } \ No newline at end of file diff --git a/pages/api/edo/invites.js b/pages/api/edo/invites.js index 91e7ad1..a51acf3 100644 --- a/pages/api/edo/invites.js +++ b/pages/api/edo/invites.js @@ -7,5 +7,5 @@ export default async function handler(req, res) { console.log("API", "EDO", "/invites"); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Account/GetInviteEdoBox`, {}); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Account/GetInviteEdoBox`, params: {} }); } \ No newline at end of file diff --git a/pages/api/edo/operators.js b/pages/api/edo/operators.js index f409e94..f5909df 100644 --- a/pages/api/edo/operators.js +++ b/pages/api/edo/operators.js @@ -7,5 +7,5 @@ export default async function handler(req, res) { console.log("API", "EDO", "/operators"); - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Account/GetEdoBox`, {}); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Account/GetEdoBox`, params: {} }); } \ No newline at end of file diff --git a/pages/api/edo/project.js b/pages/api/edo/project.js index ddb809f..204b834 100644 --- a/pages/api/edo/project.js +++ b/pages/api/edo/project.js @@ -12,5 +12,5 @@ export default async function handler(req, res) edo_box, }; - await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/Contract/CreateEDOProject`, payload); + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/CreateEDOProject`, params: payload }); } \ No newline at end of file diff --git a/pages/api/edo/sign.js b/pages/api/edo/sign.js new file mode 100644 index 0000000..5578b64 --- /dev/null +++ b/pages/api/edo/sign.js @@ -0,0 +1,13 @@ +import CRMRequestGet from '../../../lib/CRMRequestGet'; + +export default async function handler(req, res) +{ + console.log("API", "EDO", "/sign"); + + const { edoid } = req.body; + const payload = { + edoid, + }; + + await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/SignEDODocument`, params: payload }); +} \ No newline at end of file