shipOrder::shipOrder(QWidget* parent, const char* name, bool modal, Qt::WFlags fl) : XDialog(parent, name, modal, fl) { setupUi(this); connect(_create, SIGNAL(toggled(bool)), this, SLOT(sCreateToggled(bool))); connect(_select, SIGNAL(toggled(bool)), this, SLOT(sSelectToggled(bool))); connect(_ship, SIGNAL(clicked()), this, SLOT(sShip())); connect(_shipment, SIGNAL(newId(int)), this, SLOT(sFillList())); connect(_shipment, SIGNAL(newId(int)), this, SLOT(sFillTracknum())); connect(_order, SIGNAL(newId(int,QString)), this, SLOT(sHandleOrder())); connect(_warehouse,SIGNAL(newID(int)), this, SLOT(sHandleOrder())); connect(_tracknum, SIGNAL(activated(const QString&)), this, SLOT(sFillFreight())); connect(_tracknum, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(sFillFreight())); connect(_tracknum, SIGNAL(highlighted(const QString&)), this, SLOT(sFillFreight())); _captive = FALSE; _coitem->addColumn( tr("#"), _whsColumn, Qt::AlignCenter , true, "linenumber"); _coitem->addColumn( tr("Item Number"), _itemColumn, Qt::AlignLeft , true, "item_number"); _coitem->addColumn( tr("Description"), -1, Qt::AlignLeft , true, "itemdescrip"); _coitem->addColumn( tr("UOM"), _uomColumn, Qt::AlignCenter , true, "uom_name"); _coitem->addColumn( tr("Qty."), _qtyColumn, Qt::AlignRight , true, "shipitem_qty"); sCreateToggled(_create->isChecked()); sHandleButtons(); _reject = false; if (!_metrics->boolean("MultiWhs")) { _warehouseLit->hide(); _warehouse->hide(); } _order->setAllowedStatuses(OrderLineEdit::Open); _order->setAllowedTypes(OrderLineEdit::Sales | OrderLineEdit::Transfer); _order->setFromSitePrivsEnforced(TRUE); _order->setFocus(); _transDate->setEnabled(_privileges->check("AlterTransactionDates")); _transDate->setDate(omfgThis->dbDate(), true); _shipValue->setPrecision(omfgThis->moneyVal()); _shipValue->setDouble(0); }
shipOrder::shipOrder(QWidget* parent, const char* name, bool modal, Qt::WFlags fl) : XDialog(parent, name, modal, fl) { setupUi(this); connect(_create, SIGNAL(toggled(bool)), this, SLOT(sCreateToggled(bool))); connect(_select, SIGNAL(toggled(bool)), this, SLOT(sSelectToggled(bool))); connect(_ship, SIGNAL(clicked()), this, SLOT(sShip())); connect(_shipment, SIGNAL(newId(int)), this, SLOT(sFillList())); connect(_shipment, SIGNAL(newId(int)), this, SLOT(sFillTracknum())); connect(_soList, SIGNAL(clicked()), this, SLOT(sSoList())); connect(_soNumber, SIGNAL(newId(int)), this, SLOT(sHandleSo())); connect(_soNumber, SIGNAL(requestList()), this, SLOT(sSoList())); connect(_toNumber, SIGNAL(newId(int)), this, SLOT(sHandleTo())); connect(_tracknum, SIGNAL(activated(const QString&)), this, SLOT(sFillFreight())); connect(_tracknum, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(sFillFreight())); connect(_tracknum, SIGNAL(highlighted(const QString&)), this, SLOT(sFillFreight())); _captive = FALSE; #ifndef Q_WS_MAC _soList->setMaximumWidth(25); #endif _coitem->addColumn( tr("#"), _whsColumn, Qt::AlignCenter ); _coitem->addColumn( tr("Item Number"), _itemColumn, Qt::AlignLeft ); _coitem->addColumn( tr("Description"), -1, Qt::AlignLeft ); _coitem->addColumn( tr("UOM"), _uomColumn, Qt::AlignCenter ); _coitem->addColumn( tr("Qty."), _qtyColumn, Qt::AlignRight ); _select->setChecked(_privileges->check("SelectBilling") && _metrics->boolean("AutoSelectForBilling")); _select->setEnabled(_privileges->check("SelectBilling")); _create->setEnabled(_privileges->check("SelectBilling")); _toNumber->setVisible(_metrics->boolean("MultiWhs")); sCreateToggled(_create->isChecked()); sHandleButtons(); _reject = false; }
void shipOrder::sShip() { XSqlQuery shipq; shipq.prepare( "UPDATE shiphead " " SET shiphead_shipvia=:shiphead_shipvia," " shiphead_freight=:shiphead_freight," " shiphead_freight_curr_id=:shiphead_freight_curr_id," " shiphead_tracknum=:shiphead_tracknum " " WHERE (shiphead_id=:shiphead_id);"); shipq.bindValue(":shiphead_shipvia", _shipVia->currentText()); shipq.bindValue(":shiphead_freight", _freight->localValue()); shipq.bindValue(":shiphead_freight_curr_id", _freight->id()); shipq.bindValue(":shiphead_tracknum", _tracknum->currentText()); shipq.bindValue(":shiphead_id", _shipment->id()); shipq.exec(); if (shipq.lastError().type() != QSqlError::NoError) { systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__); return; } XSqlQuery rollback; rollback.prepare("ROLLBACK;"); // failed insertGLTransaction RETURNs -5 rather than RAISE EXCEPTION shipq.exec("BEGIN;"); shipq.prepare( "SELECT shipShipment(:shiphead_id, :ts) AS result;"); shipq.bindValue(":shiphead_id", _shipment->id()); shipq.bindValue(":ts", _transDate->date()); shipq.exec(); if (shipq.first()) { int result = shipq.value("result").toInt(); if (result == -6) { rollback.exec(); shipq.prepare("SELECT itemsite_id, tohead_trns_warehous_id," " tohead_dest_warehous_id " "FROM shiphead, shipitem, tohead, toitem, itemsite " "WHERE ((itemsite_item_id=toitem_item_id)" " AND (itemsite_warehous_id=tohead_src_warehous_id)" " AND (toitem_tohead_id=tohead_id)" " AND (shipitem_orderitem_id=toitem_id)" " AND (shiphead_id=shipitem_shiphead_id)" " AND (shiphead_order_type='TO')" " AND (NOT shiphead_shipped)" " AND (shiphead_id=:shiphead_id));"); shipq.bindValue(":shiphead_id", _shipment->id()); shipq.exec(); while (shipq.next()) { // missing transit itemsite is fatal here but not missing dest int transis = itemSite::createItemSite(this, shipq.value("itemsite_id").toInt(), shipq.value("tohead_trns_warehous_id").toInt(), false); int destis = itemSite::createItemSite(this, shipq.value("itemsite_id").toInt(), shipq.value("tohead_dest_warehous_id").toInt(), true); if (transis <= 0 || destis < 0) return; } if (shipq.lastError().type() != QSqlError::NoError) { systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__); return; } sShip(); // beware of endless loop if you change createItemSite err check return; // return because the recursive call cleans up for us } else if (result < 0) { rollback.exec(); systemError(this, storedProcErrorLookup("shipShipment", result), __FILE__, __LINE__); return; } } else if (shipq.lastError().type() != QSqlError::NoError) { rollback.exec(); QString errorStr = shipq.lastError().databaseText(); if(errorStr.startsWith("ERROR: null value in column \"gltrans_accnt_id\" violates not-null constraint")) errorStr = tr("One or more required accounts are not set or set incorrectly." " Please make sure that all your Cost Category and Sales Account Assignments" " are complete and correct."); systemError(this, errorStr, __FILE__, __LINE__); return; } shipq.exec("COMMIT;"); if (shipq.lastError().type() != QSqlError::NoError) { systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__); return; } // END the transaction if (_print->isChecked()) { ParameterList params; params.append("shiphead_id", _shipment->id()); params.append("print"); printPackingList newdlg(this, "", TRUE); newdlg.set(params); } if (_order->isSO() && _select->isChecked()) { shipq.prepare("SELECT selectUninvoicedShipment(:shiphead_id) AS result;"); shipq.bindValue(":shiphead_id", _shipment->id()); shipq.exec(); if (shipq.first()) { int cobmiscid = shipq.value("result").toInt(); if (cobmiscid < 0) { systemError(this, storedProcErrorLookup("selectUninvoicedShipment", cobmiscid), __FILE__, __LINE__); return; } else if (0 == cobmiscid) { QMessageBox::information(this, tr("Already Invoiced"), tr("<p>This shipment appears to have been " "invoiced already. It will not be selected " "for billing again.")); } else if (_create->isChecked()) { shipq.prepare("SELECT createInvoice(:cobmisc_id) AS result;"); shipq.bindValue(":cobmisc_id", cobmiscid); shipq.exec(); if (shipq.first()) { int result = shipq.value("result").toInt(); if (result < 0) { systemError(this, storedProcErrorLookup("postBillingSelection", result), __FILE__, __LINE__); return; } ParameterList params; params.append("invchead_id", result); printInvoice newdlg(this, "", TRUE); newdlg.set(params); newdlg.exec(); omfgThis->sInvoicesUpdated(result, TRUE); omfgThis->sSalesOrdersUpdated(_order->id()); } else if (shipq.lastError().type() != QSqlError::NoError) { systemError(this, shipq.lastError().databaseText() + tr("<p>Although Sales Order %1 was successfully shipped " "and selected for billing, the Invoice was not " "created properly. You may need to create an Invoice " "manually from the Billing Selection.") .arg(_order->id()), __FILE__, __LINE__); return; } omfgThis->sBillingSelectionUpdated(_order->id(), TRUE); } } else if (shipq.lastError().type() != QSqlError::NoError) { systemError(this, shipq.lastError().databaseText() + tr("<p>Although Sales Order %1 was successfully shipped, " "it was not selected for billing. You must manually " "select this Sales Order for Billing.") .arg(_order->id()), __FILE__, __LINE__); return; } } if (_order->isTO() && _receive->isChecked()) { QString recverr = tr("<p>Receiving inventory for this Transfer Order " "failed although Shipping the Order succeeded. " "Manually receive this order using the Enter Order " "Receipt window."); shipq.exec("BEGIN;"); ParameterList params; if (_metrics->boolean("MultiWhs")) params.append("MultiWhs"); params.append("tohead_id", _order->id()); params.append("orderid", _order->id()); params.append("ordertype", "TO"); params.append("shiphead_id", _shipment->id()); MetaSQLQuery recvm = mqlLoad("receipt", "receiveAll"); shipq = recvm.toQuery(params); while (shipq.next()) { int result = shipq.value("result").toInt(); if (result < 0) { rollback.exec(); systemError(this, recverr + storedProcErrorLookup("enterReceipt", result), __FILE__, __LINE__); } omfgThis->sPurchaseOrderReceiptsUpdated(); } if (shipq.lastError().type() != QSqlError::NoError) { rollback.exec(); systemError(this, recverr + "<br>" + shipq.lastError().databaseText(), __FILE__, __LINE__); } shipq.exec("COMMIT;"); if (shipq.lastError().type() != QSqlError::NoError) { systemError(this, recverr + "<br>" + shipq.lastError().databaseText(), __FILE__, __LINE__); } ParameterList recvParams; recvParams.append("tohead_id", _order->id()); enterPoReceipt *newdlg = new enterPoReceipt(); newdlg->set(recvParams); // to address bug 5680, replace // omfgThis->handleNewWindow(newdlg, Qt::ApplicationModal); // with newdlg->sPost(); // end of replacement } if (_captive) accept(); else { _order->setId(-1); _order->setEnabled(true); sHandleButtons(); _billToName->clear(); _shipToName->clear(); _shipToAddr1->clear(); _freight->setEnabled(TRUE); _freight->reset(); _shipVia->clear(); _shipment->clear(); _shipment->setEnabled(false); _close->setText(tr("&Close")); _order->setFocus(); } // Update the shipdatasum record to reflect shipped shipq.prepare("UPDATE shipdatasum " " SET shipdatasum_shipped=true " " WHERE ((shipdatasum_cosmisc_tracknum = :tracknum)" " AND ( (shipdatasum_shiphead_number=:shiphead_number)" " OR (:shiphead_number IS NULL)));"); shipq.bindValue(":tracknum", _tracknum->currentText()); if (! _shipment->number().isEmpty()) shipq.bindValue(":shiphead_number", _shipment->number()); shipq.exec(); if (shipq.lastError().type() != QSqlError::NoError) { systemError(this, shipq.lastError().databaseText(), __FILE__, __LINE__); return; } }