Beispiel #1
0
void SoLineEdit::setId(int pId)
{
  if (pId == _id)
    return;

  XSqlQuery sohead;
  sohead.prepare( "SELECT cohead_number, cohead_cust_id, cohead_billtoname "
                  "FROM cohead, cust "
                  "WHERE ( (cohead_cust_id=cust_id)"
                  " AND (cohead_id=:sohead_id) );" );
  sohead.bindValue(":sohead_id", pId);
  sohead.exec();
  if (sohead.first())
  {
    _id     = pId;
    _number = sohead.value("cohead_number").toInt();
    _custid = sohead.value("cohead_cust_id").toInt();
    _valid  = TRUE;

    emit numberChanged(sohead.value("cohead_number").toString());
    emit custNameChanged(sohead.value("cohead_billtoname").toString());

    setText(sohead.value("cohead_number").toString());
  }
  else
  {
    _id     = -1;
    _number = -1;
    _custid = -1;
    _valid  = FALSE;

    emit numberChanged("");
    emit custNameChanged("");
    setText("");
  }

  emit newId(_id);
  emit custidChanged(_custid);
  emit numberChanged(_number);
  emit valid(_valid);

  _parsed = TRUE;
}
Beispiel #2
0
void CLineEdit::setSilentId(int pId)
{
//  Make sure there's a change
  if (pId == _id)
    return;

  if (pId != -1)
  {
    QString sql( "<? if exists(\"customer\") ?>"
                 "  SELECT cust_number,"
                 "         cust_name,"
                 "         addr_line1, addr_line2, addr_line3,"
                 "         addr_city,  addr_state, addr_postalcode,"
                 "         addr_country, cust_creditstatus, "
                 "         cntct_addr_id, cust_cntct_id "
                 "  FROM custinfo LEFT OUTER JOIN "
                 "       cntct ON (cust_cntct_id=cntct_id) LEFT OUTER JOIN "
                 "       addr  ON (cntct_addr_id=addr_id) "
                 "  WHERE ( (cust_id=<? value(\"id\") ?>) "
                 "  <? if exists(\"active\") ?>"
                 "   AND (cust_active)"
                 "  <? endif ?>"
                 "  <? if exists(\"customer_extraclause\") ?>"
                 "  AND (<? literal(\"customer_extraclause\") ?>)"
                 "  <? endif ?>"
                 "  <? if exists(\"all_extraclause\") ?>"
                 "  AND (<? literal(\"all_extraclause\") ?>)"
                 "  <? endif ?>"
                 "  )"
                 "<? endif ?>"
                 "<? if exists(\"prospect\") ?>"
                 "  <? if exists(\"customer\") ?>"
                 "    UNION"
                 "  <? endif ?>"
                 "  SELECT prospect_number AS cust_number,"
                 "         prospect_name AS cust_name,"
                 "         addr_line1, addr_line2, addr_line3,"
                 "         addr_city,  addr_state, addr_postalcode,"
                 "         addr_country, '' AS cust_creditstatus, "
                 "         cntct_addr_id, prospect_cntct_id AS cust_cntct_id "
                 "  FROM prospect LEFT OUTER JOIN "
                 "       cntct ON (prospect_cntct_id=cntct_id) LEFT OUTER JOIN "
                 "       addr  ON (cntct_addr_id=addr_id) "
                 "  WHERE ( (prospect_id=<? value(\"id\") ?>) "
                 "  <? if exists(\"active\") ?>"
                 "   AND (prospect_active)"
                 "  <? endif ?>"
                 "  <? if exists(\"prospect_extraclause\") ?>"
                 "  AND (<? literal(\"prospect_extraclause\") ?>)"
                 "  <? endif ?>"
                 "  <? if exists(\"all_extraclause\") ?>"
                 "  AND (<? literal(\"all_extraclause\") ?>)"
                 "  <? endif ?>"
                 "  )"
                 "<? endif ?>"
                 ";");

    ParameterList params;
    params.append("id", pId);
    switch (_type)
    {
      case ActiveCustomers:
        params.append("active");
        // fall-through
      case AllCustomers:
        params.append("customer");
        break;

      case ActiveProspects:
        params.append("active");
        // fall-through
      case AllProspects:
        params.append("prospect");
        break;

      case ActiveCustomersAndProspects:
        params.append("active");
        // fall-through
      case AllCustomersAndProspects:
        params.append("customer");
        params.append("prospect");
        break;
    }
    if (! _all_extraclause.isEmpty())
      params.append("all_extraclause", _all_extraclause);
    if (! _customer_extraclause.isEmpty())
      params.append("customer_extraclause", _customer_extraclause);
    if (! _prospect_extraclause.isEmpty())
      params.append("prospect_extraclause", _prospect_extraclause);

    MetaSQLQuery mql(sql);
    XSqlQuery cust = mql.toQuery(params);

    if (cust.first())
    {
      _id = pId;

      setText(cust.value("cust_number").toString());

      emit custNumberChanged(cust.value("cust_number").toString());
      emit custNameChanged(cust.value("cust_name").toString());
      emit custAddr1Changed(cust.value("addr_line1").toString());
      emit custAddr2Changed(cust.value("addr_line2").toString());
      emit custAddr3Changed(cust.value("addr_line3").toString());
      emit custCityChanged(cust.value("addr_city").toString());
      emit custStateChanged(cust.value("addr_state").toString());
      emit custZipCodeChanged(cust.value("addr_postalcode").toString());
      emit custCountryChanged(cust.value("addr_country").toString());
      emit creditStatusChanged(cust.value("cust_creditstatus").toString());
      emit custAddressChanged(cust.value("cntct_addr_id").toInt());
      emit custContactChanged(cust.value("cust_cntct_id").toInt());

      _valid = TRUE;

      return;
    }
    else if (cust.lastError().type() != QSqlError::NoError)
      QMessageBox::critical(this, tr("A System Error occurred at %1::%2.")
                            .arg(__FILE__)
                            .arg(__LINE__),
                            cust.lastError().databaseText());
//qDebug("the query: %s", cust.lastQuery().toAscii().data());
  }

//  A valid cust could not be found, clear the cust information
  _id = -1;
  setText("");

  emit custNumberChanged("");
  emit custNameChanged("");
  emit custAddr1Changed("");
  emit custAddr2Changed("");
  emit custAddr3Changed("");
  emit custCityChanged("");
  emit custStateChanged("");
  emit custZipCodeChanged("");
  emit custCountryChanged("");
  emit creditStatusChanged("");
  emit custAddressChanged(-1);
  emit custContactChanged(-1);

  _valid = FALSE;
}
Beispiel #3
0
void SoLineEdit::setId(int pId)
{
  if (pId == _id)
    return;

  if ((_x_preferences) && (pId != -1) && (_sitePrivs))
  {
    if (_x_preferences->boolean("selectedSites"))
    {
      QString sql("SELECT coitem_id "
                  "FROM coitem, itemsite "
                  "WHERE ((coitem_cohead_id=<? value(\"sohead_id\") ?>) "
                  "  AND (coitem_itemsite_id=itemsite_id) "
                  "  AND (itemsite_warehous_id NOT IN ("
                  "       SELECT usrsite_warehous_id "
                  "       FROM usrsite "
                  "       WHERE (usrsite_username=current_user)))) "
                  "UNION "
                  "SELECT cohead_warehous_id "
                  "FROM cohead "
                  "WHERE ((cohead_id=<? value(\"sohead_id\") ?>) "
                  "  AND (cohead_warehous_id NOT IN ("
                  "       SELECT usrsite_warehous_id "
                  "       FROM usrsite "
                  "       WHERE (usrsite_username=current_user))));");
      MetaSQLQuery mql(sql);
      ParameterList params;
      params.append("sohead_id", pId);
      XSqlQuery chk = mql.toQuery(params);
      if (chk.first())
      {
              QMessageBox::critical(this, tr("Access Denied"),
                                    tr("You may not view or edit this Sales Order as it references "
                                       "a warehouse for which you have not been granted privileges.")) ;
              setId(-1);
              return;
      }
    }
  }


  XSqlQuery sohead;
  sohead.prepare( "SELECT cohead_number, cohead_cust_id, cohead_billtoname "
                  "FROM cohead, cust "
                  "WHERE ( (cohead_cust_id=cust_id)"
                  " AND (cohead_id=:sohead_id) );" );
  sohead.bindValue(":sohead_id", pId);
  sohead.exec();
  if (sohead.first())
  {
    _id     = pId;
    _number = sohead.value("cohead_number").toInt();
    _custid = sohead.value("cohead_cust_id").toInt();
    _valid  = TRUE;

    emit numberChanged(sohead.value("cohead_number").toString());
    emit custNameChanged(sohead.value("cohead_billtoname").toString());

    setText(sohead.value("cohead_number").toString());
    
    if (_mapper->model() &&
        _mapper->model()->data(_mapper->model()->index(_mapper->currentIndex(),_mapper->mappedSection(this))).toString() != text())
      _mapper->model()->setData(_mapper->model()->index(_mapper->currentIndex(),_mapper->mappedSection(this)), text());
  }
  else
  {
    _id     = -1;
    _number = -1;
    _custid = -1;
    _valid  = FALSE;

    emit numberChanged("");
    emit custNameChanged("");
    setText("");
  }

  emit newId(_id);
  emit custidChanged(_custid);
  emit numberChanged(_number);
  emit valid(_valid);

  _parsed = TRUE;
}