import React from "react"; import numeral from "numeral"; import moment from "moment"; import { eachLimit, eachSeries } from "async"; import { SpinnerCircular } from "spinners-react"; import FileDropzoneDeals from "../FileDropzoneDeals"; import EDOSign from "../../components/EDOSign"; import { acceptDealOffers, attachDealDocument, docEDOCancel, docEDOStatus, downloadDealOffer, getFile, removeDealDocument, sendDealDocuments, signDownloadFile, signGetFileContractProject } from "../../actions"; class Step extends React.Component { componentDidMount() { if(this.status === this.props.statuscode_id) { this.setState({ open: true }); } } componentDidUpdate(prevProps, prevState) { if(this.props.statuscode_id !== prevProps.statuscode_id) { if(this.status === this.props.statuscode_id) { this.setState({ open: true }); } else { this.setState({ open: false }); } } } _handle_onSwitch = () => { const { statuscode_id } = this.props; this.setState({ open: !this.state.open ? true : false }); } _renderHeader = (title) => { const { statuscode_id } = this.props; const { open } = this.state; return (
= 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 && (
) } { this._renderHeaderButtons !== undefined && this._renderHeaderButtons() }
) } } class Offers extends Step { constructor(props) { super(props); this.state = { open: false, loading: false, checked: [], }; this.status = 100; } _handle_onCheckOffer = (quote_number) => { const checked = [ ...this.state.checked ]; let is_new = true; if(checked.indexOf(quote_number) > -1) { checked.splice(checked.indexOf(quote_number), 1); is_new = false; } if(is_new) { checked.push(quote_number); } this.setState({ checked }); } _handle_onOffer = (quote_number) => { downloadDealOffer({ quote_number, filename: `ЛК Эволюция КП №${ quote_number }.pdf` }) .then(() => {}) .catch(() => {}); } _handle_onSend = (event) => { event.preventDefault(); event.stopPropagation(); this.setState({ loading: true }, () => { const { checked } = this.state; const { dealSelected, onDealsUpdate } = this.props; const offers = []; for(let i in checked) { offers.push({ quote_number: checked[i], agreed: true, }); } acceptDealOffers({ deal_id: dealSelected, offers }) .then(() => { onDealsUpdate() .then(() => { this.setState({ loading: false }); }) .catch(() => { this.setState({ loading: false }); }); }) }); } _renderHeaderButtons = () => { const { open, checked, loading } = this.state; if(!loading && open && checked.length > 0) { return (
) } return null; } render() { const { index, statuscode_id, dealSelected, offers } = this.props; const { checked, open, loading } = this.state; return (
this.status ? "done" : "" }`}>

№ { dealSelected }

{ this._renderHeader("Выбор КП ") }
{ offers === undefined || loading ? (
) : ( <> { offers.length > 0 ? ( { 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 }
this._handle_onOffer(offer.quote_number) }>

КП №{ offer.quote_number }

) : (

Нет предложений

) } ) }
) } } class FinancialProgram extends Step { constructor(props) { super(props); this.state = { open: false, }; this.status = 101; } render() { const { index, statuscode_id, dealSelected } = this.props; const { open } = this.state; return (
this.status ? "done" : "" }`}>

№ { dealSelected }

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

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

) : (

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

) }
) } } class DocumentsForm extends Step { constructor(props) { super(props); this.state = { open: false, uploaded: {}, uploading: false, completed: false, loading: true, }; this.status = 102; } componentDidMount() { if(this.status === this.props.statuscode_id) { this.setState({ open: true, }); } } componentDidUpdate(prevProps, prevState) { if(this.props.statuscode_id !== prevProps.statuscode_id) { if(this.status === this.props.statuscode_id) { this.setState({ open: true }); } else { this.setState({ open: false }); } } if(prevProps.uploaded !== this.props.uploaded) { this.setState({ uploaded: this.props.uploaded, loading: false }, () => { const completed = this._checkFilesCompleted(); this.setState({ completed }); }); } } _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 = []; for(let g in files) { for(let f in files[g]) { files_array.push(files[g][f]) } } this.setState({ uploading: true }, () => { eachLimit(files_array, 1, (file, callback) => { const { opp_number } = this.props; const payload = { deal_id: opp_number, document_id: file.group, filename: file.name, file, }; attachDealDocument(payload) .then(() => { this._onSendFileStats(file.group, file.index); callback(); }, 1000) }, () => { this.setState({ uploading: false }, () => { this._checkFilesCompleted(); onDealsUpdate(); }); }); }); */ } _onSendFileStats = (group, index) => { return new Promise((resolve) => { const uploaded = { ...this.state.uploaded }; uploaded[group].files[index].sent = true; this.setState({ uploaded }, () => { resolve(); }); }) } _handle_onAddFile = (document_id, files, update) => { const existed_files = { ...this.state.uploaded }; console.log("_handle_onAddFile", { existed_files }); const document_files = existed_files[ document_id ] === undefined ? [] : existed_files[ document_id ].files; if(existed_files[ document_id ] === undefined) { existed_files[ document_id ] = { sent: false, files: [], }; } for(let nf in files) { let e = false; for(let ef in document_files) { if(document_files[ef].name === files[nf].name) { e = true; } } if(!e) { files[nf].index = nf; files[nf].group = document_id; files[nf].sent = false; files[nf].update = update; document_files.push(files[nf]); } existed_files[ document_id ].sent = false; existed_files[ document_id ].files = document_files; } this.setState({ uploaded: existed_files, uploading: true }, () => { const { opp_number } = this.props; eachSeries(files, (file, callback) => { const payload = { deal_id: opp_number, document_id: file.group, filename: file.name, index: file.index, lastModified: file.lastModified, type: file.type, file, update, }; attachDealDocument(payload) .then(async () => { await this._onSendFileStats(document_id, file.index); callback(); }, 1000) }, () => { const completed = this._checkFilesCompleted(); this.setState({ uploading: false, completed }); }); }); } _handle_onDeleteFile = (document_id, file) => { const uploaded = { ...this.state.uploaded }; const { opp_number } = this.props; const list = []; for(let i in uploaded[document_id].files) { if(uploaded[document_id].files[i].name !== file.name) { list.push(uploaded[document_id].files[i]); } } if(list.length > 0) { uploaded[document_id].files = list; } else { delete uploaded[document_id]; } this.setState({ uploaded }, () => { const completed = this._checkFilesCompleted(); this.setState({ completed }, () => { removeDealDocument({ deal_id: opp_number, document_id }); }); }); } _handle_onQuestionnaire = (event) => { const { onQuestionnaire } = this.props; event.preventDefault(); onQuestionnaire(); } _checkFilesCompleted = () => { // 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 { uploaded } = this.state; const { documents } = this.props; let c = true; if(documents !== undefined) { for(let g in documents) { const group = documents[g].doc_id; if(uploaded[group] === undefined || uploaded[group].files.length === 0) { c = false; break; } else { for(let f in uploaded[group].files) { if(!uploaded[group].files[f].sent) { c = false; break; } } } } } else { c = false; } return c; } _renderHeaderButtons = () => { const { open, uploading, completed, loading, } = this.state; const { statuscode_id } = this.props; if(open && !uploading && !loading) { if(this.status === statuscode_id) { return (
) } } return null; } render() { const { index, statuscode_id, dealSelected, documents, questionnaire_status, } = this.props; const { open, uploaded, uploading, loading } = this.state; return (
this.status ? "done" : "" }`}>

№ { dealSelected }

{ this._renderHeader("Сборка пакета документов") }
{ loading ? (
) : ( <>

Анкета клиента:

{ questionnaire_status === "need_to_fill" ? (

Требуется обновить данные в анкете

) : ( <> { questionnaire_status !== "up_to_date" ? (

Проводится проверка анкеты Вашей организации

) : (

Вам не требуется актуализация данных анкеты Клиента

) } ) }
{ documents === undefined ? ( <> ) : ( <> { documents.map((document, index) => { console.log({ document }); return (

{ document.name }:

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

{ document.check }

) : (

{ document.check }

) } ) }
) } ) } ) } {/*}

Документы, отправленные Вами принадлежат другой организации бла бла коммент от менеджера

{*/} ) }
) } } class StatusDocumentsCheck extends Step { constructor(props) { super(props); this.state = { open: false, }; this.status = 103; } render() { const { index, statuscode_id, dealSelected } = this.props; const { open } = this.state; return (
this.status ? "done" : "" }`}>

