deals EDO sign updates
This commit is contained in:
parent
7872d0ec4b
commit
97503afe14
@ -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) =>
|
||||
{
|
||||
@ -133,3 +133,27 @@ export const signGetWMDoc = (payload) =>
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@ -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");
|
||||
@ -182,6 +182,14 @@ class EDOSign extends React.Component
|
||||
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,6 +289,27 @@ class EDOSign extends React.Component
|
||||
<div className="docs_list medium-icon">
|
||||
<p className="list_title">Подписание через ЭДО</p>
|
||||
</div>
|
||||
{ step === 0 && (
|
||||
<div className="form_field edo_list_field">
|
||||
<label>Выберите оператора для отправки пакета документов</label>
|
||||
<div className="edo_list_selection">
|
||||
{ operators !== undefined && operators !== null && operators.map((operator, index) => (
|
||||
<div className="form_field checkbox item" key={ index }>
|
||||
<input type="radio"
|
||||
checked={ operator.box_id === operator_selected.box_id }
|
||||
hidden=""
|
||||
id={ `operator_${ index }` }
|
||||
name={ `operator_${ index }` }
|
||||
onChange={ (event) => this._handle_onSelectOperator(operator) }
|
||||
disabled={ false }
|
||||
/>
|
||||
<label htmlFor={ `operator_${ index }` } className="unselectable">{ operator.provider_edo }</label>
|
||||
</div>
|
||||
)) }
|
||||
</div>
|
||||
</div>
|
||||
) }
|
||||
{ step === 1 && (
|
||||
<div className="docs_list medium-icon edo_sign_documents_list">
|
||||
{ documents.map((document, index) =>
|
||||
(
|
||||
@ -284,7 +344,7 @@ class EDOSign extends React.Component
|
||||
id="edo_attorneys_list"
|
||||
name="edo_attorneys_list"
|
||||
options={ document.attorneys }
|
||||
placeholder="Выберите подписанта"
|
||||
placeholder="Выберите доверенность"
|
||||
noOptionsMessage={ ({ inputValue }) => !inputValue ? "" :"Ничего не найдено" }
|
||||
isSearchable={ true }
|
||||
className="autocomlete autocomlete_with_indicators"
|
||||
@ -301,7 +361,7 @@ class EDOSign extends React.Component
|
||||
<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_onDownloadFile(index, document.entity_id, document.name) }>Посмотреть проект договора</button>
|
||||
<button className="button" onClick={ () => this._handle_onCancelFile(index, document.entity_id) }>Отменить подписание</button>
|
||||
</>
|
||||
) }
|
||||
@ -315,25 +375,8 @@ class EDOSign extends React.Component
|
||||
</div>
|
||||
)) }
|
||||
</div>
|
||||
) }
|
||||
<form ref={ this.ref_form } onSubmit={ this._handle_onFormSubmit } onKeyDown={(e) => {if (e.key === 'Enter') e.preventDefault() }}>
|
||||
<div className="form_field edo_list_field">
|
||||
<label>Выберите оператора для отправки пакета документов</label>
|
||||
<div className="edo_list_selection">
|
||||
{ operators !== undefined && operators !== null && operators.map((operator, index) => (
|
||||
<div className="form_field checkbox item" key={ index }>
|
||||
<input type="radio"
|
||||
checked={ operator.box_id === operator_selected.box_id }
|
||||
hidden=""
|
||||
id={ `operator_${ index }` }
|
||||
name={ `operator_${ index }` }
|
||||
onChange={ (event) => this._handle_onSelectOperator(operator) }
|
||||
disabled={ false }
|
||||
/>
|
||||
<label htmlFor={ `operator_${ index }` } className="unselectable">{ operator.provider_edo }</label>
|
||||
</div>
|
||||
)) }
|
||||
</div>
|
||||
</div>
|
||||
<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
72
lib/CRMRequest/index.js
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 };
|
||||
try
|
||||
{
|
||||
await axios.get(path, {
|
||||
params: payload,
|
||||
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, options)
|
||||
.then((crm_response) =>
|
||||
{
|
||||
if(log)
|
||||
|
||||
@ -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));
|
||||
}
|
||||
21
pages/api/contract/sign/document/download.js
Normal file
21
pages/api/contract/sign/document/download.js
Normal 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));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user