void RenderWindow::print(bool showPreview) { ORPreRender pre; pre.setDom(_doc); pre.setParamList(getParameterList()); ORODocument * doc = pre.generate(); if(doc) { QPrinter printer(QPrinter::HighResolution); if(!_printerName.isEmpty()) { printer.setPrinterName(_printerName); _printerName = QString::null; } if(showPreview) { PreviewDialog preview (doc, &printer, this); if (preview.exec() == QDialog::Rejected) return; } ORPrintRender render; render.setupPrinter(doc, &printer); QPrintDialog pd(&printer); pd.setMinMax(1, doc->pages()); if(pd.exec() == QDialog::Accepted) { render.setPrinter(&printer); render.render(doc); } } }
void RenderWindow::print(bool showPreview, int numCopies ) { ORPreRender pre; pre.setDom(_doc); pre.setParamList(getParameterList()); ORODocument * doc = pre.generate(); if(doc) { QPrinter printer(QPrinter::HighResolution); #if QT_VERSION < 0x040700 // if qt < 4.7.0 then use the old function call. printer.setNumCopies( numCopies ); #else printer.setCopyCount( numCopies ); #endif if(!_printerName.isEmpty()) { printer.setPrinterName(_printerName); _printerName = QString::null; } ORPrintRender render; render.setupPrinter(doc, &printer); if(showPreview) { if(printer.printerName().isEmpty()) { QPrintDialog pd(&printer); if(pd.exec() != QDialog::Accepted) { return; // no printer, can't preview } } PreviewDialog preview (doc, &printer, this); if (preview.exec() == QDialog::Rejected) return; } if(_autoPrint) { render.setPrinter(&printer); render.render(doc); } else { QPrintDialog pd(&printer); pd.setMinMax(1, doc->pages()); if(pd.exec() == QDialog::Accepted) { render.setPrinter(&printer); render.render(doc); } } delete doc; } }
// BVI::Sednacom // override filePrintToPDF to accept a file path void RenderWindow::filePrintToPDF( QString & pdfFileName) { // code taken from original code of the member [ void RenderWindow::filePrintToPDF() ] if(pdfFileName.isEmpty()) return; if ( QFileInfo( pdfFileName ).suffix().isEmpty() ) pdfFileName.append(".pdf"); ORPreRender pre; pre.setDom(_doc); pre.setParamList(getParameterList()); ORPrintRender::exportToPDF(pre.generate(), pdfFileName); }
void printCheck::sPrint() { if (_createACH->isEnabled() && QMessageBox::question(this, tr("Print Anyway?"), tr("<p>The recipient of this check has been " "configured for ACH transactions. Do you want " "to print this check for them anyway?<p>If you " "answer 'Yes' then a check will be printed. " "If you say 'No' then you should click Create " "ACH File."), QMessageBox::Yes | QMessageBox::Default, QMessageBox::No) == QMessageBox::No) return; q.prepare( "SELECT checkhead_printed, report_name, bankaccnt_id " "FROM checkhead, bankaccnt, form, report " "WHERE ((checkhead_bankaccnt_id=bankaccnt_id)" " AND (bankaccnt_check_form_id=form_id)" " AND (form_report_id=report_id)" " AND (checkhead_id=:checkhead_id) );" ); q.bindValue(":checkhead_id", _check->id()); q.exec(); if (q.first()) { if(q.value("checkhead_printed").toBool()) { QMessageBox::information( this, tr("Check Already Printed"), tr("<p>The selected Check has already been printed.") ); return; } QString reportname = q.value("report_name").toString(); // get the report definition out of the database // this should somehow be condensed into a common code call or something // in the near future to facilitate easier conversion in other places // of the application to use the new rendering engine directly XSqlQuery report; report.prepare( "SELECT report_source " " FROM report " " WHERE (report_name=:report_name) " "ORDER BY report_grade DESC LIMIT 1;" ); report.bindValue(":report_name", reportname); report.exec(); QDomDocument docReport; if (report.first()) { QString errorMessage; int errorLine; if (!docReport.setContent(report.value("report_source").toString(), &errorMessage, &errorLine)) { systemError(this, errorMessage, __FILE__, __LINE__); return; } } else { systemError(this, report.lastError().databaseText(), __FILE__, __LINE__); return; } // end getting the report definition out the database if(_setCheckNumber != -1 && _setCheckNumber != _nextCheckNum->text().toInt()) { q.prepare("SELECT setNextCheckNumber(:bankaccnt_id, :nextCheckNumber) AS result;"); q.bindValue(":bankaccnt_id", _bankaccnt->id()); q.bindValue(":nextCheckNumber", _nextCheckNum->text().toInt()); q.exec(); if (q.first()) { int result = q.value("result").toInt(); if (result < 0) { systemError(this, storedProcErrorLookup("setNextCheckNumber", result), __FILE__, __LINE__); return; } } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } } q.prepare("UPDATE checkhead SET checkhead_number=fetchNextCheckNumber(checkhead_bankaccnt_id)" " WHERE(checkhead_id=:checkhead_id);"); q.bindValue(":checkhead_id", _check->id()); q.exec(); if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } ParameterList params; params.append("checkhead_id", _check->id()); params.append("apchk_id", _check->id()); // replace with new renderer code so we can get a page count ORPreRender pre; pre.setDom(docReport); pre.setParamList(params); ORODocument * doc = pre.generate(); QPrinter printer(QPrinter::HighResolution); ORPrintRender render; render.setupPrinter(doc, &printer); QPrintDialog pd(&printer); pd.setMinMax(1, doc->pages()); if(pd.exec() == XDialog::Accepted) { render.setPrinter(&printer); render.render(doc); } else return; int page_num = 1; while(page_num < doc->pages()) { page_num++; XSqlQuery qq; qq.prepare("INSERT INTO checkhead" " (checkhead_recip_id, checkhead_recip_type," " checkhead_bankaccnt_id, checkhead_printed," " checkhead_checkdate, checkhead_number," " checkhead_amount, checkhead_void," " checkhead_misc," " checkhead_for, checkhead_notes," " checkhead_curr_id, checkhead_deleted) " "SELECT checkhead_recip_id, checkhead_recip_type," " checkhead_bankaccnt_id, TRUE," " checkhead_checkdate, fetchNextCheckNumber(checkhead_bankaccnt_id)," " checkhead_amount, TRUE, TRUE," " 'Continuation of Check #'||checkhead_number," " 'Continuation of Check #'||checkhead_number," " checkhead_curr_id, TRUE" " FROM checkhead" " WHERE(checkhead_id=:checkhead_id);"); qq.bindValue(":checkhead_id", _check->id()); if(!qq.exec()) { systemError(this, "Received error but will continue anyway:\n"+qq.lastError().databaseText(), __FILE__, __LINE__); } } omfgThis->sChecksUpdated(_bankaccnt->id(), _check->id(), TRUE); } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } else // join failed { QMessageBox::critical(this, tr("Cannot Print Check"), tr("<p>The selected Check cannot be printed as the " "Bank Account that it is to draw upon does not " "have a valid Check Format assigned to it. " "Please assign a valid Check Format to this Bank " "Account before attempting to print this Check.")); return; } if ( QMessageBox::question( this, tr("Check Printed"), tr("Was the selected Check printed successfully?"), QMessageBox::Yes, QMessageBox::No | QMessageBox::Default) == QMessageBox::Yes) markCheckAsPrinted(_check->id()); else if ( QMessageBox::question(this, tr("Mark Check as Voided"), tr("<p>Would you like to mark the selected " "Check as Void and create a replacement " "check?"), QMessageBox::Yes, QMessageBox::No | QMessageBox::Default) == QMessageBox::Yes) { q.prepare("SELECT voidCheck(:checkhead_id) AS result;"); q.bindValue(":checkhead_id", _check->id()); q.exec(); if (q.first()) { int result = q.value("result").toInt(); if (result < 0) { systemError(this, storedProcErrorLookup("voidCheck", result), __FILE__, __LINE__); return; } } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } q.prepare( "SELECT checkhead_bankaccnt_id," " replaceVoidedCheck(checkhead_id) AS result " "FROM checkhead " "WHERE (checkhead_id=:checkhead_id);" ); q.bindValue(":checkhead_id", _check->id()); q.exec(); if (q.first()) { int result = q.value("result").toInt(); if (result < 0) { systemError(this, storedProcErrorLookup("replaceVoidedCheck", result), __FILE__, __LINE__); return; } omfgThis->sChecksUpdated(q.value("checkhead_bankaccnt_id").toInt(), _check->id(), TRUE); sHandleBankAccount(_bankaccnt->id()); _print->setFocus(); } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } } }
void printChecks::sPrint() { QList<int> printedChecks; bool firstRun = TRUE; ParameterList params; params.append("bankaccnt_id", _bankaccnt->id()); bool setup = true; QList<ORODocument*> singleCheckPrerendered; XSqlQuery checks; checks.prepare( "SELECT checkhead_id, checkhead_number, report_name, checkhead_recip_id, checkhead_recip_type " "FROM checkhead " "LEFT OUTER JOIN vendinfo ON((checkhead_recip_id = vend_id) " " AND(checkhead_recip_type = 'V')) " "LEFT OUTER JOIN custinfo ON((checkhead_recip_id = cust_id) " " AND(checkhead_recip_type = 'C')) " "LEFT OUTER JOIN taxauth ON((checkhead_recip_id = taxauth_id) " " AND(checkhead_recip_type = 'T')), " " bankaccnt, form, report " "WHERE ( (checkhead_bankaccnt_id=bankaccnt_id)" " AND (bankaccnt_check_form_id=form_id)" " AND (form_report_id=report_id)" " AND (NOT checkhead_printed) " " AND (NOT checkhead_void) " " AND (bankaccnt_id=:bankaccnt_id) ) " "ORDER BY checkhead_recip_type DESC, COALESCE(vend_number, cust_number, taxauth_code) " "LIMIT :numtoprint; " ); checks.bindValue(":bankaccnt_id", _bankaccnt->id()); checks.bindValue(":numtoprint", _numberOfChecks->value()); checks.exec(); QDomDocument docReport; while (checks.next()) { if (setup) { // get the report definition out of the database // this should somehow be condensed into a common code call or something // in the near future to facilitate easier conversion in other places // of the application to use the new rendering engine directly XSqlQuery report; report.prepare( "SELECT report_source " " FROM report " " WHERE (report_name=:report_name) " "ORDER BY report_grade DESC LIMIT 1;" ); report.bindValue(":report_name", checks.value("report_name").toString()); report.exec(); if (report.first()) { QString errorMessage; int errorLine; if (!docReport.setContent(report.value("report_source").toString(), &errorMessage, &errorLine)) { systemError(this, errorMessage, __FILE__, __LINE__); return; } } else { systemError(this, report.lastError().databaseText(), __FILE__, __LINE__); return; } // end getting the report definition out the database if(_setCheckNumber != -1 && _setCheckNumber != _nextCheckNum->text().toInt() && firstRun) { q.prepare("SELECT setNextCheckNumber(:bankaccnt_id, :nextCheckNumber) AS result;"); q.bindValue(":bankaccnt_id", _bankaccnt->id()); q.bindValue(":nextCheckNumber", _nextCheckNum->text().toInt()); q.exec(); if (q.first()) { int result = q.value("result").toInt(); if (result < 0) { systemError(this, storedProcErrorLookup("setNextCheckNumber", result), __FILE__, __LINE__); return; } } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } firstRun = FALSE; } } q.prepare("UPDATE checkhead SET checkhead_number=fetchNextCheckNumber(checkhead_bankaccnt_id)" " WHERE(checkhead_id=:checkhead_id);"); q.bindValue(":checkhead_id", checks.value("checkhead_id").toInt()); q.exec(); if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } ParameterList params; params.append("checkhead_id", checks.value("checkhead_id").toInt()); params.append("apchk_id", checks.value("checkhead_id").toInt()); ORPreRender pre; pre.setDom(docReport); pre.setParamList(params); ORODocument * doc = pre.generate(); printedChecks.append(checks.value("checkhead_id").toInt()); int page_num = 1; while(page_num < doc->pages()) { page_num++; XSqlQuery qq; qq.prepare("INSERT INTO checkhead" " (checkhead_recip_id, checkhead_recip_type," " checkhead_bankaccnt_id, checkhead_printed," " checkhead_checkdate, checkhead_number," " checkhead_amount, checkhead_void," " checkhead_misc," " checkhead_for, checkhead_notes," " checkhead_curr_id, checkhead_deleted) " "SELECT checkhead_recip_id, checkhead_recip_type," " checkhead_bankaccnt_id, TRUE," " checkhead_checkdate, fetchNextCheckNumber(checkhead_bankaccnt_id)," " checkhead_amount, TRUE, TRUE," " 'Continuation of Check #'||checkhead_number," " 'Continuation of Check #'||checkhead_number," " checkhead_curr_id, TRUE" " FROM checkhead" " WHERE(checkhead_id=:checkhead_id);"); qq.bindValue(":checkhead_id", checks.value("checkhead_id").toInt()); if(!qq.exec()) { systemError(this, "Received error but will continue anyway:\n"+qq.lastError().databaseText(), __FILE__, __LINE__); } } singleCheckPrerendered.append(doc); } if (checks.lastError().type() != QSqlError::None) { systemError(this, checks.lastError().databaseText(), __FILE__, __LINE__); return; } if(!printedChecks.empty()) { QPrinter printer(QPrinter::HighResolution); ORODocument entireCheckRunPrerendered; for (int j = 0; j < singleCheckPrerendered.size(); j++) { for (int i = 0; i < singleCheckPrerendered.at(j)->pages(); i++) { entireCheckRunPrerendered.addPage(singleCheckPrerendered.at(j)->page(i)); } } ORPrintRender render; render.setupPrinter(&entireCheckRunPrerendered, &printer); QPrintDialog pd(&printer); pd.setMinMax(1, entireCheckRunPrerendered.pages()); if(pd.exec() != XDialog::Accepted) return; render.setPrinter(&printer); render.render(&entireCheckRunPrerendered); QList<int>::iterator it; if ( QMessageBox::question(this, tr("All Checks Printed"), tr("<p>Did all the Checks print successfully?"), QMessageBox::Yes, QMessageBox::No | QMessageBox::Default) == QMessageBox::Yes) { XSqlQuery postCheck; postCheck.prepare( "SELECT markCheckAsPrinted(:checkhead_id) AS result;"); for( it = printedChecks.begin(); it != printedChecks.end(); ++it) { postCheck.bindValue(":checkhead_id", (*it)); postCheck.exec(); if (postCheck.first()) { int result = postCheck.value("result").toInt(); if (result < 0) { systemError(this, storedProcErrorLookup("markCheckAsPrinted", result), __FILE__, __LINE__); return; } } else if (postCheck.lastError().type() != QSqlError::None) { systemError(this, postCheck.lastError().databaseText(), __FILE__, __LINE__); return; } } } else { printChecksReview newdlg(this, "", TRUE); QString query = QString( "SELECT checkhead_id, checkhead_number" " FROM checkhead" " WHERE (checkhead_id IN (" ); bool first = true; for( it = printedChecks.begin(); it != printedChecks.end(); ++it) { if(!first) query += ","; query += QString::number((*it)); first = false; } query += ") ); "; newdlg._checks->populate(query); newdlg.sSelectAll(); newdlg.sMarkPrinted(); newdlg._checks->clearSelection(); newdlg.exec(); } } else QMessageBox::information( this, tr("No Checks Printed"), tr("<p>No Checks were printed for the selected " "Bank Account.") ); omfgThis->sChecksUpdated(_bankaccnt->id(), -1, TRUE); sHandleBankAccount(_bankaccnt->id()); }
void displayPrivate::print(ParameterList pParams, bool showPreview, bool forceSetParams) { int numCopies = 1; ParameterList params = pParams; if (forceSetParams || !params.count()) { if(!_parent->setParams(params)) return; } params.append("isReport", true); XSqlQuery report; report.prepare("SELECT report_grade, report_source " " FROM report " " WHERE (report_name=:report_name)" " ORDER BY report_grade DESC LIMIT 1"); report.bindValue(":report_name", reportName); report.exec(); QDomDocument _doc; if (report.first()) { QString errorMessage; int errorLine; if (!_doc.setContent(report.value("report_source").toString(), &errorMessage, &errorLine)) { QMessageBox::critical(_parent, ::display::tr("Error Parsing Report"), ::display::tr("There was an error Parsing the report definition. %1 %2").arg(errorMessage).arg(errorLine)); return; } } else { QMessageBox::critical(_parent, ::display::tr("Report Not Found"), ::display::tr("The report %1 does not exist.").arg(reportName)); return; } ORPreRender pre; pre.setDom(_doc); pre.setParamList(params); ORODocument * doc = pre.generate(); if(doc) { ReportPrinter printer(QPrinter::HighResolution); printer.setNumCopies( numCopies ); ORPrintRender render; render.setupPrinter(doc, &printer); if(showPreview) { QPrinter * tPrinter = &printer; QPrinter pdfPrinter(QPrinter::HighResolution); if(!printer.isValid()) { render.setupPrinter(doc, &pdfPrinter); pdfPrinter.setOutputFormat(QPrinter::PdfFormat); tPrinter = &pdfPrinter; } PreviewDialog preview (doc, tPrinter, _parent); if (preview.exec() == QDialog::Rejected) return; } QPrintDialog pd(&printer); pd.setMinMax(1, doc->pages()); if(pd.exec() == QDialog::Accepted) { render.render(doc, &printer); } delete doc; } }