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 numeral from "numeral"; import { SpinnerCircular } from "spinners-react"; import pluralize from "pluralize-ru"; 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 DownloadFinesPdfButton from "../components/DownloadFinesPdfButton"; import { getContractInfo, getContractDocuments, getReconciliationFile, } from "../../actions"; const TYPES = { upd: "УПД по очередным платежам", upd_avans: "УПД по авансовым платежам", billfines: "Счета-уведомления на пени", billgibdd: "BillGIBDD", fines: "Штрафы ГИБДД", }; class ContractDocumentsPage extends React.Component { constructor(props) { super(props); this.state = { opened: [], date: null, car: null, contract_date: null, documents: null, loading: false, valid_date_start: null, valid_date_end: null, period_date_start: null, period_date_end: null, reconciliation_requested: false, reconciliation_disabled: false, }; } static getDerivedStateFromProps(nextProps, prevState) { return { date: nextProps.date, car: nextProps.car, contract_date: nextProps.contract_date, documents: nextProps.documents, }; } componentDidMount() { if (!this.state.loading && this.props.number !== undefined) { const de = moment().toDate(); this.setState( { loading: true, period_date_end: de, valid_date_end: de }, () => { 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 ) { const ds = moment(this.state.contract_date).toDate(); this.setState({ period_date_start: ds, valid_date_start: ds }); } } } _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) => { const { valid_date_start, valid_date_end, period_date_start, period_date_end, } = this.state; const md = moment(date, "DD.MM.YYYY"); if (md.isValid()) { if (date >= valid_date_start && date <= valid_date_end) { if (date < period_date_end) { this.setState({ period_date_start: date, reconciliation_disabled: false, }); } else { this.setState({ period_date_start: date, reconciliation_disabled: true, }); } } else { this.setState({ period_date_start: date, reconciliation_disabled: true, }); } } else { this.setState({ reconciliation_disabled: true }); } }; _handle_onPeriodDate_end = (date) => { console.log("_handle_onPeriodDate_end", "date", date); const { valid_date_start, valid_date_end, period_date_start, period_date_end, } = this.state; if (moment(date).isValid()) { if (date >= valid_date_start && date <= valid_date_end) { if (date > period_date_start) { this.setState({ period_date_end: date, reconciliation_disabled: false, }); } else { this.setState({ period_date_end: date, reconciliation_disabled: true, }); } } else { this.setState({ period_date_end: date, reconciliation_disabled: true }); } } else { this.setState({ reconciliation_disabled: true }); } }; _handle_onGroup = (group) => { console.log("group", group); const opened = [...this.state.opened]; if (opened.indexOf(group) < 0) { opened.push(group); } else { opened.splice(opened.indexOf(group), 1); } this.setState({ opened: opened }); }; _renderDocuments = (documents, type) => { const { number } = this.props; const { opened } = this.state; if (documents !== undefined && documents !== null) { if (documents.length > 0) { return ( <>
-1 ? "open" : "" }`} >

{TYPES[type]}

{documents .slice(0, opened.indexOf(type) > -1 ? documents.length : 3) .map((doc, index) => { console.log("doc", doc); return (

{doc.num} от {moment(doc.date).format("DD.MM.YYYY")}

); })} {opened.indexOf(type) < 0 && documents.length > 3 && (
this._handle_onGroup(type)} >

Еще {documents.length - 3}{" "} {pluralize( documents.length - 3, "документов", "документ", "документа", "документов" )}

)}
); } if (type !== "upd_avans" && type !== "billfines") { return ( <>
-1 ? "open" : "" }`} >

{TYPES[type]}

Документов пока еще нет.

 

); } } return null; }; _renderFines = (fines, type) => { console.log("_renderFines"); console.log("fines"); console.log(fines); const { number } = this.props; const { opened } = this.state; const status = { NotPaid: "danger", PaidEvolution: "success", PaidIndependently: "success", }; if (fines.length > 0) { return ( <>
-1 ? "open" : "" }`} >

{TYPES["fines"]}

{fines .slice(0, opened.indexOf("fines") > -1 ? fines.length : 3) .map((fine, fine_index) => (

№ постановления: {fine.fine_number}

  • Дата нарушения:{" "} {moment(fine.violation_date).format("DD.MM.YYYY")}
  • {fine.violation_place !== undefined && fine.violation_place !== null && (
  • Место нарушения: {fine.violation_place}
  • )}
  • Сумма:{" "} {numeral(fine.amount).format(" ., ")} ₽
  • {fine.gibdd !== undefined && fine.gibdd !== null && (
  • Подразделение: {fine.gibdd}
  • )}
  • Статус:{" "} {fine.status}

Штраф: {fine.fine_title}

{fine.status_code !== "PaidIndependently" && (

Счет на оплату

)}
{/*} {*/}
))} {opened.indexOf(type) < 0 && fines.length > 3 && (
this._handle_onGroup(type)} >

Еще {fines.length - 3}{" "} {pluralize( fines.length - 3, "постановлений", "постановление", "постановления", "постановлений" )}

)}
); } return ( <>
-1 ? "open" : "" }`} >
this._handle_onGroup(type)} >

{TYPES[type]}

Штрафов не найдено.

 

); }; render() { const { loading, date, car, contract_date, documents, period_date_start, period_date_end, valid_date_start, valid_date_end, reconciliation_requested, reconciliation_disabled, opened, } = this.state; const { number } = this.props; console.log("documentsdocumentsdocumentsdocumentsdocuments"); console.log(documents); console.log("opened"); console.log(opened); 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 номера" }` : ""}
{loading ? (
) : ( <>

Акт сверки

{documents !== undefined && documents !== null ? ( <> {this._renderDocuments(documents.upd, "upd")} {this._renderDocuments( documents.upd_avans, "upd_avans" )} {this._renderDocuments( documents.billfines, "billfines" )} {this._renderFines(documents.fines, "fines")} ) : null}

Счета-уведомления на пени

Введите планируемую дату оплаты просроченной задолженности для расчёта пеней

)}