From 664b2f15311c5542e98d8df8076920922f296d0a Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 23 Jan 2019 09:33:58 +0100 Subject: [PATCH] Printer: PDF stream attachments #1001 --- .gitignore | 1 + print/lib/config.js | 2 +- print/lib/emailEngine.js | 47 +++++++++--------- print/lib/errorHandler.js | 21 -------- print/lib/reportEngine.js | 22 +++++--- print/reports/delivery-note/index.js | 1 - print/reports/email-footer/index.js | 10 ++-- print/reports/email-header/index.js | 10 ++-- .../letter-debtor-nd/assets/files/model.ezp | Bin 9845 -> 0 bytes .../letter-debtor-nd/assets/files/model2.ezp | Bin 9845 -> 0 bytes print/reports/letter-debtor-nd/index.js | 3 ++ .../letter-debtor-st/assets/files/model.ezp | Bin 9845 -> 0 bytes .../letter-debtor-st/assets/files/model2.ezp | Bin 9845 -> 0 bytes print/reports/letter-debtor-st/index.js | 28 ++++++----- print/reports/printer-setup/index.js | 2 +- print/server.js | 8 +-- 16 files changed, 72 insertions(+), 83 deletions(-) delete mode 100644 print/lib/errorHandler.js delete mode 100755 print/reports/letter-debtor-nd/assets/files/model.ezp delete mode 100755 print/reports/letter-debtor-nd/assets/files/model2.ezp delete mode 100755 print/reports/letter-debtor-st/assets/files/model.ezp delete mode 100755 print/reports/letter-debtor-st/assets/files/model2.ezp diff --git a/.gitignore b/.gitignore index 9a4c04b95..50d3f3f91 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ dist/* npm-debug.log .eslintcache datasources.*.json +print.*.json db.json \ No newline at end of file diff --git a/print/lib/config.js b/print/lib/config.js index c14538f3e..47e58ec77 100644 --- a/print/lib/config.js +++ b/print/lib/config.js @@ -4,6 +4,7 @@ let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; let configPath = `/etc/salix`; let config = require('../config/print.json'); let configFiles = [ + `${appPath}/config/print.${env}.json`, `${configPath}/print.json`, `${configPath}/print.${env}.json` ]; @@ -28,5 +29,4 @@ for (let proxyFile of proxyFiles) { // config.proxy = proxyConf; config.env = env; - module.exports = config; diff --git a/print/lib/emailEngine.js b/print/lib/emailEngine.js index 0ae947137..cf4eceba1 100644 --- a/print/lib/emailEngine.js +++ b/print/lib/emailEngine.js @@ -47,9 +47,10 @@ module.exports = { * @param {Object} ctx - Request context */ async preFetch(component, ctx) { - const preFetchData = {attachments: []}; - let params = {}; + let mergedData = {attachments: []}; + let asyncData = {}; let data = {}; + let params = {}; if (Object.keys(ctx.body).length > 0) params = ctx.body; @@ -63,36 +64,34 @@ module.exports = { data = component.data(); if (component.hasOwnProperty('asyncData')) { - const asyncData = await component.asyncData(ctx, params); + asyncData = await component.asyncData(ctx, params); if (asyncData.locale) { const locale = component.i18n.messages[asyncData.locale]; - preFetchData.subject = locale.subject; + mergedData.subject = locale.subject; } - - if (asyncData.recipient) - preFetchData.recipient = asyncData.recipient; - - const mergedData = {...data, ...asyncData}; - component.data = function data() { - return mergedData; - }; } - if (data && data.hasOwnProperty('attachments')) { - const fileNames = data.attachments; - fileNames.forEach(attachment => { + mergedData = Object.assign(mergedData, data, asyncData); + + component.data = function data() { + return mergedData; + }; + + if (data.hasOwnProperty('files')) { + const files = data.files; + files.forEach(file => { const componentPath = `${this.path}/${component.name}`; - let fileSrc = componentPath + attachment; + let fileSrc = componentPath + file; - if (attachment.slice(0, 4) === 'http' || attachment.slice(0, 4) === 'https') - fileSrc = attachment; + if (file.slice(0, 4) === 'http' || file.slice(0, 4) === 'https') + fileSrc = file; - const fileName = attachment.split('/').pop(); - preFetchData.attachments.push({ + const fileName = file.split('/').pop(); + mergedData.attachments.push({ filename: fileName, path: fileSrc, - cid: attachment, + cid: file, }); }); } @@ -108,14 +107,14 @@ module.exports = { return Promise.all(promises).then(results => { results.forEach(result => { result.attachments.forEach(atth => { - preFetchData.attachments.push(atth); + mergedData.attachments.push(atth); }); }); - return preFetchData; + return mergedData; }); } - return preFetchData; + return mergedData; }, async attachAssets(component) { diff --git a/print/lib/errorHandler.js b/print/lib/errorHandler.js deleted file mode 100644 index ec9bc98c2..000000000 --- a/print/lib/errorHandler.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = app => { - process.on('uncaughtException', err => { - console.error(`Caught exception: ${err}`); - }); - - process.on('warning', () => { - console.error(`My warning err`); - }); - - app.use(function(error, request, response, next) { - if (!error.httpStatusCode) - return next(error); - - response.status(error.httpStatusCode); - response.json({ - httpStatusCode: error.httpStatusCode, - name: error.name, - message: error.message, - }); - }); -}; diff --git a/print/lib/reportEngine.js b/print/lib/reportEngine.js index 23b1e199e..0a818acd3 100644 --- a/print/lib/reportEngine.js +++ b/print/lib/reportEngine.js @@ -43,21 +43,29 @@ module.exports = { * @param {Object} ctx - Request context */ async preFetch(component, ctx) { + let mergedData = {}; + let asyncData = {}; let data = {}; + if (Object.keys(ctx.body).length > 0) + params = ctx.body; + + if (Object.keys(ctx.query).length > 0) + params = ctx.query; + await this.attachAssets(component); if (component.hasOwnProperty('data')) data = component.data(); - if (component.hasOwnProperty('asyncData')) { - const fetch = await component.asyncData(ctx, ctx.body); - const mergedData = {...data, ...fetch}; + if (component.hasOwnProperty('asyncData')) + asyncData = await component.asyncData(ctx, params); - component.data = function data() { - return mergedData; - }; - } + mergedData = Object.assign(mergedData, data, asyncData); + + component.data = function data() { + return mergedData; + }; if (component.components) { const components = component.components; diff --git a/print/reports/delivery-note/index.js b/print/reports/delivery-note/index.js index 07f77ffd0..34c80b1f8 100755 --- a/print/reports/delivery-note/index.js +++ b/print/reports/delivery-note/index.js @@ -4,7 +4,6 @@ const UserException = require(`${appPath}/lib/exceptions/userException`); module.exports = { name: 'delivery-note', async asyncData(ctx, params) { - console.log(params); const promises = []; const dataIndex = promises.push(this.methods.fetchData()) - 1; const itemsIndex = promises.push(this.methods.fetchItems()) - 1; diff --git a/print/reports/email-footer/index.js b/print/reports/email-footer/index.js index 07fc857dd..893e7276e 100755 --- a/print/reports/email-footer/index.js +++ b/print/reports/email-footer/index.js @@ -1,21 +1,21 @@ module.exports = { name: 'email-footer', - asyncData(ctx, params) { + asyncData(ctx) { return { isPreview: ctx.method === 'GET', }; }, created() { const embeded = []; - this.attachments.map((attachment) => { - const src = this.isPreview ? attachment : `cid:${attachment}`; - embeded[attachment] = src; + this.files.map(file => { + const src = this.isPreview ? file : `cid:${file}`; + embeded[file] = src; }); this.embeded = embeded; }, data() { return { - attachments: [ + files: [ '/assets/images/facebook.png', '/assets/images/twitter.png', '/assets/images/youtube.png', diff --git a/print/reports/email-header/index.js b/print/reports/email-header/index.js index 87b2d1aa9..93768e86f 100755 --- a/print/reports/email-header/index.js +++ b/print/reports/email-header/index.js @@ -1,22 +1,22 @@ module.exports = { name: 'email-header', - asyncData(ctx, params) { + asyncData(ctx) { return { isPreview: ctx.method === 'GET', }; }, created() { const embeded = []; - this.attachments.map((attachment) => { - const src = this.isPreview ? attachment : `cid:${attachment}`; - embeded[attachment] = src; + this.files.map(file => { + const src = this.isPreview ? file : `cid:${file}`; + embeded[file] = src; }); this.embeded = embeded; }, data() { return { - attachments: ['/assets/images/logo.png'], + files: ['/assets/images/logo.png'], }; }, }; diff --git a/print/reports/letter-debtor-nd/assets/files/model.ezp b/print/reports/letter-debtor-nd/assets/files/model.ezp deleted file mode 100755 index 297df3d214694a64f677aa40d7305ebddb368e28..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9845 zcmeHNe@s=^9sfSKh9||2*4nYk*jse!?10BFM@dJ#3i`0vpitY_kSLZ%eeHwygm-;t z-J%gKNm*tS(`n`!+ib0!u32a6m?If!OGe*lW?J2xVv8HiY(kr?-5+dg_xAbRdkGqLA|nOmjm%q3S;iwKVX~9rJ2ct`=DvXbk6pPdZ8X zCnhhSgbjR{ygPF9yt(<_ydqCtK}q4VlKf@TWXpXUTa~J5TOciFojwVSQ7C(5%OiWG z8@chxnakL`jt^LQ@fkWntLHflI=INIF?af-?ePV#r4-{iUjH~n3!q*MCi$yF;mvg+ zi=J%Ti0mqbi|YcvMHJ?H>ISP!HR$$6j0&`q$d<+yvD&de#U;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L>%&G<{rbQI7z)(o z`5%z*UTyBN+>tX2=5o6%HqS_Svf+~Q%F2qW>he769E0+S`i1F#YrUXN0OhlFWS+z=itNH7ir+hXkVE3nI7=e{Zb+5E60v?FU__Z>5F_Z?e25f zML>^tzr>C-I}?~d-;70^1e+`SVrsFbvoC_kch%>yFAA<>UrZv_boa$6^vCCJUKCz^ zUm*Rd&5KFI;@GW2;appHPx*S@5b=Moc<%jZ74Gr?wKy}RydRk7%=7Gf*bi|JTh`<^ O)c;>mciLg9iT)e;UnVyI diff --git a/print/reports/letter-debtor-nd/assets/files/model2.ezp b/print/reports/letter-debtor-nd/assets/files/model2.ezp deleted file mode 100755 index 297df3d214694a64f677aa40d7305ebddb368e28..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9845 zcmeHNe@s=^9sfSKh9||2*4nYk*jse!?10BFM@dJ#3i`0vpitY_kSLZ%eeHwygm-;t z-J%gKNm*tS(`n`!+ib0!u32a6m?If!OGe*lW?J2xVv8HiY(kr?-5+dg_xAbRdkGqLA|nOmjm%q3S;iwKVX~9rJ2ct`=DvXbk6pPdZ8X zCnhhSgbjR{ygPF9yt(<_ydqCtK}q4VlKf@TWXpXUTa~J5TOciFojwVSQ7C(5%OiWG z8@chxnakL`jt^LQ@fkWntLHflI=INIF?af-?ePV#r4-{iUjH~n3!q*MCi$yF;mvg+ zi=J%Ti0mqbi|YcvMHJ?H>ISP!HR$$6j0&`q$d<+yvD&de#U;s->TsPc!zET+##TT& zkx1~z92ac=N=N(GPtg9fXCE*^F$M|!R5b^iqJd^lbs%a)kjE|H6=KX^nB_J5?lOG2 z!6T>~S|KMaK;c*;e+_;(&S|goK$^fh^#}^f?IPcR0L^Ivb=sF2k_mj^ygS+VwoiWW zOs>{Bf1kFYCs(@-^oz*lFfe6vq1Oi74_rl#9#`WD;?FY`sT{`R+q7ZiAT|<5_ zt4cP#7B`0`c{?zX(tq!ho+tc+u#K2s@gGLp=&T;s`EV+KwvpK&=FO=*hr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nVyI diff --git a/print/reports/letter-debtor-nd/index.js b/print/reports/letter-debtor-nd/index.js index bcf788054..77eec9351 100755 --- a/print/reports/letter-debtor-nd/index.js +++ b/print/reports/letter-debtor-nd/index.js @@ -13,6 +13,9 @@ module.exports = { if (!params.clientFk) throw new UserException('No client id specified'); + if (!params.companyFk) + throw new UserException('No company id specified'); + return this.methods.fetchClientData(params.clientFk, params.companyFk) .then(([result]) => { return Object.assign(data, result[0]); diff --git a/print/reports/letter-debtor-st/assets/files/model.ezp b/print/reports/letter-debtor-st/assets/files/model.ezp deleted file mode 100755 index 297df3d214694a64f677aa40d7305ebddb368e28..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9845 zcmeHNe@s=^9sfSKh9||2*4nYk*jse!?10BFM@dJ#3i`0vpitY_kSLZ%eeHwygm-;t z-J%gKNm*tS(`n`!+ib0!u32a6m?If!OGe*lW?J2xVv8HiY(kr?-5+dg_xAbRdkGqLA|nOmjm%q3S;iwKVX~9rJ2ct`=DvXbk6pPdZ8X zCnhhSgbjR{ygPF9yt(<_ydqCtK}q4VlKf@TWXpXUTa~J5TOciFojwVSQ7C(5%OiWG z8@chxnakL`jt^LQ@fkWntLHflI=INIF?af-?ePV#r4-{iUjH~n3!q*MCi$yF;mvg+ zi=J%Ti0mqbi|YcvMHJ?H>ISP!HR$$6j0&`q$d<+yvD&de#U;s->TsPc!zET+##TT& zkx1~z92ac=N=N(GPtg9fXCE*^F$M|!R5b^iqJd^lbs%a)kjE|H6=KX^nB_J5?lOG2 z!6T>~S|KMaK;c*;e+_;(&S|goK$^fh^#}^f?IPcR0L^Ivb=sF2k_mj^ygS+VwoiWW zOs>{Bf1kFYCs(@-^oz*lFfe6vq1Oi74_rl#9#`WD;?FY`sT{`R+q7ZiAT|<5_ zt4cP#7B`0`c{?zX(tq!ho+tc+u#K2s@gGLp=&T;s`EV+KwvpK&=FO=*hrAthZ9q5bQF@KIPJIsw zeGzIQCq2SPuE)X4eMmQQAU^_{`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debtor-st/assets/files/model2.ezp deleted file mode 100755 index 297df3d214694a64f677aa40d7305ebddb368e28..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9845 zcmeHNe@s=^9sfSKh9||2*4nYk*jse!?10BFM@dJ#3i`0vpitY_kSLZ%eeHwygm-;t z-J%gKNm*tS(`n`!+ib0!u32a6m?If!OGe*lW?J2xVv8HiY(kr?-5+dg_xAbRdkGqLA|nOmjm%q3S;iwKVX~9rJ2ct`=DvXbk6pPdZ8X zCnhhSgbjR{ygPF9yt(<_ydqCtK}q4VlKf@TWXpXUTa~J5TOciFojwVSQ7C(5%OiWG z8@chxnakL`jt^LQ@fkWntLHflI=INIF?af-?ePV#r4-{iUjH~n3!q*MCi$yF;mvg+ zi=J%Ti0mqbi|YcvMHJ?H>ISP!HR$$6j0&`q$d<+yvD&de#U;s->TsPc!zET+##TT& zkx1~z92ac=N=N(GPtg9fXCE*^F$M|!R5b^iqJd^lbs%a)kjE|H6=KX^nB_J5?lOG2 z!6T>~S|KMaK;c*;e+_;(&S|goK$^fh^#}^f?IPcR0L^Ivb=sF2k_mj^ygS+VwoiWW zOs>{Bf1kFYCs(@-^oz*lFfe6vq1Oi74_rl#9#`WD;?FY`sT{`R+q7ZiAT|<5_ zt4cP#7B`0`c{?zX(tq!ho+tc+u#K2s@gGLp=&T;s`EV+KwvpK&=FO=*hrAthZ9q5bQF@KIPJIsw zeGzIQCq2SPuE)X4eMmQQAU^_{`pRa}7Tt`=dKY9L1mV|yKKkGyPb@5e%h1^aU#x47 zY?H@qds7Hr>BE+NH}kp6743{tBr%-f5jYsZKkw<^jxHx#&%uEhKhu^|Az=R{f{1#R@k#`rqe~FnN z@tzy4wS;quG;MA=kge5cB$9so*TvdTQ7CIe{lwRnYQ2!hf!{!hUcmbun0^ROUjxv~ z%E{3<2l>6NAPqME*z7krhnzCnzJBafztUqp6S~DHTuaOxK&$mOh`B|36>}kI=Q^SM zTu(t~aBZZ$fx`9~n-~3&w;wj{%-=*w6I7oKfqw+09K21(_L{QO z&+j$k(eD~NudhRL6ggPXV(PNKuV8EJC6v|g*KA9_gndSG3shRn{ZS$09PixMFi!zK zgZC;UlGA7P&*5qGS1e#bKAO547hZ!oySQ$7dm zd(=&7y^BKu|;!#@w53}Z5DDI22EY&@Xk{?no9jW(0l|{zYTOoHrfz5 z9e~Y)6)pK*>>X?IKCXG;tT`5_d*h2+V`?p-e-FwUX^=MP5!~jl$k2(>kysZ~d^wj- zjJ$5ln7y_>ea25(xts&9 zzt8RsHr0n?o|-^wbkg5^v{yxCyvQba@7owLk4cqiYPjYe&nkUwMP-FPt{=6pWbl}6DrOOK7;vT##@KD_b16O&?L0&P)d+}V2 zH`86eP9*VOjj9>8JxB{aWB#LNb5g$mPi62+*X5y5Fw(+ay%HvB2WOwtf$F#x@hD${^P@h<(oydM&cvC5eiZkL>%&G<{rbQI7z)(o z`5%z*UTyBN+>tX2=5o6%HqS_Svf+~Q%F2qW>he769E0+S`i1F#YrUXN0OhlFWS+z=itNH7ir+hXkVE3nI7=e{Zb+5E60v?FU__Z>5F_Z?e25f zML>^tzr>C-I}?~d-;70^1e+`SVrsFbvoC_kch%>yFAA<>UrZv_boa$6^vCCJUKCz^ zUm*Rd&5KFI;@GW2;appHPx*S@5b=Moc<%jZ74Gr?wKy}RydRk7%=7Gf*bi|JTh`<^ O)c;>mciLg9iT)e;UnVyI diff --git a/print/reports/letter-debtor-st/index.js b/print/reports/letter-debtor-st/index.js index 7fb41092e..8fb51e408 100755 --- a/print/reports/letter-debtor-st/index.js +++ b/print/reports/letter-debtor-st/index.js @@ -1,11 +1,14 @@ const database = require(`${appPath}/lib/database`); +const reportEngine = require(`${appPath}/lib/reportEngine.js`); const emailHeader = require('../email-header'); const emailFooter = require('../email-footer'); const UserException = require(`${appPath}/lib/exceptions/userException`); + module.exports = { name: 'letter-debtor-st', async asyncData(ctx, params) { + const promises = []; const data = { isPreview: ctx.method === 'GET', }; @@ -16,23 +19,24 @@ module.exports = { if (!params.companyFk) throw new UserException('No company id specified'); - return this.methods.fetchClientData(params.clientFk, params.companyFk) - .then(([[result]]) => { - if (!result) throw new UserException('Client data not found'); + promises.push(reportEngine.toPdf('delivery-note', ctx)); + promises.push(this.methods.fetchClient(params.clientFk, params.companyFk)); - return Object.assign(data, result); - }); + return Promise.all(promises).then(result => { + const stream = result[0]; + const [[client]] = result[1]; + + Object.assign(data, client); + Object.assign(data, {attachments: [{filename: 'delivery-note.pdf', content: stream}]}); + + return data; + }); }, created() { this.$i18n.locale = this.locale; }, - data() { - return { - attachments: ['http://localhost:5000/report/delivery-note'], - }; - }, methods: { - fetchClientData(clientFk, companyFk) { + fetchClient(clientFk, companyFk) { return database.pool.query(` SELECT u.lang locale, @@ -47,7 +51,7 @@ module.exports = { JOIN bankEntity be ON be.id = sa.bankEntityFk JOIN account.user u ON u.id = c.id WHERE c.id = ? AND cny.id = ?`, [clientFk, companyFk]); - }, + } }, computed: { accountAddress: function() { diff --git a/print/reports/printer-setup/index.js b/print/reports/printer-setup/index.js index d32ea9c18..b15542fe4 100755 --- a/print/reports/printer-setup/index.js +++ b/print/reports/printer-setup/index.js @@ -23,7 +23,7 @@ module.exports = { }, data() { return { - attachments: ['/assets/files/model.ezp'], + files: ['/assets/files/model.ezp'], }; }, methods: { diff --git a/print/server.js b/print/server.js index 61eeb3297..31830009d 100644 --- a/print/server.js +++ b/print/server.js @@ -1,18 +1,14 @@ -const database = require('./lib/database'); -const smtp = require('./lib/smtp'); - module.exports = app => { global.appPath = __dirname; process.env.OPENSSL_CONF = '/etc/ssl/'; // Init database instance - database.init(); + require('./lib/database').init(); // Init SMTP Instance - smtp.init(); + require('./lib/smtp').init(); require('./lib/router')(app); - // require('./lib/errorHandler')(app); };