void SqlStorage::_prepareStatements()
{
    _queryValidateMail = XSqlQuery(db);
    if ( ! _queryValidateMail.prepare( QLatin1String("SELECT eml_id FROM xtbatch.eml "
                                                     " WHERE :eml_hash=eml_hash::bytea;")) )
                                                     _fail( "Failed to prepare query _queryValidateMail", _queryValidateMail );

    _queryInsertMail = XSqlQuery(db);
    if ( ! _queryInsertMail.prepare( QLatin1String("INSERT INTO xtbatch.eml "
                                                   "(eml_hash, eml_date, eml_subj, eml_body, eml_msg, eml_status) "
                                                   "VALUES "
                                                   "(:eml_hash, :eml_date, :eml_subj, :eml_body,"
                                                   " :eml_msg, 'I') "
                                                   "returning eml_id;")) )
                                                    _fail( "Failed to prepare query _queryInsertMail", _queryInsertMail );

    _queryInsertAddress = XSqlQuery(db);
    if ( ! _queryInsertAddress.prepare( QLatin1String("INSERT INTO xtbatch.emladdr "
                                                      "(emladdr_eml_id, emladdr_type, emladdr_addr, emladdr_name) "
                                                      "VALUES (:emladdr_eml_id, :emladdr_type, :emladdr_addr, "
                                                      ":emladdr_name)") ) )
        _fail( "Failed to prepare query _queryInsertAddress", _queryInsertAddress );

    _queryMarkMailReady = QSqlQuery(db);
    if ( ! _queryMarkMailReady.prepare( QLatin1String("UPDATE xtbatch.eml SET eml_status = 'O' WHERE eml_id = ?") ) )
        _fail( "Failed to prepare query _queryMarkMailReady", _queryMarkMailReady );
}
Beispiel #2
0
// START_RW
void moduleSO::sPostAROpenAndDist()
{
  if ( (_metrics->value("AccountingSystem") == "RW2000") ||
       (_metrics->value("AccountingSystem") == "RealWorld91") )
  {
    if (QMessageBox::critical( omfgThis, tr("Create New AROPEN and ARDIST Files?"),
                               tr( "Creating new Export Files will delete the previous Export Files.\n"
                                   "You should make sure that the previous Export Files have been\n"
                                   "imported into RealWorld before Proceeding.\n\n"
                                   "Are you sure that you want to Create New Export Files?" ),
                                   tr("&Yes"), tr("&No"), QString::null, 0, 1  ) != 0)
      return;

    rwInterface::exportArdist(omfgThis);
    rwInterface::exportAropen(omfgThis);
  }

  if ( (_metrics->value("AccountingSystem") == "RW2000") ||
       (_metrics->value("AccountingSystem") == "RealWorld91") )
  {
    if ( QMessageBox::information( omfgThis, tr("Mark Distributions as Posted"),
                                   tr( "New ARDIST and AROPEN files have been generated in\n"
                                       "the RealWorld directory.  You should now use the RealWorld\n"
                                       "arfu/arutil tool to import these files.  After you have\n"
                                       "successfully imported the ARDIST and AROPEN files click\n"
                                       "the 'Post' button to mark these items as distributed.\n"
                                       "If, for any reason, you were unable to post the ARDIST\n"
                                       "and AROPEN files click on the 'Do Not Post' button and\n"
                                       "Re-Post Invoices to re-create the ARDIST and AROPEN files.\n" ),
                                   tr("&Post"), tr("Do &Not Post"), QString::null, 0, 1) == 0)
      XSqlQuery().exec( "SELECT postSoGLTransactions();"
                        "SELECT postAropenItems();" );
  }
}
Beispiel #3
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();
}
bool printMulticopyDocument::sPostOneDoc(XSqlQuery *docq)
{
  if (! _postQuery.isEmpty()    &&
      _data->_post->isChecked() &&
      isOnPrintedList(docq->value("docid").toInt()) &&
      ! docq->value("posted").toBool())
  {
    QString docnumber = docq->value("docnumber").toString();
    message(tr("Posting %1 #%2").arg(_data->_doctypefull, docnumber));

    ParameterList postp;
    postp.append("docid",     docq->value("docid"));
    postp.append("docnumber", docq->value("docnumber"));

    if (! _askBeforePostingQry.isEmpty())
    {
      MetaSQLQuery askm(_askBeforePostingQry);
      XSqlQuery askq = askm.toQuery(postp);
      if (ErrorReporter::error(QtCriticalMsg, this,
                               tr("Cannot Post %1").arg(docnumber),
                               askq, __FILE__, __LINE__))
        return false;
      else if (askq.value("ask").toBool() &&
               QMessageBox::question(this, tr("Post Anyway?"),
                                     _askBeforePostingMsg.arg(docnumber),
                                      QMessageBox::Yes,
                                      QMessageBox::No | QMessageBox::Default)
                  == QMessageBox::No)
        return false;
    }

    if (! _errCheckBeforePostingQry.isEmpty())
    {
      MetaSQLQuery errm(_errCheckBeforePostingQry);
      XSqlQuery errq = errm.toQuery(postp);
      if (ErrorReporter::error(QtCriticalMsg, this,
                               tr("Cannot Post %1").arg(docnumber),
                               errq, __FILE__, __LINE__))
        return false;
      else if (! errq.first() || ! errq.value("ok").toBool())
      {
        ErrorReporter::error(QtCriticalMsg, this,
                             tr("Cannot Post %1").arg(docnumber),
                             _errCheckBeforePostingMsg, __FILE__, __LINE__);
        return false;
      }
    }

    //TODO: find a way to do this without holding locks during user input
    XSqlQuery("BEGIN;");

    XSqlQuery rollback;
    rollback.prepare("ROLLBACK;");

    MetaSQLQuery postm(_postQuery);
    XSqlQuery postq = postm.toQuery(postp);
    if (postq.first())
    {
      int result = postq.value("result").toInt();
      if (result < 0)
      {
        rollback.exec();
        ErrorReporter::error(QtCriticalMsg, this,
                             tr("Cannot Post %1").arg(docnumber),
                             storedProcErrorLookup(_postFunction, result),
                             __FILE__, __LINE__);
        return false;
      }
      if (_distributeInventory &&
          (distributeInventory::SeriesAdjust(result, this) == XDialog::Rejected))
      {
        rollback.exec();
        QMessageBox::information(this, tr("Posting Canceled"),
                                 tr("Transaction Canceled") );
        return false;
      }
    }
    else if (postq.lastError().type() != QSqlError::NoError)
    {
      rollback.exec();
      ErrorReporter::error(QtCriticalMsg, this,
                           tr("Cannot Post %1").arg(docnumber),
                           postq, __FILE__, __LINE__);
      return false;
    }

    XSqlQuery("COMMIT;");

    emit posted(_data->_docid);
  }

  return true;
}
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();
}