Beispiel #1
0
void displayPrivate::print(bool showPreview)
{
  int numCopies = 1;

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

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

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

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

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

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

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

    QPrintDialog pd(&printer);
    pd.setMinMax(1, doc->pages());
    if(pd.exec() == QDialog::Accepted)
    {
      render.setPrinter(&printer);
      render.render(doc);
    }
    delete doc;
  }
}
void vendor::sCheck()
{
  _number->setText(_number->text().trimmed().toUpper());
  if (_number->text().length() && _cachedNumber != _number->text())
  {
    if(cNew == _mode && -1 != _NumberGen && _number->text().toInt() != _NumberGen)
    {
      XSqlQuery query;
      query.prepare( "SELECT releaseCRMAccountNumber(:Number);" );
      query.bindValue(":Number", _NumberGen);
      query.exec();
      ErrorReporter::error(QtCriticalMsg, this, tr("Releasing Number"),
                            query, __FILE__, __LINE__);
      _NumberGen = -1;
    }

    XSqlQuery dupq;
    dupq.prepare("SELECT vend_id, 1 AS type"
                 "  FROM vendinfo "
                 " WHERE (vend_number=:vend_number)"
                 " UNION "
                 "SELECT crmacct_id, 2 AS type "
                 "  FROM crmacct "
                 " WHERE (crmacct_number=:vend_number)"
                 " ORDER BY type;");
    dupq.bindValue(":vend_number", _number->text());
    dupq.exec();
    if (dupq.first())
    {
      if ((dupq.value("type").toInt() == 1) && (_notice))
      {
        if (QMessageBox::question(this, tr("Vendor Exists"),
                tr("<p>This number is currently "
                     "used by an existing Vendor. "
                     "Do you want to edit "
                     "that Vendor?"),
                QMessageBox::Yes,
                QMessageBox::No | QMessageBox::Default) == QMessageBox::No)
        {
          _number->setText(_cachedNumber);
          _number->setFocus();
          return;
        }
        _vendid = dupq.value("vend_id").toInt();
        _mode = cEdit;
        sPopulate();
        _name->setFocus();
      }
      else if ( (_mode == cEdit) &&
                ((dupq.value("type").toInt() == 2) ) &&
                (_notice))
      {
        QMessageBox::critical(this, tr("Invalid Number"),
                              tr("<p>This number is currently "
                                 "assigned to another Account."));
        _number->setText(_cachedNumber);
        _number->setFocus();
        _notice = false;
        return;
      }
      else if ((dupq.value("type").toInt() == 2) && (_notice))
      {
        if (QMessageBox::question(this, tr("Convert"),
                tr("<p>This number is currently assigned to Account. "
                   "Do you want to convert the Account to a Vendor?"),
                QMessageBox::Yes,
                QMessageBox::No | QMessageBox::Default) == QMessageBox::No)
        {
          _number->clear();
          _number->setFocus();
          return;
        }
        sLoadCrmAcct(dupq.value("vend_id").toInt());
      }
    }
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting Vendor"),
                                  dupq, __FILE__, __LINE__))
      return;
  }
}
bool vendor::sPopulate()
{
  if (DEBUG)
    qDebug("vendor::sPopulate() entered with _vendid %d and _crmacctid %d",
           _vendid, _crmacctid);

  MetaSQLQuery mql(
            "<? if exists('vend_id') ?>"
            "SELECT vendinfo.*, crmacct_id, crmacct_owner_username, "
            "<? if exists('key') ?>"
            "       CASE WHEN LENGTH(vend_ach_routingnumber) > 0 THEN"
            "       formatbytea(decrypt(setbytea(vend_ach_routingnumber),"
            "                           setbytea(<? value('key') ?>), 'bf'))"
            "            ELSE '' END AS routingnum,"
            "       CASE WHEN LENGTH(vend_ach_accntnumber) > 0 THEN"
            "       formatbytea(decrypt(setbytea(vend_ach_accntnumber),"
            "                           setbytea(<? value('key') ?>), 'bf'))"
            "            ELSE '' END AS accntnum "
            "<? else ?>"
            "       <? value('na') ?> AS routingnum,"
            "       <? value('na') ?> AS accntnum "
            "<? endif ?>"
            "FROM vendinfo "
            "  JOIN crmacct ON (vend_id=crmacct_vend_id) "
            "WHERE (vend_id=<? value('vend_id') ?>);"
            "<? elseif exists('crmacct_id') ?>"
            "SELECT crmacct_number AS vend_number, crmacct_name   AS vend_name,"
            "       crmacct_active AS vend_active,"
            "       crmacct_cntct_id_1 AS vend_cntct1_id,"
            "       crmacct_cntct_id_2 AS vend_cntct2_id,"
            "       fetchMetricText('DefaultPOShipVia') AS vend_shipvia,"
            "       NULL AS vend_accntnum,    NULL AS vend_vendtype_id,"
            "       NULL AS vend_name,        NULL AS vend_addr_id,"
            "       fetchMetricValue('DefaultTerms') AS vend_terms_id,"
            "       NULL  AS vend_curr_id,"
            "       FALSE AS vend_po,         FALSE AS vend_restrictpurch,"
            "       FALSE AS vend_1099,       NULL AS vend_match,"
            "       FALSE  AS vend_qualified, NULL AS vend_comments,"
            "       NULL AS vend_pocomments,  NULL AS vend_taxzone_id,"
            "       'W'  AS vend_fobsource,   NULL AS vend_fob,"
            "       NULL AS vend_ach_enabled, NULL AS routingnum,"
            "       NULL AS accntnum,         NULL AS vend_ach_use_vendinfo,"
            "       NULL AS vend_ach_indiv_number, NULL AS vend_ach_indiv_name,"
            "       NULL AS vend_ach_accnttype,"
            "       crmacct_id, crmacct_owner_username"
            "  FROM crmacct"
            " WHERE crmacct_id=<? value('crmacct_id') ?>;"
            "<? endif ?>");
  ParameterList params;
  if (_vendid > 0)
    params.append("vend_id", _vendid);
  else if (_crmacctid > 0)
    params.append("crmacct_id", _crmacctid);

  params.append("key",     omfgThis->_key);
  params.append("na",      tr("N/A"));
  XSqlQuery getq = mql.toQuery(params);
  if (getq.first())
  {
    _notice = FALSE;
    _cachedNumber = getq.value("vend_number").toString();

    _crmacctid = getq.value("crmacct_id").toInt();
    _crmowner = getq.value("crmacct_owner_username").toString();
    _number->setText(getq.value("vend_number"));
    _accountNumber->setText(getq.value("vend_accntnum"));
    _vendtype->setId(getq.value("vend_vendtype_id").toInt());
    _active->setChecked(getq.value("vend_active").toBool());
    _name->setText(getq.value("vend_name"));
    _contact1->setId(getq.value("vend_cntct1_id").toInt());
    _contact1->setSearchAcct(_crmacctid);
    _contact2->setId(getq.value("vend_cntct2_id").toInt());
    _contact2->setSearchAcct(_crmacctid);
    _address->setId(getq.value("vend_addr_id").toInt());
    _defaultTerms->setId(getq.value("vend_terms_id").toInt());
    _defaultShipVia->setText(getq.value("vend_shipvia").toString());
    _defaultCurr->setId(getq.value("vend_curr_id").toInt());
    _poItems->setChecked(getq.value("vend_po").toBool());
    _restrictToItemSource->setChecked(getq.value("vend_restrictpurch").toBool());
    _receives1099->setChecked(getq.value("vend_1099").toBool());
    _match->setChecked(getq.value("vend_match").toBool());
    _qualified->setChecked(getq.value("vend_qualified").toBool());
    _notes->setText(getq.value("vend_comments").toString());
    _poComments->setText(getq.value("vend_pocomments").toString());

    _taxzone->setId(getq.value("vend_taxzone_id").toInt());

    if (getq.value("vend_fobsource").toString() == "V")
    {
      _useVendorFOB->setChecked(TRUE);
      _vendorFOB->setText(getq.value("vend_fob"));
    }
    else
      _useWarehouseFOB->setChecked(TRUE);

    _achGroup->setChecked(getq.value("vend_ach_enabled").toBool());
    _routingNumber->setText(getq.value("routingnum").toString());
    _achAccountNumber->setText(getq.value("accntnum").toString());
    _useACHSpecial->setChecked(! getq.value("vend_ach_use_vendinfo").toBool());
    _individualId->setText(getq.value("vend_ach_indiv_number").toString());
    _individualName->setText(getq.value("vend_ach_indiv_name").toString());

    _accountType->setCode(getq.value("vend_ach_accnttype").toString());

    _account->setId(getq.value("vend_accnt_id").toInt());
    if(getq.value("vend_expcat_id").toInt() != -1)
    {
      _expcatSelected->setChecked(TRUE);
      _expcat->setId(getq.value("vend_expcat_id").toInt());
    }
    if(getq.value("vend_tax_id").toInt() != -1)
    {
      _taxSelected->setChecked(TRUE);
      _taxCode->setId(getq.value("vend_tax_id").toInt());
    }

    sFillAddressList();
    sFillTaxregList();
    sFillCharacteristic();

    _comments->setId(_crmacctid);
    _address->setSearchAcct(_crmacctid);

    emit newId(_vendid);
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting Vendor"),
                                getq, __FILE__, __LINE__))
    return false;
  else
  {
    ErrorReporter::error(QtCriticalMsg, this, tr("Getting Vendor"),
                         tr("Could not find the Vendor information. Perhaps "
                            "the Vendor and Account have been disconnected."),
                __FILE__, __LINE__);
    return false;
  }

  _crmacct->setEnabled(_crmacctid > 0 &&
                       (_privileges->check("MaintainAllCRMAccounts") ||
                        _privileges->check("ViewAllCRMAccounts") ||
                        (omfgThis->username() == _crmowner && _privileges->check("MaintainPersonalCRMAccounts")) ||
                        (omfgThis->username() == _crmowner && _privileges->check("ViewPersonalCRMAccounts"))));

  emit populated();
  return true;
}
void productCategory::sSave()
{
  XSqlQuery productSave;
  if (_category->text().trimmed().isEmpty())
  {
    QMessageBox::critical(this, tr("Missing Category"),
			  tr("You must name this Category before saving it."));
    _category->setFocus();
    return;
  }

  if (_mode == cEdit)
  {
    productSave.prepare( "SELECT prodcat_id "
               "FROM prodcat "
               "WHERE ( (prodcat_id<>:prodcat_id)"
               " AND (prodcat_code=:prodcat_code) );");
    productSave.bindValue(":prodcat_id", _prodcatid);
    productSave.bindValue(":prodcat_code", _category->text());
    productSave.exec();
    if (productSave.first())
    {
      QMessageBox::critical( this, tr("Cannot Create Product Category"),
                             tr( "A Product Category with the entered code already exists."
                                 "You may not create a Product Category with this code." ) );
      _category->setFocus();
      return;
    }

    productSave.prepare( "UPDATE prodcat "
               "SET prodcat_code=:prodcat_code, prodcat_descrip=:prodcat_descrip "
               "WHERE (prodcat_id=:prodcat_id);" );
    productSave.bindValue(":prodcat_id", _prodcatid);
    productSave.bindValue(":prodcat_code", _category->text().toUpper());
    productSave.bindValue(":prodcat_descrip", _description->text());
    productSave.exec();
  }
  else if (_mode == cNew)
  {
    productSave.prepare( "SELECT prodcat_id "
               "FROM prodcat "
               "WHERE (prodcat_code=:prodcat_code);");
    productSave.bindValue(":prodcat_code", _category->text().trimmed());
    productSave.exec();
    if (productSave.first())
    {
      QMessageBox::critical( this, tr("Cannot Create Product Category"),
                             tr( "A Product Category with the entered code already exists.\n"
                                 "You may not create a Product Category with this code." ) );
      _category->setFocus();
      return;
    }

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

    productSave.prepare( "INSERT INTO prodcat "
               "( prodcat_id, prodcat_code, prodcat_descrip ) "
               "VALUES "
               "( :prodcat_id, :prodcat_code, :prodcat_descrip );" );
    productSave.bindValue(":prodcat_id", _prodcatid);
    productSave.bindValue(":prodcat_code", _category->text().toUpper());
    productSave.bindValue(":prodcat_descrip", _description->text());
    productSave.exec();
  }

  done(_prodcatid);
}
SetResponse vendor::set(const ParameterList &pParams)
{
  XWidget::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("crmacct_id", &valid);
  if (valid)
    _crmacctid = param.toInt();

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

  if (_vendid > 0 || _crmacctid > 0)
    if (! sPopulate())
      return UndefinedError;

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

      XSqlQuery idq;
      idq.exec("SELECT NEXTVAL('vend_vend_id_seq') AS vend_id;");
      if (idq.first())
        _vendid = idq.value("vend_id").toInt();
      else if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting Id"),
                                    idq, __FILE__, __LINE__))
        return UndefinedError;

      if(((_metrics->value("CRMAccountNumberGeneration") == "A") ||
          (_metrics->value("CRMAccountNumberGeneration") == "O"))
       && _number->text().isEmpty() )
      {
        XSqlQuery numq;
        numq.exec("SELECT fetchCRMAccountNumber() AS number;");
        if (numq.first())
        {
          _number->setText(numq.value("number"));
          _NumberGen = numq.value("number").toInt();
        }
      }

      if (_privileges->check("MaintainVendorAddresses"))
      {
        connect(_vendaddr, SIGNAL(valid(bool)), _editAddress, SLOT(setEnabled(bool)));
        connect(_vendaddr, SIGNAL(valid(bool)), _deleteAddress, SLOT(setEnabled(bool)));
        connect(_vendaddr, SIGNAL(itemSelected(int)), _editAddress, SLOT(animateClick()));
      }
      else
      {
        _newAddress->setEnabled(FALSE);
        connect(_vendaddr, SIGNAL(itemSelected(int)), _viewAddress, SLOT(animateClick()));
      }

      connect(_charass, SIGNAL(valid(bool)), _editCharacteristic, SLOT(setEnabled(bool)));
      connect(_charass, SIGNAL(valid(bool)), _deleteCharacteristic, SLOT(setEnabled(bool)));

      emit newId(_vendid);
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;

      if (_privileges->check("MaintainVendorAddresses"))
      {
        connect(_vendaddr, SIGNAL(valid(bool)), _editAddress, SLOT(setEnabled(bool)));
        connect(_vendaddr, SIGNAL(valid(bool)), _deleteAddress, SLOT(setEnabled(bool)));
        connect(_vendaddr, SIGNAL(itemSelected(int)), _editAddress, SLOT(animateClick()));
      }
      else
      {
        _newAddress->setEnabled(FALSE);
        connect(_vendaddr, SIGNAL(itemSelected(int)), _viewAddress, SLOT(animateClick()));
      }

      connect(_charass, SIGNAL(valid(bool)), _editCharacteristic, SLOT(setEnabled(bool)));
      connect(_charass, SIGNAL(valid(bool)), _deleteCharacteristic, SLOT(setEnabled(bool)));
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _number->setEnabled(FALSE);
      _vendtype->setEnabled(FALSE);
      _active->setEnabled(FALSE);
      _name->setEnabled(FALSE);
      _accountNumber->setEnabled(FALSE);
      _defaultTerms->setEnabled(FALSE);
      _defaultShipVia->setEnabled(FALSE);
      _defaultCurr->setEnabled(FALSE);
      _contact1->setEnabled(FALSE);
      _contact2->setEnabled(FALSE);
      _address->setEnabled(FALSE);
      _notes->setReadOnly(TRUE);
      _poComments->setReadOnly(TRUE);
      _poItems->setEnabled(FALSE);
      _restrictToItemSource->setEnabled(FALSE);
      _receives1099->setEnabled(FALSE);
      _qualified->setEnabled(FALSE);
      _newAddress->setEnabled(FALSE);
      _defaultFOBGroup->setEnabled(false);
      _taxzone->setEnabled(false);
      _match->setEnabled(false);
      _newTaxreg->setEnabled(false);
      _comments->setReadOnly(TRUE);
      _newCharacteristic->setEnabled(FALSE);

      _achGroup->setEnabled(false);
      _routingNumber->setEnabled(false);
      _achAccountNumber->setEnabled(false);
      _individualId->setEnabled(false);
      _individualName->setEnabled(false);
      _accountType->setEnabled(false);
      _distribGroup->setEnabled(false);

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

      disconnect(_taxreg, SIGNAL(valid(bool)), _deleteTaxreg, SLOT(setEnabled(bool)));
      disconnect(_taxreg, SIGNAL(valid(bool)), _editTaxreg, SLOT(setEnabled(bool)));
      disconnect(_taxreg, SIGNAL(itemSelected(int)), _editTaxreg, SLOT(animateClick()));
      connect(_taxreg, SIGNAL(itemSelected(int)), _viewTaxreg, SLOT(animateClick()));

    }
  }

  if(_metrics->value("CRMAccountNumberGeneration") == "A")
    _number->setEnabled(FALSE);

  if(cNew == _mode || !pParams.inList("showNextPrev"))
  {
    _next->hide();
    _previous->hide();
  }

  return NoError;
}
Beispiel #6
0
void itemSource::sVendorChanged( int pId )
{
  XSqlQuery vendorChanged;
  vendorChanged.prepare("SELECT vend_curr_id "
                        "FROM vendinfo "
                        "WHERE (vend_id = :vend_id)");
  vendorChanged.bindValue(":vend_id", pId);
  vendorChanged.exec();
  if (vendorChanged.first())
  {
    _vendorCurrency->setId(vendorChanged.value("vend_curr_id").toInt());
  }
  else if (vendorChanged.lastError().type() != QSqlError::NoError)
  {
    systemError(this, vendorChanged.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  vendorChanged.prepare("SELECT contrct_id, contrct_number "
                        "FROM contrct "
                        "WHERE (contrct_vend_id = :vend_id)");
  vendorChanged.bindValue(":vend_id", pId);
  vendorChanged.exec();
  _contract->populate(vendorChanged);
  if (vendorChanged.lastError().type() != QSqlError::NoError)
  {
    systemError(this, vendorChanged.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
Beispiel #7
0
void docAttach::sSave()
{  
  XSqlQuery newDocass;
  QString title;
  QUrl url;

  //set the purpose
  if (_docAttachPurpose->currentIndex() == 0)
    _purpose = "S";
  else if (_docAttachPurpose->currentIndex() == 1)
    _purpose = "A";
  else if (_docAttachPurpose->currentIndex() == 2)
    _purpose = "C";
  else if (_docAttachPurpose->currentIndex() == 3)
    _purpose = "D";

  //if then series, type derived from the stack index. e.g.
  if (_docType->currentIndex() == 1)
  {
    _targettype = "T";
    _targetid = _cntct->id();
  }
  else if (_docType->currentIndex() == 2)
  {
    _targettype = "CRMA";
    _targetid = _crmacct->id();
  }
  else if (_docType->currentIndex() == 3)
  {
    _targettype = "C";
    _targetid = _cust->id();
  }
  else if (_docType->currentIndex() == 4)
  {
    _targettype = "EMP";
    _targetid = _emp->id();
  }
  else if (_docType->currentIndex() == 5)
  {
    if(_file->text().trimmed().isEmpty())
    {
      QMessageBox::warning( this, tr("Must Specify file"),
                            tr("You must specify a file before you may save.") );
      return;
    }

     _targettype = "URL";
     title = _filetitle->text();
     url = QUrl(_file->text());
     if (url.scheme().isEmpty())
       url.setScheme("file");
  }
  else if (_docType->currentIndex() == 6)
  {
     _targettype = "IMG";
     _targetid = _img->id();
  }
  else if (_docType->currentIndex() == 7)
  {
    _targettype = "INCDT";
    _targetid = _incdt->id();
  }
  else if (_docType->currentIndex() == 8)
  {
    _targettype = "I";
    _targetid = _item->id();
  }
  else if (_docType->currentIndex() == 9)
  {
    _targettype = "OPP";
    _targetid = _opp->id();
  }
  else if (_docType->currentIndex() == 10)
  {
    _targettype = "J";
    _targetid = _proj->id();
  }
  else if (_docType->currentIndex() == 11)
  {
    _targettype = "P";
    _targetid = _po->id();
  }
  else if (_docType->currentIndex() == 12)
  {
    _targettype = "S";
    _targetid = _so->id();
  }
  else if (_docType->currentIndex() == 13)
  {
    _targettype = "V";
    _targetid = _vend->id();
  }
  else if (_docType->currentIndex() == 14)
  {
    if(_url->text().trimmed().isEmpty())
    {
      QMessageBox::warning( this, tr("Must Specify file"),
                            tr("You must specify a file before you may save.") );
      return;
    }

    _targettype = "URL";
    title = _urltitle->text();
    url = QUrl(_url->text());
    if (url.scheme().isEmpty())
      url.setScheme("http");
  }
  else if (_docType->currentIndex() == 15)
  {
    _targettype = "W";
    _targetid = _wo->id();
  }

  if (_targettype == "IMG")
  {
     // For now images are handled differently because of legacy structures...
    newDocass.prepare( "INSERT INTO imageass "
                       "( imageass_source, imageass_source_id, imageass_image_id, imageass_purpose ) "
                       "VALUES "
                       "( :docass_source_type, :docass_source_id, :docass_target_id, :docass_purpose );" );
  }
  else if (_targettype == "URL")
  {
    if(!url.isValid())
    {
      QMessageBox::warning( this, tr("Must Specify valid path"),
                            tr("You must specify a path before you may save.") );
      return;
    }

    QByteArray  bytarr;
    QFileInfo fi(url.toLocalFile());

    if(_saveDbCheck->isChecked() &&
       (url.scheme()=="file") &&
       (_mode == "new"))
    {
      if (!fi.exists())
      {
        QMessageBox::warning( this, tr("File Error"),
                             tr("File %1 was not found and will not be saved.").arg(url.toLocalFile()));
        return;
      }
      QFile sourceFile(url.toLocalFile());
      if (!sourceFile.open(QIODevice::ReadOnly))
      {
        QMessageBox::warning( this, tr("File Open Error"),
                             tr("Could not open source file %1 for read.")
                                .arg(url.toLocalFile()));
        return;
      }
      bytarr = sourceFile.readAll();
      url.setPath(fi.fileName().remove(" "));
      url.setScheme("");
    }

    // For now urls are handled differently because of legacy structures...
    if (_mode == "new")
      newDocass.prepare( "INSERT INTO url "
                         "( url_source, url_source_id, url_title, url_url, url_stream ) "
                         "VALUES "
                         "( :docass_source_type, :docass_source_id, :title, :url, :stream );" );
    else
      newDocass.prepare( "UPDATE url SET "
                         "  url_title = :title, "
                         "  url_url = :url "
                         "WHERE (url_id=:url_id);" );
    newDocass.bindValue(":url_id", _urlid);
    newDocass.bindValue(":title", title);
    newDocass.bindValue(":url", url.toString());
    newDocass.bindValue(":stream", bytarr);
  }
  else
  {
    newDocass.prepare( "INSERT INTO docass "
                       "( docass_source_type, docass_source_id, docass_target_type, docass_target_id, docass_purpose ) "
                       "VALUES "
                       "( :docass_source_type, :docass_source_id, :docass_target_type, :docass_target_id, :docass_purpose );" );
    newDocass.bindValue(":docass_target_type", _targettype);
  }

  if (_targettype == Documents::_documentMap[_source].ident &&
      _targetid == _sourceid)
  {
    QMessageBox::critical(this,tr("Invalid Selection"),
                          tr("You may not attach a document to itself."));
    return;
  }

  newDocass.bindValue(":docass_source_type", Documents::_documentMap[_source].ident);
  newDocass.bindValue(":docass_source_id", _sourceid);
  newDocass.bindValue(":docass_target_id", _targetid);
  newDocass.bindValue(":docass_purpose", _purpose);

  newDocass.exec();

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

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

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

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

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

  int foid = 0;

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

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

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

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

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

    _item->setFocus();
  }
}
Beispiel #9
0
void plannedOrder::populate()
{
  XSqlQuery planord;
  planord.prepare( "SELECT planord.*, (planord_duedate - planord_startdate) AS leadtime,"
                   "       itemsite_warehous_id AS supplywarehousid "
                   "FROM planord LEFT OUTER JOIN itemsite ON (planord_supply_itemsite_id=itemsite_id) "
                   "WHERE (planord_id=:planord_id);" );
  planord.bindValue(":planord_id", _planordid);
  planord.exec();
  if (planord.first())
  {
    _number->setText(planord.value("planord_number").toString());
    _item->setItemsiteid(planord.value("planord_itemsite_id").toInt());
    _qty->setDouble(planord.value("planord_qty").toDouble());
    _dueDate->setDate(planord.value("planord_duedate").toDate());
    _startDate->setDate(planord.value("planord_startdate").toDate());
    _leadTime->setValue(planord.value("leadtime").toInt());
    _notes->setText(planord.value("planord_comments").toString());
    if (planord.value("planord_type").toString() == "P")
      _poButton->setChecked(TRUE);
    else if (planord.value("planord_type").toString() == "W")
      _woButton->setChecked(TRUE);
    else
    {
      _toButton->setChecked(TRUE);
      _fromWarehouse->setId(planord.value("supplywarehousid").toInt());
    }
  }
  else if (planord.lastError().type() != QSqlError::NoError)
  {
    systemError(this, planord.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
Beispiel #10
0
enum SetResponse itemCost::set(const ParameterList &pParams)
{
  XSqlQuery itemet;
  XDialog::set(pParams);
  _captive = true;

  QVariant param;
  bool     valid;

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

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

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

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

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

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

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

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

  sPopulateCostelem();

  return _foundCostElems ? NoError : UndefinedError;
}
Beispiel #11
0
void itemPricingSchedule::populate()
{
  XSqlQuery pop;
  pop.prepare( "SELECT ipshead_name, ipshead_descrip,"
             "       ipshead_effective, ipshead_expires, "
	     "       ipshead_curr_id, ipshead_updated "
             "FROM ipshead "
             "WHERE (ipshead_id=:ipshead_id);" );
  pop.bindValue(":ipshead_id", _ipsheadid);
  pop.exec();
  if (pop.first())
  {
    _name->setText(pop.value("ipshead_name").toString());
    _descrip->setText(pop.value("ipshead_descrip").toString());
    _dates->setStartDate(pop.value("ipshead_effective").toDate());
    _dates->setEndDate(pop.value("ipshead_expires").toDate());
    _currency->setId(pop.value("ipshead_curr_id").toInt());
    _currency->setEnabled(FALSE);
    QDate tmpDate = pop.value("ipshead_updated").toDate();
    if (tmpDate.isValid() && ! tmpDate.isNull())
	_updated = tmpDate;

    sFillList(-1);
  }
  else if (q.lastError().type() != QSqlError::None)
  {
	systemError(this, _rejectedMsg.arg(q.lastError().databaseText()),
                  __FILE__, __LINE__);
		  reject();
  }
}
Beispiel #12
0
void itemCost::sPopulateCostelem()
{
  XSqlQuery itemPopulateCostelem;
  if (_type == cItemCost)
  {
    if (_mode == cNew)
    {
      ParameterList params;
      params.append("item_id", _item->id());
      params.append("itemtype", _item->itemType());

      itemPopulateCostelem = mqlLoad("costelem", "unusedbyitem").toQuery(params);
      _costelem->populate(itemPopulateCostelem);
      if (itemPopulateCostelem.size() <= 0)
      {
        QMessageBox::warning(this, tr("No Costing Elements Remaining"),
                             tr("<p>Item %1 already has all available costing "
                                "elements assigned. No new Item Costs can be "
                                "created for it until more costing elements are "
                                "defined.")
                             .arg(_item->itemNumber()));
        _foundCostElems = false;
      }
    }
    else // _mode == cEdit || cView)
    {
      QString sql( "SELECT costelem_id, costelem_type "
                   "FROM costelem, itemcost "
                   "WHERE ((costelem_id=itemcost_costelem_id)"
                   "  AND  (itemcost_id=:itemcost_id));");
      itemPopulateCostelem.prepare(sql);
      itemPopulateCostelem.bindValue(":itemcost_id", _itemcostid);
      itemPopulateCostelem.exec();
      _costelem->populate(itemPopulateCostelem);
    }
  }
  if (_type == cBOMItemCost)
  {
    if (_mode == cNew)
    {
      ParameterList params;
      params.append("bomitem_id", _bomitemid);
      params.append("itemtype", _item->itemType());

      itemPopulateCostelem = mqlLoad("costelem", "unusedbyitem").toQuery(params);
      _costelem->populate(itemPopulateCostelem);
      if (itemPopulateCostelem.size() <= 0)
      {
        QMessageBox::warning(this, tr("No Costing Elements Remaining"),
                             tr("<p>BOM Item %1 already has all available costing "
                                "elements assigned. No new BOM Item Costs can be "
                                "created for it until more costing elements are "
                                "defined.")
                             .arg(_item->itemNumber()));
        _foundCostElems = false;
      }
    }
    else // _mode == cEdit || cView)
    {
      QString sql( "SELECT costelem_id, costelem_type "
                   "FROM costelem, bomitemcost "
                   "WHERE ((costelem_id=bomitemcost_costelem_id)"
                   "  AND  (bomitemcost_id=:itemcost_id));");
      itemPopulateCostelem.prepare(sql);
      itemPopulateCostelem.bindValue(":itemcost_id", _itemcostid);
      itemPopulateCostelem.exec();
      _costelem->populate(itemPopulateCostelem);
    }
  }
}
Beispiel #13
0
void itemCost::sSave()
{
  XSqlQuery itemSave;
  if (_mode != cNew && _mode != cEdit)
    done(_itemcostid);

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

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

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

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

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

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

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

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

  done(_itemcostid);
}
Beispiel #14
0
void maintainItemCosts::sFillList()
{
  if (_item->isValid())
  {
    double standardCost = 0.0;
    double actualCostBase = 0.0;
    double actualCostLocal = 0.0;

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

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

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

  }
  else
    _itemcost->clear();
}
Beispiel #15
0
itemSource::itemSource(QWidget* parent, const char* name, bool modal, Qt::WFlags fl)
    : XDialog(parent, name, modal, fl)
{
  XSqlQuery itemitemSource;
  setupUi(this);

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

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

  _vendorUOM->setType(XComboBox::UOMs);

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

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

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

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

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

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

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

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

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

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

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

  if (plannedHandleItemsite.value("supplyitemsiteid").toInt() != -1)
  {
    _toButton->setChecked(TRUE);
    _fromWarehouse->setId(plannedHandleItemsite.value("supplywarehousid").toInt());
  }
  else
    _fromWarehouse->setId(pWarehousid);
}
Beispiel #17
0
void itemSource::populate()
{
  XSqlQuery itemsrcQ;
  itemsrcQ.prepare( "SELECT * "
                    "FROM itemsrc "
                    "WHERE (itemsrc_id=:itemsrc_id);" );
  itemsrcQ.bindValue(":itemsrc_id", _itemsrcid);
  itemsrcQ.exec();
  if (itemsrcQ.first())
  {
    _item->setId(itemsrcQ.value("itemsrc_item_id").toInt());
    _active->setChecked(itemsrcQ.value("itemsrc_active").toBool());
    _default->setChecked(itemsrcQ.value("itemsrc_default").toBool());
    _vendor->setId(itemsrcQ.value("itemsrc_vend_id").toInt());
    _contract->setId(itemsrcQ.value("itemsrc_contrct_id").toInt());
    _dates->setStartDate(itemsrcQ.value("itemsrc_effective").toDate());
    _dates->setEndDate(itemsrcQ.value("itemsrc_expires").toDate());
    _vendorItemNumber->setText(itemsrcQ.value("itemsrc_vend_item_number").toString());
    _vendorItemDescrip->setText(itemsrcQ.value("itemsrc_vend_item_descrip").toString());
    _vendorUOM->setCode(itemsrcQ.value("itemsrc_vend_uom").toString());
    _invVendorUOMRatio->setDouble(itemsrcQ.value("itemsrc_invvendoruomratio").toDouble());
    _upcCode->setText(itemsrcQ.value("itemsrc_upccode"));
    _minOrderQty->setDouble(itemsrcQ.value("itemsrc_minordqty").toDouble());
    _multOrderQty->setDouble(itemsrcQ.value("itemsrc_multordqty").toDouble());
    _vendorRanking->setValue(itemsrcQ.value("itemsrc_ranking").toInt());
    _leadTime->setValue(itemsrcQ.value("itemsrc_leadtime").toInt());
    _notes->setText(itemsrcQ.value("itemsrc_comments").toString());
    _manufName->setCode(itemsrcQ.value("itemsrc_manuf_name").toString());
    _manufItemNumber->setText(itemsrcQ.value("itemsrc_manuf_item_number").toString());
    _manufItemDescrip->setText(itemsrcQ.value("itemsrc_manuf_item_descrip").toString());
    sFillPriceList();
  }
  else if (itemsrcQ.lastError().type() != QSqlError::NoError)
  {
    systemError(this, itemsrcQ.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
Beispiel #18
0
void package::sSave()
{
  XSqlQuery packageSave;
  if (_mode == cNew)
  {
    packageSave.exec("SELECT NEXTVAL('pkghead_pkghead_id_seq') AS _pkghead_id");
    if (packageSave.first())
      _pkgheadid = packageSave.value("_pkghead_id").toInt();
    else if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Retrieving Package Information"),
                                  packageSave, __FILE__, __LINE__))
    {
      return;
    }

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

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

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

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

  done(_pkgheadid);
}
Beispiel #19
0
enum SetResponse dspInventoryAvailability::set(const ParameterList &pParams)
{
    XWidget::set(pParams);
    QVariant param;
    bool     valid;

    parameterWidget()->setSavedFilters();

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

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

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

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

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

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

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

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

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

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

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

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

    parameterWidget()->applyDefaultFilterSet();

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

    return NoError;
}
Beispiel #20
0
void package::populate()
{
  XSqlQuery packagepopulate;
  if (DEBUG)    qDebug("package::populate() entered");

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

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

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

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

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

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

}
Beispiel #21
0
void unpostedGlSeries::sFillList()
{
  XSqlQuery fillq;
  fillq.prepare("SELECT *, "
		"       (formatGLAccount(glseries_accnt_id) || ' - ' ||"
		"                        accnt_descrip) AS account,"
		"       CASE WHEN (glseries_amount < 0) THEN"
		"           formatMoney(glseries_amount * -1)"
		"       ELSE '' END AS debit,"
		"       CASE WHEN (glseries_amount >= 0) THEN"
		"           formatMoney(glseries_amount)"
		"       ELSE '' END AS credit "
	        "FROM glseries, accnt "
		"WHERE (glseries_accnt_id=accnt_id) "
		"ORDER BY glseries_distdate, glseries_sequence, glseries_amount;");
  _glseries->clear();
  XTreeWidgetItem *line = 0;
  fillq.exec();
  while (fillq.next())
  {
    line = new XTreeWidgetItem(_glseries, line,
			       fillq.value("glseries_id").toInt(),
			       fillq.value("glseries_sequence").toInt(),
			       fillq.value("glseries_distdate"),
			       fillq.value("glseries_source"),
			       fillq.value("glseries_doctype"),
			       fillq.value("glseries_docnumber"),
			       fillq.value("glseries_notes"),
			       fillq.value("account"),
			       fillq.value("debit"),
			       fillq.value("credit"));
  }
  if (fillq.lastError().type() != QSqlError::None)
  {
    systemError(this, fillq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
void reassignLotSerial::sReassign()
{
  XSqlQuery reassignReassign;
  if (_expirationDate->isEnabled())
  {
    if (!_expirationDate->isValid() || _expirationDate->isNull())
    {
      QMessageBox::critical( this, tr("Enter a valid date"),
                             tr("You must enter a valid expiration date before you can continue.") );
      _expirationDate->setFocus();
      return;
    }
  }
	
  if (_source->currentItem() == 0)
  {
    QMessageBox::critical( this, tr("Select Source Location"),
                           tr("You must select a Source Location before reassigning its Lot/Serial #.") );
    _source->setFocus();
    return;
  }

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

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

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

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

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

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

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

    sFillList();

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

    _qty->setFocus();
    _lotNumber->clear();
    _expirationDate->setNull();
    _warrantyDate->setNull();
  }
}
Beispiel #23
0
int todoList::getProjectId()
{
  int returnVal = -1;

  if (_todoList->currentItem()->altId() == 4)
    returnVal = _todoList->id();
  else if (_todoList->currentItem()->altId() == 3)
  {
    XSqlQuery prj;
    prj.prepare("SELECT prjtask_prj_id FROM prjtask WHERE (prjtask_id=:prjtask_id);");
    prj.bindValue(":prjtask_id", _todoList->id());
    if (prj.exec() && prj.first())
     returnVal = prj.value("prjtask_prj_id").toInt();
    else if (prj.lastError().type() != QSqlError::NoError)
     systemError(this, prj.lastError().databaseText(), __FILE__, __LINE__);
  }
  else if (! _todoList->currentItem()->text(9).isEmpty())
  {
    XSqlQuery prj;
    prj.prepare("SELECT prj_id FROM prj WHERE (prj_number=:number);");
    prj.bindValue(":number", _todoList->currentItem()->text(9));
    if (prj.exec() && prj.first())
     returnVal = prj.value("prj_id").toInt();
    else if (prj.lastError().type() != QSqlError::NoError)
     systemError(this, prj.lastError().databaseText(), __FILE__, __LINE__);
  }
  return returnVal;
}
void reassignLotSerial::sFillList()
{
  XSqlQuery reassignFillList;
  if (_item->isValid())
  {
    reassignFillList.prepare( "SELECT itemsite_id, itemsite_perishable, itemsite_controlmethod, itemsite_warrpurc "
               "FROM itemsite "
               "WHERE ( (itemsite_item_id=:item_id)"
               " AND (itemsite_warehous_id=:warehous_id) );" );
    reassignFillList.bindValue(":item_id", _item->id());
    reassignFillList.bindValue(":warehous_id", _warehouse->id());
    reassignFillList.exec();
    if (reassignFillList.first())
    {
      if (reassignFillList.value("itemsite_controlmethod").toString() == "S")
      {
        _qty->setEnabled(FALSE);
        _qty->setDouble(1.0);
      }
      else if (reassignFillList.value("itemsite_controlmethod").toString() == "L")
        _qty->setEnabled(TRUE);
      else
      {
        _source->clear();
        return;
      }

      int itemsiteid = reassignFillList.value("itemsite_id").toInt();
      _expirationDate->setEnabled(reassignFillList.value("itemsite_perishable").toBool());
      _warrantyDate->setEnabled(reassignFillList.value("itemsite_warrpurc").toBool());

      reassignFillList.prepare( "SELECT itemloc_id, formatLocationName(itemloc_location_id) AS locationname, ls_number,"
                 "       itemloc_expiration, itemloc_warrpurc, itemloc_qty, "
                 "       'qty' AS itemloc_qty_xtnumericrole "
                 "FROM itemloc "
                 "  LEFT OUTER JOIN ls ON (itemloc_ls_id=ls_id), itemsite "
                 "WHERE ( (itemloc_itemsite_id=itemsite_id)"
                 " AND (itemsite_id=:itemsite_id) ) "
                 "ORDER BY locationname;" );
      reassignFillList.bindValue(":never", tr("Never"));
      reassignFillList.bindValue(":itemsite_id", itemsiteid);
      reassignFillList.exec();
      _source->populate(reassignFillList);
    }
    else if (reassignFillList.lastError().type() != QSqlError::NoError)
    {
      systemError(this, reassignFillList.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else
    _source->clear();
}
void vendor::sSave()
{
  XSqlQuery vendorSave;
  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(_number->text().trimmed().isEmpty(), _number,
                          tr("Please enter a Number for this new Vendor."))
         << GuiErrorCheck(_name->text().trimmed().isEmpty(), _name,
                          tr("Please enter a Name for this new Vendor."))
         << GuiErrorCheck(_defaultTerms->id() == -1, _defaultTerms,
                          tr("You must select a Terms code for this Vendor."))
         << GuiErrorCheck(_vendtype->id() == -1, _vendtype,
                          tr("You must select a Vendor Type for this Vendor."))
//         << GuiErrorCheck(_accountSelected->isChecked() &&
//                          !_account->isValid(),
//                          _account
//                          tr("You must select a Default Distribution Account for this Vendor."))
//         << GuiErrorCheck(_expcatSelected->isChecked() &&
//                          !_expcat->isValid(),
//                          _expcat
//                          tr("You must select a Default Distribution Expense Category for this Vendor."))
//         << GuiErrorCheck(_taxSelected->isChecked() &&
//                          !_taxCode->isValid(),
//                          _taxCode
//                          tr("You must select a Default Distribution Tax Code for this Vendor."))
         << GuiErrorCheck(_achGroup->isChecked() &&
                          ! _routingNumber->hasAcceptableInput() &&
                          !omfgThis->_key.isEmpty(),
                          _routingNumber,
                          tr("The Routing Number is not valid."))
         << GuiErrorCheck(_achGroup->isChecked() &&
                          ! _achAccountNumber->hasAcceptableInput() &&
                          !omfgThis->_key.isEmpty(), _achAccountNumber,
                          tr("The Account Number is not valid."))
         << GuiErrorCheck(_achGroup->isChecked() &&
                          _useACHSpecial->isChecked() &&
                          _individualName->text().trimmed().isEmpty() &&
                          !omfgThis->_key.isEmpty(),
                          _individualName,
                          tr("Please enter an Individual Name if EFT Check "
                             "Printing is enabled and '%1' is checked.")
                            .arg(_useACHSpecial->title()))
    ;

  if (_number->text().trimmed().toUpper() != _cachedNumber.toUpper())
  {
    XSqlQuery dupq;
    dupq.prepare("SELECT vend_name "
                 "FROM vendinfo "
                 "WHERE (UPPER(vend_number)=UPPER(:vend_number)) "
                 "  AND (vend_id<>:vend_id);" );
    dupq.bindValue(":vend_number", _number->text().trimmed());
    dupq.bindValue(":vend_id", _vendid);
    dupq.exec();
    if (dupq.first())
      GuiErrorCheck(true, _number,
			    tr("<p>The newly entered Vendor Number cannot be "
                               "used as it is already used by the Vendor '%1'. "
                               "Please correct or enter a new Vendor Number." )
			     .arg(vendorSave.value("vend_name").toString()) );
  }

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

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

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

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

  QString sql;
  if (_mode == cEdit)
  {
    sql = "UPDATE vendinfo "
          "SET vend_number=<? value(\"vend_number\") ?>,"
          "    vend_accntnum=<? value(\"vend_accntnum\") ?>,"
          "    vend_active=<? value(\"vend_active\") ?>,"
          "    vend_vendtype_id=<? value(\"vend_vendtype_id\") ?>,"
          "    vend_name=<? value(\"vend_name\") ?>,"
          "    vend_cntct1_id=<? value(\"vend_cntct1_id\") ?>,"
          "    vend_cntct2_id=<? value(\"vend_cntct2_id\") ?>,"
	  "    vend_addr_id=<? value(\"vend_addr_id\") ?>,"
          "    vend_po=<? value(\"vend_po\") ?>,"
          "    vend_restrictpurch=<? value(\"vend_restrictpurch\") ?>,"
          "    vend_1099=<? value(\"vend_1099\") ?>,"
          "    vend_qualified=<? value(\"vend_qualified\") ?>,"
          "    vend_comments=<? value(\"vend_comments\") ?>,"
          "    vend_pocomments=<? value(\"vend_pocomments\") ?>,"
          "    vend_fobsource=<? value(\"vend_fobsource\") ?>,"
          "    vend_fob=<? value(\"vend_fob\") ?>,"
          "    vend_terms_id=<? value(\"vend_terms_id\") ?>,"
          "    vend_shipvia=<? value(\"vend_shipvia\") ?>,"
	  "    vend_curr_id=<? value(\"vend_curr_id\") ?>,"
          "    vend_taxzone_id=<? value(\"vend_taxzone_id\") ?>,"
          "    vend_match=<? value(\"vend_match\") ?>,"
          "    vend_ach_enabled=<? value(\"vend_ach_enabled\") ?>,"
          "<? if exists(\"key\") ?>"
          "    vend_ach_routingnumber=encrypt(setbytea(<? value(\"vend_ach_routingnumber\") ?>),"
          "                             setbytea(<? value(\"key\") ?>), 'bf'),"
          "    vend_ach_accntnumber=encrypt(setbytea(<? value(\"vend_ach_accntnumber\") ?>),"
          "                           setbytea(<? value(\"key\") ?>), 'bf'),"
          "<? endif ?>"
          "    vend_ach_use_vendinfo=<? value(\"vend_ach_use_vendinfo\") ?>,"
          "    vend_ach_accnttype=<? value(\"vend_ach_accnttype\") ?>,"
          "    vend_ach_indiv_number=<? value(\"vend_ach_indiv_number\") ?>,"
          "    vend_ach_indiv_name=<? value(\"vend_ach_indiv_name\") ?>,"
          "    vend_accnt_id=<? value(\"vend_accnt_id\") ?>,"
          "    vend_expcat_id=<? value(\"vend_expcat_id\") ?>,"
          "    vend_tax_id=<? value(\"vend_tax_id\") ?> "
          "WHERE (vend_id=<? value(\"vend_id\") ?>);" ;
  }
  else if (_mode == cNew)
    sql = "INSERT INTO vendinfo "
          "( vend_id, vend_number, vend_accntnum,"
          "  vend_active, vend_vendtype_id, vend_name,"
          "  vend_cntct1_id, vend_cntct2_id, vend_addr_id,"
          "  vend_po, vend_restrictpurch,"
          "  vend_1099, vend_qualified,"
          "  vend_comments, vend_pocomments,"
          "  vend_fobsource, vend_fob,"
          "  vend_terms_id, vend_shipvia, vend_curr_id,"
          "  vend_taxzone_id, vend_match, vend_ach_enabled,"
          "  vend_ach_routingnumber, vend_ach_accntnumber,"
          "  vend_ach_use_vendinfo,"
          "  vend_ach_accnttype, vend_ach_indiv_number,"
          "  vend_ach_indiv_name,"
          "  vend_accnt_id, vend_expcat_id, vend_tax_id) "
          "VALUES "
          "( <? value(\"vend_id\") ?>,"
          "  <? value(\"vend_number\") ?>,"
          "  <? value(\"vend_accntnum\") ?>,"
          "  <? value(\"vend_active\") ?>,"
          "  <? value(\"vend_vendtype_id\") ?>,"
          "  <? value(\"vend_name\") ?>,"
          "  <? value(\"vend_cntct1_id\") ?>,"
          "  <? value(\"vend_cntct2_id\") ?>,"
          "  <? value(\"vend_addr_id\") ?>,"
          "  <? value(\"vend_po\") ?>,"
          "  <? value(\"vend_restrictpurch\") ?>,"
          "  <? value(\"vend_1099\") ?>,"
          "  <? value(\"vend_qualified\") ?>,"
          "  <? value(\"vend_comments\") ?>,"
          "  <? value(\"vend_pocomments\") ?>,"
          "  <? value(\"vend_fobsource\") ?>,"
          "  <? value(\"vend_fob\") ?>,"
          "  <? value(\"vend_terms_id\") ?>,"
          "  <? value(\"vend_shipvia\") ?>,"
          "  <? value(\"vend_curr_id\") ?>, "
          "  <? value(\"vend_taxzone_id\") ?>,"
          "  <? value(\"vend_match\") ?>,"
          "  <? value(\"vend_ach_enabled\") ?>,"
          "<? if exists(\"key\") ?>"
          "  encrypt(setbytea(<? value(\"vend_ach_routingnumber\") ?>),"
          "          setbytea(<? value(\"key\") ?>), 'bf'),"
          "  encrypt(setbytea(<? value(\"vend_ach_accntnumber\") ?>),"
          "          setbytea(<? value(\"key\") ?>), 'bf'),"
          "<? else ?>"
          "  '',"
          "  '',"
          "<? endif ?>"
          "  <? value(\"vend_ach_use_vendinfo\") ?>,"
          "  <? value(\"vend_ach_accnttype\") ?>,"
          "  <? value(\"vend_ach_indiv_number\") ?>,"
          "  <? value(\"vend_ach_indiv_name\") ?>,"
          "  <? value(\"vend_accnt_id\") ?>,"
          "  <? value(\"vend_expcat_id\") ?>,"
          "  <? value(\"vend_tax_id\") ?> "
          "   );"  ;

  ParameterList params;
  params.append("vend_id", _vendid);
  params.append("vend_vendtype_id", _vendtype->id());
  params.append("vend_terms_id", _defaultTerms->id());
  params.append("vend_curr_id", _defaultCurr->id());

  params.append("vend_number",   _number->text().trimmed().toUpper());
  params.append("vend_accntnum", _accountNumber->text().trimmed());
  params.append("vend_name",     _name->text().trimmed());

  if (_contact1->id() > 0)
    params.append("vend_cntct1_id", _contact1->id());		// else NULL
  if (_contact2->id() > 0)
    params.append("vend_cntct2_id", _contact2->id());		// else NULL
  if (_address->id() > 0)
    params.append("vend_addr_id", _address->id());		// else NULL

  params.append("vend_comments",   _notes->toPlainText());
  params.append("vend_pocomments", _poComments->toPlainText());
  params.append("vend_shipvia",    _defaultShipVia->text());

  params.append("vend_active",        QVariant(_active->isChecked()));
  params.append("vend_po",            QVariant(_poItems->isChecked()));
  params.append("vend_restrictpurch", QVariant(_restrictToItemSource->isChecked()));
  params.append("vend_1099",          QVariant(_receives1099->isChecked()));
  params.append("vend_qualified",     QVariant(_qualified->isChecked()));
  params.append("vend_match",         QVariant(_match->isChecked()));

  if (!omfgThis->_key.isEmpty())
    params.append("key",                   omfgThis->_key);
  params.append("vend_ach_enabled",      QVariant(_achGroup->isChecked()));
  params.append("vend_ach_routingnumber",_routingNumber->text().trimmed());
  params.append("vend_ach_accntnumber",  _achAccountNumber->text().trimmed());
  params.append("vend_ach_use_vendinfo", QVariant(! _useACHSpecial->isChecked()));
  params.append("vend_ach_indiv_number", _individualId->text().trimmed());
  params.append("vend_ach_indiv_name",   _individualName->text().trimmed());

  params.append("vend_ach_accnttype",  _accountType->code());

  if(_taxzone->isValid())
    params.append("vend_taxzone_id", _taxzone->id());

  if (_useWarehouseFOB->isChecked())
  {
    params.append("vend_fobsource", "W");
    params.append("vend_fob", "");
  }
  else if (_useVendorFOB)
  {
    params.append("vend_fobsource", "V");
    params.append("vend_fob", _vendorFOB->text().trimmed());
  }

  if(_accountSelected->isChecked() && _account->isValid())
  {
    params.append("vend_accnt_id", _account->id());
    params.append("vend_expcat_id", -1);
    params.append("vend_tax_id", -1);
  }
  else if (_expcatSelected->isChecked() && _expcat->isValid())
  {
    params.append("vend_accnt_id", -1);
    params.append("vend_expcat_id", _expcat->id());
    params.append("vend_tax_id", -1);
  }
  else if (_taxSelected->isChecked() && _taxCode->isValid())
  {
    params.append("vend_accnt_id", -1);
    params.append("vend_expcat_id", -1);
    params.append("vend_tax_id", _taxCode->id());
  }
  else
  {
    params.append("vend_accnt_id", -1);
    params.append("vend_expcat_id", -1);
    params.append("vend_tax_id", -1);
  }

  MetaSQLQuery mql(sql);
  XSqlQuery upsq = mql.toQuery(params);
  if (upsq.lastError().type() != QSqlError::NoError)
  {
    rollback.exec();
    ErrorReporter::error(QtCriticalMsg, this, tr("Error Saving Vendor"),
                         vendorSave, __FILE__, __LINE__);
    return;
  }


  XSqlQuery commit("COMMIT;");
  _NumberGen = -1;
  omfgThis->sVendorsUpdated();
  emit saved(_vendid);
  if (_mode == cNew)
    emit newId(_vendid);

  if(!_ignoreClose)
    close();
}
Beispiel #26
0
enum SetResponse itemSource::set(const ParameterList &pParams)
{
  XSqlQuery itemet;
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

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

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

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

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

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

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

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

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

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

  return NoError;
}
void vendor::sLoadCrmAcct(int crmacctId)
{
  _notice = FALSE;
  _crmacctid = crmacctId;

  XSqlQuery getq;
  getq.prepare("SELECT * FROM crmacct WHERE (crmacct_id=:crmacct_id);");
  getq.bindValue(":crmacct_id", crmacctId);
  getq.exec();
  if (getq.first())
  {
    _crmowner = getq.value("crmacct_owner_username").toString();
    _number->setText(getq.value("crmacct_number").toString());
    _cachedNumber=_number->text().trimmed().toUpper();
    _name->setText(getq.value("crmacct_name").toString());
    _active->setChecked(getq.value("crmacct_active").toBool());

    _contact1->setId(getq.value("crmacct_cntct_id_1").toInt());
    _contact1->setSearchAcct(_crmacctid);
    _contact2->setId(getq.value("crmacct_cntct_id_2").toInt());
    _contact2->setSearchAcct(_crmacctid);

    if (getq.value("crmacct_cntct_id_1").toInt() != 0)
    {
      XSqlQuery contactQry;
      contactQry.prepare("SELECT cntct_addr_id FROM cntct WHERE (cntct_id=:cntct_id);");
      contactQry.bindValue(":cntct_id", _contact1->id());
      contactQry.exec();
      if (contactQry.first())
      {
        _address->setId(contactQry.value("cntct_addr_id").toInt());
        _address->setSearchAcct(_crmacctid);
      }
    }
  }
  else if (ErrorReporter::error(QtCriticalMsg, this, tr("Getting Account"),
                           getq, __FILE__, __LINE__))
    return;

  _crmacct->setEnabled(_crmacctid > 0 &&
                       (_privileges->check("MaintainAllCRMAccounts") ||
                        _privileges->check("ViewAllCRMAccounts") ||
                        (omfgThis->username() == _crmowner && _privileges->check("MaintainPersonalCRMAccounts")) ||
                        (omfgThis->username() == _crmowner && _privileges->check("ViewPersonalCRMAccounts"))));

  _name->setFocus();
}
Beispiel #28
0
bool itemSource::sSave()
{
  XSqlQuery itemSave;

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

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

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

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

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

  if (_captive)
  {
    if (_mode != cCopy)
    {
      _vendor->setEnabled(FALSE);
    }
    _mode = cEdit;
    _item->setReadOnly(TRUE);
    _captive = false;
  }
  else
    done(_itemsrcid);
    
  return true;
}
Beispiel #29
0
void purchaseOrderItem::sSave()
{
    if (!_inventoryItem->isChecked() && _expcat->id() == -1)
    {
        QMessageBox::critical( this, tr("Expense Category Required"),
                               tr("<p>You must specify an Expense Category for this non-Inventory Item before you may save it.") );
        return;
    }

    if (_inventoryItem->isChecked() && !_item->isValid())
    {
        QMessageBox::critical( this, tr("No Item Selected"),
                               tr("<p>You must select an Item Number before you may save.") );
        return;
    }

    if (_inventoryItem->isChecked() && _warehouse->id() == -1)
    {
        QMessageBox::critical( this, tr("No Site Selected"),
                               tr("<p>You must select a Supplying Site before you may save.") );
        return;
    }

    if (_ordered->toDouble() == 0.0)
    {
        QMessageBox::critical( this, tr("Cannot Save Purchase Order Item"),
                               tr("<p>You must enter a quantity before you may save this Purchase Order Item.") );
        _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 (!_dueDate->isValid())
    {
        QMessageBox::critical( this, tr("Invalid Due Date"),
                               tr("<p>You must enter a due date before you may save this Purchase Order Item.") );
        _dueDate->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)
    {
        q.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 ) "
                   "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) ;" );

        q.bindValue(":status", _poStatus);
        q.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())
                q.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
        {
            q.bindValue(":poitem_expcat_id", _expcat->id());
        }
    }
    else if (_mode == cEdit)
        q.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);" );

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

    if (_parentwo != -1)
    {
        q.prepare("UPDATE poitem SET poitem_wohead_id=:parentwo WHERE (poitem_id=:poitem_id);");
        q.bindValue(":parentwo", _parentwo);
        q.bindValue(":poitem_id", _poitemid);
        q.exec();
    }

    if (_parentso != -1)
    {
        q.prepare("UPDATE poitem SET poitem_soitem_id=:parentso WHERE (poitem_id=:poitem_id);");
        q.bindValue(":parentso", _parentso);
        q.bindValue(":poitem_id", _poitemid);
        q.exec();
    }

    if ( _mode != cView )
    {
        q.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);
            q.bindValue(":target_id", _poitemid);
            q.bindValue(":char_id", _itemchar->data(idx1, Qt::UserRole));
            q.bindValue(":char_value", _itemchar->data(idx2, Qt::DisplayRole));
            q.exec();
        }
    }

    done(_poitemid);
}
Beispiel #30
0
void unpostedPoReceipts::sFillList()
{
  ParameterList fillp;
  setParams(fillp);
  MetaSQLQuery fillm = mqlLoad(":/sr/unpostedReceipts/FillListDetail.mql");
  XSqlQuery fillq = fillm.toQuery(fillp);

  _recv->clear();

  XTreeWidgetItem *line = 0;
  while (fillq.next())
  {
    line = new XTreeWidgetItem(_recv, line,
			       fillq.value("recv_id").toInt(),
			       fillq.value("recv_orderitem_id").toInt(),
			       fillq.value("recv_order_number"),
			       fillq.value("recv_order_type"),
			       fillq.value("vend_number"),
			       fillq.value("orderitem_linenumber"),
			       fillq.value("recv_duedate"),
			       fillq.value("item_number"),
			       fillq.value("uom_name"),
			       fillq.value("recv_vend_item_number"),
			       fillq.value("recv_vend_uom"),
			       fillq.value("qty_ordered"),
			       fillq.value("qty_received") );
    line->setText(RECV_QTY_COL, fillq.value("recv_qty").toString());
    line->setText(RECV_DATE_COL, fillq.value("recv_date").toString());
    line->setText(RECV_GLDISTDATE_COL, fillq.value("recv_gldistdate").toString());
  }
  if (fillq.lastError().type() != QSqlError::None)
  {
    systemError(this, fillq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}