245 lines
7.6 KiB
JavaScript
245 lines
7.6 KiB
JavaScript
import React from "react";
|
||
import Head from 'next/head';
|
||
import Image from 'next/image';
|
||
import { connect } from "react-redux";
|
||
import { withRouter } from 'next/router';
|
||
import moment from "moment";
|
||
import { SpinnerCircular } from 'spinners-react';
|
||
|
||
import { reduxWrapper } from '../../store';
|
||
|
||
import Header from '../components/Header';
|
||
import Footer from '../components/Footer';
|
||
import InnerMenu from "./components/InnerMenu";
|
||
import Company from "../components/Company";
|
||
import DateInput from '../components/DatePicker';
|
||
import DownloadPrintFormPdfButton from "../components/DownloadPrintFormPdfButton";
|
||
|
||
import { getContractInfo, getContractDocuments, getReconciliationFile } from "../../actions";
|
||
|
||
class ContractDocumentsPage extends React.Component
|
||
{
|
||
constructor(props)
|
||
{
|
||
super(props);
|
||
this.state = {
|
||
opened: [],
|
||
contract_date: null,
|
||
documents: null,
|
||
loading: false,
|
||
period_date_start: null,
|
||
period_date_end: null,
|
||
reconciliation_requested: false,
|
||
}
|
||
}
|
||
|
||
static getDerivedStateFromProps(nextProps, prevState)
|
||
{
|
||
return {
|
||
contract_date: nextProps.contract_date,
|
||
documents: nextProps.documents,
|
||
};
|
||
}
|
||
|
||
componentDidMount()
|
||
{
|
||
if(!this.state.loading && this.props.number !== undefined)
|
||
{
|
||
this.setState({ loading: true, period_date_end: moment().toDate() }, () =>
|
||
{
|
||
getContractInfo({ dispatch: this.props.dispatch, number: this.props.number });
|
||
|
||
getContractDocuments({ dispatch: this.props.dispatch, number: this.props.number }).then(() => {
|
||
this.setState({ loading: false });
|
||
}).catch(() => {});
|
||
});
|
||
}
|
||
}
|
||
|
||
componentDidUpdate(prevProps, prevState)
|
||
{
|
||
if(this.state.period_date_start === null)
|
||
{
|
||
if(prevState.contract_date === null && this.state.contract_date !== null)
|
||
{
|
||
this.setState({ period_date_start: moment(this.state.contract_date).toDate() });
|
||
}
|
||
}
|
||
}
|
||
|
||
_handle_onReconciliationFileRequest = () =>
|
||
{
|
||
const { number } = this.props;
|
||
const { reconciliation_requested, period_date_start, period_date_end, } = this.state;
|
||
|
||
if(!reconciliation_requested)
|
||
{
|
||
this.setState({ reconciliation_requested: true }, () =>
|
||
{
|
||
const date_from = moment(period_date_start).format("YYYY-MM-DD");
|
||
const date_to = moment(period_date_end).format("YYYY-MM-DD");
|
||
|
||
getReconciliationFile({
|
||
contract: number,
|
||
date_from: date_from,
|
||
date_to: date_to,
|
||
filename: `${ number }_reconciliation_${ date_from }_${ date_to }.pdf`,
|
||
})
|
||
.then(() =>
|
||
{
|
||
this.setState({ reconciliation_requested: false });
|
||
})
|
||
.catch(() =>
|
||
{
|
||
this.setState({ reconciliation_requested: false });
|
||
});
|
||
});
|
||
}
|
||
}
|
||
|
||
_handle_onPeriodDate_start = (date) =>
|
||
{
|
||
this.setState({ period_date_start: date });
|
||
}
|
||
|
||
_handle_onPeriodDate_end = (date) =>
|
||
{
|
||
this.setState({ period_date_end: date });
|
||
}
|
||
|
||
render()
|
||
{
|
||
const { loading, contract_date, documents, period_date_start, period_date_end, reconciliation_requested } = this.state;
|
||
const { number } = this.props;
|
||
|
||
console.log("documentsdocumentsdocumentsdocumentsdocuments");
|
||
console.log(documents);
|
||
|
||
const types = {
|
||
upd: "УПД по очередным платежам",
|
||
upd_avans: "УПД по авансовым платежам",
|
||
};
|
||
|
||
return (
|
||
<React.Fragment>
|
||
<Head>
|
||
<title>ЛК Эволюция автолизинга</title>
|
||
<meta
|
||
name="description"
|
||
content="ЛК Эволюция автолизинга"
|
||
/>
|
||
</Head>
|
||
<Header {...this.props} />
|
||
<main>
|
||
<section>
|
||
<div className="clear"></div>
|
||
<div className="container">
|
||
<div className="title_wrapper">
|
||
<div className="left">
|
||
<h1 className="section_title">Договор №{ number }{ contract_date !== null && (<> от { moment(contract_date).format("DD.MM.YYYY") }</>)}</h1>
|
||
</div>
|
||
<Company />
|
||
</div>
|
||
<div className="aside_container about">
|
||
<InnerMenu number={ number } {...this.props} />
|
||
<article>
|
||
{ loading ? (
|
||
<div className="table_row table_header" style={{ minHeight: 300, display: "flex", justifyContent: "center", alignItems: "center" }}>
|
||
<SpinnerCircular size={90} thickness={51} speed={100} color="rgba(28, 1, 169, 1)" secondaryColor="rgba(236, 239, 244, 1)" />
|
||
</div>
|
||
) : (
|
||
<>
|
||
<div className="reconciliation_form">
|
||
<p>Акт сверки</p>
|
||
<div className="form_group">
|
||
<div className="form_field">
|
||
<DateInput placeholder="Дата начала периода" value={ period_date_start } onChange={ this._handle_onPeriodDate_start }/>
|
||
</div>
|
||
<div className="form_field">
|
||
<DateInput placeholder="Дата окончания периода" value={ period_date_end } onChange={ this._handle_onPeriodDate_end }/>
|
||
</div>
|
||
</div>
|
||
<div className="form_group">
|
||
<button className="button button-blue" onClick={ () => { this._handle_onReconciliationFileRequest() }}>
|
||
<>
|
||
{ reconciliation_requested ? (
|
||
<SpinnerCircular size={24} thickness={100} speed={100} color="rgba(255, 255, 255, 1)" secondaryColor="rgba(255, 255, 255, 0.5)" />
|
||
) : "Скачать" }
|
||
</>
|
||
</button>
|
||
{/*<button className="button button-blue">Отправить в ЭДО</button>*/}
|
||
</div>
|
||
</div>
|
||
<div className="dropdown_blocks_list">
|
||
{ documents !== undefined && documents !== null ? (
|
||
<>
|
||
{ documents.upd && documents.upd.map((doc, index) => (
|
||
<React.Fragment key={ index }>
|
||
<div className="dropdown_block bt">
|
||
<div className="block_header">
|
||
<p>{ types[ doc.type.toLowerCase() ] }</p>
|
||
<button className="block_toggle"></button>
|
||
</div>
|
||
</div>
|
||
<div className="dosc_list medium-icon">
|
||
{ doc.upd.map((upd_document, upd_document_index) => (
|
||
<div className="row" key={ upd_document_index }>
|
||
<p className="doc_name i-pdf i-medium">
|
||
{ upd_document.num } от { moment(upd_document.date).format("DD.MM.YYYY") }
|
||
</p>
|
||
<DownloadPrintFormPdfButton filename={ `${ number }_${ upd_document.type }_${ upd_document.num }.pdf` } contract={ number } num={ upd_document.num } date={ upd_document.date } type={ upd_document.type }/>
|
||
</div>
|
||
)) }
|
||
</div>
|
||
</React.Fragment>
|
||
)) }
|
||
</>
|
||
) : null }
|
||
</div>
|
||
</>
|
||
) }
|
||
</article>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
<Footer />
|
||
</React.Fragment>
|
||
);
|
||
}
|
||
}
|
||
|
||
function mapStateToProps(state, ownProps)
|
||
{
|
||
return {
|
||
contract_date: state.contract.date,
|
||
documents: state.contract.documents,
|
||
}
|
||
}
|
||
|
||
export const getServerSideProps = reduxWrapper.getServerSideProps(store =>
|
||
async ({ req, res, query }) =>
|
||
{
|
||
return {
|
||
props: {
|
||
number: query.number,
|
||
}
|
||
}
|
||
}
|
||
);
|
||
|
||
export default withRouter(connect(mapStateToProps)(ContractDocumentsPage));
|
||
|
||
{/*}
|
||
<div className="block_body">
|
||
<div className="transaction_detail">
|
||
<p>№ постановления: <b>3432434242334</b></p>
|
||
<ul>
|
||
<li>Сумма: <b>3 000,00 р.</b></li>
|
||
<li>Дата: <b>01/01/2020</b></li>
|
||
<li>Статус: <b className="success">Оплачен</b></li>
|
||
<li>Штраф: п. 1.15 - Несоблюдение правил парковки </li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
{*/} |