コード例 #1
0
void reconcileBankaccount::sReconcile()
{
  XSqlQuery reconcileReconcile;
  if(_bankrecid == -1)
  {
    QMessageBox::critical( this, tr("Cannot Reconcile Account"),
      tr("<p>There was an error trying to reconcile this account. "
         "Please contact your Systems Administrator.") );
    return;
  }

  if (!_startDate->isValid())
  {
    QMessageBox::warning( this, tr("Missing Opening Date"),
      tr("<p>No Opening Date was specified for this reconciliation. Please specify an Opening Date.") );
    _startDate->setFocus();
    return;
  }

  if (!_endDate->isValid())
  {
    QMessageBox::warning( this, tr("Missing Ending Date"),
      tr("<p>No Ending Date was specified for this reconciliation. Please specify an Ending Date.") );
    _endDate->setFocus();
    return;
  }

  if (_endDate->date() < _startDate->date())
  {
    QMessageBox::warning( this, tr("Invalid End Date"),
                           tr("The end date cannot be earlier than the start date.") );
    _endDate->setFocus();
    return;
  }

  if(!_datesAreOK)
  {
    QMessageBox::critical( this, tr("Dates already reconciled"),
                tr("The date range you have entered already has "
                   "reconciled dates in it. Please choose a different "
                   "date range.") );
    _startDate->setFocus();
    _datesAreOK = false;
    return;
  }

  double begBal = _openBal->localValue();
  double endBal = _endBal->localValue();

  // calculate cleared balance
  MetaSQLQuery mbal = mqlLoad("bankrec", "clearedbalance");
  ParameterList params;
  params.append("bankaccntid", _bankaccnt->id());
  params.append("bankrecid", _bankrecid);
  params.append("endBal", endBal);
  params.append("begBal", begBal);
  params.append("curr_id",   _currency->id());
  params.append("effective", _startDate->date());
  params.append("expires",   _endDate->date());
  XSqlQuery bal = mbal.toQuery(params);
  if(!bal.first())
  {
    systemError(this, bal.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  if(bal.value("diff_value").toDouble() != 0.0)
  {
    QMessageBox::critical( this, tr("Balances Do Not Match"),
      tr("The cleared amounts do not balance with the specified\n"
         "beginning and ending balances.\n"
         "Please correct this before continuing.") );
    return;
  }

  if (! sSave(false))
    return;

  reconcileReconcile.prepare("SELECT postBankReconciliation(:bankrecid) AS result;");
  reconcileReconcile.bindValue(":bankrecid", _bankrecid);
  reconcileReconcile.exec();
  if (reconcileReconcile.first())
  {
    int result = reconcileReconcile.value("result").toInt();
    if (result < 0)
    {
      systemError(this, storedProcErrorLookup("postBankReconciliation", result),
		  __FILE__, __LINE__);
      return;
    }
    _bankrecid = -1;
    close();
  }
  else if (reconcileReconcile.lastError().type() != QSqlError::NoError)
  {
    systemError(this, reconcileReconcile.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
コード例 #2
0
enum SetResponse printShippingForm::set(const ParameterList &pParams)
{
  QVariant param;
  bool     valid;

  param = pParams.value("cosmisc_id", &valid);	// deprecated
  if (valid)
  {
    _shipment->setId(param.toInt());
    q.prepare( "SELECT cohead_id, cohead_shiptoname, cohead_shiptoaddress1, cosmisc_shipchrg_id,"
               "       COALESCE(cosmisc_shipform_id, cohead_shipform_id) AS shipform_id "
               "FROM cosmisc, cohead "
               "WHERE ( (cosmisc_cohead_id=cohead_id)"
               " AND (cosmisc_id=:cosmisc_id) );" );
    q.bindValue(":cosmisc_id", _shipment->id());
    q.exec();
    if (q.first())
    {
      _captive = TRUE;

      _so->setId(q.value("cohead_id").toInt());
      _so->setEnabled(FALSE);

      _shipToName->setText(q.value("cohead_shiptoname").toString());
      _shipToAddr1->setText(q.value("cohead_shiptoaddress1").toString());
      _shippingForm->setId(q.value("shipform_id").toInt());
      _shipchrg->setId(q.value("cosmisc_shipchrg_id").toInt());
    }
    else if (q.lastError().type() != QSqlError::None)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
    _print->setFocus();
  }

  param = pParams.value("shiphead_id", &valid);
  if (valid)
  {
    int orderid = -1;
    QString ordertype;

    _shipment->setId(param.toInt());
    q.prepare( "SELECT shiphead_order_id, shiphead_order_type,"
	       "       shiphead_shipchrg_id, shiphead_shipform_id "
	       "FROM shiphead "
	       "WHERE (shiphead_id=:shiphead_id);" );
    q.bindValue(":shiphead_id", _shipment->id());
    q.exec();
    if (q.first())
    {
      ordertype = q.value("shiphead_order_type").toString();
      orderid = q.value("shiphead_order_id").toInt();
      if (! q.value("shiphead_shipform_id").isNull())
	_shippingForm->setId(q.value("shiphead_shipform_id").toInt());
      _shipchrg->setId(q.value("shiphead_shipchrg_id").toInt());
    }
    else if (q.lastError().type() != QSqlError::None)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }

    ParameterList headp;
    if (ordertype == "SO")
    {
      headp.append("sohead_id", orderid);
      _to->setId(-1);
      _so->setId(orderid);
    }
    else if (ordertype == "TO")
    {
      headp.append("tohead_id", orderid);
      _so->setId(-1);
      _to->setId(orderid);
    }

    QString heads = "<? if exists(\"sohead_id\") ?>"
		  "SELECT cohead_id AS order_id, cohead_shiptoname AS shipto,"
		  "      cohead_shiptoaddress1 AS addr1,"
		  "      cohead_shipform_id AS shipform_id "
		  "FROM cohead "
		  "WHERE (cohead_id=<? value(\"sohead_id\") ?>);"
		  "<? elseif exists(\"tohead_id\") ?>"
		  "SELECT tohead_id AS order_id, tohead_destname AS shipto,"
		  "      tohead_destaddress1 AS addr1,"
		  "      tohead_shipform_id AS shipform_id "
		  "FROM tohead "
		  "WHERE (tohead_id=<? value(\"tohead_id\") ?>);"
		  "<? endif ?>"
		  ;
    MetaSQLQuery headm(heads);
    XSqlQuery headq = headm.toQuery(headp);
    if (headq.first())
    {
      _captive = TRUE;

      _shipToName->setText(headq.value("shipto").toString());
      _shipToAddr1->setText(headq.value("addr1").toString());
      if (_shippingForm->id() <= 0)
	_shippingForm->setId(headq.value("shipform_id").toInt());

      _so->setEnabled(false);
      _to->setEnabled(false);
    }
    else if (headq.lastError().type() != QSqlError::None)
    {
      systemError(this, headq.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
    _print->setFocus();
  }

  return NoError;
}
コード例 #3
0
void ItemLineEdit::setItemNumber(const QString& pNumber)
{
  if (DEBUG)
    qDebug("%s::setItemNumber(%s) entered",
           qPrintable(objectName()), qPrintable(pNumber));
  XSqlQuery item;
  bool      found = FALSE;

  _parsed = TRUE;

  if (pNumber == text())
    return;

  if (!pNumber.isEmpty())
  {
    if (_useValidationQuery)
    {
      item.prepare(_validationSql);
      item.bindValue(":item_number", pNumber);
      item.exec();
      if (item.first())
        found = TRUE;
    }
    else if (_useQuery)
    {
      item.prepare(_sql);
      item.exec();
      found = (item.findFirst("item_number", pNumber) != -1);
    }
    else if (pNumber != QString::Null())
    {
      QString pre( "SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2,"
                   "                uom_name, item_type, item_config, item_fractional, item_upccode");

      QStringList clauses;
      clauses = _extraClauses;
      clauses << "(item_number=:item_number OR item_upccode=:item_number)";

      item.prepare(buildItemLineEditQuery(pre, clauses, QString::null, _type, false));
      item.bindValue(":item_number", pNumber);
      item.exec();
      
      if (item.size() > 1)
      { 
        ParameterList params;
        params.append("search", pNumber);
        params.append("searchNumber");
        params.append("searchUpc");
        sSearch(params);
        return;
      }
      else
        found = item.first();
    }
  }
  if (found)
  {
    _itemNumber = pNumber;
    _uom        = item.value("uom_name").toString();
    _itemType   = item.value("item_type").toString();
    _configured = item.value("item_config").toBool();
    _fractional = item.value("item_fractional").toBool();
    _id         = item.value("item_id").toInt();
    _upc        = item.value("item_upccode").toInt();
    _valid      = TRUE;

    setText(item.value("item_number").toString());

    emit aliasChanged("");
    emit typeChanged(_itemType);
    emit descrip1Changed(item.value("item_descrip1").toString());
    emit descrip2Changed(item.value("item_descrip2").toString());
    emit uomChanged(item.value("uom_name").toString());
    emit configured(item.value("item_config").toBool());
    emit fractional(item.value("item_fractional").toBool());
    emit upcChanged(item.value("item_upccode").toString());
    
    emit valid(TRUE);
  }
  else
  {
    _itemNumber = "";
    _uom        = "";
    _itemType   = "";
    _id         = -1;
    _valid      = FALSE;
    _upc        = "";

    setText("");

    emit aliasChanged("");
    emit typeChanged("");
    emit descrip1Changed("");
    emit descrip2Changed("");
    emit uomChanged("");
    emit configured(FALSE);
    emit fractional(FALSE);
    emit upcChanged("");

    emit valid(FALSE);
  }
}
コード例 #4
0
void enterPoitemReceipt::populate()
{
  ParameterList params;

  if (_metrics->boolean("MultiWhs"))
    params.append("MultiWhs");

  // NOTE: this crashes if popm is defined and toQuery() is called outside the blocks
  if (_mode == cNew)
  {
    MetaSQLQuery popm = mqlLoad(":/sr/enterItemReceipt/PopulateNew.mql");

    params.append("ordertype",    _ordertype);
    params.append("orderitem_id", _orderitemid);

    q = popm.toQuery(params);
  }
  else if (_mode == cEdit)
  {
    MetaSQLQuery popm = mqlLoad(":/sr/enterItemReceipt/PopulateEdit.mql");
    params.append("recv_id", _recvid);
    q = popm.toQuery(params);
  }
  else
  {
    systemError(this, tr("<p>Incomplete Parameter List: "
			 "_orderitem_id=%1, _ordertype=%2, _mode=%3.")
                       .arg(_orderitemid)
                       .arg(_ordertype)
                       .arg(_mode) );
    return;
  }

  if (q.first())
  {
    _orderNumber->setText(q.value("order_number").toString());
    _lineNumber->setText(q.value("orderitem_linenumber").toString());
    _vendorItemNumber->setText(q.value("vend_item_number").toString());
    _vendorDescrip->setText(q.value("vend_item_descrip").toString());
    _vendorUOM->setText(q.value("vend_uom").toString());
    _invVendorUOMRatio->setText(q.value("f_venduomratio").toString());
    _dueDate->setDate(q.value("duedate").toDate());
    _ordered->setText(q.value("f_qtyordered").toString());
    _received->setText(q.value("f_qtyreceived").toString());
    _receivable = q.value("receivable").toDouble();
    _notes->setText(q.value("notes").toString());
    _receiptDate->setDate(q.value("effective").toDate());
    _freight->setId(q.value("curr_id").toInt());
    _freight->setLocalValue(q.value("recv_freight").toDouble());

    if (_ordertype.isEmpty())
      _ordertype = q.value("recv_order_type").toString();
    if (_ordertype == "PO")
      _orderType->setText(tr("P/O"));
    else if (_ordertype == "TO")
      _orderType->setText(tr("T/O"));
    else if (_ordertype == "RA")
      _orderType->setText(tr("R/A"));

    int itemsiteid = q.value("itemsiteid").toInt();
    if (itemsiteid > 0)
      _item->setItemsiteid(itemsiteid);
    _item->setEnabled(false);

    if (_mode == cNew)
      _toReceive->setText(q.value("f_qtytoreceive").toString());

    if (q.value("inventoryitem").toBool() && itemsiteid <= 0)
    {
      MetaSQLQuery ism = mqlLoad(":/sr/enterItemReceipt/GetSrcItemSite.mql");
      XSqlQuery isq = ism.toQuery(params);
      if (isq.first())
      {
        itemsiteid = itemSite::createItemSite(this,
                      isq.value("itemsite_id").toInt(),
                      isq.value("warehous_id").toInt(),
                      true);
        if (itemsiteid < 0)
          return;
        _item->setItemsiteid(itemsiteid);
      }
      else if (isq.lastError().type() != QSqlError::None)
      {
        systemError(this, isq.lastError().databaseText(), __FILE__, __LINE__);
        return;
      }
    }
  }
  else if (q.lastError().type() != QSqlError::None)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
コード例 #5
0
void OrderLineEdit::sParse()
{
  bool oldvalid = _valid;
  if (! _parsed)
  {
    QString stripped = text().stripWhiteSpace().upper();
    if (stripped.length() == 0)
    {
      _parsed = true;
      setId(-1);
    }
    else
    {
      QString oldExtraClause = _extraClause;

      XSqlQuery countQ;
      countQ.prepare("SELECT COUNT(*) AS count FROM orderhead WHERE (TRUE) " +
		      _numClause +
		      (_extraClause.isEmpty() || !_strict ? "" : " AND " + _extraClause) +
		      QString(";"));
      countQ.bindValue(":number", text());
      countQ.exec();
      if (countQ.first())
      {
	int result = countQ.value("count").toInt();
	if (result <= 0)
	{
	  _id = -1;
	  XLineEdit::clear();
	}
	else if (result == 1)
	{
	  XSqlQuery numQ;
	  numQ.prepare(_query + _numClause +
		      (_extraClause.isEmpty() || !_strict ? "" : " AND " + _extraClause) +
		      QString(";"));
	  numQ.bindValue(":number", text());
	  numQ.exec();
	  if (numQ.first())
	  {
	    _valid = true;
	    setId(numQ.value("id").toInt(), numQ.value("name").toString());
	    _description	= numQ.value("description").toString();
	    _from		= numQ.value("orderhead_from").toString();
	    _to		= numQ.value("orderhead_to").toString();
	  }
	  else if (numQ.lastError().type() != QSqlError::None)
	    QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
					  .arg(__FILE__)
					  .arg(__LINE__),
				  numQ.lastError().databaseText());
	}
	else
	{
	  _extraClause += "AND (orderhead_number=" + text() + ")";
	  sEllipses();
	  _extraClause += "AND (orderhead_type='" + type() + "')";
	}
      }
      else if (countQ.lastError().type() != QSqlError::None)
      {
	QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
				      .arg(__FILE__)
				      .arg(__LINE__),
			      countQ.lastError().databaseText());
      }

      _extraClause = oldExtraClause;
    }
  }

  _parsed = true;
  if (_valid != oldvalid)
    emit valid(_valid);
  emit parsed();
  emit numberChanged(text(), _name);
}
コード例 #6
0
void printPackingListBatchByShipvia::sPrint()
{
  QPrinter printer(QPrinter::HighResolution);
  bool     setupPrinter = TRUE;

  XSqlQuery prtd;
  QString prts("UPDATE pack SET pack_printed=TRUE"
               " WHERE ((pack_head_id=<? value(\"head_id\") ?>) "
	       "   AND  (pack_head_type=<? value(\"head_type\") ?>)"
	       "<? if exists(\"shiphead_id\") ?>"
	       "   AND  (pack_shiphead_id=<? value(\"shiphead_id\") ?>)"
	       "<? else ?>"
	       "   AND (pack_shiphead_id IS NULL)"
	       "<? endif ?>"
	       ");" );


  XSqlQuery packq;
  ParameterList params;
  if (_metrics->boolean("MultiWhs"))
    params.append("MultiWhs");
  params.append("shipvia", _shipvia->currentText());
  MetaSQLQuery packm = mqlLoad(":/sr/forms/printPackingListBatchByShipvia/ToPrint.mql");
  packq = packm.toQuery(params);
  if (packq.lastError().type() != QSqlError::None)
  {
    systemError(this, packq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  bool userCanceled = false;
  if (orReport::beginMultiPrint(&printer, userCanceled) == false)
  {
    if(!userCanceled)
      systemError(this, tr("Could not initialize printing system for multiple reports."));
    return;
  }
  while (packq.next())
  {
    // leave sohead_id and cosmisc_id for compatibility with existing reports
    ParameterList params;
    params.append("head_id",   packq.value("pack_head_id").toInt());
    params.append("head_type", packq.value("pack_head_type").toString());
    if (packq.value("pack_head_type").toString() == "SO")
      params.append("sohead_id", packq.value("pack_head_id").toInt());
    else if (packq.value("pack_head_type").toString() == "TO")
      params.append("tohead_id", packq.value("pack_head_id").toInt());
    if (! packq.value("pack_shiphead_id").isNull())
    {
      params.append("cosmisc_id", packq.value("pack_shiphead_id").toInt());
      params.append("shiphead_id",  packq.value("pack_shiphead_id").toInt());
    }
    if (_metrics->boolean("MultiWhs"))
      params.append("MultiWhs");

    orReport report(packq.value( packq.value("pack_shiphead_id").isNull() ?
			      "pickform" : "packform").toString(), params);
    if (report.isValid())
    {
      if (report.print(&printer, setupPrinter))
        setupPrinter = FALSE;
      else
      {
	orReport::endMultiPrint(&printer);
        return;
      }
    }
    else
    {
      report.reportError(this);
      orReport::endMultiPrint(&printer);
      return;
    }

    MetaSQLQuery mql(prts);
    prtd = mql.toQuery(params);
    if (prtd.lastError().type() != QSqlError::None)
    {
      systemError(this, prtd.lastError().databaseText(), __FILE__, __LINE__);
      orReport::endMultiPrint(&printer);
      return;
    }

  }
  orReport::endMultiPrint(&printer);
}
コード例 #7
0
ファイル: shipTo.cpp プロジェクト: dwatson78/qt-client
void shipTo::sPopulateNumber()
{
  if (_shipToNumber->text().trimmed().length() == 0)
  {
    XSqlQuery nextnumq;
    nextnumq.prepare( "SELECT (COALESCE(MAX(CAST(shipto_num AS INTEGER)), 0) + 1) AS n_shipto_num "
                      "  FROM shiptoinfo "
                      " WHERE ((shipto_cust_id=:cust_id)"
                      "   AND  (shipto_num~'^[0-9]*$') )" );
    nextnumq.bindValue(":cust_id", _custid);
    nextnumq.exec();
    if (nextnumq.first())
      _shipToNumber->setText(nextnumq.value("n_shipto_num"));
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Ship To Information"),
                                  nextnumq, __FILE__, __LINE__))
    {
      return;
    }
  }
  else
  {
    XSqlQuery dupnumq;
    dupnumq.prepare( "SELECT shipto_id "
                     "FROM shiptoinfo "
                     "WHERE ( (shipto_cust_id=:cust_id)"
                     " AND (UPPER(shipto_num)=UPPER(:shipto_num))"
                     " AND (shipto_id != :shipto_id));" );
    dupnumq.bindValue(":cust_id", _custid);
    dupnumq.bindValue(":shipto_num", _shipToNumber->text().trimmed());
    dupnumq.bindValue(":shipto_id", _shiptoid);
    dupnumq.exec();
    if (dupnumq.first())
    {
      if (_mode == cNew && _shiptoid != -1)
      {
        XSqlQuery delnumq;
        delnumq.prepare( "DELETE FROM shiptoinfo "
                         "WHERE (shipto_id=:shipto_id);" );
        delnumq.bindValue(":shipto_id", _shiptoid);
        delnumq.exec();
      }
      _mode = cEdit;
      _shiptoid = dupnumq.value("shipto_id").toInt();
      populate();

      _shipToNumber->setEnabled(false);
      _name->setFocus();
    }
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Ship To Information"),
                                  dupnumq, __FILE__, __LINE__))
    {
      return;
    }
  }

  if (_mode == cNew && _shiptoid == -1)
  {
    XSqlQuery newnumq;
    newnumq.prepare( "INSERT INTO shiptoinfo "
                     "( shipto_cust_id, shipto_active, shipto_num, shipto_commission ) "
                     "VALUES "
                     "( :shipto_cust_id, :shipto_active, :shipto_num, :shipto_commission ) "
                     "RETURNING shipto_id;");

    newnumq.bindValue(":shipto_active", QVariant(_active->isChecked()));
    newnumq.bindValue(":shipto_cust_id", _custid);
    newnumq.bindValue(":shipto_num", _shipToNumber->text().trimmed());
    newnumq.bindValue(":shipto_commission", (_commission->toDouble() / 100));
    newnumq.exec();
    if (newnumq.first())
      _shiptoid = newnumq.value("shipto_id").toInt();
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Ship To Information"),
                                  newnumq, __FILE__, __LINE__))
    {
      return;
    }
  }
  _documents->setId(_shiptoid);
  _save->setEnabled(true);
}
コード例 #8
0
/*
    Make sure the row is internally consistent. If so then fix it so the
    parent class has a valid row to insert (some of the SELECTed columns
    shouldn't be directly modified in the db 'cause they're not part of the
    model's current table).
*/
bool PoitemTableModel::validRow(QSqlRecord& record)
{
  QString errormsg;
  QString warningmsg;

  // TODO: what is a better way to decide if this is an inventory item or not?
  bool inventoryItem = ! record.value("item_number").toString().isEmpty();

  if (! inventoryItem &&
      record.value("poitem_expcat_id").toInt() < 0)
    errormsg = tr("<p>You must specify an Expense Category for this "
		  "non-Inventory Item before you may save it.");

  else if (inventoryItem &&
	   record.value("item_number").toString().isEmpty())
    errormsg = tr("<p>You must select an Item Number before you may save.");

  else if (inventoryItem &&
	   record.value("warehous_id").toInt() <= 0)
    errormsg = tr("<p>You must select a Supplying Site before you may save.");

  else if (record.value("poitem_qty_ordered").toDouble() <= 0)
    errormsg = tr("<p>You must enter a quantity before you may save this "
		  "Purchase Order Item.");

  else if (record.value("itemsrc_minordqty").toDouble() > 0 &&
	   record.value("poitem_qty_ordered").toDouble() < record.value("itemsrc_minordqty").toDouble())
    warningmsg = tr("<p>The quantity that you are ordering is below the "
		    "Minimum Order Quantity for this Item Source.  You may "
		    "continue but this Vendor may not honor pricing or "
		    "delivery quotations. ");

  else if (record.value("itemsrc_multordqty").toDouble() > 0 &&
	   record.value("poitem_qty_ordered").toInt() % (int)(record.value("itemsrc_multordqty").toDouble()))
    warningmsg = tr("<p>The quantity that you are ordering does not fall "
		    "within the Order Multiple for this Item Source.  You may "
		    "continue but this Vendor may not honor pricing or "
		    "delivery quotations.");

  else if (! record.value("poitem_duedate").toDate().isValid())
    errormsg = tr("<p>You must enter a due date.");

  else if (record.value("earliestDate").toDate().isValid() &&
	   record.value("poitem_duedate").toDate() < record.value("earliestDate").toDate())
    warningmsg = tr("<p>The Due Date that you are requesting does not fall "
		    "within the Lead Time Days for this Item Source.  You may "
		    "continue but this Vendor may not honor pricing or "
		    "delivery quotations or may not be able to deliver by the "
		    "requested Due Date.");

  else if (record.value("poitem_pohead_id").toInt() <= 0 &&
	   _poheadid <= 0)
    errormsg = tr("<p>There is no Purchase Order header yet. "
	     "Try entering a Vendor if you are using the Purchase Order "
	     "window.");

  else if (inventoryItem &&
	   record.value("item_id").toInt() > 0 &&
	   record.value("warehous_id").toInt() > 0)
  {
    XSqlQuery isq;
    isq.prepare("SELECT itemsite_id, item_id "
		"FROM itemsite, item "
		"WHERE ((itemsite_item_id=item_id)"
		"  AND  (itemsite_warehous_id=:whs_id)"
		"  AND  (item_id=:item_id));");
    isq.bindValue(":whs_id", record.value("warehous_id").toInt());
    isq.bindValue(":item_id", record.value("item_id").toInt());
    isq.exec();
    if (isq.first())
    {
      int itemsiteid = isq.value("itemsite_id").toInt();
      if (itemsiteid != record.value("poitem_itemsite_id").toInt())
	record.setValue("poitem_itemsite_id", itemsiteid);
    }
    else if (isq.lastError().type() != QSqlError::NoError)
      errormsg = isq.lastError().databaseText();
    else
      errormsg = tr("<p>There is no Item Site for this Site (%1) and "
	       "Item Number (%2).")
	       .arg(record.value("warehous_code").toInt())
	       .arg(record.value("item_number").toString());
  }

  int index = record.indexOf("poitem_pohead_id");
  if (index < 0)
  {
    QSqlField field("poitem_pohead_id", QVariant::Int);
    field.setValue(_poheadid);
    record.append(field);
  }
  else
    record.setValue(index, _poheadid);

  XSqlQuery ln;
  /*
  ln.prepare("SELECT MAX(poitem_linenumber) + 1 AS newln "
	     "FROM poitem "
	     "WHERE (poitem_pohead_id=:pohead_id);");
             */
  // get the smallest available line number
  ln.prepare("SELECT MIN(sequence_value) AS newln "
             "FROM sequence "
             "WHERE sequence_value NOT IN (SELECT poitem_linenumber "
             "                             FROM poitem"
             "                             WHERE (poitem_pohead_id=:pohead_id));");
  ln.bindValue(":pohead_id", _poheadid);
  if (record.indexOf("poitem_linenumber") < 0)
  {
    ln.exec();
    if (ln.first())
    {
      QSqlField field("poitem_linenumber", QVariant::Int);
      field.setValue(ln.value("newln"));
      record.append(field);
    }
    else if (ln.lastError().type() != QSqlError::NoError)
    {
      errormsg = ln.lastError().databaseText();
    }
  }
  else if (record.value("poitem_linenumber").toInt() <= 0)
  {
    ln.exec();
    if (ln.first())
      record.setValue("poitem_linenumber", ln.value("newln"));
    else if (ln.lastError().type() != QSqlError::NoError)
    {
      errormsg = ln.lastError().databaseText();
    }
  }

  if (record.value("poitem_id").isNull())
  {
    XSqlQuery idq("SELECT NEXTVAL('poitem_poitem_id_seq') AS poitem_id;");
    if (idq.first())
      record.setValue("poitem_id", idq.value("poitem_id"));
    else
    {
      errormsg = idq.lastError().databaseText();
    }
  }

  if (_postatus.isEmpty())
    findHeadData();

  index = record.indexOf("poitem_status");
  if (index < 0)
  {
    QSqlField field("poitem_status", QVariant::String);
    field.setValue(_postatus);
    record.append(field);
  }
  else if (record.field(index).value().toString().isEmpty())
    record.setValue(index, _postatus);

  if (record.field("poitem_invvenduomratio").value().isNull() &&
      record.field("itemsrc_invvendoruomratio").value().isNull())
    record.setValue("poitem_invvenduomratio", 1);
  else if (record.field("poitem_invvenduomratio").value().isNull())
    record.setValue("poitem_invvenduomratio", record.value("itemsrc_invvendoruomratio"));

  if (! errormsg.isEmpty())
  {
    setLastError(QSqlError(QString("PoitemTableModel::validRow() error"),
			   errormsg, QSqlError::UnknownError));
    return false;
  }
  else if (! warningmsg.isEmpty())
  {
    if (QMessageBox::question(0, tr("Are you sure you want to continue?"),
		    warningmsg + tr("<p>Do you wish to Save this Order?"),
		    QMessageBox::Yes,
		    QMessageBox::No | QMessageBox::Default) == QMessageBox::No)
    return false;
  }

  record.remove(record.indexOf("earliestdate"));
  record.remove(record.indexOf("itemsrc_invvendoruomratio"));
  record.remove(record.indexOf("itemsrc_multordqty"));
  record.remove(record.indexOf("itemsrc_minordqty"));
  record.remove(record.indexOf("expcat_code"));
  record.remove(record.indexOf("prj_number"));
  record.remove(record.indexOf("extprice"));
  record.remove(record.indexOf("warehous_code"));
  record.remove(record.indexOf("warehous_id"));
  record.remove(record.indexOf("item_number"));
  record.remove(record.indexOf("item_id"));
  record.remove(record.indexOf("pohead_number"));

  return true;
}
コード例 #9
0
void PoitemTableModel::findHeadData()
{
  _poheadcurrid = CurrDisplay::baseId();
  _poheaddate	= QDate();
  _postatus	= "U";	// safest default
  _vendid	= -1;
  _vendrestrictpurch = false;

  XSqlQuery poheadq;
  XSqlQuery vendq;
  if (_poheadid > 0)
  {
    poheadq.prepare("SELECT pohead_id, pohead_curr_id, pohead_orderdate,"
		    "       pohead_status "
		    "FROM pohead "
		    "WHERE (pohead_id=:pohead_id);");
    poheadq.bindValue(":pohead_id", _poheadid);
    vendq.prepare("SELECT vend_id, vend_restrictpurch "
		  "FROM vend, pohead "
		  "WHERE ((vend_id=pohead_vend_id)"
		  "  AND  (pohead_id=:id));");
    vendq.bindValue(":id", _poheadid);
  }
  else if (_poheadid > 0)
  {
    poheadq.prepare("SELECT pohead_id, pohead_curr_id, pohead_orderdate,"
		    "       pohead_status "
		    "FROM pohead "
		    "WHERE pohead_id IN (SELECT poitem_pohead_id "
		    "                    FROM poitem WHERE poitem_id=:poitem_id);");
    poheadq.bindValue(":poitem_id", _poitemid);
    vendq.prepare("SELECT vend_id, vend_restrictpurch "
		  "FROM vend, pohead, poitem "
		  "WHERE ((vend_id=pohead_vend_id)"
		  "  AND  (pohead_id=poitem_pohead_id)"
		  "  AND  (poitem_id=:id));");
    vendq.bindValue(":id", _poitemid);
  }
  else
    return;

  poheadq.exec();
  if (poheadq.first())
  {
    _poheadcurrid = poheadq.value("pohead_curr_id").toInt();
    _poheaddate   = poheadq.value("pohead_orderdate").toDate();
    _postatus	  = poheadq.value("pohead_status").toString();
  }
  else if (poheadq.lastError().type() != QSqlError::NoError)
  {
    systemError(0, poheadq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  vendq.exec();
  if (vendq.first())
  {
    _vendid		= vendq.value("vend_id").toInt();
    _vendrestrictpurch	= vendq.value("vend_restrictpurch").toBool();
  }
  else if (vendq.lastError().type() != QSqlError::NoError)
  {
    systemError(0, vendq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
コード例 #10
0
void todoList::sDelete()
{
  QString recurstr;
  QString recurtype;
  if (list()->altId() == 1)
  {
    recurstr = "SELECT MAX(todoitem_due_date) AS max"
               "  FROM todoitem"
               " WHERE todoitem_recurring_todoitem_id=:id"
               "   AND todoitem_id!=:id;" ;
    recurtype = "TODO";
  }
  /* TODO: can't delete incidents from here. why not?
  else if (list()->altId() == 2)
  {
    recurstr = "SELECT MAX(incdt_timestamp) AS max"
               "   FROM incdt"
               " WHERE incdt_recurring_incdt_id=:id;" ;
    recurtype = "INCDT";
  }
   */

  bool deleteAll  = false;
  bool createMore = false;
  if (! recurstr.isEmpty())
  {
    XSqlQuery recurq;
    recurq.prepare(recurstr);
    recurq.bindValue(":id", list()->id());
    recurq.exec();
    if (recurq.first() && !recurq.value("max").isNull())
    {
      QMessageBox askdelete(QMessageBox::Question, tr("Delete Recurring Item?"),
                            tr("<p>This is a recurring item. Do you want to "
                               "delete just this one item or delete all open "
                               "items in this recurrence?"),
                            QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::Cancel,
                            this);
      askdelete.setDefaultButton(QMessageBox::Cancel);
      int ret = askdelete.exec();
      if (ret == QMessageBox::Cancel)
        return;
      else if (ret == QMessageBox::YesToAll)
        deleteAll = true;
      // user said delete one but the only one that exists is the base
      else if (ret == QMessageBox::Yes && recurq.value("max").isNull())
        createMore = true;
    }
    else if (recurq.lastError().type() != QSqlError::NoError)
    {
      systemError(this, recurq.lastError().text(), __FILE__, __LINE__);
      return;
    }
    else if (QMessageBox::warning(this, tr("Delete List Item?"),
                                  tr("<p>Are you sure that you want to "
                                     "completely delete the selected item?"),
	  		    QMessageBox::Yes | QMessageBox::No,
			    QMessageBox::No) == QMessageBox::No)
      return;
  }
  else if (QMessageBox::warning(this, tr("Delete List Item?"),
                                tr("<p>Are you sure that you want to "
                                   "completely delete the selected item?"),
	  		    QMessageBox::Yes | QMessageBox::No,
			    QMessageBox::No) == QMessageBox::No)
    return;

  QString procname;
  int procresult = 0;
  if (deleteAll)
  {
    procname = "deleteOpenRecurringItems";
    q.prepare("SELECT deleteOpenRecurringItems(:id, :type, NULL, TRUE)"
              "       AS result;");
    q.bindValue(":id",   list()->id());
    q.bindValue(":type", recurtype);
    q.exec();
    if (q.first())
      procresult = q.value("result").toInt();
  }
  if (procresult >= 0 && createMore)
  {
    procname = "createRecurringItems";
    q.prepare("SELECT createRecurringItems(:id, :type) AS result;");
    q.bindValue(":id",   list()->id());
    q.bindValue(":type", recurtype);
    q.exec();
    if (q.first())
      procresult = q.value("result").toInt();
  }

  // not elseif - error handling for 1 or 2 queries
  if (procresult < 0)
  {
    systemError(this, storedProcErrorLookup(procname, procresult));
    return;
  }
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  if (list()->altId() == 1)
    q.prepare("SELECT deleteTodoItem(:todoitem_id) AS result;");
  else if (list()->altId() == 3)
    q.prepare("DELETE FROM prjtask"
              " WHERE (prjtask_id=:todoitem_id); ");
  else if (list()->altId() == 4)
    q.prepare("SELECT deleteProject(:todoitem_id) AS result");
  else
    return;
  q.bindValue(":todoitem_id", list()->id());
  q.exec();
  if (q.first())
  {
    int result = q.value("result").toInt();
    if (result < 0)
    {
      systemError(this, storedProcErrorLookup("deleteTodoItem", result));
      return;
    }
  }
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  sFillList();
}
コード例 #11
0
ファイル: returnAuthCheck.cpp プロジェクト: AlFoX/qt-client
void returnAuthCheck::sSave()
{
  XSqlQuery returnSave;
  if (!_date->isValid())
  {
    QMessageBox::warning( this, tr("Cannot Create Miscellaneous Check"),
                          tr("<p>You must enter a date for this check.") );
    _date->setFocus();
    return;
  }

  else if (_amount->isZero())
  {
    QMessageBox::warning( this, tr("Cannot Create Miscellaneous Check"),
                          tr("<p>You must enter an amount for this check.") );
    return;
  }

  else if (!_bankaccnt->isValid())
  {
    QMessageBox::warning( this, tr("Cannot Create Miscellaneous Check"),
                          tr("<p>You must select a bank account for this check.") );
    _date->setFocus();
    return;
  }

  else
  {
    returnSave.prepare("SELECT createCheck(:bankaccnt_id, 'C', :recipid,"
	      "                   :checkDate, :amount, :curr_id, NULL,"
	      "                   NULL, :for, :notes, TRUE, :aropen_id) AS result; ");
    returnSave.bindValue(":bankaccnt_id", _bankaccnt->id());
    returnSave.bindValue(":recipid",	_custid);
    returnSave.bindValue(":checkDate", _date->date());
    returnSave.bindValue(":amount",	_amount->localValue());
    returnSave.bindValue(":curr_id",	_amount->id());
    returnSave.bindValue(":for",	_for->text().trimmed());
    returnSave.bindValue(":notes", _notes->toPlainText().trimmed());
	returnSave.bindValue(":aropen_id", _aropenid);
	returnSave.exec();
    if (returnSave.first())
    {
      _checkid = returnSave.value("result").toInt();
      if (_checkid < 0)
      {
        systemError(this, storedProcErrorLookup("createCheck", _checkid),
		    __FILE__, __LINE__);
        return;
      }
      returnSave.prepare( "SELECT checkhead_number "
               "FROM checkhead "
               "WHERE (checkhead_id=:check_id);" );
      returnSave.bindValue(":check_id", _checkid);
      returnSave.exec();
      if (returnSave.lastError().type() != QSqlError::NoError)
      {
        systemError(this, returnSave.lastError().databaseText(), __FILE__, __LINE__);
        return;
      }
	  done(TRUE);
	}
    else if (returnSave.lastError().type() != QSqlError::NoError)
    {
     systemError(this, returnSave.lastError().databaseText(), __FILE__, __LINE__);
        return;
    }
  }
}
コード例 #12
0
void reconcileBankaccount::sBankaccntChanged()
{
  XSqlQuery reconcileBankaccntChanged;
  if(_bankrecid != -1)
  {
    reconcileBankaccntChanged.prepare("SELECT count(*) AS num"
	          "  FROM bankrecitem"
	          " WHERE (bankrecitem_bankrec_id=:bankrecid); ");
    reconcileBankaccntChanged.bindValue(":bankrecid", _bankrecid);
    reconcileBankaccntChanged.exec();
    if (reconcileBankaccntChanged.first() && reconcileBankaccntChanged.value("num").toInt() > 0)
    {
      if (QMessageBox::question(this, tr("Save Bank Reconciliation?"),
				                      tr("<p>Do you want to save this Bank Reconciliation?"),
				                QMessageBox::No,
				                QMessageBox::Yes | QMessageBox::Default) == QMessageBox::Yes)
      {
	    sSave(false);
      }
      else
	  {
        reconcileBankaccntChanged.prepare( "SELECT deleteBankReconciliation(:bankrecid) AS result;" );
        reconcileBankaccntChanged.bindValue(":bankrecid", _bankrecid);
        reconcileBankaccntChanged.exec();
        if (reconcileBankaccntChanged.first())
        {
	      int result = reconcileBankaccntChanged.value("result").toInt();
	      if (result < 0)
	      {
	        systemError(this, storedProcErrorLookup("deleteBankReconciliation", result),
		                __FILE__, __LINE__);
	        return;
	      }
        }
        else if (reconcileBankaccntChanged.lastError().type() != QSqlError::NoError)
        {
	      systemError(this, reconcileBankaccntChanged.lastError().databaseText(), __FILE__, __LINE__);
	      return;
        }
      }
	}
  }

  _bankaccntid = _bankaccnt->id();
  XSqlQuery accntq;
  accntq.prepare("SELECT bankaccnt_curr_id "
            "FROM bankaccnt WHERE bankaccnt_id = :accntId;");
  accntq.bindValue(":accntId", _bankaccnt->id());
  accntq.exec();
  if (accntq.first())
    _currency->setId(accntq.value("bankaccnt_curr_id").toInt());
  else if (accntq.lastError().type() != QSqlError::NoError)
  {
    systemError(this, accntq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  accntq.prepare("SELECT * FROM bankrec "
		 "WHERE ((bankrec_bankaccnt_id=:accntId)"
		 "  AND  (NOT bankrec_posted));");
  accntq.bindValue(":accntId", _bankaccnt->id());
  accntq.exec();
  if (accntq.first())
  {
    _bankrecid = accntq.value("bankrec_id").toInt();
    _startDate->setDate(accntq.value("bankrec_opendate").toDate(), true);
    _endDate->setDate(accntq.value("bankrec_enddate").toDate(), true);
    _openBal->setLocalValue(accntq.value("bankrec_openbal").toDouble());
    _endBal->setLocalValue(accntq.value("bankrec_endbal").toDouble());
  }
  else if (accntq.lastError().type() != QSqlError::NoError)
  {
    systemError(this, accntq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  else
  {
    accntq.prepare("SELECT NEXTVAL('bankrec_bankrec_id_seq') AS bankrec_id");
    accntq.exec();
    if (accntq.first())
      _bankrecid = accntq.value("bankrec_id").toInt();
    else if (accntq.lastError().type() != QSqlError::NoError)
    {
      systemError(this, accntq.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
    
    accntq.prepare("SELECT bankrec_enddate + 1 AS startdate, "
                   " bankrec_endbal AS openbal "
                   "FROM bankrec "
                   "WHERE (bankrec_bankaccnt_id=:accntId) "
                   "ORDER BY bankrec_enddate DESC "
                   "LIMIT 1");
    accntq.bindValue(":accntId", _bankaccnt->id());
    accntq.exec();
    if (accntq.first())
    {
      _startDate->setDate(accntq.value("startdate").toDate());
      _openBal->setLocalValue(accntq.value("openbal").toDouble());
    }
    else
    {
      _startDate->clear();
      _openBal->clear();
    }
    if (accntq.lastError().type() != QSqlError::NoError)
    {
      systemError(this, accntq.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }

  populate();
}
コード例 #13
0
void reconcileBankaccount::sReceiptsToggleCleared()
{
  XSqlQuery reconcileReceiptsToggleCleared;
  XTreeWidgetItem *item = (XTreeWidgetItem*)_receipts->currentItem();
  XTreeWidgetItem *child = 0;
  bool setto = true;

  if(0 == item)
    return;

  _receipts->scrollToItem(item);

  if(item->altId() == 9)
  {
    setto = item->text(0) == tr("No");
    for (int i = 0; i < item->childCount(); i++)
    {
      child = item->child(i);
      if(child->text(0) != (setto ? tr("Yes") : tr("No")))
      {
        double rate = QLocale().toDouble(child->text(6));
        double baseamount = QLocale().toDouble(child->text(7));
        double amount = QLocale().toDouble(child->text(8));

        if (_allowEdit->isChecked() && child->text(0) != tr("Yes"))
        {
          ParameterList params;
          params.append("transtype", "receipt");
          params.append("bankaccntid", _bankaccnt->id());
          params.append("bankrecid", _bankrecid);
          params.append("sourceid", child->id());
          if(child->altId()==1)
            params.append("source", "GL");
          else if(child->altId()==2)
            params.append("source", "SL");
          else if(child->altId()==3)
            params.append("source", "AD");
          toggleBankrecCleared newdlg(this, "", TRUE);
          newdlg.set(params);
          newdlg.exec();
        }
        else
        {
          reconcileReceiptsToggleCleared.prepare("SELECT toggleBankrecCleared(:bankrecid, :source, :sourceid, :currrate, :amount) AS cleared");
          reconcileReceiptsToggleCleared.bindValue(":bankrecid", _bankrecid);
          reconcileReceiptsToggleCleared.bindValue(":sourceid", child->id());
          if(child->altId()==1)
            reconcileReceiptsToggleCleared.bindValue(":source", "GL");
          else if(child->altId()==2)
            reconcileReceiptsToggleCleared.bindValue(":source", "SL");
          else if(child->altId()==3)
            reconcileReceiptsToggleCleared.bindValue(":source", "AD");
          reconcileReceiptsToggleCleared.bindValue(":currrate", rate);
          reconcileReceiptsToggleCleared.bindValue(":amount", amount);
          reconcileReceiptsToggleCleared.exec();
          if(reconcileReceiptsToggleCleared.first())
            child->setText(0, (reconcileReceiptsToggleCleared.value("cleared").toBool() ? tr("Yes") : tr("No") ));
          else if (reconcileReceiptsToggleCleared.lastError().type() != QSqlError::NoError)
          {
            systemError(this, reconcileReceiptsToggleCleared.lastError().databaseText(), __FILE__, __LINE__);
            return;
          }
        }
      }
    }
    item->setText(0, (setto ? tr("Yes") : tr("No")));
    populate();
  }
  else
  {
    double rate = QLocale().toDouble(item->text(6));
    double baseamount = QLocale().toDouble(item->text(7));
    double amount = QLocale().toDouble(item->text(8));
    
    if (_allowEdit->isChecked() && item->text(0) != tr("Yes"))
    {
      ParameterList params;
      params.append("transtype", "receipt");
      params.append("bankaccntid", _bankaccnt->id());
      params.append("bankrecid", _bankrecid);
      params.append("sourceid", item->id());
      if(item->altId()==1)
        params.append("source", "GL");
      else if(item->altId()==2)
        params.append("source", "SL");
      else if(item->altId()==3)
        params.append("source", "AD");
      toggleBankrecCleared newdlg(this, "", TRUE);
      newdlg.set(params);
      newdlg.exec();
      populate();
    }
    else
    {
      reconcileReceiptsToggleCleared.prepare("SELECT toggleBankrecCleared(:bankrecid, :source, :sourceid, :currrate, :amount) AS cleared");
      reconcileReceiptsToggleCleared.bindValue(":bankrecid", _bankrecid);
      reconcileReceiptsToggleCleared.bindValue(":sourceid", item->id());
      if(item->altId()==1)
        reconcileReceiptsToggleCleared.bindValue(":source", "GL");
      else if(item->altId()==2)
        reconcileReceiptsToggleCleared.bindValue(":source", "SL");
      else if(item->altId()==3)
        reconcileReceiptsToggleCleared.bindValue(":source", "AD");
      reconcileReceiptsToggleCleared.bindValue(":currrate", rate);
      reconcileReceiptsToggleCleared.bindValue(":amount", amount);
      reconcileReceiptsToggleCleared.exec();
      if(reconcileReceiptsToggleCleared.first())
      {
        item->setText(0, (reconcileReceiptsToggleCleared.value("cleared").toBool() ? tr("Yes") : tr("No") ));

        item = (XTreeWidgetItem*)item->QTreeWidgetItem::parent();
        if(item != 0 && item->altId() == 9)
        {
          setto = true;
          for (int i = 0; i < item->childCount(); i++)
          {
            setto = (setto && (item->child(i)->text(0) == tr("Yes")));
          }
          item->setText(0, (setto ? tr("Yes") : tr("No")));
        }
      }
      else
      {
        populate();
        if (reconcileReceiptsToggleCleared.lastError().type() != QSqlError::NoError)
        {
          systemError(this, reconcileReceiptsToggleCleared.lastError().databaseText(), __FILE__, __LINE__);
          return;
        }
      }
    }
  }
}
コード例 #14
0
/* 
   Note that the SELECTs here are UNIONs of the gltrans table (in the base
   currency), sltrans table (in the base currency) and the bankadj table
   (in the bank account's currency).
*/
void reconcileBankaccount::populate()
{
  qApp->setOverrideCursor(QCursor(Qt::WaitCursor));

  double begBal = _openBal->localValue();
  double endBal = _endBal->localValue();

  int currid = -1;

  ParameterList params;
  params.append("bankaccntid", _bankaccnt->id());
  params.append("bankrecid", _bankrecid);

  // fill receipts list
  currid = _receipts->id();
  _receipts->clear();
  MetaSQLQuery mrcp = mqlLoad("bankrec", "receipts");
  XSqlQuery rcp = mrcp.toQuery(params);
  if (rcp.lastError().type() != QSqlError::NoError)
  {
    systemError(this, rcp.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  int jrnlnum = 0;
  XTreeWidgetItem * parent = 0;
  XTreeWidgetItem * lastChild = 0;
  XTreeWidgetItem * last = 0;
  bool cleared = TRUE;
  double amount = 0.0;
  bool amountNull = true;
  while (rcp.next())
  {
    if(rcp.value("use").toString() == "C/R")
    {
      if(rcp.value("jrnlnum").toInt() != jrnlnum || (0 == parent))
      {
        if(parent != 0)
        {
          parent->setText(0, (cleared ? tr("Yes") : tr("No")));
          parent->setText(8, amountNull ? tr("?????") : formatMoney(amount));
        }
        jrnlnum = rcp.value("jrnlnum").toInt();
        last = new XTreeWidgetItem( _receipts, last,
          jrnlnum, 9, "", formatDate(rcp.value("f_jrnldate").toDate()), tr("JS"), rcp.value("jrnlnum"));
        parent = last;
        cleared = true;
        amount = 0.0;
	amountNull = true;
        lastChild = 0;
      }
      cleared = (cleared && rcp.value("cleared").toBool());
      amount += rcp.value("amount").toDouble();
      amountNull = rcp.value("amount").isNull();
      
      lastChild = new XTreeWidgetItem( parent, lastChild,
        rcp.value("id").toInt(), rcp.value("altid").toInt(),
        (rcp.value("cleared").toBool() ? tr("Yes") : tr("No")),
        formatDate(rcp.value("f_date").toDate()), rcp.value("doc_type"), rcp.value("docnumber"),
        rcp.value("notes"),
        rcp.value("doc_curr"),
        rcp.value("doc_exchrate").isNull() ? tr("?????") : formatUOMRatio(rcp.value("doc_exchrate").toDouble()),
        rcp.value("base_amount").isNull() ? tr("?????") : formatMoney(rcp.value("base_amount").toDouble()),
        rcp.value("amount").isNull() ? tr("?????") : formatMoney(rcp.value("amount").toDouble()) );
    }
    else
    {
      if(parent != 0)
      {
        parent->setText(0, (cleared ? tr("Yes") : tr("No")));
        parent->setText(8, formatMoney(amount));
      }
      parent = 0;
      cleared = true;
      amount = 0.0;
      amountNull = true;
      lastChild = 0;
      last = new XTreeWidgetItem( _receipts, last,
        rcp.value("id").toInt(), rcp.value("altid").toInt(),
        (rcp.value("cleared").toBool() ? tr("Yes") : tr("No")),
        formatDate(rcp.value("f_date").toDate()), rcp.value("doc_type"), rcp.value("docnumber"),
        rcp.value("notes"),
        rcp.value("doc_curr"),
        rcp.value("doc_exchrate").isNull() ? tr("?????") : formatUOMRatio(rcp.value("doc_exchrate").toDouble()),
        rcp.value("base_amount").isNull() ? tr("?????") : formatMoney(rcp.value("base_amount").toDouble()),
        rcp.value("amount").isNull() ? tr("?????") : formatMoney(rcp.value("amount").toDouble()) );
    }
  }
  if(parent != 0)
  {
    parent->setText(0, (cleared ? tr("Yes") : tr("No")));
    parent->setText(8, amountNull ? tr("?????") : formatMoney(amount));
  }

  if(currid != -1)
    _receipts->setCurrentItem(_receipts->topLevelItem(currid));
  if(_receipts->currentItem())
    _receipts->scrollToItem(_receipts->currentItem());

  // fill checks list
  currid = _checks->id();
  _checks->clear();
  MetaSQLQuery mchk = mqlLoad("bankrec", "checks");
  XSqlQuery chk = mchk.toQuery(params);
  if (chk.lastError().type() != QSqlError::NoError)
  {
    systemError(this, chk.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  _checks->populate(chk, TRUE);

  if(currid != -1)
    _checks->setCurrentItem(_checks->topLevelItem(currid));
  if(_checks->currentItem())
    _checks->scrollToItem(_checks->currentItem());

  params.append("summary", true);

  // fill receipts cleared value
  rcp = mrcp.toQuery(params);
  if (rcp.first())
    _clearedReceipts->setDouble(rcp.value("cleared_amount").toDouble());
  else if (rcp.lastError().type() != QSqlError::NoError)
  {
    systemError(this, rcp.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  // fill checks cleared value
  chk = mchk.toQuery(params);
  if (chk.first())
    _clearedChecks->setDouble(chk.value("cleared_amount").toDouble());
  else if (chk.lastError().type() != QSqlError::NoError)
  {
    systemError(this, chk.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  // calculate cleared balance
  MetaSQLQuery mbal = mqlLoad("bankrec", "clearedbalance");
  params.append("endBal", endBal);
  params.append("begBal", begBal);
  params.append("curr_id",   _currency->id());
  params.append("effective", _startDate->date());
  params.append("expires",   _endDate->date());
  XSqlQuery bal = mbal.toQuery(params);
  bool enableRec = FALSE;
  if(bal.first())
  {
    _clearBal->setDouble(bal.value("cleared_amount").toDouble());
    _endBal2->setDouble(bal.value("end_amount").toDouble());
    _diffBal->setDouble(bal.value("diff_amount").toDouble());

    QString stylesheet;

    if(bal.value("diff_value").toDouble() == 0.0)
    {
      if(_startDate->isValid() && _endDate->isValid())
        enableRec = TRUE;
    }
    else
      stylesheet = QString("* { color: %1; }").arg(namedColor("error").name());

    _diffBal->setStyleSheet(stylesheet);
  }
  else if (bal.lastError().type() != QSqlError::NoError)
  {
    systemError(this, bal.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  //_reconcile->setEnabled(enableRec);

  qApp->restoreOverrideCursor();
}
コード例 #15
0
void purchaseOrder::populate()
{
  XSqlQuery po;
  po.prepare( "SELECT pohead_number, COALESCE(pohead_warehous_id,-1) AS pohead_warehous_id, "
              "       pohead_orderdate, pohead_status, pohead_printed, "
              "       pohead_shipvia, pohead_comments,"
              "       pohead_fob, COALESCE(pohead_terms_id,-1) AS pohead_terms_id, "
              "       COALESCE(pohead_vend_id,-1) AS pohead_vend_id,"
              "       pohead_tax, pohead_freight,"
              "       pohead_agent_username,"
              "       vend_name, vend_address1, vend_address2, vend_address3,"
              "       vend_city, vend_state, vend_zip, vend_country,"
              "       COALESCE(vendaddr_id, -1) AS vendaddrid,"
              "       vendaddr_code, vendaddr_name, vendaddr_address1, vendaddr_address2,"
              "       vendaddr_address3, vendaddr_city, vendaddr_state, vendaddr_zipcode,"
              "       vendaddr_country, pohead_curr_id, vend_emailpodelivery "
              "FROM vend, pohead LEFT OUTER JOIN vendaddr ON (pohead_vendaddr_id=vendaddr_id) "
              "WHERE ( (pohead_vend_id=vend_id)"
              " AND (pohead_id=:pohead_id) );" );
  po.bindValue(":pohead_id", _poheadid);
  po.exec();
  if (po.first())
  {
    _orderNumber->setText(po.value("pohead_number"));
    _warehouse->setId(po.value("pohead_warehous_id").toInt());
    _orderDate->setDate(po.value("pohead_orderdate").toDate(), true);
    _agent->setText(po.value("pohead_agent_username").toString());
    _status->setText(po.value("pohead_status").toString());
    _printed = po.value("pohead_printed").toBool();
    _terms->setId(po.value("pohead_terms_id").toInt());
    _shipVia->setText(po.value("pohead_shipvia"));
    _fob->setText(po.value("pohead_fob"));
    _notes->setText(po.value("pohead_comments").toString());

    _vendaddrid = po.value("vendaddrid").toInt();
    if (_vendaddrid == -1)
    {
      _vendaddrCode->setText(tr("Main"));
      _vendaddrName->setText(po.value("vend_name"));
      _vendaddrAddr1->setText(po.value("vend_address1"));
      _vendaddrAddr2->setText(po.value("vend_address2"));
      _vendaddrAddr3->setText(po.value("vend_address3"));
      _vendaddrCity->setText(po.value("vend_city"));
      _vendaddrState->setText(po.value("vend_state"));
      _vendaddrZipCode->setText(po.value("vend_zip"));
      _vendaddrCountry->setText(po.value("vend_country"));
    }
    else
    {
      _vendaddrCode->setText(po.value("vendaddr_code"));
      _vendaddrName->setText(po.value("vendaddr_name"));
      _vendaddrAddr1->setText(po.value("vendaddr_address1"));
      _vendaddrAddr2->setText(po.value("vendaddr_address2"));
      _vendaddrAddr3->setText(po.value("vendaddr_address3"));
      _vendaddrCity->setText(po.value("vendaddr_city"));
      _vendaddrState->setText(po.value("vendaddr_state"));
      _vendaddrZipCode->setText(po.value("vendaddr_zipcode"));
      _vendaddrCountry->setText(po.value("vendaddr_country"));
    }

    _comments->setId(_poheadid);
    _vendor->setId(po.value("pohead_vend_id").toInt());
    _vendEmail = po.value("vend_emailpodelivery").toBool();
    _poCurrency->setId(po.value("pohead_curr_id").toInt());
    _tax->setLocalValue(po.value("pohead_tax").toDouble());
    _freight->setLocalValue(po.value("pohead_freight").toDouble());
  }

  sFillList();
}
コード例 #16
0
ファイル: custCluster.cpp プロジェクト: Wushaowei001/xtuple-1
void CLineEdit::sNew()
{
  QString uiName="customer";
  ParameterList params;
  QMessageBox ask(this);
  ask.setIcon(QMessageBox::Question);
  QPushButton *pbutton = ask.addButton(tr("Prospect"), QMessageBox::YesRole);
  QPushButton *cbutton = ask.addButton(tr("Customer"), QMessageBox::YesRole);
  ask.setDefaultButton(cbutton);
  ask.setWindowTitle(tr("Customer or Prospect?"));

  if (_subtype == CRMAcctLineEdit::Prospect ||
      (_subtype == CRMAcctLineEdit::CustAndProspect &&
       !_x_privileges->check("MaintainCustomerMasters")))
  {
    params.append("mode", "new");
    uiName="prospect";
  }
  if (_subtype == CRMAcctLineEdit::CustAndProspect &&
       !_x_privileges->check("MaintainProspectMasters"))
    params.append("mode", "new");
  else
  {
    if (_subtype == CRMAcctLineEdit::Cust)
      ask.setText(tr("<p>Would you like to create a new Customer or convert "
                     "an existing Prospect?"));
    else
      ask.setText(tr("<p>Would you like to create a new Customer or "
                     "a new Prospect?"));

    ask.exec();

    if (ask.clickedButton() == pbutton &&
        _subtype == CRMAcctLineEdit::Cust)  // converting prospect
    {
      int prospectid = -1;
      if (_x_preferences->value("DefaultEllipsesAction") == "search")
      {
        CRMAcctSearch* search = new CRMAcctSearch(this);
        search->setSubtype(CRMAcctLineEdit::Prospect);
        prospectid = search->exec();
      }
      else
      {
        CRMAcctList* list = new CRMAcctList(this);
        list->setSubtype(CRMAcctLineEdit::Prospect);
        prospectid = list->exec();
      }

      if (prospectid > 0)
      {
        XSqlQuery convertq;
        convertq.prepare("SELECT convertProspectToCustomer(:id) AS result;");
        convertq.bindValue(":id", prospectid);
        convertq.exec();
        if (convertq.first())
        {
          int result = convertq.value("result").toInt();
          if (result < 0)
          {
            QMessageBox::critical(this, tr("Processing Error"),
                                  storedProcErrorLookup("convertProspectToCustomer", result));
            return;
          }
          params.append("cust_id", prospectid);
          params.append("mode", "edit");
        }
      }
      else
        return;
    }
    else
    {
      params.append("mode", "new");
      if (ask.clickedButton() == pbutton)
        uiName = "prospect";
    }
  }

  sOpenWindow(uiName, params);
}
コード例 #17
0
void unpostedPoReceipts::sPost()
{
  XSqlQuery unpostedPost;
  bool changeDate = false;
  QDate newDate = QDate::currentDate();

  if (_privileges->check("ChangePORecvPostDate"))
  {
    getGLDistDate newdlg(this, "", TRUE);
    newdlg.sSetDefaultLit(tr("Receipt Date"));
    if (newdlg.exec() == XDialog::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<XTreeWidgetItem*>selected = _recv->selectedItems();
  QList<XTreeWidgetItem*>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::NoError)
      {
        systemError(this, setDate.lastError().databaseText(), __FILE__, __LINE__);
      }
    }
  }
  
  XSqlQuery postLine;
  postLine.prepare("SELECT postReceipt(:id, NULL::integer) AS result, "
                   "  (recv_order_type = 'RA' AND COALESCE(itemsite_costmethod, '') = 'J') AS issuewo, "
                   "  COALESCE(pohead_dropship, false) AS dropship "
                   "FROM recv "
                   "  LEFT OUTER JOIN itemsite ON (itemsite_id=recv_itemsite_id) "
                   "  LEFT OUTER JOIN poitem ON ((recv_order_type='PO') "
                   "                         AND (recv_orderitem_id=poitem_id)) "
                   "  LEFT OUTER JOIN pohead ON (poitem_pohead_id=pohead_id) "
                   "WHERE (recv_id=:id);");
  XSqlQuery rollback;
  rollback.prepare("ROLLBACK;");

  bool tryagain = false;
  do {
    unpostedPost.exec("BEGIN;");

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

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

        if (distributeInventory::SeriesAdjust(result, this) == XDialog::Rejected)
        {
          rollback.exec();
          QMessageBox::information( this, tr("Unposted Receipts"), tr("Post Canceled") );
          return;
        }

        // Job item for Return Service; issue this to work order
        if (postLine.value("issuewo").toBool())
        {
          XSqlQuery issuewo;
          issuewo.prepare("SELECT issueWoRtnReceipt(coitem_order_id, invhist_id) AS result "
                          "FROM invhist, recv "
                          " JOIN raitem ON (raitem_id=recv_orderitem_id) "
                          " JOIN coitem ON (coitem_id=raitem_new_coitem_id) "
                          "WHERE ((invhist_series=:itemlocseries) "
                          " AND (recv_id=:id));");
          issuewo.bindValue(":itemlocseries", postLine.value("result").toInt());
          issuewo.bindValue(":id", id);
          issuewo.exec();
          if (issuewo.lastError().type() != QSqlError::NoError)
          {
            systemError(this, issuewo.lastError().databaseText(), __FILE__, __LINE__);
            rollback.exec();
            return;
          }
        }
        // Issue drop ship orders to shipping
        else if (postLine.value("dropship").toBool())
        {
          XSqlQuery issue;
          issue.prepare("SELECT issueToShipping('SO', coitem_id, "
                        "  (recv_qty * poitem_invvenduomratio / coitem_qty_invuomratio), "
                        "  :itemlocseries, now(), invhist_id ) AS result, "
                        "  coitem_cohead_id, cohead_holdtype, pohead_number "
                        "FROM invhist, recv "
                        " JOIN poitem ON (poitem_id=recv_orderitem_id) "
                        " JOIN pohead ON (poitem_pohead_id=pohead_id) "
                        " JOIN coitem ON (coitem_id=poitem_order_id AND poitem_order_type='S') "
                        " JOIN cohead ON (coitem_cohead_id=cohead_id) "
                        "WHERE ((invhist_series=:itemlocseries) "
                        " AND (recv_id=:id));");
          issue.bindValue(":itemlocseries", postLine.value("result").toInt());
          issue.bindValue(":id",  id);
          issue.exec();
          if (issue.first())
          {
            if (issue.value("cohead_holdtype").toString() != "N")
            {
              QString msg = tr("Purchase Order %1 is being drop shipped against "
                       "a Sales Order that is on Hold.  The Sales Order must "
                       "be taken off Hold before the Receipt may be Posted.")
                  .arg(issue.value("pohead_number").toString());
              rollback.exec();
              QMessageBox::warning(this, tr("Cannot Ship Order"), msg);
              sFillList();
              return;
            }

            if (!_soheadid.contains(issue.value("coitem_cohead_id").toInt()))
              _soheadid.append(issue.value("coitem_cohead_id").toInt());
            issue.prepare("SELECT postItemLocSeries(:itemlocseries);");
            issue.bindValue(":itemlocseries", postLine.value("result").toInt());
            issue.exec();
          }
          if (issue.lastError().type() != QSqlError::NoError)
          {
            systemError(this, issue.lastError().databaseText(), __FILE__, __LINE__);
            rollback.exec();
            return;
          }
        }    
      }
      // 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::NoError)
      {
        rollback.exec();
        systemError(this, postLine.lastError().databaseText(), __FILE__, __LINE__);
      }
    } // for each selected line

    // Ship any drop shipped orders
    while (_soheadid.count())
    {
      XSqlQuery ship;
      ship.prepare("SELECT shipShipment(shiphead_id) AS result, "
                   "  shiphead_id "
                   "FROM shiphead "
                   "WHERE ( (shiphead_order_type='SO') "
                   " AND (shiphead_order_id=:cohead_id) "
                   " AND (NOT shiphead_shipped) );");
      ship.bindValue(":cohead_id", _soheadid.at(0));
      ship.exec();
      if (_metrics->boolean("BillDropShip") && ship.first())
      {
        int shipheadid = ship.value("shiphead_id").toInt();
        ship.prepare("SELECT selectUninvoicedShipment(:shiphead_id);");
        ship.bindValue(":shiphead_id", shipheadid);
        ship.exec();
        if (ship.lastError().type() != QSqlError::NoError)
        {
          rollback.exec();
          systemError(this, ship.lastError().databaseText(), __FILE__, __LINE__);
          return;
        }
      }
      if (ship.lastError().type() != QSqlError::NoError)
      {
        rollback.exec();
        systemError(this, ship.lastError().databaseText(), __FILE__, __LINE__);
        return;
      }
      _soheadid.takeFirst();
    }

    unpostedPost.exec("COMMIT;");

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

  omfgThis->sPurchaseOrderReceiptsUpdated();
}
コード例 #18
0
void purchaseOrderItem::sPopulateItemSourceInfo(int pItemsrcid)
{
  XSqlQuery src;
  bool skipClear = false;
  if (!_item->isValid())
    skipClear = true;
  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, "
                 "       contrct_number "
				 "FROM itemsrc LEFT OUTER JOIN contrct ON (itemsrc_contrct_id = contrct_id) "
                 "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();
        _contrctNumber->setText(src.value("contrct_number").toString());
        
        _manufName->setCode(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->date() < _earliestDate->date())
          _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->setId(-1);
      _manufItemNumber->clear();
      _manufItemDescrip->clear();
  
      _invVendUOMRatio = 1;
      _minimumOrder = 0;
      _orderMultiple = 0;
    }
  }
}
コード例 #19
0
ファイル: shipTo.cpp プロジェクト: dwatson78/qt-client
void shipTo::populate()
{
  XSqlQuery popq;
  popq.prepare( "SELECT cust_number, cust_name, shipto_active, shipto_default,"
                "       shipto_cust_id,"
                "       shipto_num, shipto_name, shipto_cntct_id,"
                "       shipto_shipvia, shipto_commission,"
                "       shipto_comments, shipto_shipcomments,"
                "       shipto_taxzone_id, shipto_shipchrg_id,"
                "       COALESCE(shipto_salesrep_id,-1) AS shipto_salesrep_id,"
                "       COALESCE(shipto_shipzone_id,-1) AS shipto_shipzone_id,"
                "       COALESCE(shipto_shipform_id,-1) AS shipto_shipform_id,"
                "       shipto_preferred_warehous_id, shipto_addr_id,"
                "       crmacct_id "
                "FROM shiptoinfo "
                "  LEFT OUTER JOIN custinfo ON (shipto_cust_id=cust_id) "
                "  LEFT OUTER JOIN crmacct ON (cust_id=crmacct_cust_id) "
                "WHERE (shipto_id=:shipto_id);" );
  popq.bindValue(":shipto_id", _shiptoid);
  popq.exec();
  if (popq.first())
  {
    double commission = popq.value("shipto_commission").toDouble();
    _custid = popq.value("shipto_cust_id").toInt();
    _custNum->setText(popq.value("cust_number").toString());
    _custName->setText(popq.value("cust_name").toString());
    _active->setChecked(popq.value("shipto_active").toBool());
    _default->setChecked(popq.value("shipto_default").toBool());
    _shipToNumber->setText(popq.value("shipto_num"));
    _name->setText(popq.value("shipto_name"));
    _contact->setId(popq.value("shipto_cntct_id").toInt());
    _contact->setSearchAcct(popq.value("crmacct_id").toInt());
    _address->setSearchAcct(popq.value("crmacct_id").toInt());
    _comments->setText(popq.value("shipto_comments").toString());
    _shippingComments->setText(popq.value("shipto_shipcomments").toString());
    _taxzone->setId(popq.value("shipto_taxzone_id").toInt());
    _shipZone->setId(popq.value("shipto_shipzone_id").toInt());
    _shipform->setId(popq.value("shipto_shipform_id").toInt());
    _shipchrg->setId(popq.value("shipto_shipchrg_id").toInt());
    _sellingWarehouse->setId(popq.value("shipto_preferred_warehous_id").toInt());
    _address->setId(popq.value("shipto_addr_id").toInt());

    //  Handle the free-form Ship Via
    _shipVia->setCurrentIndex(-1);
    QString shipvia = popq.value("shipto_shipvia").toString();
    if (shipvia.trimmed().length() != 0)
    {
      for (int counter = 0; counter < _shipVia->count(); counter++)
        if (_shipVia->itemText(counter) == shipvia)
          _shipVia->setCurrentIndex(counter);

      if (_shipVia->id() == -1)
      {
        _shipVia->addItem(shipvia);
        _shipVia->setCurrentIndex(_shipVia->count() - 1);
      }
    }

    _salesRep->setId(popq.value("shipto_salesrep_id").toInt());
    _commission->setDouble(commission * 100);

    emit newId(_shiptoid);
    emit populated();
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Ship To Information"),
                                popq, __FILE__, __LINE__))
  {
    return;
  }
}
コード例 #20
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;
}
コード例 #21
0
ファイル: shipTo.cpp プロジェクト: dwatson78/qt-client
enum SetResponse shipTo::set(const ParameterList &pParams)
{
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

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

  param = pParams.value("shipto_id", &valid);
  if (valid)
  {
    _shiptoid = param.toInt();
    _documents->setId(_shiptoid);
    populate();
  }

  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "new")
    {
      _mode = cNew;
      _salesRep->setType(XComboBox::SalesRepsActive);

      XSqlQuery cust;
      cust.prepare( "SELECT cust_number, cust_name, cust_taxzone_id, "
                 "       cust_salesrep_id, cust_shipform_id, cust_shipvia, cust_shipchrg_id, "
                 "       crmacct_id "
                 "FROM custinfo "
                 "  JOIN crmacct ON (cust_id=crmacct_cust_id) "
                 "WHERE (cust_id=:cust_id);" );
      cust.bindValue(":cust_id", _custid);
      cust.exec();
      if (cust.first())
      {
        _custNum->setText(cust.value("cust_number").toString());
        _custName->setText(cust.value("cust_name").toString());
        _salesRep->setId(cust.value("cust_salesrep_id").toInt());
        _shipform->setId(cust.value("cust_shipform_id").toInt());
        _taxzone->setId(cust.value("cust_taxzone_id").toInt());
        _contact->setSearchAcct(cust.value("crmacct_id").toInt());
        _address->setSearchAcct(cust.value("crmacct_id").toInt());
        _shipchrg->setId(cust.value("cust_shipchrg_id").toInt());

	//  Handle the free-form Ship Via
        _shipVia->setId(-1);
        QString shipvia = cust.value("cust_shipvia").toString().trimmed();
        if (shipvia.length())
        {
          for (int counter = 0; counter < _shipVia->count(); counter++)
            if (_shipVia->itemText(counter) == shipvia)
              _shipVia->setCurrentIndex(counter);

          if (_shipVia->id() == -1)
          {
            _shipVia->addItem(shipvia);
            _shipVia->setCurrentIndex(_shipVia->count() - 1);
          }
        }
      }
      if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Customer Information"),
                                    cust, __FILE__, __LINE__))
      {
        return UndefinedError;
      }
      sPopulateNumber();
      _name->setFocus();
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;
      _shipToNumber->setEnabled(false);
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _shipToNumber->setEnabled(false);
      _active->setEnabled(false);
      _default->setEnabled(false);
      _name->setEnabled(false);
      _contact->setEnabled(false);
      _address->setEnabled(false);
      _salesRep->setEnabled(false);
      _commission->setEnabled(false);
      _shipZone->setEnabled(false);
      _taxzone->setEnabled(false);
      _shipVia->setEnabled(false);
      _shipform->setEnabled(false);
      _shipchrg->setEnabled(false);
      _sellingWarehouse->setEnabled(false);
      _comments->setEnabled(false);
      _shippingComments->setEnabled(false);
      _documents->setReadOnly(true);
      _close->setText(tr("&Close"));
      _save->hide();
    }
  }

  return NoError;
}
コード例 #22
0
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();
}
コード例 #23
0
void printShippingForms::sPrint()
{
  if (!_printNew->isChecked() && !_printDirty->isChecked())
  {
    QMessageBox::warning( this, tr("Cannot Print Shipping Forms"),
                          tr("You must indicate if you wish to print Shipping Forms for New and/or Changed Shipments.") );
    return;
  }

  QString sql( "SELECT shiphead_id, report_name "
               "FROM shiphead, cohead, shipform, report "
               "WHERE ( (NOT shiphead_shipped)"
               " AND (shiphead_order_id=cohead_id)"
	       " AND (shiphead_order_type='SO')"
               " AND (shipform_report_id=report_id)"
               " AND (shipform_id=COALESCE(shiphead_shipform_id, cohead_shipform_id))"
               " AND (shiphead_sfstatus IN (" );

  if (_printNew->isChecked())
  {
    sql += "'N'";

    if (_printDirty->isChecked())
      sql += ", 'D'";
  }
  else if (_printDirty->isChecked())
    sql += "'D'";
  sql += ")) ) "
         "ORDER BY shiphead_id;";

  XSqlQuery reports;
  reports.exec(sql);
  if (reports.first())
  {
    QPrinter printer(QPrinter::HighResolution);

    bool     setupPrinter = TRUE;
    bool userCanceled = false;
    if (orReport::beginMultiPrint(&printer, userCanceled) == false)
    {
      if(!userCanceled)
        systemError(this, tr("Could not initialize printing system for multiple reports."));
      return;
    }

    do
    {
      for (int i = 0; i < _shipformWatermarks->topLevelItemCount(); i++ )
      {
        ParameterList params;

        params.append("cosmisc_id", reports.value("shiphead_id").toInt());
        params.append("shiphead_id", reports.value("shiphead_id").toInt());

        params.append("watermark", _shipformWatermarks->topLevelItem(i)->text(1));

#if 0
        params.append("shipchrg_id", _shipchrg->id());

#endif

        if (_shipformWatermarks->topLevelItem(i)->text(2) == tr("Yes"))
          params.append("showcosts");

        orReport report(reports.value("report_name").toString(), params);
        if (report.print(&printer, setupPrinter))
          setupPrinter = FALSE;
        else
        {
          report.reportError(this);
	  orReport::endMultiPrint(&printer);
          return;
        }
      }

      XSqlQuery setStatus;
      setStatus.prepare( "UPDATE shiphead "
                         "SET shiphead_sfstatus='P' "
                         "WHERE (shiphead_id=:shiphead_id);" );
      setStatus.bindValue(":shiphead_id", reports.value("shiphead_id").toInt());
      setStatus.exec();
    }
    while (reports.next());
    orReport::endMultiPrint(&printer);

    if (_captive)
      accept();
  }
  else
    QMessageBox::warning( this, tr("Cannot Print Shipping Forms"),
                          tr("There are no New or Changed Shipments for which Shipping Forms should be printed.") );

}
コード例 #24
0
void purchaseOrderItem::populate()
{
  XSqlQuery purchasepopulate;
  MetaSQLQuery mql = mqlLoad("purchaseOrderItems", "detail");

  ParameterList params;
  params.append("poitem_id", _poitemid);
  params.append("sonum",     tr("Sales Order #")),
  params.append("wonum",     tr("Work Order #")),
  purchasepopulate = mql.toQuery(params);
  if (purchasepopulate.lastError().type() != QSqlError::NoError)
  {
    systemError(this, purchasepopulate.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  if (purchasepopulate.first())
  {
    _poNumber->setText(purchasepopulate.value("pohead_number").toString());
    _lineNumber->setText(purchasepopulate.value("poitem_linenumber").toString());
    _taxzoneid=purchasepopulate.value("pohead_taxzone_id").toInt();   // added  to pick up tax zone id.
    _dueDate->setDate(purchasepopulate.value("poitem_duedate").toDate());
    _ordered->setDouble(purchasepopulate.value("poitem_qty_ordered").toDouble());
    _orderQtyCache = _ordered->toDouble();
    _received->setDouble(purchasepopulate.value("poitem_qty_received").toDouble());
    _unitPrice->set(purchasepopulate.value("poitem_unitprice").toDouble(),
		    purchasepopulate.value("pohead_curr_id").toInt(),
		    purchasepopulate.value("pohead_orderdate").toDate(), false);
    _freight->setLocalValue(purchasepopulate.value("poitem_freight").toDouble());
    _extendedPrice->setLocalValue(purchasepopulate.value("extended_price").toDouble());
    _taxtype->setId(purchasepopulate.value("poitem_taxtype_id").toInt());
    _taxRecoverable->setChecked(purchasepopulate.value("poitem_tax_recoverable").toBool());
    _notes->setText(purchasepopulate.value("poitem_comments").toString());
    _project->setId(purchasepopulate.value("poitem_prj_id").toInt());
    if(purchasepopulate.value("override_cost").toDouble() > 0)
      _overriddenUnitPrice = true;

    if(purchasepopulate.value("poitem_order_id") != -1)
    {
      _ordered->setEnabled(FALSE);
      _dueDate->setEnabled(FALSE);
      _soLit->setText(purchasepopulate.value("demand_type").toString());
      _so->setText(purchasepopulate.value("order_number").toString());
//      _soLine->setText(purchasepopulate.value("orderline_number").toString());
    }
    else
      _tab->setTabEnabled(_tab->indexOf(_demandTab), FALSE);

    if (purchasepopulate.value("poitem_itemsite_id").toInt() == -1)
    {
      _nonInventoryItem->setChecked(TRUE);
      _expcat->setId(purchasepopulate.value("poitem_expcat_id").toInt());
      sPopulateItemSourceInfo(-1);

      _vendorItemNumber->setText(purchasepopulate.value("poitem_vend_item_number").toString());
      _vendorDescrip->setText(purchasepopulate.value("poitem_vend_item_descrip").toString());
      _vendorUOM->setText(purchasepopulate.value("poitem_vend_uom").toString());
      _uom->setText(purchasepopulate.value("poitem_vend_uom").toString());
    }
    else
    {
      _inventoryItem->setChecked(TRUE);
      _item->setItemsiteid(purchasepopulate.value("poitem_itemsite_id").toInt());
      sPopulateItemSourceInfo(purchasepopulate.value("poitem_itemsrc_id").toInt());
      if (_metrics->boolean("RevControl"))
      {
        _bomRevision->setId(purchasepopulate.value("poitem_bom_rev_id").toInt());
        _booRevision->setId(purchasepopulate.value("poitem_boo_rev_id").toInt());
        _bomRevision->setEnabled(purchasepopulate.value("poitem_status").toString() == "U" && _privileges->boolean("UseInactiveRevisions"));
        _booRevision->setEnabled(purchasepopulate.value("poitem_status").toString() == "U" && _privileges->boolean("UseInactiveRevisions"));
      }
    }

    _itemsrcid = purchasepopulate.value("poitem_itemsrc_id").toInt();
    _contrctNumber->setText(purchasepopulate.value("contrct_number").toString());
    _vendorItemNumber->setText(purchasepopulate.value("poitem_vend_item_number").toString());
    _vendorDescrip->setText(purchasepopulate.value("poitem_vend_item_descrip").toString());
    _vendorUOM->setText(purchasepopulate.value("poitem_vend_uom").toString());
    _uom->setText(purchasepopulate.value("poitem_vend_uom").toString());
    _invVendorUOMRatio->setDouble(purchasepopulate.value("poitem_invvenduomratio").toDouble());
    _invVendUOMRatio = purchasepopulate.value("poitem_invvenduomratio").toDouble();
    _manufName->setText(purchasepopulate.value("poitem_manuf_name").toString());
    if (_manufName->id() < 0)
    {
      _manufName->append(_manufName->count(),
                         purchasepopulate.value("poitem_manuf_name").toString());
      _manufName->setText(purchasepopulate.value("poitem_manuf_name").toString());
    }
    _manufItemNumber->setText(purchasepopulate.value("poitem_manuf_item_number").toString());
    _manufItemDescrip->setText(purchasepopulate.value("poitem_manuf_item_descrip").toString());

    if (_itemsrcid != -1)
    {
      _vendorUOM->setEnabled(FALSE);
      _manufName->setEnabled(FALSE);
      _manufItemNumber->setEnabled(FALSE);
      _manufItemDescrip->setEnabled(FALSE);

      if(_vendorItemNumber->text().isEmpty())
        _vendorItemNumber->setText(purchasepopulate.value("itemsrc_vend_item_number").toString());
      if(_vendorDescrip->toPlainText().isEmpty())
        _vendorDescrip->setText(purchasepopulate.value("itemsrc_vend_item_descrip").toString());
      _minOrderQty->setDouble(purchasepopulate.value("itemsrc_minordqty").toDouble());
      _orderQtyMult->setDouble(purchasepopulate.value("itemsrc_multordqty").toDouble());

      _minimumOrder = purchasepopulate.value("itemsrc_minordqty").toDouble();
      _orderMultiple = purchasepopulate.value("itemsrc_multordqty").toDouble();

      if(_manufName->currentText().isEmpty())
        _manufName->setText(purchasepopulate.value("itemsrc_manuf_name").toString());
      if(_manufItemNumber->text().isEmpty())
        _manufItemNumber->setText(purchasepopulate.value("itemsrc_manuf_item_number").toString());
      if(_manufItemDescrip->toPlainText().isEmpty())
        _manufItemDescrip->setText(purchasepopulate.value("itemsrc_manuf_item_descrip").toString());
    }

    purchasepopulate.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;" );
    purchasepopulate.bindValue(":item_id", _item->id());
    purchasepopulate.bindValue(":poitem_id", _poitemid);
    purchasepopulate.exec();
    int row = 0;
    QModelIndex idx;
    while(purchasepopulate.next())
    {
      _itemchar->insertRow(_itemchar->rowCount());
      idx = _itemchar->index(row, 0);
      _itemchar->setData(idx, purchasepopulate.value("char_name"), Qt::DisplayRole);
      _itemchar->setData(idx, purchasepopulate.value("char_id"), Qt::UserRole);
      idx = _itemchar->index(row, 1);
      _itemchar->setData(idx, purchasepopulate.value("charass_value"), Qt::DisplayRole);
      _itemchar->setData(idx, _item->id(), Xt::IdRole);
      _itemchar->setData(idx, _item->id(), Qt::UserRole);
      row++;
    }

    _comments->setId(_poitemid);
  }
}
コード例 #25
0
void OrderLineEdit::silentSetId(const int pId)
{
  if (pId == -1)
    XLineEdit::clear();
  else
  {
    QString oldExtraClause = _extraClause;

    XSqlQuery countQ;
    countQ.prepare("SELECT COUNT(*) AS count FROM orderhead WHERE (TRUE) " + _idClause +
		    (_extraClause.isEmpty() || !_strict ? "" : " AND " + _extraClause) +
		    QString(";"));
    countQ.bindValue(":id", pId);
    countQ.exec();
    if (countQ.first())
    {
      int result = countQ.value("count").toInt();
      if (result <= 0)
      {
	_id = -1;
	XLineEdit::clear();
      }
      else if (result == 1)
	_id = pId;
      else
      {
	_extraClause += "AND (orderhead_id=" + QString::number(pId) + ")";
	sEllipses();
	_extraClause += "AND (orderhead_type='" + type() + "')";
      }
    }
    else if (countQ.lastError().type() != QSqlError::None)
    {
      QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
				    .arg(__FILE__)
				    .arg(__LINE__),
			    countQ.lastError().databaseText());
    }

    if (_id > 0)
    {
      XSqlQuery idQ;
      idQ.prepare(_query + _idClause +
		  (_extraClause.isEmpty() || !_strict ? "" : " AND " + _extraClause) +
		  QString(";"));
      idQ.bindValue(":id", pId);
      idQ.exec();
      if (idQ.first())
      {
	_id = pId;
	_valid = true;
	setText(idQ.value("number").toString());
	_name		= idQ.value("name").toString();
	_description	= idQ.value("description").toString();
	_from		= idQ.value("orderhead_from").toString();
	_to		= idQ.value("orderhead_to").toString();
      }
      else if (idQ.lastError().type() != QSqlError::None)
	QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
				      .arg(__FILE__)
				      .arg(__LINE__),
			      idQ.lastError().databaseText());
    }
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
  if (cNew == _mode && !_captive)
  {
    clear();
    prepare();
    _item->setFocus();
  }
  else
    done(_poitemid);
}
コード例 #27
0
int PaymentechProcessor::buildCommon(QString & pordernum, const int pccardid, const int pcvv, const double pamount, const int /*pcurrid*/, QString &prequest, QString pordertype, const QString & pAuthcode, const QString & pRespdate)
{
  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,"
    "  ccard_type,"
    "  custinfo.* "
    "  FROM ccard, custinfo "
    "WHERE ((ccard_id=:ccardid)"
    "  AND  (ccard_cust_id=cust_id));");
  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;
  }

  _extraHeaders.clear();
  _extraHeaders.append(qMakePair(QString("Stateless-Transaction"), QString("true")));
  _extraHeaders.append(qMakePair(QString("Auth-MID"), QString(_metricsenc->value("CCPTDivisionNumber").rightJustified(10, '0', true))));
  _extraHeaders.append(qMakePair(QString("Auth-User"), QString(_metricsenc->value("CCLogin"))));
  _extraHeaders.append(qMakePair(QString("Auth-Password"), QString(_metricsenc->value("CCPassword"))));
  _extraHeaders.append(qMakePair(QString("Content-type"), QString("SALEM05210/SLM")));

  prequest = "P74V";
  prequest += pordernum.leftJustified(22, ' ', true);

  QString ccardType = anq.value("ccard_type").toString();
  if("V" == ccardType) // Visa
    ccardType = "VI";
  else if("M" == ccardType) // Master Card
    ccardType = "MC";
  else if("A" == ccardType) // American Express
    ccardType = "AX";
  else if("D" == ccardType) // Discover
    ccardType = "DI";
  else if("P" == ccardType) // PayPal
    ccardType = "PY";
  else
  {
    _errorMsg = errorMsg(-209);
    return -209;
  }
  prequest += ccardType;

  prequest += anq.value("ccard_number").toString().leftJustified(19, ' ', true);

  QString work_month;
  work_month.setNum(anq.value("ccard_month_expired").toDouble());
  if (work_month.length() == 1)
    work_month = "0" + work_month;
  prequest += work_month + anq.value("ccard_year_expired").toString().right(2);

  prequest += _metricsenc->value("CCPTDivisionNumber").rightJustified(10, '0', true);

  double shiftedAmt = pamount * 100.0;
  int amount = (int)shiftedAmt;
  prequest += QString::number(amount).rightJustified(12, '0', true);

  // TODO: this needs to be changed to support non-us
  prequest += "840"; // CurrencyCode: U.S. Dollars

  prequest += "7"; // TransactionType: 1 - single trans over mail/phone card holder not present, 7 - e-commerce

  prequest += "    "; // EncryptionFlag, PaymentIndicator: both optional not using

  prequest += pordertype; // ActionCode 2 digit

  prequest += " "; // Reserved

  if(pordertype == "AU")
  {
    // Bill To Address Information
    prequest += "AB";
    prequest += "               "; // TelephoneType, TelephoneNumber (1,14, Optional)
    QStringList nameParts = anq.value("ccard_name").toString().split(QRegExp("\\s+"));
    QString name = "";
    if(!nameParts.isEmpty())
    {
      QString lName = nameParts.takeLast();
      QString fName = nameParts.join(" ");
      name = fName + " *" + lName;
    }
    prequest += name.leftJustified(30, ' ', true);
    prequest += anq.value("ccard_address1").toString().leftJustified(30, ' ', true);
    prequest += anq.value("ccard_address2").toString().leftJustified(28, ' ', true);

    QString cntry = anq.value("ccard_country").toString();
    XSqlQuery qCntry;
    qCntry.prepare("SELECT 1 AS ord, country_abbr FROM country WHERE country_name = :cname"
                   " UNION "
                   "SELECT 2 AS ord, country_abbr FROM country WHERE country_abbr = :cname"
                   " ORDER BY ord LIMIT 1;");
    qCntry.bindValue(":cname", cntry);
    qCntry.exec();
    if(qCntry.first())
      cntry = qCntry.value("country_abbr").toString();
    else
      cntry = "";
    prequest += cntry.leftJustified(2, ' ', true);
  
    prequest += anq.value("ccard_city").toString().leftJustified(20, ' ', true);
  
    QString state = anq.value("ccard_state").toString();
    XSqlQuery qState;
    qState.prepare("SELECT 1 AS ord, state_abbr FROM state WHERE state_name = :cname"
                   " UNION "
                   "SELECT 2 AS ord, state_abbr FROM state WHERE state_abbr = :cname"
                   " ORDER BY ord LIMIT 1;");
    qState.bindValue(":cname", state);
    qState.exec();
    if(qState.first())
      state = qState.value("state_abbr").toString();
    else
      state = "";
    prequest += state.leftJustified(2, ' ', true);
  
    prequest += anq.value("ccard_zip").toString().leftJustified(10, ' ', true);

  } // end Address Billing record

  if(pordertype == "AR")
  {
    prequest += "PA";
    prequest += pRespdate.leftJustified(6, '0', true);
    prequest += pAuthcode.leftJustified(6, ' ', true);
    prequest += "        "; // DebitTraceNumber: leave blank
  }

  if (pcvv > 0)
  {
    prequest += "FR";
    prequest += "1";
    prequest += QString::number(pcvv).leftJustified(4, ' ', true);
  }

  // version records -- should always include
  prequest += "VVISAN\r"; // add version record to end
  prequest = prequest.toUpper();

  _extraHeaders.append(qMakePair(QString("Content-Length"), QString("%1").arg(prequest.size())));

  if (DEBUG)
    qDebug("Paymentech:buildCommon built %s\n", prequest.toAscii().data());
  return 0;
}
コード例 #28
0
void purchaseOrderItem::sPopulateItemInfo(int pItemid)
{
  XSqlQuery item;
  if (pItemid != -1 && _mode == cNew)
  {
      item.prepare("SELECT stdCost(item_id) AS stdcost, "
                   "       getItemTaxType(item_id, pohead_taxzone_id) AS taxtype_id, "
                   "       item_tax_recoverable, COALESCE(item_maxcost, 0.0) AS maxcost "
                   "FROM item, pohead "
                   "WHERE ( (item_id=:item_id) "
                   "  AND   (pohead_id=:pohead_id) );");
      item.bindValue(":item_id", pItemid);
      item.bindValue(":pohead_id", _poheadid);
      item.exec();

      if (item.first())
      {
          // Reset order qty cache
          _orderQtyCache = -1;

          if(_metrics->boolean("RequireStdCostForPOItem") && item.value("stdcost").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;
          }

        _taxtype->setId(item.value("taxtype_id").toInt());
        _taxRecoverable->setChecked(item.value("item_tax_recoverable").toBool());
        _maxCost = item.value("maxcost").toDouble();

        sPopulateItemsiteInfo();

        item.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;" );
        item.bindValue(":item_id", pItemid);
        item.bindValue(":poitem_id", _poitemid);
        item.exec();
        int row = 0;
        _itemchar->removeRows(0, _itemchar->rowCount());
        QModelIndex idx;
        while(item.next())
        {
          _itemchar->insertRow(_itemchar->rowCount());
          idx = _itemchar->index(row, 0);
          _itemchar->setData(idx, item.value("char_name"), Qt::DisplayRole);
          _itemchar->setData(idx, item.value("char_id"), Qt::UserRole);
          idx = _itemchar->index(row, 1);
          _itemchar->setData(idx, item.value("charass_value"), Qt::DisplayRole);
          _itemchar->setData(idx, pItemid, Xt::IdRole);
          _itemchar->setData(idx, pItemid, Qt::UserRole);
          row++;
        }

        item.prepare("SELECT itemsrc_id "
                     "FROM itemsrc, pohead "
                     "WHERE ( (itemsrc_vend_id=pohead_vend_id)"
                     " AND (itemsrc_item_id=:item_id)"
                     " AND (:effective BETWEEN itemsrc_effective AND (itemsrc_expires - 1))"
                     " AND (itemsrc_active)"
                     " AND (pohead_id=:pohead_id) );" );
        item.bindValue(":item_id", pItemid);
        item.bindValue(":pohead_id", _poheadid);
        item.bindValue(":effective", _unitPrice->effective());
        item.exec();
        if (item.size() == 1)
        {
          item.first();

          if (item.value("itemsrc_id").toInt() != _itemsrcid)
            sPopulateItemSourceInfo(item.value("itemsrc_id").toInt());
        }
        else if (item.size() > 1)
        {
          bool isCurrent = false;
          while (item.next())
          {
            if (item.value("itemsrc_id").toInt() == _itemsrcid)
              isCurrent = true;
          }
          if (!isCurrent)
          {
            _vendorItemNumber->clear();
            sVendorItemNumberList();
          }
        }
        else
        {
          _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->setId(-1);
          _manufItemNumber->clear();
          _manufItemDescrip->clear();

          _invVendUOMRatio = 1;
          _minimumOrder = 0;
          _orderMultiple = 0;
        }
      }
  }
}
コード例 #29
0
void ItemLineEdit::silentSetId(const int pId)
{
  if (DEBUG)
    qDebug("%s::silentSetId(%d) entered",
           qPrintable(objectName()), pId);

  XSqlQuery item;
  bool      found = FALSE;

  _parsed = TRUE;

  if (_useValidationQuery)
  {
    item.prepare(_validationSql);
    item.bindValue(":item_id", pId);
    item.exec();
    if (item.first())
      found = TRUE;
  }
  else if (_useQuery)
  {
    item.prepare(_sql);
    item.exec();
    found = (item.findFirst("item_id", pId) != -1);
  }
  else if (pId != -1)
  {
    QString pre( "SELECT DISTINCT item_number, item_descrip1, item_descrip2,"
                 "                uom_name, item_type, item_config, item_fractional, item_upccode");

    QStringList clauses;
    clauses = _extraClauses;
    clauses << "(item_id=:item_id)";

    item.prepare(buildItemLineEditQuery(pre, clauses, QString::null, _type, false));
    item.bindValue(":item_id", pId);
    item.exec();

    found = item.first();
  }

  if (found)
  {
    if (completer())
    {
      disconnect(this, SIGNAL(textChanged(QString)), this, SLOT(sHandleCompleter()));
      static_cast<QSqlQueryModel* >(completer()->model())->setQuery(QSqlQuery());
    }

    _itemNumber = item.value("item_number").toString();
    _uom        = item.value("uom_name").toString();
    _itemType   = item.value("item_type").toString();
    _configured = item.value("item_config").toBool();
    _fractional = item.value("item_fractional").toBool();
    _upc        = item.value("item_upccode").toString();
    _id         = pId;
    _valid      = TRUE;

    setText(item.value("item_number").toString());
    emit aliasChanged("");
    emit typeChanged(_itemType);
    emit descrip1Changed(item.value("item_descrip1").toString());
    emit descrip2Changed(item.value("item_descrip2").toString());
    emit uomChanged(item.value("uom_name").toString());
    emit configured(item.value("item_config").toBool());
    emit fractional(item.value("item_fractional").toBool());
    emit upcChanged(item.value("item_upccode").toString());
    
    emit valid(TRUE);

    if (completer())
      connect(this, SIGNAL(textChanged(QString)), this, SLOT(sHandleCompleter()));
  }
  else
  {
    _itemNumber = "";
    _uom        = "";
    _itemType   = "";
    _id         = -1;
    _upc        = "";
    _valid      = FALSE;

    setText("");

    emit aliasChanged("");
    emit typeChanged("");
    emit descrip1Changed("");
    emit descrip2Changed("");
    emit uomChanged("");
    emit configured(FALSE);
    emit fractional(FALSE);
    emit upcChanged("");

    emit valid(FALSE);
  }
} 
コード例 #30
0
void cashReceiptItem::populate()
{
  XSqlQuery query;

  if (_mode == cNew)
  {
    query.prepare( "SELECT aropen_cust_id, aropen_docnumber, aropen_doctype, "
                   "       aropen_docdate, aropen_duedate, "
                   "       cashrcpt_curr_id, cashrcpt_distdate, "
                   "       currToCurr(aropen_curr_id, cashrcpt_curr_id, (aropen_amount - aropen_paid), "
                   "       cashrcpt_distdate) AS f_amount, "
                   "       COALESCE(ABS(cashrcptitem_discount), 0.00) AS discount "
                   "FROM cashrcpt, aropen LEFT OUTER JOIN cashrcptitem ON (aropen_id=cashrcptitem_aropen_id) "
                   "WHERE ( (aropen_id=:aropen_id)"
                   " AND (cashrcpt_id=:cashrcpt_id))" );
    query.bindValue(":aropen_id", _aropenid);
    query.bindValue(":cashrcpt_id", _cashrcptid);
    query.exec();
    if (query.first())
    {
      _cust->setId(query.value("aropen_cust_id").toInt());
      _docNumber->setText(query.value("aropen_docnumber").toString());
      _docType->setText(query.value("aropen_doctype").toString());
      _docDate->setDate(query.value("aropen_docdate").toDate(), true);
      _dueDate->setDate(query.value("aropen_duedate").toDate());
      _discountAmount->setLocalValue(query.value("discount").toDouble());
      _openAmount->set(query.value("f_amount").toDouble(),
                       query.value("cashrcpt_curr_id").toInt(),
                       query.value("cashrcpt_distdate").toDate(), false);
      _discount->setEnabled(query.value("aropen_doctype").toString() == "I" ||
                            query.value("aropen_doctype").toString() == "D");
    } 
  }
  else if (_mode == cEdit)
  {
    query.prepare( "SELECT aropen_cust_id, aropen_docnumber, aropen_doctype, "
                   "       aropen_docdate, aropen_duedate, "
                   "       currToCurr(aropen_curr_id, cashrcpt_curr_id, (aropen_amount - aropen_paid), "
                   "       cashrcpt_distdate) AS balance, "
                   "       ABS(cashrcptitem_amount) AS cashrcptitem_amount, "
                   "       cashrcpt_curr_id, cashrcpt_distdate,  "
                   "       ABS(cashrcptitem_discount) AS discount "
                   "FROM cashrcptitem, cashrcpt, aropen "
                   "WHERE ( (cashrcptitem_cashrcpt_id=cashrcpt_id)"
                   " AND (cashrcptitem_aropen_id=aropen_id)"
                   " AND (cashrcptitem_id=:cashrcptitem_id) );" );
    query.bindValue(":cashrcptitem_id", _cashrcptitemid);
    query.exec();
    if (query.first())
    {
      _cust->setId(query.value("aropen_cust_id").toInt());
      _docNumber->setText(query.value("aropen_docnumber").toString());
      _docType->setText(query.value("aropen_doctype").toString());
      _docDate->setDate(query.value("aropen_docdate").toDate(), true);
      _dueDate->setDate(query.value("aropen_duedate").toDate());
      _openAmount->set(query.value("balance").toDouble(),
		       query.value("cashrcpt_curr_id").toInt(),
                       query.value("cashrcpt_distdate").toDate(), false);
      _amountToApply->setLocalValue(query.value("cashrcptitem_amount").toDouble());
      _discountAmount->setLocalValue(query.value("discount").toDouble());
      _discount->setEnabled(query.value("aropen_doctype").toString() == "I" ||
                            query.value("aropen_doctype").toString() == "D");
    }
//  ToDo
  }
}