From 330233ec567f9f33dc3b5fc2475032bfbaab0e81 Mon Sep 17 00:00:00 2001 From: Greg Pazo Date: Tue, 25 Feb 2014 14:24:06 -0500 Subject: [PATCH] issue #22461 working for now from invoice->gear>print --- node-datasource/main.js | 2 +- node-datasource/routes/generate_report.js | 22 ++++++++++++++++++++-- node-datasource/sample_config.js | 1 + package.json | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/node-datasource/main.js b/node-datasource/main.js index ee436073c..83010b009 100755 --- a/node-datasource/main.js +++ b/node-datasource/main.js @@ -609,7 +609,7 @@ io.of('/clientsock').authorization(function (handshakeData, callback) { debugging: X.options.datasource.debugging, biAvailable: _.isObject(X.options.biServer) && !_.isEmpty(X.options.biServer), emailAvailable: _.isString(X.options.datasource.smtpHost) && X.options.datasource.smtpHost !== "", - printAvailable: false, + printAvailable: _.isString(X.options.datasource.printer) && X.options.datasource.printer !== "", version: X.version }); callback(callbackObj); diff --git a/node-datasource/routes/generate_report.js b/node-datasource/routes/generate_report.js index b2ae63a0a..a6da7fea0 100644 --- a/node-datasource/routes/generate_report.js +++ b/node-datasource/routes/generate_report.js @@ -13,6 +13,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */ async = require("async"), fs = require("fs"), path = require("path"), + ipp = require("ipp"), Report = require('fluentreports').Report, queryForData = require("./report").queryForData; @@ -25,7 +26,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */ @property req.query.action Sample URL: - https://localhost:8543/qatest/generate-report?nameSpace=XM&type=Invoice&id=60000 + https://localhost:8443/dev/generate-report?nameSpace=XM&type=Invoice&id=60000&action=print */ var generateReport = function (req, res) { @@ -279,8 +280,25 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */ Silent-print to a printer registered in the node-datasource. */ var responsePrint = function (res, data, done) { - // TODO + + var printer = ipp.Printer(X.options.datasource.printer); + var msg = { + "operation-attributes-tag": { + "job-name": "Silent Print", + "document-format": "application/pdf" + }, + data: data + }; + printer.execute("Print-Job", msg, function(error, result){ + if (error) { + X.log("Print error", error); + res.send({isError: true, message: "Error printing"}); done(); + } else { + res.send({message: "Print Success"}); + done(); + } + }); }; // Convenience hash to avoid log if-else diff --git a/node-datasource/sample_config.js b/node-datasource/sample_config.js index 57be4aeab..5b5a7f5e4 100644 --- a/node-datasource/sample_config.js +++ b/node-datasource/sample_config.js @@ -41,6 +41,7 @@ newcap:true, noarg:true, regexp:true, undef:true, strict:true, trailing:true, wh smtpPort: 587, smtpUser: "", smtpPassword: "", + printer: "", // these properties are dynamically registered with the // node discovery service diff --git a/package.json b/package.json index bc10bcc19..d114caa7b 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "ejs": "0.8.x", "express": "3.1.x", "fluentreports": "git://github.com/xtuple/fluentreports.git", + "ipp": "0.0.5", "json-patch": "git://github.com/xtuple/JSON-Patch.git", "less": "1.5.0", "moment": "2.4.x", -- 2.39.2