Пример #1
0
void printCreditMemos::sPrint()
{
  XSqlQuery cmhead( "SELECT cmhead_id, cmhead_number,"
                    "       findCustomerForm(cmhead_cust_id, 'C') AS _reportname "
                    "FROM cmhead "
                    "WHERE ( (NOT cmhead_hold)"
                    " AND (NOT cmhead_printed) );");
  if (cmhead.first())
  {
    QPrinter printer;
    bool     setupPrinter  = TRUE;
    int      itemlocSeries = 0;
    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( "The Credit Memo Form '%1' for Credit Memo #%2 cannot be found.\n"
                                     "This Credit Memo cannot be printed until Customer Form Assignments are updated to remove\n"
                                     "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())
        {
          XSqlQuery postCreditMemo;
          postCreditMemo.prepare("SELECT postCreditMemo(:cmhead_id, :itemlocSeries) AS result;");
          postCreditMemo.bindValue(":cmhead_id", cmhead.value("cmhead_id").toInt());
          postCreditMemo.bindValue(":itemlocSeries", itemlocSeries);
          postCreditMemo.exec();
          if (postCreditMemo.first())
            itemlocSeries = postCreditMemo.value("result").toInt();
          else
            systemError(this, tr("A System Error occurred at %1::%2.")
                              .arg(__FILE__)
                              .arg(__LINE__) );
        }
      }
    }
    while (cmhead.next());
    orReport::endMultiPrint(&printer);

    if ( QMessageBox::information( this, tr("Mark Credit Memos as Printed?"),
                                   tr("Did all of the Credit Memos print correctly?"),
                                   tr("&Yes"), tr("&No"), QString::null, 0, 1) == 0)
      XSqlQuery().exec( "UPDATE cmhead "
                        "SET cmhead_printed=TRUE "
                        "WHERE (NOT cmhead_printed);" );

    omfgThis->sCreditMemosUpdated();
  }
  else
    QMessageBox::information( this, tr("No Credit Memos to Print"),
                              tr("There aren't any Credit Memos to print.") );

  accept();
}
Пример #2
0
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();
}