download PDF for contract change graphic
This commit is contained in:
parent
a53600fb85
commit
644ea3877b
@ -188,23 +188,6 @@ export const getBitrixFile = ({ url, filename }) =>
|
||||
|
||||
reject();
|
||||
});
|
||||
|
||||
/*
|
||||
axios.get(`${ url }`, {
|
||||
responseType: 'blob',
|
||||
})
|
||||
.then((response) =>
|
||||
{
|
||||
fileDownload(response.data, filename);
|
||||
resolve();
|
||||
})
|
||||
.catch((error) =>
|
||||
{
|
||||
console.log("error");
|
||||
console.error(error);
|
||||
reject();
|
||||
});
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
@ -253,6 +236,31 @@ export const getContractPenaltyInvoiceFile = ({ contract }) =>
|
||||
console.error("getContractPenaltyInvoiceFile", "error");
|
||||
console.error(error);
|
||||
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const getContractCalculationPDFFile = ({ calculation }) =>
|
||||
{
|
||||
console.log("ACTION", "getContractCalculationPDFFile", { calculation });
|
||||
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
axios.get(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/file/contract/graphic`, {
|
||||
params: { calculation },
|
||||
responseType: 'blob',
|
||||
})
|
||||
.then((response) =>
|
||||
{
|
||||
fileDownload(response.data, Buffer.from(response.headers.filename, 'base64'));
|
||||
resolve();
|
||||
})
|
||||
.catch((error) =>
|
||||
{
|
||||
console.error("getContractCalculationPDFFile", "error");
|
||||
console.error(error);
|
||||
|
||||
reject();
|
||||
});
|
||||
});
|
||||
|
||||
@ -18,7 +18,6 @@ export default async function handler(req, res)
|
||||
{
|
||||
if(jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT))
|
||||
{
|
||||
console.log("req.query.urlreq.query.urlreq.query.urlreq.query.urlreq.query.url", req.query.url);
|
||||
try
|
||||
{
|
||||
axios.get(req.query.url, {
|
||||
|
||||
58
pages/api/file/contract/graphic.js
Normal file
58
pages/api/file/contract/graphic.js
Normal file
@ -0,0 +1,58 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import axios from 'axios';
|
||||
import { Cookies } from 'react-cookie';
|
||||
import cookie from 'cookie';
|
||||
import moment from 'moment';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { cors } from '../../../../lib/cors';
|
||||
|
||||
export default async function handler(req, res)
|
||||
{
|
||||
await cors(req, res);
|
||||
|
||||
console.log("API", "file", "contract", "graphic");
|
||||
console.log(req.query);
|
||||
console.log("-".repeat(50));
|
||||
|
||||
if(req.headers.cookie !== undefined)
|
||||
{
|
||||
const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : "");
|
||||
|
||||
if(cookies.jwt !== undefined && cookies.jwt !== null)
|
||||
{
|
||||
var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT);
|
||||
var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true });
|
||||
|
||||
try
|
||||
{
|
||||
axios.get(`${ process.env.CRM_API_HOST }/lk/add-contract/GetPreCalculationGraphPrintForm`, {
|
||||
params: { addcontract_number: req.query.calculation },
|
||||
headers: {
|
||||
"Authorization": `Bearer ${ crm_jwt }`,
|
||||
}
|
||||
})
|
||||
.then((crm_response) =>
|
||||
{
|
||||
console.log("API", "/file/contract/graphic", "crm_response.data");
|
||||
|
||||
res.setHeader("filename", Buffer.from(crm_response.data.key).toString('base64'));
|
||||
res.status(200).send(Buffer.from(crm_response.data.value, 'base64'));
|
||||
})
|
||||
.catch((error) =>
|
||||
{
|
||||
console.error(error);
|
||||
res.status(500);
|
||||
});
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.error(e);
|
||||
res.status(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.status(403);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,6 +125,7 @@ export default class Comparison extends React.Component
|
||||
console.log(this.props);
|
||||
console.log("this.state");
|
||||
console.log(this.state);
|
||||
this.props.onDownloadPDF(0);
|
||||
}
|
||||
|
||||
_renderMixedPayments = () =>
|
||||
@ -226,16 +227,16 @@ export default class Comparison extends React.Component
|
||||
render()
|
||||
{
|
||||
const { calculation, mixed_index, today, show_previous, signatories_show_all } = this.state;
|
||||
const { number, signer, signatories, current, calculated } = this.props;
|
||||
const { number, signer, signatories, current, calculated, loading_pdf } = this.props;
|
||||
|
||||
return (
|
||||
<article className="compare">
|
||||
<div className="compare_top">
|
||||
<p>Выбранный(ые) варианты изменения графика</p>
|
||||
<a className="interactive" onClick={ this._handle_onOptions }>Вернуться к параметрам изменения графика</a>
|
||||
{/*}
|
||||
<button className="button button-blue" onClick={ this._handle_onDownloadPDF }>Скачать PDF</button>
|
||||
{*/}
|
||||
<button className="button button-blue" onClick={ this._handle_onDownloadPDF } style={{ minWidth: 112 }}>{ loading_pdf ? (
|
||||
<SpinnerCircular size={24} thickness={100} speed={100} color="rgba(255, 255, 255, 1)" secondaryColor="rgba(255, 255, 255, 0.5)" style={{ marginTop: "0px" }}/>
|
||||
) : "Скачать PDF" }</button>
|
||||
</div>
|
||||
<div className="compare_data">
|
||||
{ calculation !== undefined && calculation !== null && calculation.fix_last_payment_available_comment !== null && (
|
||||
|
||||
@ -29,7 +29,8 @@ import {
|
||||
getContractGraphicChangeGetCalculated,
|
||||
getContractGraphicChangeSignatories,
|
||||
getContractGraphicChangeCalculationsList,
|
||||
signContractGraphicChange,
|
||||
signContractGraphicChange,
|
||||
getContractCalculationPDFFile,
|
||||
} from "../../../actions";
|
||||
import Options from "./components/Options";
|
||||
import Comparison from "./components/Comparison";
|
||||
@ -43,6 +44,7 @@ class ChangeGraphicPage extends React.Component
|
||||
super(props);
|
||||
this.state = {
|
||||
loading: false,
|
||||
loading_pdf: false,
|
||||
contracts_info: {},
|
||||
mode_options: false,
|
||||
mode_comparison: false,
|
||||
@ -233,6 +235,27 @@ class ChangeGraphicPage extends React.Component
|
||||
});
|
||||
}
|
||||
|
||||
_handle_onDownloadPDF = () =>
|
||||
{
|
||||
const { calculation_id, } = this.state;
|
||||
|
||||
this.setState({ loading_pdf: true, }, () =>
|
||||
{
|
||||
getContractCalculationPDFFile({ calculation: calculation_id, })
|
||||
.then(() =>
|
||||
{
|
||||
this.setState({ loading_pdf: false, });
|
||||
})
|
||||
.catch(() =>
|
||||
{
|
||||
this.setState({ loading_pdf: false, }, () =>
|
||||
{
|
||||
alert("К сожалению, при создании файла PDF расчёта возникла ошибка.\n\nПожалуйста, попробуйте позднее или воспользуйтесь графиком ниже.");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_handle_onCalculate = (calculation_id) =>
|
||||
{
|
||||
const { dispatch, number } = this.props;
|
||||
@ -270,7 +293,7 @@ class ChangeGraphicPage extends React.Component
|
||||
render()
|
||||
{
|
||||
const { number } = this.props;
|
||||
const { loading, contracts_info, mode_options, mode_comparison, mode_calculation, mode_final, signer, signatories, calculations, calculation_id, editable, variants, variants_loading, variants_selected, variants_types, variants_unavailable, options, current, calculated, comment } = this.state;
|
||||
const { loading, loading_pdf, contracts_info, mode_options, mode_comparison, mode_calculation, mode_final, signer, signatories, calculations, calculation_id, editable, variants, variants_loading, variants_selected, variants_types, variants_unavailable, options, current, calculated, comment } = this.state;
|
||||
|
||||
let { date, car, status } = contracts_info[ number ] !== undefined ? contracts_info[ number ] : {};
|
||||
|
||||
@ -310,6 +333,7 @@ class ChangeGraphicPage extends React.Component
|
||||
) : (
|
||||
<div className="aside_container about">
|
||||
<Comparison
|
||||
loading_pdf={ loading_pdf }
|
||||
signer={ signer }
|
||||
signatories={ signatories }
|
||||
calculations={ calculations }
|
||||
@ -321,6 +345,7 @@ class ChangeGraphicPage extends React.Component
|
||||
onOptions={ this._handle_onOptions }
|
||||
onSigner={ this._handle_onSigner }
|
||||
onSign={ this._handle_onSign }
|
||||
onDownloadPDF={ this._handle_onDownloadPDF }
|
||||
/>
|
||||
</div>
|
||||
) }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user