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 { acceptDealOffers, uploadDocument } from "../../actions";
class Step extends React.Component
{
componentDidMount()
{
if(this.status.indexOf(this.props.statuscode_id) > -1)
{
this.setState({ open: true });
}
}
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 });
}
}
}
_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[ 0 ] ? { position: "relative", } : { position: "relative", cursor: "inherit" }} onClick={ statuscode_id >= this.status[ 0 ] ? this._handle_onSwitch : () => {} }>
{ this.status.indexOf(statuscode_id) > -1 && (
)}
{ title }
{ statuscode_id >= this.status[ 0 ] && (
) }
{ 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_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_numbers: 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 (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
№ { dealSelected }
{ this._renderHeader("Выбор КП ") }
{ offers === undefined || loading ? (
) : (
<>
{ offers.length > 0 ? (
) : (
Нет предложений
) }
>
) }
)
}
}
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 (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
№ { dealSelected }
{ this._renderHeader("Программа финансирования") }
Статусный текст о том что выбирается программа финансированияи
)
}
}
class DocumentsForm extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
files: {},
uploading: false,
completed: false,
};
this.status = [ 102 ];
}
_handle_onSendFiles = (event) =>
{
event.stopPropagation();
// event.preventDefault();
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) =>
{
console.log({ file, props: this.props });
const { opp_number } = this.props;
const payload = {
number: opp_number,
entity: "opportunity",
id: file.group,
filename: file.name,
file,
};
uploadDocument(payload)
.then(() =>
{
this._onSendFileStats(file.group, file.index);
callback();
}, 1000)
}, () =>
{
console.log("ready");
this.setState({ uploading: false }, () =>
{
this._checkFilesCompleted();
});
});
});
}
_onSendFileStats = (group, index) =>
{
const files = { ...this.state.files };
files[group][index].sent = true;
this.setState({ files });
}
_handle_onAddFile = (file_id, files) =>
{
const existed_files = this.state.files;
const document_files = existed_files[ file_id ] === undefined ? [] : existed_files[ file_id ];
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 = file_id;
files[nf].sent = false;
document_files.push(files[nf]);
}
existed_files[ file_id ] = document_files;
this.setState({ files: existed_files }, () =>
{
this._checkFilesCompleted();
});
}
}
_handle_onDeleteFile = (file_id, file) =>
{
const files = { ...this.state.files };
const list = [];
for(let i in files[file_id])
{
if(files[file_id][i].name !== file.name)
{
list.push(files[file_id][i]);
}
}
if(list.length > 0)
{
files[file_id] = list;
}
else
{
delete files[file_id];
}
this.setState({ files }, () =>
{
this._checkFilesCompleted();
});
}
_checkFilesCompleted = () =>
{
//Object.keys(files).length > 0
const { files } = this.state;
const { documents } = this.props;
let c = true;
for(let g in documents)
{
const group = documents[g].doc_id;
if(files[group] === undefined || files[group].length === 0)
{
c = false;
break;
}
else
{
for(let f in files[group])
{
if(!files[group][f].sent)
{
c = false;
break;
}
}
}
}
/*
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;
if(open && !uploading && !completed)
{
return (
)
}
return null;
}
render()
{
const { index, statuscode_id, dealSelected, documents, questionnaire_status } = this.props;
const { open, files, uploading } = this.state;
// console.log("DocumentsForm", { documents });
return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
№ { dealSelected }
{ this._renderHeader("Сборка пакета документов") }
{ questionnaire_status === "need_to_fill" ? (
Требуется обновить данные в анкете
) : (
<>
{ questionnaire_status !== "up_to_date" ? (
Проводится проверка анкеты Вашей организации
) : (
Вам не требуется актуализация данных анкеты Клиента
) }
>
) }
{ documents === undefined ? (
<>>
) : (
<>
{ documents.map((document, index) => (
{ this._handle_onAddFile(document.doc_id, file) } }
onDeleteFile={ (file) => this._handle_onDeleteFile(document.doc_id, file) }
/>
)) }
>
) }
{/*}
Документы, отправленные Вами принадлежат другой организации бла бла коммент от менеджера
{*/}
)
}
}
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 (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
№ { dealSelected }
{ this._renderHeader("Проверка документов") }
Статусный текст о том что выбирается программа финансированияи
)
}
}
class StatusDecisionMaking extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
};
this.status = [ 104, 105, ];
}
render()
{
const { index, statuscode_id, dealSelected } = this.props;
const { open } = this.state;
return (
-1 ? "current" : (statuscode_id > this.status[0] && statuscode_id > this.status[1]) ? "done" : "" }`}>
№ { dealSelected }
{ this._renderHeader("Принятие решения по сделке") }
Статусный текст о том что выбирается программа финансированияи
)
}
}
class StatusLeasingRegistration 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 (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
№ { dealSelected }
{ this._renderHeader("Принято положительное решение") }
Статусный текст о том что выбирается программа финансированияи
)
}
}
class SigningTypeSelection extends Step
{
constructor(props)
{
super(props);
this.state = {
open: false,
checked: {
prepared_contracts: [],
signing_plan_contracts: [],
signing_fact_contracts: [],
issued_contracts: [],
annulled_contracts: [],
},
};
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",
},
];
}
_render_preparedContracts = () =>
{
const checked = this.state.checked.prepared_contracts;
const contracts = this.props.contracts['prepared_contracts'];
console.log("_render_preparedContracts", { contracts });
return (
{ contracts.length > 0 ?
contracts.map((contract, index) => (
)) : (
Нет договоров
) }
)
}
_render_signingPlanContracts = () =>
{
const contracts = this.props.contracts['prepared_contracts'];
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 && (
) }
)) : (
Нет договоров
) }
)
}
_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 } = this.state;
return (
-1 ? "current" : statuscode_id > this.status[ 0 ] ? "done" : "" }`}>
№ { dealSelected }
{ this._renderHeader("Оформление лизинга") }
{ this.types.map((type, index) => (
{ this._render_contracts(type.key) }
)) }
)
}
}
export default class SingleDeal extends React.Component
{
constructor(props)
{
super(props);
}
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 contracts = deals.details[ dealSelected ] !== undefined ? deals.details[ dealSelected ].contracts : undefined;
return (
)
}
}