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 numeral from "numeral"; import moment from "moment"; 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, getContractDebtInvoiceFile, getContractInfo, getContractPenaltyInvoiceFile } from './../../actions'; import AccountLayout from "../components/Layout/Account"; class ContractSchedulePage extends React.Component { constructor(props) { super(props); this.state = { loading: false, payments: null, avans: null, debt: null, penalty: null, date: null, car: null, full: false, opened: [], debt_invoice_file_loading: false, penalty_invoice_file_loading: false, } } static getDerivedStateFromProps(nextProps, prevState) { return { date: nextProps.date, car: nextProps.car, payments: nextProps.payments, avans: nextProps.avans, debt: nextProps.debt, penalty: nextProps.penalty, }; } componentDidMount() { if(!this.state.loading && this.props.number !== undefined) { 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(() => {}); }); } } _getLastPayDate = () => { let last = null; const { payments } = this.state; for(let i in payments) { if(payments[i].status === "Paid") { last = moment(payments[i].date, "DD-MM-YYYY"); } } return last; } _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 }); } _handle_onDownloadDebtFile = () => { const { number } = this.props; if(!this.state.debt_invoice_file_loading) { this.setState({ debt_invoice_file_loading: true }, () => { getContractDebtInvoiceFile({ contract: number }) .then(() => { this.setState({ debt_invoice_file_loading: false }); }) .catch(() => { this.setState({ debt_invoice_file_loading: false }); }); }); } } _handle_onDownloadPenaltyFile = () => { const { number } = this.props; if(!this.state.penalty_invoice_file_loading) { this.setState({ penalty_invoice_file_loading: true }, () => { getContractPenaltyInvoiceFile({ contract: number }) .then(() => { this.setState({ penalty_invoice_file_loading: false }); }) .catch(() => { this.setState({ penalty_invoice_file_loading: false }); }); }); } } _handle_onCalculatePenalty = () => { const { number } = this.props; this.props.router.push(`/contract/${ number }/documents#penalties`); } render() { const { payments, avans, debt, penalty, date, car, full, opened, loading, debt_invoice_file_loading, penalty_invoice_file_loading } = this.state; const { number } = this.props; console.log(".".repeat(50)); console.log("this.state", this.state); console.log("this.props", this.props); console.log(".".repeat(50)); console.log("RENDER", "payments"); console.log(payments); console.log("avans", avans); const statuses = { "NotPaid": "", "HalfPaid": "overpayment-1", "OverPaid": "overpayment-2", "Paid": "paid", }; let today = moment(); let last_pay_date = this._getLastPayDate(); return ( ЛК Эволюция автолизинга

Договор №{ number }

{ date !== undefined && date !== null && date !== null && (<> от { moment(date).format("DD.MM.YYYY") })}{ car !== undefined && car !== null ? ` - ${ car.brand.name } ${ car.model.name } | ${ car.reg_number !== null ? car.reg_number : 'без рег. номера' } | ${ car.vin_number !== null ? car.vin_number : 'без VIN номера' }` : '' }

{ parseInt(avans, 10) > 0 && (

Сумма авансовых поступлений по договору: { numeral(avans).format(' ., ') } ₽

) } {/* Вариант 1 */}
{ parseInt(debt, 10) > 0 && (

Счёт на основной долг: { numeral(debt).format(' ., ') } ₽

) } { parseInt(penalty, 10) > 0 && (

Пени: { numeral(penalty).format(' ., ') } ₽

) }
№ платежа
Дата лизингового платежа
Лизинговый платеж с НДС ₽
НДС, 20% ₽
Статус платежа
Платежное поручение
{ loading ? (
) : ( <> { !full && ( ) } { payments !== undefined && payments !== null && Object.values(payments).map((payment, index) => { let pd = moment(payment.date, "DD-MM-YYYY"); if(!full && pd < last_pay_date) { return null; } return (
-1 ? "opened" : "" }` } data-status={ payment.status === "NotPaid" && pd < today ? "notpaid" : statuses[payment.status] } key={ index } onClick={ () => this._handle_onSetOpen(payment.number) }>
{ payment.number }
{ moment(payment.date, "DD-MM-YYYY").format("DD.MM.YYYY") }
{ numeral(payment.total_amount).format(' ., ') } ₽
{ numeral(payment.vat_amount).format(' ., ') } ₽
{ payment.status === "Paid" && "Оплачено" } { payment.status === "NotPaid" && "Не оплачено" } { payment.status === "HalfPaid" && ( <>Недоплата
{ numeral(payment.total_amount - payment.paid_amount).format(' ., ') } ₽ ) } { payment.status === "OverPaid" && ( <>Переплата { numeral(payment.total_amount).format(' ., ') } ₽ ) }
{ payment.invoices !== undefined && payment.invoices.map((invoice, invoice_index) => (

№{ invoice.number } от { moment(invoice.date, "DD-MM-YYYY").format("DD.MM.YYYY") } на сумму { numeral(invoice.total_amount).format(' ., ') } ₽

)) }
) }) } {/*}
11
21.02.2021
239 724,05
43 079,18
Переплата 15 000,00 ₽
№18432 от 20/01/2021 на сумму 255 000,00 ₽
12
21.02.2021
239 724,05
43 079,18
Переплата 10 000,00 ₽
№34223 от 21/02/2021 на сумму 229 724,05 ₽
13
21.02.2021
239 724,05
43 079,18
Оплачено
№44911 от 10/03/2021 на сумму 100 000,00 ₽ №49877 от 21/03/2021 на сумму 139 724,05 ₽
14
21.02.2021
239 724,05
43 079,18
Не оплачено
-
{*/} ) }