№ { dealSelected }

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

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

) : (

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

) }
) } } class StatusDecisionMaking extends Step { constructor(props) { super(props); this.state = { open: false, }; this.status = 104; } render() { const { index, statuscode_id, dealSelected } = this.props; const { open } = this.state; if(statuscode_id === 105) { return null; } return (
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("Требуется изменение параметров") }

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

) } } class StatusPositiveDecision extends Step { constructor(props) { super(props); this.state = { open: false, }; this.status = 106; } render() { const { index, statuscode_id, dealSelected } = this.props; const { open } = this.state; return (
this.status ? "done" : "" }`}>

№ { dealSelected }

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

Идёт подготовка необходимых документов для заключения сделки

) : (

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

) }
) } } 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) { super(props); this.state = { open: false, /* checked: { prepared_contracts: [], signing_plan_contracts: [], signing_fact_contracts: [], issued_contracts: [], annulled_contracts: [], }, */ checked: [], edo: false, }; this.status = 107; this.types = [ { title: "Подготовлено", key: "prepared_contracts", }, { title: "К подписанию", key: "signing_plan_contracts", }, { title: "Подписано", key: "signing_fact_contracts", }, { title: "Выдано", key: "issued_contracts", }, { title: "Анулировано", key: "annulled_contracts", }, ]; this.container_ref = React.createRef(); } _handle_onScrollToContainer = () => { const element = this.container_ref.current; const y = (element.getBoundingClientRect().top + window.scrollY - 160); window.scrollTo({top: y, behavior: 'smooth'}); } _handle_onPreparedContract = (contract) => { const checked = [ ...this.state.checked ]; if(checked.indexOf(contract) > -1) { checked.splice(checked.indexOf(contract), 1); } else { checked.push(contract); } this.setState({ checked }); } _handle_onSignEDO = () => { this.setState({ edo: true }, () => { this._handle_onScrollToContainer(); }); } _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']; const { checked } = this.state; const documents = []; for(let i in contracts) { if(checked.indexOf(contracts[i].name) > -1) { documents.push({ id: contracts[i].name, name: `Договор № ${ contracts[i].name }`, date: contracts[i].date, type: `${ contracts[i].brand_name } ${ contracts[i].model_name }`, extension: 'pdf', }) } } return documents; } _render_preparedContracts = () => { const { edo, checked } = this.state; //const checked = this.state.checked.prepared_contracts; const contracts = this.props.contracts['prepared_contracts']; console.log("_render_preparedContracts", { contracts }); if(edo) { return ( ) } return (
{ contracts.length > 0 ? contracts.map((contract, index) => (
-1 ? true : false } onChange={ () => { this._handle_onPreparedContract(contract.name) } }/>
{ moment(contract.date).format('MM.DD.YYYY') } { contract.brand_name } { contract.model_name }
)) : (

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

) }
{ contracts.length > 0 && (
) }
) } _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) => ( ) ) : (

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

) }
) } _render_signingFactContracts = () => { const contracts = this.props.contracts['signing_fact_contracts']; console.log("_render_signingFactContracts", { 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 }
{ contract.statuscode_name }
)) : (

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

) }
) } _render_issuedContracts = () => { const contracts = this.props.contracts['issued_contracts']; console.log("_render_issuedContracts", { 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 }
)) : (

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

) }
) } _render_annuledContracts = () => { const contracts = this.props.contracts['annulled_contracts']; console.log("_render_annuledContracts", { 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 }
)) : (

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

) }
) } _render_contracts = (type) => { const { contracts } = this.props; if(contracts !== undefined) { switch (type) { case "prepared_contracts": { return this._render_preparedContracts(); } case "signing_plan_contracts": { return this._render_signingPlanContracts(); } case "signing_fact_contracts": { return this._render_signingFactContracts(); } case "issued_contracts": { return this._render_issuedContracts(); } case "annulled_contracts": { return this._render_annuledContracts(); } } } else { return null; } } render() { const { index, statuscode_id, dealSelected } = this.props; const { open, edo } = this.state; return (
this.status ? "done" : "" }`} ref={ this.container_ref }>

№ { dealSelected }

{ this._renderHeader("Оформление лизинга") }
{ this.props.contracts === undefined ? (
) : ( <> { this.types.map((type, index) => (
{ edo ? ( <> { type.key !== "prepared_contracts" && (

{ type.title }

) } ) : (

{ type.title }

) }
{ this._render_contracts(type.key) }
)) } ) }
) } } export default class SingleDeal extends React.Component { constructor(props) { super(props); this.leasing_registration_ref = React.createRef(); } _onDealContractsUpdate = () => { const { onDealContractsUpdate, dealSelected } = this.props; onDealContractsUpdate(dealSelected); } render() { const { index, status, deals, dealSelected, onCloseDeal, } = this.props; const offers = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].offers : undefined; const documents = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].documents : undefined; const uploaded = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].uploaded : undefined; const contracts = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].contracts : undefined; return (
{/*}

Статус сделки

{*/}
Свернуть
) } }