void externalShipping::sSave()
{
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(!_order->isValid(), _order,
                          tr("You must enter a valid Order Number for this External Shipping Record "
                             "before continuing"))
         << GuiErrorCheck(!_shipment->isValid(), _shipment,
                          tr("You must select a valid Shipment Number for this External Shipping Record "
                             "before continuing"))
         << GuiErrorCheck(_shipper->text().isEmpty(), _shipper,
                          tr("You must select a valid Shipper for this External Shipping Record "
                             "before continuing"))
         << GuiErrorCheck(_packnumTracknum->text().isEmpty(), _packnumTracknum,
                          tr("You must select a valid Package Tracking Number for this External Shipping Record "
                             "before continuing"))
         << GuiErrorCheck(_tracknum->text().isEmpty(), _tracknum,
                          tr("You must select a valid Tracking Number for this External Shipping Record "
                             "before continuing"))
     ;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Shipping Record"), errors))
    return;
  else
  {
    _screen->save();
  }
  if (_screen->mode() != Screen::New)
  {
    accept();
  }
  else
  {
    _order->setFocus();
  }
}
Пример #2
0
bool dspTaxReturn::setParams(ParameterList &params)
{
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(!_taxAuth->isValid(), _taxAuth,
                          tr("You must select a Tax Authority.") );
  errors << GuiErrorCheck(!_dates->startDate().isValid(), _dates,
                          tr("You must enter a valid Start Date to print this report.") );
  errors << GuiErrorCheck(!_dates->endDate().isValid(), _dates,
                          tr("You must enter a valid End Date to print this report.") );

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Execute Tax Return"), errors))
      return false;
  
  if (_metrics->boolean("CashBasedTax"))
    params.append("cashbasedtax", true);
    
  if (_distDate->isChecked())
    params.append("distDate");

  _dates->appendValue(params);
 
  params.append("taxauth_id",_taxAuth->id());
  params.append("taxauth", _taxAuth->currentText());
    
  params.append("sales_taxable",tr("Sales Taxable"));
  params.append("sales_nontaxable",tr("Sales Zero-Rated"));
  params.append("purchases_taxable",tr("Purchases Taxable "));
  params.append("purchases_nontaxable",tr("Purchases Zero-Rated"));
  params.append("reversecharges", tr("Reverse Charge"));

  return true;
}
Пример #3
0
void taxCode::sSave()
{
  XSqlQuery taxSave;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_code->text().trimmed().isEmpty(), _code, 
                          tr("You must specify a Code for this Tax.") )
         << GuiErrorCheck(!_account->isValid(), _account,
                          tr("You must select a Ledger Account for this Tax.") )
         << GuiErrorCheck(_metrics->boolean("CashBasedTax") && !_distaccount->isValid(), _distaccount,
                          tr("You must select a Distribution Ledger Account for this Tax.") )
  ;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Tax Code"), errors))
      return;

  taxSave.prepare("SELECT tax_id"
                  "  FROM tax"
                  " WHERE((tax_id!= :tax_id)"
                  "   AND (tax_code=:tax_code));");
  taxSave.bindValue(":tax_id", _taxid);
  taxSave.bindValue(":tax_code", _code->text().trimmed());
  taxSave.exec();
  if(taxSave.first())
  {
    QMessageBox::critical(this, tr("Duplicate Tax Code"),
      tr("A Tax Code already exists for the parameters specified.") );
    _code->setFocus();
    return;
  }

  taxSave.prepare("UPDATE tax "
                  "SET tax_code=:tax_code, tax_descrip=:tax_descrip,"
                  "    tax_sales_accnt_id=:tax_sales_accnt_id,"
                  "    tax_dist_accnt_id=:tax_dist_accnt_id,"
                  "    tax_taxclass_id=:tax_taxclass_id,"
                  "    tax_taxauth_id=:tax_taxauth_id,"
                  "    tax_basis_tax_id=:tax_basis_tax_id "
                  "WHERE (tax_id=:tax_id);" );
  
  taxSave.bindValue(":tax_code", _code->text().trimmed());
  taxSave.bindValue(":tax_descrip", _description->text());
  if(_account->isValid())
     taxSave.bindValue(":tax_sales_accnt_id", _account->id());
  if(_distaccount->isValid())
    taxSave.bindValue(":tax_dist_accnt_id", _distaccount->id());
  if(_taxauth->isValid())
    taxSave.bindValue(":tax_taxauth_id", _taxauth->id());
  if(_taxClass->isValid())
    taxSave.bindValue(":tax_taxclass_id", _taxClass->id());
  if(_basis->isValid())
    taxSave.bindValue(":tax_basis_tax_id", _basis->id());
  taxSave.bindValue(":tax_id", _taxid); 
  taxSave.exec();
  if (ErrorReporter::error(QtCriticalMsg, this, tr("Saving Tax Code"),
                           taxSave, __FILE__, __LINE__))
    return;

  done (_taxid);
}
Пример #4
0
void uomConv::sSave()
{
    XSqlQuery uomSave;
    bool valid;
    QList<GuiErrorCheck> errors;
    errors << GuiErrorCheck(!_uomFrom->isValid(), _uomFrom,
                            tr("You must select a From UOM."))
           << GuiErrorCheck(!_uomTo->isValid(), _uomTo,
                            tr("You must select a To UOM."))
           << GuiErrorCheck(_fromValue->toDouble(&valid) == 0, _fromValue,
                            tr("You must enter a valid Ratio before saving this UOM Conversion."))
           << GuiErrorCheck(_toValue->toDouble(&valid) == 0, _toValue,
                            tr("You must enter a valid Ratio before saving this UOM Conversion."))
           ;

    if (GuiErrorCheck::reportErrors(this, tr("Cannot Save UOM Conversion"), errors))
        return;

    if (_mode == cEdit)
        uomSave.prepare( "UPDATE uomconv "
                         "   SET uomconv_from_value=:uomconv_from_value,"
                         "       uomconv_to_value=:uomconv_to_value,"
                         "       uomconv_fractional=:uomconv_fractional "
                         " WHERE(uomconv_id=:uomconv_id);" );
    else if (_mode == cNew)
    {
        uomSave.exec("SELECT NEXTVAL('uomconv_uomconv_id_seq') AS uomconv_id");
        if (uomSave.first())
            _uomconvid = uomSave.value("uomconv_id").toInt();
        else
        {
            systemError(this, tr("A System Error occurred at %1::%2.")
                        .arg(__FILE__)
                        .arg(__LINE__) );
            return;
        }

        uomSave.prepare( "INSERT INTO uomconv "
                         "( uomconv_id, uomconv_from_uom_id, uomconv_from_value, uomconv_to_uom_id, uomconv_to_value, uomconv_fractional ) "
                         "VALUES "
                         "( :uomconv_id, :uomconv_from_uom_id, :uomconv_from_value, :uomconv_to_uom_id, :uomconv_to_value, :uomconv_fractional );" );
    }

    uomSave.bindValue(":uomconv_id", _uomconvid);
    uomSave.bindValue(":uomconv_from_uom_id", _uomFrom->id());
    uomSave.bindValue(":uomconv_to_uom_id", _uomTo->id());
    uomSave.bindValue(":uomconv_from_value", _fromValue->toDouble());
    uomSave.bindValue(":uomconv_to_value", _toValue->toDouble());
    uomSave.bindValue(":uomconv_fractional", QVariant(_fractional->isChecked()));
    uomSave.exec();

    accept();
}
Пример #5
0
void currency::sSave()
{
  XSqlQuery currencySave;
  sConfirmBaseFlag();

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_currName->text().trimmed().isEmpty(), _currName,
                          tr("Currency name is required."))
         << GuiErrorCheck(_currAbbr->text().trimmed().isEmpty()
                       && _currSymbol->text().trimmed().isEmpty(), _currSymbol,
                          tr("Either the currency symbol or abbreviation must be "
		              "supplied.\n(Both would be better)."))
         << GuiErrorCheck(_currAbbr->text().length() > 3, _currAbbr,
                          tr("The currency abbreviation must have "
		         "3 or fewer characters.\n"
			 "ISO abbreviations are exactly 3 characters long."))
    ;
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Currency"), errors))
    return;
  
  if (_mode == cNew)
  {
      currencySave.prepare( "INSERT INTO curr_symbol "
		 "(  curr_name,  curr_symbol,  curr_abbr,  curr_base ) "
		 "VALUES "
		 "( :curr_name, :curr_symbol, :curr_abbr, :curr_base );" );
  }
  else if (_mode == cEdit)
  {
    currencySave.prepare( "UPDATE curr_symbol "
               "SET curr_name=:curr_name, curr_symbol=:curr_symbol, "
	       "    curr_abbr=:curr_abbr, curr_base = :curr_base "
               "WHERE (curr_id=:curr_id);" );
    currencySave.bindValue(":curr_id", _currid);
   }
  
  currencySave.bindValue(":curr_name", _currName->text().trimmed());
  currencySave.bindValue(":curr_symbol", _currSymbol->text().trimmed());
  currencySave.bindValue(":curr_abbr", _currAbbr->text().trimmed());
  currencySave.bindValue(":curr_base", QVariant(_currBase->isChecked()));
  currencySave.exec();

  if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Currency Information"),
                                currencySave, __FILE__, __LINE__))
  {
    return;
  }
  
  done(_currid);
}
Пример #6
0
void saleType::sSave()
{
  XSqlQuery saleTypeSave;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_code->text().length() == 0, _code,
                          tr("You must enter a valid Sale Type Code "
                             "before continuing"))
     ;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Sale Type"), errors))
    return;

  MetaSQLQuery mql = mqlLoad("saletype", "table");
  ParameterList params;
  if (_mode == cNew)
    params.append("NewMode");
  else
  {
    params.append("EditMode");
    params.append("saletype_id", _saletypeid);
  }
  params.append("saletype_code", _code->text());
  params.append("saletype_descr", _description->text());
  params.append("saletype_active", QVariant(_active->isChecked()));
  saleTypeSave = mql.toQuery(params);
  if (saleTypeSave.first() && _mode == cNew)
    _saletypeid = saleTypeSave.value("saletype_id").toInt();

  done(_saletypeid);
}
Пример #7
0
void copyBudget::sCopy()
{
  XSqlQuery copyCopy;

  QList<GuiErrorCheck>errors;
  errors<<GuiErrorCheck(_name->text().trimmed().isEmpty(), _name,
                        tr("Budget Name is a required field."));

  if(GuiErrorCheck::reportErrors(this,tr("Cannot Copy Budget"),errors))
      return;

  copyCopy.prepare("SELECT copyBudget(:budghead_id, :name, :descrip, :interval) AS result;");
  copyCopy.bindValue(":budghead_id", _budgheadid);
  copyCopy.bindValue(":name", _name->text());
  copyCopy.bindValue(":descrip", _descrip->text());
  copyCopy.bindValue(":interval", _interval->value());
  copyCopy.exec();

  if(copyCopy.first() && copyCopy.value("result").toInt() < 0)
  {
    QMessageBox::information( this, tr("Error Copying Budget"),
                              tr( "There was an error copying the budget. Make sure there are valid periods\n"
                                  "In the future to match the current periods of the budget being copied plus\n"
                                  "the period inteval." ));
    return;
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Copying Budget"),
                                copyCopy, __FILE__, __LINE__))
  {
    return;
  }

  accept();
}
Пример #8
0
void adjustInvValue::sPost()
{
  XSqlQuery adjustPost;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_itemsiteid == -1, _item,
                          tr("You must select a valid Itemsite before posting this transaction.") )
         << GuiErrorCheck(_newValue->text().length() == 0, _newValue,
                          tr("<p>You must enter a valid New Value before posting this transaction.") )
         << GuiErrorCheck(_altAccnt->isChecked() && ! _accnt->isValid(), _accnt,
                          tr("<p>You must enter a valid Alternate G/L Account before posting this transaction.") )
         << GuiErrorCheck(_qtyonhand <= 0.0, _item,
                          tr("You must select an Itemsite with a positive Qty on Hand before posting this transaction.") )
    ;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Post Transaction"), errors))
    return;

  ParameterList params;
  params.append("newValue", _newValue->toDouble());
  params.append("itemsite_id", _itemsiteid);
  if (_altAccnt->isChecked() && _accnt->id() != -1)
    params.append("accnt_id", _accnt->id());

  QString sql = "SELECT adjustInvValue(<? value('itemsite_id') ?>, "
                "                      <? value('newValue') ?>, "
                "                      <? value('accnt_id') ?>) AS result;";

  MetaSQLQuery mql(sql);
  adjustPost = mql.toQuery(params);
  if (adjustPost.lastError().type() != QSqlError::NoError)
  {
    systemError(this, adjustPost.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  QMessageBox::information( this, tr("Post Successful"),
                         tr( "<p>Value successfully updated. ") );
  sPopulate();
  _newValue->clear();
}
Пример #9
0
void cashReceiptItem::sSave()
{
  double epsilon = 0.005;
  QList<GuiErrorCheck> errors;
  errors<< GuiErrorCheck((_amountToApply->localValue() + _discountAmount->localValue()) - _openAmount->localValue() > epsilon, _amountToApply,
                         tr("You may not apply more than the balance of this item."))
  ;
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Apply"), errors))
    return;

  int sense = 1;
  if (_docType->text() == "C" || _docType->text() == "R")
    sense = -1;

  if (_mode == cNew)
  {
    XSqlQuery cashrcptitemid("SELECT NEXTVAL('cashrcptitem_cashrcptitem_id_seq') AS _cashrcptitem_id;");
    if (cashrcptitemid.first())
      _cashrcptitemid = cashrcptitemid.value("_cashrcptitem_id").toInt();

    XSqlQuery newReceipt;
    newReceipt.prepare( "INSERT INTO cashrcptitem "
                        "( cashrcptitem_id, cashrcptitem_cashrcpt_id,"
                        "  cashrcptitem_aropen_id, cashrcptitem_amount, cashrcptitem_discount ) "
                        "VALUES "
                        "( :cashrcptitem_id, :cashrcptitem_cashrcpt_id,"
                        "  :cashrcptitem_aropen_id, :cashrcptitem_amount, :cashrcptitem_discount );" );
    newReceipt.bindValue(":cashrcptitem_id", _cashrcptitemid);
    newReceipt.bindValue(":cashrcptitem_cashrcpt_id", _cashrcptid);
    newReceipt.bindValue(":cashrcptitem_aropen_id", _aropenid);
    newReceipt.bindValue(":cashrcptitem_amount", _amountToApply->localValue() * sense);
    newReceipt.bindValue(":cashrcptitem_discount", _discountAmount->localValue() * sense);

    newReceipt.exec();
  }
  else if (_mode == cEdit)
  {
    XSqlQuery updateReceipt;
    updateReceipt.prepare( "UPDATE cashrcptitem "
                           "SET cashrcptitem_amount=:cashrcptitem_amount, "
						   "cashrcptitem_discount=:cashrcptitem_discount "
                           "WHERE (cashrcptitem_id=:cashrcptitem_id);" );
    updateReceipt.bindValue(":cashrcptitem_id", _cashrcptitemid);
    updateReceipt.bindValue(":cashrcptitem_amount", _amountToApply->localValue() * sense);
    updateReceipt.bindValue(":cashrcptitem_discount", _discountAmount->localValue() * sense);

    updateReceipt.exec();
  }

  done(_cashrcptitemid);
}
bool printShippingForms::isOkToPrint()
{
  QList<GuiErrorCheck> errors;
  errors<< GuiErrorCheck(!_printNew->isChecked() && !_printDirty->isChecked(),
                         _printNew,
                         tr("You must indicate if you wish to print Shipping "
                            "Forms for New and/or Changed Shipments."))
    ;
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Print Shipping Forms"),
                                  errors))
    return false;

  return true;
}
Пример #11
0
bool dspCheckRegister::setParams(ParameterList &pParams)
{

  QList<GuiErrorCheck> errors;
  errors<< GuiErrorCheck(!_dates->allValid(), _dates,
            tr("Invalid dates specified. Please specify a valid date range."))
  ;
  if (GuiErrorCheck::reportErrors(this, tr("Invalid Dates"), errors))
    return false;
  
  if(_recipGroup->isChecked())
  {
    pParams.append("recip", 100);
    if(_vendRB->isChecked())
    {
      pParams.append("recip_type_v", 100);
      if(_vend->isValid())
      {
        pParams.append("recip_id", _vend->id());
      }
    }
    if(_custRB->isChecked())
    {
      pParams.append("recip_type_c", 100);
      if(_cust->isValid())
      {
        pParams.append("recip_id", _cust->id());
      }
    }
    if(_taxauthRB->isChecked())
    {
      pParams.append("recip_type_t", 100);
      pParams.append("recip_id", _taxauth_2->id());
    }
  }

  if(_checkNumber->text() != "")
  {
    pParams.append("check_number", _checkNumber->text());
  }
  
  pParams.append("bankaccnt_id", _bankaccnt->id());
  _dates->appendValue(pParams);

  if(_showDetail->isChecked())
    pParams.append("showDetail");
  
  return true;
}
Пример #12
0
void customerGroup::sSave()
{
  XSqlQuery customerSave;

  QList<GuiErrorCheck>errors;
  errors<<GuiErrorCheck(_name->text().trimmed().isEmpty(), _name,
                        tr("You cannot have an empty name."));

  if(GuiErrorCheck::reportErrors(this,tr("Cannot Save Customer Group"),errors))
      return;

  customerSave.prepare("SELECT custgrp_id"
            "  FROM custgrp"
            " WHERE((custgrp_name=:custgrp_name)"
            "   AND (custgrp_id != :custgrp_id))");
  customerSave.bindValue(":custgrp_id", _custgrpid);
  customerSave.bindValue(":custgrp_name", _name->text());
  customerSave.exec();
  if(customerSave.first())
  {
    QMessageBox::warning(this, tr("Cannot Save Customer Group"),
      tr("You cannot have a duplicate name."));
    _name->setFocus();
    return;
  }

  if (_mode == cNew)
    customerSave.prepare( "INSERT INTO custgrp "
               "(custgrp_id, custgrp_name, custgrp_descrip) "
               "VALUES "
               "(:custgrp_id, :custgrp_name, :custgrp_descrip);" );
  else if (_mode == cEdit)
    customerSave.prepare( "UPDATE custgrp "
               "SET custgrp_name=:custgrp_name, custgrp_descrip=:custgrp_descrip "
               "WHERE (custgrp_id=:custgrp_id);" );

  customerSave.bindValue(":custgrp_id", _custgrpid);
  customerSave.bindValue(":custgrp_name", _name->text());
  customerSave.bindValue(":custgrp_descrip", _descrip->text().trimmed());
  customerSave.exec();
  if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Customer Group"),
                                customerSave, __FILE__, __LINE__))
  {
    return;
  }

  done(_custgrpid);
}
Пример #13
0
void classCode::sSave()
{
  XSqlQuery classSave;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_classCode->text().length() == 0, _classCode,
                          tr("You must enter a valid Class Code "
                             "before continuing"))
     ;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Class Code"), errors))
    return;

  if (_mode == cEdit)
    classSave.prepare( "UPDATE classcode "
               "SET classcode_code=:classcode_code, classcode_descrip=:classcode_descrip "
               "WHERE (classcode_id=:classcode_id);" );
  else if (_mode == cNew)
  {
    classSave.exec("SELECT NEXTVAL('classcode_classcode_id_seq') AS classcode_id");
    if (classSave.first())
      _classcodeid = classSave.value("classcode_id").toInt();
    else
    {
      systemError(this, tr("A System Error occurred at %1::%2.")
                        .arg(__FILE__)
                        .arg(__LINE__) );
      return;
    }
 
    classSave.prepare( "INSERT INTO classcode "
               "( classcode_id, classcode_code, classcode_descrip ) "
               "VALUES "
               "( :classcode_id, :classcode_code, :classcode_descrip );" );
  }

  classSave.bindValue(":classcode_id", _classcodeid);
  classSave.bindValue(":classcode_code", _classCode->text());
  classSave.bindValue(":classcode_descrip", _description->text());
  classSave.exec();

  done(_classcodeid);
}
Пример #14
0
QScriptValue constructGuiErrorCheck(QScriptContext *context, QScriptEngine *engine)
{
  GuiErrorCheck obj;

  if (context->argumentCount() == 3    &&
      context->argument(0).isBoolean() &&
      qscriptvalue_cast<QWidget*>(context->argument(1)) &&
      context->argument(2).isString()) {
    obj = GuiErrorCheck(context->argument(0).toBoolean(),
                        qscriptvalue_cast<QWidget*>(context->argument(1)),
                        context->argument(2).toString());
  }
  else {
    context->throwError(QScriptContext::UnknownError,
                        "Could not find an appropriate GuiErrorCheck constructor");
  }

  return engine->toScriptValue(obj);
}
Пример #15
0
bool taxAuthority::sSave()
{
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_code->text().isEmpty(), _code,
                          tr("You must enter a valid Code."))
    ;

  XSqlQuery dupq;
  dupq.prepare("SELECT taxauth_id "
               "FROM taxauth "
               "WHERE ( (taxauth_id<>:taxauth_id)"
               " AND (UPPER(taxauth_code)=UPPER(:taxauth_code)) );");
  dupq.bindValue(":taxauth_id", _taxauthid);
  dupq.bindValue(":taxauth_code", _code->text().trimmed());
  dupq.exec();
  if (dupq.first())
    errors << GuiErrorCheck(true, _code,
                            tr("A Tax Authority with the entered code already "
                               "exists. You may not create a Tax Authority "
                               "with this code."));
  else if (ErrorReporter::error(QtCriticalMsg, this,
                                tr("Cannot Create Tax Authority"),
                                dupq, __FILE__, __LINE__))
    return false;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Tax Authority"), errors))
    return false;

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

  XSqlQuery begin("BEGIN;");

  int saveResult = _address->save(AddressCluster::CHECK);
  if (-2 == saveResult)
  {
    int answer = QMessageBox::question(this,
                   tr("Question Saving Address"),
                   tr("<p>There are multiple uses of this "
                      "Address. What would you like to do?"),
                   tr("Change This One"),
                   tr("Change Address for All"),
                   tr("Cancel"),
                   2, 2);
    if (0 == answer)
      saveResult = _address->save(AddressCluster::CHANGEONE);
    else if (1 == answer)
      saveResult = _address->save(AddressCluster::CHANGEALL);
  }
  if (saveResult < 0)  // not else-if: this is error check for CHANGE{ONE,ALL}
  {
    rollback.exec();
    ErrorReporter::error(QtCriticalMsg, this, tr("Error saving Address"),
                          storedProcErrorLookup("saveAddr", saveResult),
                          __FILE__, __LINE__);
    _address->setFocus();
    return false;
  }

  XSqlQuery upsq;
  if (_mode == cEdit)
  {
    upsq.prepare( "UPDATE taxauth "
               "   SET taxauth_code=:taxauth_code,"
               "       taxauth_name=:taxauth_name,"
               "       taxauth_extref=:taxauth_extref,"
               "       taxauth_curr_id=:taxauth_curr_id,"
               "       taxauth_addr_id=:taxauth_addr_id,"
               "       taxauth_county=:taxauth_county,"
               "       taxauth_accnt_id=:taxauth_accnt_id "
               "WHERE (taxauth_id=:taxauth_id) "
               "RETURNING taxauth_id;" );
    upsq.bindValue(":taxauth_id", _taxauthid);
  }
  else if (_mode == cNew)
    upsq.prepare( "INSERT INTO taxauth "
               "( taxauth_id, taxauth_code, taxauth_name, taxauth_extref,"
               "  taxauth_curr_id, taxauth_addr_id, taxauth_county,"
               "  taxauth_accnt_id) "
               "VALUES "
               "( DEFAULT, :taxauth_code, :taxauth_name, :taxauth_extref,"
               "  :taxauth_curr_id, :taxauth_addr_id, :taxauth_county,"
               "  :taxauth_accnt_id) "
               "RETURNING taxauth_id;" );

  upsq.bindValue(":taxauth_code", _code->text().trimmed());
  upsq.bindValue(":taxauth_name", _name->text());
  upsq.bindValue(":taxauth_extref", _extref->text());
  if(_currency->isValid())
    upsq.bindValue(":taxauth_curr_id", _currency->id());
  if(_address->isValid())
    upsq.bindValue(":taxauth_addr_id", _address->id());
  upsq.bindValue(":taxauth_county",    _county->text());
  if(_glaccnt->isValid())
    upsq.bindValue(":taxauth_accnt_id", _glaccnt->id());
  upsq.exec();
  if (upsq.first())
    _taxauthid = upsq.value("taxauth_id").toInt();
  else if (upsq.lastError().type() != QSqlError::NoError)
  {
    rollback.exec();
    ErrorReporter::error(QtCriticalMsg, this, tr("Cannot save Tax Authority"),
                         upsq, __FILE__, __LINE__);
    return false;
  }

  XSqlQuery commit("COMMIT;");
  _NumberGen = -1;

  omfgThis->sTaxAuthsUpdated(_taxauthid);

  done(_taxauthid);
  return true;
}
Пример #16
0
bool itemSource::sSave()
{
  XSqlQuery itemSave;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(!_item->isValid(), _item,
                          tr( "You must select an Item that this Item Source represents\n"
                              "before you may save this Item Source." ) )
         << GuiErrorCheck(!_vendor->isValid(), _vendor,
                          tr( "You must select this Vendor that this Item Source is sold by\n"
                              "before you may save this Item Source." ) )
         << GuiErrorCheck(_dates->endDate() < _dates->startDate(), _dates,
                          tr("The expiration date cannot be earlier than the effective date."))
         << GuiErrorCheck(_vendorUOM->currentText().length() == 0, _vendorUOM,
                          tr( "You must indicate the Unit of Measure that this Item Source is sold in\n"
                               "before you may save this Item Source." ) )
         << GuiErrorCheck(_invVendorUOMRatio->toDouble() == 0.0, _invVendorUOMRatio,
                          tr( "You must indicate the Ratio of Inventory to Vendor Unit of Measures\n"
                               "before you may save this Item Source." ) )
     ;

  /* TODO - need this?
  itemSave.prepare( "SELECT count(*) AS numberOfOverlaps "
                    "FROM itemsrc "
                    "WHERE (itemsrc_item_id = :itemsrc_item_id)"
                    "  AND (itemsrc_vend_id = :itemsrc_vend_id)"
                    "  AND (itemsrc_id != :itemsrc_id)"
                    "  AND ( (itemsrc_effective BETWEEN :itemsrc_effective AND :itemsrc_expires OR"
                    "         itemsrc_expires BETWEEN :itemsrc_effective AND :itemsrc_expires)"
                    "   OR   (itemsrc_effective <= :itemsrc_effective AND"
                    "         itemsrc_expires   >= :itemsrc_expires) );" );
  itemSave.bindValue(":itemsrc_id", _itemsrcid);
  itemSave.bindValue(":itemsrc_item_id", _item->id());
  itemSave.bindValue(":itemsrc_vend_id", _vendor->id());
  itemSave.bindValue(":itemsrc_effective", _dates->startDate());
  itemSave.bindValue(":itemsrc_expires", _dates->endDate());
  itemSave.exec();
  if (itemSave.first())
  {
    if (itemSave.value("numberOfOverlaps").toInt() > 0)
    {
      errors << GuiErrorCheck(true, _dates,
                              tr("The date range overlaps with another date range.\n"
                                 "Please check the values of these dates."));
    }
  }
  else if (itemSave.lastError().type() != QSqlError::NoError)
  {
    systemError(this, itemSave.lastError().databaseText(), __FILE__, __LINE__);
    return false;
  }
  */

  if(_mode == cNew || _mode == cCopy)
  {
    itemSave.prepare( "SELECT itemsrc_id "
                      "  FROM itemsrc "
                      " WHERE ((itemsrc_item_id=:item_id) "
                      "   AND (itemsrc_vend_id=:vend_id) "
                      "   AND (itemsrc_vend_item_number=:itemsrc_vend_item_number) "
                      "   AND (UPPER(itemsrc_manuf_name)=UPPER(:itemsrc_manuf_name)) "
                      "   AND (UPPER(itemsrc_manuf_item_number)=UPPER(:itemsrc_manuf_item_number)) ) ");
    itemSave.bindValue(":item_id", _item->id());
    itemSave.bindValue(":vend_id", _vendor->id());
    itemSave.bindValue(":itemsrc_vend_item_number", _vendorItemNumber->text());
    itemSave.bindValue(":itemsrc_manuf_name", _manufName->currentText());
    itemSave.bindValue(":itemsrc_manuf_item_number", _manufItemNumber->text());
    itemSave.exec();
    if(itemSave.first())
    {
      errors << GuiErrorCheck(true, _item,
                              tr("An Item Source already exists for the Item Number, Vendor,\n"
                                 "Vendor Item, Manfacturer Name and Manufacturer Item Number you have specified."));
    }
    else if (itemSave.lastError().type() != QSqlError::NoError)
    {
      systemError(this, itemSave.lastError().databaseText(), __FILE__, __LINE__);
      return false;
    }
  }
  
  if(_active->isChecked())
  {
    itemSave.prepare("SELECT item_id "
                     "FROM item "
                     "WHERE ((item_id=:item_id)"
                     "  AND  (item_active)) "
                     "LIMIT 1; ");
    itemSave.bindValue(":item_id", _item->id());
    itemSave.exec();
    if (!itemSave.first())         
    { 
      errors << GuiErrorCheck(true, _active,
                              tr("This Item Source refers to an inactive Item and must be marked as inactive.") );
    }
  }
    
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Item Source"), errors))
    return false;

  if (_mode == cNew || _mode == cCopy)
    itemSave.prepare( "INSERT INTO itemsrc "
               "( itemsrc_id, itemsrc_item_id, itemsrc_active, itemsrc_default, itemsrc_vend_id,"
               "  itemsrc_contrct_id, itemsrc_effective, itemsrc_expires,"
               "  itemsrc_vend_item_number, itemsrc_vend_item_descrip,"
               "  itemsrc_vend_uom, itemsrc_invvendoruomratio,"
               "  itemsrc_minordqty, itemsrc_multordqty, itemsrc_upccode,"
               "  itemsrc_leadtime, itemsrc_ranking,"
               "  itemsrc_comments, itemsrc_manuf_name, "
               "  itemsrc_manuf_item_number, itemsrc_manuf_item_descrip ) "
               "VALUES "
               "( :itemsrc_id, :itemsrc_item_id, :itemsrc_active, :itemsrc_default, :itemsrc_vend_id,"
               "  :itemsrc_contrct_id, :itemsrc_effective, :itemsrc_expires,"
               "  :itemsrc_vend_item_number, :itemsrc_vend_item_descrip,"
               "  :itemsrc_vend_uom, :itemsrc_invvendoruomratio,"
               "  :itemsrc_minordqty, :itemsrc_multordqty, :itemsrc_upccode,"
               "  :itemsrc_leadtime, :itemsrc_ranking,"
               "  :itemsrc_comments, :itemsrc_manuf_name, "
               "  :itemsrc_manuf_item_number, :itemsrc_manuf_item_descrip );" );
  if (_mode == cEdit)
    itemSave.prepare( "UPDATE itemsrc "
               "SET itemsrc_active=:itemsrc_active,"
               "    itemsrc_default=:itemsrc_default,"
               "    itemsrc_vend_id=:itemsrc_vend_id,"
               "    itemsrc_contrct_id=:itemsrc_contrct_id,"
               "    itemsrc_effective=:itemsrc_effective,"
               "    itemsrc_expires=:itemsrc_expires,"
               "    itemsrc_vend_item_number=:itemsrc_vend_item_number,"
               "    itemsrc_vend_item_descrip=:itemsrc_vend_item_descrip,"
               "    itemsrc_vend_uom=:itemsrc_vend_uom,"
               "    itemsrc_invvendoruomratio=:itemsrc_invvendoruomratio,"
			   "    itemsrc_upccode=:itemsrc_upccode,"
               "    itemsrc_minordqty=:itemsrc_minordqty, itemsrc_multordqty=:itemsrc_multordqty,"
               "    itemsrc_leadtime=:itemsrc_leadtime, itemsrc_ranking=:itemsrc_ranking,"
               "    itemsrc_comments=:itemsrc_comments, itemsrc_manuf_name=:itemsrc_manuf_name, "
               "    itemsrc_manuf_item_number=:itemsrc_manuf_item_number, "
               "    itemsrc_manuf_item_descrip=:itemsrc_manuf_item_descrip "
               "WHERE (itemsrc_id=:itemsrc_id);" );

  itemSave.bindValue(":itemsrc_id", _itemsrcid);
  itemSave.bindValue(":itemsrc_item_id", _item->id());
  itemSave.bindValue(":itemsrc_active", QVariant(_active->isChecked()));
  itemSave.bindValue(":itemsrc_default", QVariant(_default->isChecked()));
  itemSave.bindValue(":itemsrc_vend_id", _vendor->id());
  if (_contract->isValid())
    itemSave.bindValue(":itemsrc_contrct_id", _contract->id());
  itemSave.bindValue(":itemsrc_effective", _dates->startDate());
  itemSave.bindValue(":itemsrc_expires", _dates->endDate());
  itemSave.bindValue(":itemsrc_vend_item_number", _vendorItemNumber->text());
  itemSave.bindValue(":itemsrc_vend_item_descrip", _vendorItemDescrip->toPlainText());
  itemSave.bindValue(":itemsrc_vend_uom", _vendorUOM->currentText());
  itemSave.bindValue(":itemsrc_invvendoruomratio", _invVendorUOMRatio->toDouble());
  itemSave.bindValue(":itemsrc_upccode", _upcCode->text());
  itemSave.bindValue(":itemsrc_minordqty", _minOrderQty->toDouble());
  itemSave.bindValue(":itemsrc_multordqty", _multOrderQty->toDouble());
  itemSave.bindValue(":itemsrc_leadtime", _leadTime->text().toInt());
  itemSave.bindValue(":itemsrc_ranking", _vendorRanking->value());
  itemSave.bindValue(":itemsrc_comments", _notes->toPlainText().trimmed());
  itemSave.bindValue(":itemsrc_manuf_name", _manufName->currentText());
  itemSave.bindValue(":itemsrc_manuf_item_number", _manufItemNumber->text());
  itemSave.bindValue(":itemsrc_manuf_item_descrip", _manufItemDescrip->toPlainText());
  itemSave.exec();
  if (itemSave.lastError().type() != QSqlError::NoError)
  {
    systemError(this, itemSave.lastError().databaseText(), __FILE__, __LINE__);
    return false;
  }

  if (_captive)
  {
    if (_mode != cCopy)
    {
      _vendor->setEnabled(FALSE);
    }
    _mode = cEdit;
    _item->setReadOnly(TRUE);
    _captive = false;
  }
  else
    done(_itemsrcid);
    
  return true;
}
Пример #17
0
bool contract::sSave()
{
  XSqlQuery itemSave;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(!_vendor->isValid(), _vendor,
                          tr( "You must select a Vendor before you may save this Contract." ) )
         << GuiErrorCheck(_dates->endDate() < _dates->startDate(), _dates,
                          tr("The expiration date cannot be earlier than the effective date.") )
         << GuiErrorCheck(_number->isNull(), _number,
                          tr( "You must enter a Contract Number before you may save this Contract." ) )
         << GuiErrorCheck(_descrip->isNull(), _descrip,
                          tr( "You must enter a Description before you may save this Contract." ) )
     ;

  itemSave.prepare( "SELECT count(*) AS numberOfOverlaps "
                    "FROM contrct "
                    "WHERE (contrct_vend_id = :contrct_vend_id)"
                    "  AND (contrct_id != :contrct_id)"
                    "  AND ( (contrct_effective BETWEEN :contrct_effective AND :contrct_expires OR"
                    "         contrct_expires BETWEEN :contrct_effective AND :contrct_expires)"
                    "   OR   (contrct_effective <= :contrct_effective AND"
                    "         contrct_expires   >= :contrct_expires) );" );
  itemSave.bindValue(":contrct_id", _contrctid);
  itemSave.bindValue(":contrct_vend_id", _vendor->id());
  itemSave.bindValue(":contrct_effective", _dates->startDate());
  itemSave.bindValue(":contrct_expires", _dates->endDate());
  itemSave.exec();
  if (itemSave.first())
  {
    if (itemSave.value("numberOfOverlaps").toInt() > 0)
    {
      errors << GuiErrorCheck(true, _dates,
                              tr("The date range overlaps with another date range.\n"
                                 "Please check the values of these dates."));
    }
  }
  else if (itemSave.lastError().type() != QSqlError::NoError)
  {
    systemError(this, itemSave.lastError().databaseText(), __FILE__, __LINE__);
    return false;
  }

  if(_mode == cNew || _mode == cCopy)
  {
    itemSave.prepare( "SELECT contrct_id "
                      "  FROM contrct "
                      " WHERE ((contrct_vend_id=:vend_id) "
                      "   AND (contrct_number=:contrct_number));" );
    itemSave.bindValue(":vend_id", _vendor->id());
    itemSave.bindValue(":contrct_number", _number->text());
    itemSave.exec();
    if(itemSave.first())
    {
      errors << GuiErrorCheck(true, _vendor,
                              tr("A Contract already exists for the Vendor,\n"
                                 "Contract Number you have specified."));
    }
    else if (itemSave.lastError().type() != QSqlError::NoError)
    {
      systemError(this, itemSave.lastError().databaseText(), __FILE__, __LINE__);
      return false;
    }
  }
  
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Contract"), errors))
    return false;

  if (_mode == cNew || _mode == cCopy)
    itemSave.prepare( "INSERT INTO contrct "
               "( contrct_id, contrct_vend_id,"
               "  contrct_number, contrct_descrip,"
               "  contrct_effective, contrct_expires,"
               "  contrct_note ) "
               "VALUES "
               "( :contrct_id, :contrct_vend_id,"
               "  :contrct_number, :contrct_descrip,"
               "  :contrct_effective, :contrct_expires,"
               "  :contrct_note );" );
  if (_mode == cEdit)
    itemSave.prepare( "UPDATE contrct "
               "SET contrct_number=:contrct_number,"
               "    contrct_descrip=:contrct_descrip,"
               "    contrct_effective=:contrct_effective,"
               "    contrct_expires=:contrct_expires,"
               "    contrct_note=:contrct_note "
               "WHERE (contrct_id=:contrct_id);" );

  itemSave.bindValue(":contrct_id", _contrctid);
  itemSave.bindValue(":contrct_vend_id", _vendor->id());
  itemSave.bindValue(":contrct_effective", _dates->startDate());
  itemSave.bindValue(":contrct_expires", _dates->endDate());
  itemSave.bindValue(":contrct_number", _number->text());
  itemSave.bindValue(":contrct_descrip", _descrip->text());
  itemSave.bindValue(":contrct_note", _notes->toPlainText());
  itemSave.exec();
  if (itemSave.lastError().type() != QSqlError::NoError)
  {
    systemError(this, itemSave.lastError().databaseText(), __FILE__, __LINE__);
    return false;
  }

  if (_captive)
  {
    if (_mode != cCopy)
    {
      _vendor->setEnabled(FALSE);
    }
    _mode = cEdit;
    _captive = false;
  }
    
  return true;
}
Пример #18
0
void apAccountAssignment::sSave()
{
  QList<GuiErrorCheck> errors;

  if (_metrics->boolean("InterfaceAPToGL"))
  {
    errors << GuiErrorCheck(!_ap->isValid(), _ap,
                            tr("<p>You must select an A/P Account before saving this A/P Account Assignment."))
           << GuiErrorCheck(!_prepaid->isValid(), _prepaid,
                            tr("<p>You must select a Prepaid Account before saving this A/P Account Assignment."))
           << GuiErrorCheck(!_discount->isValid(), _discount,
                            tr("<p>You must select a Discount Account before saving this A/P Account Assignment."))
           ;
  }

  XSqlQuery saveAssign;
  if (_mode == cNew)
  {
    saveAssign.prepare( "SELECT apaccnt_id "
               "FROM apaccnt "
               "WHERE ( (apaccnt_vendtype_id=:apaccnt_vendtype_id)"
               " AND (apaccnt_vendtype=:apaccnt_vendtype) );" );

    if (_allVendorTypes->isChecked())
    {
      saveAssign.bindValue(":apaccnt_vendtype_id", -1);
      saveAssign.bindValue(":apaccnt_vendtype", ".*");
    }
    else if (_selectedVendorType->isChecked())
    {
      saveAssign.bindValue(":apaccnt_vendtype_id", _vendorTypes->id());
      saveAssign.bindValue(":apaccnt_vendtype", "");
    }
    else if (_vendorTypePattern->isChecked())
    {
      saveAssign.bindValue(":apaccnt_vendtype_id", -1);
      saveAssign.bindValue(":apaccnt_vendtype", _vendorType->text().trimmed());
    }

    saveAssign.exec();
    if (saveAssign.first())
    {
      errors << GuiErrorCheck(true, _allVendorTypes,
                             tr("<p>You may not save this A/P Account Assignment as it already exists."));
    }
  }

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save A/P Account Assignment"), errors))
    return;

  if (_mode == cNew)
  {
    saveAssign.exec("SELECT NEXTVAL('apaccnt_apaccnt_id_seq') AS _apaccnt_id;");
    if (saveAssign.first())
      _apaccntid = saveAssign.value("_apaccnt_id").toInt();
//  ToDo

    saveAssign.prepare( "INSERT INTO apaccnt "
               "( apaccnt_id, apaccnt_vendtype_id, apaccnt_vendtype,"
               "  apaccnt_ap_accnt_id, apaccnt_prepaid_accnt_id,"
               "  apaccnt_discount_accnt_id ) "
               "VALUES "
               "( :apaccnt_id, :apaccnt_vendtype_id, :apaccnt_vendtype,"
               "  :apaccnt_ap_accnt_id, :apaccnt_prepaid_accnt_id,"
               "  :apaccnt_discount_accnt_id ) " );
  }
  else if (_mode == cEdit)
    saveAssign.prepare( "UPDATE apaccnt "
               "SET apaccnt_vendtype_id=:apaccnt_vendtype_id,"
               "    apaccnt_vendtype=:apaccnt_vendtype,"
               "    apaccnt_ap_accnt_id=:apaccnt_ap_accnt_id,"
               "    apaccnt_prepaid_accnt_id=:apaccnt_prepaid_accnt_id,"
               "    apaccnt_discount_accnt_id=:apaccnt_discount_accnt_id "
               "WHERE (apaccnt_id=:apaccnt_id);" );

  saveAssign.bindValue(":apaccnt_id", _apaccntid);
  saveAssign.bindValue(":apaccnt_ap_accnt_id", _ap->id());
  saveAssign.bindValue(":apaccnt_prepaid_accnt_id", _prepaid->id());
  saveAssign.bindValue(":apaccnt_discount_accnt_id", _discount->id());

  if (_allVendorTypes->isChecked())
  {
    saveAssign.bindValue(":apaccnt_vendtype_id", -1);
    saveAssign.bindValue(":apaccnt_vendtype", ".*");
  }
  else if (_selectedVendorType->isChecked())
  {
    saveAssign.bindValue(":apaccnt_vendtype_id", _vendorTypes->id());
    saveAssign.bindValue(":apaccnt_vendtype", "");
  }
  else if (_vendorTypePattern->isChecked())
  {
    saveAssign.bindValue(":apaccnt_vendtype_id", -1);
    saveAssign.bindValue(":apaccnt_vendtype", _vendorType->text().trimmed());
  }

  saveAssign.exec();

  done(_apaccntid);
}
Пример #19
0
void purchaseOrderItem::sSave()
{
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(!_inventoryItem->isChecked() && _expcat->id() == -1, _expcat,
                          tr("<p>You must specify an Expense Category for this non-Inventory Item before you may save."))
         << GuiErrorCheck(_inventoryItem->isChecked() && !_item->isValid(), _item,
                          tr("<p>You must select an Item Number before you may save."))
         << GuiErrorCheck(_inventoryItem->isChecked() && _warehouse->id() == -1, _warehouse,
                          tr("<p>You must select a Supplying Site before you may save."))
         << GuiErrorCheck(!_dueDate->isValid(), _dueDate,
                          tr("<p>You must enter a due date before you may save this Purchase Order Item."))
         << GuiErrorCheck(_metrics->boolean("RequirePOTax") && !_taxtype->isValid(), _taxtype,
                          tr("<p>You must select a Tax Type before you may save." ))
         << GuiErrorCheck(_so->text().length() == 0 && _costmethod == "J", _item,
                          tr("<p>You may not purchase a Job Item without an associated demand."))
         << GuiErrorCheck(!_project->isValid() && _metrics->boolean("RequireProjectAssignment"), _project,
                          tr("<p>You must enter a Project for this order item before you may save it."))
     ;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Purchase Order Item"), errors))
    return;

  XSqlQuery purchaseSave;
  if (_ordered->toDouble() == 0.0)
  {
    if (QMessageBox::critical( this, tr("Zero Order Quantity"),
                               tr( "<p>The quantity that you are ordering is zero. "
                                   "<p>Do you wish to Continue or Change the Order Qty?" ),
                               QString("&Continue"), QString("Change Order &Qty."), QString::null, 1, 1 ) == 1)
    {
      _ordered->setFocus();
      return;
    }
  }

  if (_ordered->toDouble() < _minimumOrder)
  {
    if (QMessageBox::critical( this, tr("Invalid Order Quantity"),
                               tr( "<p>The quantity that you are ordering is below the Minimum Order Quantity for this "
                                   "Item Source.  You may continue but this Vendor may not honor pricing or delivery quotations. "
                                   "<p>Do you wish to Continue or Change the Order Qty?" ),
                               QString("&Continue"), QString("Change Order &Qty."), QString::null, 1, 1 ) == 1)
    {
      _ordered->setFocus();
      return;
    }
  }

  if ((int)_orderMultiple)
  {
    if (qRound(_ordered->toDouble()) % (int)_orderMultiple)
    {
      if (QMessageBox::critical( this, tr("Invalid Order Quantity"),
                                 tr( "<p>The quantity that you are ordering does not fall within the Order Multiple for this "
                                     "Item Source.  You may continue but this Vendor may not honor pricing or delivery quotations. "
                                     "<p>Do you wish to Continue or Change the Order Qty?" ),
                                 QString("&Continue"), QString("Change Order &Qty."), QString::null, 1, 1 ) == 1)
      {
        _ordered->setFocus();
        return;
      }
    }
  }

  if (_unitPrice->baseValue() > _maxCost && _maxCost > 0.0)
  {
    if (QMessageBox::critical( this, tr("Invalid Unit Price"),
                               tr( "<p>The Unit Price is above the Maximum Desired Cost for this Item."
                                   "<p>Do you wish to Continue or Change the Unit Price?" ),
                               QString("&Continue"), QString("Change Unit &Price."), QString::null, 1, 1 ) == 1)
    {
      _unitPrice->setFocus();
      return;
    }
  }

  if (_dueDate->date() < _earliestDate->date())
  {
    if (QMessageBox::critical( this, tr("Invalid Due Date "),
                               tr( "<p>The Due Date that you are requesting does not fall within the Lead Time Days for this "
                                   "Item Source.  You may continue but this Vendor may not honor pricing or delivery quotations "
                                   "or may not be able to deliver by the requested Due Date. "
                                   "<p>Do you wish to Continue or Change the Due Date?" ),
                               QString("&Continue"), QString("Change Order &Due Date"), QString::null, 1, 1 ) == 1)
    {
      _dueDate->setFocus();
      return;
    }
  }

  if (_mode == cNew)
  {
    purchaseSave.prepare( "INSERT INTO poitem "
               "( poitem_id, poitem_pohead_id, poitem_status, poitem_linenumber,"
               "  poitem_taxtype_id, poitem_tax_recoverable,"
               "  poitem_itemsite_id, poitem_expcat_id,"
               "  poitem_itemsrc_id, poitem_vend_item_number, poitem_vend_item_descrip,"
               "  poitem_vend_uom, poitem_invvenduomratio,"
               "  poitem_qty_ordered,"
               "  poitem_unitprice, poitem_freight, poitem_duedate, "
               "  poitem_bom_rev_id, poitem_boo_rev_id, "
               "  poitem_comments, poitem_prj_id, poitem_stdcost, poitem_manuf_name, "
               "  poitem_manuf_item_number, poitem_manuf_item_descrip, poitem_rlsd_duedate ) "
               "VALUES "
               "( :poitem_id, :poitem_pohead_id, :status, :poitem_linenumber,"
               "  :poitem_taxtype_id, :poitem_tax_recoverable,"
               "  :poitem_itemsite_id, :poitem_expcat_id,"
               "  :poitem_itemsrc_id, :poitem_vend_item_number, :poitem_vend_item_descrip,"
               "  :poitem_vend_uom, :poitem_invvenduomratio,"
               "  :poitem_qty_ordered,"
               "  :poitem_unitprice, :poitem_freight, :poitem_duedate, "
               "  :poitem_bom_rev_id, :poitem_boo_rev_id, "
               "  :poitem_comments, :poitem_prj_id, stdcost(:item_id), :poitem_manuf_name, "
               "  :poitem_manuf_item_number, :poitem_manuf_item_descrip, :poitem_duedate) ;" );

    purchaseSave.bindValue(":status", _poStatus);
    purchaseSave.bindValue(":item_id", _item->id());

    if (_inventoryItem->isChecked())
    {
      XSqlQuery itemsiteid;
      itemsiteid.prepare( "SELECT itemsite_id "
                          "FROM itemsite "
                          "WHERE ( (itemsite_item_id=:item_id)"
                          " AND (itemsite_warehous_id=:warehous_id) );" );
      itemsiteid.bindValue(":item_id", _item->id());
      itemsiteid.bindValue(":warehous_id", _warehouse->id());
      itemsiteid.exec();
      if (itemsiteid.first())
        purchaseSave.bindValue(":poitem_itemsite_id", itemsiteid.value("itemsite_id").toInt());
      else
      {
        QMessageBox::critical( this, tr("Invalid Item/Site"),
                               tr("<p>The Item and Site you have selected does not appear to be a valid combination. "
                                  "Make sure you have a Site selected and that there is a valid itemsite for "
                                  "this Item and Site combination.") );
        return;
      }
    }
    else
    {
      purchaseSave.bindValue(":poitem_expcat_id", _expcat->id());
    }
  }
  else if (_mode == cEdit)
    purchaseSave.prepare( "UPDATE poitem "
               "SET poitem_itemsrc_id=:poitem_itemsrc_id,"   
               "    poitem_taxtype_id=:poitem_taxtype_id,"
               "    poitem_tax_recoverable=:poitem_tax_recoverable,"
               "    poitem_vend_item_number=:poitem_vend_item_number,"
               "    poitem_vend_item_descrip=:poitem_vend_item_descrip,"
               "    poitem_vend_uom=:poitem_vend_uom, poitem_invvenduomratio=:poitem_invvenduomratio,"
               "    poitem_qty_ordered=:poitem_qty_ordered, poitem_unitprice=:poitem_unitprice,"
               "    poitem_freight=:poitem_freight,"
               "    poitem_duedate=:poitem_duedate, poitem_comments=:poitem_comments,"
               "    poitem_prj_id=:poitem_prj_id, "
               "    poitem_bom_rev_id=:poitem_bom_rev_id, "
               "    poitem_boo_rev_id=:poitem_boo_rev_id, "
               "    poitem_manuf_name=:poitem_manuf_name, "
               "    poitem_manuf_item_number=:poitem_manuf_item_number, "
               "    poitem_manuf_item_descrip=:poitem_manuf_item_descrip "
               "WHERE (poitem_id=:poitem_id);" );

  purchaseSave.bindValue(":poitem_id", _poitemid);
  if (_taxtype->id() != -1)
    purchaseSave.bindValue(":poitem_taxtype_id", _taxtype->id());
  purchaseSave.bindValue(":poitem_tax_recoverable", QVariant(_taxRecoverable->isChecked()));
  purchaseSave.bindValue(":poitem_pohead_id", _poheadid);
  purchaseSave.bindValue(":poitem_linenumber", _lineNumber->text().toInt());
  if (_itemsrcid != -1)
    purchaseSave.bindValue(":poitem_itemsrc_id", _itemsrcid);
  purchaseSave.bindValue(":poitem_vend_item_number", _vendorItemNumber->text());
  purchaseSave.bindValue(":poitem_vend_item_descrip", _vendorDescrip->toPlainText());
  purchaseSave.bindValue(":poitem_vend_uom", _vendorUOM->text());
  purchaseSave.bindValue(":poitem_invvenduomratio", _invVendorUOMRatio->toDouble());
  purchaseSave.bindValue(":poitem_qty_ordered", _ordered->toDouble());
  purchaseSave.bindValue(":poitem_unitprice", _unitPrice->localValue());
  purchaseSave.bindValue(":poitem_freight", _freight->localValue());
  purchaseSave.bindValue(":poitem_duedate", _dueDate->date());
  purchaseSave.bindValue(":poitem_manuf_name", _manufName->currentText());
  purchaseSave.bindValue(":poitem_manuf_item_number", _manufItemNumber->text());
  purchaseSave.bindValue(":poitem_manuf_item_descrip", _manufItemDescrip->toPlainText());
  purchaseSave.bindValue(":poitem_comments", _notes->toPlainText());
  if (_project->isValid())
    purchaseSave.bindValue(":poitem_prj_id", _project->id());
  if (_metrics->boolean("RevControl"))
  {
    purchaseSave.bindValue(":poitem_bom_rev_id", _bomRevision->id());
    purchaseSave.bindValue(":poitem_boo_rev_id", _booRevision->id());
  }
  purchaseSave.exec();
  if (purchaseSave.lastError().type() != QSqlError::NoError)
  {
    systemError(this, purchaseSave.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  if (_parentwo != -1)
  {
    purchaseSave.prepare("UPDATE poitem SET poitem_order_id=:parentwo, poitem_order_type='W' WHERE (poitem_id=:poitem_id);");
    purchaseSave.bindValue(":parentwo", _parentwo);
    purchaseSave.bindValue(":poitem_id", _poitemid);
    purchaseSave.exec();
  }

  if (_parentso != -1)
  {
    purchaseSave.prepare("UPDATE poitem SET poitem_order_id=:parentso, poitem_order_type='S' WHERE (poitem_id=:poitem_id);");
    purchaseSave.bindValue(":parentso", _parentso);
    purchaseSave.bindValue(":poitem_id", _poitemid);
    purchaseSave.exec();
    purchaseSave.prepare("UPDATE coitem SET coitem_order_id=:poitem_id, coitem_order_type='P' WHERE (coitem_id=:parentso);");
    purchaseSave.bindValue(":parentso", _parentso);
    purchaseSave.bindValue(":poitem_id", _poitemid);
    purchaseSave.exec();
  }

  if ( _mode != cView )
  {
    purchaseSave.prepare("SELECT updateCharAssignment('PI', :target_id, :char_id, :char_value);");

    QModelIndex idx1, idx2;
    for(int i = 0; i < _itemchar->rowCount(); i++)
    {
      idx1 = _itemchar->index(i, 0);
      idx2 = _itemchar->index(i, 1);
      purchaseSave.bindValue(":target_id", _poitemid);
      purchaseSave.bindValue(":char_id", _itemchar->data(idx1, Qt::UserRole));
      purchaseSave.bindValue(":char_value", _itemchar->data(idx2, Qt::DisplayRole));
      purchaseSave.exec();
    }
  }

  
  if (cNew == _mode && !_captive)
  {
    clear();
    prepare();
    _item->setFocus();
  }
  else
    done(_poitemid);
}
Пример #20
0
void costCategory::sSave()
{
  XSqlQuery costSave;
  QList<GuiErrorCheck> errors;

  errors << GuiErrorCheck(_category->text().trimmed().isEmpty(), _category,
                         tr("<p>You must enter a name for this Cost Category before saving it."));

  if (_metrics->boolean("InterfaceToGL"))
  {
    errors << GuiErrorCheck(!_asset->isValid(), _asset,
                            tr("<p>You must select an Inventory Asset Account before saving."))
           << GuiErrorCheck(!_expense->isValid(), _expense,
                            tr("<p>You must select an Expense Asset Account before saving."))
           << GuiErrorCheck(!_wip->isValid(), _wip,
                            tr("<p>You must select a WIP Asset Account before saving."))
           << GuiErrorCheck(!_inventoryCost->isValid(), _inventoryCost,
                            tr("<p>You must select an Inventory Cost Variance Account before saving."))
           << GuiErrorCheck(_metrics->boolean("MultiWhs") && _metrics->boolean("Transforms") && !_transformClearing->isValid(), _transformClearing,
                            tr("<p>You must select a Transform Clearing Account before saving."))
           << GuiErrorCheck(!_purchasePrice->isValid(), _purchasePrice,
                            tr("<p>You must select a Purchase Price Variance Account before saving."))
           << GuiErrorCheck(!_adjustment->isValid(), _adjustment,
                            tr("<p>You must select an Inventory Adjustment Account before saving."))
           << GuiErrorCheck(!_invScrap->isValid(), _invScrap,
                            tr("<p>You must select an Inventory Scrap Account before saving."))
           << GuiErrorCheck(!_mfgScrap->isValid(), _mfgScrap,
                            tr("<p>You must select a Manufacturing Scrap Account before saving."))
           << GuiErrorCheck(!_liability->isValid(), _liability,
                            tr("<p>You must select a P/O Liability Clearing Account before saving."))
           << GuiErrorCheck(!_shippingAsset->isValid(), _shippingAsset,
                            tr("<p>You must select a Shipping Asset Account before saving."))
           << GuiErrorCheck(!_freight->isValid(), _freight,
                            tr("<p>You must select a Line Item Freight Expense Account before saving."))
           << GuiErrorCheck(_metrics->boolean("MultiWhs") && !_toLiabilityClearing->isValid(), _toLiabilityClearing,
                            tr("<p>You must select a Transfer Order Liability Clearing Account before saving."))
           ;
  }

  costSave.prepare( "SELECT costcat_id"
             "  FROM costcat"
             " WHERE((UPPER(costcat_code)=UPPER(:costcat_code))"
             "   AND (costcat_id != :costcat_id));" );
  costSave.bindValue(":costcat_code", _category->text().trimmed());
  costSave.bindValue(":costcat_id", _costcatid);
  costSave.exec();
  if (costSave.first())
  {
    errors << GuiErrorCheck(true, _category,
                           tr("<p>The Name you have entered for this Cost Category is already in use."));
  }

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Cost Category"), errors))
    return;

  QSqlQuery newCostCategory;

  if ( (_mode == cNew) || (_mode == cCopy) )
  {
    costSave.exec("SELECT NEXTVAL('costcat_costcat_id_seq') AS costcat_id");
    if (costSave.first())
      _costcatid = costSave.value("costcat_id").toInt();
    else
    {
      systemError(this, costSave.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }

    costSave.prepare( "INSERT INTO costcat"
               "( costcat_id, costcat_code, costcat_descrip,"
               "  costcat_asset_accnt_id, costcat_invcost_accnt_id,"
               "  costcat_liability_accnt_id, costcat_freight_accnt_id,"
               "  costcat_adjustment_accnt_id, costcat_scrap_accnt_id, costcat_mfgscrap_accnt_id,"
               "  costcat_transform_accnt_id, costcat_wip_accnt_id,"
               "  costcat_purchprice_accnt_id,"
               "  costcat_shipasset_accnt_id, costcat_toliability_accnt_id, "
               "  costcat_exp_accnt_id) "
               "VALUES "
               "( :costcat_id, :costcat_code, :costcat_descrip,"
               "  :costcat_asset_accnt_id, :costcat_invcost_accnt_id,"
               "  :costcat_liability_accnt_id, :costcat_freight_accnt_id,"
               "  :costcat_adjustment_accnt_id, :costcat_scrap_accnt_id, :costcat_mfgscrap_accnt_id,"
               "  :costcat_transform_accnt_id, :costcat_wip_accnt_id,"
               "  :costcat_purchprice_accnt_id,"
               "  :costcat_shipasset_accnt_id, :costcat_toliability_accnt_id,"
               "  :costcat_exp_accnt_id);" );
  }
  else if (_mode == cEdit)
    costSave.prepare( "UPDATE costcat "
               "SET costcat_code=:costcat_code, costcat_descrip=:costcat_descrip,"
               "    costcat_asset_accnt_id=:costcat_asset_accnt_id,"
               "    costcat_invcost_accnt_id=:costcat_invcost_accnt_id,"
               "    costcat_liability_accnt_id=:costcat_liability_accnt_id,"
               "    costcat_freight_accnt_id=:costcat_freight_accnt_id,"
               "    costcat_adjustment_accnt_id=:costcat_adjustment_accnt_id,"
               "    costcat_scrap_accnt_id=:costcat_scrap_accnt_id,"
               "    costcat_mfgscrap_accnt_id=:costcat_mfgscrap_accnt_id,"
               "    costcat_transform_accnt_id=:costcat_transform_accnt_id,"
               "    costcat_wip_accnt_id=:costcat_wip_accnt_id,"
               "    costcat_purchprice_accnt_id=:costcat_purchprice_accnt_id,"
               "    costcat_shipasset_accnt_id=:costcat_shipasset_accnt_id,"
               "    costcat_toliability_accnt_id=:costcat_toliability_accnt_id, "
               "    costcat_exp_accnt_id=:costcat_exp_accnt_id "
               "WHERE (costcat_id=:costcat_id);" );

  costSave.bindValue(":costcat_id", _costcatid);
  costSave.bindValue(":costcat_code", _category->text().trimmed());
  costSave.bindValue(":costcat_descrip", _description->text().trimmed());
  costSave.bindValue(":costcat_asset_accnt_id", _asset->id());
  costSave.bindValue(":costcat_invcost_accnt_id", _inventoryCost->id());
  costSave.bindValue(":costcat_liability_accnt_id", _liability->id());
  costSave.bindValue(":costcat_freight_accnt_id", _freight->id());
  costSave.bindValue(":costcat_adjustment_accnt_id", _adjustment->id());
  costSave.bindValue(":costcat_scrap_accnt_id", _invScrap->id());
  costSave.bindValue(":costcat_mfgscrap_accnt_id", _mfgScrap->id());
  costSave.bindValue(":costcat_transform_accnt_id", _transformClearing->id());
  costSave.bindValue(":costcat_wip_accnt_id", _wip->id());
  costSave.bindValue(":costcat_purchprice_accnt_id", _purchasePrice->id());
  costSave.bindValue(":costcat_shipasset_accnt_id", _shippingAsset->id());
  costSave.bindValue(":costcat_exp_accnt_id", _expense->id());
  if (_toLiabilityClearing->isValid())
    costSave.bindValue(":costcat_toliability_accnt_id", _toLiabilityClearing->id());
  costSave.exec();
  if (costSave.lastError().type() != QSqlError::NoError)
  {
    systemError(this, costSave.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  emit saved(_costcatid);
  done(_costcatid);
}
Пример #21
0
void copyContract::sCopy()
{
  XSqlQuery copyq;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(!_effective->isValid(), _effective,
                          tr( "You must select an Effective Date before you may copy this Contract." ) )
         << GuiErrorCheck(!_expires->isValid(), _expires,
                          tr( "You must select an Expiration Date before you may copy this Contract." ) )
         << GuiErrorCheck(_expires->date() < _effective->date(), _effective,
                          tr("The expiration date cannot be earlier than the effective date.") )
         << GuiErrorCheck(_contract->isNull(), _contract,
                          tr( "You must enter a Contract Number before you may save this Contract." ) )
     ;

  copyq.prepare( "SELECT count(*) AS numberOfOverlaps "
                 "FROM contrct "
                 "WHERE (contrct_vend_id = :contrct_vend_id)"
                 "  AND (contrct_id != :contrct_id)"
                 "  AND ( (contrct_effective BETWEEN :contrct_effective AND :contrct_expires OR"
                 "         contrct_expires BETWEEN :contrct_effective AND :contrct_expires)"
                 "   OR   (contrct_effective <= :contrct_effective AND"
                 "         contrct_expires   >= :contrct_expires) );" );
  copyq.bindValue(":contrct_id", _contrctid);
  copyq.bindValue(":contrct_vend_id", _vendid);
  copyq.bindValue(":contrct_effective", _effective->date());
  copyq.bindValue(":contrct_expires", _expires->date());
  copyq.exec();
  if (copyq.first())
  {
    if (copyq.value("numberOfOverlaps").toInt() > 0)
    {
      errors << GuiErrorCheck(true, _effective,
                              tr("The date range overlaps with another date range.\n"
                                 "Please check the values of these dates."));
    }
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Copying Contract"),
                                copyq, __FILE__, __LINE__))
  {
    return;
  }

  copyq.prepare( "SELECT contrct_id "
                 "  FROM contrct "
                 " WHERE ((contrct_vend_id=:vend_id) "
                 "   AND (contrct_number=:contrct_number));" );
  copyq.bindValue(":vend_id", _vendid);
  copyq.bindValue(":contrct_number", _contract->text());
  copyq.exec();
  if(copyq.first())
  {
    errors << GuiErrorCheck(true, _contract,
                            tr("A Contract already exists for the Vendor,\n"
                               "Contract Number you have specified."));
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Copying Contract"),
                                copyq, __FILE__, __LINE__))
  {
    return;
  }

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

  copyq.prepare("SELECT copyContract(:contrct_id, :contrct_number, :contrct_effective, :contrct_expires) AS contrct_id;");
  copyq.bindValue(":contrct_id", _contrctid);
  copyq.bindValue(":contrct_number", _contract->text());
  copyq.bindValue(":contrct_effective", _effective->date());
  copyq.bindValue(":contrct_expires", _expires->date());

  copyq.exec();

  if (_captive)
  {
    if (copyq.first())
    {
      int contrctid = copyq.value("contrct_id").toInt();
      done(contrctid);
    }
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Copying Contract"),
                                  copyq, __FILE__, __LINE__))
    {
      return;
    }
  }
}
Пример #22
0
bool user::save()
{
    QString username = _username->text().trimmed().toLower();

    QList<GuiErrorCheck> errors;
    errors << GuiErrorCheck(! username.contains(QRegExp("[A-Za-z]")), _username,
                            tr("You must enter a valid Username before you can save this User Account."))
           << GuiErrorCheck(_username->text().contains(QRegExp("\\s")), _username,
                            tr("The Username cannot include any spaces."))
           << GuiErrorCheck(_passwd->text().isEmpty(), _passwd,
                            tr("You must enter a valid Password before you can save this User Account."))
           << GuiErrorCheck(_passwd->text() != _verify->text(), _passwd,
                            tr("The entered password and verify do not match. "
                               "Please enter both again carefully."))
           ;

    if (GuiErrorCheck::reportErrors(this, tr("Cannot save User Account"), errors))
    {
        if (_passwd->text() != _verify->text())
        {
            _passwd->clear();
            _verify->clear();
        }
        return false;
    }

    QString passwd = _passwd->text();
    if(_enhancedAuth->isChecked())
    {
        QRegExp xtuplecloud(".*\\.xtuplecloud\\.com.*");
        QRegExp xtuple(".*\\.xtuple\\.com.*");

        bool isCloud = xtuplecloud.exactMatch(omfgThis->databaseURL());
        bool isXtuple = xtuple.exactMatch(omfgThis->databaseURL());
        QString salt;

        if(isCloud || isXtuple)
        {
            salt = "j3H44uadEI#8#kSmkh#H%JSLAKDOHImklhdfsn3#432?%^kjasdjla3uy989apa3uipoweurw-03235##+=-lhkhdNOHA?%@mxncvbwoiwerNKLJHwe278NH28shNeGc";
        }
        else
        {
            salt = "xTuple";
        }
        passwd = passwd + salt + username;
        passwd = QMd5(passwd);
    }

    XSqlQuery usrq;
    if (_mode == cNew)
    {
        usrq.prepare("SELECT usesysid"
                     "  FROM pg_user"
                     " WHERE (usename=:username);" );
        usrq.bindValue(":username", username);
        usrq.exec();
        if (!usrq.first())
        {
            usrq.prepare("SELECT createUser(:username, :createUsers);");
            usrq.bindValue(":username", username);
            usrq.bindValue(":createUsers", QVariant(_createUsers->isChecked()));
            usrq.exec();
            if (ErrorReporter::error(QtCriticalMsg, this, tr("Creating User"),
                                     usrq, __FILE__, __LINE__))
                return false;
        }
    }
    else if (_mode == cEdit)
    {
        if(_createUsers->isEnabled())
        {
            usrq.prepare("SELECT setUserCanCreateUsers(:username, :createUsers);");
            usrq.bindValue(":username", username);
            usrq.bindValue(":createUsers", QVariant(_createUsers->isChecked()));
            usrq.exec();
            if (ErrorReporter::error(QtCriticalMsg, this, tr("Saving User Account"),
                                     usrq, __FILE__, __LINE__))
                return false;
        }
    }

    if(_createUsers->isEnabled())
    {
        usrq.prepare("SELECT pg_has_role(:username,'xtrole','member') AS result;");
        usrq.bindValue(":username", username);
        usrq.exec();
        if(usrq.first() && !usrq.value("result").toBool())
        {
            usrq.exec( QString("ALTER GROUP xtrole ADD USER %1;")
                       .arg(username) );
        }
        if (ErrorReporter::error(QtCriticalMsg, this, tr("Saving User Account"),
                                 usrq, __FILE__, __LINE__))
            return false;
    }

    if (_passwd->text() != "        ")
    {
        usrq.prepare( QString( "ALTER USER \"%1\" WITH PASSWORD :password;")
                      .arg(username) );
        usrq.bindValue(":password", passwd);
        usrq.exec();
        if (ErrorReporter::error(QtCriticalMsg, this, tr("Setting Password"),
                                 usrq, __FILE__, __LINE__))
            return false;
    }

    usrq.prepare("SELECT setUserPreference(:username, 'DisableExportContents', :export),"
                 "       setUserPreference(:username, 'UseEnhancedAuthentication', :enhanced),"
                 "       setUserPreference(:username, 'selectedSites', :sites),"
                 "       setUserPreference(:username, 'propername', :propername),"
                 "       setUserPreference(:username, 'email', :email),"
                 "       setUserPreference(:username, 'initials', :initials),"
                 "       setUserPreference(:username, 'locale_id', text(:locale_id)),"
                 "       setUserPreference(:username, 'agent', :agent),"
                 "       setUserPreference(:username, 'active', :active);");
    usrq.bindValue(":username", username);
    usrq.bindValue(":export", (_exportContents->isChecked() ? "t" : "f"));
    usrq.bindValue(":enhanced", (_enhancedAuth->isChecked() ? "t" : "f"));
    usrq.bindValue(":sites", (_selectedSites->isChecked() ? "t" : "f"));
    usrq.bindValue(":propername", _properName->text());
    usrq.bindValue(":email", _email->text());
    usrq.bindValue(":initials", _initials->text());
    usrq.bindValue(":locale_id", _locale->id());
    usrq.bindValue(":agent", (_agent->isChecked() ? "t" : "f"));
    usrq.bindValue(":active", (_active->isChecked() ? "t" : "f"));
    usrq.exec();
    if (ErrorReporter::error(QtCriticalMsg, this, tr("Saving User Account"),
                             usrq, __FILE__, __LINE__))
        return false;

    omfgThis->sUserUpdated(username);
    return true;
}
Пример #23
0
void updatePrices::sUpdate()
{
  XSqlQuery updateUpdate;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_byItem->isChecked() && !_item->isValid(), _item,
                          tr("You must select an Item to continue."))
         << GuiErrorCheck(!_sel->topLevelItemCount(), _sel,
                          tr("You must select a Pricing Schedule to continue."))
         << GuiErrorCheck(!_nominal->isChecked() && !_discount->isChecked() && !_markup->isChecked(), _nominal,
                          tr("You must select a least one Price Type to continue."))
         << GuiErrorCheck(_updateBy->toDouble() == 0.0, _updateBy,
                          tr("You must provide a Value to continue."))
  ;

  if (GuiErrorCheck::reportErrors(this, tr("Cannot Update Prices"), errors))
    return;
  
  ParameterList params;
  
  if (_byItem->isChecked())
    params.append("item_id", _item->id());
  else
    _paramGroup->appendValue(params);
  if (_nominal->isChecked())
    params.append("nominal", true);
  if (_discount->isChecked())
    params.append("discount", true);
  if (_markup->isChecked())
    params.append("markup", true);
  params.append("updateBy", _updateBy->toDouble());
  if (_value->isChecked())
    params.append("updateByValue", true);
  else
    params.append("updateByPercent", true);

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

  updateUpdate.exec("BEGIN;");

  MetaSQLQuery mql = mqlLoad("updateprices", "update");
  updateUpdate = mql.toQuery(params);
  if (updateUpdate.lastError().type() != QSqlError::NoError)
  {
    rollback.exec();
    systemError(this, updateUpdate.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  if (_updateCharPrices->isChecked())
  {
    MetaSQLQuery mql2 = mqlLoad("updateprices", "updatechar");
    updateUpdate = mql2.toQuery(params);
    if (updateUpdate.lastError().type() != QSqlError::NoError)
    {
      rollback.exec();
      systemError(this, updateUpdate.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }

  updateUpdate.exec("COMMIT;");
  
  QMessageBox::information( this, tr("Success"),
                            tr("Update Completed.") );
  _updateBy->clear();
}
Пример #24
0
bool salesRep::save()
{
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_number->text().isEmpty(), _number,
                          tr("You must enter a Number for this Sales Rep."))
         << GuiErrorCheck(! _commPrcnt->isValid() && _commPrcnt->text().isEmpty(),
                          _commPrcnt,
                          tr("You must enter a Commission Rate for this Sales Rep."))
  ;
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Sales Rep"), errors))
    return false;

  XSqlQuery saveq;
  if (_mode == cNew)
    saveq.prepare( "INSERT INTO salesrep ("
                   "  salesrep_number,  salesrep_active,"
                   "  salesrep_name,    salesrep_commission"
                   ") VALUES ("
                   "  :salesrep_number, :salesrep_active,"
                   "  :salesrep_name,   :salesrep_commission"
                   ") RETURNING salesrep_id;" );
  else if (_mode == cEdit)
  {
    saveq.prepare( "UPDATE salesrep "
                   "SET salesrep_active=:salesrep_active, "
                   "    salesrep_number=:salesrep_number,"
                   "    salesrep_name=:salesrep_name, "
                   "    salesrep_commission=:salesrep_commission "
                   "WHERE (salesrep_id=:salesrep_id) "
                   "RETURNING salesrep_id;" );
    saveq.bindValue(":salesrep_id", _salesrepid);
  }

  saveq.bindValue(":salesrep_number",     _number->text());
  saveq.bindValue(":salesrep_name",       _name->text());
  saveq.bindValue(":salesrep_commission", (_commPrcnt->toDouble() / 100));
  saveq.bindValue(":salesrep_active",     QVariant(_active->isChecked()));
  saveq.exec();
  if (saveq.first())
    _salesrepid = saveq.value("salesrep_id").toInt();
  else if (ErrorReporter::error(QtCriticalMsg, this,
                                tr("Error saving Sales Rep"),
                                saveq, __FILE__, __LINE__))
    return false;

  XSqlQuery crmq;
  crmq.prepare("SELECT crmacct_id, crmacct_emp_id"
               "  FROM crmacct"
               " WHERE crmacct_salesrep_id=:id;");
  crmq.bindValue(":id", _salesrepid);
  crmq.exec();
  if (crmq.first())
  {
    _crmacctid = crmq.value("crmacct_id").toInt();
    _empid     = crmq.value("crmacct_emp_id").toInt();
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Database Error"),
                                crmq, __FILE__, __LINE__))
    return false;
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("CRM Account Error"),
                          tr("<p>The Sales Rep should now have a CRM Account, "
                             "but that CRM Account could not be found. Please "
                             "check the database server log for errors.")))
    return false;

  omfgThis->sSalesRepUpdated(_salesrepid);
  return true;
}
Пример #25
0
void salesCategory::sSave()
{
    XSqlQuery salesSave;
    QList<GuiErrorCheck> errors;

    errors << GuiErrorCheck(_category->text().trimmed().isEmpty(), _category,
                            tr("<p>You must specify a name for the Sales Category."));

    salesSave.prepare("SELECT salescat_id"
                      "  FROM salescat"
                      " WHERE((salescat_name=:salescat_name)"
                      "   AND (salescat_id != :salescat_id))");
    salesSave.bindValue(":salescat_id", _salescatid);
    salesSave.bindValue(":salescat_name", _category->text().trimmed());
    salesSave.exec();
    if(salesSave.first())
    {
        errors << GuiErrorCheck(true, _category,
                                tr("<p>You cannot specify a duplicate name for the Sales Category."));
    }

    if (_metrics->boolean("InterfaceARToGL"))
    {
        errors << GuiErrorCheck(!_sales->isValid(), _sales,
                                tr("<p>You must select a Sales Account Number for this Sales Category before you may save it."))
               << GuiErrorCheck(!_prepaid->isValid(), _prepaid,
                                tr("<p>You must select a Prepaid Account Number for this Sales Category before you may save it."))
               << GuiErrorCheck(!_araccnt->isValid(), _araccnt,
                                tr("<p>You must select an A/R Account Number for this Sales Category before you may save it."))
               ;
    }

    if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Sales Category"), errors))
        return;

    if ( (_mode == cNew) || (_mode == cCopy) )
    {
        salesSave.exec("SELECT NEXTVAL('salescat_salescat_id_seq') AS salescat_id");
        if (salesSave.first())
            _salescatid = salesSave.value("salescat_id").toInt();

        salesSave.prepare( "INSERT INTO salescat"
                           "( salescat_id, salescat_name, salescat_active, salescat_descrip,"
                           "  salescat_sales_accnt_id, salescat_prepaid_accnt_id, salescat_ar_accnt_id ) "
                           "VALUES "
                           "( :salescat_id, :salescat_name, :salescat_active, :salescat_descrip,"
                           "  :salescat_sales_accnt_id, :salescat_prepaid_accnt_id, :salescat_ar_accnt_id );" );
    }
    else if (_mode == cEdit)
        salesSave.prepare( "UPDATE salescat "
                           "SET salescat_name=:salescat_name, salescat_active=:salescat_active,"
                           "    salescat_descrip=:salescat_descrip,"
                           "    salescat_sales_accnt_id=:salescat_sales_accnt_id,"
                           "    salescat_prepaid_accnt_id=:salescat_prepaid_accnt_id,"
                           "    salescat_ar_accnt_id=:salescat_ar_accnt_id "
                           "WHERE (salescat_id=:salescat_id);" );

    salesSave.bindValue(":salescat_id", _salescatid);
    salesSave.bindValue(":salescat_name", _category->text().trimmed());
    salesSave.bindValue(":salescat_active", QVariant(_active->isChecked()));
    salesSave.bindValue(":salescat_descrip", _description->text().trimmed());
    salesSave.bindValue(":salescat_sales_accnt_id", _sales->id());
    salesSave.bindValue(":salescat_prepaid_accnt_id", _prepaid->id());
    salesSave.bindValue(":salescat_ar_accnt_id", _araccnt->id());
    salesSave.exec();

    done(_salescatid);
}
Пример #26
0
void shipTo::sSave()
{
  XSqlQuery shipSave;
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_name->text().length() == 0, _name,
                          tr("You must enter a valid Name."))
  ;
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Ship To"), errors))
    return;

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

  if (! shipSave.exec("BEGIN"))
  {
    systemError(this, shipSave.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  int saveResult = _address->save(AddressCluster::CHECK);
  if (-2 == saveResult)
  {
    int answer = QMessageBox::question(this,
		    tr("Question Saving Address"),
		    tr("<p>There are multiple uses of this Ship-To "
		       "Address. What would you like to do?"),
		    tr("Change This One"),
		    tr("Change Address for All"),
		    tr("Cancel"),
		    2, 2);
    if (0 == answer)
      saveResult = _address->save(AddressCluster::CHANGEONE);
    else if (1 == answer)
      saveResult = _address->save(AddressCluster::CHANGEALL);
  }
  if (saveResult < 0)	// not else-if: this is error check for CHANGE{ONE,ALL}
  {
    systemError(this, tr("<p>There was an error saving this address (%1). "
			 "Check the database server log for errors.")
		      .arg(saveResult), __FILE__, __LINE__);
    rollback.exec();
    _address->setFocus();
    return;
  }

  XSqlQuery saveq;
  saveq.prepare( "UPDATE shiptoinfo "
                 "SET shipto_active=:shipto_active, shipto_default=:shipto_default,"
                 "    shipto_num=:shipto_num, shipto_name=:shipto_name,"
                 "    shipto_cntct_id=:shipto_cntct_id, shipto_commission=:shipto_commission,"
                 "    shipto_comments=:shipto_comments, shipto_shipcomments=:shipto_shipcomments,"
                 "    shipto_taxzone_id=:shipto_taxzone_id, shipto_salesrep_id=:shipto_salesrep_id,"
                 "    shipto_shipzone_id=:shipto_shipzone_id,"
                 "    shipto_shipvia=:shipto_shipvia, shipto_shipform_id=:shipto_shipform_id,"
                 "    shipto_shipchrg_id=:shipto_shipchrg_id,"
                 "    shipto_preferred_warehous_id=:shipto_preferred_warehous_id,"
                 "    shipto_addr_id=:shipto_addr_id "
                 "WHERE (shipto_id=:shipto_id);" );

  saveq.bindValue(":shipto_id", _shiptoid);
  saveq.bindValue(":shipto_active", QVariant(_active->isChecked()));
  saveq.bindValue(":shipto_default", QVariant(_default->isChecked()));
  saveq.bindValue(":shipto_cust_id", _custid);
  saveq.bindValue(":shipto_num", _shipToNumber->text().trimmed());
  saveq.bindValue(":shipto_name", _name->text());
  if (_contact->id() > 0)
    saveq.bindValue(":shipto_cntct_id", _contact->id());
  if (_address->id() > 0)
    saveq.bindValue(":shipto_addr_id", _address->id());
  saveq.bindValue(":shipto_commission", (_commission->toDouble() / 100));
  saveq.bindValue(":shipto_comments", _comments->toPlainText());
  saveq.bindValue(":shipto_shipcomments", _shippingComments->toPlainText());
  saveq.bindValue(":shipto_shipvia", _shipVia->currentText());
  if (_taxzone->isValid())
    saveq.bindValue(":shipto_taxzone_id",  _taxzone->id());
  if (_salesRep->id() != -1)
    saveq.bindValue(":shipto_salesrep_id", _salesRep->id());
  if (_shipZone->isValid())
    saveq.bindValue(":shipto_shipzone_id", _shipZone->id());
  if (_shipform->id() != -1)
    saveq.bindValue(":shipto_shipform_id", _shipform->id());
  if (_shipchrg->id() != -1)
    saveq.bindValue(":shipto_shipchrg_id", _shipchrg->id());
  saveq.bindValue(":shipto_preferred_warehous_id", _sellingWarehouse->id());
  saveq.exec();
  if (saveq.lastError().type() != QSqlError::NoError)
  {
    rollback.exec();
    systemError(this, saveq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  shipSave.exec("COMMIT;");

  if (_mode == cNew)
    emit newId(_shiptoid);
  _mode = 0;

  done(_shiptoid);
}
Пример #27
0
void warehouse::sSave()
{
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_code->text().trimmed().isEmpty(), _code,
                          tr("<p>You must enter a code for this Site "
                                 "before saving it."))
         << GuiErrorCheck(!_sitetype->isValid(), _sitetype,
                          tr("<p>You must enter a Type for this "
                                 "Site before saving it."))
         << GuiErrorCheck(_account->id() == -1, _account,
                          tr("<p>You must enter a default Account for this "
                             "Site before saving it."))
         << GuiErrorCheck(_transit->isChecked() && ! _costcat->isValid(),
                          _costcat,
                          tr("<p>You must select a Cost Category for this "
                             "Transit Site before saving it."))
         ;

  XSqlQuery ctq;
  if (_mode != cNew)
  {
    ctq.prepare( "SELECT warehous_id "
               "FROM whsinfo "
               "WHERE ( (warehous_counttag_prefix=:prefix)"
               " AND (warehous_id<>:warehous_id) );" );
    ctq.bindValue(":warehous_id", _warehousid);
  }
  else
    ctq.prepare( "SELECT warehous_id "
               "FROM whsinfo "
               "WHERE (warehous_counttag_prefix=:prefix)" );
  ctq.bindValue(":prefix", _countTagPrefix->text());
  ctq.exec();
  if (ctq.first())
  {
    errors << GuiErrorCheck(true, _countTagPrefix,
                           tr("<p>The Count Tag prefix entered has been used "
                              "in another Site. To enable Count Tag "
                              "audits, the application requires a unique Count "
                              "Tag prefix for each Site. Please enter a "
                              "different Count Tag prefix." ) );
    _countTagPrefix->clear();
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Checking Count Tag"),
                                ctq, __FILE__, __LINE__))
    return;

  XSqlQuery uniq;
  uniq.prepare("SELECT warehous_id "
               "FROM whsinfo "
               "WHERE ( (warehous_id<>:warehous_id)"
               " AND (UPPER(warehous_code)=UPPER(:warehous_code)) );" );
  uniq.bindValue(":warehous_id", _warehousid);
  uniq.bindValue(":warehous_code", _code->text());
  uniq.exec();
  if (uniq.first())
  {
    errors << GuiErrorCheck(true, _code,
                            tr("<p>The new Site information cannot be "
                               "saved as the new Site Code that you "
                               "entered conflicts with an existing Site. "
                               "You must uniquely name this Site before "
                               "you may save it." ));
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Checking Site Code"),
                                uniq, __FILE__, __LINE__))
    return;

  XSqlQuery activeq;
  if (!_active->isChecked())
  {
    activeq.prepare( "SELECT itemsite_id "
                     "FROM itemsite "
                     "WHERE ( (itemsite_active)"
                     " AND (itemsite_warehous_id=:warehous_id) );" );
    activeq.bindValue(":warehous_id", _warehousid);
    activeq.exec();
    if (activeq.first())
    {
      errors << GuiErrorCheck(true, _active,
                              tr("This Site is used in an active Item Site and must be marked as active. "
                              "Deactivate the Item Sites to allow this Site to not be active.") );
      _active->setFocus();
    }
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Checking Active Itemsites"),
                                  activeq, __FILE__, __LINE__))
      return;
  }

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

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

  XSqlQuery begin("BEGIN");
  if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving"),
                           begin, __FILE__, __LINE__))
    return;

  int saveResult = _address->save(AddressCluster::CHECK);
  if (-2 == saveResult)
  {
    int answer = QMessageBox::question(this, tr("Question Saving Address"),
                    tr("<p>There are multiple uses of this Site Address.</p>"
                       "<p>What would you like to do?</p>"),
                    tr("Change This One"),
                    tr("Change Address for All"),
                    tr("Cancel"),
                    2, 2);
    if (0 == answer)
      saveResult = _address->save(AddressCluster::CHANGEONE);
    else if (1 == answer)
      saveResult = _address->save(AddressCluster::CHANGEALL);
  }
  if (saveResult < 0)   // not else-if: this is error check for CHANGE{ONE,ALL}
  {
    rollback.exec();
    ErrorReporter::error(QtCriticalMsg, this, tr("Error Occurred"),
                         tr("%1: There was an error saving this address (%2).\n"
                            "Check the database server log for errors.")
                         .arg(windowTitle())
                         .arg(saveResult),__FILE__,__LINE__);
    _address->setFocus();
    return;
  }

  XSqlQuery upsq;
  if (_mode == cNew)
    upsq.prepare( "INSERT INTO whsinfo "
               "( warehous_id, warehous_code, warehous_descrip,"
               "  warehous_cntct_id, warehous_fob, warehous_active,"
               "  warehous_bol_prefix, warehous_bol_number, warehous_shipping,"
               "  warehous_counttag_prefix, warehous_counttag_number, warehous_useslips,"
               "  warehous_aislesize, warehous_aislealpha,"
               "  warehous_racksize, warehous_rackalpha,"
               "  warehous_binsize, warehous_binalpha,"
               "  warehous_locationsize, warehous_locationalpha,"
               "  warehous_enforcearbl, warehous_usezones, "
               "  warehous_default_accnt_id, warehous_shipping_commission, "
               "  warehous_addr_id, warehous_taxzone_id, warehous_transit,"
               "  warehous_shipform_id, warehous_picklist_shipform_id, warehous_shipvia_id,"
               "  warehous_shipcomments, warehous_costcat_id, warehous_sitetype_id,"
               "  warehous_sequence ) "
               "VALUES "
               "( :warehous_id, :warehous_code, :warehous_descrip,"
               "  :warehous_cntct_id, :warehous_fob, :warehous_active,"
               "  :warehous_bol_prefix, :warehous_bol_number, :warehous_shipping,"
               "  :warehous_counttag_prefix, :warehous_counttag_number, :warehous_useslips,"
               "  :warehous_aislesize, :warehous_aislealpha,"
               "  :warehous_racksize, :warehous_rackalpha,"
               "  :warehous_binsize, :warehous_binalpha,"
               "  :warehous_locationsize, :warehous_locationalpha,"
               "  :warehous_enforcearbl, :warehous_usezones, "
               "  :warehous_default_accnt_id, :warehous_shipping_commission, "
               "  :warehous_addr_id, :warehous_taxzone_id, :warehous_transit,"
               "  :warehous_shipform_id, :warehous_picklist_shipform_id, :warehous_shipvia_id,"
               "  :warehous_shipcomments, :warehous_costcat_id, :warehous_sitetype_id,"
               "  :warehous_sequence );" );
  else if (_mode == cEdit)
    upsq.prepare( "UPDATE whsinfo "
               "SET warehous_code=:warehous_code,"
               "    warehous_descrip=:warehous_descrip,"
               "    warehous_cntct_id=:warehous_cntct_id, "
               "    warehous_fob=:warehous_fob,"
               "    warehous_active=:warehous_active,"
               "    warehous_bol_prefix=:warehous_bol_prefix,"
               "    warehous_bol_number=:warehous_bol_number,"
               "    warehous_shipping=:warehous_shipping,"
               "    warehous_counttag_prefix=:warehous_counttag_prefix,"
               "    warehous_counttag_number=:warehous_counttag_number,"
               "    warehous_useslips=:warehous_useslips,"
               "    warehous_aislesize=:warehous_aislesize,"
               "    warehous_aislealpha=:warehous_aislealpha,"
               "    warehous_racksize=:warehous_racksize,"
               "    warehous_rackalpha=:warehous_rackalpha,"
               "    warehous_binsize=:warehous_binsize,"
               "    warehous_binalpha=:warehous_binalpha,"
               "    warehous_locationsize=:warehous_locationsize,"
               "    warehous_locationalpha=:warehous_locationalpha,"
               "    warehous_enforcearbl=:warehous_enforcearbl,"
               "    warehous_usezones=:warehous_usezones,"
               "    warehous_default_accnt_id=:warehous_default_accnt_id, "
               "    warehous_shipping_commission=:warehous_shipping_commission,"
               "    warehous_addr_id=:warehous_addr_id,"
               "    warehous_taxzone_id=:warehous_taxzone_id,"
               "    warehous_transit=:warehous_transit,"
               "    warehous_shipform_id=:warehous_shipform_id,"
               "    warehous_picklist_shipform_id=:warehous_picklist_shipform_id,"
               "    warehous_shipvia_id=:warehous_shipvia_id,"
               "    warehous_shipcomments=:warehous_shipcomments,"
               "    warehous_costcat_id=:warehous_costcat_id, "
               "    warehous_sitetype_id=:warehous_sitetype_id,"
               "    warehous_sequence=:warehous_sequence "
               "WHERE (warehous_id=:warehous_id);" );

  upsq.bindValue(":warehous_id", _warehousid);
  upsq.bindValue(":warehous_code", _code->text().trimmed().toUpper());
  upsq.bindValue(":warehous_descrip", _description->text());
  if (_contact->id() > 0)
    upsq.bindValue(":warehous_cntct_id", _contact->id());  // else NULL
  if (_address->id() > 0)
    upsq.bindValue(":warehous_addr_id", _address->id());   // else NULL

  upsq.bindValue(":warehous_active", QVariant(_active->isChecked()));
  upsq.bindValue(":warehous_default_accnt_id", _account->id());
  if(_sitetype->isValid())
    upsq.bindValue(":warehous_sitetype_id", _sitetype->id());
  upsq.bindValue(":warehous_sequence",     _sequence->value());

  if (_standard->isChecked())
  {
    upsq.bindValue(":warehous_fob",             _defaultFOB->text());
    upsq.bindValue(":warehous_bol_prefix",      _bolPrefix->text());
    upsq.bindValue(":warehous_bol_number",      _bolNumber->text().toInt());
    upsq.bindValue(":warehous_counttag_prefix", _countTagPrefix->text());
    upsq.bindValue(":warehous_counttag_number", _countTagNumber->text().toInt());
    upsq.bindValue(":warehous_shipping",   QVariant(_shipping->isChecked()));
    upsq.bindValue(":warehous_useslips",   QVariant(_useSlips->isChecked()));
    upsq.bindValue(":warehous_enforcearbl",QVariant(_arblGroup->isChecked()));
    upsq.bindValue(":warehous_aislesize",  _aisleSize->value());
    upsq.bindValue(":warehous_aislealpha", QVariant(_aisleAlpha->isChecked()));
    upsq.bindValue(":warehous_racksize",   _rackSize->value());
    upsq.bindValue(":warehous_rackalpha",  QVariant(_rackAlpha->isChecked()));
    upsq.bindValue(":warehous_binsize",    _binSize->value());
    upsq.bindValue(":warehous_binalpha",   QVariant(_binAlpha->isChecked()));
    upsq.bindValue(":warehous_locationsize",  _locationSize->value());
    upsq.bindValue(":warehous_locationalpha", QVariant(_locationAlpha->isChecked()));
    upsq.bindValue(":warehous_usezones",      QVariant(_useZones->isChecked()));
    upsq.bindValue(":warehous_shipping_commission", (_shipcomm->toDouble() / 100));
    if(_taxzone->isValid())
      upsq.bindValue(":warehous_taxzone_id",       _taxzone->id());
  }

  upsq.bindValue(":warehous_transit",      QVariant(_transit->isChecked()));
  if (_transit->isChecked())
  {
    if (_shipform->isValid())
      upsq.bindValue(":warehous_shipform_id",      _shipform->id());
    if (_pickList->isValid())
      upsq.bindValue(":warehous_picklist_shipform_id",  _pickList->id()); 
    if (_shipvia->isValid())
      upsq.bindValue(":warehous_shipvia_id",       _shipvia->id());
    upsq.bindValue(":warehous_shipcomments",       _shipcomments->toPlainText());
    if (_costcat->isValid())
      upsq.bindValue(":warehous_costcat_id",       _costcat->id());
  }

  upsq.exec();
  if (upsq.lastError().type() != QSqlError::NoError)
  {
    rollback.exec();
    ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving"),
                         upsq, __FILE__, __LINE__);
    return;
  }

  XSqlQuery commit("COMMIT;");

  omfgThis->sWarehousesUpdated();
  emit saved(_warehousid);
  done(_warehousid);
}
Пример #28
0
bool employee::sSave(const bool pClose)
{
  bool dupCode   = false;
  bool dupNumber = false;

  XSqlQuery dupq;
  dupq.prepare("SELECT emp_id"
               "  FROM emp"
               " WHERE(emp_code=:code) AND (emp_id != :id);");
  dupq.bindValue(":code", _code->text());
  dupq.bindValue(":id",   _empid);
  dupq.exec();
  if(dupq.first())
    dupCode = true;
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Database Error"),
                                dupq, __FILE__, __LINE__))
    return false;

  dupq.prepare("SELECT emp_id"
               "  FROM emp"
               " WHERE(emp_number=:number) AND (emp_id != :id);");
  dupq.bindValue(":number", _number->text());
  dupq.bindValue(":id",     _empid);
  dupq.exec();
  if(dupq.first())
    dupNumber = true;
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Database Error"),
                                dupq, __FILE__, __LINE__))
    return false;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_code->text().isEmpty(), _code,
                          tr("You must enter a valid Employee Code."))
         << GuiErrorCheck(_number->text().isEmpty(), _number,
                          tr("You must enter an Employee Number."))
         << GuiErrorCheck(dupCode, _code,
                          tr("An Employee already exists for the Code specified."))
         << GuiErrorCheck(_code->text() == _mgr->number(), _number,
                          tr("An Employee already exists for the Number specified."))
         << GuiErrorCheck(_code->text() == _mgr->number(), _mgr,
                          tr("An Employee cannot be his or her own Manager."))
    ;
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Employee"), errors))
    return false;

  _contact->check();

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

  XSqlQuery begin("BEGIN;");
  int cntctResult = _contact->save();
  if (cntctResult < 0)
  {
    rollback.exec();
    ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Contact"),
                         storedProcErrorLookup("saveContact", cntctResult));
    return false;
  }

  XSqlQuery upsq;
  if (_mode == cNew)
    upsq.prepare("INSERT INTO emp ("
                 " emp_code,        emp_number,   emp_active,       emp_cntct_id,"
                 " emp_warehous_id, emp_mgr_emp_id,"
                 " emp_wage_type,   emp_wage,     emp_wage_curr_id, emp_wage_period,"
                 " emp_dept_id,     emp_shift_id, emp_notes,        emp_image_id,"
                 " emp_extrate,     emp_extrate_period, emp_startdate, emp_name"
                 ") VALUES ("
                 " :code,        :number,   :active,       :cntct_id,"
                 " :warehous_id, :mgr_emp_id,"
                 " :wage_type,   :wage,     :wage_curr_id, :wage_period,"
                 " :dept_id,     :shift_id, :notes,        :image_id,"
                 " :extrate,     :extrate_period, :startdate, :name"
                 ") RETURNING emp_id;");

  else if (_mode == cEdit)
  {
    upsq.prepare("UPDATE emp SET"
                 " emp_code=:code,"
                 " emp_number=:number,"
                 " emp_active=:active,"
                 " emp_cntct_id=:cntct_id,"
                 " emp_warehous_id=:warehous_id,"
                 " emp_mgr_emp_id=:mgr_emp_id,"
                 " emp_wage_type=:wage_type,"
                 " emp_wage=:wage,"
                 " emp_wage_curr_id=:wage_curr_id,"
                 " emp_wage_period=:wage_period,"
                 " emp_dept_id=:dept_id,"
                 " emp_shift_id=:shift_id,"
                 " emp_notes=:notes,"
                 " emp_image_id=:image_id,"
                 " emp_extrate=:extrate,"
                 " emp_extrate_period=:extrate_period,"
                 " emp_startdate=:startdate,"
                 " emp_name=:name"
              " WHERE (emp_id=:emp_id)"
              " RETURNING emp_id;" );
    upsq.bindValue(":emp_id", _empid);
  }

  upsq.bindValue(":code",           _code->text());
  upsq.bindValue(":number",         _number->text());
  upsq.bindValue(":active",         _active->isChecked());
  if (_contact->isValid())
    upsq.bindValue(":cntct_id",     _contact->id());
  if (_site->isValid())
    upsq.bindValue(":warehous_id",  _site->id());
  if (_mgr->isValid())
    upsq.bindValue(":mgr_emp_id",   _mgr->id());
  upsq.bindValue(":wage_type",      _wagetype->code());
  upsq.bindValue(":wage",           _rate->localValue());
  if (_rate->id() > 0)
    upsq.bindValue(":wage_curr_id", _rate->id());
  upsq.bindValue(":wage_period",    _per->code());
  if (_dept->isValid())
    upsq.bindValue(":dept_id",      _dept->id());
  if (_shift->isValid())
    upsq.bindValue(":shift_id",     _shift->id());
  upsq.bindValue(":notes",          _notes->toPlainText());
  if (_image->isValid())
    upsq.bindValue(":image_id",     _image->id());
  upsq.bindValue(":extrate",        _externalRate->localValue());
  upsq.bindValue(":extrate_period", _perExt->code());
  upsq.bindValue(":startdate",      _startDate->date());
  upsq.bindValue(":name",           _name->text());

  upsq.exec();
  if (upsq.first())
    _empid = upsq.value("emp_id").toInt();
  else if (upsq.lastError().type() != QSqlError::NoError)
  {
    rollback.exec();
    ErrorReporter::error(QtCriticalMsg, this, tr("Error saving Employee"),
                         upsq, __FILE__, __LINE__);
    return false;
  }

  XSqlQuery commit("COMMIT;");

  emit saved();
  omfgThis->sEmployeeUpdated(_empid);

  if (pClose)
    done(_empid);
  else
    sPopulate();

  return true;
}
Пример #29
0
void currencyConversion::_sSave()
{
  XSqlQuery currency_sSave;

  QList<GuiErrorCheck>errors;
  errors<<GuiErrorCheck(! _currency->isValid(), _currency,
                        tr("Please specify a currency for this exchange rate."))
       <<GuiErrorCheck(_rate->toDouble() == 0, _rate,
                        tr("You must specify a Rate that is not zero."))
       <<GuiErrorCheck(!_dateCluster->startDate().isValid(), _dateCluster,
                        tr("Please specify a Start Date for this exchange rate."))
       <<GuiErrorCheck(!_dateCluster->endDate().isValid(), _dateCluster,
                        tr("Please specify an End Date for this exchange rate."))
       <<GuiErrorCheck(_dateCluster->startDate() > _dateCluster->endDate(), _dateCluster,
                        tr("The Start Date for this exchange rate is "
                           "later than the End Date.\n"
                           "Please check the values of these dates."));

  if(GuiErrorCheck::reportErrors(this,tr("Cannot Save Currency Conversion"),errors))
      return;
  
  currency_sSave.prepare( "SELECT count(*) AS numberOfOverlaps "
             "FROM curr_rate "
             "WHERE curr_id = :curr_id"
             "  AND curr_rate_id != :curr_rate_id"
             "  AND ( (curr_effective BETWEEN :curr_effective AND :curr_expires OR"
             "         curr_expires BETWEEN :curr_effective AND :curr_expires)"
             "   OR   (curr_effective <= :curr_effective AND"
             "         curr_expires   >= :curr_expires) );" );
  currency_sSave.bindValue(":curr_rate_id", _curr_rate_id);
  currency_sSave.bindValue(":curr_id", _currency->id());
  currency_sSave.bindValue(":curr_effective", _dateCluster->startDate());
  currency_sSave.bindValue(":curr_expires", _dateCluster->endDate());
  currency_sSave.exec();
  if (currency_sSave.first())
  {
    if (currency_sSave.value("numberOfOverlaps").toInt() > 0)
    {
      QMessageBox::warning(this, tr("Invalid Date Range"),
                          tr("The date range overlaps with  "
                             "another date range.\n"
                             "Please check the values of these dates."));
      _dateCluster->setFocus();
      return;
    }
  }

  QString inverter("");
  if (_metrics->value("CurrencyExchangeSense").toInt() == 1)
      inverter = "1 / ";

  QString sql;
  if (_mode == cNew)
      sql = QString("INSERT INTO curr_rate "
                    "(curr_id, curr_rate, curr_effective, curr_expires) "
                    "VALUES "
                    "(:curr_id, %1 CAST(:curr_rate AS NUMERIC), "
                    " :curr_effective, :curr_expires)")
                  .arg(inverter);
  else if (_mode == cEdit)
      sql = QString("UPDATE curr_rate SET "
                    "curr_id = :curr_id, "
                    "curr_rate = %1 CAST(:curr_rate AS NUMERIC), "
                    "curr_effective = :curr_effective, "
                    "curr_expires = :curr_expires "
                    "WHERE curr_rate_id = :curr_rate_id")
                    .arg(inverter);

  _rate->setText(_rate->text().replace(',', '.'));

  currency_sSave.prepare(sql);
  currency_sSave.bindValue(":curr_rate_id", _curr_rate_id);
  currency_sSave.bindValue(":curr_id", _currency->id());
  currency_sSave.bindValue(":curr_rate", _rate->toDouble());
  currency_sSave.bindValue(":curr_effective", _dateCluster->startDate());
  currency_sSave.bindValue(":curr_expires", _dateCluster->endDate());
  
  currency_sSave.exec();

  if (currency_sSave.lastError().type() != QSqlError::NoError)
  {
      QMessageBox::critical(this, tr("A System Error occurred at %1::%2.")
                            .arg(__FILE__)
                            .arg(__LINE__),
                            currency_sSave.lastError().databaseText());
      return;
  }

  done(_curr_rate_id);
}
Пример #30
0
void prospect::sSave()
{
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_number->text().trimmed().isEmpty(), _number,
                          tr("You must enter a number for this Prospect"))
         << GuiErrorCheck(_name->text().trimmed().isEmpty(), _name,
                          tr("You must enter a name for this Prospect"))
    ;
  // disallow overlap of prospect and customer numbers
  if (_number->text().trimmed() != _cachedNumber)
  {
    XSqlQuery dupq;
    dupq.prepare( "SELECT prospect_name AS name "
	       "FROM prospect "
	       "WHERE (UPPER(prospect_number)=UPPER(:prospect_number)) "
	       "  AND (prospect_id<>:prospect_id) "
	       "UNION "
	       "SELECT cust_name AS name "
	       "FROM custinfo "
	       "WHERE (UPPER(cust_number)=UPPER(:prospect_number));" );
    dupq.bindValue(":prospect_number", _number->text().trimmed());
    dupq.bindValue(":prospect_id",     _prospectid);
    dupq.exec();
    if (dupq.first())
      errors << GuiErrorCheck(true, _number,
			     tr("<p>The newly entered Prospect Number cannot "
				"be used as it is currently in use by '%1'. "
				"Please enter a different Prospect Number." )
			     .arg(dupq.value("name").toString()) );
  }

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

  XSqlQuery upsq;
  if (_mode == cEdit)
  {
    upsq.prepare( "UPDATE prospect SET "
               "       prospect_number=:prospect_number,"
               "       prospect_name=:prospect_name,"
               "       prospect_cntct_id=:prospect_cntct_id,"
               "       prospect_comments=:prospect_comments,"
               "       prospect_taxzone_id=:prospect_taxzone_id,"
               "       prospect_salesrep_id=:prospect_salesrep_id,"
               "       prospect_warehous_id=:prospect_warehous_id,"
               "       prospect_active=:prospect_active"
               " WHERE (prospect_id=:prospect_id)"
               " RETURNING prospect_id;" );
    upsq.bindValue(":prospect_id",	_prospectid);
  }
  else
    upsq.prepare("INSERT INTO prospect "
               "( prospect_id,	      prospect_number,	    prospect_name,"
               "  prospect_cntct_id,  prospect_taxzone_id,  prospect_comments,"
               "  prospect_salesrep_id, prospect_warehous_id, prospect_active )"
               " VALUES "
               "( DEFAULT,     	      :prospect_number,	    :prospect_name,"
               "  :prospect_cntct_id, :prospect_taxzone_id, :prospect_comments,"
               "  :prospect_salesrep_id, :prospect_warehous_id, :prospect_active )"
               " RETURNING prospect_id;");

  upsq.bindValue(":prospect_number",	_number->text().trimmed());
  upsq.bindValue(":prospect_name",	_name->text().trimmed());
  upsq.bindValue(":prospect_comments",	_notes->toPlainText());
  upsq.bindValue(":prospect_active",	QVariant(_active->isChecked()));
  if (_contact->isValid())
    upsq.bindValue(":prospect_cntct_id",    _contact->id());
  if (_taxzone->isValid())
    upsq.bindValue(":prospect_taxzone_id",  _taxzone->id());
  if (_salesrep->isValid())
    upsq.bindValue(":prospect_salesrep_id", _salesrep->id());
  if (_site->isValid())
    upsq.bindValue(":prospect_warehous_id", _site->id());

  upsq.exec();
  if (upsq.first())
    _prospectid = upsq.value("prospect_id").toInt();
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Saving Prospect"),
                                upsq, __FILE__, __LINE__))
    return;

  _NumberGen = -1;
  omfgThis->sProspectsUpdated();
  emit saved(_prospectid);
  if (_mode == cNew)
  {
    omfgThis->sCrmAccountsUpdated(_crmacctid);
    emit newId(_prospectid);   // cluster listeners couldn't handle set()'s emit
  }

  close();
}