Merge branch 'master' of https://github.com/merelendor/evoleasing-account
This commit is contained in:
commit
0c0e35dda3
@ -170,7 +170,8 @@ export const getDealDocuments = ({ dispatch, deal_id }) =>
|
||||
type: actionTypes.DEAL_DOCUMENTS_LIST,
|
||||
data: {
|
||||
deal_id,
|
||||
list: response.data
|
||||
documents: response.data.documents,
|
||||
files: response.data.files,
|
||||
}
|
||||
});
|
||||
|
||||
@ -185,7 +186,8 @@ export const getDealDocuments = ({ dispatch, deal_id }) =>
|
||||
type: actionTypes.DEAL_DOCUMENTS_LIST,
|
||||
data: {
|
||||
deal_id,
|
||||
list: []
|
||||
documents: [],
|
||||
files: {},
|
||||
}
|
||||
});
|
||||
|
||||
@ -194,6 +196,32 @@ export const getDealDocuments = ({ dispatch, deal_id }) =>
|
||||
});
|
||||
}
|
||||
|
||||
export const sendDealDocuments = ({ deal_id }) =>
|
||||
{
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
const payload = {
|
||||
deal_id,
|
||||
};
|
||||
|
||||
axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/upload`, payload,
|
||||
{
|
||||
withCredentials: true,
|
||||
})
|
||||
.then(async (response) =>
|
||||
{
|
||||
console.log("ACTION", "deals", "sendDealDocuments", "response.data", response.data);
|
||||
|
||||
resolve();
|
||||
})
|
||||
.catch((error) =>
|
||||
{
|
||||
console.error(error);
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const getDealContracts = ({ dispatch, deal_id }) =>
|
||||
{
|
||||
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/contracts`;
|
||||
@ -238,7 +266,7 @@ export const getDealContracts = ({ dispatch, deal_id }) =>
|
||||
});
|
||||
}
|
||||
|
||||
export const uploadDocument = ({ number, entity, id, filename, file }) =>
|
||||
export const attachDealDocument = ({ deal_id, document_id, index, lastModified, filename, file, type }) =>
|
||||
{
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
@ -246,13 +274,15 @@ export const uploadDocument = ({ number, entity, id, filename, file }) =>
|
||||
data.append('file', file);
|
||||
|
||||
const payload = new URLSearchParams({
|
||||
number,
|
||||
entity,
|
||||
id,
|
||||
deal_id,
|
||||
document_id,
|
||||
filename,
|
||||
index,
|
||||
lastModified,
|
||||
type
|
||||
});
|
||||
|
||||
axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/upload?${ payload.toString() }`, data,
|
||||
axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/file/attach?${ payload.toString() }`, data,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
@ -261,7 +291,34 @@ export const uploadDocument = ({ number, entity, id, filename, file }) =>
|
||||
})
|
||||
.then(async (response) =>
|
||||
{
|
||||
console.log("ACTION", "deals", "uploadDocument", "response.data", response.data);
|
||||
console.log("ACTION", "deals", "attachDealDocument", "response.data", response.data);
|
||||
|
||||
resolve();
|
||||
})
|
||||
.catch((error) =>
|
||||
{
|
||||
console.error(error);
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const removeDealDocument = ({ deal_id, document_id, }) =>
|
||||
{
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
const payload = new URLSearchParams({
|
||||
deal_id,
|
||||
document_id,
|
||||
});
|
||||
|
||||
axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/file/remove?${ payload.toString() }`, {},
|
||||
{
|
||||
withCredentials: true,
|
||||
})
|
||||
.then(async (response) =>
|
||||
{
|
||||
console.log("ACTION", "deals", "removeDocument", "response.data", response.data);
|
||||
|
||||
resolve();
|
||||
})
|
||||
|
||||
@ -5,7 +5,7 @@ import { eachLimit } from "async";
|
||||
|
||||
import { SpinnerCircular } from "spinners-react";
|
||||
import FileDropzoneDeals from "../FileDropzoneDeals";
|
||||
import { acceptDealOffers, uploadDocument } from "../../actions";
|
||||
import { acceptDealOffers, attachDealDocument, removeDealDocument, sendDealDocuments } from "../../actions";
|
||||
|
||||
class Step extends React.Component
|
||||
{
|
||||
@ -28,7 +28,7 @@ class Step extends React.Component
|
||||
else
|
||||
{
|
||||
this.setState({ open: false });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,15 +266,53 @@ class DocumentsForm extends Step
|
||||
files: {},
|
||||
uploading: false,
|
||||
completed: false,
|
||||
loading: true,
|
||||
};
|
||||
this.status = [ 102 ];
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState)
|
||||
{
|
||||
if(this.props.statuscode_id !== prevProps.statuscode_id)
|
||||
{
|
||||
if(this.status.indexOf(this.props.statuscode_id) > -1)
|
||||
{
|
||||
this.setState({ open: true });
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setState({ open: false });
|
||||
}
|
||||
}
|
||||
|
||||
if(prevProps.files !== this.props.files)
|
||||
{
|
||||
this.setState({ files: this.props.files, loading: false }, () =>
|
||||
{
|
||||
this._checkFilesCompleted();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_handle_onSendFiles = (event) =>
|
||||
{
|
||||
event.stopPropagation();
|
||||
// event.preventDefault();
|
||||
const { dealSelected, onDealsUpdate } = this.props;
|
||||
|
||||
this.setState({ loading: true }, () =>
|
||||
{
|
||||
sendDealDocuments({ deal_id: dealSelected })
|
||||
.then(() =>
|
||||
{
|
||||
onDealsUpdate();
|
||||
})
|
||||
.catch(() =>
|
||||
{
|
||||
|
||||
});
|
||||
})
|
||||
/*
|
||||
const { files } = this.state;
|
||||
const files_array = [];
|
||||
|
||||
@ -290,18 +328,16 @@ class DocumentsForm extends Step
|
||||
{
|
||||
eachLimit(files_array, 1, (file, callback) =>
|
||||
{
|
||||
console.log({ file, props: this.props });
|
||||
const { opp_number } = this.props;
|
||||
|
||||
const payload = {
|
||||
number: opp_number,
|
||||
entity: "opportunity",
|
||||
id: file.group,
|
||||
deal_id: opp_number,
|
||||
document_id: file.group,
|
||||
filename: file.name,
|
||||
file,
|
||||
};
|
||||
|
||||
uploadDocument(payload)
|
||||
attachDealDocument(payload)
|
||||
.then(() =>
|
||||
{
|
||||
this._onSendFileStats(file.group, file.index);
|
||||
@ -310,13 +346,14 @@ class DocumentsForm extends Step
|
||||
}, 1000)
|
||||
}, () =>
|
||||
{
|
||||
console.log("ready");
|
||||
this.setState({ uploading: false }, () =>
|
||||
{
|
||||
this._checkFilesCompleted();
|
||||
onDealsUpdate();
|
||||
});
|
||||
});
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
_onSendFileStats = (group, index) =>
|
||||
@ -328,10 +365,10 @@ class DocumentsForm extends Step
|
||||
this.setState({ files });
|
||||
}
|
||||
|
||||
_handle_onAddFile = (file_id, files) =>
|
||||
_handle_onAddFile = (document_id, files) =>
|
||||
{
|
||||
const existed_files = this.state.files;
|
||||
const document_files = existed_files[ file_id ] === undefined ? [] : existed_files[ file_id ];
|
||||
const document_files = existed_files[ document_id ] === undefined ? [] : existed_files[ document_id ];
|
||||
|
||||
for(let nf in files)
|
||||
{
|
||||
@ -344,51 +381,77 @@ class DocumentsForm extends Step
|
||||
if(!e)
|
||||
{
|
||||
files[nf].index = nf;
|
||||
files[nf].group = file_id;
|
||||
files[nf].group = document_id;
|
||||
files[nf].sent = false;
|
||||
document_files.push(files[nf]);
|
||||
}
|
||||
|
||||
existed_files[ file_id ] = document_files;
|
||||
existed_files[ document_id ] = document_files;
|
||||
|
||||
this.setState({ files: existed_files }, () =>
|
||||
{
|
||||
this._checkFilesCompleted();
|
||||
const { opp_number } = this.props;
|
||||
|
||||
const payload = {
|
||||
deal_id: opp_number,
|
||||
document_id: files[0].group,
|
||||
filename: files[0].name,
|
||||
index: files[0].index,
|
||||
lastModified: files[0].lastModified,
|
||||
file: files[0],
|
||||
type: files[0].type,
|
||||
};
|
||||
|
||||
attachDealDocument(payload)
|
||||
.then(() =>
|
||||
{
|
||||
this._onSendFileStats(document_id, 0);
|
||||
this._checkFilesCompleted();
|
||||
}, 1000)
|
||||
//this._checkFilesCompleted();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_handle_onDeleteFile = (file_id, file) =>
|
||||
_handle_onDeleteFile = (document_id, file) =>
|
||||
{
|
||||
const files = { ...this.state.files };
|
||||
const { opp_number } = this.props;
|
||||
|
||||
const list = [];
|
||||
|
||||
for(let i in files[file_id])
|
||||
for(let i in files[document_id])
|
||||
{
|
||||
if(files[file_id][i].name !== file.name)
|
||||
if(files[document_id][i].name !== file.name)
|
||||
{
|
||||
list.push(files[file_id][i]);
|
||||
list.push(files[document_id][i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(list.length > 0)
|
||||
{
|
||||
files[file_id] = list;
|
||||
files[document_id] = list;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete files[file_id];
|
||||
delete files[document_id];
|
||||
}
|
||||
|
||||
this.setState({ files }, () =>
|
||||
{
|
||||
this._checkFilesCompleted();
|
||||
|
||||
removeDealDocument({ deal_id: opp_number, document_id });
|
||||
});
|
||||
}
|
||||
|
||||
_checkFilesCompleted = () =>
|
||||
{
|
||||
//Object.keys(files).length > 0
|
||||
const documents_length = this.props.documents.length;
|
||||
const files_length = Object.keys(this.state.files).length;
|
||||
|
||||
const c = files_length >= documents_length ? true : false;
|
||||
/*
|
||||
const { files } = this.state;
|
||||
const { documents } = this.props;
|
||||
|
||||
@ -414,33 +477,16 @@ class DocumentsForm extends Step
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if(c)
|
||||
{
|
||||
for(let g in files)
|
||||
{
|
||||
for(let f in files[g])
|
||||
{
|
||||
if(!files[g][f].sent)
|
||||
{
|
||||
c = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
console.log({ c })
|
||||
this.setState({ completed: c });
|
||||
}
|
||||
|
||||
_renderHeaderButtons = () =>
|
||||
{
|
||||
const { open, uploading, completed, } = this.state;
|
||||
const { open, uploading, completed, loading, } = this.state;
|
||||
|
||||
if(open && !uploading && !completed)
|
||||
if(open && !uploading && !loading && completed)
|
||||
{
|
||||
return (
|
||||
<div className="buttons">
|
||||
@ -455,9 +501,7 @@ class DocumentsForm extends Step
|
||||
render()
|
||||
{
|
||||
const { index, statuscode_id, dealSelected, documents, questionnaire_status } = this.props;
|
||||
const { open, files, uploading } = this.state;
|
||||
|
||||
// console.log("DocumentsForm", { documents });
|
||||
const { open, files, uploading, loading } = this.state;
|
||||
|
||||
return (
|
||||
<div className={`${ this.status.indexOf( statuscode_id ) > -1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
|
||||
@ -466,69 +510,77 @@ class DocumentsForm extends Step
|
||||
<div className="status_body">
|
||||
{ this._renderHeader("Сборка пакета документов") }
|
||||
<div className="wrap form" style={{ display: open ? "block" : "none" }}>
|
||||
<div className="block">
|
||||
<div className="left">
|
||||
<p><b>Устав организации:</b></p>
|
||||
{ loading ? (
|
||||
<div style={{ minHeight: 100, display: "flex", justifyContent: "center", alignItems: "center", }}>
|
||||
<SpinnerCircular size={ 50 } thickness={ 51 } speed={ 100 } color="rgba(28, 1, 169, 1)" secondaryColor="rgba(236, 239, 244, 1)" />
|
||||
</div>
|
||||
<div className="right">
|
||||
{ questionnaire_status === "need_to_fill" ? (
|
||||
<div className="message alert">
|
||||
<p>Требуется обновить данные в анкете</p>
|
||||
<button className="button button-blue">Актуализировать данные</button>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{ questionnaire_status !== "up_to_date" ? (
|
||||
<div className="message wait">
|
||||
<p>Проводится проверка анкеты Вашей организации</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="message ok">
|
||||
<p>Вам не требуется актуализация данных анкеты Клиента</p>
|
||||
</div>
|
||||
) }
|
||||
</>
|
||||
) }
|
||||
</div>
|
||||
</div>
|
||||
{ documents === undefined ? (
|
||||
<></>
|
||||
) : (
|
||||
<>
|
||||
{ documents.map((document, index) => (
|
||||
<div className="block" key={ index }>
|
||||
<div className="left">
|
||||
<p><b><span>{ document.name }</span>:</b></p>
|
||||
<div className="block">
|
||||
<div className="left">
|
||||
<p><b>Анкета клиента:</b></p>
|
||||
</div>
|
||||
<div className="right">
|
||||
{ questionnaire_status === "need_to_fill" ? (
|
||||
<div className="message alert">
|
||||
<p>Требуется обновить данные в анкете</p>
|
||||
<button className="button button-blue">Актуализировать данные</button>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{ questionnaire_status !== "up_to_date" ? (
|
||||
<div className="message wait">
|
||||
<p>Проводится проверка анкеты Вашей организации</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="message ok">
|
||||
<p>Вам не требуется актуализация данных анкеты Клиента</p>
|
||||
</div>
|
||||
) }
|
||||
</>
|
||||
) }
|
||||
</div>
|
||||
</div>
|
||||
{ documents === undefined ? (
|
||||
<></>
|
||||
) : (
|
||||
<>
|
||||
{ documents.map((document, index) => (
|
||||
<div className="block" key={ index }>
|
||||
<div className="left">
|
||||
<p><b><span>{ document.name }</span>:</b></p>
|
||||
</div>
|
||||
<div className="right">
|
||||
<FileDropzoneDeals
|
||||
uploading={ uploading }
|
||||
files={ files[ document.doc_id ] !== undefined ? files[ document.doc_id ] : [] }
|
||||
onAddFile={ (file) => { this._handle_onAddFile(document.doc_id, file) } }
|
||||
onDeleteFile={ (file) => this._handle_onDeleteFile(document.doc_id, file) }
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)) }
|
||||
</>
|
||||
) }
|
||||
{/*}
|
||||
<div className="message documents">
|
||||
<div className="doc_list">
|
||||
<div className="docs_list medium-icon">
|
||||
<div className="row">
|
||||
<p className="doc_name i-pdf i-medium">№123/2023 от 01.01.2023</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="right">
|
||||
<FileDropzoneDeals
|
||||
uploading={ uploading }
|
||||
files={ files[ document.doc_id ] !== undefined ? files[ document.doc_id ] : [] }
|
||||
onAddFile={ (file) => { this._handle_onAddFile(document.doc_id, file) } }
|
||||
onDeleteFile={ (file) => this._handle_onDeleteFile(document.doc_id, file) }
|
||||
/>
|
||||
<div className="docs_list medium-icon">
|
||||
<div className="row">
|
||||
<p className="doc_name i-pdf i-medium">№123/2023 от 01.01.2023</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)) }
|
||||
<p>Документы, отправленные Вами принадлежат другой организации бла бла коммент от менеджера</p>
|
||||
</div>
|
||||
{*/}
|
||||
</>
|
||||
) }
|
||||
{/*}
|
||||
<div className="message documents">
|
||||
<div className="doc_list">
|
||||
<div className="docs_list medium-icon">
|
||||
<div className="row">
|
||||
<p className="doc_name i-pdf i-medium">№123/2023 от 01.01.2023</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="docs_list medium-icon">
|
||||
<div className="row">
|
||||
<p className="doc_name i-pdf i-medium">№123/2023 от 01.01.2023</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p>Документы, отправленные Вами принадлежат другой организации бла бла коммент от менеджера</p>
|
||||
</div>
|
||||
{*/}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -923,10 +975,10 @@ export default class SingleDeal extends React.Component
|
||||
render()
|
||||
{
|
||||
const { index, status, deals, dealSelected, onCloseDeal, } = this.props;
|
||||
console.log({ "deals": deals });
|
||||
|
||||
const offers = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].offers : undefined;
|
||||
const documents = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].documents : undefined;
|
||||
const files = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].files : undefined;
|
||||
const contracts = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].contracts : undefined;
|
||||
|
||||
return (
|
||||
@ -940,7 +992,7 @@ export default class SingleDeal extends React.Component
|
||||
<div className="modal_body single_status">
|
||||
<Offers { ...this.props } offers={ offers }/>
|
||||
<FinancialProgram { ...this.props }/>
|
||||
<DocumentsForm { ...this.props } documents={ documents }/>
|
||||
<DocumentsForm { ...this.props } documents={ documents } files={ files }/>
|
||||
<StatusDocumentsCheck { ...this.props }/>
|
||||
<StatusDecisionMaking { ...this.props }/>
|
||||
<StatusLeasingRegistration { ...this.props }/>
|
||||
|
||||
@ -4,7 +4,7 @@ import moment from "moment";
|
||||
import { SpinnerCircular } from 'spinners-react';
|
||||
|
||||
const LIMIT = 10000000;
|
||||
const LIMIT_FILES = 10;
|
||||
const LIMIT_FILES = 1;
|
||||
|
||||
export default class FileDropzoneDeals extends FileDropzone
|
||||
{
|
||||
@ -19,21 +19,13 @@ export default class FileDropzoneDeals extends FileDropzone
|
||||
{ files.map((file, index) => (
|
||||
<div className="file" key={ index }>
|
||||
{ file.sent ? (
|
||||
<div className="loading">
|
||||
<div className="success"></div>
|
||||
<div className="delete" onClick={ () => onDeleteFile(file) }>
|
||||
<div className="icon"></div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{ uploading ? (
|
||||
<div className="loading">
|
||||
<SpinnerCircular size={ 22 } thickness={ 100 } speed={ 100 } color="rgba(255, 255, 255, 1)" secondaryColor="rgba(168, 2, 107, 0.5)" style={{ marginTop: "8px" }}/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="delete" onClick={ () => onDeleteFile(file) }>
|
||||
<div className="icon"></div>
|
||||
</div>
|
||||
) }
|
||||
</>
|
||||
<div className="loading">
|
||||
<SpinnerCircular size={ 22 } thickness={ 100 } speed={ 100 } color="rgba(255, 255, 255, 1)" secondaryColor="rgba(168, 2, 107, 0.5)" style={{ marginTop: "8px" }}/>
|
||||
</div>
|
||||
) }
|
||||
<div className="doc_icon">
|
||||
<span className="extension">PDF</span>
|
||||
@ -50,7 +42,7 @@ export default class FileDropzoneDeals extends FileDropzone
|
||||
</div>
|
||||
) }
|
||||
{ !uploading && files.length < LIMIT_FILES && (
|
||||
<Dropzone onDrop={ (acceptedFiles) => onAddFile(acceptedFiles) } maxFiles={ LIMIT_FILES }>
|
||||
<Dropzone onDrop={ (acceptedFiles) => onAddFile(acceptedFiles) } maxFiles={ LIMIT_FILES } multiple={ false }>
|
||||
{ ({getRootProps, getInputProps}) => (
|
||||
<div className={`file_upload dropzone horizontal_dropzone_wrapper`} { ...getRootProps() }>
|
||||
<div className={`files`}></div>
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
2.7.3 - Метод согласования Предложений Клиентом по Лизинговой сделке в CRM
|
||||
POST /lk/ConsiderationOpportunity/quote
|
||||
*/
|
||||
|
||||
import CRMRequestPost from '../../../lib/CRMRequestPost';
|
||||
|
||||
export default async function handler(req, res)
|
||||
|
||||
@ -3,15 +3,85 @@
|
||||
GET /lk/ConsiderationOpportunity/document
|
||||
*/
|
||||
|
||||
import CRMRequestGet from '../../../lib/CRMRequestGet';
|
||||
import axios from 'axios';
|
||||
import { Cookies } from 'react-cookie';
|
||||
import cookie from 'cookie';
|
||||
import moment from 'moment';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { cors } from '../../../lib/cors';
|
||||
import RedisClient from '../../../lib/RedisClient';
|
||||
|
||||
export default async function handler(req, res)
|
||||
{
|
||||
console.log("API", "DEALS", "documents");
|
||||
console.log(req.body);
|
||||
console.log("-".repeat(50));
|
||||
|
||||
await cors(req, res);
|
||||
const { deal_id } = req.body;
|
||||
|
||||
await CRMRequestGet(req, res, `${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/document`, { ...{ opp_number: deal_id } });
|
||||
return new Promise((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(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true });
|
||||
|
||||
try
|
||||
{
|
||||
axios.get(`${ process.env.CRM_API_HOST }/lk/ConsiderationOpportunity/document`, {
|
||||
params: { opp_number: deal_id },
|
||||
headers: {
|
||||
"Authorization": `Bearer ${ crm_jwt }`,
|
||||
}
|
||||
})
|
||||
.then(async (crm_response) =>
|
||||
{
|
||||
const documents = crm_response.data;
|
||||
|
||||
const key = `deals_${ client_jwt_decoded.acc_number }`;
|
||||
var deals = await RedisClient.get(key);
|
||||
|
||||
console.log({ key })
|
||||
|
||||
var files = {};
|
||||
if(deals !== null)
|
||||
{
|
||||
deals = JSON.parse(deals);
|
||||
|
||||
if(deals[ deal_id ] !== undefined)
|
||||
{
|
||||
files = deals[ deal_id ].files;
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).send({ documents, files });
|
||||
resolve();
|
||||
})
|
||||
.catch((error) =>
|
||||
{
|
||||
console.error(error);
|
||||
res.status(500).send();
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.error(e);
|
||||
res.status(500).send();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(403).send();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(403).send();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
105
pages/api/deals/file/attach.js
Normal file
105
pages/api/deals/file/attach.js
Normal file
@ -0,0 +1,105 @@
|
||||
// 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 Redis from 'ioredis';
|
||||
import md5 from 'md5';
|
||||
import { inspect } from 'util';
|
||||
import multer from 'multer';
|
||||
|
||||
import { cors } from '../../../../lib/cors';
|
||||
import RedisClient from '../../../../lib/RedisClient';
|
||||
|
||||
const storage = multer.memoryStorage();
|
||||
const upload = multer({ storage: storage, limits: { fileSize: 1024 * 1024 * 300 } });
|
||||
|
||||
export default async function handler(req, res)
|
||||
{
|
||||
console.log("API", "DEALS", "FILE", "upload");
|
||||
await cors(req, res);
|
||||
|
||||
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);
|
||||
|
||||
upload.single("file")(req, {}, async (err) =>
|
||||
{
|
||||
const { file, } = req;
|
||||
const { deal_id, document_id, type, index, lastModified } = req.query;
|
||||
|
||||
const local_filename = `${ client_jwt_decoded.acc_number }_${ deal_id }_${ document_id }`;
|
||||
|
||||
const file_payload = {
|
||||
name: Buffer.from(file.originalname, 'latin1').toString('utf8'),
|
||||
filename: local_filename,
|
||||
group: document_id,
|
||||
index,
|
||||
type,
|
||||
lastModified,
|
||||
sent: true
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
fs.writeFileSync(`${ __dirname }/../../../../../../uploads/deals/${ local_filename }`, file.buffer);
|
||||
console.log("multer.upload.single file");
|
||||
console.log({ file_payload });
|
||||
|
||||
const key = `deals_${ client_jwt_decoded.acc_number }`;
|
||||
var deals = await RedisClient.get(key);
|
||||
|
||||
var files = {};
|
||||
if(deals !== null)
|
||||
{
|
||||
deals = JSON.parse(deals);
|
||||
|
||||
if(deals[ deal_id ] !== undefined)
|
||||
{
|
||||
files = deals[ deal_id ].files;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
deals = {};
|
||||
}
|
||||
|
||||
files[ document_id ] = [ file_payload ];
|
||||
deals[ deal_id ] = { files };
|
||||
|
||||
await RedisClient.set(key, JSON.stringify(deals));
|
||||
|
||||
res.status(200).json(file_payload);
|
||||
resolve();
|
||||
}
|
||||
catch(upload_single_error)
|
||||
{
|
||||
console.error("upload_single_error");
|
||||
console.error(upload_single_error);
|
||||
res.status(500).send();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(403).send();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: false
|
||||
}
|
||||
}
|
||||
99
pages/api/deals/file/remove.js
Normal file
99
pages/api/deals/file/remove.js
Normal file
@ -0,0 +1,99 @@
|
||||
// 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 Redis from 'ioredis';
|
||||
import md5 from 'md5';
|
||||
import { inspect } from 'util';
|
||||
import multer from 'multer';
|
||||
|
||||
import { cors } from '../../../../lib/cors';
|
||||
import RedisClient from '../../../../lib/RedisClient';
|
||||
|
||||
const storage = multer.memoryStorage();
|
||||
const upload = multer({ storage: storage });
|
||||
|
||||
export default async function handler(req, res)
|
||||
{
|
||||
console.log("API", "DEALS", "FILE", "remove");
|
||||
await cors(req, res);
|
||||
|
||||
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);
|
||||
|
||||
const { deal_id, document_id } = req.query;
|
||||
const local_filename = `${ client_jwt_decoded.acc_number }_${ deal_id }_${ document_id }`;
|
||||
|
||||
try
|
||||
{
|
||||
console.log("local_filename", local_filename);
|
||||
const filename = `${ __dirname }/../../../../../../uploads/deals/${ local_filename }`;
|
||||
|
||||
if (fs.existsSync(filename))
|
||||
{
|
||||
fs.unlinkSync(filename);
|
||||
|
||||
const key = `deals_${ client_jwt_decoded.acc_number }`;
|
||||
var deals = await RedisClient.get(key);
|
||||
|
||||
var files = {};
|
||||
if(deals !== null)
|
||||
{
|
||||
deals = JSON.parse(deals);
|
||||
|
||||
if(deals[ deal_id ] !== undefined)
|
||||
{
|
||||
files = deals[ deal_id ].files;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
deals = {};
|
||||
}
|
||||
|
||||
delete files[ document_id ];
|
||||
deals[ deal_id ] = { files };
|
||||
|
||||
await RedisClient.set(key, JSON.stringify(deals));
|
||||
}
|
||||
else
|
||||
{
|
||||
console.error("NOT exists filename", filename);
|
||||
}
|
||||
|
||||
res.status(200).send();
|
||||
resolve();
|
||||
}
|
||||
catch(remove_single_error)
|
||||
{
|
||||
console.error("remove_single_error");
|
||||
console.error(remove_single_error);
|
||||
|
||||
res.status(500).send();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(403).send();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: false
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
2.7.5 - Метод отправки документов по Сделке на проверку
|
||||
POST /lk/document
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import axios from 'axios';
|
||||
import { Cookies } from 'react-cookie';
|
||||
import cookie from 'cookie';
|
||||
@ -11,19 +11,28 @@ import jwt from 'jsonwebtoken';
|
||||
import { inspect } from 'util';
|
||||
import FormData from 'form-data';
|
||||
import multer from 'multer';
|
||||
import { eachLimit } from 'async';
|
||||
|
||||
import { cors } from '../../../lib/cors';
|
||||
import RedisClient from '../../../lib/RedisClient';
|
||||
|
||||
const storage = multer.memoryStorage();
|
||||
const upload = multer({ storage: storage });
|
||||
const uploads = `${ __dirname }/../../../../../uploads/deals/`;
|
||||
|
||||
/*
|
||||
function uploadFiles()
|
||||
{
|
||||
return new Promise(() => )
|
||||
}
|
||||
*/
|
||||
|
||||
export default async function handler(req, res)
|
||||
{
|
||||
await cors(req, res);
|
||||
|
||||
const { number, entity, id, filename } = req.query;
|
||||
// const { number, entity, id, filename } = req.query;
|
||||
const { deal_id } = req.body;
|
||||
|
||||
return new Promise((resolve) =>
|
||||
return new Promise(async (resolve) =>
|
||||
{
|
||||
if(req.headers.cookie !== undefined)
|
||||
{
|
||||
@ -34,13 +43,112 @@ export default async function handler(req, res)
|
||||
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 });
|
||||
|
||||
const key = `deals_${ client_jwt_decoded.acc_number }`;
|
||||
var deals = await RedisClient.get(key);
|
||||
|
||||
var files = [];
|
||||
if(deals !== null)
|
||||
{
|
||||
deals = JSON.parse(deals);
|
||||
|
||||
if(deals[ deal_id ] !== undefined)
|
||||
{
|
||||
for(let i in deals[ deal_id ].files)
|
||||
{
|
||||
files.push(deals[ deal_id ].files[i]);
|
||||
}
|
||||
|
||||
console.log({ files });
|
||||
console.log(files[0])
|
||||
|
||||
eachLimit(files, 5, (file_entry, callback) =>
|
||||
{
|
||||
const file = file_entry[0];
|
||||
try
|
||||
{
|
||||
if(fs.existsSync(`${ uploads }${ file.filename }`))
|
||||
{
|
||||
const file_to_send_data = fs.readFileSync(`${ uploads }${ file.filename }`);
|
||||
const data = new FormData();
|
||||
data.append("file", file_to_send_data, file.name);
|
||||
|
||||
const payload = new URLSearchParams({
|
||||
name: deal_id,
|
||||
entity: "opportunity",
|
||||
documentTypeNumber: file.group,
|
||||
documentName: file.name,
|
||||
});
|
||||
|
||||
const file_upload_url = `${ process.env.CRM_API_HOST }/lk/document/upload?${ payload.toString() }`;
|
||||
console.log( file_upload_url );
|
||||
|
||||
axios.post(file_upload_url, data,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": `multipart/form-data; boundary=${ data._boundary }`,
|
||||
"Authorization": `Bearer ${ crm_jwt }`,
|
||||
},
|
||||
withCredentials: true,
|
||||
})
|
||||
.then(() =>
|
||||
{
|
||||
console.log("FILE", file.filename, "SENT");
|
||||
callback();
|
||||
})
|
||||
.catch(() =>
|
||||
{
|
||||
callback();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
callback();
|
||||
}
|
||||
/*
|
||||
console.log({ file_upload_url });
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.error(e)
|
||||
callback();
|
||||
}
|
||||
}, () =>
|
||||
{
|
||||
console.log("ALL FILES SENT");
|
||||
res.status(200).json({});
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(403).json({});
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(403).json({});
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(403).json({});
|
||||
resolve();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
const payload = new URLSearchParams({
|
||||
name: number,
|
||||
entity: entity,
|
||||
documentTypeNumber: id,
|
||||
documentName: filename,
|
||||
});
|
||||
const path = `${ process.env.CRM_API_HOST }/lk/Document/upload?${ payload.toString() }`;
|
||||
const path = `${ process.env.CRM_API_HOST }/lk/document/upload?${ payload.toString() }`;
|
||||
console.log({ path });
|
||||
|
||||
upload.single("file")(req, {}, err =>
|
||||
@ -63,6 +171,7 @@ export default async function handler(req, res)
|
||||
})
|
||||
.then((crm_response) =>
|
||||
{
|
||||
console.log("/lk/document/upload SUCCESS");
|
||||
res.status(200).json(crm_response.data);
|
||||
resolve();
|
||||
})
|
||||
@ -88,6 +197,7 @@ export default async function handler(req, res)
|
||||
res.status(403).send();
|
||||
resolve();
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -95,10 +205,4 @@ export default async function handler(req, res)
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: false
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,7 @@ class Insurance extends React.Component
|
||||
|
||||
render()
|
||||
{
|
||||
const { type, title, entry, index, } = this.props;
|
||||
const { type, title, entry, index, number } = this.props;
|
||||
|
||||
return (
|
||||
<React.Fragment key={ index }>
|
||||
@ -312,16 +312,16 @@ class ContractServicesPage extends React.Component
|
||||
{ this._checkInsuranceAvailable() ? (
|
||||
<div className="block_body full">
|
||||
{ insurance.kasko !== undefined && insurance.kasko !== null && insurance.kasko !== "" && insurance.kasko.map !== undefined && insurance.kasko.map((entry, index) => (
|
||||
<Insurance type="kasko" title="КАСКО" entry={ entry } index={ index } key={ index } />
|
||||
<Insurance type="kasko" title="КАСКО" entry={ entry } index={ index } key={ index } number={ number }/>
|
||||
)) }
|
||||
{ insurance.osago !== undefined && insurance.osago !== null && insurance.osago !== "" && insurance.osago.map !== undefined && insurance.osago.map((entry, index) => (
|
||||
<Insurance type="osago" title="ОСАГО" entry={ entry } index={ index } key={ index }/>
|
||||
<Insurance type="osago" title="ОСАГО" entry={ entry } index={ index } key={ index } number={ number }/>
|
||||
)) }
|
||||
{ insurance.nsib !== undefined && insurance.nsib !== null && insurance.nsib !== "" && insurance.nsib.map !== undefined && insurance.nsib.map((entry, index) => (
|
||||
<Insurance type="nsib" title="НСИБ" entry={ entry } index={ index } key={ index }/>
|
||||
<Insurance type="nsib" title="НСИБ" entry={ entry } index={ index } key={ index } number={ number }/>
|
||||
)) }
|
||||
{ insurance.fingap !== undefined && insurance.fingap !== null && insurance.fingap !== "" && insurance.fingap.map !== undefined && insurance.fingap.map((entry, index) => (
|
||||
<Insurance type="fingap" title="Safe Finance" entry={ entry } index={ index } key={ index }/>
|
||||
<Insurance type="fingap" title="Safe Finance" entry={ entry } index={ index } key={ index } number={ number }/>
|
||||
)) }
|
||||
</div>
|
||||
) : (
|
||||
|
||||
@ -55,7 +55,7 @@ const dealsReducer = (state = initialState.deals, action) =>
|
||||
console.log("ACTION", actionTypes.DEAL_DOCUMENTS_LIST, { action });
|
||||
|
||||
const details = state.details;
|
||||
details[action.data.deal_id] = { ...details[action.data.deal_id], ...{ documents: action.data.list } };
|
||||
details[action.data.deal_id] = { ...details[action.data.deal_id], ...{ documents: action.data.documents, files: action.data.files } };
|
||||
|
||||
return {
|
||||
...state,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user