Exemple #1
0
void invoiceItem::sPriceUOMChanged()
{
  if(_pricingUOM->id() == -1 || _qtyUOM->id() == -1)
    return;

  if(_pricingUOM->id() == _invuomid)
    _priceinvuomratio = 1.0;
  else
  {
    XSqlQuery invuom;
    invuom.prepare("SELECT itemuomtouomratio(item_id, :uom_id, item_inv_uom_id) AS ratio"
                   "  FROM item"
                   " WHERE(item_id=:item_id);");
    invuom.bindValue(":item_id", _item->id());
    invuom.bindValue(":uom_id", _pricingUOM->id());
    invuom.exec();
    if(invuom.first())
      _priceinvuomratio = invuom.value("ratio").toDouble();
    else
      systemError(this, invuom.lastError().databaseText(), __FILE__, __LINE__);
  }

  XSqlQuery item;
  item.prepare("SELECT item_listprice"
               "  FROM item"
               " WHERE(item_id=:item_id);");
  item.bindValue(":item_id", _item->id());
  item.exec();
  item.first();
  _listPrice->setBaseValue(item.value("item_listprice").toDouble() * (_priceinvuomratio / _priceRatioCache));
  sDeterminePrice();
  sCalculateExtendedPrice();
}
Exemple #2
0
void invoiceItem::sQtyUOMChanged()
{
  if(_qtyUOM->id() == _invuomid)
    _qtyinvuomratio = 1.0;
  else
  {
    XSqlQuery invuom;
    invuom.prepare("SELECT itemuomtouomratio(item_id, :uom_id, item_inv_uom_id) AS ratio"
                   "  FROM item"
                   " WHERE(item_id=:item_id);");
    invuom.bindValue(":item_id", _item->id());
    invuom.bindValue(":uom_id", _qtyUOM->id());
    invuom.exec();
    if(invuom.first())
      _qtyinvuomratio = invuom.value("ratio").toDouble();
    else
      systemError(this, invuom.lastError().databaseText(), __FILE__, __LINE__);
  }

  if(_qtyUOM->id() != _invuomid)
  {
    _pricingUOM->setId(_qtyUOM->id());
    _pricingUOM->setEnabled(false);
  }
  else
    _pricingUOM->setEnabled(true);
  sDeterminePrice();
  sCalculateExtendedPrice();
}
Exemple #3
0
purchaseOrderItem::purchaseOrderItem(QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
    : XDialog(parent, name, modal, fl)
{
  setupUi(this);

#ifndef Q_WS_MAC
  _vendorItemNumberList->setMaximumWidth(25);
#endif

  connect(_ordered, SIGNAL(lostFocus()), this, SLOT(sDeterminePrice()));
  connect(_inventoryItem, SIGNAL(toggled(bool)), this, SLOT(sInventoryItemToggled(bool)));
  connect(_item, SIGNAL(privateIdChanged(int)), this, SLOT(sFindWarehouseItemsites(int)));
  connect(_item, SIGNAL(newId(int)), this, SLOT(sPopulateItemInfo(int)));
  connect(_save, SIGNAL(clicked()), this, SLOT(sSave()));
  connect(_ordered, SIGNAL(lostFocus()), this, SLOT(sUpdateVendorQty()));
  connect(_vendorItemNumberList, SIGNAL(clicked()), this, SLOT(sVendorItemNumberList()));
  connect(_notesButton, SIGNAL(toggled(bool)), this, SLOT(sHandleButtons()));

  _parentwo = -1;
  _parentso = -1;
  _itemsrcid = -1;

  _overriddenUnitPrice = false;

  _ordered->setValidator(omfgThis->qtyVal());

  _project->setType(ProjectLineEdit::PurchaseOrder);
  if(!_metrics->boolean("UseProjects"))
    _project->hide();

  _itemchar = new QStandardItemModel(0, 2, this);
  _itemchar->setHeaderData( 0, Qt::Horizontal, tr("Name"), Qt::DisplayRole);
  _itemchar->setHeaderData( 1, Qt::Horizontal, tr("Value"), Qt::DisplayRole);

  _itemcharView->setModel(_itemchar);
  ItemCharacteristicDelegate * delegate = new ItemCharacteristicDelegate(this);
  _itemcharView->setItemDelegate(delegate);

  _minOrderQty->setValidator(omfgThis->qtyVal());
  _orderQtyMult->setValidator(omfgThis->qtyVal());
  _received->setValidator(omfgThis->qtyVal());
  _invVendorUOMRatio->setValidator(omfgThis->ratioVal());

  q.exec("SELECT DISTINCT 1,itemsrc_manuf_name FROM itemsrc;");
  _manufName->populate(q);
  _manufName->setCurrentText("");

  //If not multi-warehouse hide whs control
  if (!_metrics->boolean("MultiWhs"))
  {
    _warehouseLit->hide();
    _warehouse->hide();
  }
  //If not Revision Control, hide controls
  if (!_metrics->boolean("RevControl"))
   _tab->removePage(_tab->page(4));
   
  adjustSize();
}
Exemple #4
0
void purchaseOrderItem::sVendorListPrices()
{
  ParameterList params;
  params.append("itemsrc_id", _itemsrcid);
  params.append("qty", _ordered->toDouble());
  vendorPriceList newdlg(this, "", TRUE);
  newdlg.set(params);
  if ( (newdlg.exec() == XDialog::Accepted))
  {
    _ordered->setDouble(newdlg._selectedQty);
    _orderQtyCache = _ordered->toDouble();
    sDeterminePrice();
  }
}
Exemple #5
0
purchaseOrderItem::purchaseOrderItem(QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
    : QDialog(parent, name, modal, fl)
{
  setupUi(this);

#ifndef Q_WS_MAC
  _vendorItemNumberList->setMaximumWidth(25);
#endif

  connect(_ordered, SIGNAL(lostFocus()), this, SLOT(sDeterminePrice()));
  connect(_inventoryItem, SIGNAL(toggled(bool)), this, SLOT(sInventoryItemToggled(bool)));
  connect(_item, SIGNAL(newId(int)), this, SLOT(sPopulateItemSourceInfo(int)));
  connect(_save, SIGNAL(clicked()), this, SLOT(sSave()));
  connect(_ordered, SIGNAL(lostFocus()), this, SLOT(sUpdateVendorQty()));
  connect(_vendorItemNumberList, SIGNAL(clicked()), this, SLOT(sVendorItemNumberList()));

  _parentwo = -1;
  _parentso = -1;

  _overriddenUnitPrice = false;

  _ordered->setValidator(omfgThis->qtyVal());

  _project->setType(ProjectLineEdit::PurchaseOrder);
  if(!_metrics->boolean("UseProjects"))
    _project->hide();

  _itemchar = new QStandardItemModel(0, 2, this);
  _itemchar->setHeaderData( 0, Qt::Horizontal, tr("Name"), Qt::DisplayRole);
  _itemchar->setHeaderData( 1, Qt::Horizontal, tr("Value"), Qt::DisplayRole);

  _itemcharView->setModel(_itemchar);
  ItemCharacteristicDelegate * delegate = new ItemCharacteristicDelegate(this);
  _itemcharView->setItemDelegate(delegate);

  //If not multi-warehouse hide whs control
  if (!_metrics->boolean("MultiWhs"))
  {
    _warehouseLit->hide();
    _warehouse->hide();
  }
  //If not Revision Control, hide controls
  if (!_metrics->boolean("RevControl"))
   _tab->removePage(_tab->page(4));
   
  resize(minimumSize());
}
Exemple #6
0
void invoiceItem::sPopulateItemInfo(int pItemid)
{
  if ( (_itemSelected->isChecked()) && (pItemid != -1) )
  {
    q.prepare( "SELECT item_priceuom,"
               "       item_invpricerat, formatUOMRatio(item_invpricerat) AS f_invpricerat,"
               "       item_listprice, "
               "       stdcost(item_id) AS f_unitcost,"
	       "       getItemTaxType(item_id, :taxauth) AS taxtype_id "
               "FROM item "
               "WHERE (item_id=:item_id);" );
    q.bindValue(":item_id", pItemid);
    q.bindValue(":taxauth", _taxauthid);
    q.exec();
    if (q.first())
    {
      if (_mode == cNew)
        sDeterminePrice();

      _priceRatioCache = q.value("item_invpricerat").toDouble();
      _priceRatio->setText(q.value("f_invpricerat").toString());
      _pricingUOM->setText(q.value("item_priceuom").toString());
      _listPrice->setBaseValue(q.value("item_listprice").toDouble());
      _unitCost->setBaseValue(q.value("f_unitcost").toDouble());
      _taxtype->setId(q.value("taxtype_id").toInt());
    }
    else if (q.lastError().type() != QSqlError::None)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else
  {
    _priceRatioCache = 1.0;
    _priceRatio->setText("1.0");
    _pricingUOM->setText(tr("EACH"));
    _listPrice->clear();
    _unitCost->clear();
  }
}
void purchaseOrderItem::sVendorListPrices()
{
  ParameterList params;
  params.append("itemsrc_id", _itemsrcid);
  params.append("qty", _ordered->toDouble());
  vendorPriceList newdlg(this, "", TRUE);
  newdlg.set(params);
  if ( (newdlg.exec() == XDialog::Accepted))
  {
    if (_ordered->text().toDouble() < newdlg._selectedQty)
    {
      if (QMessageBox::question(this, tr("Update Quantity?"),
                  tr("<p>You must order at least %1 to qualify for this price. Do you want to update the Quantity?").arg(QString().setNum(newdlg._selectedQty)),
                  QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::No)
        return;
  
      _ordered->setDouble(newdlg._selectedQty);
      _orderQtyCache = -1;
      sDeterminePrice();
    }
  }
}
Exemple #8
0
void invoiceItem::sPopulateItemInfo(int pItemid)
{
  if ( (_itemSelected->isChecked()) && (pItemid != -1) )
  {
    XSqlQuery uom;
    uom.prepare("SELECT uom_id, uom_name"
                "  FROM item"
                "  JOIN uom ON (item_inv_uom_id=uom_id)"
                " WHERE(item_id=:item_id)"
                " UNION "
                "SELECT uom_id, uom_name"
                "  FROM item"
                "  JOIN itemuomconv ON (itemuomconv_item_id=item_id)"
                "  JOIN uom ON (itemuomconv_to_uom_id=uom_id)"
                " WHERE((itemuomconv_from_uom_id=item_inv_uom_id)"
                "   AND (item_id=:item_id))"
                " UNION "
                "SELECT uom_id, uom_name"
                "  FROM item"
                "  JOIN itemuomconv ON (itemuomconv_item_id=item_id)"
                "  JOIN uom ON (itemuomconv_from_uom_id=uom_id)"
                " WHERE((itemuomconv_to_uom_id=item_inv_uom_id)"
                "   AND (item_id=:item_id))"
                " ORDER BY uom_name;");
    uom.bindValue(":item_id", _item->id());
    uom.exec();
    _qtyUOM->populate(uom);
    _pricingUOM->populate(uom);

    q.prepare( "SELECT item_inv_uom_id, item_price_uom_id,"
               "       iteminvpricerat(item_id) AS invpricerat,"
               "       item_listprice, "
               "       stdcost(item_id) AS f_unitcost,"
	       "       getItemTaxType(item_id, :taxauth) AS taxtype_id "
               "  FROM item"
               " WHERE (item_id=:item_id);" );
    q.bindValue(":item_id", pItemid);
    q.bindValue(":taxauth", _taxauthid);
    q.exec();
    if (q.first())
    {
      if (_mode == cNew)
        sDeterminePrice();

      _priceRatioCache = q.value("invpricerat").toDouble();
      _listPrice->setBaseValue(q.value("item_listprice").toDouble());

      _invuomid = q.value("item_inv_uom_id").toInt();
      _qtyUOM->setId(q.value("item_inv_uom_id").toInt());
      _pricingUOM->setId(q.value("item_price_uom_id").toInt());
      _qtyinvuomratio = 1.0;
      _priceinvuomratio = q.value("invpricerat").toDouble();
      _unitCost->setBaseValue(q.value("f_unitcost").toDouble());
      _taxtype->setId(q.value("taxtype_id").toInt());
    }
    else if (q.lastError().type() != QSqlError::NoError)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else
  {
    _priceRatioCache = 1.0;
    _qtyinvuomratio = 1.0;
    _priceinvuomratio = 1.0;
    _qtyUOM->clear();
    _pricingUOM->clear();
    _listPrice->clear();
    _unitCost->clear();
  }
}
Exemple #9
0
enum SetResponse invoiceItem::set(const ParameterList &pParams)
{
  QVariant param;
  bool     valid;

  param = pParams.value("invchead_id", &valid);
  if (valid)
  {
    _invcheadid = param.toInt();

    q.prepare("SELECT taxauth_id, "
              "       COALESCE(taxauth_curr_id, invchead_curr_id) AS curr_id "
              "FROM invchead, taxauth "
              "WHERE ((invchead_taxauth_id=taxauth_id)"
              "  AND  (invchead_id=:invchead_id));");
    q.bindValue(":invchead_id", _invcheadid);
    q.exec();
    if (q.first())
    {
      _taxauthid = q.value("taxauth_id").toInt();
      _tax->setId(q.value("curr_id").toInt());
    }
    else if (q.lastError().type() != QSqlError::NoError)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
  }

  param = pParams.value("invoiceNumber", &valid);
  if (valid)
    _invoiceNumber->setText(param.toString());

  param = pParams.value("cust_id", &valid);
  if (valid)
    _custid = param.toInt();

  param = pParams.value("cust_curr_id", &valid);
  if (valid)
  {
    _price->setId(param.toInt());
    sPriceGroup();
  }

  param = pParams.value("curr_date", &valid);
  if (valid)
    _price->setEffective(param.toDate());

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

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

      q.prepare( "SELECT (COALESCE(MAX(invcitem_linenumber), 0) + 1) AS linenumber "
                 "FROM invcitem "
                 "WHERE (invcitem_invchead_id=:invchead_id);" );
      q.bindValue(":invchead_id", _invcheadid);
      q.exec();
      if (q.first())
        _lineNumber->setText(q.value("linenumber").toString());
      else if (q.lastError().type() != QSqlError::NoError)
      {
	systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
	return UndefinedError;
      }

      connect(_billed, SIGNAL(lostFocus()), this, SLOT(sDeterminePrice()));
      connect(_billed, SIGNAL(lostFocus()), this, SLOT(sCalculateExtendedPrice()));
      connect(_price, SIGNAL(lostFocus()), this, SLOT(sCalculateExtendedPrice()));
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;

      connect(_billed, SIGNAL(lostFocus()), this, SLOT(sCalculateExtendedPrice()));
      connect(_price, SIGNAL(lostFocus()), this, SLOT(sCalculateExtendedPrice()));

      _save->setFocus();
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _itemTypeGroup->setEnabled(FALSE);
      _custPn->setEnabled(FALSE);
      _ordered->setEnabled(FALSE);
      _billed->setEnabled(FALSE);
      _price->setEnabled(FALSE);
      _notes->setReadOnly(TRUE);
      _taxtype->setEnabled(false);
      _taxcode->setEnabled(false);
      _save->hide();
      _close->setText(tr("&Cancel"));

      _close->setFocus();
    }
  }

  return NoError;
}
Exemple #10
0
void purchaseOrderItem::sPopulateItemSourceInfo(int pItemid)
{
  bool skipClear = false;
  _itemchar->removeRows(0, _itemchar->rowCount());
  if (_mode == cNew)
  {
    if (pItemid != -1)
    {
      if(_metrics->boolean("RequireStdCostForPOItem"))
      {
        q.prepare("SELECT stdCost(:item_id) AS result");
        q.bindValue(":item_id", pItemid);
        q.exec();
        if(q.first() && q.value("result").toDouble() == 0.0)
        {
          QMessageBox::critical( this, tr("Selected Item Missing Cost"),
		  tr("<p>The selected item has no Std. Costing information. "
		     "Please see your controller to correct this situation "
		     "before continuing."));
          _item->setId(-1);
          return;
        }
      }

      q.prepare( "SELECT itemsrc_id, itemsrc_vend_item_number,"
                 "       itemsrc_vend_item_descrip, itemsrc_vend_uom,"
                 "       itemsrc_minordqty,"
                 "       itemsrc_multordqty,"
                 "       itemsrc_invvendoruomratio,"
                 "       (CURRENT_DATE + itemsrc_leadtime) AS earliestdate "
                 "FROM pohead, itemsrc "
                 "WHERE ( (itemsrc_vend_id=pohead_vend_id)"
                 " AND (itemsrc_item_id=:item_id)"
                 " AND (pohead_id=:pohead_id) );" );
      q.bindValue(":item_id", pItemid);
      q.bindValue(":pohead_id", _poheadid);
      q.exec();
      if (q.first())
      {
        _itemsrcid = q.value("itemsrc_id").toInt();
  
        _vendorItemNumber->setText(q.value("itemsrc_vend_item_number").toString());
        _vendorDescrip->setText(q.value("itemsrc_vend_item_descrip").toString());
        _vendorUOM->setText(q.value("itemsrc_vend_uom").toString());
        _minOrderQty->setDouble(q.value("itemsrc_minordqty").toDouble());
        _orderQtyMult->setDouble(q.value("itemsrc_multordqty").toDouble());
        _invVendorUOMRatio->setDouble(q.value("itemsrc_invvendoruomratio").toDouble());
        _earliestDate->setDate(q.value("earliestdate").toDate());

        _invVendUOMRatio = q.value("itemsrc_invvendoruomratio").toDouble();
        _minimumOrder = q.value("itemsrc_minordqty").toDouble();
        _orderMultiple = q.value("itemsrc_multordqty").toDouble();

        if (_ordered->toDouble() != 0)
          sDeterminePrice();

        _ordered->setFocus();

        if(_metrics->boolean("UseEarliestAvailDateOnPOItem"))
          _dueDate->setDate(_earliestDate->date());

        skipClear = true;
      }
    }

    if(!skipClear)
    {
      _itemsrcid = -1;
  
      _vendorItemNumber->clear();
      _vendorDescrip->clear();
      _vendorUOM->setText(_item->uom());
      _minOrderQty->clear();
      _orderQtyMult->clear();
      _invVendorUOMRatio->setDouble(1.0);
      _earliestDate->setDate(omfgThis->dbDate());
  
      _invVendUOMRatio = 1;
      _minimumOrder = 0;
      _orderMultiple = 0;
    }

    q.prepare( "SELECT DISTINCT char_id, char_name,"
               "       COALESCE(b.charass_value, (SELECT c.charass_value FROM charass c WHERE ((c.charass_target_type='I') AND (c.charass_target_id=:item_id) AND (c.charass_default) AND (c.charass_char_id=char_id)) LIMIT 1)) AS charass_value"
               "  FROM charass a, char "
               "    LEFT OUTER JOIN charass b"
               "      ON (b.charass_target_type='PI'"
               "      AND b.charass_target_id=:poitem_id"
               "      AND b.charass_char_id=char_id) "
               " WHERE ( (a.charass_char_id=char_id)"
               "   AND   (a.charass_target_type='I')"
               "   AND   (a.charass_target_id=:item_id) ) "
               " ORDER BY char_name;" );
    q.bindValue(":item_id", pItemid);
    q.bindValue(":poitem_id", _poitemid);
    q.exec();
    int row = 0;
    QModelIndex idx;
    while(q.next())
    {
      _itemchar->insertRow(_itemchar->rowCount());
      idx = _itemchar->index(row, 0);
      _itemchar->setData(idx, q.value("char_name"), Qt::DisplayRole);
      _itemchar->setData(idx, q.value("char_id"), Qt::UserRole);
      idx = _itemchar->index(row, 1);
      _itemchar->setData(idx, q.value("charass_value"), Qt::DisplayRole);
      _itemchar->setData(idx, pItemid, Qt::UserRole);
      row++;
    }
  }
}
purchaseOrderItem::purchaseOrderItem(QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
    : XDialog(parent, name, modal, fl)
{
  XSqlQuery purchasepurchaseOrderItem;
  setupUi(this);

#ifndef Q_WS_MAC
  _vendorItemNumberList->setMaximumWidth(25);
#else
  _listPrices->setMinimumWidth(60);
#endif

  _vendid = -1;
  _preferredWarehouseid = -1;
  _invVendUOMRatio = 1;
  _minimumOrder = 0;
  _orderMultiple = 0;
  _maxCost = 0.0;
  _dropship = false;
  _costmethod = "";
  _captive = false;

  connect(_ordered, SIGNAL(editingFinished()), this, SLOT(sDeterminePrice()));
  connect(_inventoryItem, SIGNAL(toggled(bool)), this, SLOT(sInventoryItemToggled(bool)));
  connect(_item, SIGNAL(privateIdChanged(int)), this, SLOT(sFindWarehouseItemsites(int)));
  connect(_item, SIGNAL(newId(int)), this, SLOT(sPopulateItemInfo(int)));
  connect(_warehouse, SIGNAL(newID(int)), this, SLOT(sPopulateItemsiteInfo()));
  connect(_save, SIGNAL(clicked()), this, SLOT(sSave()));
  connect(_vendorItemNumberList, SIGNAL(clicked()), this, SLOT(sVendorItemNumberSearch()));
  connect(_notesButton, SIGNAL(toggled(bool)), this, SLOT(sHandleButtons()));
  connect(_listPrices, SIGNAL(clicked()), this, SLOT(sVendorListPrices()));
  connect(_taxLit, SIGNAL(leftClickedURL(QString)), this, SLOT(sTaxDetail()));  // new slot added for tax url //
  connect(_extendedPrice, SIGNAL(valueChanged()), this, SLOT(sCalculateTax()));  // new slot added for price //
  connect(_taxtype, SIGNAL(newID(int)), this, SLOT(sCalculateTax()));            // new slot added for taxtype //

  _bomRevision->setMode(RevisionLineEdit::Use);
  _bomRevision->setType("BOM");
  _booRevision->setMode(RevisionLineEdit::Use);
  _booRevision->setType("BOO");

  _parentwo = -1;
  _parentso = -1;
  _itemsrcid = -1;
  _taxzoneid = -1;   //  _taxzoneid  added //
  _orderQtyCache = -1;

  _overriddenUnitPrice = false;

  _ordered->setValidator(omfgThis->qtyVal());

  _project->setType(ProjectLineEdit::PurchaseOrder);
  if(!_metrics->boolean("UseProjects"))
    _project->hide();

  _itemchar = new QStandardItemModel(0, 2, this);
  _itemchar->setHeaderData( 0, Qt::Horizontal, tr("Name"), Qt::DisplayRole);
  _itemchar->setHeaderData( 1, Qt::Horizontal, tr("Value"), Qt::DisplayRole);

  _itemcharView->setModel(_itemchar);
  ItemCharacteristicDelegate * delegate = new ItemCharacteristicDelegate(this);
  _itemcharView->setItemDelegate(delegate);

  _minOrderQty->setValidator(omfgThis->qtyVal());
  _orderQtyMult->setValidator(omfgThis->qtyVal());
  _received->setValidator(omfgThis->qtyVal());
  _invVendorUOMRatio->setValidator(omfgThis->ratioVal());

  purchasepurchaseOrderItem.exec("SELECT DISTINCT itemsrc_manuf_name FROM itemsrc ORDER BY 1;");
  for (int i = 0; purchasepurchaseOrderItem.next(); i++)
    _manufName->append(i, purchasepurchaseOrderItem.value("itemsrc_manuf_name").toString());
  _manufName->setId(-1);

  //If not multi-warehouse hide whs control
  if (!_metrics->boolean("MultiWhs"))
  {
    _warehouseLit->hide();
    _warehouse->hide();
  }
  //If not Revision Control, hide controls
  if (!_metrics->boolean("RevControl"))
   _tab->removeTab(_tab->indexOf(_revision));
   
  adjustSize();
  
  //TO DO: Implement later
  _taxRecoverable->hide();
}
enum SetResponse invoiceItem::set(const ParameterList &pParams)
{
  XSqlQuery invoiceet;
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("invchead_id", &valid);
  if (valid)
  {
    _invcheadid = param.toInt();

    invoiceet.prepare("SELECT * "
                      "FROM invchead "
			  "WHERE (invchead_id = :invchead_id);");
    invoiceet.bindValue(":invchead_id", _invcheadid);
    invoiceet.exec();
    if (invoiceet.first())
    {
      _invoiceNumber->setText(invoiceet.value("invchead_invcnumber").toString());
      _custid = invoiceet.value("invchead_cust_id").toInt();
      _taxzoneid = invoiceet.value("invchead_taxzone_id").toInt();
      _tax->setId(invoiceet.value("invchead_curr_id").toInt());
      _price->setId(invoiceet.value("invchead_curr_id").toInt());
      _price->setEffective(invoiceet.value("invchead_invcdate").toDate());
      sPriceGroup();
    }
    else if (invoiceet.lastError().type() != QSqlError::NoError)
    {
      systemError(this, invoiceet.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
  }

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

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

      invoiceet.exec("SELECT NEXTVAL('invcitem_invcitem_id_seq') AS invcitem_id;");
      if (invoiceet.first())
        _invcitemid = invoiceet.value("invcitem_id").toInt();
      else if (invoiceet.lastError().type() != QSqlError::NoError)
      {
            systemError(this, invoiceet.lastError().databaseText(), __FILE__, __LINE__);
            return UndefinedError;
      }

      invoiceet.prepare( "SELECT (COALESCE(MAX(invcitem_linenumber), 0) + 1) AS linenumber "
                         "FROM invcitem "
                         "WHERE (invcitem_invchead_id=:invchead_id);" );
      invoiceet.bindValue(":invchead_id", _invcheadid);
      invoiceet.exec();
      if (invoiceet.first())
        _lineNumber->setText(invoiceet.value("linenumber").toString());
      else if (invoiceet.lastError().type() != QSqlError::NoError)
      {
	    systemError(this, invoiceet.lastError().databaseText(), __FILE__, __LINE__);
	    return UndefinedError;
      }

      connect(_billed, SIGNAL(editingFinished()), this, SLOT(sDeterminePrice()));
      connect(_billed, SIGNAL(editingFinished()), this, SLOT(sCalculateExtendedPrice()));
      connect(_price, SIGNAL(editingFinished()), this, SLOT(sCalculateExtendedPrice()));
      _item->setType(ItemLineEdit::cSold);
      _salescat->setType(XComboBox::SalesCategoriesActive);
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;

      connect(_billed, SIGNAL(editingFinished()), this, SLOT(sDeterminePrice()));
      connect(_billed, SIGNAL(editingFinished()), this, SLOT(sCalculateExtendedPrice()));
      connect(_price, SIGNAL(editingFinished()), this, SLOT(sCalculateExtendedPrice()));
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _itemTypeGroup->setEnabled(FALSE);
      _custPn->setEnabled(FALSE);
      _ordered->setEnabled(FALSE);
      _billed->setEnabled(FALSE);
      _price->setEnabled(FALSE);
      _notes->setReadOnly(TRUE);
      _taxtype->setEnabled(false);
      _altRevAccnt->setEnabled(false);
      _qtyUOM->setEnabled(false);
      _pricingUOM->setEnabled(false);

      _save->hide();
      _close->setText(tr("&Cancel"));
    }
  }

  return NoError;
}
void invoiceItem::sPopulateItemInfo(int pItemid)
{
  XSqlQuery invoicePopulateItemInfo;
  if ( (_itemSelected->isChecked()) && (pItemid != -1) )
  {
    XSqlQuery uom;
    uom.prepare("SELECT uom_id, uom_name"
                "  FROM item"
                "  JOIN uom ON (item_inv_uom_id=uom_id)"
                " WHERE(item_id=:item_id)"
                " UNION "
                "SELECT uom_id, uom_name"
                "  FROM item"
                "  JOIN itemuomconv ON (itemuomconv_item_id=item_id)"
                "  JOIN uom ON (itemuomconv_to_uom_id=uom_id)"
                " WHERE((itemuomconv_from_uom_id=item_inv_uom_id)"
                "   AND (item_id=:item_id))"
                " UNION "
                "SELECT uom_id, uom_name"
                "  FROM item"
                "  JOIN itemuomconv ON (itemuomconv_item_id=item_id)"
                "  JOIN uom ON (itemuomconv_from_uom_id=uom_id)"
                " WHERE((itemuomconv_to_uom_id=item_inv_uom_id)"
                "   AND (item_id=:item_id))"
                " ORDER BY uom_name;");
    uom.bindValue(":item_id", _item->id());
    uom.exec();
    _qtyUOM->populate(uom);
    _pricingUOM->populate(uom);

    invoicePopulateItemInfo.prepare( "SELECT item_inv_uom_id, item_price_uom_id,"
               "       iteminvpricerat(item_id) AS invpricerat,"
               "       item_listprice, item_fractional, "
               "       stdcost(item_id) AS f_unitcost,"
               "       getItemTaxType(item_id, :taxzone) AS taxtype_id,"
               "       itemsite_costmethod"
               "  FROM item"
               "  JOIN itemsite ON (item_id=itemsite_item_id)"
               " WHERE ((item_id=:item_id)"
               "    AND (itemsite_warehous_id=:whsid));" );
    invoicePopulateItemInfo.bindValue(":item_id", pItemid);
    invoicePopulateItemInfo.bindValue(":taxzone", _taxzoneid);
    invoicePopulateItemInfo.bindValue(":whsid",   _warehouse->id());
    invoicePopulateItemInfo.exec();
    if (invoicePopulateItemInfo.first())
    {
      _priceRatioCache = invoicePopulateItemInfo.value("invpricerat").toDouble();
      _listPrice->setBaseValue(invoicePopulateItemInfo.value("item_listprice").toDouble());

      _invuomid = invoicePopulateItemInfo.value("item_inv_uom_id").toInt();
      _qtyUOM->setId(invoicePopulateItemInfo.value("item_inv_uom_id").toInt());
      _pricingUOM->setId(invoicePopulateItemInfo.value("item_price_uom_id").toInt());
      _qtyinvuomratio = 1.0;
      _priceinvuomratio = invoicePopulateItemInfo.value("invpricerat").toDouble();
      _unitCost->setBaseValue(invoicePopulateItemInfo.value("f_unitcost").toDouble());
      _taxtype->setId(invoicePopulateItemInfo.value("taxtype_id").toInt());
      if (invoicePopulateItemInfo.value("item_fractional").toBool())
      {
        _ordered->setValidator(omfgThis->qtyVal());
        _billed->setValidator(omfgThis->qtyVal());
      }
      else
      {
        _ordered->setValidator(new XDoubleValidator(0, 999999, 0, this));
        _billed->setValidator(new XDoubleValidator(0, 999999, 0, this));
      }
      sDeterminePrice();

      // TODO: should this check itemsite_controlmethod == N?
      _trackqoh = (invoicePopulateItemInfo.value("itemsite_costmethod").toString() != "J");
    }
    else if (invoicePopulateItemInfo.lastError().type() != QSqlError::NoError)
    {
      systemError(this, invoicePopulateItemInfo.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else
  {
    _priceRatioCache = 1.0;
    _qtyinvuomratio = 1.0;
    _priceinvuomratio = 1.0;
    _qtyUOM->clear();
    _pricingUOM->clear();
    _listPrice->clear();
    _unitCost->clear();
  }
}
Exemple #14
0
void purchaseOrderItem::sPopulateItemSourceInfo(int pItemsrcid)
{
  XSqlQuery src;
  bool skipClear = false;
  if (!_item->isValid())
    skipClear = true;
  _itemchar->removeRows(0, _itemchar->rowCount());
  if (_mode == cNew)
  {
    if (pItemsrcid != -1)
    {
      src.prepare( "SELECT itemsrc_id, itemsrc_item_id, itemsrc_vend_item_number,"
                 "       itemsrc_vend_item_descrip, itemsrc_vend_uom,"
                 "       itemsrc_minordqty,"
                 "       itemsrc_multordqty,"
                 "       itemsrc_invvendoruomratio,"
                 "       (CURRENT_DATE + itemsrc_leadtime) AS earliestdate, "
                 "       itemsrc_manuf_name, "
                 "       itemsrc_manuf_item_number, "
                 "       itemsrc_manuf_item_descrip "
                 "FROM pohead, itemsrc "
                 "WHERE (itemsrc_id=:itemsrc_id);" );
      src.bindValue(":itemsrc_id", pItemsrcid);
      src.exec();
      if (src.first())
      {
        _itemsrcid = src.value("itemsrc_id").toInt();
        _item->setId(src.value("itemsrc_item_id").toInt());
  
        _vendorItemNumber->setText(src.value("itemsrc_vend_item_number").toString());
        _vendorDescrip->setText(src.value("itemsrc_vend_item_descrip").toString());
        _vendorUOM->setText(src.value("itemsrc_vend_uom").toString());
        _uom->setText(src.value("itemsrc_vend_uom").toString());
        _minOrderQty->setDouble(src.value("itemsrc_minordqty").toDouble());
        _orderQtyMult->setDouble(src.value("itemsrc_multordqty").toDouble());
        _invVendorUOMRatio->setDouble(src.value("itemsrc_invvendoruomratio").toDouble());
        _earliestDate->setDate(src.value("earliestdate").toDate());

        _invVendUOMRatio = src.value("itemsrc_invvendoruomratio").toDouble();
        _minimumOrder = src.value("itemsrc_minordqty").toDouble();
        _orderMultiple = src.value("itemsrc_multordqty").toDouble();
        
        _manufName->setCurrentText(src.value("itemsrc_manuf_name").toString());
        _manufItemNumber->setText(src.value("itemsrc_manuf_item_number").toString());
        _manufItemDescrip->setText(src.value("itemsrc_manuf_item_descrip").toString());

        if (_ordered->toDouble() != 0)
          sDeterminePrice();

        _ordered->setFocus();

        if(_metrics->boolean("UseEarliestAvailDateOnPOItem"))
          _dueDate->setDate(_earliestDate->date());

        skipClear = true;
      }
    }

    if(!skipClear)
    {
      _itemsrcid = -1;
  
      _vendorItemNumber->clear();
      _vendorDescrip->clear();
      _vendorUOM->setText(_item->uom());
      _uom->setText(_item->uom());
      _minOrderQty->clear();
      _orderQtyMult->clear();
      _invVendorUOMRatio->setDouble(1.0);
      _earliestDate->setDate(omfgThis->dbDate());
      _manufName->clear();
      _manufItemNumber->clear();
      _manufItemDescrip->clear();
  
      _invVendUOMRatio = 1;
      _minimumOrder = 0;
      _orderMultiple = 0;
    }
  }
}
enum SetResponse purchaseOrderItem::set(const ParameterList &pParams)
{
  XSqlQuery purchaseet;
  XDialog::set(pParams);
  QVariant param;
  bool     valid;
  bool     haveQty  = FALSE;
  bool     haveDate = FALSE;



  param = pParams.value("vend_id", &valid);
  if (valid)
    _vendid = param.toInt();

  param = pParams.value("warehous_id", &valid);
  if (valid)
    _preferredWarehouseid = param.toInt();

  param = pParams.value("dropship", &valid);
  if (valid)
    _dropship = param.toBool();

  param = pParams.value("parentWo", &valid);
  if (valid)
    _parentwo = param.toInt();

  param = pParams.value("parentSo", &valid);
  if (valid)
    _parentso = param.toInt();

  if (_metrics->boolean("CopyPRtoPOItem"))
  {
    param = pParams.value("pr_releasenote", &valid);
    if(valid)
      _notes->setText(param.toString());
  }

  param = pParams.value("pohead_id", &valid);
  if (valid)
  {
    _poheadid = param.toInt();

    purchaseet.prepare( "SELECT pohead_taxzone_id, pohead_number, pohead_orderdate, pohead_status, " // pohead_taxzone_id added
               "       vend_id, vend_restrictpurch, pohead_curr_id "
               "FROM pohead, vendinfo "
               "WHERE ( (pohead_vend_id=vend_id)"
               " AND (pohead_id=:pohead_id) );" );
    purchaseet.bindValue(":pohead_id", param.toInt());
    purchaseet.exec();
    if (purchaseet.first())
    {
      _poNumber->setText(purchaseet.value("pohead_number").toString());
      _poStatus = purchaseet.value("pohead_status").toString();
      _unitPrice->setEffective(purchaseet.value("pohead_orderdate").toDate());
      _unitPrice->setId(purchaseet.value("pohead_curr_id").toInt());
	  _taxzoneid=purchaseet.value("pohead_taxzone_id").toInt();   // added  to pick up tax zone id.
	  _tax->setEffective(purchaseet.value("pohead_orderdate").toDate());
      _tax->setId(purchaseet.value("pohead_curr_id").toInt());

      if (purchaseet.value("vend_restrictpurch").toBool())
      {
        _item->setQuery( QString( "SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2,"
                                  "                (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,"
                                  "                uom_name, item_type, item_config, item_active, item_upccode "
                                  "FROM item, itemsite, itemsrc, uom  "
                                  "WHERE ( (itemsite_item_id=item_id)"
                                  " AND (itemsrc_item_id=item_id)"
                                  " AND (item_inv_uom_id=uom_id)"
                                  " AND (itemsite_active)"
                                  " AND (item_active)"
                                  " AND (itemsrc_active)"
                                  " AND (itemsrc_vend_id=%1) ) "
                                  "ORDER BY item_number" )
                         .arg(purchaseet.value("vend_id").toInt()) );
        _item->setValidationQuery( QString( "SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2,"
                                            "                (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,"
                                            "                uom_name, item_type, item_config, item_active, item_upccode "
                                            "FROM item, itemsite, itemsrc, uom  "
                                            "WHERE ( (itemsite_item_id=item_id)"
                                            " AND (itemsrc_item_id=item_id)"
                                            " AND (item_inv_uom_id=uom_id)"
                                            " AND (itemsite_active)"
                                            " AND (item_active)"
                                            " AND (itemsrc_active)"
                                            " AND (itemsrc_vend_id=%1) "
                                            " AND (itemsite_item_id=:item_id) ) ")
                                   .arg(purchaseet.value("vend_id").toInt()) );
      }
      else
      {
        _item->setType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cGeneralManufactured |
		               ItemLineEdit::cTooling | ItemLineEdit::cActive);
        _item->setDefaultType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cActive);
      }
    }
    else
    {
      systemError(this, tr("A System Error occurred at %1::%2.")
                        .arg(__FILE__)
                        .arg(__LINE__) );
      return UndefinedError;
    }
  }

  param = pParams.value("poitem_id", &valid);
  if (valid)
  {
    _poitemid = param.toInt();

    purchaseet.prepare( "SELECT pohead_number, pohead_id "
               "FROM pohead, poitem "
               "WHERE ( (pohead_id=poitem_pohead_id) "
               " AND (poitem_id=:poitem_id) );" );
    purchaseet.bindValue(":poitem_id", param.toInt());
    purchaseet.exec();
    if (purchaseet.first())
    {
      _poNumber->setText(purchaseet.value("pohead_number").toString());
	  _poheadid = purchaseet.value("pohead_id").toInt();
    }

    populate();
	sCalculateTax();
  }
  // connect here and not in the .ui to avoid timing issues at initialization
  connect(_unitPrice, SIGNAL(valueChanged()), this, SLOT(sPopulateExtPrice()));

  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "new")
    {
      _mode = cNew;
      _save->setEnabled(false);

      purchaseet.exec("SELECT NEXTVAL('poitem_poitem_id_seq') AS poitem_id;");
      if (purchaseet.first())
        _poitemid = purchaseet.value("poitem_id").toInt();
      else
      {
        systemError(this, tr("A System Error occurred at %1::%2.")
                          .arg(__FILE__)
                          .arg(__LINE__) );
        return UndefinedError;
      }

      if(_parentwo != -1)
      {
        purchaseet.prepare("SELECT wo_number"
                  "  FROM womatl JOIN wo ON (wo_id=womatl_wo_id)"
                  " WHERE (womatl_id=:parentwo); ");
        purchaseet.bindValue(":parentwo", _parentwo);
        purchaseet.exec();
        if(purchaseet.first())
        {
          _so->setText(purchaseet.value("wo_number").toString());
          _soLine->setText("");
        }
      }

      if(_parentso != -1)
      {
        purchaseet.prepare( "INSERT INTO charass"
                   "      (charass_target_type, charass_target_id,"
                   "       charass_char_id, charass_value) "
                   "SELECT 'PI', :orderid, charass_char_id, charass_value"
                   "  FROM charass"
                   " WHERE ((charass_target_type='SI')"
                   "   AND  (charass_target_id=:soitem_id));");
        purchaseet.bindValue(":orderid", _poitemid);
        purchaseet.bindValue(":soitem_id", _parentso);
        purchaseet.exec();
      }

      purchaseet.prepare( "SELECT (COALESCE(MAX(poitem_linenumber), 0) + 1) AS _linenumber "
                 "FROM poitem "
                 "WHERE (poitem_pohead_id=:pohead_id);" );
      purchaseet.bindValue(":pohead_id", _poheadid);
      purchaseet.exec();
      if (purchaseet.first())
        _lineNumber->setText(purchaseet.value("_linenumber").toString());
      else
      {
        systemError(this, tr("A System Error occurred at %1::%2.")
                          .arg(__FILE__)
                          .arg(__LINE__) );

        return UndefinedError;
      }

      _bomRevision->setEnabled(_privileges->boolean("UseInactiveRevisions"));
      _booRevision->setEnabled(_privileges->boolean("UseInactiveRevisions"));
      _comments->setId(_poitemid);
      _tab->setTabEnabled(_tab->indexOf(_demandTab), FALSE);
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;

      _typeGroup->setEnabled(FALSE);
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _typeGroup->setEnabled(FALSE);
      _vendorItemNumber->setEnabled(FALSE);
      _vendorItemNumberList->setEnabled(FALSE);
      _vendorDescrip->setEnabled(FALSE);
      _warehouse->setEnabled(FALSE);
      _dueDate->setEnabled(FALSE);
      _ordered->setEnabled(FALSE);
      _unitPrice->setEnabled(FALSE);
      _freight->setEnabled(FALSE);
      _notes->setReadOnly(TRUE);
      _comments->setReadOnly(TRUE);
      _project->setEnabled(FALSE);
      _taxtype->setEnabled(FALSE);
      _taxRecoverable->setEnabled(FALSE);
      _bomRevision->setEnabled(FALSE);
      _booRevision->setEnabled(FALSE);

      _close->setText(tr("&Close"));
      _save->hide();
    }
  }

  param = pParams.value("itemsite_id", &valid);
  if (valid)
  {
    _item->setItemsiteid(param.toInt());
    _item->setEnabled(FALSE);
    _warehouse->setEnabled(FALSE);
  }
  
  param = pParams.value("itemsrc_id", &valid);
  if (valid)
    sPopulateItemSourceInfo(param.toInt());

  param = pParams.value("qty", &valid);
  if (valid)
  {
    _ordered->setDouble((param.toDouble()/_invVendUOMRatio));

    if (_item->isValid())
      sDeterminePrice();

    haveQty = TRUE;
  }

  param = pParams.value("dueDate", &valid);
  if (valid)
  {
    _dueDate->setDate(param.toDate());
    haveDate = TRUE;
  }

  param = pParams.value("prj_id", &valid);
  if (valid)
    _project->setId(param.toInt());

  if(_parentso != -1)
  {
    purchaseet.prepare("SELECT cohead_number, coitem_linenumber, coitem_prcost"
              "  FROM coitem JOIN cohead ON (cohead_id=coitem_cohead_id)"
              " WHERE (coitem_id=:parentso); ");
    purchaseet.bindValue(":parentso", _parentso);
    purchaseet.exec();
    if(purchaseet.first())
    {
      _so->setText(purchaseet.value("cohead_number").toString());
      _soLine->setText(purchaseet.value("coitem_linenumber").toString());
      if(purchaseet.value("coitem_prcost").toDouble() > 0)
      {
        _overriddenUnitPrice = true;
        _unitPrice->setLocalValue(purchaseet.value("coitem_prcost").toDouble());
        sPopulateExtPrice();
      }
    }
  }

  param = pParams.value("captive", &valid);
  if (valid)
    _captive = true;
  
  return NoError;
}
Exemple #16
0
enum SetResponse purchaseOrderItem::set(const ParameterList &pParams)
{
  QVariant param;
  bool     valid;
  bool     haveQty  = FALSE;
  bool     haveDate = FALSE;

  param = pParams.value("warehous_id", &valid);
  if (valid)
    _preferredWarehouseid = param.toInt();

  param = pParams.value("parentWo", &valid);
  if (valid)
    _parentwo = param.toInt();

  param = pParams.value("parentSo", &valid);
  if (valid)
    _parentso = param.toInt();

  param = pParams.value("pohead_id", &valid);
  if (valid)
  {
    _poheadid = param.toInt();

    q.prepare( "SELECT pohead_number, pohead_orderdate, pohead_status, "
               "       vend_id, vend_restrictpurch, pohead_curr_id "
               "FROM pohead, vend "
               "WHERE ( (pohead_vend_id=vend_id)"
               " AND (pohead_id=:pohead_id) );" );
    q.bindValue(":pohead_id", param.toInt());
    q.exec();
    if (q.first())
    {
      _poNumber->setText(q.value("pohead_number").toString());
      _poStatus = q.value("pohead_status").toString();
      _unitPrice->setEffective(q.value("pohead_orderdate").toDate());
      _unitPrice->setId(q.value("pohead_curr_id").toInt());

      if (q.value("vend_restrictpurch").toBool())
      {
        _item->setQuery( QString( "SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2,"
                                  "                (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,"
                                  "                uom_name, item_type, item_config, item_active "
                                  "FROM item, itemsite, itemsrc, uom  "
                                  "WHERE ( (itemsite_item_id=item_id)"
                                  " AND (itemsrc_item_id=item_id)"
                                  " AND (item_inv_uom_id=uom_id)"
                                  " AND (itemsite_active)"
                                  " AND (item_active)"
                                  " AND (itemsrc_active)"
                                  " AND (itemsrc_vend_id=%1) ) "
                                  "ORDER BY item_number" )
                         .arg(q.value("vend_id").toInt()) );
        _item->setValidationQuery( QString( "SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2,"
                                            "                (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,"
                                            "                uom_name, item_type, item_config, item_active "
                                            "FROM item, itemsite, itemsrc, uom  "
                                            "WHERE ( (itemsite_item_id=item_id)"
                                            " AND (itemsrc_item_id=item_id)"
                                            " AND (item_inv_uom_id=uom_id)"
                                            " AND (itemsite_active)"
                                            " AND (item_active)"
                                            " AND (itemsrc_active)"
                                            " AND (itemsrc_vend_id=%1) "
                                            " AND (itemsite_item_id=:item_id) ) ")
                                   .arg(q.value("vend_id").toInt()) );
      }
      else
	  {
        _item->setType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cGeneralManufactured | ItemLineEdit::cActive);
        _item->setDefaultType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cActive);
      }
    }
    else
    {
      systemError(this, tr("A System Error occurred at %1::%2.")
                        .arg(__FILE__)
                        .arg(__LINE__) );
      return UndefinedError;
    }
  }

  param = pParams.value("poitem_id", &valid);
  if (valid)
  {
    _poitemid = param.toInt();

    q.prepare( "SELECT pohead_number "
               "FROM pohead, poitem "
               "WHERE ( (pohead_id=poitem_pohead_id) "
               " AND (poitem_id=:poitem_id) );" );
    q.bindValue(":poitem_id", param.toInt());
    q.exec();
    if (q.first())
    {
      _poNumber->setText(q.value("pohead_number").toString());
    }

    populate();
  }
  // connect here and not in the .ui to avoid timing issues at initialization
  connect(_unitPrice, SIGNAL(valueChanged()), this, SLOT(sPopulateExtPrice()));

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

      q.exec("SELECT NEXTVAL('poitem_poitem_id_seq') AS poitem_id;");
      if (q.first())
        _poitemid = q.value("poitem_id").toInt();
      else
      {
        systemError(this, tr("A System Error occurred at %1::%2.")
                          .arg(__FILE__)
                          .arg(__LINE__) );
        return UndefinedError;
      }

      if(_parentso != -1)
      {
        q.prepare( "INSERT INTO charass"
                   "      (charass_target_type, charass_target_id,"
                   "       charass_char_id, charass_value) "
                   "SELECT 'PI', :orderid, charass_char_id, charass_value"
                   "  FROM charass"
                   " WHERE ((charass_target_type='SI')"
                   "   AND  (charass_target_id=:soitem_id));");
        q.bindValue(":orderid", _poitemid);
        q.bindValue(":soitem_id", _parentso);
        q.exec();
      }

      q.prepare( "SELECT (COALESCE(MAX(poitem_linenumber), 0) + 1) AS _linenumber "
                 "FROM poitem "
                 "WHERE (poitem_pohead_id=:pohead_id);" );
      q.bindValue(":pohead_id", _poheadid);
      q.exec();
      if (q.first())
        _lineNumber->setText(q.value("_linenumber").toString());
      else
      {
        systemError(this, tr("A System Error occurred at %1::%2.")
                          .arg(__FILE__)
                          .arg(__LINE__) );

        return UndefinedError;
      }

      if (!_item->isValid())
        _item->setFocus();
      else if (!haveQty)
        _ordered->setFocus();
      else if (!haveDate)
        _dueDate->setFocus();

      _comments->setEnabled(FALSE);
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;

      _typeGroup->setEnabled(FALSE);

      _ordered->setFocus();
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _typeGroup->setEnabled(FALSE);
      _vendorItemNumber->setEnabled(FALSE);
      _vendorItemNumberList->setEnabled(FALSE);
      _vendorDescrip->setEnabled(FALSE);
      _warehouse->setEnabled(FALSE);
      _dueDate->setEnabled(FALSE);
      _ordered->setEnabled(FALSE);
      _unitPrice->setEnabled(FALSE);
      _freight->setEnabled(FALSE);
      _notes->setReadOnly(TRUE);
      _comments->setReadOnly(TRUE);
      _project->setEnabled(FALSE);

      _close->setText(tr("&Close"));
      _save->hide();

      _close->setFocus();
    }
  }

  param = pParams.value("itemsite_id", &valid);
  if (valid)
  {
    _item->setItemsiteid(param.toInt());
    _item->setEnabled(FALSE);
    _warehouse->setEnabled(FALSE);
  }
  
  param = pParams.value("itemsrc_id", &valid);
  if (valid)
    sPopulateItemSourceInfo(param.toInt());

  param = pParams.value("qty", &valid);
  if (valid)
  {
    _ordered->setDouble((param.toDouble()/_invVendUOMRatio));

    if (_item->isValid())
      sDeterminePrice();

    haveQty = TRUE;
  }

  param = pParams.value("dueDate", &valid);
  if (valid)
  {
    _dueDate->setDate(param.toDate());
    haveDate = TRUE;
  }

  param = pParams.value("prj_id", &valid);
  if (valid)
    _project->setId(param.toInt());

  if(_parentso != -1)
  {
    q.prepare("SELECT coitem_prcost"
              "  FROM coitem"
              " WHERE (coitem_id=:parentso); ");
    q.bindValue(":parentso", _parentso);
    q.exec();
    if(q.first())
    {
      if(q.value("coitem_prcost").toDouble() > 0)
      {
        _overriddenUnitPrice = true;
        _unitPrice->setLocalValue(q.value("coitem_prcost").toDouble());
        sPopulateExtPrice();
      }
    }
  }

  return NoError;
}
void invoiceItem::sPopulateItemInfo(int pItemid)
{
  XSqlQuery invoicePopulateItemInfo;
  if ( (_itemSelected->isChecked()) && (pItemid != -1) )
  {
    // Get list of active, valid Selling UOMs
    MetaSQLQuery muom = mqlLoad("uoms", "item");

    ParameterList params;
    params.append("uomtype", "Selling");
    params.append("item_id", pItemid);

    // Also have to factor UOMs previously used on Invoice now inactive
    if (_invcitemid != -1)
    {
      XSqlQuery invuom;
      invuom.prepare("SELECT invcitem_qty_uom_id, invcitem_price_uom_id "
                "  FROM invcitem"
                " WHERE(invcitem_id=:invcitem_id);");
      invuom.bindValue(":invcitem_id", _invcitemid);
      invuom.exec();
      if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting Invoice UOMs"),
                           invuom, __FILE__, __LINE__))
        return;
      else if (invuom.first())
      {
        params.append("uom_id", invuom.value("invcitem_qty_uom_id"));
        params.append("uom_id2", invuom.value("invcitem_price_uom_id"));
      }
    }
    XSqlQuery uom = muom.toQuery(params);
    if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting UOMs"),
                           uom, __FILE__, __LINE__))
      return;

    _qtyUOM->populate(uom);
    _pricingUOM->populate(uom);

    invoicePopulateItemInfo.prepare( "SELECT item_inv_uom_id, item_price_uom_id,"
               "       iteminvpricerat(item_id) AS invpricerat,"
               "       item_listprice, item_fractional, "
               "       stdcost(item_id) AS f_unitcost,"
               "       getItemTaxType(item_id, :taxzone) AS taxtype_id,"
               "       itemsite_costmethod"
               "  FROM item"
               "  JOIN itemsite ON (item_id=itemsite_item_id)"
               " WHERE ((item_id=:item_id)"
               "    AND (itemsite_warehous_id=:whsid));" );
    invoicePopulateItemInfo.bindValue(":item_id", pItemid);
    invoicePopulateItemInfo.bindValue(":taxzone", _taxzoneid);
    invoicePopulateItemInfo.bindValue(":whsid",   _warehouse->id());
    invoicePopulateItemInfo.exec();
    if (invoicePopulateItemInfo.first())
    {
      _priceRatioCache = invoicePopulateItemInfo.value("invpricerat").toDouble();
      _listPrice->setBaseValue(invoicePopulateItemInfo.value("item_listprice").toDouble());

      _invuomid = invoicePopulateItemInfo.value("item_inv_uom_id").toInt();
      _qtyUOM->setId(invoicePopulateItemInfo.value("item_inv_uom_id").toInt());
      _pricingUOM->setId(invoicePopulateItemInfo.value("item_price_uom_id").toInt());
      _qtyinvuomratio = 1.0;
      _priceinvuomratio = invoicePopulateItemInfo.value("invpricerat").toDouble();
      _unitCost->setBaseValue(invoicePopulateItemInfo.value("f_unitcost").toDouble());
      _taxtype->setId(invoicePopulateItemInfo.value("taxtype_id").toInt());
      if (invoicePopulateItemInfo.value("item_fractional").toBool())
      {
        _ordered->setValidator(omfgThis->qtyVal());
        _billed->setValidator(omfgThis->qtyVal());
      }
      else
      {
        _ordered->setValidator(new XDoubleValidator(0, 999999, 0, this));
        _billed->setValidator(new XDoubleValidator(0, 999999, 0, this));
      }
      sDeterminePrice();

      // TODO: should this check itemsite_controlmethod == N?
      _trackqoh = (invoicePopulateItemInfo.value("itemsite_costmethod").toString() != "J");
    }
    else if (invoicePopulateItemInfo.lastError().type() != QSqlError::NoError)
    {
      systemError(this, invoicePopulateItemInfo.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else
  {
    _priceRatioCache = 1.0;
    _qtyinvuomratio = 1.0;
    _priceinvuomratio = 1.0;
    _qtyUOM->clear();
    _pricingUOM->clear();
    _listPrice->clear();
    _unitCost->clear();
  }
}