void AddressList::sFillList() { _listTab->clear(); XSqlQuery query; query.prepare(_parent->_query + _parent->_extraClause + " ORDER BY addr_country, addr_state, addr_postalcode;"); query.exec(); query.first(); if (query.lastError().type() != QSqlError::NoError) { QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), query.lastError().databaseText()); return; } else if (query.size() < 1)// no rows found with limit so try without { query.prepare(_parent->_query + " ORDER BY addr_country, addr_state, addr_postalcode;"); query.exec(); query.first(); if (query.lastError().type() != QSqlError::NoError) { QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), query.lastError().databaseText()); return; } } _listTab->populate(query); }
int XSqlQueryProto::size() { XSqlQuery *item = qscriptvalue_cast<XSqlQuery*>(thisObject()); if (item) return item->size(); return 0; }
void assignLotSerial::sPrint() { QPrinter printer(QPrinter::HighResolution); bool setupPrinter = true; bool userCanceled = false; QString label; QString presetPrinter(xtsettingsValue(QString("%1.defaultPrinter").arg(objectName())).toString()); XSqlQuery qlabel; qlabel.prepare("SELECT ls_id, itemsite_controlmethod " "FROM itemlocdist " "LEFT OUTER JOIN itemsite ON (itemlocdist_itemsite_id = itemsite_id) " "JOIN ls ON (itemlocdist_ls_id=ls_id) " "WHERE (itemlocdist_series=:itemlocdist_series) " "ORDER BY ls_number;"); qlabel.bindValue(":itemlocdist_series", _itemlocSeries); qlabel.exec(); if (qlabel.first()) { if (qlabel.value("itemsite_controlmethod").toString() == "L") label = tr("Lot#:"); else label = tr("Serial#:"); if (presetPrinter.isEmpty()) { if (orReport::beginMultiPrint(&printer, userCanceled) == false) { if(!userCanceled) { systemError(this, tr("<p>Could not initialize printing system for " "multiple reports.")); return; } } } else { printer.setPrinterName(presetPrinter); orReport::beginMultiPrint(&printer); } for (int i = 0; i < qlabel.size(); i++) { ParameterList params; params.append("label", label); params.append("ls_id", qlabel.value("ls_id").toInt()); orReport report("LotSerialLabel", params); if (report.isValid() && report.print(&printer, setupPrinter)) setupPrinter = false; else { report.reportError(this); break; } qlabel.next(); } orReport::endMultiPrint(&printer); } else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } }
QString ExportHelper::generateHTML(QString qtext, ParameterList ¶ms, QString &errmsg) { if (DEBUG) qDebug("ExportHelper::generateHTML(%s..., %d params, errmsg) entered", qPrintable(qtext.left(80)), params.size()); if (qtext.isEmpty()) return QString::null; QTextDocument doc(0); QTextCursor cursor(&doc); QTextTableFormat tablefmt; bool valid; QVariant includeheaderVar = params.value("includeHeaderLine", &valid); bool includeheader = (valid ? includeheaderVar.toBool() : false); if (DEBUG) qDebug("generateHTML(qtest, params, errmsg) includeheader = %d, valid = %d", includeheader, valid); MetaSQLQuery mql(qtext); XSqlQuery qry = mql.toQuery(params); if (qry.first()) { int cols = qry.record().count(); int expected = qry.size(); if (includeheader) expected++; // presize the table cursor.insertTable((expected < 0 ? 1 : expected), cols, tablefmt); if (includeheader) { tablefmt.setHeaderRowCount(1); for (int p = 0; p < cols; p++) { cursor.insertText(qry.record().fieldName(p)); cursor.movePosition(QTextCursor::NextCell); } } do { for (int i = 0; i < cols; i++) { cursor.insertText(qry.value(i).toString()); cursor.movePosition(QTextCursor::NextCell); } } while (qry.next()); } if (qry.lastError().type() != QSqlError::NoError) errmsg = qry.lastError().text(); return doc.toHtml(); }
void updateItemSiteLeadTimes::sUpdate() { ParameterList params; _warehouse->appendValue(params); _classCode->appendValue(params); XSqlQuery updateUpdate; QProgressDialog progress; progress.setWindowModality(Qt::ApplicationModal); MetaSQLQuery mql = mqlLoad("updateItemsiteLeadTimes", "load"); updateUpdate = mql.toQuery(params); if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Loading Item Site Lead Times"), updateUpdate, __FILE__, __LINE__)) { return; } int count=0; progress.setMaximum(updateUpdate.size()); XSqlQuery update; while (updateUpdate.next()) { progress.setLabelText(tr("Site: %1\n" "Item: %2 - %3") .arg(updateUpdate.value("warehous_code").toString()) .arg(updateUpdate.value("item_number").toString()) .arg(updateUpdate.value("item_descrip1").toString())); ParameterList rparams = params; rparams.append("itemsite_id", updateUpdate.value("itemsite_id")); rparams.append("leadTimePad", _leadTimePad->value()); MetaSQLQuery mql2 = mqlLoad("updateItemsiteLeadTimes", "update"); update = mql2.toQuery(rparams); if (ErrorReporter::error(QtCriticalMsg, this, tr("Error Updating Item Site Lead Times"), update, __FILE__, __LINE__)) { return; } if (progress.wasCanceled()) break; count++; progress.setValue(count); } accept(); }
void AddressList::sFillList() { _listTab->clear(); XSqlQuery query; query.prepare(_parent->_query + _parent->_extraClause + " ORDER BY addr_country, addr_state, addr_postalcode;"); query.exec(); query.first(); if (query.lastError().type() != QSqlError::None) { QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), query.lastError().databaseText()); return; } else if (query.size() < 1)// no rows found with limit so try without { query.prepare(_parent->_query + " ORDER BY addr_country, addr_state, addr_postalcode;"); query.exec(); query.first(); if (query.lastError().type() != QSqlError::None) { QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), query.lastError().databaseText()); return; } } XTreeWidgetItem *last = NULL; do { last = new XTreeWidgetItem(_listTab, last, query.value("addr_id").toInt(), 0, query.value("addr_line1"), query.value("addr_line2"), query.value("addr_line3"), query.value("addr_city"), query.value("addr_state"), query.value("addr_country"), query.value("addr_postalcode")); } while (query.next()); }
void PlanOrdLineEdit::sParse() { if (text().contains('-')) { int number = text().left(text().find('-')).toInt(); int subNumber = text().right(text().length() - text().find('-') - 1).toInt(); XSqlQuery planord; planord.prepare( "SELECT planord_id " "FROM planord " "WHERE ( (planord_number=:planord_number)" " AND (planord_subnumber=:planord_subnumber) );" ); planord.bindValue(":planord_number", number); planord.bindValue(":planord_subnumber", subNumber); planord.exec(); if (planord.first()) setId(planord.value("planord_id").toInt()); else setId(-1); } else if (text().length()) { XSqlQuery planord; planord.prepare( "SELECT planord_id, planord_number " "FROM planord " "WHERE (planord_number=:planord_number);" ); planord.bindValue(":planord_number", text().toInt()); planord.exec(); if (planord.first()) { if (planord.size() == 1) setId(planord.value("planord_id").toInt()); else { setId(-1); setText(planord.value("planord_number").toString() + "-"); setFocus(); } } else setId(-1); } else setId(-1); }
void displayPrivate::setupCharacteristics(QStringList uses) { QString column; QString name; QString sql = QString("SELECT char_id, char_name, char_type " "FROM char " " JOIN charuse ON char_id = charuse_char_id" " WHERE char_search " " AND charuse_target_type IN ('%1')" " ORDER BY char_name;").arg(uses.join("','")); XSqlQuery chars; chars.exec(sql); if (chars.size() <= 0) { qWarning() << "Could not find any characteristics matching" << uses; } while (chars.next()) { characteristic::Type chartype = (characteristic::Type)chars.value("char_type").toInt(); column = QString("char%1").arg(chars.value("char_id").toString()); name = chars.value("char_name").toString(); _list->addColumn(name, -1, Qt::AlignLeft , false, column ); if (chartype == characteristic::Text) { _charidstext.append(chars.value("char_id").toInt()); _parameterWidget->append(name, column, ParameterWidget::Text); } else if (chartype == characteristic::List) { _charidslist.append(chars.value("char_id").toInt()); QString sql = QString("SELECT charopt_value, charopt_value " "FROM charopt " "WHERE (charopt_char_id=%1);") .arg(chars.value("char_id").toInt()); _parameterWidget->append(name, column, ParameterWidget::Multiselect, QVariant(), false, sql); } else if (chartype == characteristic::Date) { _charidsdate.append(chars.value("char_id").toInt()); QString start = QApplication::translate("display", "Start Date", 0); QString end = QApplication::translate("display", "End Date", 0); _parameterWidget->append(name + " " + start, column + "startDate", ParameterWidget::Date); _parameterWidget->append(name + " " + end, column + "endDate", ParameterWidget::Date); } } }
void ContactList::sFillList() { _listTab->clear(); XSqlQuery query; query.prepare(_parent->_query + _parent->_extraClause + " ORDER BY cntct_last_name, cntct_first_name;"); query.bindValue(":crmacct_id", _parent->_crmAcct->id()); query.bindValue(":searchAcctId", _parent->_searchAcctId); query.exec(); query.first(); if (query.lastError().type() != QSqlError::None) { QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), query.lastError().databaseText()); return; } else if (query.size() < 1) // no rows found with limit so try without { query.prepare(_parent->_query + " ORDER BY cntct_last_name, cntct_first_name;"); query.exec(); query.first(); if (query.lastError().type() != QSqlError::None) { QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), query.lastError().databaseText()); return; } } XTreeWidgetItem *last = 0; do { last = new XTreeWidgetItem(_listTab, last, query.value("cntct_id").toInt(), 0, query.value("cntct_number"), query.value("cntct_first_name"), query.value("cntct_last_name"), query.value("crmacct_name")); } while (query.next()); }
void createPlannedOrdersByPlannerCode::sCreate(ParameterList params) { XSqlQuery createCreate; QProgressDialog progress; progress.setWindowModality(Qt::ApplicationModal); MetaSQLQuery mql = mqlLoad("schedule", "load"); createCreate = mql.toQuery(params); if (createCreate.lastError().type() != QSqlError::NoError) { systemError(this, createCreate.lastError().databaseText(), __FILE__, __LINE__); return; } int count=0; progress.setMaximum(createCreate.size()); XSqlQuery create; while (createCreate.next()) { progress.setLabelText(tr("Site: %1\n" "Item: %2 - %3") .arg(createCreate.value("warehous_code").toString()) .arg(createCreate.value("item_number").toString()) .arg(createCreate.value("item_descrip1").toString())); ParameterList rparams = params; rparams.append("itemsite_id", createCreate.value("itemsite_id")); MetaSQLQuery mql2 = mqlLoad("schedule", "create"); create = mql2.toQuery(rparams); if (create.lastError().type() != QSqlError::NoError) { systemError(this, create.lastError().databaseText(), __FILE__, __LINE__); return; } if (progress.wasCanceled()) break; count++; progress.setValue(count); } accept(); }
void UsernameLineEdit::setId(const int pId) { QString sql("SELECT usr_username AS number, " " usr_propername AS name " " FROM usr" " WHERE ((usr_id=:id)"); if(UsersActive == _type) sql += " AND (usr_active)"; else if(UsersInactive == _type) sql += " AND (NOT usr_active)"; sql += " );"; XSqlQuery query; query.prepare(sql); query.bindValue(":id", pId); query.exec(); setStrikeOut(!query.size()); if(query.first()) { _id = pId; _valid = true; _username = query.value("number").toString(); setText(_username); _name = query.value("name").toString(); } else { _id = -1; _valid = false; _name = QString(); _description = QString(); } emit newId(_id); emit valid(_valid); emit parsed(); _parsed = true; }
configureIM::configureIM(QWidget* parent, const char* name, bool /*modal*/, Qt::WFlags fl) : XAbstractConfigure(parent, fl) { XSqlQuery configureconfigureIM; setupUi(this); if (name) setObjectName(name); //Inventory //Disable multi-warehouse if PostBooks if (_metrics->value("Application") == "PostBooks") _multiWhs->hide(); else { configureconfigureIM.exec("SELECT * " "FROM whsinfo"); if (configureconfigureIM.size() > 1) { _multiWhs->setCheckable(FALSE); _multiWhs->setTitle("Multiple Sites"); } else _multiWhs->setChecked(_metrics->boolean("MultiWhs")); if (_metrics->value("TONumberGeneration") == "M") _toNumGeneration->setCurrentIndex(0); else if (_metrics->value("TONumberGeneration") == "A") _toNumGeneration->setCurrentIndex(1); else if (_metrics->value("TONumberGeneration") == "O") _toNumGeneration->setCurrentIndex(2); _toNextNum->setValidator(omfgThis->orderVal()); configureconfigureIM.exec( "SELECT orderseq_number AS tonumber " "FROM orderseq " "WHERE (orderseq_name='ToNumber');" ); if (configureconfigureIM.first()) _toNextNum->setText(configureconfigureIM.value("tonumber").toString()); else if (configureconfigureIM.lastError().type() != QSqlError::NoError) systemError(this, configureconfigureIM.lastError().databaseText(), __FILE__, __LINE__); _enableToShipping->setChecked(_metrics->boolean("EnableTOShipping")); _transferOrderChangeLog->setChecked(_metrics->boolean("TransferOrderChangeLog")); } _eventFence->setValue(_metrics->value("DefaultEventFence").toInt()); _itemSiteChangeLog->setChecked(_metrics->boolean("ItemSiteChangeLog")); _warehouseChangeLog->setChecked(_metrics->boolean("WarehouseChangeLog")); if (_metrics->boolean("PostCountTagToDefault")) _postToDefault->setChecked(TRUE); else _doNotPost->setChecked(TRUE); _defaultTransWhs->setId(_metrics->value("DefaultTransitWarehouse").toInt()); QString countSlipAuditing = _metrics->value("CountSlipAuditing"); if (countSlipAuditing == "N") _noSlipChecks->setChecked(TRUE); else if (countSlipAuditing == "W") _checkOnUnpostedWarehouse->setChecked(TRUE); else if (countSlipAuditing == "A") _checkOnUnposted->setChecked(TRUE); else if (countSlipAuditing == "X") _checkOnAllWarehouse->setChecked(TRUE); else if (countSlipAuditing == "B") _checkOnAll->setChecked(TRUE); QString avgCostingMethod = _metrics->value("CountAvgCostMethod"); if (avgCostingMethod == "STD") _useStdCost->setChecked(TRUE); else if (avgCostingMethod == "ACT") { _useAvgCost->setChecked(TRUE); _useActCost->setChecked(TRUE); } else if (avgCostingMethod == "AVG") _useAvgCost->setChecked(TRUE); else _useStdCost->setChecked(TRUE); if(_metrics->value("Application") != "PostBooks") { configureconfigureIM.exec("SELECT DISTINCT itemsite_controlmethod " "FROM itemsite " "WHERE (itemsite_controlmethod IN ('L','S'));"); if (configureconfigureIM.first()) { _lotSerial->setChecked(TRUE); _lotSerial->setEnabled(FALSE); } else _lotSerial->setChecked(_metrics->boolean("LotSerialControl")); } else _lotSerial->hide(); _setDefLoc->setChecked(_metrics->boolean("SetDefaultLocations")); // Shipping and Receiving QString metric = _metrics->value("ShipmentNumberGeneration"); if (metric == "A") _shipmentNumGeneration->setCurrentIndex(0); _nextShipmentNum->setValidator(omfgThis->orderVal()); configureconfigureIM.exec("SELECT setval('shipment_number_seq', nextval('shipment_number_seq') -1); " "SELECT currval('shipment_number_seq') AS shipment_number;"); if (configureconfigureIM.first()) _nextShipmentNum->setText(configureconfigureIM.value("shipment_number")); else if (configureconfigureIM.lastError().type() != QSqlError::NoError) systemError(this, configureconfigureIM.lastError().databaseText(), __FILE__, __LINE__); _kitInheritCOS->setChecked(_metrics->boolean("KitComponentInheritCOS")); _disallowReceiptExcess->setChecked(_metrics->boolean("DisallowReceiptExcessQty")); _warnIfReceiptDiffers->setChecked(_metrics->boolean("WarnIfReceiptQtyDiffers")); _recordPpvOnReceipt->setChecked(_metrics->boolean("RecordPPVonReceipt")); _tolerance->setValidator(omfgThis->percentVal()); _tolerance->setText(_metrics->value("ReceiptQtyTolerancePct")); _costAvg->setChecked(_metrics->boolean("AllowAvgCostMethod")); _costStd->setChecked(_metrics->boolean("AllowStdCostMethod")); _costJob->setChecked(_metrics->boolean("AllowJobCostMethod")); configureconfigureIM.prepare("SELECT count(*) AS result FROM itemsite WHERE(itemsite_costmethod='A');"); configureconfigureIM.exec(); if(configureconfigureIM.first() && configureconfigureIM.value("result").toInt() > 0) { _costAvg->setChecked(true); _costAvg->setEnabled(false); } configureconfigureIM.prepare("SELECT count(*) AS result FROM itemsite WHERE(itemsite_costmethod='S');"); configureconfigureIM.exec(); if(configureconfigureIM.first() && configureconfigureIM.value("result").toInt() > 0) { _costStd->setChecked(true); _costStd->setEnabled(false); } if(!_costAvg->isChecked() && !_costStd->isChecked()) _costStd->isChecked(); _asOfQOH->setChecked(_metrics->boolean("EnableAsOfQOH")); // Jobs at this time should always be checked and disabled // when this is changed in the future this should be replaced with // similar code checks as for Avg and Std cost _costJob->setChecked(true); _costJob->setEnabled(false); // Receipt Cost Override _receiptCostOverride->setChecked(_metrics->boolean("AllowReceiptCostOverride")); connect(_receiptCostOverride, SIGNAL(toggled(bool)), this, SLOT(sReceiptCostOverrideWarning())); this->setWindowTitle("Inventory Configuration"); // Requires Consolidated shipping package _shipByGroup->hide(); adjustSize(); }
void ItemLineEdit::sParse() { if (!_parsed) { _parsed = TRUE; if (text().length() == 0) { setId(-1); return; } else if (_useValidationQuery) { XSqlQuery item; item.prepare("SELECT item_id FROM item WHERE (item_number = :searchString OR item_upccode = :searchString);"); item.bindValue(":searchString", text().trimmed().toUpper()); item.exec(); if (item.first()) { int itemid = item.value("item_id").toInt(); item.prepare(_validationSql); item.bindValue(":item_id", itemid); item.exec(); if (item.size() > 1) { ParameterList params; params.append("search", text().trimmed().toUpper()); params.append("searchNumber"); params.append("searchUpc"); sSearch(params); return; } else if (item.first()) { setId(itemid); return; } } } else if (_useQuery) { XSqlQuery item; item.prepare(_sql); item.exec(); if (item.first()) { do { if (item.value("item_number").toString().startsWith(text().trimmed().toUpper())) { setId(item.value("item_id").toInt()); return; } } while (item.next()); } } else { XSqlQuery item; QString pre( "SELECT DISTINCT item_id, item_number AS number, " "(item_descrip1 || ' ' || item_descrip2) AS name, " "item_upccode AS description " ); QStringList clauses; clauses = _extraClauses; clauses << "(item_number ~* :searchString OR item_upccode ~* :searchString)"; item.prepare(buildItemLineEditQuery(pre, clauses, QString::null, _type).replace(";"," ORDER BY item_number LIMIT 1;")); item.bindValue(":searchString", QString(text().trimmed().toUpper()).prepend("^")); item.exec(); if (item.first()) { setId(item.value("item_id").toInt()); return; } } setId(-1); } }
void ItemLineEdit::setItemNumber(const QString& pNumber) { XSqlQuery item; bool found = FALSE; _parsed = TRUE; if (pNumber == text()) return; if (!pNumber.isEmpty()) { if (_useValidationQuery) { item.prepare(_validationSql); item.bindValue(":item_number", pNumber); item.exec(); if (item.first()) found = TRUE; } else if (_useQuery) { item.prepare(_sql); item.exec(); found = (item.findFirst("item_number", pNumber) != -1); } else if (pNumber != QString::Null()) { QString pre( "SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2," " uom_name, item_type, item_config, item_upccode"); QStringList clauses; clauses = _extraClauses; clauses << "(item_number=:item_number OR item_upccode=:item_number)"; item.prepare(buildItemLineEditQuery(pre, clauses, QString::null, _type)); item.bindValue(":item_number", pNumber); item.exec(); if (item.size() > 1) { ParameterList params; params.append("search", pNumber); params.append("searchNumber"); params.append("searchUpc"); sSearch(params); return; } else found = item.first(); } } if (found) { _itemNumber = pNumber; _uom = item.value("uom_name").toString(); _itemType = item.value("item_type").toString(); _configured = item.value("item_config").toBool(); _id = item.value("item_id").toInt(); _upc = item.value("item_upccode").toInt(); _valid = TRUE; setText(item.value("item_number").toString()); emit aliasChanged(""); emit typeChanged(_itemType); emit descrip1Changed(item.value("item_descrip1").toString()); emit descrip2Changed(item.value("item_descrip2").toString()); emit uomChanged(item.value("uom_name").toString()); emit configured(item.value("item_config").toBool()); emit upcChanged(item.value("item_upccode").toString()); emit valid(TRUE); } else { _itemNumber = ""; _uom = ""; _itemType = ""; _id = -1; _valid = FALSE; _upc = ""; setText(""); emit aliasChanged(""); emit typeChanged(""); emit descrip1Changed(""); emit descrip2Changed(""); emit uomChanged(""); emit configured(FALSE); emit upcChanged(""); emit valid(FALSE); } }
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); } } }
void creditMemoItem::sListPrices() { XSqlQuery creditListPrices; creditListPrices.prepare( "SELECT currToCurr(ipshead_curr_id, :curr_id, ipsprice_price, :effective) AS price" " FROM ipsass, ipshead, ipsprice " " WHERE ( (ipsass_ipshead_id=ipshead_id)" " AND (ipsprice_ipshead_id=ipshead_id)" " AND (ipsprice_item_id=:item_id)" " AND (ipsass_cust_id=:cust_id)" " AND (COALESCE(LENGTH(ipsass_shipto_pattern), 0) = 0)" " AND (CURRENT_DATE BETWEEN ipshead_effective AND (ipshead_expires - 1) ) )" " UNION SELECT ipsprice_price AS price" " FROM ipsass, ipshead, ipsprice " " WHERE ( (ipsass_ipshead_id=ipshead_id)" " AND (ipsprice_ipshead_id=ipshead_id)" " AND (ipsprice_item_id=:item_id)" " AND (ipsass_shipto_id=:shipto_id)" " AND (ipsass_shipto_id != -1)" " AND (CURRENT_DATE BETWEEN ipshead_effective AND (ipshead_expires - 1)) )" " UNION SELECT ipsprice_price AS price" " FROM ipsass, ipshead, ipsprice, custinfo " " WHERE ( (ipsass_ipshead_id=ipshead_id)" " AND (ipsprice_ipshead_id=ipshead_id)" " AND (ipsprice_item_id=:item_id)" " AND (ipsass_custtype_id=cust_custtype_id)" " AND (cust_id=:cust_id)" " AND (CURRENT_DATE BETWEEN ipshead_effective AND (ipshead_expires - 1)) )" " UNION SELECT ipsprice_price AS price" " FROM ipsass, ipshead, ipsprice, custtype, custinfo " " WHERE ( (ipsass_ipshead_id=ipshead_id)" " AND (ipsprice_ipshead_id=ipshead_id)" " AND (ipsprice_item_id=:item_id)" " AND (coalesce(length(ipsass_custtype_pattern), 0) > 0)" " AND (custtype_code ~ ipsass_custtype_pattern)" " AND (cust_custtype_id=custtype_id)" " AND (cust_id=:cust_id)" " AND (CURRENT_DATE BETWEEN ipshead_effective AND (ipshead_expires - 1)))" " UNION SELECT ipsprice_price AS price" " FROM ipsass, ipshead, ipsprice, shiptoinfo " " WHERE ( (ipsass_ipshead_id=ipshead_id)" " AND (ipsprice_ipshead_id=ipshead_id)" " AND (ipsprice_item_id=:item_id)" " AND (shipto_id=:shipto_id)" " AND (COALESCE(LENGTH(ipsass_shipto_pattern), 0) > 0)" " AND (shipto_num ~ ipsass_shipto_pattern)" " AND (ipsass_cust_id=:cust_id)" " AND (CURRENT_DATE BETWEEN ipshead_effective AND (ipshead_expires - 1)) )" " UNION SELECT ipsprice_price AS price" " FROM sale, ipshead, ipsprice " " WHERE ((sale_ipshead_id=ipshead_id)" " AND (ipsprice_ipshead_id=ipshead_id)" " AND (ipsprice_item_id=:item_id)" " AND (CURRENT_DATE BETWEEN sale_startdate AND (sale_enddate - 1)) ) " " UNION SELECT (item_listprice - (item_listprice * cust_discntprcnt)) AS price " " FROM item, custinfo " " WHERE ( (item_sold)" " AND (NOT item_exclusive)" " AND (item_id=:item_id)" " AND (cust_id=:cust_id) );"); creditListPrices.bindValue(":item_id", _item->id()); creditListPrices.bindValue(":cust_id", _custid); creditListPrices.bindValue(":shipto_id", _shiptoid); creditListPrices.bindValue(":curr_id", _netUnitPrice->id()); creditListPrices.bindValue(":effective", _netUnitPrice->effective()); creditListPrices.exec(); if (creditListPrices.size() == 1) { creditListPrices.first(); _netUnitPrice->setLocalValue(creditListPrices.value("price").toDouble() * (_priceinvuomratio / _priceRatio)); } else { ParameterList params; params.append("cust_id", _custid); params.append("shipto_id", _shiptoid); params.append("item_id", _item->id()); params.append("warehous_id", _warehouse->id()); // don't params.append("qty", ...) as we don't know how many were purchased params.append("curr_id", _netUnitPrice->id()); params.append("effective", _netUnitPrice->effective()); priceList newdlg(this); newdlg.set(params); if (newdlg.exec() == XDialog::Accepted) { _netUnitPrice->setLocalValue(newdlg._selectedPrice * (_priceinvuomratio / _priceRatio)); sCalculateDiscountPrcnt(); } } }
void ItemLineEdit::sParse() { if (DEBUG) qDebug("%s::sParse() entered with parsed %d, text [%s], " "_useValidationQuery %d, _useQuery %d", qPrintable(objectName()), _parsed, qPrintable(text()), _useValidationQuery, _useQuery); if (!_parsed) { _parsed = TRUE; if (text().length() == 0) { setId(-1); return; } else if (_useValidationQuery) { XSqlQuery item; if (completer()) item.prepare("SELECT item_id" " FROM item" " WHERE ((POSITION(:searchString IN item_number) = 1)" " OR (POSITION(:searchString IN item_upccode) = 1));"); else item.prepare("SELECT item_id" " FROM item" " WHERE (item_number = :searchString" " OR item_upccode = :searchString);"); item.bindValue(":searchString", text().trimmed().toUpper()); item.exec(); while (item.next()) { int itemid = item.value("item_id").toInt(); XSqlQuery oneq; oneq.prepare(_validationSql); oneq.bindValue(":item_id", itemid); oneq.exec(); if (oneq.size() > 1) { ParameterList params; params.append("search", text().trimmed().toUpper()); params.append("searchNumber"); params.append("searchUpc"); sSearch(params); return; } else if (oneq.first()) { setId(itemid); return; } } } else if (_useQuery) { XSqlQuery item; item.prepare(_sql); item.exec(); if (item.first()) { do { if (item.value("item_number").toString().startsWith(text().trimmed().toUpper()) || item.value("item_upccode").toString().startsWith(text().trimmed().toUpper())) { setId(item.value("item_id").toInt()); return; } } while (item.next()); } } else { XSqlQuery item; QString pre( "SELECT DISTINCT item_id, item_number AS number, " "(item_descrip1 || ' ' || item_descrip2) AS name, " "item_upccode AS description " ); QStringList clauses; clauses = _extraClauses; clauses << "((POSITION(:searchString IN item_number) = 1)" " OR (POSITION(:searchString IN item_upccode) = 1))"; item.prepare(buildItemLineEditQuery(pre, clauses, QString::null, _type, true) .replace(";"," ORDER BY item_number LIMIT 1;")); item.bindValue(":searchString", QString(text().trimmed().toUpper())); item.exec(); if (item.first()) { setId(item.value("item_id").toInt()); return; } } setId(-1); } }
void purchaseOrderItem::sPopulateItemInfo(int pItemid) { XSqlQuery item; if (pItemid != -1 && _mode == cNew) { if(_metrics->boolean("RequireStdCostForPOItem")) { item.prepare("SELECT stdCost(:item_id) AS result"); item.bindValue(":item_id", pItemid); item.exec(); if(item.first() && item.value("result").toDouble() == 0.0) { QMessageBox::critical( this, tr("Selected Item Missing Cost"), tr("<p>The selected item has no Std. Costing information. " "Please see your controller to correct this situation " "before continuing.")); _item->setId(-1); return; } } item.prepare( "SELECT DISTINCT char_id, char_name," " COALESCE(b.charass_value, (SELECT c.charass_value FROM charass c WHERE ((c.charass_target_type='I') AND (c.charass_target_id=:item_id) AND (c.charass_default) AND (c.charass_char_id=char_id)) LIMIT 1)) AS charass_value" " FROM charass a, char " " LEFT OUTER JOIN charass b" " ON (b.charass_target_type='PI'" " AND b.charass_target_id=:poitem_id" " AND b.charass_char_id=char_id) " " WHERE ( (a.charass_char_id=char_id)" " AND (a.charass_target_type='I')" " AND (a.charass_target_id=:item_id) ) " " ORDER BY char_name;" ); item.bindValue(":item_id", pItemid); item.bindValue(":poitem_id", _poitemid); item.exec(); int row = 0; QModelIndex idx; while(item.next()) { _itemchar->insertRow(_itemchar->rowCount()); idx = _itemchar->index(row, 0); _itemchar->setData(idx, item.value("char_name"), Qt::DisplayRole); _itemchar->setData(idx, item.value("char_id"), Qt::UserRole); idx = _itemchar->index(row, 1); _itemchar->setData(idx, item.value("charass_value"), Qt::DisplayRole); _itemchar->setData(idx, pItemid, Qt::UserRole); row++; } item.prepare("SELECT itemsrc_id " "FROM itemsrc, pohead " "WHERE ( (itemsrc_vend_id=pohead_vend_id)" " AND (itemsrc_item_id=:item_id)" " AND (pohead_id=:pohead_id) );" ); item.bindValue(":item_id", pItemid); item.bindValue(":pohead_id", _poheadid); item.exec(); if (item.size() == 1) { item.first(); if (item.value("itemsrc_id").toInt() != _itemsrcid) sPopulateItemSourceInfo(item.value("itemsrc_id").toInt()); } else if (item.size() > 1) { bool isCurrent = false; while (item.next()) { if (item.value("itemsrc_id").toInt() == _itemsrcid) isCurrent = true; } if (!isCurrent) { _vendorItemNumber->clear(); sVendorItemNumberList(); } } else { _itemsrcid = -1; _vendorItemNumber->clear(); _vendorDescrip->clear(); _vendorUOM->setText(_item->uom()); _uom->setText(_item->uom()); _minOrderQty->clear(); _orderQtyMult->clear(); _invVendorUOMRatio->setDouble(1.0); _earliestDate->setDate(omfgThis->dbDate()); _manufName->clear(); _manufItemNumber->clear(); _manufItemDescrip->clear(); _invVendUOMRatio = 1; _minimumOrder = 0; _orderMultiple = 0; } } }
void purchaseOrderItem::sPopulateItemInfo(int pItemid) { XSqlQuery item; if (pItemid != -1 && _mode == cNew) { item.prepare("SELECT stdCost(item_id) AS stdcost, " " getItemTaxType(item_id, pohead_taxzone_id) AS taxtype_id, " " item_tax_recoverable, COALESCE(item_maxcost, 0.0) AS maxcost " "FROM item, pohead " "WHERE ( (item_id=:item_id) " " AND (pohead_id=:pohead_id) );"); item.bindValue(":item_id", pItemid); item.bindValue(":pohead_id", _poheadid); item.exec(); if (item.first()) { // Reset order qty cache _orderQtyCache = -1; if(_metrics->boolean("RequireStdCostForPOItem") && item.value("stdcost").toDouble() == 0.0) { QMessageBox::critical( this, tr("Selected Item Missing Cost"), tr("<p>The selected item has no Std. Costing information. " "Please see your controller to correct this situation " "before continuing.")); _item->setId(-1); return; } _taxtype->setId(item.value("taxtype_id").toInt()); _taxRecoverable->setChecked(item.value("item_tax_recoverable").toBool()); _maxCost = item.value("maxcost").toDouble(); sPopulateItemsiteInfo(); sPopulateItemChar(); item.prepare("SELECT itemsrc_id " "FROM itemsrc, pohead " "WHERE ( (itemsrc_vend_id=pohead_vend_id)" " AND (itemsrc_item_id=:item_id)" " AND (:effective BETWEEN itemsrc_effective AND (itemsrc_expires - 1))" " AND (itemsrc_active)" " AND (pohead_id=:pohead_id) );" ); item.bindValue(":item_id", pItemid); item.bindValue(":pohead_id", _poheadid); item.bindValue(":effective", _unitPrice->effective()); item.exec(); if (item.size() == 1) { item.first(); if (item.value("itemsrc_id").toInt() != _itemsrcid) sPopulateItemSourceInfo(item.value("itemsrc_id").toInt()); } else if (item.size() > 1) { bool isCurrent = false; while (item.next()) { if (item.value("itemsrc_id").toInt() == _itemsrcid) isCurrent = true; } if (!isCurrent) { _vendorItemNumber->clear(); sVendorItemNumberList(); } } else { _itemsrcid = -1; _vendorItemNumber->clear(); _vendorDescrip->clear(); _vendorUOM->setText(_item->uom()); _uom->setText(_item->uom()); _minOrderQty->clear(); _orderQtyMult->clear(); _invVendorUOMRatio->setDouble(1.0); _earliestDate->setDate(omfgThis->dbDate()); _manufName->setId(-1); _manufItemNumber->clear(); _manufItemDescrip->clear(); _invVendUOMRatio = 1; _minimumOrder = 0; _orderMultiple = 0; } } } }
void ContactWidget::findDuplicates() { if (_first->text().isEmpty() && _last->text().isEmpty()) return; QString msg; XSqlQuery r; r.prepare( "SELECT cntct_id, COALESCE(cntct_crmacct_id,0) AS cntct_crmacct_id " "FROM cntct " "WHERE ( ( cntct_first_name ~~* :first) " " AND (cntct_last_name ~~* :last) );"); r.bindValue(":first", _first->text()); r.bindValue(":last", _last->text()); r.bindValue(":crmacct_id", _searchAcctId); r.exec(); if (r.size() == 1) { r.first(); msg = tr("A contact exists with the same first and last name"); if (_searchAcctId > 0 && r.value("cntct_crmacct_id").toInt() == 0) msg += tr(" not associated with any CRM Account"); else if (_searchAcctId == r.value("cntct_crmacct_id").toInt()) msg += tr(" on the current CRM Account"); else if (_searchAcctId > 0) msg += tr(" associated with another CRM Account"); msg += tr(". Would you like to use the existing contact?"); if (QMessageBox::question(this, tr("Existing Contact"), msg, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes) { r.first(); setId(r.value("cntct_id").toInt()); } } else if (r.size() > 1) { if (_searchAcctId > 0) { int cnt = 0; int cntctid = 0; while (r.next()) { if (r.value("cntct_crmacct_id").toInt() == _searchAcctId) { cnt += 1; cntctid = r.value("cntct_id").toInt(); } } if (cnt == 1) { msg = tr("A contact exists with the same first and last name " "on the current CRM Account. " "Would you like to use the existing contact?"); if (QMessageBox::question(this, tr("Existing Contact"), msg, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes) setId(cntctid); return; } if (cnt == 0) _searchAcctId = -1; } QString msg = tr("Multple contacts exist with the same first and last name"); msg += tr(". Would you like to view all the existing contacts?"); if (QMessageBox::question(this, tr("Existing Contacts"), msg, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes) { ContactSearch* newdlg = new ContactSearch(this); if (newdlg) { newdlg->_searchFirst->setChecked(true); newdlg->_searchLast->setChecked(true); newdlg->_search->setText(_first->text() + " " + _last->text()); newdlg->sFillList(); int id = newdlg->exec(); setId(id); } else QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), tr("Could not instantiate a Search Dialog")); } } else if (r.lastError().type() != QSqlError::NoError) QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), r.lastError().databaseText()); }
void ContactSearch::sFillList() { _listTab->clear(); if (_search->text().isEmpty() || (!_searchFirst->isChecked() && !_searchLast->isChecked() && !_searchCRMAcct->isChecked() && !_searchTitle->isChecked() && !_searchPhones->isChecked() && !_searchEmail->isChecked() && !_searchWebAddr->isChecked() )) return; QString limits = "<? if exists(\"extraClause\") ?> " " AND " "<? else ?>" " WHERE " "<? endif ?> " "<? if exists(\"searchInactive\") ?> " " true " "<? else ?>" " cntct_active " "<? endif ?>" "<? if reExists(\"search[FLCTPEW]\") ?> " " AND (" " <? if exists(\"searchFirst\") ?> " " COALESCE(cntct_first_name,'') || '\n' " " <? else ?>" " '\n' " " <? endif ?>" " <? if exists(\"searchLast\") ?> " " || COALESCE(cntct_last_name,'') || '\n' " " <? endif ?>" " <? if exists(\"searchCRMAcct\") ?> " " || COALESCE(crmacct_name,'') || '\n' " " <? endif ?>" " <? if exists(\"searchTitle\") ?> " " || COALESCE(cntct_title,'') || '\n' " " <? endif ?>" " <? if exists(\"searchPhones\") ?> " " || COALESCE(cntct_phone,'') || '\n' " " || COALESCE(cntct_phone2,'') || '\n' " " || COALESCE(cntct_fax,'') || '\n' " " <? endif ?>" " <? if exists(\"searchEmail\") ?> " " || COALESCE(cntct_email,'') || '\n' " " <? endif ?>" " <? if exists(\"searchWebAddr\") ?> " " || COALESCE(cntct_webaddr,'') || '\n' " " <? endif ?>" " ~* <? value(\"searchText\") ?> )" "<? endif ?>" "ORDER BY cntct_last_name, cntct_first_name, crmacct_number;"; QString sql = _parent->_query + _parent->_extraClause.replace(":searchAcctId", QString::number(_parent->_searchAcctId)) + limits; ParameterList params; if (_searchFirst->isChecked()) params.append("searchFirst"); if (_searchLast->isChecked()) params.append("searchLast"); if (_searchCRMAcct->isChecked()) params.append("searchCRMAcct"); if (_searchTitle->isChecked()) params.append("searchTitle"); if (_searchPhones->isChecked()) params.append("searchPhones"); if (_searchEmail->isChecked()) params.append("searchEmail"); if (_searchWebAddr->isChecked()) params.append("searchWebAddr"); if (_searchInactive->isChecked()) params.append("searchInactive"); if (! _parent->_extraClause.isEmpty()) params.append("extraClause", _parent->_extraClause); params.append("searchText", _search->text()); MetaSQLQuery mql(sql); XSqlQuery query = mql.toQuery(params); if (query.lastError().type() != QSqlError::None) { QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), query.lastError().databaseText()); return; } else if (query.size() < 1) // no rows found with limit so try without { sql = _parent->_query + limits; MetaSQLQuery mqlAllAccnts(sql); query = mqlAllAccnts.toQuery(params); if (query.lastError().type() != QSqlError::None) { QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.") .arg(__FILE__) .arg(__LINE__), query.lastError().databaseText()); return; } } XTreeWidgetItem *last = 0; while (query.next()) { last = new XTreeWidgetItem(_listTab, last, query.value("cntct_id").toInt(), 0, query.value("cntct_first_name"), query.value("cntct_last_name"), query.value("crmacct_name"), query.value("cntct_title"), query.value("cntct_phone"), query.value("cntct_phone2"), query.value("cntct_fax"), query.value("cntct_email"), query.value("cntct_webaddr")); } }
void PoitemTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *pModel, const QModelIndex &index) const { XSqlQuery PoitemetModelData; if (DEBUG) qDebug("PoitemTableDelegate::setModelData() entered"); bool hitError = false; QVariant oldval = pModel->data(index); PoitemTableModel *model = static_cast<PoitemTableModel*>(pModel); switch (index.column()) { case ITEM_NUMBER_COL: { ItemLineEdit *item = static_cast<ItemLineEdit*>(editor); if (item->itemNumber() != oldval.toString()) { if (item->itemNumber().isEmpty()) { model->setData(index, QVariant()); model->setData(model->index(index.row(), ITEM_ID_COL), QVariant()); model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), QVariant()); model->setData(model->index(index.row(), WAREHOUS_ID_COL), QVariant()); model->setData(model->index(index.row(), WAREHOUS_CODE_COL), QVariant()); model->setData(model->index(index.row(), POITEM_ITEMSRC_ID_COL), QVariant()); model->setData(model->index(index.row(), POITEM_VEND_ITEM_NUMBER_COL), QVariant()); model->setData(model->index(index.row(), POITEM_VEND_ITEM_DESCRIP_COL), QVariant()); model->setData(model->index(index.row(), POITEM_VEND_UOM_COL), QVariant()); model->setData(model->index(index.row(), ITEMSRC_MINORDQTY_COL), QVariant()); model->setData(model->index(index.row(), ITEMSRC_MULTORDQTY_COL), QVariant()); model->setData(model->index(index.row(), ITEMSRC_INVVENDORUOMRATIO_COL), QVariant()); model->setData(model->index(index.row(), POITEM_INVVENDUOMRATIO_COL), QVariant()); model->setData(model->index(index.row(), EARLIESTDATE_COL), QVariant()); } else { model->setData(index, item->itemNumber()); model->setData(model->index(index.row(), ITEM_ID_COL), item->id()); if (item->isValid()) { XSqlQuery itemq; itemq.prepare("SELECT (warehous_id=:preferred) AS preferred, " " itemsite_id, warehous_id, warehous_code " "FROM itemsite, whsinfo " "WHERE ((itemsite_item_id=:item_id)" " AND (itemsite_warehous_id=warehous_id)) " "ORDER BY preferred DESC, warehous_code " "LIMIT 1;"); itemq.bindValue(":item_id", item->id()); itemq.bindValue(":preferred", _x_preferences->value("PreferredWarehouse").toInt()); itemq.exec(); if (itemq.first()) { model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), itemq.value("itemsite_id").toInt()); model->setData(model->index(index.row(), WAREHOUS_ID_COL), itemq.value("warehous_id").toInt()); model->setData(model->index(index.row(), WAREHOUS_CODE_COL), itemq.value("warehous_code").toString()); } else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving PO Information"), itemq, __FILE__, __LINE__)) { hitError = true; break; } else { ErrorReporter::error(QtCriticalMsg, 0, tr("Error Occurred"), tr("Could not find Item Site for %1 (%2).") .arg(item->itemNumber()) .arg(item->id()),__FILE__,__LINE__); hitError = true; break; } if (_metrics->boolean("RequireStdCostForPOItem")) { XSqlQuery stdcostq; stdcostq.prepare("SELECT stdCost(:item_id) AS result"); stdcostq.bindValue(":item_id", item->id()); stdcostq.exec(); if(stdcostq.first() && stdcostq.value("result").toDouble() == 0.0) { QMessageBox::critical(0, tr("Selected Item Missing Cost"), tr("<p>The selected item has no Std. Costing information. " "Please see your controller to correct this situation " "before continuing.")); model->setData(index, QString()); model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), QVariant()); model->setData(model->index(index.row(), WAREHOUS_ID_COL), QVariant()); model->setData(model->index(index.row(), WAREHOUS_CODE_COL), QString()); model->setData(index, QString()); hitError = true; break; } else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Standard Cost Information"), stdcostq, __FILE__, __LINE__)) { hitError = true; break; } } XSqlQuery itemsrcq; itemsrcq.prepare( "SELECT pohead_vend_id, itemsrc_id, itemsrc_vend_item_number," " itemsrc_vend_item_descrip, itemsrc_vend_uom," " itemsrc_minordqty," " itemsrc_multordqty," " itemsrc_invvendoruomratio," " itemsrc_manuf_name," " itemsrc_manuf_item_number," " itemsrc_manuf_item_descrip," " (CURRENT_DATE + itemsrc_leadtime) AS earliestdate " "FROM pohead, itemsrc " "WHERE ( (itemsrc_vend_id=pohead_vend_id)" " AND (itemsrc_item_id=:item_id)" " AND (pohead_id=:pohead_id) );" ); itemsrcq.bindValue(":item_id", item->id()); itemsrcq.bindValue(":pohead_id", model->headId()); itemsrcq.exec(); if (itemsrcq.size() > 1) { itemsrcq.first(); ParameterList params; params.append("vend_id", itemsrcq.value("pohead_vend_id").toInt()); params.append("search", item->itemNumber()); itemSourceSearch newdlg(0, "", true); newdlg.set(params); if(newdlg.exec() == XDialog::Accepted) { int itemsrcid = newdlg.itemsrcId(); if(itemsrcid != -1) { itemsrcq.prepare( "SELECT itemsrc_id, itemsrc_vend_item_number," " itemsrc_vend_item_descrip, itemsrc_vend_uom," " itemsrc_minordqty," " itemsrc_multordqty," " itemsrc_invvendoruomratio," " itemsrc_manuf_name," " itemsrc_manuf_item_number," " itemsrc_manuf_item_descrip," " (CURRENT_DATE + itemsrc_leadtime) AS earliestdate " "FROM pohead, itemsrc " "WHERE (itemsrc_id=:itemsrc_id);" ); itemsrcq.bindValue(":itemsrc_id", itemsrcid); itemsrcq.exec(); } } else itemsrcq.clear(); } if (itemsrcq.first()) { model->setData(model->index(index.row(), POITEM_ITEMSRC_ID_COL), itemsrcq.value("itemsrc_id").toInt()); model->setData(model->index(index.row(), POITEM_VEND_ITEM_NUMBER_COL), itemsrcq.value("itemsrc_vend_item_number").toString()); model->setData(model->index(index.row(), POITEM_VEND_ITEM_DESCRIP_COL), itemsrcq.value("itemsrc_vend_item_descrip").toString()); model->setData(model->index(index.row(), POITEM_VEND_UOM_COL), itemsrcq.value("itemsrc_vend_uom").toString()); model->setData(model->index(index.row(), ITEMSRC_MINORDQTY_COL), itemsrcq.value("itemsrc_minordqty").toDouble()); model->setData(model->index(index.row(), ITEMSRC_MULTORDQTY_COL), itemsrcq.value("itemsrc_multordqty").toDouble()); model->setData(model->index(index.row(), ITEMSRC_INVVENDORUOMRATIO_COL), itemsrcq.value("itemsrc_invvendoruomratio").toDouble()); model->setData(model->index(index.row(), POITEM_INVVENDUOMRATIO_COL), itemsrcq.value("itemsrc_invvendoruomratio").toDouble()); model->setData(model->index(index.row(), POITEM_MANUF_NAME_COL), itemsrcq.value("itemsrc_manuf_name").toString()); model->setData(model->index(index.row(), POITEM_MANUF_ITEM_NUMBER_COL), itemsrcq.value("itemsrc_manuf_item_number").toString()); model->setData(model->index(index.row(), POITEM_MANUF_ITEM_DESCRIP_COL), itemsrcq.value("itemsrc_manuf_item_descrip").toString()); model->setData(model->index(index.row(), EARLIESTDATE_COL), itemsrcq.value("earliestdate").toDate()); if (_metrics->boolean("UseEarliestAvailDateOnPOItem")) model->setData(model->index(index.row(), POITEM_DUEDATE_COL), itemsrcq.value("earliestdate").toDate()); } else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Item Information"), itemsrcq, __FILE__, __LINE__)) { hitError = true; break; } } } } break; } case WAREHOUS_CODE_COL: { WComboBox *whs = static_cast<WComboBox*>(editor); if (whs->id() < 0) { model->setData(model->index(index.row(), WAREHOUS_ID_COL), QVariant()); model->setData(index, QVariant()); } else if (whs->id() != oldval.toInt()) { model->setData(model->index(index.row(), WAREHOUS_ID_COL), whs->id()); model->setData(index, whs->currentText()); if (whs->isValid()) { XSqlQuery itemq; itemq.prepare("SELECT itemsite_id " "FROM itemsite " "WHERE ((itemsite_item_id=:item_id)" " AND (itemsite_warehous_id=:whs_id)) " "LIMIT 1;"); itemq.bindValue(":item_id", model->index(index.row(), ITEM_ID_COL).data()); itemq.bindValue(":whs_id", whs->id()); itemq.exec(); if (itemq.first()) { model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), itemq.value("itemsite_id").toInt()); } else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Item Site Information"), itemq, __FILE__, __LINE__)) { hitError = true; break; } else { ErrorReporter::error(QtCriticalMsg, 0, tr("Error Occurred"), tr("%1: Could not find Item Site for %1 in %2.") .arg(model->index(index.row(), ITEM_NUMBER_COL).data().toString()) .arg(whs->currentText()) ,__FILE__,__LINE__); hitError = true; break; } } } break; } case POITEM_VEND_ITEM_DESCRIP_COL: { XLineEdit *lineedit = static_cast<XLineEdit*>(editor); if (lineedit->text() != oldval.toString()) model->setData(index, lineedit->text()); break; } case POITEM_VEND_ITEM_NUMBER_COL: { XLineEdit *lineedit = static_cast<XLineEdit*>(editor); if (lineedit->text() != oldval.toString()) model->setData(index, lineedit->text()); break; } case POITEM_FREIGHT_COL: { XLineEdit *lineedit = static_cast<XLineEdit*>(editor); if (lineedit->toDouble() != oldval.toDouble()) model->setData(index, lineedit->toDouble()); break; } case POITEM_QTY_ORDERED_COL: { XLineEdit *lineedit = static_cast<XLineEdit*>(editor); if (lineedit->text().isEmpty()) { model->setData(index, QVariant()); model->setData(model->index(index.row(), EXTPRICE_COL), QVariant()); break; } double qty = lineedit->toDouble(); if (qty != oldval.toDouble()) { model->setData(index, qty); if (model->data(model->index(index.row(), POITEM_QTY_ORDERED_COL)).toDouble() > 0 && model->data(model->index(index.row(), POITEM_ITEMSRC_ID_COL)).toInt() > 0) { PoitemetModelData.prepare( "SELECT ROUND(currToCurr(itemsrcp_curr_id, :curr_id, itemsrcp_price, :effective), :prec) " "AS new_itemsrcp_price " "FROM itemsrcp " "WHERE ( (itemsrcp_itemsrc_id=:itemsrc_id)" " AND (itemsrcp_qtybreak <= :qty) ) " "ORDER BY itemsrcp_qtybreak DESC " "LIMIT 1;" ); PoitemetModelData.bindValue(":itemsrc_id", model->data(model->index(index.row(), POITEM_ITEMSRC_ID_COL)).toInt()); PoitemetModelData.bindValue(":qty", model->data(model->index(index.row(), POITEM_QTY_ORDERED_COL)).toDouble()); PoitemetModelData.bindValue(":curr_id", model->currId()); PoitemetModelData.bindValue(":effective", model->transDate().toString()); PoitemetModelData.bindValue(":prec", omfgThis->priceVal()->decimals()); PoitemetModelData.exec(); if (PoitemetModelData.first()) { model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), PoitemetModelData.value("new_itemsrcp_price").toDouble()); } else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Item Information"), PoitemetModelData, __FILE__, __LINE__)) { hitError = true; break; } else model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), 0); } double prc = model->data(model->index(index.row(), POITEM_UNITPRICE_COL)).toDouble(); model->setData(model->index(index.row(), EXTPRICE_COL), (qty * prc)); } break; } case POITEM_UNITPRICE_COL: { XLineEdit *lineedit = static_cast<XLineEdit*>(editor); if (lineedit->text().isEmpty()) { model->setData(index, QVariant()); model->setData(model->index(index.row(), EXTPRICE_COL), QVariant()); break; } double prc = lineedit->text().toDouble(); if (prc != oldval.toDouble()) { model->setData(index, prc); double qty = model->data(model->index(index.row(),POITEM_QTY_ORDERED_COL)).toDouble(); model->setData(model->index(index.row(), EXTPRICE_COL), (qty * prc)); } break; } case POITEM_DUEDATE_COL: { XDateEdit *duedate = static_cast<XDateEdit*>(editor); duedate->parseDate(); if (duedate->date() != oldval.toDate()) { if (DEBUG) qDebug("PoitemTableDelegate::setModelData() setting duedate to %s with null %d, valid %d", qPrintable(duedate->date().toString()), duedate->isNull(), duedate->isValid()); model->setData(index, duedate->date()); } break; } #ifdef QE_NONINVENTORY case EXPCAT_CODE_COL: { ExpenseLineEdit *exp = static_cast<ExpenseLineEdit*>(editor); if (exp->id() != oldval.toInt()) { model->setData(model->index(index.row(), POITEM_EXPCAT_ID_COL), exp->id()); model->setData(index, exp->text()); } break; } #endif default: break; } QTableView *view = qobject_cast<QTableView*>(parent()); if (view) { if (hitError) view->setCurrentIndex(index); else if (index.row() >= (model->rowCount() - 1)) { QHeaderView* header = view->horizontalHeader(); if (header->visualIndex(index.column()) >= (header->count() - header->hiddenSectionCount() - 1)) { model->insertRow(model->rowCount()); } } } return; }