示例#1
0
void arOpenItem::sSave()
{
  XSqlQuery arSave;
  QString storedProc;

  if (_mode == cNew)
  {

    QList<GuiErrorCheck>errors;
    errors<<GuiErrorCheck(!_docDate->isValid(), _docDate,
                            tr("You must enter a document date for this Receivable Memo before you may save it."))
          <<GuiErrorCheck(!_dueDate->isValid(), _dueDate,
                           tr("You must enter a due date for this Receivable Memo before you may save it."))
          <<GuiErrorCheck(_amount->isZero(), _amount,
                          tr("You must enter an amount for this Receivable Memo before you may save it."))
          <<GuiErrorCheck(_tax->localValue() > _amount->localValue(), _tax,
                          tr("The tax amount may not be greater than the total Receivable Memo amount."));


    if (_useAltPrepaid->isChecked())
    {
      errors<<GuiErrorCheck(_altSalescatidSelected->isChecked() && !_altSalescatid->isValid(), _altSalescatid,
                           tr("You must choose a valid Alternate Sales Category for this Receivable Memo before you may save it."))
            <<GuiErrorCheck(_altAccntidSelected->isChecked() && !_altAccntid->isValid(), _altAccntid,
                          tr("You must choose a valid Alternate Prepaid Account Number for this Receivable Memo before you may save it."));

    }

    if(GuiErrorCheck::reportErrors(this,tr("Cannot Save Receivable Memo"),errors))
        return;

    if (_docType->code() == "C")
    {
      arSave.prepare( "SELECT createARCreditMemo( :aropen_id, :cust_id, :aropen_docnumber, :aropen_ordernumber,"
                 "                           :aropen_docdate, :aropen_amount, :aropen_notes, :aropen_rsncode_id,"
                 "                           :aropen_salescat_id, :aropen_accnt_id, :aropen_duedate,"
                 "                           :aropen_terms_id, :aropen_salesrep_id, :aropen_commission_due,"
                 "                           NULL, :curr_id, NULL, NULL, :taxzone ) AS result;" );
      storedProc = "createARCreditMemo";
    }
    else if (_docType->code() == "D")
    {
      arSave.prepare( "SELECT createARDebitMemo( :aropen_id,:cust_id, NULL, :aropen_docnumber, :aropen_ordernumber,"
                 "                          :aropen_docdate, :aropen_amount, :aropen_notes, :aropen_rsncode_id,"
                 "                          :aropen_salescat_id, :aropen_accnt_id, :aropen_duedate,"
                 "                          :aropen_terms_id, :aropen_salesrep_id, :aropen_commission_due, "
                 "                          :curr_id, :taxzone ) AS result;" );
      storedProc = "createARDebitMemo";
    }

    arSave.bindValue(":cust_id", _cust->id());
  }
  else if (_mode == cEdit)
  {
    if (_cAmount != _amount->localValue())
      if ( QMessageBox::warning( this, tr("A/R Open Amount Changed"),
                                 tr( "You are changing the open amount of this A/R Open Item.  If you do not post a G/L Transaction\n"
                                     "to distribute this change then the A/R Open Item total will be out of balance with the\n"
                                     "A/R Trial Balance(s).\n"
                                     "Are you sure that you want to save this change?" ),
                                 tr("Yes"), tr("No"), QString::null ) == 1 )
        return;

    arSave.prepare( "UPDATE aropen "
               "SET aropen_duedate=:aropen_duedate,"
               "    aropen_terms_id=:aropen_terms_id, aropen_salesrep_id=:aropen_salesrep_id,"
               "    aropen_amount=:aropen_amount,"
               "    aropen_commission_due=:aropen_commission_due, aropen_notes=:aropen_notes,"
               "    aropen_rsncode_id=:aropen_rsncode_id, "
               "    aropen_curr_id=:curr_id, "
               "    aropen_taxzone_id=:taxzone "
               "WHERE (aropen_id=:aropen_id);" );
  }

  if (_aropenid != -1)
    arSave.bindValue(":aropen_id", _aropenid);
  arSave.bindValue(":aropen_docdate", _docDate->date());
  arSave.bindValue(":aropen_duedate", _dueDate->date());
  arSave.bindValue(":aropen_docnumber", _docNumber->text());
  arSave.bindValue(":aropen_ordernumber", _orderNumber->text());
  arSave.bindValue(":aropen_terms_id", _terms->id());

  if (_salesrep->isValid())
    arSave.bindValue(":aropen_salesrep_id", _salesrep->id());

  arSave.bindValue(":aropen_amount", _amount->localValue());
  arSave.bindValue(":aropen_commission_due", _commissionDue->baseValue());
  arSave.bindValue(":aropen_notes",          _notes->toPlainText());
  arSave.bindValue(":aropen_rsncode_id", _rsnCode->id());
  arSave.bindValue(":curr_id", _amount->id());
  if (_taxzone->isValid())
    arSave.bindValue(":taxzone", _taxzone->id());

  if(_useAltPrepaid->isChecked() && _altSalescatidSelected->isChecked())
    arSave.bindValue(":aropen_salescat_id", _altSalescatid->id());
  else
    arSave.bindValue(":aropen_salescat_id", -1);
  if(_useAltPrepaid->isChecked() && _altAccntidSelected->isChecked())
    arSave.bindValue(":aropen_accnt_id", _altAccntid->id());
  else
    arSave.bindValue(":aropen_accnt_id", -1);

  arSave.bindValue(":aropen_doctype", _docType->code());

  if (arSave.exec())
  {
    if (_mode == cEdit)
      done(_aropenid);
    else
    {
      arSave.first();
      if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Posting A/R %1M").arg(_docType->code()),
                                    arSave, __FILE__, __LINE__))
      {
        reset();
        return;
      }
      _last = arSave.value("result").toInt();
      if (_last < 0)
      {
        if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Posting A/R %1M").arg(_docType->code()),
                                    arSave, __FILE__, __LINE__))
        {
          reset();
        }
        return;
      }
      if(_printOnPost->isChecked())
        sPrintOnPost(_last);
      reset();
    }
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Posting A/R %1M").arg(_docType->code()),
                                arSave, __FILE__, __LINE__))
  {
    if (_mode == cNew)
      reset();
    return;
  }
}
示例#2
0
void apOpenItem::sSave()
{
  XSqlQuery saveOpenItem;
  if (_mode == cNew)
  {
    QList<GuiErrorCheck> errors;
    errors << GuiErrorCheck(!_docDate->isValid(), _docDate,
                            tr("<p>You must enter a Document Date for this A/P Memo "
                               "before you may save it"))
    << GuiErrorCheck(!_dueDate->isValid(), _dueDate,
                     tr("<p>You must enter a Due Date for this A/P Memo "
                        "before you may save it"))
    << GuiErrorCheck(_amount->isZero(), _amount,
                     tr("<p>You must enter an amount for this A/P Memo "
                        "before you may save it"))
    << GuiErrorCheck(_tax->localValue() > _amount->localValue(), _tax,
                     tr("The tax amount may not be greater than the total A/P Memo amount."))
    << GuiErrorCheck(!_usePrepaid->isChecked() && !_accntId->isValid(), _accntId,
                     tr("<p>You must choose a valid Distribution "
                        "Account Number for this A/P Memo before you "
                        "may save it."))
    ;
    if (GuiErrorCheck::reportErrors(this, tr("Cannot Save A/P Memo"), errors))
      return;
    
    QString tmpFunctionName;
    QString queryStr;

    if (_docType->code() == "C")
      tmpFunctionName = "createAPCreditMemo";
    else if (_docType->code() == "D")
      tmpFunctionName = "createAPDebitMemo";
    else
    {
      ErrorReporter::error(QtCriticalMsg, this, tr("Cannot Save A/P Memo"),
                           tr("Internal Error: _docType has an invalid document type of %1")
                           .arg(_docType->currentIndex()), __FILE__, __LINE__);
      return;
    }

    queryStr = "SELECT " + tmpFunctionName + "( :apopen_id, :vend_id, " +
		(_journalNumber->text().isEmpty() ?
		      QString("fetchJournalNumber('AP-MISC')") : _journalNumber->text()) +
	       ", :apopen_docnumber, :apopen_ponumber, :apopen_docdate,"
	       "  :apopen_amount, :apopen_notes, :apopen_accnt_id,"
	       "  :apopen_duedate, :apopen_terms_id, :curr_id, :apopen_taxzone_id ) AS result;";
	
    saveOpenItem.prepare(queryStr);
    saveOpenItem.bindValue(":vend_id", _vend->id());
    saveOpenItem.bindValue(":apopen_docdate", _docDate->date());
  }
  else if (_mode == cEdit)
  {
    if (_cAmount != _amount->localValue())
      if ( QMessageBox::warning( this, tr("A/P Open Amount Changed"),
                                 tr( "<p>You are changing the open amount of "
                                    "this A/P Open Item.  If you do not post a "
                                    "G/L Transaction to distribute this change "
                                    "then the A/P Open Item total will be out "
                                    "of balance with the A/P Trial Balance(s). "
                                    "Are you sure that you want to save this "
                                    "change?" ),
                                 tr("Yes"), tr("No"), QString::null ) == 1 )
        return;

    saveOpenItem.prepare( "UPDATE apopen "
	       "SET apopen_doctype=:apopen_doctype,"
               "    apopen_ponumber=:apopen_ponumber, apopen_docnumber=:apopen_docnumber,"
               "    apopen_amount=:apopen_amount,"
               "    apopen_terms_id=:apopen_terms_id, "
	       "    apopen_notes=:apopen_notes, "
               "    apopen_curr_id=:curr_id, "
	       "    apopen_status = :apopen_status, "
               "    apopen_taxzone_id = :apopen_taxzone_id "
               "WHERE (apopen_id=:apopen_id);" );
  }

  if (_apopenid != -1)
    saveOpenItem.bindValue(":apopen_id", _apopenid);
  saveOpenItem.bindValue(":apopen_docnumber", _docNumber->text());
  saveOpenItem.bindValue(":apopen_duedate", _dueDate->date());
  saveOpenItem.bindValue(":apopen_ponumber", _poNumber->text());
  saveOpenItem.bindValue(":apopen_amount", _amount->localValue());
  saveOpenItem.bindValue(":apopen_notes",   _notes->toPlainText());
  saveOpenItem.bindValue(":curr_id", _amount->id());
  saveOpenItem.bindValue(":apopen_terms_id", _terms->id());
  if (_taxzone->isValid())
    saveOpenItem.bindValue(":apopen_taxzone_id", _taxzone->id());
  QString temp;
  if (_status->id() == 1)
    temp = "O" ;
  else
	temp = "H" ;
  saveOpenItem.bindValue(":apopen_status", temp);
  if(!_usePrepaid->isChecked())
    saveOpenItem.bindValue(":apopen_accnt_id", _accntId->id());
  else
    saveOpenItem.bindValue(":apopen_accnt_id", -1);

  saveOpenItem.bindValue(":apopen_doctype", _docType->code());

  saveOpenItem.exec();
  if (saveOpenItem.first())
  {
    if (_mode == cNew)
    {
      if (saveOpenItem.value("result").toInt() == -1)
      {
        QMessageBox::critical( this, tr("Cannot Create A/P Memo"),
                               tr( "<p>The A/P Memo cannot be created as there "
                                  "are missing A/P Account Assignments for the "
                                  "selected Vendor. You must create an A/P "
                                  "Account Assignment for the selected "
                                  "Vendor's Vendor Type before you may create "
                                  "this A/P Memo." ) );
        return;
      }
    }
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Cannot Create A/P Memo"),
                                saveOpenItem, __FILE__, __LINE__))
  {
    return;
  }

  if (_mode == cEdit)
  {
    if(_printOnPost->isChecked())
      sPrintOnPost(_apopenid);
    done(_apopenid);
  }
  else
  {
    if(_printOnPost->isChecked())
    {
      if (_docType->code() == "C")
//    Credit Memo function returns journal# not apopenid so we have to go find it
      {
        XSqlQuery getCMid;
        getCMid.prepare("SELECT apopen_id AS result FROM apopen "
                        "WHERE ((apopen_doctype = 'C') "
                        " AND (apopen_docnumber = :docnumber) "
                        " AND (apopen_journalnumber = :journal));");
        getCMid.bindValue(":docnumber", _docNumber->text());
        getCMid.bindValue(":journal", saveOpenItem.value("result").toInt());
        getCMid.exec();
        if (ErrorReporter::error(QtCriticalMsg, this, tr("Returning apopenid"),
                           getCMid, __FILE__, __LINE__))
        {
          return;
        }
        if (getCMid.first())
        {
          sPrintOnPost(getCMid.value("result").toInt());
        }
      }
      else
      {
//      The Debit Memo returns apopenid so is fine
        sPrintOnPost(saveOpenItem.value("result").toInt());
      }
    }
    done(saveOpenItem.value("result").toInt());
  }
}
示例#3
0
void arOpenItem::sSave()
{
  QString storedProc;

  if (_mode == cNew)
  {
    if (!_docDate->isValid())
    {
      QMessageBox::critical( this, tr("Cannot Save Receivable Memo"),
                             tr("You must enter a date for this Receivable Memo before you may save it") );
      _docDate->setFocus();
      return;
    }

    if (!_dueDate->isValid())
    {
      QMessageBox::critical( this, tr("Cannot Save Receivable Memo"),
                             tr("You must enter a date for this Receivable Memo before you may save it") );
      _dueDate->setFocus();
      return;
    }

    if (_amount->isZero())
    {
      QMessageBox::critical( this, tr("Cannot Save Receivable Memo"),
                             tr("You must enter an amount for this Receivable Memo before you may save it") );
      _amount->setFocus();
      return;
    }
    
    if(_tax->localValue() > _amount->localValue())
    {
      QMessageBox::critical( this, tr("Cannot Save Receivable Memo"),
                             tr("The tax amount may not be greater than the total Receivable Memo amount.") );
      return;
    }

    if (_altPrepaid->isChecked())
    {
      if(_altSalescatidSelected->isChecked() && !_altSalescatid->isValid())
      {
        QMessageBox::critical( this, tr("Cannot Save Receivable Memo"),
                               tr("You must choose a valid Alternate Sales Category for this Receivable Memo before you may save it") );
        return;
      }

      if(_altAccntidSelected->isChecked() && !_altAccntid->isValid())
      {
        QMessageBox::critical( this, tr("Cannot Save Receivable Memo"),
                               tr("You must choose a valid Alternate Prepaid Account Number for this Receivable Memo before you may save it.") );
        return;
      }
    }

    if (_docType->currentIndex() == 0)
    {
      q.prepare( "SELECT createARCreditMemo( :aropen_id, :cust_id, :aropen_docnumber, :aropen_ordernumber,"
                 "                           :aropen_docdate, :aropen_amount, :aropen_notes, :aropen_rsncode_id,"
                 "                           :aropen_salescat_id, :aropen_accnt_id, :aropen_duedate,"
                 "                           :aropen_terms_id, :aropen_salesrep_id, :aropen_commission_due,"
                 "                           :curr_id ) AS result;" );
      storedProc = "createARCreditMemo";
    }
    else if (_docType->currentIndex() == 1)
    {
      q.prepare( "SELECT createARDebitMemo( :aropen_id,:cust_id, NULL, :aropen_docnumber, :aropen_ordernumber,"
                 "                          :aropen_docdate, :aropen_amount, :aropen_notes, :aropen_rsncode_id,"
                 "                          :aropen_salescat_id, :aropen_accnt_id, :aropen_duedate,"
                 "                          :aropen_terms_id, :aropen_salesrep_id, :aropen_commission_due, "
                 "                          :curr_id ) AS result;" );
      storedProc = "createARCreditMemo";
    }

    q.bindValue(":cust_id", _cust->id());
  }
  else if (_mode == cEdit)
  {
    if (_cAmount != _amount->localValue())
      if ( QMessageBox::warning( this, tr("A/R Open Amount Changed"),
                                 tr( "You are changing the open amount of this A/R Open Item.  If you do not post a G/L Transaction\n"
                                     "to distribute this change then the A/R Open Item total will be out of balance with the\n"
                                     "A/R Trial Balance(s).\n"
                                     "Are you sure that you want to save this change?" ),
                                 tr("Yes"), tr("No"), QString::null ) == 1 )
        return;

    q.prepare( "UPDATE aropen "
               "SET aropen_duedate=:aropen_duedate,"
               "    aropen_terms_id=:aropen_terms_id, aropen_salesrep_id=:aropen_salesrep_id,"
               "    aropen_amount=:aropen_amount,"
               "    aropen_commission_due=:aropen_commission_due, aropen_notes=:aropen_notes,"
               "    aropen_rsncode_id=:aropen_rsncode_id, "
	       "    aropen_curr_id=:curr_id "
               "WHERE (aropen_id=:aropen_id);" );
  }

  if (_aropenid != -1)
    q.bindValue(":aropen_id", _aropenid);
  q.bindValue(":aropen_docdate", _docDate->date());
  q.bindValue(":aropen_duedate", _dueDate->date());
  q.bindValue(":aropen_docnumber", _docNumber->text());
  q.bindValue(":aropen_ordernumber", _orderNumber->text());
  q.bindValue(":aropen_terms_id", _terms->id());
  q.bindValue(":aropen_salesrep_id", _salesrep->id());
  q.bindValue(":aropen_amount", _amount->localValue());
  q.bindValue(":aropen_commission_due", _commissionDue->baseValue());
  q.bindValue(":aropen_notes",          _notes->toPlainText());
  q.bindValue(":aropen_rsncode_id", _rsnCode->id());
  q.bindValue(":curr_id", _amount->id());
  if(_altPrepaid->isChecked() && _altSalescatidSelected->isChecked())
    q.bindValue(":aropen_salescat_id", _altSalescatid->id());
  else
    q.bindValue(":aropen_salescat_id", -1);
  if(_altPrepaid->isChecked() && _altAccntidSelected->isChecked())
    q.bindValue(":aropen_accnt_id", _altAccntid->id());
  else
    q.bindValue(":aropen_accnt_id", -1);

  switch (_docType->currentIndex())
  {
    case 0:
      q.bindValue(":aropen_doctype", "C");
      break;

    case 1:
      q.bindValue(":aropen_doctype", "D");
      break;

    case 2:
      q.bindValue(":aropen_doctype", "I");
      break;

    case 3:
      q.bindValue(":aropen_doctype", "R");
      break;
  }

  if (q.exec())
  {
    if (_mode == cEdit)
      done(_aropenid);
    else
    {
      q.first();
      if (q.lastError().type() != QSqlError::NoError)
      {
	systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
        reset();
	return;
      }
      _last = q.value("result").toInt();
      if (_last < 0)
      {
	systemError(this, storedProc.isEmpty() ?
			    tr("Saving Credit Memo Failed: %1").arg(_last) :
			    storedProcErrorLookup(storedProc, _last),
		    __FILE__, __LINE__);
        reset();
	return;
      }
      reset();
    }
  }
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    if (_mode == cNew)
      reset();
    return;
  }

  q.exec("SELECT MAX(aropen_id) AS max_aropen_id FROM aropen;");
  if (q.first())
  {
    if(_printOnPost->isChecked())
    {
      sPrintOnPost(q.value("max_aropen_id").toInt()); 
    }
  }
}