2023-06-22 05:49:35 +00:00
|
|
|
const print = require('vn-print');
|
|
|
|
|
2019-03-28 10:55:23 +00:00
|
|
|
module.exports = Self => {
|
2019-04-25 06:28:08 +00:00
|
|
|
require('../methods/invoiceOut/filter')(Self);
|
2019-03-28 10:55:23 +00:00
|
|
|
require('../methods/invoiceOut/summary')(Self);
|
2021-06-14 09:38:57 +00:00
|
|
|
require('../methods/invoiceOut/getTickets')(Self);
|
2019-03-28 10:55:23 +00:00
|
|
|
require('../methods/invoiceOut/download')(Self);
|
2022-10-24 12:20:09 +00:00
|
|
|
require('../methods/invoiceOut/downloadZip')(Self);
|
2019-04-26 10:05:49 +00:00
|
|
|
require('../methods/invoiceOut/delete')(Self);
|
2019-04-30 09:03:48 +00:00
|
|
|
require('../methods/invoiceOut/book')(Self);
|
2021-03-11 07:58:34 +00:00
|
|
|
require('../methods/invoiceOut/createPdf')(Self);
|
2021-07-27 07:07:04 +00:00
|
|
|
require('../methods/invoiceOut/createManualInvoice')(Self);
|
2022-10-26 08:36:41 +00:00
|
|
|
require('../methods/invoiceOut/clientsToInvoice')(Self);
|
2022-10-20 05:23:57 +00:00
|
|
|
require('../methods/invoiceOut/invoiceClient')(Self);
|
2022-07-14 11:40:50 +00:00
|
|
|
require('../methods/invoiceOut/refund')(Self);
|
2022-09-26 11:33:27 +00:00
|
|
|
require('../methods/invoiceOut/invoiceEmail')(Self);
|
|
|
|
require('../methods/invoiceOut/exportationPdf')(Self);
|
2022-10-03 06:28:47 +00:00
|
|
|
require('../methods/invoiceOut/invoiceCsv')(Self);
|
|
|
|
require('../methods/invoiceOut/invoiceCsvEmail')(Self);
|
2023-01-26 12:49:09 +00:00
|
|
|
require('../methods/invoiceOut/invoiceOutPdf')(Self);
|
2023-02-23 08:25:23 +00:00
|
|
|
require('../methods/invoiceOut/getInvoiceDate')(Self);
|
2023-04-21 06:20:38 +00:00
|
|
|
require('../methods/invoiceOut/negativeBases')(Self);
|
|
|
|
require('../methods/invoiceOut/negativeBasesCsv')(Self);
|
2023-06-22 05:49:35 +00:00
|
|
|
|
|
|
|
Self.makePdf = async function(id, options) {
|
2023-06-22 06:50:18 +00:00
|
|
|
let tx;
|
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
2023-06-22 05:49:35 +00:00
|
|
|
|
2023-06-22 06:50:18 +00:00
|
|
|
if (!myOptions.transaction) {
|
|
|
|
tx = await Self.beginTransaction({});
|
|
|
|
myOptions.transaction = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fields = ['id', 'hasPdf', 'ref', 'issued'];
|
|
|
|
const invoiceOut = await Self.findById(id, {fields}, myOptions);
|
2023-06-22 05:49:35 +00:00
|
|
|
const invoiceReport = new print.Report('invoice', {
|
|
|
|
reference: invoiceOut.ref
|
|
|
|
});
|
|
|
|
const buffer = await invoiceReport.toPdfStream();
|
|
|
|
|
|
|
|
const issued = invoiceOut.issued;
|
|
|
|
const year = issued.getFullYear().toString();
|
|
|
|
const month = (issued.getMonth() + 1).toString();
|
|
|
|
const day = issued.getDate().toString();
|
|
|
|
|
|
|
|
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
|
|
|
|
|
|
|
// Store invoice
|
|
|
|
|
|
|
|
await invoiceOut.updateAttributes({
|
|
|
|
hasPdf: true
|
2023-06-22 06:50:18 +00:00
|
|
|
}, myOptions);
|
2023-06-22 05:49:35 +00:00
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
await print.storage.write(buffer, {
|
|
|
|
type: 'invoice',
|
|
|
|
path: `${year}/${month}/${day}`,
|
|
|
|
fileName: fileName
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-03-28 10:55:23 +00:00
|
|
|
};
|