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 { downloadInvoiceFile, getContract, getContractDebtInvoiceFile, getContractInfo, getContractInvoices, getContractPenaltyInvoiceFile, signGetGUIDEntity, signGetWMDoc } from './../../actions'; import AccountLayout from "../components/Layout/Account"; import ContractHeader from "./components/ContractHeader"; class Invoice extends React.Component { constructor(props) { super(props); this.state = { loading: false, } } _handle_downloadFile = () => { const { group, contract_number } = this.props; this.setState({ loading: true }, async () => { switch(group.type) { case "kaskoProlong": { } break; case "fingapProlong": { } break; default: { const guid_result = await signGetGUIDEntity({ contract_number }); console.log({ guid_result, code: group.code }); await downloadInvoiceFile({ payload: { entity_id: guid_result.entityid, code: group.code }, filename: `ЛК Эволюция - договор ${ contract_number } - ${ group.title }.pdf` }); } break; } this.setState({ loading: false }); }); } render() { const { group, invoices } = this.props; const { loading } = this.state; console.log({ invoices }, group.type) if(invoices[group.type]) { return (

{ group.title }

PDF
{ loading ? ( ) : ( ) }
) } return null; } } class ContractSchedulePage extends React.Component { constructor(props) { super(props); this.state = { loading: false, contracts_info: {}, payments: null, avans: null, debt: null, penalty: null, invoices: {}, full: false, opened: [], debt_invoice_file_loading: false, penalty_invoice_file_loading: false, } } static getDerivedStateFromProps(nextProps, prevState) { return { contracts_info: nextProps.contracts_info, payments: nextProps.payments, avans: nextProps.avans, debt: nextProps.debt, penalty: nextProps.penalty, invoices: nextProps.invoices, }; } componentDidMount() { //console.log("ContractSchedulePage", "this.state", this.state); const { dispatch, number } = this.props; if(!this.state.loading && number !== undefined) { this.setState({ loading: true }, () => { if(this.state.contracts_info[ number ] === undefined) { getContractInfo({ dispatch, number }); } getContract({ dispatch, number }) .then(() => { this.setState({ loading: false }); }) .catch(() => {}); getContractInvoices({ dispatch, number, }) .then(() => { }) .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 { number } = this.props; const { loading, contracts_info, payments, avans, debt, penalty, full, opened, debt_invoice_file_loading, penalty_invoice_file_loading, invoices, } = this.state; let { date, car, status } = contracts_info[ number ] !== undefined ? contracts_info[ number ] : {}; //console.log("RENDER", "payments"); //console.log(payments); //console.log("avans", avans); const invoice_types = [ { type: "firstPayment", title: "Счет на аванс", code: "Invoice_Payment", }, { type: "nextPayment", title: "Счет на очередной платеж", code: "InvoicePlanPayment_attach", }, { type: "osagoInvoice", title: "Счет ОСАГО", code: "OSAGO_Pay_contract", }, { type: "kaskoInvoice", title: "Счет КАСКО", code: "KASKO_Pay_contract", }, { type: "kaskoProlong", title: "Счет на пролонгацию КАСКО", }, { type: "fingapInvoice", title: "Счет EvoSafeFinance", code: "Fingap_Pay_contract", }, { type: "fingapProlong", title: "Счет на пролонгацию EvoSafeFinance", }, ]; const statuses = { "NotPaid": "", "HalfPaid": "overpayment-1", "OverPaid": "overpayment-2", "Paid": "paid", }; let today = moment(); let last_pay_date = this._getLastPayDate(); return ( ЛК Эволюция автолизинга
{ parseInt(avans, 10) > 0 && (

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

) } { invoices[number] !== undefined && (

Подготовленные счета

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

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

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

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

) }
{ invoices[number] !== undefined && invoice_types.map((group, index) => ( )) }

График платежей

№ платежа
Дата лизингового платежа
Лизинговый платеж с НДС ₽
НДС, 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
Не оплачено
-
{*/} ) }