コード例 #1
0
ファイル: shipOrder.cpp プロジェクト: josemdv/qt-client
void shipOrder::sHandleSo()
{
  XSqlQuery shipHandleSo;
  _coitem->clear();
  _shipment->setEnabled(false);
  _shipment->removeOrderLimit();

  sHandleButtons();


  shipHandleSo.prepare( "SELECT cohead_holdtype, cust_name, cohead_shiptoname, "
             "       cohead_shiptoaddress1, cohead_curr_id, cohead_freight "
             "FROM cohead, custinfo "
             "WHERE ((cohead_cust_id=cust_id) "
             "  AND  (cohead_id=:sohead_id));" );
  shipHandleSo.bindValue(":sohead_id", _order->id());
  shipHandleSo.exec();
  if (shipHandleSo.first())
  {
    QString msg;
    if ( (shipHandleSo.value("cohead_holdtype").toString() == "C"))
      msg = storedProcErrorLookup("shipShipment", -12);
    else if (shipHandleSo.value("cohead_holdtype").toString() == "P")
      msg = storedProcErrorLookup("shipShipment", -13);
    else if (shipHandleSo.value("cohead_holdtype").toString() == "R")
      msg = storedProcErrorLookup("shipShipment", -14);
    else if (shipHandleSo.value("cohead_holdtype").toString() == "S")
      msg = storedProcErrorLookup("shipShipment", -15);

    if (! msg.isEmpty())
    {
      QMessageBox::warning(this, tr("Cannot Ship Order"), msg);
      if (_captive)
      {
        _reject = true;	// so set() can return an error
        reject();	// this only works if shipOrder has been exec()'ed
      }
      else
      {
        _order->setId(-1);
        return;
      }
    }

    _freight->setId(shipHandleSo.value("cohead_curr_id").toInt());
    _freight->setLocalValue(shipHandleSo.value("cohead_freight").toDouble());
    _billToName->setText(shipHandleSo.value("cust_name").toString());
    _shipToName->setText(shipHandleSo.value("cohead_shiptoname").toString());
    _shipToAddr1->setText(shipHandleSo.value("cohead_shiptoaddress1").toString());

    QString sql( "SELECT shiphead_id "
                 "FROM shiphead "
                 "WHERE ( (NOT shiphead_shipped)"
                 "<? if exists(\"shiphead_id\") ?>"
                 " AND (shiphead_id=<? value(\"shiphead_id\") ?>)"
                 "<? endif ?>"
                 " AND (shiphead_order_id=<? value(\"sohead_id\") ?>)"
                 " AND (shiphead_order_type='SO'));" );
    ParameterList params;
    params.append("sohead_id", _order->id());
    if (_shipment->isValid())
      params.append("shiphead_id", _shipment->id());
    MetaSQLQuery mql(sql);
    shipHandleSo = mql.toQuery(params);
    if (shipHandleSo.first())
    {
      if (_shipment->id() != shipHandleSo.value("shiphead_id").toInt())
        _shipment->setId(shipHandleSo.value("shiphead_id").toInt());

      if (shipHandleSo.next())
      {
        _shipment->setType("SO");
        _shipment->limitToOrder(_order->id());
        _shipment->setEnabled(true);
      }
    }
    else if (shipHandleSo.lastError().type() != QSqlError::NoError)
    {
      systemError(this, shipHandleSo.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
    else if (_shipment->isValid())
    {
      params.clear();
      params.append("sohead_id", _order->id());
      MetaSQLQuery mql(sql);
      shipHandleSo = mql.toQuery(params);
      if (shipHandleSo.first())
      {
        _shipment->setId(shipHandleSo.value("shiphead_id").toInt());
        if (shipHandleSo.next())
        {
          _shipment->setType("SO");
          _shipment->limitToOrder(_order->id());
          _shipment->setEnabled(true);
        }
      }
      else if (shipHandleSo.lastError().type() != QSqlError::NoError)
      {
        systemError(this, shipHandleSo.lastError().databaseText(), __FILE__, __LINE__);
        return;
      }
      else
        _shipment->clear();
    }
    else
    {
      QMessageBox::warning(this, tr("Nothing to ship"),
                        tr("<p>You may not ship this Sales Order because "
                           "no stock has been issued to shipping for it."));
      _order->setFocus();
      return;
    }
  }
  else if (shipHandleSo.lastError().type() != QSqlError::NoError)
  {
    systemError(this, shipHandleSo.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
コード例 #2
0
enum SetResponse itemSource::set(const ParameterList &pParams)
{
  XSqlQuery itemet;
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("itemsrc_id", &valid);
  if (valid)
  {
    _itemsrcid = param.toInt();
    populate();
  }

  param = pParams.value("item_id", &valid);
  if (valid)
  {
    _item->setId(param.toInt());
    _item->setEnabled(FALSE);
  }

  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "new")
    {
      _mode = cNew;
      _new = true;

      itemet.exec("SELECT NEXTVAL('itemsrc_itemsrc_id_seq') AS _itemsrc_id;");
      if (itemet.first())
        _itemsrcid = itemet.value("_itemsrc_id").toInt();
      else if (itemet.lastError().type() != QSqlError::NoError)
      {
        systemError(this, itemet.lastError().databaseText(), __FILE__, __LINE__);
        return UndefinedError;
      }
      _captive = true;
      
      connect(_itemsrcp, SIGNAL(valid(bool)), _edit, SLOT(setEnabled(bool)));
      connect(_itemsrcp, SIGNAL(valid(bool)), _delete, SLOT(setEnabled(bool)));
      connect(_itemsrcp, SIGNAL(itemSelected(int)), _edit, SLOT(animateClick()));
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;

      connect(_itemsrcp, SIGNAL(valid(bool)), _edit, SLOT(setEnabled(bool)));
      connect(_itemsrcp, SIGNAL(valid(bool)), _delete, SLOT(setEnabled(bool)));
      connect(_itemsrcp, SIGNAL(itemSelected(int)), _edit, SLOT(animateClick()));

      _item->setReadOnly(TRUE);
      _vendor->setEnabled(FALSE);
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _item->setReadOnly(TRUE);
      _active->setEnabled(FALSE);
      _default->setEnabled(FALSE);
      _vendor->setEnabled(FALSE);
      _dates->setEnabled(FALSE);
      _vendorItemNumber->setEnabled(FALSE);
      _vendorItemDescrip->setEnabled(FALSE);
      _vendorUOM->setEnabled(FALSE);
      _invVendorUOMRatio->setEnabled(FALSE);
      _vendorRanking->setEnabled(FALSE);
      _minOrderQty->setEnabled(FALSE);
      _multOrderQty->setEnabled(FALSE);
      _leadTime->setEnabled(FALSE);
      _notes->setEnabled(FALSE);
      _upcCode->setEnabled(FALSE);
      _add->setEnabled(FALSE);
      _delete->setEnabled(FALSE);
      _close->setText(tr("&Close"));
      _save->hide();
    }
    if (param.toString() == "copy")
    {
      _mode = cCopy;
      _new = true;
      _captive = true;
      int itemsrcidold = _itemsrcid;

      itemet.exec("SELECT NEXTVAL('itemsrc_itemsrc_id_seq') AS _itemsrc_id;");
      if (itemet.first())
        _itemsrcid = itemet.value("_itemsrc_id").toInt();
      else if (itemet.lastError().type() != QSqlError::NoError)
      {
        systemError(this, itemet.lastError().databaseText(), __FILE__, __LINE__);
        return UndefinedError;
      }
      
      connect(_itemsrcp, SIGNAL(valid(bool)), _edit, SLOT(setEnabled(bool)));
      connect(_itemsrcp, SIGNAL(valid(bool)), _delete, SLOT(setEnabled(bool)));
      connect(_itemsrcp, SIGNAL(itemSelected(int)), _edit, SLOT(animateClick()));
      
      _item->setReadOnly(TRUE);
      _vendorItemNumber->setText(_vendorItemNumber->text().prepend("Copy Of "));
      _dates->setStartDate(omfgThis->dbDate());

      if (sSave())
      {
        itemet.prepare("INSERT INTO itemsrcp ( "
                  "itemsrcp_itemsrc_id, itemsrcp_qtybreak, "
                  "itemsrcp_price, itemsrcp_updated, itemsrcp_curr_id) "
                  "SELECT :itemsrcid, itemsrcp_qtybreak, "
                  "itemsrcp_price, current_date, itemsrcp_curr_id "
                  "FROM itemsrcp "
                  "WHERE (itemsrcp_itemsrc_id=:itemsrcidold); ");
        itemet.bindValue(":itemsrcid", _itemsrcid);
        itemet.bindValue(":itemsrcidold", itemsrcidold);
        itemet.exec();
        sFillPriceList();
      }
    }
  }

  return NoError;
}
コード例 #3
0
itemSource::itemSource(QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
    : XDialog(parent, name, modal, fl)
{
  XSqlQuery itemitemSource;
  setupUi(this);

  connect(_add,                SIGNAL(clicked()), this, SLOT(sAdd()));
  connect(_close,              SIGNAL(clicked()), this, SLOT(reject()));
  connect(_delete,             SIGNAL(clicked()), this, SLOT(sDelete()));
  connect(_edit,               SIGNAL(clicked()), this, SLOT(sEdit()));
  connect(_itemsrcp,SIGNAL(populateMenu(QMenu*, XTreeWidgetItem*)), this, SLOT(sPopulateMenu(QMenu*)));
  connect(_save,               SIGNAL(clicked()), this, SLOT(sSaveClicked()));
  connect(_vendor,             SIGNAL(newId(int)), this, SLOT(sVendorChanged(int)));
  connect(_vendorCurrency,     SIGNAL(newID(int)), this, SLOT(sFillPriceList()));
  connect(_contract,           SIGNAL(newID(int)), this, SLOT(sContractChanged(int)));
  connect(this,                SIGNAL(rejected()), this, SLOT(sRejected()));

//  TODO method doesn't exist?
//  connect(_vendorUOM, SIGNAL(textChanged()), this, SLOT(sClearVendorUOM()));
//  connect(_invVendorUOMRatio, SIGNAL(textChanged(QString)), this, SLOT(sClearVendorUOM()));

  _vendorUOM->setType(XComboBox::UOMs);

  _item->setType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cGeneralManufactured | ItemLineEdit::cTooling);
  _item->setDefaultType(ItemLineEdit::cGeneralPurchased);

  _dates->setStartNull(tr("Always"), omfgThis->startOfTime(), TRUE);
  _dates->setStartCaption(tr("Effective"));
  _dates->setEndNull(tr("Never"), omfgThis->endOfTime(), TRUE);
  _dates->setEndCaption(tr("Expires"));

  _captive = false;
  _new = false;
  
  QString base;
  itemitemSource.exec("SELECT currConcat(baseCurrID()) AS base;");
  if (itemitemSource.first())
    base = itemitemSource.value("base").toString();
  else
    base = tr("Base");

  if (_metrics->boolean("MultiWhs"))
  {
    _itemsrcp->addColumn(tr("Site"),                      _qtyColumn, Qt::AlignCenter,true, "warehous_code");
    _itemsrcp->addColumn(tr("Order Type"),                        -1, Qt::AlignCenter,true, "itemsrcp_dropship");
  }
  _itemsrcp->addColumn(tr("Qty Break"),                   _qtyColumn, Qt::AlignRight, true, "itemsrcp_qtybreak");
  _itemsrcp->addColumn(tr("Unit Price"),                          -1, Qt::AlignRight, true, "itemsrcp_price");
  _itemsrcp->addColumn(tr("Currency"),               _currencyColumn, Qt::AlignLeft,  true, "item_curr");
  _itemsrcp->addColumn(tr("Discount Percent"),                    -1, Qt::AlignRight, true, "itemsrcp_discntprcnt" );
  _itemsrcp->addColumn(tr("Discount Fixed Amt."),                 -1, Qt::AlignRight, true, "itemsrcp_fixedamtdiscount" );
  _itemsrcp->addColumn(tr("Unit Price\n(%1)").arg(base),_moneyColumn, Qt::AlignRight, true, "price_base");
  _itemsrcp->addColumn(tr("Type"),                      _orderColumn, Qt::AlignLeft,  true, "type" );
  _itemsrcp->addColumn(tr("Method"),                    _orderColumn, Qt::AlignLeft,  true, "method" );

  if (omfgThis->singleCurrency())
  {
    _itemsrcp->hideColumn(1);
    _itemsrcp->hideColumn(2);
    _itemsrcp->headerItem()->setText(3, tr("Unit Price"));
  }

  _invVendorUOMRatio->setValidator(omfgThis->ratioVal());
  _minOrderQty->setValidator(omfgThis->qtyVal());
  _multOrderQty->setValidator(omfgThis->qtyVal());

  _vendorCurrency->setType(XComboBox::Currencies);
  _vendorCurrency->setLabel(_vendorCurrencyLit);
  
  itemitemSource.exec("SELECT MAX(itemsrc_id),itemsrc_manuf_name, itemsrc_manuf_name FROM itemsrc GROUP BY itemsrc_manuf_name;");
  _manufName->populate(itemitemSource);
  _manufName->setCurrentIndex(0);
}
コード例 #4
0
void plannedOrder::sHandleItemsite(int pWarehousid)
{
  XSqlQuery plannedHandleItemsite;
  plannedHandleItemsite.prepare( "SELECT itemsite_leadtime, itemsite_wosupply, itemsite_posupply, item_type "
             "FROM itemsite JOIN item ON (item_id=itemsite_item_id) "
             "WHERE ( (itemsite_item_id=:item_id)"
             " AND (itemsite_warehous_id=:warehous_id) );" );
  plannedHandleItemsite.bindValue(":item_id", _item->id());
  plannedHandleItemsite.bindValue(":warehous_id", pWarehousid);
  plannedHandleItemsite.exec();
  if (!plannedHandleItemsite.first())
  {
    systemError(this, plannedHandleItemsite.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  _leadTime->setValue(plannedHandleItemsite.value("itemsite_leadtime").toInt());
  
  if ( plannedHandleItemsite.value("itemsite_posupply").toBool() &&
      (plannedHandleItemsite.value("item_type").toString() == "P" ||
       plannedHandleItemsite.value("item_type").toString() == "O" ||
       plannedHandleItemsite.value("item_type").toString() == "T" ||
       plannedHandleItemsite.value("item_type").toString() == "M") )
    _poButton->setEnabled(TRUE);
  else
    _poButton->setEnabled(FALSE);
  if ( plannedHandleItemsite.value("itemsite_wosupply").toBool() &&
      (plannedHandleItemsite.value("item_type").toString() == "P" ||
       plannedHandleItemsite.value("item_type").toString() == "T" ||
       plannedHandleItemsite.value("item_type").toString() == "M") )
    _woButton->setEnabled(TRUE);
  else
    _woButton->setEnabled(FALSE);
  if ( plannedHandleItemsite.value("itemsite_wosupply").toBool() && plannedHandleItemsite.value("itemsite_posupply").toBool() && plannedHandleItemsite.value("item_type").toString() == "P" )
  {
    _poButton->setChecked(TRUE);
    _woButton->setChecked(FALSE);
  }
  else if ( plannedHandleItemsite.value("itemsite_wosupply").toBool() )
  {
    _poButton->setChecked(FALSE);
    _woButton->setChecked(TRUE);
  }
  else
  {
    _poButton->setChecked(TRUE);
    _woButton->setChecked(FALSE);
  }

  plannedHandleItemsite.prepare( "SELECT COALESCE(COUNT(*), 0) AS supplysites "
             "FROM itemsite "
             "WHERE ( (itemsite_item_id=:item_id)"
             " AND (itemsite_warehous_id <> :warehous_id) );" );
  plannedHandleItemsite.bindValue(":item_id", _item->id());
  plannedHandleItemsite.bindValue(":warehous_id", pWarehousid);
  plannedHandleItemsite.exec();
  if (!plannedHandleItemsite.first())
  {
    systemError(this, plannedHandleItemsite.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  if (plannedHandleItemsite.value("supplysites").toInt() > 0)
    _toButton->setEnabled(TRUE);
  else
    _toButton->setEnabled(FALSE);

  plannedHandleItemsite.prepare( "SELECT COALESCE(supply.itemsite_id, -1) AS supplyitemsiteid,"
             "       COALESCE(supply.itemsite_warehous_id, -1) AS supplywarehousid "
             "FROM itemsite LEFT OUTER JOIN itemsite supply ON (supply.itemsite_id=itemsite.itemsite_supply_itemsite_id)"
             "WHERE ( (itemsite.itemsite_item_id=:item_id)"
             "  AND   (itemsite.itemsite_warehous_id=:warehous_id) );" );
  plannedHandleItemsite.bindValue(":item_id", _item->id());
  plannedHandleItemsite.bindValue(":warehous_id", pWarehousid);
  plannedHandleItemsite.exec();
  if (!plannedHandleItemsite.first())
  {
    systemError(this, plannedHandleItemsite.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  if (plannedHandleItemsite.value("supplyitemsiteid").toInt() != -1)
  {
    _toButton->setChecked(TRUE);
    _fromWarehouse->setId(plannedHandleItemsite.value("supplywarehousid").toInt());
  }
  else
    _fromWarehouse->setId(pWarehousid);
}
コード例 #5
0
ファイル: package.cpp プロジェクト: dwatson78/qt-client
void package::populate()
{
  XSqlQuery packagepopulate;
  if (DEBUG)    qDebug("package::populate() entered");

  packagepopulate.prepare("SELECT *, packageIsEnabled(pkghead_name) AS enabled "
            "FROM pkghead WHERE (pkghead_id=:pkghead_id);");
  packagepopulate.bindValue(":pkghead_id", _pkgheadid);
  packagepopulate.exec();
  if (packagepopulate.first())
  {
    if (DEBUG)    qDebug("package::populate() select pkghead succeeded");
    _name->setText(packagepopulate.value("pkghead_name").toString());
    _description->setText(packagepopulate.value("pkghead_descrip").toString());
    if (DEBUG)    qDebug("package::populate() select pkghead half done");
    _version->setText(packagepopulate.value("pkghead_version").toString());
    _developer->setText(packagepopulate.value("pkghead_developer").toString());
    _notes->setText(packagepopulate.value("pkghead_notes").toString());
    _enabled->setChecked(packagepopulate.value("enabled").toBool());
    _priorEnabledState = _enabled->isChecked();
    _indev->setChecked(packagepopulate.value("pkghead_indev").toBool());
    if (DEBUG)    qDebug("package::populate() select pkghead complete");
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Package Information"),
                                packagepopulate, __FILE__, __LINE__))
  {
    return;
  }

  ParameterList params;
  params.append("pkgname", _name->text());
  params.append("script",  tr("Script"));
  params.append("cmd",     tr("Custom Command"));
  params.append("function",tr("Stored Procedure"));
  params.append("trigger", tr("Trigger"));
  params.append("image",   tr("Image"));
  params.append("metasql", tr("MetaSQL"));
  params.append("priv",    tr("Privilege"));
  params.append("report",  tr("Report"));
  params.append("schema",  tr("Schema"));
  params.append("table",   tr("Table"));
  params.append("uiform",  tr("Screen"));
  params.append("view",    tr("View"));
  params.append("sequence",tr("Sequence"));
  params.append("index",   tr("Index"));
  if (_showSystemDetails->isChecked())
    params.append("showsystemdetails");

  MetaSQLQuery itemmql = mqlLoad("package", "items");
  packagepopulate = itemmql.toQuery(params);

  packagepopulate.exec();
  if (DEBUG)    qDebug("package::populate() select pkgitem exec'ed");
  _rec->populate(packagepopulate);
  if (DEBUG)    qDebug("package::populate() populate pkgitem done");
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Package Information"),
                                packagepopulate, __FILE__, __LINE__))
  {
    return;
  }

  // TODO: make this recursive?
  packagepopulate.prepare("SELECT pkghead.* "
            "FROM pkgdep, pkghead "
            "WHERE ((pkgdep_pkghead_id=pkghead_id)"
            "  AND  (pkgdep_parent_pkghead_id=:pkghead_id));");
  packagepopulate.bindValue(":pkghead_id", _pkgheadid);
  packagepopulate.exec();
  if (DEBUG)    qDebug("package::populate() select pkgdep exec'ed");
  _dep->populate(packagepopulate);
  if (DEBUG)    qDebug("package::populate() populate pkgdep done");
  if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting Package Info"),
                           packagepopulate, __FILE__, __LINE__))
  {
    return;
  }

  // TODO: make this recursive?
  packagepopulate.prepare("SELECT * "
            "FROM pkgdep, pkghead "
            "WHERE ((pkgdep_parent_pkghead_id=pkghead_id)"
            "  AND  (pkgdep_pkghead_id=:pkghead_id));");
  packagepopulate.bindValue(":pkghead_id", _pkgheadid);
  packagepopulate.exec();
  if (DEBUG)    qDebug("package::populate() select pkgdep exec'ed");
  _req->populate(packagepopulate);
  if (DEBUG)    qDebug("package::populate() populate pkgdep done");
  if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting Package Info"),
                           packagepopulate, __FILE__, __LINE__))
  {
    return;
  }

}
コード例 #6
0
void maintainItemCosts::sFillList()
{
  if (_item->isValid())
  {
    double standardCost = 0.0;
    double actualCostBase = 0.0;
    double actualCostLocal = 0.0;

    q.prepare( "SELECT itemcost_id,"
               "       CASE WHEN (costelem_sys) THEN 1"
               "            ELSE 0"
               "       END,"
               "       CASE WHEN itemcost_costelem_id = -1 THEN :error "
	       "	    ELSE costelem_type "
	       "	END AS costelem_type, itemcost_lowlevel,"
               "       itemcost_stdcost, currConcat(baseCurrID()) AS baseCurr, "
	       "       itemcost_posted,"
               "       itemcost_actcost, currConcat(itemcost_curr_id) AS costCurr, "
	       "       itemcost_updated,"
	       "       currToBase(itemcost_curr_id, itemcost_actcost, CURRENT_DATE) AS actcostBase, "
	       "       itemcost_curr_id, "
               "       'cost' AS itemcost_stdcost_xtnumericrole, "
               "       'cost' AS itemcost_actcost_xtnumericrole "
               "FROM itemcost LEFT OUTER JOIN costelem ON "
               "	(itemcost_costelem_id=costelem_id)"
               "WHERE (itemcost_item_id=:item_id) "
               "ORDER BY itemcost_lowlevel, costelem_type;" );
    q.bindValue(":item_id", _item->id());
    q.bindValue(":error", tr("!ERROR!"));
    q.exec();
    _itemcost->populate(q, TRUE);

    bool multipleCurrencies = false;
    int firstCurrency = 0;
    bool baseKnown = true;
    if (q.first())
    {
      firstCurrency = q.value("itemcost_curr_id").toInt();
      do
      {
        standardCost += q.value("itemcost_stdcost").toDouble();
	if (q.value("itemcost_actcost").isNull())
	    baseKnown = false;
	else
	    actualCostBase += q.value("actcostBase").toDouble();
        actualCostLocal += q.value("itemcost_actcost").toDouble();
	if (! multipleCurrencies &&
	    q.value("itemcost_curr_id").toInt() != firstCurrency)
	    multipleCurrencies = true;
      }
      while (q.next());
    }

    XSqlQuery convert;
    double actualCost = 0;
    if (multipleCurrencies)
    {
	actualCost = actualCostBase;
	convert.prepare("SELECT currConcat(baseCurrId()) AS baseConcat, "
			"       currConcat(baseCurrId()) AS currConcat;");
    }
    else
    {
	actualCost = actualCostLocal;
	baseKnown = true; // not necessarily but we can trust actualCost
	convert.prepare("SELECT currConcat(baseCurrId()) AS baseConcat, "
			"	currConcat(:firstCurrency) AS currConcat;" );
	convert.bindValue(":firstCurrency", firstCurrency);
    }
    convert.exec();
    if (convert.first())
	new XTreeWidgetItem(_itemcost,
			    _itemcost->topLevelItem(_itemcost->topLevelItemCount() - 1), -1,
			    QVariant(tr("Totals")),
			    "",
			    formatCost(standardCost),
			    convert.value("baseConcat"),
			    "",
			    baseKnown ? formatCost(actualCost) : tr("?????"),
			    convert.value("currConcat"));
    else if (convert.lastError().type() != QSqlError::NoError)
	systemError(this, convert.lastError().databaseText(), __FILE__, __LINE__);

  }
  else
    _itemcost->clear();
}
コード例 #7
0
enum SetResponse itemCost::set(const ParameterList &pParams)
{
  XSqlQuery itemet;
  XDialog::set(pParams);
  _captive = true;

  QVariant param;
  bool     valid;

  param = pParams.value("bomitem_id", &valid);
  if (valid)
  {
    _type = cBOMItemCost;
    _bomitemid = param.toInt();
    itemet.prepare( "SELECT bomitem_item_id "
               "FROM bomitem "
               "WHERE (bomitem_id=:bomitem_id);" );
    itemet.bindValue(":bomitem_id", _bomitemid);
    itemet.exec();
    if (itemet.first())
    {
      _item->setId(itemet.value("bomitem_item_id").toInt());
      _item->setReadOnly(TRUE);
    }
  }

  param = pParams.value("bomitem_item_id", &valid);
  if (valid)
  {
    _type = cBOMItemCost;
    _item->setId(param.toInt());
    _item->setReadOnly(TRUE);
  }

  param = pParams.value("bomitemcost_id", &valid);
  if (valid)
  {
    _type = cBOMItemCost;
    _itemcostid = param.toInt();
    _item->setReadOnly(TRUE);

    itemet.prepare( "SELECT bomitem_item_id, formatBoolYN(bomitemcost_lowlevel) AS lowlevel,"
               "       bomitemcost_actcost, bomitemcost_curr_id, bomitemcost_updated "
               "FROM bomitem, bomitemcost "
               "WHERE ( (bomitemcost_bomitem_id=bomitem_id)"
               " AND    (bomitemcost_id=:bomitemcost_id) );" );
    itemet.bindValue(":bomitemcost_id", _itemcostid);
    itemet.exec();
    if (itemet.first())
    {
      _item->setId(itemet.value("bomitem_item_id").toInt());
      _lowerLevel->setText(itemet.value("lowlevel").toString());
      _actualCost->set(itemet.value("bomitemcost_actcost").toDouble(),
                       itemet.value("bomitemcost_curr_id").toInt(),
                       QDate::currentDate(),
                       false);
    }
    else if (itemet.lastError().type() != QSqlError::NoError)
    {
      systemError(this, itemet.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
  }

  param = pParams.value("item_id", &valid);
  if (valid)
  {
    _type = cItemCost;
    _item->setId(param.toInt());
    _item->setReadOnly(TRUE);
  }

  param = pParams.value("itemcost_id", &valid);
  if (valid)
  {
    _type = cItemCost;
    _itemcostid = param.toInt();
    _item->setReadOnly(TRUE);

    itemet.prepare( "SELECT item_id, formatBoolYN(itemcost_lowlevel) AS lowlevel,"
               "       itemcost_actcost, itemcost_curr_id, itemcost_updated "
               "FROM item, itemcost "
               "WHERE ( (itemcost_item_id=item_id)"
               " AND    (itemcost_id=:itemcost_id) );" );
    itemet.bindValue(":itemcost_id", _itemcostid);
    itemet.exec();
    if (itemet.first())
    {
      _item->setId(itemet.value("item_id").toInt());
      _lowerLevel->setText(itemet.value("lowlevel").toString());
      _actualCost->set(itemet.value("itemcost_actcost").toDouble(),
		       itemet.value("itemcost_curr_id").toInt(),
		       QDate::currentDate(),
		       false);
    }
    else if (itemet.lastError().type() != QSqlError::NoError)
    {
      systemError(this, itemet.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
  }

  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "new")
    {
      _mode = cNew;
      _lowerLevel->hide();
      _lowerLevelLit->hide();
      if (_type == cItemCost)
        setWindowTitle("Create Item Cost");
      else
        setWindowTitle("Create BOM Item Cost");
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;
      _costelem->setEnabled(false);
      if (_type == cItemCost)
        setWindowTitle("Enter Actual Cost");
      else
        setWindowTitle("Enter BOM Item Actual Cost");
    }
    else if (param.toString() == "view")
    {
      _actualCost->setEnabled(false);
      _costelem->setEnabled(false);
      if (_type == cItemCost)
        setWindowTitle("View Actual Cost");
      else
        setWindowTitle("View BOM Item Actual Cost");
    }
  }

  sPopulateCostelem();

  return _foundCostElems ? NoError : UndefinedError;
}
コード例 #8
0
ファイル: terms.cpp プロジェクト: shackbarth/qt-client
void terms::sSave()
{
    XSqlQuery termsSave;
    if(_code->text().trimmed().isEmpty())
    {
        QMessageBox::warning(this, tr("Cannot Save Terms"),
                             tr("You must specify a code for the Terms."));
        _code->setFocus();
        return;
    }

    if (_mode == cNew)
    {
        if (sCheck())
        {
            QMessageBox::warning( this, tr("Cannot Save Terms Code"),
                                  tr("This Terms code already exists.  You have been placed in edit mode.") );
            return;
        }

        termsSave.exec("SELECT NEXTVAL('terms_terms_id_seq') AS _terms_id");
        if (termsSave.first())
            _termsid = termsSave.value("_terms_id").toInt();
        else
        {
            systemError(this, tr("A System Error occurred at %1::%2.")
                        .arg(__FILE__)
                        .arg(__LINE__) );
            return;
        }

        termsSave.prepare( "INSERT INTO terms "
                           "( terms_id, terms_code, terms_descrip, terms_type,"
                           "  terms_ap, terms_ar,"
                           "  terms_duedays, terms_discdays, terms_discprcnt, terms_cutoffday ) "
                           "VALUES "
                           "( :terms_id, :terms_code, :terms_descrip, :terms_type,"
                           "  :terms_ap, :terms_ar,"
                           "  :terms_duedays, :terms_discdays, :terms_discprcnt, :terms_cutoffday );" );
    }
    else if (_mode == cEdit)
    {
        termsSave.prepare( "SELECT terms_id "
                           "FROM terms "
                           "WHERE ( (UPPER(terms_code)=UPPER(:terms_code))"
                           " AND (terms_id<>:terms_id) );" );
        termsSave.bindValue(":terms_id", _termsid);
        termsSave.bindValue(":terms_code", _code->text().trimmed());
        termsSave.exec();
        if (termsSave.first())
        {
            QMessageBox::warning( this, tr("Cannot Save Terms"),
                                  tr("You may not rename this Terms code with the entered name as it is in use by another Terms code.") );
            return;
        }

        termsSave.prepare( "UPDATE terms "
                           "SET terms_code=:terms_code, terms_descrip=:terms_descrip, terms_type=:terms_type,"
                           "    terms_ap=:terms_ap, terms_ar=:terms_ar,"
                           "    terms_duedays=:terms_duedays, terms_discdays=:terms_discdays,"
                           "    terms_discprcnt=:terms_discprcnt, terms_cutoffday=:terms_cutoffday "
                           "WHERE (terms_id=:terms_id);" );
    }

    if (_days->isChecked())
        termsSave.bindValue(":terms_type", "D");
    else
        termsSave.bindValue(":terms_type", "P");

    termsSave.bindValue(":terms_id", _termsid);
    termsSave.bindValue(":terms_code", _code->text().trimmed());
    termsSave.bindValue(":terms_descrip", _description->text().trimmed());
    termsSave.bindValue(":terms_ap", QVariant(_ap->isChecked()));
    termsSave.bindValue(":terms_ar", QVariant(_ar->isChecked()));
    termsSave.bindValue(":terms_duedays", _dueDays->value());
    termsSave.bindValue(":terms_discdays", _discountDays->value());
    termsSave.bindValue(":terms_discprcnt", (_discountPercent->toDouble() / 100.0));
    termsSave.bindValue(":terms_cutoffday", _cutOffDay->value());
    termsSave.exec();

    done(_termsid);
}
コード例 #9
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);
}
コード例 #10
0
void createItemSitesByClassCode::sSave()
{
  if (_warehouse->id() == -1)
  {
    QMessageBox::critical( this, tr("Select a Site"),
                           tr( "You must select a Site for this Item Site before creating it.\n" ) );
    _warehouse->setFocus();
    return;
  }

  if ( (_metrics->boolean("InterfaceToGL")) && (_costcat->id() == -1) )
  {
    QMessageBox::critical( this, tr("Cannot Create Item Sites"),
                           tr("You must select a Cost Category for these Item Sites before you may create them.") );
    _costcat->setFocus();
    return;
  } 

  if (_plannerCode->id() == -1)
  {
    QMessageBox::critical( this, tr("Cannot Create Item Sites"),
                           tr("You must select a Planner Code for these Item Sites before you may create them.") );
    _plannerCode->setFocus();
    return;
  } 

  if (_controlMethod->currentItem() == -1)
  {
    QMessageBox::critical( this, tr("Cannot Create Item Sites"),
                           tr("You must select a Control Method for these Item Sites before you may create them.") );
    _controlMethod->setFocus();
    return;
  }

  if(!_costNone->isChecked() && !_costAvg->isChecked()
   && !_costStd->isChecked() && !_costJob->isChecked())
  {
    QMessageBox::critical(this, tr("Cannot Save Item Site"),
                          tr("<p>You must select a Cost Method for this "
                             "Item Site before you may save it.") );
    return;
  }

  if (_stocked->isChecked() && _reorderLevel->toDouble() == 0)
  {
    QMessageBox::critical( this, tr("Cannot Save Item Site"),
                           tr("<p>You must set a reorder level "
			      "for a stocked item before you may save it.") );
    _reorderLevel->setFocus();
    return;
  }
  
  if ( _locationControl->isChecked() )
  {
    XSqlQuery locationid;
    locationid.prepare( "SELECT location_id "
                        "FROM location "
                        "WHERE (location_warehous_id=:warehous_id)"
                        "LIMIT 1;" );
    locationid.bindValue(":warehous_id", _warehouse->id());
    locationid.exec();
    if (!locationid.first())
    {
      QMessageBox::critical( this, tr("Cannot Save Item Site"),
                             tr( "You must first create at least one valid "
				 "Location for this Site before items may be "
				 "multiply located." ) );
      return;
    }
  }

  QString sql( "INSERT INTO itemsite "
               "( itemsite_item_id,"
               "  itemsite_warehous_id, itemsite_qtyonhand, itemsite_value,"
               "  itemsite_useparams, itemsite_useparamsmanual,"
               "  itemsite_reorderlevel, itemsite_ordertoqty,"
               "  itemsite_minordqty, itemsite_maxordqty, itemsite_multordqty,"
               "  itemsite_safetystock, itemsite_cyclecountfreq,"
               "  itemsite_leadtime, itemsite_eventfence, itemsite_plancode_id, itemsite_costcat_id,"
               "  itemsite_supply, itemsite_createpr, itemsite_createwo,"
               "  itemsite_sold, itemsite_soldranking,"
               "  itemsite_stocked,"
               "  itemsite_controlmethod, itemsite_perishable, itemsite_active,"
               "  itemsite_loccntrl, itemsite_location_id, itemsite_location,"
               "  itemsite_location_comments, itemsite_notes,"
               "  itemsite_abcclass, itemsite_freeze, itemsite_datelastused,"
               "  itemsite_ordergroup, itemsite_mps_timefence, "
               "  itemsite_autoabcclass, itemsite_costmethod ) "
               "SELECT item_id,"
               "       :warehous_id, 0.0, 0.0,"
               "       :itemsite_useparams, :itemsite_useparamsmanual,"
               "       :itemsite_reorderlevel, :itemsite_ordertoqty,"
               "       :itemsite_minordqty, :itemsite_maxordqty, :itemsite_multordqty,"
               "       :itemsite_safetystock, :itemsite_cyclecountfreq,"
               "       :itemsite_leadtime, :itemsite_eventfence, :itemsite_plancode_id, :itemsite_costcat_id,"
               "       :itemsite_supply, :itemsite_createpr, :itemsite_createwo,"
               "       :itemsite_sold, :itemsite_soldranking,"
               "       :itemsite_stocked,"
               "       :itemsite_controlmethod, :itemsite_perishable, TRUE,"
               "       :itemsite_loccntrl, :itemsite_location_id, :itemsite_location,"
               "       :itemsite_location_comments, '',"
               "       :itemsite_abcclass, FALSE, startOfTime(),"
               "       :itemsite_ordergroup, :itemsite_mps_timefence, "
               "       FALSE, CASE WHEN(item_type='R') THEN 'N' WHEN(item_type='J') THEN 'J' ELSE :itemsite_costmethod END "
               "FROM item "
               "WHERE ( (item_id NOT IN ( SELECT itemsite_item_id"
               "                          FROM itemsite"
               "                          WHERE (itemsite_warehous_id=:warehous_id) ) )" );

  if (_classCode->isSelected())
    sql += " AND (item_classcode_id=:classcode_id)";
  else if (_classCode->isPattern())
    sql += " AND (item_classcode_id IN (SELECT classcode_id FROM classcode WHERE (classcode_code ~ :classcode_pattern)))";

  sql += ");";

  q.prepare(sql);
  q.bindValue(":itemsite_reorderlevel", _reorderLevel->toDouble());
  q.bindValue(":itemsite_ordertoqty", _orderUpToQty->toDouble());
  q.bindValue(":itemsite_minordqty", _minimumOrder->toDouble());
  q.bindValue(":itemsite_maxordqty", _maximumOrder->toDouble());
  q.bindValue(":itemsite_multordqty", _orderMultiple->toDouble());
  q.bindValue(":itemsite_safetystock", _safetyStock->toDouble());
  q.bindValue(":itemsite_cyclecountfreq", _cycleCountFreq->value());
  q.bindValue(":itemsite_leadtime", _leadTime->value());
  q.bindValue(":itemsite_eventfence", _eventFence->value());
  q.bindValue(":itemsite_plancode_id", _plannerCode->id());
  q.bindValue(":itemsite_costcat_id", _costcat->id());
  q.bindValue(":itemsite_useparams", QVariant(_useParameters->isChecked(), 0));
  q.bindValue(":itemsite_useparamsmanual", QVariant(_useParametersOnManual->isChecked(), 0));
  q.bindValue(":itemsite_supply", QVariant(_supply->isChecked(), 0));
  q.bindValue(":itemsite_createpr", QVariant(_createPr->isChecked(), 0));
  q.bindValue(":itemsite_createwo", QVariant(_createWo->isChecked(), 0));
  q.bindValue(":itemsite_sold", QVariant(_sold->isChecked(), 0));
  q.bindValue(":itemsite_stocked", QVariant(_stocked->isChecked(), 0));
  q.bindValue(":itemsite_loccntrl", QVariant(_locationControl->isChecked(), 0));
  q.bindValue(":itemsite_perishable", QVariant(_perishable->isChecked(), 0));
  q.bindValue(":itemsite_soldranking", _soldRanking->value());
  q.bindValue(":itemsite_location_comments", _locationComments->text().stripWhiteSpace());
  q.bindValue(":itemsite_abcclass", _abcClass->currentText());

  q.bindValue(":itemsite_ordergroup", _orderGroup->value());
  q.bindValue(":itemsite_mps_timefence", _mpsTimeFence->value());

  if (_useDefaultLocation->isChecked())
  {
    if (_location->isChecked())
    {
      q.bindValue(":itemsite_location", "");
      q.bindValue(":itemsite_location_id", _locations->id());
    }
    else if (_miscLocation->isChecked())
    {
      q.bindValue(":itemsite_location", _miscLocationName->text().stripWhiteSpace());
      q.bindValue(":itemsite_location_id", -1);
    }
  }
  else
  {
    q.bindValue(":itemsite_location", "");
    q.bindValue(":itemsite_location_id", -1);
  }

  if (_controlMethod->currentItem() == 0)
    q.bindValue(":itemsite_controlmethod", "N");
  else if (_controlMethod->currentItem() == 1)
    q.bindValue(":itemsite_controlmethod", "R");
  else if (_controlMethod->currentItem() == 2)
    q.bindValue(":itemsite_controlmethod", "L");
  else if (_controlMethod->currentItem() == 3)
    q.bindValue(":itemsite_controlmethod", "S");

  if(_costNone->isChecked())
    q.bindValue(":itemsite_costmethod", "N");
  else if(_costAvg->isChecked())
    q.bindValue(":itemsite_costmethod", "A");
  else if(_costStd->isChecked())
    q.bindValue(":itemsite_costmethod", "S");
  else if(_costJob->isChecked())
    q.bindValue(":itemsite_costmethod", "J");

  q.bindValue(":warehous_id", _warehouse->id());
  _classCode->bindValue(q);
  q.exec();

  omfgThis->sItemsitesUpdated();

  accept();
}
コード例 #11
0
ファイル: state.cpp プロジェクト: AlFoX/qt-client
void state::sSave()
{
  XSqlQuery stateSave;
  _abbr->setText(_abbr->text().trimmed());
  _name->setText(_name->text().trimmed());

  struct {
    bool	condition;
    QString	msg;
    QWidget*	widget;
  } error[] = {
    { (! _country->isValid()), tr("<p>You must select a country."), _country },
    { _name->text().isEmpty(),
            tr("<p>You must enter a name for the state/province."), _name    },
    { true, "", NULL }
  }; // error[]

  int errIndex;
  for (errIndex = 0; ! error[errIndex].condition; errIndex++)
    ;
  if (! error[errIndex].msg.isEmpty())
  {
    QMessageBox::warning(this, tr("Cannot Save State/Province"),
                         error[errIndex].msg);
    error[errIndex].widget->setFocus();
    return;
  }

  XSqlQuery stateq;
  stateq.prepare("SELECT state_id "
                 "FROM state "
                 "WHERE ((state_country_id=:country_id)"
                 "   AND ((UPPER(state_abbr)=UPPER(:state_abbr) AND :state_abbr != '')"
                 "        OR (UPPER(state_name)=UPPER(:state_name) AND :state_name != ''))"
                 "   AND (state_id!=:state_id));");
  stateq.bindValue(":country_id", _country->id());
  stateq.bindValue(":state_abbr", _abbr->text());
  stateq.bindValue(":state_name", _name->text());
  stateq.bindValue(":state_id",   _stateid);
  stateq.exec();
  if (stateq.first())
  {
    QMessageBox::warning(this, tr("Cannot Save State/Province"),
                         tr("There is already another state/province for %1 "
                            "with the same name or abbreviation.")
                           .arg(_country->currentText()));
    _abbr->setFocus();
    return;

  }
  else if (stateq.lastError().type() != QSqlError::NoError)
  {
    systemError(this, stateq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  if (_mode == cNew)
    stateSave.prepare("INSERT INTO state ("
              "  state_id, state_abbr, state_name, state_country_id"
              ") VALUES ("
              "  DEFAULT, :state_abbr, :state_name, :country_id"
              ") RETURNING state_id;");
  else if (_mode == cEdit)
  {
    stateSave.prepare("UPDATE state "
              "SET state_abbr=:state_abbr, state_name=:state_name,"
              "    state_country_id=:country_id "
              "WHERE (state_id=:state_id) RETURNING state_id;" );
    stateSave.bindValue(":state_id", _stateid);
  }

  stateSave.bindValue(":state_abbr", _abbr->text().trimmed());
  stateSave.bindValue(":state_name", _name->text().trimmed());
  stateSave.bindValue(":country_id", _country->id());
  stateSave.exec();
  if (stateSave.first())
    _stateid = stateSave.value("state_id").toInt();
  else if (stateSave.lastError().type() != QSqlError::NoError)
  {
    systemError(this, stateSave.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  done(_stateid);
}
コード例 #12
0
checkForUpdates::checkForUpdates(QWidget* parent, Qt::WFlags fl)
    : XWidget(parent, fl)
{
  setupUi(this);

  QUrl updatequrl("http://updates.xtuple.com/checkForUpdates.php");
  updatequrl.addQueryItem("xtuple", _Version);

  XSqlQuery versions;
  versions.exec("SELECT version() AS pgver,"
                "       fetchMetricText('ServerVersion') AS dbver,"
                "       fetchMetricText('Application') AS dbprod;");
  if(versions.first())
  {
    updatequrl.addQueryItem("postgres", versions.value("pgver").toString());
    updatequrl.addQueryItem(versions.value("dbprod").toString(),
                            versions.value("dbver").toString());
  }
  else if (versions.lastError().type() != QSqlError::NoError)
    systemError(this, versions.lastError().text(), __FILE__, __LINE__);
  // no return - let's learn as much as we can

#ifdef Q_WS_MACX
  QString helpdir = QApplication::applicationDirPath() +
                    "/../Resources/helpXTupleGUIClient";
#else
  QString helpdir = QApplication::applicationDirPath() + "helpXTupleGUIClient";
#endif
  QFile helpfile(helpdir + "/index.html");
  QString helpver;
  if (helpfile.exists())
  {
    if (helpfile.open(QIODevice::ReadOnly))
    {
      QXmlQuery helpverq;
      if (helpverq.setFocus(&helpfile))
      {
        helpverq.setQuery("/descendant::p[attribute::class='releaseinfo']/text()/string()");
        if (helpverq.isValid())
        {
          QStringList helpverlist;
          if (helpverq.evaluateTo(&helpverlist) && ! helpverlist.isEmpty())
            helpver = helpverlist.at(0);
          else if (DEBUG)
            qDebug("Could not find the releaseinfo in %s",
                     qPrintable(helpfile.fileName()));
        }
        else if (DEBUG)
          qDebug("The helpver query is not valid for some reason");
      }
      else if (DEBUG)
        qDebug("Could not set focus on the help file %s",
                 qPrintable(helpfile.fileName()));
    }
    else if (DEBUG)
      qDebug("Found the help file %s but could not open it: %s",
               qPrintable(helpfile.fileName()),
               qPrintable(helpfile.errorString()));
  }
  else if (DEBUG)
    qDebug("The help file %s does not exist", qPrintable(helpfile.fileName()));
  updatequrl.addQueryItem("xTupleHelp", helpver);

  QStringList context;
  context << "xTuple" << "openrpt" << "reports"; // duplicated from main.cpp!

  versions.exec("SELECT pkghead_name, pkghead_version"
                "  FROM pkghead"
                " WHERE packageisenabled(pkghead_id);");
  while(versions.next())
  {
    updatequrl.addQueryItem(versions.value("pkghead_name").toString(),
                            versions.value("pkghead_version").toString());
    context << versions.value("pkghead_name").toString();
  }
  if (versions.lastError().type() != QSqlError::NoError)
    systemError(this, versions.lastError().text(), __FILE__, __LINE__);
  // no return - let's learn as much as we can

  // get all of the locales on the system
  versions.exec("SELECT DISTINCT lang_abbr2, country_abbr"
                "  FROM locale"
                "  JOIN lang ON (locale_lang_id=lang_id)"
                "  LEFT OUTER JOIN country ON (locale_country_id=country_id)"
                " ORDER BY lang_abbr2, country_abbr;");
  QStringList locale;
  while(versions.next())
  {
    QString tmp = versions.value("lang_abbr2").toString();
    if (! versions.value("country_abbr").isNull())
      tmp += "_" + versions.value("country_abbr").toString();
    locale.append(tmp);
  }
  if (! locale.isEmpty())
    updatequrl.addQueryItem("locales", locale.join(","));
  else if(versions.lastError().type() != QSqlError::NoError)
    systemError(this, versions.lastError().text(), __FILE__, __LINE__);

  // maybe i want to update just _my_ translation file
  versions.exec("SELECT lang_abbr2, country_abbr"
                "  FROM locale"
                "  JOIN usr ON (locale_id=usr_locale_id)"
                "  JOIN lang ON (locale_lang_id=lang_id)"
                "  LEFT OUTER JOIN country ON (locale_country_id=country_id)"
                " WHERE (usr_username=CURRENT_USER);");
  if (versions.first())
  {
    QString tmp = versions.value("lang_abbr2").toString();
    if (! versions.value("country_abbr").isNull())
      tmp += "_" + versions.value("country_abbr").toString();
    updatequrl.addQueryItem("mylocale", tmp);
  }
  else if(versions.lastError().type() != QSqlError::NoError)
    systemError(this, versions.lastError().text(), __FILE__, __LINE__);

  QString qmparam = "qm.%1.%2";
  for (int l = 0; l < locale.length(); l++)
  {
    for (int c = 0; c < context.length(); c++)
    {
      QString version("");
      QString tf = translationFile(locale.at(l), context.at(c), version);
      updatequrl.addQueryItem(qmparam.arg(context.at(c), locale.at(l)), version);
    }
  }

  if (DEBUG)
    qDebug("checkForUpdates::checkForUpdates() sending %s",
           updatequrl.toEncoded().data());

  _view->load(updatequrl);
}
コード例 #13
0
ファイル: shipOrder.cpp プロジェクト: josemdv/qt-client
void shipOrder::sFillList()
{
  if (_shipment->isValid())
  {
    calcFreight();

    QString ordertype;
    XSqlQuery shipq;
    shipq.prepare("SELECT shiphead_order_id, shiphead_shipvia, shiphead_order_type,"
                  "       shiphead_tracknum, shiphead_freight, shiphead_freight_curr_id,"
		  "       COALESCE(shipchrg_custfreight, TRUE) AS custfreight,"
		  "       COALESCE(shiphead_shipdate,CURRENT_DATE) AS effective "
		  "FROM shiphead LEFT OUTER JOIN "
		  "     shipchrg ON (shiphead_shipchrg_id=shipchrg_id) "
		  "WHERE ( (NOT shiphead_shipped)"
		  " AND (shiphead_id=:shiphead_id));" );
    shipq.bindValue(":shiphead_id", _shipment->id());
    shipq.exec();
    if (shipq.first())
    {
      _order->setId(shipq.value("shiphead_order_id").toInt(),shipq.value("shiphead_order_type").toString());
      _shipVia->setText(shipq.value("shiphead_shipvia").toString());
      ordertype = shipq.value("shiphead_order_type").toString();
      _tracknum->addItem(shipq.value("shiphead_tracknum").toString(), shipq.value("shiphead_tracknum").toString());

      if (shipq.value("custfreight").toBool())
      {
	_freight->setEnabled(TRUE);
	_freight->set(shipq.value("shiphead_freight").toDouble(),
		      shipq.value("shiphead_freight_curr_id").toInt(),
		      shipq.value("effective").toDate(), false);
      }
      else
      {
	_freight->setEnabled(FALSE);
	_freight->set(0,
		      shipq.value("shiphead_freight_curr_id").toInt(),
		      shipq.value("effective").toDate());
      }
    }
    else if (shipq.lastError().type() != QSqlError::NoError)
    {
      systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
    else
    {
      QMessageBox::warning(this, tr("Shipment/Order mismatch"),
			   tr("<p>Shipment #%1 either is not part of "
			      "Order #%2 or has already shipped. Please change "
			      "either the Order # or Shipment #.")
			     .arg(_shipment->number())
			     .arg(_order->number()));
      _shipment->clear();
      _shipment->setEnabled(false);
      return;
    }

    ParameterList itemp;
    itemp.append("shiphead_id", _shipment->id());
    itemp.append("ordertype", ordertype);
    if (ordertype == "SO")
      itemp.append("sohead_id", _order->id());
    else if (ordertype == "TO")
      itemp.append("tohead_id", _order->id());

    QString items = "<? if exists(\"sohead_id\") ?>"
		 "SELECT coitem_id,"
		 "       formatSOlinenumber(coitem_id) AS linenumber, item_number,"
		 "       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,"
		 "       uom_name,"
		 "       SUM(shipitem_qty) AS shipitem_qty, "
                 "       'qty' AS shipitem_qty_xtnumericrole "
                 "FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id) "
                 "              JOIN coitem ON (coitem_id=shipitem_orderitem_id) "
                 "              JOIN itemsite ON (itemsite_id=coitem_itemsite_id) "
                 "              JOIN item ON (item_id=itemsite_item_id) "
                 "              JOIN uom ON (uom_id=coitem_qty_uom_id) "
                 "WHERE ( (shiphead_id=<? value(\"shiphead_id\") ?>)"
                 "  AND   (NOT shiphead_shipped) ) "
		 "GROUP BY coitem_id, coitem_linenumber, item_number,"
		 "         uom_name, itemdescrip, coitem_subnumber "
                 "ORDER BY coitem_linenumber, coitem_subnumber;"
		 "<? elseif exists(\"tohead_id\") ?>"
		 "SELECT toitem_id,"
		 "       toitem_linenumber AS linenumber, item_number,"
		 "       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,"
		 "       uom_name,"
		 "       SUM(shipitem_qty) AS shipitem_qty, "
                 "       'qty' AS shipitem_qty_xtnumericrole "
                 "FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id) "
                 "              JOIN toitem ON (toitem_id=shipitem_orderitem_id) "
                 "              JOIN item ON (item_id=toitem_item_id) "
                 "              JOIN uom ON (uom_id=item_inv_uom_id) "
                 "WHERE ( (shiphead_id=<? value(\"shiphead_id\") ?>)"
                 "  AND   (NOT shiphead_shipped) ) "
		 "GROUP BY toitem_id, toitem_linenumber, item_number,"
		 "         uom_name, itemdescrip "
                 "ORDER BY toitem_linenumber;"
		 "<? endif ?>" ;
    MetaSQLQuery itemm(items);
    shipq = itemm.toQuery(itemp);
    _coitem->populate(shipq);
    if (shipq.lastError().type() != QSqlError::NoError)
    {
      systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }

    QString vals = "<? if exists(\"sohead_id\") ?>"
	    "SELECT SUM(round((shipitem_qty * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio),2)) AS value "
            "FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id) "
            "              JOIN coitem ON (coitem_id=shipitem_orderitem_id) "
            "WHERE ( (shiphead_id=<? value(\"shiphead_id\") ?>)"
            "  AND   (NOT shiphead_shipped) );"
	    "<? elseif exists(\"tohead_id\") ?>"
	    "SELECT SUM(toitem_stdcost * shipitem_qty) AS value "
            "FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id) "
            "              JOIN toitem ON (toitem_id=shipitem_orderitem_id) "
            "WHERE ( (shiphead_id=<? value(\"shiphead_id\") ?>)"
            "  AND   (NOT shiphead_shipped) );"
	    "<? endif ?>" ;
    MetaSQLQuery valm(vals);
    shipq = valm.toQuery(itemp);	// shared parameters
    if(shipq.first())
      _shipValue->setDouble(shipq.value("value").toDouble());
    else if (shipq.lastError().type() != QSqlError::NoError)
    {
      systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else
  {
    _billToName->clear();
    _shipToName->clear();
    _shipToAddr1->clear();
    _freight->setEnabled(TRUE);
    _freight->reset();
    _shipVia->clear();
    _tracknum->clear();
    _shipment->clear();
    _shipment->setEnabled(false);
  }
}
コード例 #14
0
ファイル: shipOrder.cpp プロジェクト: josemdv/qt-client
void shipOrder::sHandleTo()
{
  XSqlQuery shipHandleTo;
  _coitem->clear();
  _shipment->setEnabled(false);
  _shipment->removeOrderLimit();

  sHandleButtons();

  shipHandleTo.prepare("SELECT tohead_freight_curr_id, tohead_destname,"
            "       tohead_destaddress1,"
            "       SUM(toitem_freight) + tohead_freight AS freight "
            "FROM tohead, toitem "
            "WHERE ((toitem_tohead_id=tohead_id)"
            "  AND  (toitem_status<>'X')"
            "  AND  (tohead_id=:tohead_id)) "
            "GROUP BY tohead_freight_curr_id, tohead_destname,"
            "         tohead_destaddress1, tohead_freight;");
  shipHandleTo.bindValue(":tohead_id", _order->id());
  shipHandleTo.exec();
  if (shipHandleTo.first())
  {
    _freight->setId(shipHandleTo.value("tohead_freight_curr_id").toInt());
    _freight->setLocalValue(shipHandleTo.value("freight").toDouble());
    _billToName->setText(tr("Transfer Order"));
    _shipToName->setText(shipHandleTo.value("tohead_destname").toString());
    _shipToAddr1->setText(shipHandleTo.value("tohead_destaddress1").toString());
  }
  else if (shipHandleTo.lastError().type() != QSqlError::NoError)
  {
    systemError(this, shipHandleTo.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  QString sql( "SELECT shiphead_id "
               "FROM shiphead "
               "WHERE ( (NOT shiphead_shipped)"
               "<? if exists(\"shiphead_id\") ?>"
               " AND (shiphead_id=<? value(\"shiphead_id\") ?>)"
               "<? endif ?>"
               " AND (shiphead_order_id=<? value(\"tohead_id\") ?>)"
               " AND (shiphead_order_type='TO'));" );
  ParameterList params;
  params.append("tohead_id", _order->id());
  if (_shipment->isValid())
    params.append("shiphead_id", _shipment->id());
  MetaSQLQuery mql(sql);
  shipHandleTo = mql.toQuery(params);
  if (shipHandleTo.first())
  {
    if (_shipment->id() != shipHandleTo.value("shiphead_id").toInt())
      _shipment->setId(shipHandleTo.value("shiphead_id").toInt());

    if (shipHandleTo.next())
    {
      _shipment->setType("TO");
      _shipment->limitToOrder(_order->id());
      _shipment->setEnabled(true);
    }
  }
  else if (shipHandleTo.lastError().type() != QSqlError::NoError)
  {
    systemError(this, shipHandleTo.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  else if (_shipment->isValid())
  {
    params.clear();
    params.append("tohead_id", _order->id());
    MetaSQLQuery mql(sql);
    shipHandleTo = mql.toQuery(params);
    if (shipHandleTo.first())
    {
      _shipment->setId(shipHandleTo.value("shiphead_id").toInt());
      if (shipHandleTo.next())
      {
        _shipment->setType("TO");
        _shipment->limitToOrder(_order->id());
        _shipment->setEnabled(true);
      }
    }
    else if (shipHandleTo.lastError().type() != QSqlError::NoError)
    {
      systemError(this, shipHandleTo.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
    else
      _shipment->clear();
  }
  else
  {
    QMessageBox::warning(this, tr("Nothing to ship"),
                      tr("<p>You may not ship this Transfer Order because "
                         "no stock has been issued to shipping for it."));
    _order->setFocus();
    return;
  }
}
コード例 #15
0
void unpostedPoReceipts::sPost()
{
  bool changeDate = false;
  QDate newDate = QDate::currentDate();

  if (_privleges->check("ChangePORecvPostDate"))
  {
    getGLDistDate newdlg(this, "", TRUE);
    newdlg.sSetDefaultLit(tr("Receipt Date"));
    if (newdlg.exec() == QDialog::Accepted)
    {
      newDate = newdlg.date();
      changeDate = (newDate.isValid());
    }
    else
      return;
  }

  XSqlQuery setDate;
  setDate.prepare("UPDATE recv SET recv_gldistdate=:distdate "
		  "WHERE recv_id=:recv_id;");

  QList<QTreeWidgetItem*>selected = _recv->selectedItems();
  QList<QTreeWidgetItem*>triedToClosed;

  for (int i = 0; i < selected.size(); i++)
  {
    int id = ((XTreeWidgetItem*)(selected[i]))->id();

    if (changeDate)
    {
      setDate.bindValue(":distdate",  newDate);
      setDate.bindValue(":recv_id", id);
      setDate.exec();
      if (setDate.lastError().type() != QSqlError::None)
      {
	systemError(this, setDate.lastError().databaseText(), __FILE__, __LINE__);
      }
    }
  }
  
  XSqlQuery postLine;
  postLine.prepare("SELECT postReceipt(:id, NULL) AS result;");
  XSqlQuery rollback;
  rollback.prepare("ROLLBACK;");

  bool tryagain = false;
  do {
    for (int i = 0; i < selected.size(); i++)
    {
      int id = ((XTreeWidgetItem*)(selected[i]))->id();

      q.exec("BEGIN;");
      postLine.bindValue(":id", id);
      postLine.exec();
      if (postLine.first())
      {
	int result = postLine.value("result").toInt();
	if (result < 0)
	{
	  rollback.exec();
	  systemError(this, storedProcErrorLookup("postReceipt", result),
		      __FILE__, __LINE__);
	  continue;
	}
	q.exec("COMMIT;");

	distributeInventory::SeriesAdjust(result, this);
      }
      // contains() string is hard-coded in stored procedure
      else if (postLine.lastError().databaseText().contains("posted to closed period"))
      {
	if (changeDate)
	{
	  triedToClosed = selected;
	  break;
	}
	else
	  triedToClosed.append(selected[i]);
      }
      else if (postLine.lastError().type() != QSqlError::None)
      {
	rollback.exec();
	systemError(this, postLine.lastError().databaseText(), __FILE__, __LINE__);
      }
    } // for each selected line

    if (triedToClosed.size() > 0)
    {
      failedPostList newdlg(this, "", true);
      newdlg.sSetList(triedToClosed, _recv->headerItem(), _recv->header());
      tryagain = (newdlg.exec() == QDialog::Accepted);
      selected = triedToClosed;
      triedToClosed.clear();
    }
  } while (tryagain);

  omfgThis->sPurchaseOrderReceiptsUpdated();
}
コード例 #16
0
ファイル: copyItem.cpp プロジェクト: jmstandring/qt-client
void copyItem::sAddBomitem()
{
    if (_availablebomitems->id() == -1)
    {
        QMessageBox::critical(this, tr("Error"), tr("Please select an Available BOM Item."));
        return;
    }

    XSqlQuery bomitemq;
    int uomid;
    QString uomname;
    double qtyper;
    bool ok;

    bomitemq.prepare("SELECT item_inv_uom_id, uom_name "
                     "FROM item JOIN uom ON (uom_id=item_inv_uom_id) "
                     "WHERE (item_id=:item_id);");
    bomitemq.bindValue(":item_id", _availablebomitems->id());
    bomitemq.exec();
    if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting UOM"),
                             bomitemq, __FILE__, __LINE__))
        return;

    if (bomitemq.first())
    {
        uomid = bomitemq.value("item_inv_uom_id").toInt();
        uomname = bomitemq.value("uom_name").toString();
    }
    qtyper = QInputDialog::getDouble(this, tr("Quantity Per"),
                                     uomname,
                                     qtyper, 1, 10000, 5, &ok);
    if ( !ok )
        return;

    bomitemq.prepare( "INSERT INTO bomitem"
                      " ( bomitem_parent_item_id, bomitem_seqnumber,"
                      "   bomitem_item_id, bomitem_qtyper, bomitem_scrap,"
                      "   bomitem_status, bomitem_effective, bomitem_expires,"
                      "   bomitem_createwo, bomitem_issuemethod, bomitem_schedatwooper,"
                      "   bomitem_ecn, bomitem_moddate, bomitem_subtype,"
                      "   bomitem_uom_id, bomitem_rev_id, bomitem_booitem_seq_id,"
                      "   bomitem_char_id, bomitem_value, bomitem_notes,"
                      "   bomitem_ref, bomitem_qtyfxd, bomitem_issuewo )"
                      " SELECT"
                      "   :targetitemid, (MAX(bomitem_seqnumber) + 10),"
                      "   :bomitemid, :qtyper, 0.0,"
                      "   NULL, startOfTime(), endOfTime(),"
                      "   FALSE, 'M', TRUE,"
                      "   NULL, CURRENT_DATE, 'I',"
                      "   :uomid, -1, -1,"
                      "   NULL, NULL, NULL,"
                      "   NULL, 0.0, FALSE "
                      " FROM bomitem "
                      " WHERE (bomitem_parent_item_id=:targetitemid);" );
    bomitemq.bindValue(":targetitemid", _newitemid);
    bomitemq.bindValue(":bomitemid", _availablebomitems->id());
    bomitemq.bindValue(":qtyper", qtyper);
    bomitemq.bindValue(":uomid", uomid);
    bomitemq.exec();
    if (ErrorReporter::error(QtCriticalMsg, this, tr("Adding Bomitem"),
                             bomitemq, __FILE__, __LINE__))
        return;

    sFillBomitem();
}
コード例 #17
0
void displayPrivate::print(bool showPreview)
{
  int numCopies = 1;

  ParameterList params;
  if(!_parent->setParams(params))
    return;

  XSqlQuery report;
  report.prepare("SELECT report_grade, report_source "
                 "  FROM report "
                 " WHERE (report_name=:report_name)"
                 " ORDER BY report_grade DESC LIMIT 1");
  report.bindValue(":report_name", reportName);
  report.exec();
  QDomDocument _doc;
  if (report.first())
  {
    QString errorMessage;
    int     errorLine;

    if (!_doc.setContent(report.value("report_source").toString(), &errorMessage, &errorLine))
    {
      QMessageBox::critical(_parent, ::display::tr("Error Parsing Report"),
        ::display::tr("There was an error Parsing the report definition. %1 %2").arg(errorMessage).arg(errorLine));
      return;
    }
  }
  else
  {
    QMessageBox::critical(_parent, ::display::tr("Report Not Found"),
      ::display::tr("The report %1 does not exist.").arg(reportName));
    return;
  }

  ORPreRender pre;
  pre.setDom(_doc);
  pre.setParamList(params);
  ORODocument * doc = pre.generate();

  if(doc)
  {
    QPrinter printer(QPrinter::HighResolution);
    printer.setNumCopies( numCopies );

    ORPrintRender render;
    render.setupPrinter(doc, &printer);

    if(showPreview)
    {
      PreviewDialog preview (doc, &printer, _parent);
      if (preview.exec() == QDialog::Rejected)
        return;
    }

    QPrintDialog pd(&printer);
    pd.setMinMax(1, doc->pages());
    if(pd.exec() == QDialog::Accepted)
    {
      render.setPrinter(&printer);
      render.render(doc);
    }
    delete doc;
  }
}
コード例 #18
0
ファイル: prerequisite.cpp プロジェクト: gpazo/xtuple-svn
bool Prerequisite::met(QString &errMsg)
{
  if (DEBUG)
    qDebug("Prerequisite::met() name %s, type %d (%s), message %s, "
           "dependency %p (%s %s %s), query %s",
           qPrintable(_name), _type, qPrintable(typeToName(_type)),
           qPrintable(_message), _dependency,
           qPrintable(/*_dependency ? _dependency->name()     :*/ QString()),
           qPrintable(/*_dependency ? _dependency->version()  :*/ QString()),
           qPrintable(/*_dependency ? _dependency->developer():*/ QString()),
           qPrintable(_query));

  bool returnVal = false;

  switch (_type)
  {
    case Query:
      {
      XSqlQuery query;
      query.exec(_query);
      if (query.first())
      {
        returnVal = query.value(0).toBool();
        errMsg    = _message;
      }
      else if (query.lastError().type() != QSqlError::NoError)
        errMsg = _sqlerrtxt.arg(_name).arg(query.lastError().databaseText())
                           .arg(query.lastError().driverText());
      else
      {
        returnVal = false;
        errMsg    = _message;
      }
      break;
      }

    case License:
      {
      LicenseWindow newdlg(_message);
      returnVal = (newdlg.exec() == QDialog::Accepted);
      if (! returnVal)
        errMsg = TR("The user declined to accept the usage license.");
      break;
      }

    case Dependency:
      {
      QString sql = "SELECT * FROM pkghead WHERE ((pkghead_name=:name) ";
      if (! _dependency->version().isEmpty())
        sql += "AND (pkghead_version=:version) ";
      if (! _dependency->developer().isEmpty())
        sql += "AND (pkghead_developer=:developer) ";
      sql += ");";

      XSqlQuery query;
      query.prepare(sql);
      query.bindValue(":name",      _dependency->name());
      query.bindValue(":version",   _dependency->version());
      query.bindValue(":developer", _dependency->developer());
      query.exec();
      if (query.first())
        returnVal = true;
      else if (query.lastError().type() != QSqlError::NoError)
        errMsg = _sqlerrtxt.arg(_name).arg(query.lastError().databaseText())
                           .arg(query.lastError().driverText());
      else
        errMsg = TR("%1<br>The prerequisite %2 has not been met. It "
                             "requires that the package %3 (version %4, "
                             "developer %5) be installed first.")
                    .arg(_message).arg(_name).arg(_dependency->name())
                    .arg(_dependency->version().isEmpty() ?
                         TR("Unspecified") : _dependency->version())
                    .arg(_dependency->developer().isEmpty() ?
                         TR("Unspecified") : _dependency->developer());
      break;
      }

    default:
      errMsg = TR("Encountered an unknown Prerequisite type. "
                           "Prerequisite '%1' has not been validated.")
                        .arg(_name);
      break;
  }

  return returnVal;
}
コード例 #19
0
void itemCost::sSave()
{
  XSqlQuery itemSave;
  if (_mode != cNew && _mode != cEdit)
    done(_itemcostid);

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_costelem->id() < 0, _costelem,
                          tr("You must select a Costing Element to save this Item Cost."))
     ;
  if (GuiErrorCheck::reportErrors(this, tr("Cannot Save Item Cost"), errors))
    return;

  if (_type == cItemCost)
  {
    if (_mode == cNew)
    {
      itemSave.exec("SELECT NEXTVAL('itemcost_itemcost_id_seq') AS itemcost_id;");
      if (itemSave.first())
      {
        _itemcostid = itemSave.value("itemcost_id").toInt();

        itemSave.prepare( "INSERT INTO itemcost "
                   "( itemcost_id, itemcost_item_id,"
                   "  itemcost_costelem_id, itemcost_lowlevel,"
                   "  itemcost_stdcost, itemcost_posted,"
                   "  itemcost_actcost, itemcost_updated, "
                   "  itemcost_curr_id ) "
                   "VALUES "
                   "( :itemcost_id, :itemcost_item_id,"
                   "  :itemcost_costelem_id, FALSE,"
                   "  0, startOfTime(),"
                   "  :itemcost_actcost, CURRENT_DATE, "
                   "  :itemcost_curr_id );" );
        itemSave.bindValue(":itemcost_item_id", _item->id());
        itemSave.bindValue(":itemcost_costelem_id", _costelem->id());
      }
    }
    else if (_mode == cEdit)
    {
        itemSave.prepare( "UPDATE itemcost SET"
                   " itemcost_actcost=:itemcost_actcost,"
                   " itemcost_curr_id=:itemcost_curr_id, "
                   " itemcost_updated=CURRENT_DATE "
                   "WHERE (itemcost_id=:itemcost_id);");
    }
    itemSave.bindValue(":itemcost_id", _itemcostid);
    itemSave.bindValue(":itemcost_actcost", _actualCost->localValue());
    itemSave.bindValue(":itemcost_curr_id", _actualCost->id());

    if (itemSave.exec() && _postCost->isChecked())
    {
      itemSave.prepare("SELECT postCost(:itemcost_id) AS result;");
      itemSave.bindValue(":itemcost_id", _itemcostid);
      itemSave.exec();
      if (itemSave.first())
      {
        int result = itemSave.value("result").toInt();
        if (result < 0)
        {
          systemError(this, storedProcErrorLookup("postCost", result),
                      __FILE__, __LINE__);
          return;
        }
      }
    }

    if (itemSave.lastError().type() != QSqlError::NoError)  // if EITHER itemSave.exec() failed
    {
      systemError(this, itemSave.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else if (_type == cBOMItemCost)
  {
    if (_mode == cNew)
    {
      itemSave.exec("SELECT NEXTVAL('bomitemcost_bomitemcost_id_seq') AS itemcost_id;");
      if (itemSave.first())
      {
        _itemcostid = itemSave.value("itemcost_id").toInt();

        itemSave.prepare( "INSERT INTO bomitemcost "
                   "( bomitemcost_id, bomitemcost_bomitem_id,"
                   "  bomitemcost_costelem_id, bomitemcost_lowlevel,"
                   "  bomitemcost_stdcost, bomitemcost_posted,"
                   "  bomitemcost_actcost, bomitemcost_updated, "
                   "  bomitemcost_curr_id ) "
                   "VALUES "
                   "( :bomitemcost_id, :bomitemcost_bomitem_id,"
                   "  :bomitemcost_costelem_id, FALSE,"
                   "  0, startOfTime(),"
                   "  :bomitemcost_actcost, CURRENT_DATE, "
                   "  :bomitemcost_curr_id );" );
        itemSave.bindValue(":bomitemcost_bomitem_id", _bomitemid);
        itemSave.bindValue(":bomitemcost_costelem_id", _costelem->id());
      }
    }
    else if (_mode == cEdit)
    {
      itemSave.prepare( "UPDATE bomitemcost SET"
                 " bomitemcost_actcost=:bomitemcost_actcost,"
                 " bomitemcost_curr_id=:bomitemcost_curr_id, "
                 " bomitemcost_updated=CURRENT_DATE "
                 "WHERE (bomitemcost_id=:bomitemcost_id);");
    }
    itemSave.bindValue(":bomitemcost_id", _itemcostid);
    itemSave.bindValue(":bomitemcost_actcost", _actualCost->localValue());
    itemSave.bindValue(":bomitemcost_curr_id", _actualCost->id());

    if (itemSave.exec() && _postCost->isChecked())
    {
      itemSave.prepare("UPDATE bomitemcost"
                       "   SET bomitemcost_stdcost=currToBase(bomitemcost_curr_id,"
                       "                                      bomitemcost_actcost, CURRENT_DATE), "
                       "       bomitemcost_posted=CURRENT_DATE "
                       "WHERE bomitemcost_id=:bomitemcost_id;");
      itemSave.bindValue(":bomitemcost_id", _itemcostid);
      itemSave.exec();
    }

    if (itemSave.lastError().type() != QSqlError::NoError)  // if EITHER itemSave.exec() failed
    {
      systemError(this, itemSave.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }

  done(_itemcostid);
}
コード例 #20
0
ファイル: prerequisite.cpp プロジェクト: gpazo/xtuple-svn
int Prerequisite::writeToDB(const QString pkgname, QString &errMsg)
{
  if (DEBUG)
    qDebug("Prerequisite::writeToDB(%s, &errMsg)", qPrintable(pkgname));

  if (! pkgname.isEmpty() && _dependency)
  {
    XSqlQuery select;
    int pkgheadid = -1;
    select.prepare("SELECT pkghead_id FROM pkghead WHERE (pkghead_name=:name);");
    select.bindValue(":name", pkgname);
    select.exec();
    if (select.first())
      pkgheadid = select.value(0).toInt();
    else if (select.lastError().type() != QSqlError::NoError)
    {
      errMsg = _sqlerrtxt.arg(_name)
                         .arg(select.lastError().databaseText())
                         .arg(select.lastError().driverText());
      return -1;
    }

    int parentid = -1;
    QString sql = "SELECT * FROM pkghead WHERE ((pkghead_name=:name) ";
    if (! _dependency->version().isEmpty())
      sql += "AND (pkghead_version=:version) ";
    if (! _dependency->developer().isEmpty())
      sql += "AND (pkghead_developer=:developer) ";
    sql += ") ORDER BY pkghead_version DESC LIMIT 1;";

    select.prepare(sql);
    select.bindValue(":name",      _dependency->name());
    select.bindValue(":version",   _dependency->version());
    select.bindValue(":developer", _dependency->developer());
    select.exec();
    if (select.first())
      parentid = select.value(0).toInt();
    else if (select.lastError().type() != QSqlError::NoError)
    {
      errMsg = _sqlerrtxt.arg(_name)
                         .arg(select.lastError().databaseText())
                         .arg(select.lastError().driverText());
      return -2;
    }
    else
    {
      errMsg = TR("Could not record the dependency %1 of package %2 "
                           "on package %3 (version %4, developer %5) because "
                           "the record for %6 was not found.")
                    .arg(_name).arg(pkgname).arg(_dependency->name())
                    .arg(_dependency->version().isEmpty() ?
                         TR("Unspecified") : _dependency->version())
                    .arg(_dependency->developer().isEmpty() ?
                         TR("Unspecified") : _dependency->developer())
                    .arg(_dependency->name());
      return -3;
    }

    int pkgdepid = -1;
    select.prepare("SELECT * FROM pkgdep "
                   "WHERE ((pkgdep_pkghead_id=:pkgheadid)"
                   "  AND  (pkgdep_parent_pkghead_id=:parentid));");
    select.bindValue(":pkgheadid", pkgheadid);
    select.bindValue(":parentid",  parentid);
    select.exec();
    if (select.first())
      pkgdepid=select.value(0).toInt();
    else if (select.lastError().type() != QSqlError::NoError)
    {
      errMsg = _sqlerrtxt.arg(_name)
                         .arg(select.lastError().databaseText())
                         .arg(select.lastError().driverText());
      return -4;
    }

    XSqlQuery upsert;
    if (pkgdepid > 0)
      upsert.prepare("UPDATE pkgdep "
                     "SET pkgdep_pkghead_id=:pkgheadid,"
                     "    pkgdep_parent_pkghead_id=:parentid "
                     "WHERE (pkgdep_id=:pkgdepid);");
    else
    {
      upsert.exec("SELECT NEXTVAL('pkgdep_pkgdep_id_seq');");
      if (upsert.first())
        pkgdepid = upsert.value(0).toInt();
      else if (upsert.lastError().type() != QSqlError::NoError)
      {
        QSqlError err = upsert.lastError();
        errMsg = _sqlerrtxt.arg(_name).arg(err.driverText()).arg(err.databaseText());
        return -5;
      }
      upsert.prepare("INSERT INTO pkgdep ("
                     "   pkgdep_id, pkgdep_pkghead_id, pkgdep_parent_pkghead_id"
                     ") VALUES ("
                     "    :pkgdepid, :pkgheadid, :parentid);");
    }

    upsert.bindValue(":pkgdepid",   pkgdepid);
    upsert.bindValue(":pkgheadid",  pkgheadid);
    upsert.bindValue(":parentid",   parentid);

    if (! upsert.exec())
    {
      QSqlError err = upsert.lastError();
      errMsg = _sqlerrtxt.arg(_name).arg(err.driverText()).arg(err.databaseText());
      return -6;
    }

    return pkgdepid;
  }

  return 0;
}
コード例 #21
0
void plannedOrder::sCreate()
{
  XSqlQuery plannedCreate;
  if (!(_item->isValid()))
  {
    QMessageBox::information( this, tr("No Item Number Selected"),
                              tr("You must enter or select a valid Item number before creating this Planned Order")  );
    return;
  }

  if (!_qty->text().length())
  {
    QMessageBox::information( this, tr("Invalid Quantity Ordered"),
                              tr( "You have entered an invalid Qty. Ordered.\n"
                                  "Please correct before creating this Planned Order"  ) );
    _qty->setFocus();
    return;
  }

  if (!_dueDate->isValid())
  {
    QMessageBox::information( this, tr("Invalid Due Date Entered"),
                              tr( "You have entered an invalid Due Date.\n"
                                  "Please correct before creating this Planned Order"  ) );
    _dueDate->setFocus();
    return;
  }

  plannedCreate.prepare( "SELECT itemsite_id "
             "FROM itemsite "
             "WHERE ( (itemsite_item_id=:item_id)"
             " AND (itemsite_warehous_id=:warehous_id) );" );
  plannedCreate.bindValue(":item_id", _item->id());
  plannedCreate.bindValue(":warehous_id", _warehouse->id());
  plannedCreate.exec();
  if (!plannedCreate.first())
  {
    QMessageBox::information( this, tr("Invalid Item Site"),
                              tr("The Item and Site entered is and invalid Item Site combination.")  );
    return;
  }

  int itemsiteid = plannedCreate.value("itemsite_id").toInt();
  int _supplyItemsiteId = -1;
  if (_toButton->isChecked())
  {
    plannedCreate.prepare("SELECT itemsite_id "
              "FROM itemsite "
              "WHERE ( (itemsite_item_id=:item_id)"
              "  AND   (itemsite_warehous_id=:warehous_id) ); ");
    plannedCreate.bindValue(":item_id", _item->id());
    plannedCreate.bindValue(":warehous_id", _fromWarehouse->id());
    plannedCreate.exec();
    if (plannedCreate.first())
    {
      if (plannedCreate.value("itemsite_id").toInt() == itemsiteid)
      { 
        QMessageBox::warning( this, tr("Cannot Save Planned Order"),
          tr("The Supplied From Site must be different from the Transfer To Site.") );
        return;
      }
      else
        _supplyItemsiteId = plannedCreate.value("itemsite_id").toInt();
    }
    else
    { 
      QMessageBox::warning( this, tr("Cannot Save Planned"),
        tr("Cannot find Supplied From Item Site.") );
      return;
    }
  }

  int foid = 0;

  if(cEdit == _mode)
  {
    plannedCreate.prepare( "UPDATE planord "
               "SET planord_number=:planord_number, "
               "    planord_type=:planord_type, "
               "    planord_itemsite_id=:planord_itemsite_id, "
               "    planord_supply_itemsite_id=:planord_supply_itemsite_id, "
               "    planord_comments=:planord_comments, "
               "    planord_qty=:planord_qty, "
               "    planord_duedate=:planord_dueDate, "
               "    planord_startdate=(DATE(:planord_dueDate) - :planord_leadTime) "
               "WHERE (planord_id=:planord_id);" );
    plannedCreate.bindValue(":planord_number", _number->text().toInt());
    plannedCreate.bindValue(":planord_itemsite_id", itemsiteid);
    if (_poButton->isChecked())
      plannedCreate.bindValue(":planord_type", "P");
    else if (_woButton->isChecked())
      plannedCreate.bindValue(":planord_type", "W");
    else if (_toButton->isChecked())
    {
      plannedCreate.bindValue(":planord_type", "T");
      plannedCreate.bindValue(":planord_supply_itemsite_id", _supplyItemsiteId);
    }
    plannedCreate.bindValue(":planord_qty", _qty->toDouble());
    plannedCreate.bindValue(":planord_dueDate", _dueDate->date());
    plannedCreate.bindValue(":planord_leadTime", _leadTime->value());
    plannedCreate.bindValue(":planord_comments", _notes->toPlainText());
    plannedCreate.bindValue(":planord_id", _planordid);
    plannedCreate.exec();
    if (plannedCreate.lastError().type() != QSqlError::NoError)
    {
      systemError(this, plannedCreate.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }

    plannedCreate.prepare( "SELECT explodePlannedOrder( :planord_id, true) AS result;" );
    plannedCreate.bindValue(":planord_id", _planordid);
    plannedCreate.exec();
    if (plannedCreate.first())
    {
      double result = plannedCreate.value("result").toDouble();
      if (result < 0.0)
      {
        systemError(this, tr("ExplodePlannedOrder returned %, indicating an "
                             "error occurred.").arg(result),
                    __FILE__, __LINE__);
        return;
      }
    }
    else if (plannedCreate.lastError().type() != QSqlError::NoError)
    {
      systemError(this, plannedCreate.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else
  {
    plannedCreate.prepare( "SELECT createPlannedOrder( :orderNumber, :itemsite_id, :qty, "
               "                           (DATE(:dueDate) - :leadTime), :dueDate, "
               "                           :type, :supply_itemsite_id, :notes) AS result;" );
    plannedCreate.bindValue(":orderNumber", _number->text().toInt());
    plannedCreate.bindValue(":itemsite_id", itemsiteid);
    plannedCreate.bindValue(":qty", _qty->toDouble());
    plannedCreate.bindValue(":dueDate", _dueDate->date());
    plannedCreate.bindValue(":leadTime", _leadTime->value());
    plannedCreate.bindValue(":notes",    _notes->toPlainText());
    if (_poButton->isChecked())
      plannedCreate.bindValue(":type", "P");
    else if (_woButton->isChecked())
      plannedCreate.bindValue(":type", "W");
    else if (_toButton->isChecked())
    {
      plannedCreate.bindValue(":type", "T");
      plannedCreate.bindValue(":supply_itemsite_id", _supplyItemsiteId);
    }
  
    plannedCreate.exec();
    if (!plannedCreate.first())
    {
      systemError( this, tr("A System Error occurred at %1::%2.")
                         .arg(__FILE__)
                         .arg(__LINE__) );
      return;
    }

    foid = XDialog::Rejected;
    switch (plannedCreate.value("result").toInt())
    {
      case -1:
        QMessageBox::critical( this, tr("Planned Order not Exploded"),
                               tr( "The Planned Order was created but not Exploded as there is no valid Bill of Materials for the selected Item.\n"
                                   "You must create a valid Bill of Materials before you may explode this Planned Order." ));
        break;
  
      case -2:
        QMessageBox::critical( this, tr("Planned Order not Exploded"),
                               tr( "The Planned Order was created but not Exploded as Component Items defined in the Bill of Materials\n"
                                   "for the selected Planned Order Item do not exist in the selected Planned Order Site.\n"
                                   "You must create Item Sites for these Component Items before you may explode this Planned Order." ));
        break;

      default:
        foid = plannedCreate.value("result").toInt();
        break;
    }
  }

  if (_captive)
    done(foid);
  else
  {
    populateFoNumber();
    _item->setId(-1);
    _typeGroup->setEnabled(FALSE);
    _qty->clear();
    _dueDate->setNull();
    _leadTime->setValue(0);
    _startDate->setNull();
    _notes->clear();
    _close->setText(tr("&Close"));

    _item->setFocus();
  }
}
コード例 #22
0
int characteristicAssignment::set(const ParameterList &pParams)
{
  QVariant param;
  bool     valid;

  /* derive the targetType from the source table and pParams,
     skipping params we know don't describe targets.
   */
  QStringList passedIn;
  foreach (Parameter p, pParams)
  {
    if (p.name() != "charass_id" && p.name() != "char_id" &&
        p.name() != "mode"       && p.name() != "showPrices")
    {
      passedIn << p.name();
    }
  }
  if (! passedIn.isEmpty())
  {
    ParameterList srcp;
    srcp.append("paramName", passedIn);

    MetaSQLQuery srcm("SELECT source.* FROM source WHERE source_key_param IN ("
                      "<? foreach('paramName') ?>"
                      "  <? if not isfirst('paramName') ?>, <? endif ?>"
                      "  <? value('paramName') ?>"
                      "<? endforeach ?>);");
    XSqlQuery srcq = srcm.toQuery(srcp);
    if (srcq.first())
    {
      QString paramName = srcq.value("source_key_param").toString();
      param = pParams.value(paramName, &valid);
      if (valid)
      {
        _targetId = param.toInt();
        _d->targetType = srcq.value("source_charass").toString();
        _d->handleTargetType();
      }
    }
    else if (ErrorReporter::error(QtCriticalMsg, this,
                                  tr("Error Finding Characteristic Information"),
                                  srcq, __FILE__, __LINE__))
    {
      return Error_NoSetup;
    }
  }

  param = pParams.value("charass_id", &valid);
  if (valid)
  {
    _charassid = param.toInt();
    populate();
  }

  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "new")
    {
      _mode = cNew;
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _char->setEnabled(false);
      _value->setEnabled(false);
      _buttonBox->setStandardButtons(QDialogButtonBox::Close);
    }
  }

  param = pParams.value("showPrices", &valid);
  if (valid)
  {
    _listpriceLit->show();
    _listprice->show();
  }

  param = pParams.value("char_id", &valid);
  if (valid)
  {
    for (int i = 0; i < _char->model()->rowCount(); i++)
    {
      QModelIndex idx = _char->model()->index(i, _d->idCol);
      if (_char->model()->data(idx) == param)
        _char->setCurrentIndex(i);
    }
  }

  return NoError;
}
コード例 #23
0
ファイル: package.cpp プロジェクト: dwatson78/qt-client
void package::sSave()
{
  XSqlQuery packageSave;
  if (_mode == cNew)
  {
    packageSave.exec("SELECT NEXTVAL('pkghead_pkghead_id_seq') AS _pkghead_id");
    if (packageSave.first())
      _pkgheadid = packageSave.value("_pkghead_id").toInt();
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Package Information"),
                                  packageSave, __FILE__, __LINE__))
    {
      return;
    }

    packageSave.prepare( "INSERT INTO pkghead ("
               "  pkghead_id, pkghead_name, pkghead_descrip,"
               "  pkghead_version, pkghead_developer, pkghead_notes,"
               "  pkghead_indev"
               ") VALUES ("
               "  :pkghead_id, :pkghead_name, :pkghead_descrip, "
               "  :pkghead_version, :pkghead_developer, :pkghead_notes,"
               "  :pkghead_indev);");
  }
  else if (_mode == cEdit)
  {
    packageSave.prepare( "SELECT pkghead_id "
               "FROM pkghead "
               "WHERE ( (UPPER(pkghead_name)=UPPER(:pkghead_name))"
               " AND (pkghead_id<>:pkghead_id) );" );
    packageSave.bindValue(":pkghead_id",   _pkgheadid);
    packageSave.bindValue(":pkghead_name", _name->text());
    packageSave.exec();
    if (packageSave.first())
    {
      QMessageBox::warning( this, tr("Cannot Save Package"),
                            tr("<p>You may not rename this Package to %1 as "
                               "this value is used by a different Package.") );
      return;
    }

    packageSave.prepare( "UPDATE pkghead "
               "SET pkghead_name=:pkghead_name,"
               "    pkghead_descrip=:pkghead_descrip,"
               "    pkghead_version=:pkghead_version,"
               "    pkghead_developer=:pkghead_developer,"
               "    pkghead_notes=:pkghead_notes,"
               "    pkghead_indev=:pkghead_indev "
               "WHERE (pkghead_id=:pkghead_id);" );
  }

  packageSave.bindValue(":pkghead_id",       _pkgheadid);
  packageSave.bindValue(":pkghead_name",     _name->text());
  packageSave.bindValue(":pkghead_descrip",  _description->text());
  packageSave.bindValue(":pkghead_version",  _version->text());
  packageSave.bindValue(":pkghead_developer",_developer->text());
  packageSave.bindValue(":pkghead_notes",    _notes->toPlainText());
  packageSave.bindValue(":pkghead_indev",    _indev->isChecked());
  packageSave.exec();
  if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Package Information"),
                                packageSave, __FILE__, __LINE__))
  {
    return;
  }

  if (DEBUG) qDebug("_enabled->isChecked: %d\tprior state: %d",
                    _enabled->isChecked(), _priorEnabledState);
  if (_enabled->isChecked() != _priorEnabledState)
  {
    XSqlQuery eq;
    QString funcname;
    if (_enabled->isChecked())
    {
      eq.prepare("SELECT enablePackage(:id) AS result;");
      funcname = "enablePackage";
    }
    else
    {
      eq.prepare("SELECT disablePackage(:id) AS result;");
      funcname = "disablePackage";
    }
    eq.bindValue(":id", _pkgheadid);
    eq.exec();
    if (eq.first())
    {
      int result = eq.value("result").toInt();
      if (result < 0)
      {
        ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Package Information"),
                               storedProcErrorLookup("funcname", result),
                               __FILE__, __LINE__);
        return;
      }
    }
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Package Information"),
                                  eq, __FILE__, __LINE__))
    {
      return;
    }
  }

  done(_pkgheadid);
}
コード例 #24
0
void characteristicAssignment::sSave()
{
  if(_d->targetType == "I" || _d->targetType == "ITEMGRP")
  {
    if ( ((_stackedWidget->currentIndex() == CHARTEXT) && (_value->text().trimmed() == "")) ||
         ((_stackedWidget->currentIndex() == CHARLIST) && (_listValue->currentText() == "")) ||
         ((_stackedWidget->currentIndex() == CHARDATE) && (_dateValue->date().toString() == "")) )
      {
          QMessageBox::information( this, tr("No Value Entered"),
                                    tr("You must enter a value before saving this Characteristic.") );
          return;
      }
  }

  XSqlQuery characteristicSave;
  if (_char->model()->data(_char->model()->index(_char->currentIndex(), _d->idCol)) == -1)
  {
    QMessageBox::information( this, tr("No Characteristic Selected"),
                              tr("You must select a Characteristic before saving this Characteristic Assignment.") );
    _char->setFocus();
    return;
  }
  if (_mode == cNew &&
      _d->_template &&
      _stackedWidget->currentIndex() == CHARDATE)
  {
    characteristicSave.prepare("SELECT charass_id "
              "FROM charass "
              "WHERE ((charass_char_id=:charass_char_id) "
              "  AND (charass_target_id=:charass_target_id) "
              "  AND (charass_target_type=:charass_target_type));");
    characteristicSave.bindValue(":charass_target_id", _targetId);
    characteristicSave.bindValue(":charass_target_type", _d->targetType);
    characteristicSave.bindValue(":charass_char_id", _char->model()->data(_char->model()->index(_char->currentIndex(), _d->idCol)));
    characteristicSave.exec();
    if (characteristicSave.first())
    {
      QMessageBox::critical(this, tr("Error"), tr("You can not use the same characteristic "
                                                  "for date type characteristics more than "
                                                  "once in this context."));
      return;
    }
  }

  if (_mode == cNew)
  {
    characteristicSave.exec("SELECT NEXTVAL('charass_charass_id_seq') AS charass_id;");
    if (characteristicSave.first())
    {
      _charassid = characteristicSave.value("charass_id").toInt();

      characteristicSave.prepare( "INSERT INTO charass "
                 "( charass_id, charass_target_id, charass_target_type, charass_char_id, charass_value, charass_price, charass_default ) "
                 "VALUES "
                 "( :charass_id, :charass_target_id, :charass_target_type, :charass_char_id, :charass_value, :charass_price, :charass_default );" );
    }
  }
  else if (_mode == cEdit)
    characteristicSave.prepare( "UPDATE charass "
               "SET charass_char_id=:charass_char_id, charass_value=:charass_value, "
               "charass_price=:charass_price, charass_default=:charass_default "
               "WHERE (charass_id=:charass_id);" );

  characteristicSave.bindValue(":charass_id", _charassid);
  characteristicSave.bindValue(":charass_target_id", _targetId);
  characteristicSave.bindValue(":charass_target_type", _d->targetType);
  characteristicSave.bindValue(":charass_char_id", _char->model()->data(_char->model()->index(_char->currentIndex(), _d->idCol)));
  if (_stackedWidget->currentIndex() == CHARTEXT)
    characteristicSave.bindValue(":charass_value", _value->text());
  else if (_stackedWidget->currentIndex() == CHARLIST)
    characteristicSave.bindValue(":charass_value", _listValue->currentText());
  else if (_stackedWidget->currentIndex() == CHARDATE)
    characteristicSave.bindValue(":charass_value", _dateValue->date());
  characteristicSave.bindValue(":charass_price", _listprice->toDouble());
  characteristicSave.bindValue(":charass_default", QVariant(_default->isChecked()));
  characteristicSave.exec();

  done(_charassid);
}
コード例 #25
0
void reassignLotSerial::sReassign()
{
  XSqlQuery reassignReassign;
  if (_expirationDate->isEnabled())
  {
    if (!_expirationDate->isValid() || _expirationDate->isNull())
    {
      QMessageBox::critical( this, tr("Enter a valid date"),
                             tr("You must enter a valid expiration date before you can continue.") );
      _expirationDate->setFocus();
      return;
    }
  }
	
  if (_source->currentItem() == 0)
  {
    QMessageBox::critical( this, tr("Select Source Location"),
                           tr("You must select a Source Location before reassigning its Lot/Serial #.") );
    _source->setFocus();
    return;
  }

  if (_qty->toDouble() == 0)
  {
    QMessageBox::critical( this, tr("Enter Quantity to Reassign"),
                           tr("You must enter a quantity to reassign.") );
    _qty->setFocus();
    return;
  }

  if (_lotNumber->text().length() == 0)
  {
    QMessageBox::critical( this, tr("Enter New Lot Number to Reassign"),
                           tr("You must enter a New Lot Number to reassign.") );
    _qty->setFocus();
    return;
  }

  QDoubleValidator* qtyVal = (QDoubleValidator*)(_qty->validator());
  reassignReassign.prepare("SELECT reassignLotSerial(:source, CAST (:qty AS NUMERIC(100,:decimals)), "
	    "                         :lotNumber, :expirationDate, :warrantyDate) AS result;");
  reassignReassign.bindValue(":source", _source->id());
  reassignReassign.bindValue(":qty", _qty->toDouble());
  reassignReassign.bindValue(":decimals", qtyVal->decimals());
  reassignReassign.bindValue(":lotNumber", _lotNumber->text());

  if (_expirationDate->isEnabled())
    reassignReassign.bindValue(":expirationDate", _expirationDate->date());
  else
    reassignReassign.bindValue(":expirationDate", omfgThis->endOfTime());

  if (_warrantyDate->isEnabled())
    reassignReassign.bindValue(":warrantyDate", _warrantyDate->date());

  reassignReassign.exec();
  if (reassignReassign.first())
  {
    int result = reassignReassign.value("result").toInt();
    if (result < 0)
    {
      systemError(this, storedProcErrorLookup("reassignLotSerial", result),
		  __FILE__, __LINE__);
      return;
    }
  }
  else if (reassignReassign.lastError().type() != QSqlError::NoError)
  {
    systemError(this, reassignReassign.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  if (_captive)
    accept();
  else
  {
    _close->setText(tr("&Close"));

    sFillList();

    if (_qty->isEnabled())
      _qty->clear();

    _qty->setFocus();
    _lotNumber->clear();
    _expirationDate->setNull();
    _warrantyDate->setNull();
  }
}
コード例 #26
0
int AuthorizeDotNetProcessor::buildCommon(const int pccardid, const int pcvv, const double pamount, const int pcurrid, QString &prequest, QString pordertype)
{
  // TODO: if check and not credit card transaction do something else
  XSqlQuery anq;
  anq.prepare(
    "SELECT ccard_active,"
    "  formatbytea(decrypt(setbytea(ccard_number),   setbytea(:key),'bf')) AS ccard_number,"
    "  formatccnumber(decrypt(setbytea(ccard_number),setbytea(:key),'bf')) AS ccard_number_x,"
    "  formatbytea(decrypt(setbytea(ccard_name),     setbytea(:key),'bf')) AS ccard_name,"
    "  formatbytea(decrypt(setbytea(ccard_address1), setbytea(:key),'bf')) AS ccard_address1,"
    "  formatbytea(decrypt(setbytea(ccard_address2), setbytea(:key),'bf')) AS ccard_address2,"
    "  formatbytea(decrypt(setbytea(ccard_city),     setbytea(:key),'bf')) AS ccard_city,"
    "  formatbytea(decrypt(setbytea(ccard_state),    setbytea(:key),'bf')) AS ccard_state,"
    "  formatbytea(decrypt(setbytea(ccard_zip),      setbytea(:key),'bf')) AS ccard_zip,"
    "  formatbytea(decrypt(setbytea(ccard_country),  setbytea(:key),'bf')) AS ccard_country,"
    "  formatbytea(decrypt(setbytea(ccard_month_expired),setbytea(:key),'bf')) AS ccard_month_expired,"
    "  formatbytea(decrypt(setbytea(ccard_year_expired),setbytea(:key), 'bf')) AS ccard_year_expired,"
    "  cust.* "
    "  FROM ccard, cust "
    "WHERE ((ccard_id=:ccardid)"
    "  AND  (ccard_cust_id=cust_id));");
  // note use of the cust view instead of the custinfo table
  anq.bindValue(":ccardid", pccardid);
  anq.bindValue(":key",     omfgThis->_key);
  anq.exec();

  if (anq.first())
  {
    if (!anq.value("ccard_active").toBool())
    {
      _errorMsg = errorMsg(-10);
      return -10;
    }
  }
  else if (anq.lastError().type() != QSqlError::NoError)
  {
    _errorMsg = anq.lastError().databaseText();
    return -1;
  }
  else
  {
    _errorMsg = errorMsg(-17).arg(pccardid);
    return -17;
  }

  if (! _metrics->value("CCANDelim").isEmpty())
    APPENDFIELD(prequest, "x_delim_char", _metrics->value("CCANDelim"));

  APPENDFIELD(prequest, "x_version",      _metrics->value("CCANVer"));
  APPENDFIELD(prequest, "x_delim_data", "TRUE");

  if (! _metrics->value("CCANEncap").isEmpty())
    APPENDFIELD(prequest, "x_encap_char", _metrics->value("CCANEncap"));

  APPENDFIELD(prequest, "x_login",    _metricsenc->value("CCLogin"));
  APPENDFIELD(prequest, "x_tran_key", _metricsenc->value("CCPassword"));
  APPENDFIELD(prequest, "x_amount",   QString::number(pamount));
  // TODO: if check and not credit card transaction do something else
  APPENDFIELD(prequest, "x_card_num", anq.value("ccard_number").toString());
  APPENDFIELD(prequest, "x_test_request", isLive() ? "FALSE" : "TRUE");

  // TODO: if check and not credit card transaction do something else
  QString work_month;
  work_month.setNum(anq.value("ccard_month_expired").toDouble());
  if (work_month.length() == 1)
    work_month = "0" + work_month;
  APPENDFIELD(prequest, "x_exp_date",
	      work_month + anq.value("ccard_year_expired").toString().right(2));

  APPENDFIELD(prequest, "x_relay_response", "FALSE");
  APPENDFIELD(prequest, "x_duplicate_window",
			_metrics->value("CCANDuplicateWindow"));

  QStringList name = anq.value("ccard_name").toString().split(QRegExp("\\s+"));
  APPENDFIELD(prequest, "x_first_name", name.at(0));
  APPENDFIELD(prequest, "x_last_name",  name.at(name.size() - 1));
  APPENDFIELD(prequest, "x_company",    anq.value("cust_name").toString());
  APPENDFIELD(prequest, "x_address",    anq.value("ccard_address1").toString());
  APPENDFIELD(prequest, "x_city",       anq.value("ccard_city").toString());
  APPENDFIELD(prequest, "x_state",      anq.value("ccard_state").toString());
  APPENDFIELD(prequest, "x_zip",        anq.value("ccard_zip").toString());
  APPENDFIELD(prequest, "x_country",    anq.value("ccard_country").toString());

  if (_metrics->boolean("CCANWellsFargoSecureSource"))
  {
    APPENDFIELD(prequest, "x_phone",    anq.value("cust_phone").toString());
    APPENDFIELD(prequest, "x_email",    anq.value("cust_email").toString());
  }

  anq.prepare("SELECT curr_abbr FROM curr_symbol WHERE (curr_id=:currid);");
  anq.bindValue(":currid", pcurrid);
  anq.exec();
  if (anq.first())
  {
    APPENDFIELD(prequest, "x_currency_code", anq.value("curr_abbr").toString());
  }
  else if (anq.lastError().type() != QSqlError::NoError)
  {
    _errorMsg = anq.lastError().databaseText();
    return -1;
  }
  else
  {
    _errorMsg = errorMsg(-17).arg(pccardid);
    return -17;
  }

  // TODO: if check and not credit card transaction do something else
  APPENDFIELD(prequest, "x_method",     "CC");
  APPENDFIELD(prequest, "x_type",       pordertype);

  if (pcvv > 0)
    APPENDFIELD(prequest, "x_card_code", pcvv);

  if (DEBUG)
    qDebug("AN:buildCommon built %s\n", prequest.toAscii().data());
  return 0;
}
コード例 #27
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." ) )
     ;

  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;
}
コード例 #28
0
int AuthorizeDotNetProcessor::handleResponse(const QString &presponse, const int pccardid, const QString &ptype, const double pamount, const int pcurrid, QString &pneworder, QString &preforder, int &pccpayid, ParameterList &pparams)
{
  if (DEBUG)
    qDebug("AN::handleResponse(%s, %d, %s, %f, %d, %s, %d, pparams)",
	   presponse.toAscii().data(), pccardid,
	   ptype.toAscii().data(), pamount, pcurrid,
	   preforder.toAscii().data(), pccpayid);

  // if we got an error msg very early on
  if (presponse.startsWith("<HTML>"))
  {
    _errorMsg = errorMsg(-207).arg(presponse);
    return -207;
  }

  QString delim = _metrics->value("CCANDelim").isEmpty() ? "," :
						  _metrics->value("CCANDelim");
  QString encap = _metrics->value("CCANEncap");

  QString r_approved;
  QString r_avs;
  QString r_code;
  QString r_cvv;
  QString r_error;
  QString r_message;
  QString r_ordernum;
  QString r_reason;     // not stored
  QString r_ref;
  QString r_shipping;
  QString r_tax;

  QString status;

  // TODO: explore using encap here and code from CSV Import to properly split

  /* add an extra field at the beginning. otherwise we'll be off by one
     because the Advanced Integration Method (AIM) Implementation Guide
     numbers fields starting at 1 but QString::split() creates a list
     starting at 0.
   */
  QStringList responseFields = presponse.split(delim);
  
  QString r_response;
  int returnValue = fieldValue(responseFields, 1, r_response);
  if (returnValue < 0)
    return returnValue;

  if (r_response.toInt() == 1)
    r_approved = "APPROVED";
  else if (r_response.toInt() == 2)
    r_approved == "DECLINED";
  else if (r_response.toInt() == 3)
    r_approved == "ERROR";
  else if (r_response.toInt() == 4)
    r_approved == "HELDFORREVIEW";

  // fieldValue(responseFields, 2);				// subcode

  returnValue = fieldValue(responseFields, 3, r_reason);	// reason code
  if (returnValue < 0)
    return returnValue;
  returnValue = fieldValue(responseFields, 4, r_message);	// reason text
  if (returnValue < 0)
    return returnValue;

  returnValue = fieldValue(responseFields, 5, r_code);	 	// approval code
  if (returnValue < 0)
    return returnValue;
  returnValue = fieldValue(responseFields, 6, r_avs);	 	// avs result
  if (returnValue < 0)
    return returnValue;
  returnValue = fieldValue(responseFields, 7, r_ordernum);	// transaction id

  if (returnValue < 0)
    return returnValue;

  // fieldValue(responseFields, 8-10);	// echo invoice_number description amount 
  // fieldValue(responseFields, 11-13);	// echo method type cust_id
  // fieldValue(responseFields, 14-24);	// echo name, company, and address info
  // fieldValue(responseFields, 25-32);	// echo ship_to fields

  returnValue = fieldValue(responseFields, 33, r_tax);		// echo x_tax
  if (returnValue < 0)
    return returnValue;

  // fieldValue(responseFields, 34);				// echo x_duty

  returnValue = fieldValue(responseFields, 35, r_shipping);	// echo x_freight
  if (returnValue < 0)
    return returnValue;

  // fieldValue(responseFields, 36);		// echo x_tax_exempt
  // fieldValue(responseFields, 37);		// echo x_po_num

  returnValue = fieldValue(responseFields, 39, r_cvv); // ccv response code
  if (returnValue < 0)
    return returnValue;

  // fieldValue(responseFields, 40);		// cavv response code
  // fieldValue(responseFields, 41-68);		// reserved for future use
  // fieldValue(responseFields, 69+);		// echo of merchant-defined fields

  /* treat heldforreview as approved because the AIM doc says response
     reason codes 252 and 253 are both approved but being reviewed.
     the intent of the other heldforreview, 193, is ambiguous.
   */
  if (r_approved == "APPROVED" || r_approved == "HELDFORREVIEW")
  {
    _errorMsg = errorMsg(0).arg(r_code);
    if (ptype == "A")
      status = "A";	// Authorized
    else if (ptype == "V")
      status = "V";	// Voided
    else
      status = "C";	// Completed/Charged
  }
  else if (r_approved == "DECLINED")
  {
    _errorMsg = errorMsg(-92).arg(r_message);
    returnValue = -92;
    status = "D";
  }
  else if (r_approved == "ERROR")
  {
    r_error = r_message;
    _errorMsg = errorMsg(-12).arg(r_error);
    returnValue = -12;
  }

  else if (r_approved.isEmpty() && ! r_message.isEmpty())
  {
    _errorMsg = errorMsg(-95).arg(r_message);
    returnValue = -95;
    status = "X";
  }

  else if (r_approved.isEmpty())
  {
    _errorMsg = errorMsg(-100).arg(r_error).arg(r_message).arg(presponse);
    returnValue = -100;
    status = "X";
  }

  // always use the AVS checking configured on the gateway
  _passedAvs = ((r_reason.toInt() != 27) &&
	        (r_reason.toInt() != 127));

  // always use the CVV checking configured on the gateway
  _passedCvv = (r_reason.toInt() != 78);

  if (DEBUG)
    qDebug("AN:%s _passedAvs %d\t%s _passedCvv %d",
	    r_avs.toAscii().data(), _passedAvs,
	    r_cvv.toAscii().data(), _passedCvv);

  pparams.append("ccard_id",    pccardid);
  pparams.append("currid",      pcurrid);
  pparams.append("auth_charge", ptype);
  pparams.append("type",        ptype);
  pparams.append("reforder",    (preforder.isEmpty()) ? pneworder : preforder);
  pparams.append("status",      status);
  pparams.append("avs",         r_avs);
  pparams.append("ordernum",    pneworder);
  pparams.append("xactionid",   r_ordernum);
  pparams.append("error",       r_error);
  pparams.append("approved",    r_approved);
  pparams.append("code",        r_code);
  pparams.append("shipping",    r_shipping);
  pparams.append("tax",         r_tax);
  pparams.append("ref",         r_ref);
  pparams.append("message",     r_message);

  if (ptype == "A")
    pparams.append("auth", QVariant(true, 0));
  else
    pparams.append("auth", QVariant(false, 1));

  if (DEBUG)
    qDebug("AN:r_error.isEmpty() = %d", r_error.isEmpty());

  if (returnValue == 0)
    pparams.append("amount",   pamount);
  else
    pparams.append("amount",   0);	// no money changed hands this attempt

  // don't bother checking MD5 if we hit a bigger problem
  if (returnValue == 0 && _metrics->boolean("CCANMD5HashSetOnGateway"))
  {
    QString expected_hash;
    QString r_hash;

    returnValue = fieldValue(responseFields, 38, r_hash);	// md5 hash
    XSqlQuery anq;
    anq.prepare("SELECT UPPER(MD5(:inputstr)) AS expected;");
    anq.bindValue(":inputstr", _metricsenc->value("CCANMD5Hash") +
			       _metricsenc->value("CCLogin") +
			       r_ordernum +
			       QString::number(pamount, 'f', 2));
    anq.exec();
    if (anq.first())
      expected_hash = anq.value("expected").toString();
    else if (q.lastError().type() != QSqlError::None)
    {
      _errorMsg = errorMsg(-1).arg(anq.lastError().databaseText());
      returnValue = -1;
    }
    if (DEBUG)
      qDebug("AN:handleResponse expected md5 %s and got %s",
	      expected_hash.toAscii().data(), r_hash.toAscii().data());

    if (_metrics->value("CCANMD5HashAction") == "F" && expected_hash != r_hash)
    {
      _errorMsg = errorMsg(-206);
      returnValue = -206;
    }
    else if (_metrics->value("CCANMD5HashAction") == "W" && expected_hash != r_hash)
    {
      _errorMsg = errorMsg(206);
      returnValue = 206;
    }
  }

  if (DEBUG)
    qDebug("AN::handleResponse returning %d %s",
           returnValue, errorMsg().toAscii().data());
  return returnValue;
}
コード例 #29
0
enum SetResponse dspInventoryAvailability::set(const ParameterList &pParams)
{
    XWidget::set(pParams);
    QVariant param;
    bool     valid;

    parameterWidget()->setSavedFilters();

    param = pParams.value("classcode_id", &valid);
    if (valid)
        parameterWidget()->setDefault(tr("Class Code"), param);

    param = pParams.value("classcode_pattern", &valid);
    if (valid)
        parameterWidget()->setDefault(tr("Class Code Pattern"), param);

    param = pParams.value("plancode_id", &valid);
    if (valid)
        parameterWidget()->setDefault(tr("Planner Code"), param);

    param = pParams.value("plancode_pattern", &valid);
    if (valid)
        parameterWidget()->setDefault(tr("Planner Code Pattern"), param);

    param = pParams.value("itemgrp_id", &valid);
    if (valid)
        parameterWidget()->setDefault(tr("Item Group"), param);

    param = pParams.value("itemgrp_pattern", &valid);
    if (valid)
        parameterWidget()->setDefault(tr("Item Group Pattern"), param);

    param = pParams.value("item_id", &valid);
    if (valid)
        parameterWidget()->setDefault(tr("Item"), param);

    param = pParams.value("itemsite_id", &valid);
    if (valid)
    {
        XSqlQuery qry;
        qry.prepare("SELECT itemsite_item_id, itemsite_warehous_id "
                    "FROM itemsite "
                    "WHERE itemsite_id=:itemsite_id;");
        qry.bindValue(":itemsite_id", param.toInt());
        qry.exec();
        if (qry.first())
        {
            parameterWidget()->setDefault(tr("Item"), qry.value("itemsite_item_id"));
            parameterWidget()->setDefault(tr("Site"), qry.value("itemsite_warehous_id"));
        }
    }

    param = pParams.value("warehous_id", &valid);
    if (valid)
        parameterWidget()->setDefault(tr("Site"), param);

    param = pParams.value("byDays", &valid);
    if (valid)
    {
        _forgetful = true;
        _asof->setCurrentIndex(LOOKAHEADDAYS);
        _days->setValue(param.toInt());
    }

    param = pParams.value("byDate", &valid);
    if (valid)
    {
        _forgetful = true;
        _asof->setCurrentIndex(CUTOFFDATE);
        _date->setDate(param.toDate());
    }

    // sources may not exist, so turn by Vendor off to avoid confusion
    _byVendor->setForgetful(true);
    _byVendor->setChecked(false);

    parameterWidget()->applyDefaultFilterSet();

    if (pParams.inList("run"))
    {
        sFillList();
        return NoError_Run;
    }

    return NoError;
}
コード例 #30
0
ファイル: shipOrder.cpp プロジェクト: josemdv/qt-client
void shipOrder::sShip()
{
  XSqlQuery shipq;
  shipq.prepare( "UPDATE shiphead "
	     "   SET shiphead_shipvia=:shiphead_shipvia,"
	     "       shiphead_freight=:shiphead_freight,"
	     "       shiphead_freight_curr_id=:shiphead_freight_curr_id,"
	     "       shiphead_tracknum=:shiphead_tracknum "
	     " WHERE (shiphead_id=:shiphead_id);");
  shipq.bindValue(":shiphead_shipvia",	_shipVia->currentText());
  shipq.bindValue(":shiphead_freight",	_freight->localValue());
  shipq.bindValue(":shiphead_freight_curr_id", _freight->id());
  shipq.bindValue(":shiphead_tracknum",	_tracknum->currentText());
  shipq.bindValue(":shiphead_id",		_shipment->id());
  shipq.exec();
  if (shipq.lastError().type() != QSqlError::NoError)
  {
    systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  XSqlQuery rollback;
  rollback.prepare("ROLLBACK;");
  // failed insertGLTransaction RETURNs -5 rather than RAISE EXCEPTION
  shipq.exec("BEGIN;");

  shipq.prepare( "SELECT shipShipment(:shiphead_id, :ts) AS result;");
  shipq.bindValue(":shiphead_id", _shipment->id());
  shipq.bindValue(":ts",          _transDate->date());
  shipq.exec();
  if (shipq.first())
  {
    int result = shipq.value("result").toInt();
    if (result == -6)
    {
      rollback.exec();
      shipq.prepare("SELECT itemsite_id, tohead_trns_warehous_id,"
	        "       tohead_dest_warehous_id "
	        "FROM shiphead, shipitem, tohead, toitem, itemsite "
	        "WHERE ((itemsite_item_id=toitem_item_id)"
	        "  AND  (itemsite_warehous_id=tohead_src_warehous_id)"
	        "  AND  (toitem_tohead_id=tohead_id)"
	        "  AND  (shipitem_orderitem_id=toitem_id)"
	        "  AND  (shiphead_id=shipitem_shiphead_id)"
	        "  AND  (shiphead_order_type='TO')"
	        "  AND  (NOT shiphead_shipped)"
	        "  AND  (shiphead_id=:shiphead_id));");
      shipq.bindValue(":shiphead_id", _shipment->id());
      shipq.exec();
      while (shipq.next())
      {
	// missing transit itemsite is fatal here but not missing dest
	int transis = itemSite::createItemSite(this,
					       shipq.value("itemsite_id").toInt(),
				     shipq.value("tohead_trns_warehous_id").toInt(),
				     false);
	int destis  = itemSite::createItemSite(this,
					       shipq.value("itemsite_id").toInt(),
				     shipq.value("tohead_dest_warehous_id").toInt(),
				     true);
	if (transis <= 0 || destis < 0)
	  return;
      }
      if (shipq.lastError().type() != QSqlError::NoError)
      {
        systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__);
	return;
      }
      sShip();	// beware of endless loop if you change createItemSite err check
      return;	// return because the recursive call cleans up for us
    }
    else if (result < 0)
    {
      rollback.exec();
      systemError(this, storedProcErrorLookup("shipShipment", result),
		  __FILE__, __LINE__);
      return;
    }
  }
  else if (shipq.lastError().type() != QSqlError::NoError)
  {
    rollback.exec();
    QString errorStr = shipq.lastError().databaseText();
    if(errorStr.startsWith("ERROR:  null value in column \"gltrans_accnt_id\" violates not-null constraint"))
      errorStr = tr("One or more required accounts are not set or set incorrectly."
                    " Please make sure that all your Cost Category and Sales Account Assignments"
                    " are complete and correct.");
    systemError(this, errorStr, __FILE__, __LINE__);
    return;
  }

  shipq.exec("COMMIT;");
  if (shipq.lastError().type() != QSqlError::NoError)
  {
    systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  // END the transaction

  if (_print->isChecked())
  {
    ParameterList params;
    params.append("shiphead_id", _shipment->id());
    params.append("print");

    printPackingList newdlg(this, "", TRUE);
    newdlg.set(params);
  }

  if (_order->isSO() && _select->isChecked())
  {
    shipq.prepare("SELECT selectUninvoicedShipment(:shiphead_id) AS result;");
    shipq.bindValue(":shiphead_id", _shipment->id());
    shipq.exec();
    if (shipq.first())
    {
      int cobmiscid = shipq.value("result").toInt();
      if (cobmiscid < 0)
      {
	systemError(this,
	      storedProcErrorLookup("selectUninvoicedShipment", cobmiscid),
	      __FILE__, __LINE__);
	return;
      }
      else if (0 == cobmiscid)
      {
	QMessageBox::information(this, tr("Already Invoiced"),
				 tr("<p>This shipment appears to have been "
				   "invoiced already. It will not be selected "
				   "for billing again."));
      }
      else if (_create->isChecked())
      {
        shipq.prepare("SELECT createInvoice(:cobmisc_id) AS result;");
	shipq.bindValue(":cobmisc_id", cobmiscid);
	shipq.exec();
	if (shipq.first())
	{
	  int result = shipq.value("result").toInt();
	  if (result < 0)
	  {
	    systemError(this,
		      storedProcErrorLookup("postBillingSelection", result),
		      __FILE__, __LINE__);
	    return;
	  }
	  ParameterList params;
	  params.append("invchead_id", result);

	  printInvoice newdlg(this, "", TRUE);
	  newdlg.set(params);
	  newdlg.exec();

	  omfgThis->sInvoicesUpdated(result, TRUE);
	  omfgThis->sSalesOrdersUpdated(_order->id());
	}
	else if (shipq.lastError().type() != QSqlError::NoError)
	{
	  systemError(this, shipq.lastError().databaseText() +
		      tr("<p>Although Sales Order %1 was successfully shipped "
			 "and selected for billing, the Invoice was not "
			 "created properly. You may need to create an Invoice "
			 "manually from the Billing Selection.")
			.arg(_order->id()),
		      __FILE__, __LINE__);
	  return;
	}

	omfgThis->sBillingSelectionUpdated(_order->id(), TRUE);
      }
    }
    else if (shipq.lastError().type() != QSqlError::NoError)
    {
      systemError(this, shipq.lastError().databaseText() +
		  tr("<p>Although Sales Order %1 was successfully shipped, "
		     "it was not selected for billing. You must manually "
		     "select this Sales Order for Billing.")
		    .arg(_order->id()),
		  __FILE__, __LINE__);
      return;
    }
  }

  if (_order->isTO() && _receive->isChecked())
  {
    QString recverr = tr("<p>Receiving inventory for this Transfer Order "
			"failed although Shipping the Order succeeded. "
			"Manually receive this order using the Enter Order "
			"Receipt window.");
    shipq.exec("BEGIN;");
    ParameterList params;

    if (_metrics->boolean("MultiWhs"))
      params.append("MultiWhs");
    params.append("tohead_id",   _order->id());
    params.append("orderid",     _order->id());
    params.append("ordertype",   "TO");
    params.append("shiphead_id", _shipment->id());

    MetaSQLQuery recvm = mqlLoad("receipt", "receiveAll");
    shipq = recvm.toQuery(params);

    while (shipq.next())
    {
      int result = shipq.value("result").toInt();
      if (result < 0)
      {
	rollback.exec();
	systemError(this,
		    recverr + storedProcErrorLookup("enterReceipt", result),
		    __FILE__, __LINE__);
      }
      omfgThis->sPurchaseOrderReceiptsUpdated();
    }
    if (shipq.lastError().type() != QSqlError::NoError)
    {
      rollback.exec();
      systemError(this, recverr + "<br>" + shipq.lastError().databaseText(),
		  __FILE__, __LINE__);
    }

    shipq.exec("COMMIT;");
    if (shipq.lastError().type() != QSqlError::NoError)
    {
      systemError(this,
		  recverr + "<br>" + shipq.lastError().databaseText(),
		  __FILE__, __LINE__);
    }

    ParameterList recvParams;
    recvParams.append("tohead_id", _order->id());
    enterPoReceipt *newdlg = new enterPoReceipt();
    newdlg->set(recvParams);

    // to address bug 5680, replace
    // omfgThis->handleNewWindow(newdlg, Qt::ApplicationModal);
    // with
    newdlg->sPost();
    // end of replacement
  }

  if (_captive)
    accept();
  else
  {
    _order->setId(-1);
    _order->setEnabled(true);
    sHandleButtons();
    _billToName->clear();
    _shipToName->clear();
    _shipToAddr1->clear();
    _freight->setEnabled(TRUE);
    _freight->reset();
    _shipVia->clear();
    _shipment->clear();
    _shipment->setEnabled(false);
    _close->setText(tr("&Close"));

    _order->setFocus();
  }

  // Update the shipdatasum record to reflect shipped
  shipq.prepare("UPDATE shipdatasum "
		"   SET shipdatasum_shipped=true "
                " WHERE ((shipdatasum_cosmisc_tracknum = :tracknum)"
		"   AND  (   (shipdatasum_shiphead_number=:shiphead_number)"
		"         OR (:shiphead_number IS NULL)));");
  shipq.bindValue(":tracknum", _tracknum->currentText());
  if (! _shipment->number().isEmpty())
    shipq.bindValue(":shiphead_number", _shipment->number());
  shipq.exec();
  if (shipq.lastError().type() != QSqlError::NoError)
  {
    systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}