diff --git a/actions/dealsActions.js b/actions/dealsActions.js index a411392..7e55989 100644 --- a/actions/dealsActions.js +++ b/actions/dealsActions.js @@ -238,7 +238,10 @@ export const sendDealDocuments = ({ deal_id }) => { console.log("ACTION", "deals", "sendDealDocuments", "response.data", response.data); - resolve(); + setTimeout(() => + { + resolve(); + }, 20000); }) .catch((error) => { diff --git a/actions/signActions.js b/actions/signActions.js index 811a268..8bf4d25 100644 --- a/actions/signActions.js +++ b/actions/signActions.js @@ -246,6 +246,60 @@ export const signUploadPaperDocument = (contract_number, deal_id, files) => console.error("ACTION", "sign", "signUploadPaperDocument()", "ERROR"); console.error(error); + reject(error.data); + }); + }); +} + +export const signCheckCancelDocument = ({ contract_number, doc_type_id }) => +{ + const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/cancel/check`; + + console.log("ACTION", "sign", "signCheckCancelDocument()", { url }); + + return new Promise((resolve, reject) => + { + axios.post(url, { contract_number, doc_type_id }, { + withCredentials: true, + }) + .then((response) => + { + console.log("ACTION", "sign", "signCheckCancelDocument()", "response", response.data); + + resolve(response.data); + }) + .catch((error) => + { + console.error("ACTION", "sign", "signCheckCancelDocument()", "ERROR"); + console.error(error); + + reject(error.data); + }); + }); +} + +export const signCancelDocument = ({ contract_number, doc_type_id }) => +{ + const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/contract/sign/cancel`; + + console.log("ACTION", "sign", "signCancelDocument()", { url }); + + return new Promise((resolve, reject) => + { + axios.post(url, { contract_number, doc_type_id }, { + withCredentials: true, + }) + .then((response) => + { + console.log("ACTION", "sign", "signCancelDocument()", "response", response.data); + + resolve(response.data); + }) + .catch((error) => + { + console.error("ACTION", "sign", "signCancelDocument()", "ERROR"); + console.error(error); + reject(error.data); }); }); diff --git a/components/DealsStatus/components/DealContractsSignEDO.js b/components/DealsStatus/components/DealContractsSignEDO.js index e8e3fe5..b85932f 100644 --- a/components/DealsStatus/components/DealContractsSignEDO.js +++ b/components/DealsStatus/components/DealContractsSignEDO.js @@ -6,7 +6,7 @@ import { concatSeries } from "async"; import { eachSeries } from 'async'; import Select from 'react-select'; -import { createEDOProject, docEDOCancel, signCheckCreatePrintForm, signCheckPowerAttorneyClient, signDownloadFile, signGetGUIDEntity, signGetPowerAttorneyClient, signGetWMDoc, docEDOSign, docEDOStatus, docEDOConnect, getFile, signGetFileContractProject } from "../../../actions"; +import { createEDOProject, signCheckCreatePrintForm, signCheckPowerAttorneyClient, signDownloadFile, signGetGUIDEntity, signGetPowerAttorneyClient, signGetWMDoc, docEDOSign, docEDOStatus, docEDOConnect, getFile, signGetFileContractProject, signCheckCancelDocument, signCancelDocument } from "../../../actions"; class DealContractsSignEDO extends React.Component { @@ -370,17 +370,29 @@ class DealContractsSignEDO extends React.Component 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) + const check_result = await signCheckCancelDocument({ contract_number: documents[index].id, doc_type_id: "144" }); + if(check_result.status === "success") { - this.setState({ documents: docs, loading: false, disabled: false, }); + await signCancelDocument({ 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); + } } else { - onCancel(true); + await this._updateDocs(index, { + loading: false, + error: true, + message: check_result.message !== undefined && check_result.message !== null ? check_result.message : "Возникла ошибка при отмене подписания через ЭДО", + }); } }); } diff --git a/components/DealsStatus/components/DealContractsSignPaper.js b/components/DealsStatus/components/DealContractsSignPaper.js index aa7cdc0..9bf5026 100644 --- a/components/DealsStatus/components/DealContractsSignPaper.js +++ b/components/DealsStatus/components/DealContractsSignPaper.js @@ -7,7 +7,7 @@ import { eachSeries } from 'async'; import Select from 'react-select'; import Dropzone from 'react-dropzone'; -import { docEDOCancel, signCheckCreatePrintForm, signGetGUIDEntity, signGetWMDoc, docEDOStatus, getFile, signGetFileContractProject, signUploadPaperDocument } from "../../../actions"; +import { signCheckCreatePrintForm, signGetGUIDEntity, signGetWMDoc, docEDOStatus, getFile, signGetFileContractProject, signUploadPaperDocument, signCheckCancelDocument, signCancelDocument } from "../../../actions"; export default class DealContractsSignPaper extends React.Component { @@ -224,17 +224,29 @@ export default class DealContractsSignPaper extends React.Component this.setState({ loading: true, disabled: true }, async () => { - await docEDOCancel({ contract_number: documents[index].id, doc_type_id: "60" }); - const docs = [ ...this.state.documents ]; - docs.splice(index, 1); - - if(docs.length > 0) + const check_result = await signCheckCancelDocument({ contract_number: documents[index].id, doc_type_id: "60" }); + if(check_result.status === "success") { - this.setState({ documents: docs, loading: false, disabled: false, }); + await signCancelDocument({ contract_number: documents[index].id, doc_type_id: "60" }); + const docs = [ ...this.state.documents ]; + docs.splice(index, 1); + + if(docs.length > 0) + { + this.setState({ documents: docs, loading: false, disabled: false, }); + } + else + { + onCancel(true); + } } else { - onCancel(true); + await this._updateDocs(index, { + loading: false, + error: true, + message: check_result.message !== undefined && check_result.message !== null ? check_result.message : "Возникла ошибка при отмене подписания", + }); } }); } diff --git a/components/DealsStatus/components/SignPlannedContract.js b/components/DealsStatus/components/SignPlannedContract.js index eda5dd3..2869b19 100644 --- a/components/DealsStatus/components/SignPlannedContract.js +++ b/components/DealsStatus/components/SignPlannedContract.js @@ -3,7 +3,7 @@ import moment from "moment"; import { SpinnerCircular } from "spinners-react"; import Dropzone from 'react-dropzone'; -import { docEDOCancel, docEDOStatus, getFile, signCheckDownloadContractProject, signGetFileContractProject, signUploadPaperDocument } from "../../../actions"; +import { docEDOStatus, getFile, signCancelDocument, signCheckCancelDocument, signCheckDownloadContractProject, signGetFileContractProject, signUploadPaperDocument } from "../../../actions"; export default class SignPlannedContract extends React.Component { @@ -16,6 +16,7 @@ export default class SignPlannedContract extends React.Component finished: false, loading_download_file: false, loading_cancel_sign: false, + loading_signing: false, loading_uploading_file: false, disabled: false, status: undefined, @@ -54,7 +55,7 @@ export default class SignPlannedContract extends React.Component }); } - _handle_downloadFile = (edo) => + _handle_downloadFile = () => { console.log("_handle_downloadFile"); @@ -74,7 +75,7 @@ export default class SignPlannedContract extends React.Component console.log("_handle_downloadFile", { link_result }); await getFile({ id: link_result.url, filename: `ЛК ЭВОЛЮЦИЯ ${ contract.name }.${ link_result.extension }` }); - this.setState({ disabled: false, loading_download_file: false, error: false, uploading: edo ? false : true, }); + this.setState({ disabled: false, loading_download_file: false, error: false, uploading: contract.sign_type === "EDO" ? false : true, }); } else { @@ -91,24 +92,72 @@ export default class SignPlannedContract extends React.Component }); } - _handle_cancelEDOSign = () => + _handle_cancelSign = () => { - console.log("_handle_cancelEDOSign"); + console.log("_handle_cancelSign"); 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); + const check_result = await signCheckCancelDocument({ contract_number: contract.name, doc_type_id: contract.sign_type === "EDO" ? "144" : "60" }); + if(check_result.status === "success") + { + const cancel_result = await signCancelDocument({ contract_number: contract.name, doc_type_id: contract.sign_type === "EDO" ? "144" : "60" }); + setTimeout(() => { + onDealContractsUpdate(); + // this.setState({ disabled: false, loading_cancel_sign: false }); + }, 1000); + } + else + { + this.setState({ + loading: false, + loading_cancel_sign: false, + error: true, + message: check_result.message !== undefined && check_result.message !== null ? check_result.message : `Возникла ошибка при отмене подписания${ contract.sign_type === "EDO" ? " через ЭДО" : "" }`, + }); + } }); } _handle_sendToEDO = () => { console.log("_handle_sendToEDO"); + + const { contract, onDealContractsUpdate } = this.props; + + this.setState({ disabled: true, loading_signing: true }, async () => + { + const check_result = await signCheckDownloadContractProject({ contract_number: contract.name }); + if(check_result.status === "success") + { + 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 }); + } + else + { + this.setState({ + loading: false, + loading_signing: false, + error: true, + message: status_result.message !== undefined && status_result.message !== null ? status_result.message : `Возникла ошибка при отправке в ЭДО`, + }); + } + } + else + { + this.setState({ + loading: false, + loading_signing: false, + error: true, + message: check_result.message !== undefined && check_result.message !== null ? check_result.message : `Возникла ошибка при отправке в ЭДО`, + }); + } + }); } _handle_onGoToEDO = () => @@ -170,7 +219,7 @@ export default class SignPlannedContract extends React.Component this._handle_onUploadFile(acceptedFiles, index) } maxFiles={ 10 }> { ({getRootProps, getInputProps}) => (
- + <> + + + ) }
) } @@ -197,17 +255,17 @@ export default class SignPlannedContract extends React.Component { contract.sign_type === "EDO" && (
{ status === 1 && ( - ) } { status === 1 && ( - )} { status === 1 && ( - + ) } { status >= 2 && ( diff --git a/components/EDOSign/index.js b/components/EDOSign/index.js index 54c003d..57f7356 100644 --- a/components/EDOSign/index.js +++ b/components/EDOSign/index.js @@ -6,7 +6,7 @@ import { concatSeries } from "async"; import { eachSeries } from 'async'; import Select from 'react-select'; -import { createEDOProject, docEDOCancel, signCheckCreatePrintForm, signCheckPowerAttorneyClient, signDownloadFile, signGetGUIDEntity, signGetPowerAttorneyClient, signGetWMDoc, docEDOSign, docEDOStatus, docEDOConnect, getFile, signGetFileContractProject } from "../../actions"; +import { createEDOProject, signCheckCreatePrintForm, signCheckPowerAttorneyClient, signDownloadFile, signGetGUIDEntity, signGetPowerAttorneyClient, signGetWMDoc, docEDOSign, docEDOStatus, docEDOConnect, getFile, signGetFileContractProject, signCheckCancelDocument } from "../../actions"; //import { getDeals, getDealOffers, getDealDocuments, getDealContracts } from "../../actions"; class EDOSign extends React.Component @@ -371,7 +371,7 @@ class EDOSign extends React.Component this.setState({ loading: true, disabled: true }, async () => { - await docEDOCancel({ contract_number: documents[index].id, doc_type_id: "144" }); + await signCheckCancelDocument({ contract_number: documents[index].id, doc_type_id: "144" }); const docs = [ ...this.state.documents ]; docs.splice(index, 1); diff --git a/css/main/style.css b/css/main/style.css index e67209b..c2821ae 100644 --- a/css/main/style.css +++ b/css/main/style.css @@ -6385,7 +6385,7 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block .block_body .fines_ .contractStatus_modal .single_status > div .status_body .documents .document .actions { display: flex; flex: 1; - gap: 0px 20px; + gap: 0px 0px; flex-direction: row; justify-content: flex-end; align-items: center; diff --git a/css/main/style.less b/css/main/style.less index 7c6466e..0c5810c 100644 --- a/css/main/style.less +++ b/css/main/style.less @@ -7274,7 +7274,7 @@ main .dropdown_blocks_list.zero-margin.gibdd .dropdown_block { .actions { display: flex; flex: 1; - gap: 0px 20px; + gap: 0px 0px; flex-direction: row; justify-content: flex-end; align-items: center; diff --git a/pages/api/contract/sign/cancel/check.js b/pages/api/contract/sign/cancel/check.js index b8cdf04..c7dc921 100644 --- a/pages/api/contract/sign/cancel/check.js +++ b/pages/api/contract/sign/cancel/check.js @@ -4,20 +4,12 @@ export default async function handler(req, res) { console.log("\n\n", "API", "SIGN", "/cancel/check"); - const { contract_number, sign_type } = req.body; + const { contract_number, doc_type_id } = req.body; const payload = { - contract_number + contract_number, + doc_type_id, }; - if(sign_type === "EDO") - { - payload.doc_type_id = 144; - } - else - { - payload.doc_type_id = 60; - } - await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/CheckCancelDocument`, params: payload, diff --git a/pages/api/contract/sign/cancel/index.js b/pages/api/contract/sign/cancel/index.js index ae7d6d6..c1a2756 100644 --- a/pages/api/contract/sign/cancel/index.js +++ b/pages/api/contract/sign/cancel/index.js @@ -4,20 +4,12 @@ export default async function handler(req, res) { console.log("\n\n", "API", "SIGN", "/cancel"); - const { contract_number, sign_type } = req.body; + const { contract_number, doc_type_id } = req.body; const payload = { - contract_number + contract_number, + doc_type_id, }; - if(sign_type === "EDO") - { - payload.doc_type_id = 144; - } - else - { - payload.doc_type_id = 60; - } - await CRMRequestGet({ req, res, path: `${ process.env.CRM_API_HOST }/lk/Contract/CancelDocument`, params: payload, diff --git a/pages/api/deals/upload.js b/pages/api/deals/upload.js index 2111899..3e5419a 100644 --- a/pages/api/deals/upload.js +++ b/pages/api/deals/upload.js @@ -79,7 +79,7 @@ function uploadFile({ deal_id, filename, name, group, crm_jwt }) const path = `${ uploads }${ filename }`; const file_to_send_data = fs.readFileSync(path); - console.log({ filename, len: file_to_send_data.length, path }); + console.log("uploadFile", { filename, len: file_to_send_data.length, path }); const data = new FormData(); data.append("file", file_to_send_data, name); @@ -91,7 +91,11 @@ function uploadFile({ deal_id, filename, name, group, crm_jwt }) documentName: name, }); - const file_upload_url = `${ process.env.CRM_API_HOST }/lk/document/upload?${ payload.toString() }`; + console.log("uploadFile", { payload }); + + const payload_string = new URLSearchParams(payload).toString(); + + const file_upload_url = `${ process.env.CRM_API_HOST }/lk/document/upload?${ payload_string }`; console.log( file_upload_url ); axios.post(file_upload_url, data,