245 lines
9.1 KiB
JavaScript
245 lines
9.1 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 { SpinnerCircular } from 'spinners-react';
|
||
|
||
import { reduxWrapper } from '../../store';
|
||
|
||
import Header from '../components/Header';
|
||
import Footer from '../components/Footer';
|
||
import Company from "../components/Company";
|
||
import InnerMenu from "./components/InnerMenu";
|
||
|
||
import { getContract, getContractInfo } from './../../actions';
|
||
import numeral from "numeral";
|
||
import moment from "moment";
|
||
|
||
class ContractSchedulePage extends React.Component
|
||
{
|
||
constructor(props)
|
||
{
|
||
super(props);
|
||
this.state = {
|
||
loading: false,
|
||
payments: null,
|
||
contract_date: null,
|
||
full: false,
|
||
opened: [],
|
||
}
|
||
}
|
||
|
||
static getDerivedStateFromProps(nextProps, prevState)
|
||
{
|
||
return {
|
||
payments: nextProps.payments,
|
||
contract_date: nextProps.contract_date,
|
||
};
|
||
}
|
||
|
||
componentDidMount()
|
||
{
|
||
console.log("this.props");
|
||
console.log(this.props);
|
||
|
||
if(!this.state.loading && this.props.number !== undefined)
|
||
{
|
||
console.log("this.props.number", this.props.number);
|
||
|
||
this.setState({ loading: true }, () =>
|
||
{
|
||
getContractInfo({ dispatch: this.props.dispatch, number: this.props.number });
|
||
|
||
getContract({ dispatch: this.props.dispatch, number: this.props.number }).then(() => {
|
||
this.setState({ loading: false });
|
||
}).catch(() => {});
|
||
});
|
||
}
|
||
}
|
||
|
||
_handle_onSetFull = () =>
|
||
{
|
||
this.setState({ full: true });
|
||
}
|
||
|
||
_handle_onSetOpen = (number) =>
|
||
{
|
||
const opened = [ ...this.state.opened ];
|
||
|
||
if(opened.indexOf(number) < 0)
|
||
{ opened.push(number); }
|
||
else
|
||
{ opened.splice(opened.indexOf(number), 1); }
|
||
|
||
this.setState({ opened: opened });
|
||
}
|
||
|
||
render()
|
||
{
|
||
const { payments, contract_date, full, opened, loading } = this.state;
|
||
const { number } = this.props;
|
||
|
||
console.log("RENDER", "payments");
|
||
console.log(payments);
|
||
|
||
const statuses = {
|
||
"NotPaid": "",
|
||
"HalfPaid": "overpayment-1",
|
||
"OverPaid": "overpayment-2",
|
||
"Paid": "paid",
|
||
};
|
||
let today = moment();
|
||
|
||
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.replace("_", "/") }{ 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>
|
||
<div className="contract_table schedule">
|
||
<div className="table_row table_header">
|
||
<div className="table_cell">№ платежа</div>
|
||
<div className="table_cell">Дата лизингового платежа</div>
|
||
<div className="table_cell">Лизинговый платеж с НДС (рубли)</div>
|
||
<div className="table_cell">НДС, 20% (рубли)</div>
|
||
<div className="table_cell">Статус платежа</div>
|
||
<div className="table_cell">Платежное поручение</div>
|
||
</div>
|
||
{ 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>
|
||
) : (
|
||
<>
|
||
{ !full && (
|
||
<button className="show_more primary" onClick={ this._handle_onSetFull }>Показать прошедшие платежи</button>
|
||
) }
|
||
{ payments !== null && Object.values(payments).map((payment, index) =>
|
||
{
|
||
let pd = moment(payment.date, "DD-MM-YYYY");
|
||
if(!full && today > pd) { return null; }
|
||
|
||
return (
|
||
<div className={ `table_row ${ opened.indexOf(payment.number) > -1 ? "opened" : "" }` } data-status={ payment.status === "NotPaid" && pd < today ? "notpaid" : statuses[payment.status] } key={ index }>
|
||
<div className="table_cell" data-title="Платеж №">{ payment.number }</div>
|
||
<div className="table_cell" data-title="от">{ moment(payment.date, "DD-MM-YYYY").format("DD.MM.YYYY") }</div>
|
||
<div className="table_cell" data-title="На сумму">{ numeral(payment.total_amount).format('') }</div>
|
||
<div className="table_cell" data-title="НДС, 20% ₽">{ numeral(payment.vat_amount).format('') }</div>
|
||
<div className="table_cell">
|
||
{ payment.status === "Paid" && "Оплачено" }
|
||
{ payment.status === "NotPaid" && "Не оплачено" }
|
||
{ payment.status === "HalfPaid" && "Частично оплачено" }
|
||
{ payment.status === "OverPaid" && (
|
||
<div className="table_cell"><span>Переплата</span> <span>{ numeral(payment.total_amount).format('') } ₽</span></div>
|
||
) }
|
||
</div>
|
||
<div className="table_cell">
|
||
{ payment.invoices.map((invoice, invoice_index) =>
|
||
(
|
||
<React.Fragment key={invoice_index}>
|
||
<p style={{ paddingBottom: "15px", lineHeight: "18px" }}>№{ invoice.number } от { moment(invoice.date, "DD-MM-YYYY").format("DD.MM.YYYY") } на сумму { numeral(invoice.total_amount).format('') } ₽</p>
|
||
</React.Fragment>
|
||
)) }
|
||
</div>
|
||
<button className="toggle_cell" onClick={ () => this._handle_onSetOpen(payment.number) }></button>
|
||
</div>
|
||
)
|
||
}) }
|
||
{/*}
|
||
<div className="table_row" data-status="overpayment-2">
|
||
<div className="table_cell" data-title="Платеж №">11</div>
|
||
<div className="table_cell" data-title="от">21.02.2021</div>
|
||
<div className="table_cell" data-title="На сумму">239 724,05</div>
|
||
<div className="table_cell" data-title="НДС, 20% ₽">43 079,18</div>
|
||
<div className="table_cell"><span>Переплата</span> <span>15 000,00 ₽</span></div>
|
||
<div className="table_cell">№18432 от 20/01/2021 на сумму 255 000,00 ₽</div>
|
||
|
||
<button className="toggle_cell"></button>
|
||
</div>
|
||
<div className="table_row opened" data-status="overpayment-1">
|
||
<div className="table_cell" data-title="Платеж №">12</div>
|
||
<div className="table_cell" data-title="от">21.02.2021</div>
|
||
<div className="table_cell" data-title="На сумму">239 724,05</div>
|
||
<div className="table_cell" data-title="НДС, 20% ₽">43 079,18</div>
|
||
<div className="table_cell">Переплата 10 000,00 ₽</div>
|
||
<div className="table_cell">№34223 от 21/02/2021 на сумму 229 724,05 ₽</div>
|
||
|
||
<button className="toggle_cell"></button>
|
||
</div>
|
||
<div className="table_row" data-status="paid">
|
||
<div className="table_cell" data-title="Платеж №">13</div>
|
||
<div className="table_cell" data-title="от">21.02.2021</div>
|
||
<div className="table_cell" data-title="На сумму">239 724,05</div>
|
||
<div className="table_cell" data-title="НДС, 20% ₽">43 079,18</div>
|
||
<div className="table_cell">Оплачено </div>
|
||
<div className="table_cell">№44911 от 10/03/2021 на сумму 100 000,00 ₽
|
||
№49877 от 21/03/2021 на сумму 139 724,05 ₽</div>
|
||
|
||
<button className="toggle_cell"></button>
|
||
</div>
|
||
<div className="table_row">
|
||
<div className="table_cell" data-title="Платеж №">14</div>
|
||
<div className="table_cell" data-title="от">21.02.2021</div>
|
||
<div className="table_cell" data-title="На сумму">239 724,05</div>
|
||
<div className="table_cell" data-title="НДС, 20% ₽">43 079,18</div>
|
||
<div className="table_cell">Не оплачено </div>
|
||
<div className="table_cell">-</div>
|
||
|
||
<button className="toggle_cell"></button>
|
||
</div>
|
||
{*/}
|
||
</>
|
||
) }
|
||
</div>
|
||
</article>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
<Footer/>
|
||
</React.Fragment>
|
||
);
|
||
}
|
||
}
|
||
|
||
function mapStateToProps(state, ownProps)
|
||
{
|
||
return {
|
||
company: state.company,
|
||
payments: state.contract.payments,
|
||
contract_date: state.contract.date,
|
||
//schedule: state.payments,
|
||
}
|
||
}
|
||
|
||
export const getServerSideProps = reduxWrapper.getServerSideProps(store =>
|
||
async ({ req, res, query }) =>
|
||
{
|
||
return {
|
||
props: {
|
||
number: query.number,
|
||
}
|
||
}
|
||
}
|
||
);
|
||
|
||
export default withRouter(connect(mapStateToProps)(ContractSchedulePage));
|