void printQuote::sPrint() { ParameterList params; params.append("quhead_id", _quheadid); orReport report(_report->code(), params); if (report.isValid()) { report.print(); emit finishedPrinting(_quheadid); if (_captive) accept(); } else { report.reportError(this); if (_captive) reject(); } _quheadid = -1; _number->clear(); _cust->setId(-1); _cust->setFocus(); _cust->setEnabled(true); }
bool printMulticopyDocument::sPrintOneDoc(XSqlQuery *docq) { QString reportname = docq->value("reportname").toString(); QString docnumber = docq->value("docnumber").toString(); bool printedOk = false; if (! _data->_mpIsInitialized) { bool userCanceled = false; if (orReport::beginMultiPrint(_data->_printer, userCanceled) == false) { if(!userCanceled) ErrorReporter::error(QtCriticalMsg, this, tr("Error Occurred"), tr("%1: Could not initialize printing system " "for multiple reports. ").arg(windowTitle()),__FILE__,__LINE__); return false; } } orReport report(reportname); if (! report.isValid()) QMessageBox::critical(this, tr("Cannot Find Form"), tr("<p>Cannot find form '%1' for %2 %3. " "It cannot be printed until the Form " "Assignment is updated to remove references " "to this Form or the Form is created.") .arg(reportname, _data->_doctypefull, docnumber)); else { for (int i = 0; i < _data->_copies->numCopies(); i++) { report.setParamList(getParamsOneCopy(i, docq)); if (! report.isValid()) { ErrorReporter::error(QtCriticalMsg, this, tr("Invalid Parameters"), tr("<p>Report '%1' cannot be run. Parameters " "are missing.").arg(reportname), __FILE__, __LINE__); printedOk = false; continue; } else if (report.print(_data->_printer, ! _data->_mpIsInitialized)) { _data->_mpIsInitialized = true; printedOk = true; } else { report.reportError(this); printedOk = false; continue; } } } if (printedOk) emit finishedPrinting(docq->value("docid").toInt()); return printedOk; }
void printPoForm::sPrint() { q.prepare( "SELECT form_report_name AS report_name " "FROM form " "WHERE ( (form_id=:form_id) );"); q.bindValue(":form_id", _report->id()); q.exec(); if (q.first()) { ParameterList params; params.append("pohead_id", _po->id()); orReport report(q.value("report_name").toString(), params); if (report.isValid()) { if (report.print()) emit finishedPrinting(_po->id()); } else { report.reportError(this); reject(); } _po->setId(-1); _po->setFocus(); } else QMessageBox::warning( this, tr("Could not locate report"), tr("Could not locate the report definition the form \"%1\"") .arg(_report->currentText()) ); }
void quotes::sPrint() { QPrinter printer(QPrinter::HighResolution); bool setupPrinter = TRUE; q.prepare( "SELECT findCustomerForm(quhead_cust_id, 'Q') AS reportname " "FROM quhead " "WHERE (quhead_id=:quheadid); " ); bool userCanceled = false; QList<XTreeWidgetItem*> selected = _quote->selectedItems(); if (selected.size() > 0 && orReport::beginMultiPrint(&printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("<p>Could not initialize printing system for " "multiple reports.")); return; } QList<int> printedQuotes; for (int i = 0; i < selected.size(); i++) { int quheadid = ((XTreeWidgetItem*)(selected[i]))->id(); q.bindValue(":quheadid", quheadid); q.exec(); if (q.first()) { if (checkSitePrivs(((XTreeWidgetItem*)(selected[i]))->id())) { ParameterList params; params.append("quhead_id", quheadid); orReport report(q.value("reportname").toString(), params); if (report.isValid() && report.print(&printer, setupPrinter)) { setupPrinter = FALSE; printedQuotes.append(quheadid); } else { report.reportError(this); break; } } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); break; } } } if (selected.size() > 0) orReport::endMultiPrint(&printer); for (int i = 0; i < printedQuotes.size(); i++) emit finishedPrinting(printedQuotes.at(i)); }
void printStatementByCustomer::sPrint() { ParameterList params; if(! setParams(params)) return; MetaSQLQuery agem("SELECT * FROM araging (<? value('asofDate') ?>, true)" " WHERE (araging_cust_id = <? value('cust_id') ?>);"); XSqlQuery ageq = agem.toQuery(params); if(ageq.first()) { MetaSQLQuery formm("SELECT findCustomerForm(<? value('cust_id') ?>, 'S')" " AS _reportname;"); XSqlQuery formq = formm.toQuery(params); if (formq.first()) { orReport report(formq.value("_reportname").toString(), params); if (report.isValid()) { if (report.print()) emit finishedPrinting(_cust->id()); } else { report.reportError(this); reject(); } if (_captive) accept(); else { _close->setText(tr("&Close")); _cust->setId(-1); _cust->setFocus(); } } else if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting Form"), formq, __FILE__, __LINE__)) return; } else if (ErrorReporter::error(QtCriticalMsg, this, tr("Database Error"), ageq, __FILE__, __LINE__)) return; else QMessageBox::warning( this, tr("No Statement to Print"), tr("No statement is available for the specified " "Customer and Asof Date.") ); }
void packingListBatch::sPrintBatch() { XSqlQuery packingPrintBatch; XSqlQuery updateq; updateq.prepare("UPDATE pack " "SET pack_printed=TRUE " "WHERE (pack_id=:packid);" ); ParameterList params; if (_metrics->boolean("MultiWhs")) params.append("MultiWhs"); MetaSQLQuery mql = mqlLoad("packingListBatch", "print"); packingPrintBatch = mql.toQuery(params); if (packingPrintBatch.lastError().type() != QSqlError::NoError) { systemError(this, packingPrintBatch.lastError().databaseText(), __FILE__, __LINE__); return; } QPrinter printer(QPrinter::HighResolution); bool setupPrinter = TRUE; bool userCanceled = false; if (orReport::beginMultiPrint(&printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("Could not initialize printing system for multiple reports.")); return; } while (packingPrintBatch.next()) { int osmiscid = packingPrintBatch.value("pack_shiphead_id").toInt(); bool usePickForm; if (_printPick->isChecked()) usePickForm = true; else if (_printPack->isChecked()) usePickForm = false; else if (osmiscid > 0) usePickForm = false; else usePickForm = true; // skip when PackForm and no shiphead_id if (!usePickForm && osmiscid <= 0) continue; // set sohead_id, tohead_id, and shiphead_id for customer and 3rd-party use ParameterList params; params.append("head_id", packingPrintBatch.value("pack_head_id").toInt()); params.append("head_type", packingPrintBatch.value("pack_head_type").toString()); if (packingPrintBatch.value("pack_head_type").toString() == "SO") params.append("sohead_id", packingPrintBatch.value("pack_head_id").toInt()); else if (packingPrintBatch.value("pack_head_type").toString() == "TO") params.append("tohead_id", packingPrintBatch.value("pack_head_id").toInt()); if (osmiscid > 0) { params.append("shiphead_id", osmiscid); } if (_metrics->boolean("MultiWhs")) params.append("MultiWhs"); orReport report(packingPrintBatch.value(usePickForm ? "pickform" : "packform").toString(), params); if (! report.isValid()) { report.reportError(this); } else if (report.print(&printer, setupPrinter)) { setupPrinter = FALSE; updateq.bindValue(":packid", packingPrintBatch.value("pack_id").toInt()); updateq.exec(); if (updateq.lastError().type() != QSqlError::NoError) { systemError(this, updateq.lastError().databaseText(), __FILE__, __LINE__); orReport::endMultiPrint(&printer); return; } emit finishedPrinting(packingPrintBatch.value("pack_head_id").toInt(), packingPrintBatch.value("pack_head_type").toString(), packingPrintBatch.value("pack_shiphead_id").toInt()); } else { report.reportError(this); orReport::endMultiPrint(&printer); return; } } orReport::endMultiPrint(&printer); if (setupPrinter) { QMessageBox::warning(this, tr("Nothing to Print"), tr("<p>All of the Packing Lists appear to have been " "printed already.")); } else { sFillList(); } }
void printPurchaseOrdersByAgent::sPrint() { XSqlQuery markprinted; markprinted.prepare("UPDATE pohead" " SET pohead_printed=true" " WHERE (pohead_id=:pohead_id);"); XSqlQuery pohead; pohead.prepare( "SELECT pohead_id " "FROM pohead " "WHERE ( (pohead_agent_username=:username)" " AND (pohead_status='O')" " AND (NOT pohead_printed)" " AND (pohead_saved) );" ); pohead.bindValue(":username", _agent->currentText()); pohead.exec(); if (pohead.first()) { QPrinter *printer = new QPrinter(QPrinter::HighResolution); bool setupPrinter = true; bool userCanceled = false; if (orReport::beginMultiPrint(printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("Could not initialize printing system for multiple reports.")); return; } do { if (_vendorCopy->isChecked()) { ParameterList params; params.append("pohead_id", pohead.value("pohead_id").toInt()); params.append("title", "Vendor Copy"); orReport report("PurchaseOrder", params); if (report.isValid() && report.print(printer, setupPrinter)) setupPrinter = false; else { report.reportError(this); orReport::endMultiPrint(printer); return; } } if (_internalCopy->isChecked()) { for (int counter = _numOfCopies->value(); counter; counter--) { ParameterList params; params.append("pohead_id", pohead.value("pohead_id")); params.append("title", QString("Internal Copy #%1").arg(counter)); orReport report("PurchaseOrder", params); if (report.isValid() && report.print(printer, setupPrinter)) setupPrinter = false; else { report.reportError(this); orReport::endMultiPrint(printer); return; } } } markprinted.bindValue(":pohead_id", pohead.value("pohead_id").toInt()); markprinted.exec(); if (markprinted.lastError().type() != QSqlError::NoError) { systemError(this, markprinted.lastError().databaseText(), __FILE__, __LINE__); orReport::endMultiPrint(printer); return; } emit finishedPrinting(pohead.value("pohead_id").toInt()); } while (pohead.next()); orReport::endMultiPrint(printer); } else if (pohead.lastError().type() != QSqlError::NoError) { systemError(this, pohead.lastError().databaseText(), __FILE__, __LINE__); return; } else QMessageBox::information( this, tr("No Purchase Orders to Print"), tr("There are no posted, unprinted Purchase Orders entered by the selected Purchasing Agent to print.") ); accept(); }
void printPackingListBatchByShipvia::sPrint() { QPrinter printer(QPrinter::HighResolution); bool setupPrinter = true; if (!_dates->allValid()) { QMessageBox::warning( this, tr("Enter a Valid Start and End Date"), tr("You must enter a valid Start and End Date for this report.") ); _dates->setFocus(); return; } XSqlQuery prtd; QString prts("UPDATE pack SET pack_printed=true" " WHERE ((pack_head_id=<? value('head_id') ?>) " " AND (pack_head_type=<? value('head_type') ?>)" "<? if exists('shiphead_id') ?>" " AND (pack_shiphead_id=<? value('shiphead_id') ?>)" "<? else ?>" " AND (pack_shiphead_id IS NULL)" "<? endif ?>" ");" ); XSqlQuery packq; ParameterList params; _dates->appendValue(params); _warehouse->appendValue(params); if (_metrics->boolean("MultiWhs")) params.append("MultiWhs"); if (_shipvia->isValid()) params.append("shipvia", _shipvia->currentText()); MetaSQLQuery packm = mqlLoad("packingListBatchByShipVia", "print"); packq = packm.toQuery(params); if (packq.lastError().type() != QSqlError::NoError) { systemError(this, packq.lastError().databaseText(), __FILE__, __LINE__); return; } bool userCanceled = false; if (orReport::beginMultiPrint(&printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("Could not initialize printing system for multiple reports.")); return; } while (packq.next()) { ParameterList params; params.append("head_id", packq.value("pack_head_id").toInt()); params.append("head_type", packq.value("pack_head_type").toString()); if (packq.value("pack_head_type").toString() == "SO") params.append("sohead_id", packq.value("pack_head_id").toInt()); else if (packq.value("pack_head_type").toString() == "TO") params.append("tohead_id", packq.value("pack_head_id").toInt()); if (! packq.value("pack_shiphead_id").isNull()) { params.append("shiphead_id", packq.value("pack_shiphead_id").toInt()); } _warehouse->appendValue(params); if (_metrics->boolean("MultiWhs")) params.append("MultiWhs"); if (packq.value("orderhead_status").toString() != "C") { bool usePickForm; if (_auto->isChecked()) usePickForm = packq.value("pack_shiphead_id").isNull(); else usePickForm = _pick->isChecked(); orReport report(packq.value( usePickForm ? "pickform" : "packform").toString(), params); if (report.isValid()) { if (report.print(&printer, setupPrinter)) { setupPrinter = false; emit finishedPrinting(packq.value("pack_head_id").toInt(), packq.value("pack_head_type").toString(), packq.value("pack_shiphead_id").toInt()); } else { orReport::endMultiPrint(&printer); return; } } else { report.reportError(this); orReport::endMultiPrint(&printer); return; } } MetaSQLQuery mql(prts); prtd = mql.toQuery(params); if (prtd.lastError().type() != QSqlError::NoError) { systemError(this, prtd.lastError().databaseText(), __FILE__, __LINE__); orReport::endMultiPrint(&printer); return; } } orReport::endMultiPrint(&printer); sPopulateShipVia(); }
void printInvoicesByShipvia::sPrint() { XSqlQuery invoices; invoices.prepare( "SELECT * FROM (" " SELECT invchead_id, invchead_invcnumber, invchead_ordernumber, " " findCustomerForm(invchead_cust_id, 'I') AS reportname " " FROM invchead " " WHERE ( (NOT invchead_printed)" " AND (NOT invchead_posted)" " AND (invchead_shipvia=:shipvia)) ) AS data " "WHERE (checkInvoiceSitePrivs(invchead_id)) " "ORDER BY invchead_ordernumber;" ); invoices.bindValue(":shipvia", _shipvia->currentText()); invoices.exec(); if (invoices.first()) { XSqlQuery local; QPrinter printer(QPrinter::HighResolution); bool setupPrinter = TRUE; bool userCanceled = false; if (orReport::beginMultiPrint(&printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("Could not initialize printing system for multiple reports.")); return; } do { int invoiceNumber = invoices.value("invchead_invcnumber").toInt(); if (invoiceNumber == 0) { local.prepare("SELECT fetchInvcNumber() AS invoicenumber;"); local.exec(); if (local.first()) { invoiceNumber = local.value("invoicenumber").toInt(); local.prepare( "UPDATE invchead " "SET invchead_invcnumber=text(:invoicenumber) " "WHERE (invchead_id=:invchead_id);" ); local.bindValue(":invoicenumber", invoiceNumber); local.bindValue(":invchead_id", invoices.value("invchead_id").toInt()); local.exec(); } // not else because local is re-prepared inside the block if (local.lastError().type() != QSqlError::NoError) { systemError(this, local.lastError().databaseText(), __FILE__, __LINE__); return; } } XSqlQuery xrate; xrate.prepare("SELECT curr_rate " "FROM curr_rate, invchead " "WHERE ((curr_id=invchead_curr_id)" " AND (invchead_id=:invchead_id)" " AND (invchead_invcdate BETWEEN curr_effective AND curr_expires));"); // if SUM becomes dependent on curr_id then move XRATE before it in the loop XSqlQuery sum; sum.prepare("SELECT invoiceTotal(:invchead_id) AS subtotal;"); message( tr("Printing Invoice #%1...") .arg(invoiceNumber) ); for (int i = 0; i < _invoiceWatermarks->topLevelItemCount(); i++ ) { QTreeWidgetItem *cursor = _invoiceWatermarks->topLevelItem(i); ParameterList params; params.append("invchead_id", invoices.value("invchead_id").toInt()); params.append("showcosts", ((cursor->text(2) == tr("Yes")) ? "TRUE" : "FALSE")); params.append("watermark", cursor->text(1)); orReport report(invoices.value("reportname").toString(), params); message( tr("Printing Invoice #%1...") .arg(invoiceNumber) ); if (!report.isValid()) { QMessageBox::critical( this, tr("Cannot Find Invoice Form"), tr( "The Invoice Form '%1' cannot be found for Invoice #%2.\n" "This Invoice cannot be printed until a Customer Form Assignment is updated to remove any\n" "references to this Invoice Form or this Invoice Form is created." ) .arg(invoices.value("reportname").toString()) .arg(invoiceNumber) ); resetMessage(); } else { if (report.print(&printer, setupPrinter)) setupPrinter = FALSE; else { systemError( this, tr("A Printing Error occurred at printInvoices::%1.") .arg(__LINE__) ); orReport::endMultiPrint(&printer); return; } if (_post->isChecked()) { int invcheadId = invoices.value("invchead_id").toInt(); sum.bindValue(":invchead_id", invcheadId); if (sum.exec() && sum.first() && sum.value("subtotal").toDouble() == 0) { if (QMessageBox::question(this, tr("Invoice Has Value 0"), tr("Invoice #%1 has a total value of 0.\n" "Would you like to post it anyway?") .arg(invoiceNumber), QMessageBox::Yes, QMessageBox::No | QMessageBox::Default) == QMessageBox::No) continue; } else if (sum.lastError().type() != QSqlError::NoError) { systemError(this, sum.lastError().databaseText(), __FILE__, __LINE__); continue; } else if (sum.value("subtotal").toDouble() != 0) { xrate.bindValue(":invchead_id", invcheadId); xrate.exec(); if (xrate.lastError().type() != QSqlError::NoError) { systemError(this, tr("System Error posting Invoice #%1\n%2") .arg(invoiceNumber) .arg(xrate.lastError().databaseText()), __FILE__, __LINE__); continue; } else if (!xrate.first() || xrate.value("curr_rate").isNull()) { systemError(this, tr("Could not post Invoice #%1 because of a missing exchange rate.") .arg(invoiceNumber)); continue; } } message( tr("Posting Invoice #%1...") .arg(invoiceNumber) ); local.prepare("SELECT postInvoice(:invchead_id) AS result;"); local.bindValue(":invchead_id", invcheadId); local.exec(); if (local.lastError().type() != QSqlError::NoError) { systemError(this, local.lastError().databaseText(), __FILE__, __LINE__); } } } } emit finishedPrinting(invoices.value("invchead_id").toInt()); } while (invoices.next()); orReport::endMultiPrint(&printer); resetMessage(); if (!_post->isChecked()) { if ( QMessageBox::information( this, tr("Mark Invoices as Printed?"), tr("Did all of the Invoices print correctly?"), tr("&Yes"), tr("&No"), QString::null, 0, 1) == 0) { q.prepare( "UPDATE invchead " " SET invchead_printed=TRUE " " WHERE ( (NOT invchead_printed)" " AND (invchead_shipvia=:shipvia) ); "); q.bindValue(":shipvia", _shipvia->currentText()); q.exec(); if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } omfgThis->sInvoicesUpdated(-1, TRUE); } } } else if (invoices.lastError().type() != QSqlError::NoError) { systemError(this, invoices.lastError().databaseText(), __FILE__, __LINE__); return; } else QMessageBox::information( this, tr("No Invoices to Print"), tr("There aren't any Invoices to print for the selected Ship Via.") ); accept(); }
void printInvoice::sPrint() { q.prepare( "SELECT invchead_invcnumber, invchead_printed, invchead_posted," " findCustomerForm(invchead_cust_id, 'I') AS reportname " "FROM invchead " "WHERE (invchead_id=:invchead_id);" ); q.bindValue(":invchead_id", _invcheadid); q.exec(); if (q.first()) { XSqlQuery xrate; xrate.prepare("SELECT curr_rate " "FROM curr_rate, invchead " "WHERE ((curr_id=invchead_curr_id)" " AND (invchead_id=:invchead_id)" " AND (invchead_invcdate BETWEEN curr_effective AND curr_expires));"); // if SUM becomes dependent on curr_id then move XRATE before it in the loop XSqlQuery sum; sum.prepare("SELECT invoiceTotal(:invchead_id) AS subtotal;"); QString reportname = q.value("reportname").toString(); QString invchead_invcnumber = q.value("invchead_invcnumber").toString(); bool dosetup = (!_setup); if (dosetup) { bool userCanceled = false; if (orReport::beginMultiPrint(_printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("Could not initialize printing system for multiple reports.")); return; } } for (int i = 0; i < _invoiceWatermarks->topLevelItemCount(); i++ ) { QTreeWidgetItem *cursor = _invoiceWatermarks->topLevelItem(i); ParameterList params; params.append("invchead_id", _invcheadid); params.append("showcosts", ((cursor->text(2) == tr("Yes")) ? "TRUE" : "FALSE")); params.append("watermark", cursor->text(1)); orReport report(reportname, params); if (!report.isValid()) QMessageBox::critical( this, tr("Cannot Find Invoice Form"), tr( "The Invoice Form '%1' cannot be found for Invoice #%2.\n" "This Invoice cannot be printed until a Customer Form Assignment is updated to remove any\n" "references to this Invoice Form or this Invoice Form is created." ) .arg(reportname) .arg(invchead_invcnumber) ); else { if (report.print(_printer, dosetup)) dosetup = FALSE; else { systemError( this, tr("A Printing Error occurred at printInvoice::%1.") .arg(__LINE__) ); if (!_captive) orReport::endMultiPrint(_printer); return; } } } emit finishedPrinting(_invcheadid); if (!_captive) orReport::endMultiPrint(_printer); q.prepare( "UPDATE invchead " "SET invchead_printed=TRUE " "WHERE (invchead_id=:invchead_id);" ); q.bindValue(":invchead_id", _invcheadid); q.exec(); if (_alert) omfgThis->sInvoicesUpdated(_invcheadid, TRUE); if (_post->isChecked()) { sum.bindValue(":invchead_id", _invcheadid); if (sum.exec() && sum.first() && sum.value("subtotal").toDouble() == 0) { if (QMessageBox::question(this, tr("Invoice Has Value 0"), tr("Invoice #%1 has a total value of 0.\n" "Would you like to post it anyway?") .arg(invchead_invcnumber), QMessageBox::Yes, QMessageBox::No | QMessageBox::Default) == QMessageBox::No) return; } else if (sum.lastError().type() != QSqlError::NoError) { systemError(this, sum.lastError().databaseText(), __FILE__, __LINE__); return; } else if (sum.value("subtotal").toInt() != 0) { xrate.bindValue(":invchead_id", _invcheadid); xrate.exec(); if (xrate.lastError().type() != QSqlError::NoError) { systemError(this, tr("System Error posting Invoice #%1\n%2") .arg(invchead_invcnumber) .arg(xrate.lastError().databaseText()), __FILE__, __LINE__); return; } else if (!xrate.first() || xrate.value("curr_rate").isNull()) { systemError(this, tr("Could not post Invoice #%1 because of a missing exchange rate.") .arg(invchead_invcnumber)); return; } } q.exec("BEGIN;"); //TO DO: Replace this method with commit that doesn't require transaction //block that can lead to locking issues XSqlQuery rollback; rollback.prepare("ROLLBACK;"); q.prepare("SELECT postInvoice(:invchead_id) AS result;"); q.bindValue(":invchead_id", _invcheadid); q.exec(); if (q.first()) { int result = q.value("result").toInt(); if (result < 0) { rollback.exec(); systemError( this, storedProcErrorLookup("postInvoice", result), __FILE__, __LINE__); return; } else { if (distributeInventory::SeriesAdjust(result, this) == XDialog::Rejected) { rollback.exec(); QMessageBox::information( this, tr("Post Invoice"), tr("Transaction Canceled") ); return; } } } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); rollback.exec(); return; } q.exec("COMMIT;"); } if (_captive) accept(); } else if (q.lastError().type() != QSqlError::NoError) systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); }
void printCreditMemos::sPrint() { XSqlQuery cmhead( "SELECT cmhead_id, cmhead_number," " findCustomerForm(cmhead_cust_id, 'C') AS _reportname " "FROM ( SELECT cmhead_id, cmhead_number, cmhead_cust_id " " FROM cmhead " " WHERE ( (NOT cmhead_hold)" " AND (NOT COALESCE(cmhead_printed,false)) ) ) AS data " "WHERE (checkCreditMemoSitePrivs(cmhead_id));" ); if (cmhead.first()) { QPrinter printer(QPrinter::HighResolution); bool setupPrinter = TRUE; bool userCanceled = false; if (orReport::beginMultiPrint(&printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("Could not initialize printing system for multiple reports.")); return; } do { for (int i = 0; i < _creditMemoWatermarks->topLevelItemCount(); i++ ) { ParameterList params; params.append("cmhead_id", cmhead.value("cmhead_id").toInt()); params.append("showcosts", ((_creditMemoWatermarks->topLevelItem(i)->text(2) == tr("Yes")) ? "TRUE" : "FALSE")); params.append("watermark", _creditMemoWatermarks->topLevelItem(i)->text(1)); orReport report(cmhead.value("_reportname").toString(), params); if (!report.isValid()) QMessageBox::critical( this, tr("Cannot Find Credit Memo Form"), tr("<p>The Credit Memo Form '%1' for Credit " "Memo #%2 cannot be found. This Credit " "Memo cannot be printed until Customer " "Form Assignments are updated to remove " "any references to this Credit Memo Form " "or this Credit Memo Form is created." ) .arg(cmhead.value("_reportname").toString()) .arg(cmhead.value("cmhead_number").toString()) ); else { if (report.print(&printer, setupPrinter)) setupPrinter = FALSE; else { systemError( this, tr("A Printing Error occurred at printCreditMemos::%1.") .arg(__LINE__) ); orReport::endMultiPrint(&printer); return; } } if ( (_post->isChecked()) && (i == 0) ) { q.exec("BEGIN;"); //TO DO: Replace this method with commit that doesn't require transaction //block that can lead to locking issues XSqlQuery rollback; rollback.prepare("ROLLBACK;"); q.prepare("SELECT postCreditMemo(:cmhead_id, 0) AS result;"); q.bindValue(":cmhead_id", cmhead.value("cmhead_id").toInt()); q.exec(); q.first(); int result = q.value("result").toInt(); if (result < 0) { rollback.exec(); systemError( this, storedProcErrorLookup("postCreditMemo", result), __FILE__, __LINE__); } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); rollback.exec(); } else { if (distributeInventory::SeriesAdjust(result, this) == XDialog::Rejected) { rollback.exec(); QMessageBox::information( this, tr("Post Credit Memo"), tr("Transaction Canceled") ); } q.exec("COMMIT;"); } } } emit finishedPrinting(cmhead.value("cmhead_id").toInt()); } while (cmhead.next()); orReport::endMultiPrint(&printer); if (QMessageBox::question(this, tr("Mark Credit Memos as Printed?"), tr("<p>Did all of the Credit Memos print " "correctly?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) XSqlQuery().exec( "UPDATE cmhead " "SET cmhead_printed=TRUE " "WHERE (NOT COALESCE(cmhead_printed,false));" ); omfgThis->sCreditMemosUpdated(); } else QMessageBox::information( this, tr("No Credit Memos to Print"), tr("There aren't any Credit Memos to print.") ); accept(); }
void reprintInvoices::sPrint() { QPrinter printer(QPrinter::HighResolution); bool setupPrinter = TRUE; bool userCanceled = false; if (orReport::beginMultiPrint(&printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("Could not initialize printing system for multiple reports.")); return; } QList<XTreeWidgetItem*> selected = _invoice->selectedItems(); for (int i = 0; i < selected.size(); i++) { XTreeWidgetItem *cursor = (XTreeWidgetItem*)selected[i]; for (int j = 0; j < _watermarks->topLevelItemCount(); j++) { q.prepare("SELECT findCustomerForm(:cust_id, 'I') AS _reportname;"); q.bindValue(":cust_id", cursor->altId()); q.exec(); if (q.first()) { ParameterList params; params.append("invchead_id", cursor->id()); params.append("showcosts", ((_watermarks->topLevelItem(j)->text(2) == tr("Yes")) ? "TRUE" : "FALSE") ); params.append("watermark", _watermarks->topLevelItem(j)->text(1)); orReport report(q.value("_reportname").toString(), params); if (report.isValid()) { if (report.print(&printer, setupPrinter)) setupPrinter = FALSE; else { report.reportError(this); orReport::endMultiPrint(&printer); return; } } else QMessageBox::critical(this, tr("Cannot Find Invoice Form"), tr("<p>The Invoice Form '%1' cannot be found. " "One or more of the selected Invoices " "cannot be printed until a Customer Form " "Assignment is updated to remove any " "references to this Invoice Form or this " "Invoice Form is created.") .arg(q.value("_reportname").toString()) ); } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } } emit finishedPrinting(cursor->id()); } orReport::endMultiPrint(&printer); _invoice->clearSelection(); _close->setText(tr("&Close")); _print->setEnabled(FALSE); }
void printStatementsByCustomerType::sPrint() { MetaSQLQuery custm("SELECT cust_id, (cust_number || '-' || cust_name) AS customer," " findCustomerForm(cust_id, 'S') AS reportname " "FROM custinfo, custtype, aropen " "WHERE ( (cust_custtype_id=custtype_id)" " AND (aropen_cust_id=cust_id)" " AND (aropen_open)" "<? if exists(\"graceDays\") ?>" " AND (aropen_duedate < (CURRENT_DATE - <? value (\"graceDays\") ?>))" "<? endif ?>" "<? if exists(\"custtype_id\") ?>" " AND (custtype_id=<? value (\"custtype_id\") ?>)" "<? elseif exists(\"custtype_pattern\") ?>" " AND (custtype_code ~ <? value (\"custtype_pattern\") ?>)" "<? endif ?>" ") " "GROUP BY cust_id, cust_number, cust_name " "HAVING (SUM((aropen_amount - aropen_paid) *" " CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1" " ELSE 1 END) > 0) " "ORDER BY cust_number;" ); ParameterList custp; _customerTypes->appendValue(custp); if (_graceDays->value() > 0) custp.append("graceDays", _graceDays->value()); if (_dueonly->isChecked()) custp.append("graceDays", _graceDays->value()); XSqlQuery custq = custm.toQuery(custp); if (custq.first()) { QPrinter printer(QPrinter::HighResolution); bool userCanceled = false; if (orReport::beginMultiPrint(&printer, userCanceled) == false) { if(!userCanceled) systemError(this, tr("Could not initialize printing system for multiple reports.")); return; } bool doSetup = true; do { if (DEBUG) qDebug("printing statement for %s", qPrintable(custq.value("customer").toString())); message( tr("Printing Statement for Customer %1.") .arg(custq.value("customer").toString()) ); ParameterList params; params.append("cust_id", custq.value("cust_id").toInt()); if (DEBUG) qDebug("instantiating report"); orReport report(custq.value("reportname").toString(), params); if (! (report.isValid() && report.print(&printer, doSetup)) ) { report.reportError(this); orReport::endMultiPrint(&printer); reject(); } doSetup = false; if (DEBUG) qDebug("emitting finishedPrinting(%d)", custq.value("cust_id").toInt()); emit finishedPrinting(custq.value("cust_id").toInt()); } while (custq.next()); orReport::endMultiPrint(&printer); message(""); } else if (custq.lastError().type() != QSqlError::NoError) { systemError(this, custq.lastError().databaseText(), __FILE__, __LINE__); return; } else QMessageBox::information( this, tr("No Statement to Print"), tr("<p>There are no Customers whose accounts are " "past due for which Statements should be " "printed.") ); if (_captive) accept(); else _close->setText(tr("&Close")); }