示例#1
0
void changePoitemQty::sPopulate(int pPoitemid)
{
  if (pPoitemid == -1)
  {
    _currentQtyReceived->clear();
    _newQtyReceived->clear();
    _currentQtyOrdered->clear();
    _newQty->clear();
    _currentQtyBalance->clear();
    _newQtyBalance->clear();
    _freight->clear();
  }
  else
  {
    q.prepare( "SELECT poitem_qty_ordered, poitem_qty_received, poitem_qty_returned,"
               "             poitem_freight "
               "FROM poitem "
               "WHERE (poitem_id=:poitem_id);" );
    q.bindValue(":poitem_id", pPoitemid);
    q.exec();
    if (q.first())
    {
      _currentQtyOrdered->setText(formatQty(q.value("poitem_qty_ordered").toDouble()));
      _currentQtyReceived->setText(formatQty(q.value("poitem_qty_received").toDouble()));
      _currentQtyBalance->setText(formatQty((q.value("poitem_qty_ordered").toDouble() - q.value("poitem_qty_received").toDouble())));
      _newQtyReceived->setText(formatQty(q.value("poitem_qty_received").toDouble()));
      _cacheFreight = q.value("poitem_freight").toDouble();
      _freight->setText(formatMoney(q.value("poitem_freight").toDouble()));
      sQtyChanged();
    }
  }
}
示例#2
0
void itemSource::populate()
{
  XSqlQuery itemsrcQ;
  itemsrcQ.prepare( "SELECT itemsrc_item_id, itemsrc_active, itemsrc_vend_id,"
             "       itemsrc_vend_item_number, itemsrc_vend_item_descrip,"
             "       itemsrc_vend_uom, formatUOMRatio(itemsrc_invvendoruomratio) AS invpurchratio,"
             "       itemsrc_minordqty, itemsrc_multordqty,"
             "       itemsrc_ranking, itemsrc_leadtime, itemsrc_comments "
             "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());
    _vendor->setId(itemsrcQ.value("itemsrc_vend_id").toInt());
    _vendorItemNumber->setText(itemsrcQ.value("itemsrc_vend_item_number").toString());
    _vendorItemDescrip->setText(itemsrcQ.value("itemsrc_vend_item_descrip").toString());
    _vendorUOM->setText(itemsrcQ.value("itemsrc_vend_uom").toString());
    _invVendorUOMRatio->setText(itemsrcQ.value("invpurchratio").toString());
    _minOrderQty->setText(formatQty(itemsrcQ.value("itemsrc_minordqty").toDouble()));
    _multOrderQty->setText(formatQty(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());
    sFillPriceList();
  }
  else if (itemsrcQ.lastError().type() != QSqlError::None)
  {
    systemError(this, itemsrcQ.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
示例#3
0
void invoiceItem::populate()
{
  XSqlQuery invcitem;
  invcitem.prepare( "SELECT invcitem.*,"
                    "       CASE WHEN (item_id IS NULL) THEN :na"
                    "            ELSE item_listprice"
                    "       END AS f_listprice "
                    "FROM invcitem LEFT OUTER JOIN item ON (invcitem_item_id=item_id) " 
                    "WHERE (invcitem_id=:invcitem_id);" );
  invcitem.bindValue(":invcitem_id", _invcitemid);
  invcitem.exec();
  if (invcitem.first())
  {
    _invcheadid = invcitem.value("invcitem_invchead_id").toInt();
    _lineNumber->setText(invcitem.value("invcitem_linenumber").toString());

    if (invcitem.value("invcitem_item_id").toInt() != -1)
    {
      _itemSelected->setChecked(TRUE);
      _item->setId(invcitem.value("invcitem_item_id").toInt());
      _warehouse->setId(invcitem.value("invcitem_warehous_id").toInt());
    }
    else
    {
      _miscSelected->setChecked(TRUE);
      _itemNumber->setText(invcitem.value("invcitem_number"));
      _itemDescrip->setText(invcitem.value("invcitem_descrip").toString());
      _salescat->setId(invcitem.value("invcitem_salescat_id").toInt());
    }

    _ordered->setText(formatQty(invcitem.value("invcitem_ordered").toDouble()));
    _billed->setText(formatQty(invcitem.value("invcitem_billed").toDouble()));
    _price->setLocalValue(invcitem.value("invcitem_price").toDouble());
    _custPrice->setLocalValue(invcitem.value("invcitem_custprice").toDouble());
    _listPrice->setBaseValue(invcitem.value("f_listprice").toDouble());

    _custPn->setText(invcitem.value("invcitem_custpn").toString());
    _notes->setText(invcitem.value("invcitem_notes").toString());

    // do taxcode/taxtype before invcitem_tax_* to avoid signal cascade problems
    _taxcode->setId(invcitem.value("invcitem_tax_id").toInt());
    _taxtype->setId(invcitem.value("invcitem_taxtype_id").toInt());

    _cachedPctA  = invcitem.value("invcitem_tax_pcta").toDouble();
    _cachedPctB  = invcitem.value("invcitem_tax_pctb").toDouble();
    _cachedPctC  = invcitem.value("invcitem_tax_pctc").toDouble();
    _cachedRateA = invcitem.value("invcitem_tax_ratea").toDouble();
    _cachedRateB = invcitem.value("invcitem_tax_rateb").toDouble();
    _cachedRateC = invcitem.value("invcitem_tax_ratec").toDouble();

    _tax->setLocalValue(_cachedRateA + _cachedRateB + _cachedRateC);
  }
  else if (q.lastError().type() != QSqlError::None)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  sCalculateExtendedPrice();
}
示例#4
0
void itemPricingScheduleItem::populate()
{
  if(_itemSelected->isChecked())
  {
    q.prepare( "SELECT ipsitem_item_id,"
               "       ipsitem_qtybreak, ipsitem_price "
               "FROM ipsitem "
               "WHERE (ipsitem_id=:ipsitem_id);" );
    q.bindValue(":ipsitem_id", _ipsitemid);
    q.exec();
    if (q.first())
    {
      _item->setId(q.value("ipsitem_item_id").toInt());
      _qtyBreak->setText(formatQty(q.value("ipsitem_qtybreak").toDouble()));
      _price->setLocalValue(q.value("ipsitem_price").toDouble());

      sUpdateMargins();
    }
  }
  else
  {
    q.prepare( "SELECT ipsprodcat_prodcat_id,"
               "       ipsprodcat_qtybreak, ipsprodcat_discntprcnt "
               "FROM ipsprodcat "
               "WHERE (ipsprodcat_id=:ipsprodcat_id);" );
    q.bindValue(":ipsprodcat_id", _ipsprodcatid);
    q.exec();
    if (q.first())
    {
      _prodcat->setId(q.value("ipsprodcat_prodcat_id").toInt());
      _qtyBreakCat->setText(formatQty(q.value("ipsprodcat_qtybreak").toDouble()));
      _discount->setText(formatPercent(q.value("ipsprodcat_discntprcnt").toDouble()));
    }
  }
}
示例#5
0
enum SetResponse transactionInformation::set(const ParameterList &pParams)
{
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("invhist_id", &valid);
  if (valid)
  {
    _invhistid = param.toInt();

    q.prepare( "SELECT * "
               "FROM invhist "
               "WHERE (invhist_id=:invhist_id);" );
    q.bindValue(":invhist_id", _invhistid);
    q.exec();
    if (q.first())
    {
      _analyze->setChecked(q.value("invhist_analyze").toBool());
      _transactionType->setText(q.value("invhist_transtype").toString());
      _transactionDate->setDate(q.value("invhist_transdate").toDate());
      _createdDate->setDate(q.value("invhist_created").toDate());
      _username->setText(q.value("invhist_user").toString());
      _item->setItemsiteid(q.value("invhist_itemsite_id").toInt());
      _transactionQty->setText(formatQty(q.value("invhist_invqty").toDouble()));
      _qohBefore->setText(formatQty(q.value("invhist_qoh_before").toDouble()));
      _qohAfter->setText(formatQty(q.value("invhist_qoh_after").toDouble()));
      _notes->setText(q.value("invhist_comments").toString());
    }
    else if (q.lastError().type() != QSqlError::NoError)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
  }

  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "edit")
      _mode = cEdit;
    else if (param.toString() == "view")
    {
      _mode = cView;

      _analyze->setEnabled(FALSE);

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

  return NoError;
}
示例#6
0
void changeWoQty::sChangeQty()
{
  if (_wo->status() == 'R')
  {
    QMessageBox::warning( this, tr("Cannot Reschedule Released W/O"),
                          tr( "The selected Work Order has been Released.\n"
                              "You must Recall this Work Order before Rescheduling it." ) );
    return;
  }

  double    newQty = _newQtyOrdered->toDouble();

  q.prepare( "SELECT validateOrderQty(wo_itemsite_id, :qty, TRUE) AS qty "
             "FROM wo "
             "WHERE (wo_id=:wo_id);" );
  q.bindValue(":wo_id", _wo->id());
  q.bindValue(":qty", _newQtyOrdered->toDouble());
  q.exec();
  if (q.first())
  {
    if (q.value("qty").toDouble() != newQty)
    {
      if ( QMessageBox::warning( this, tr("Invalid Order Qty"),
                                 tr( "The new Order Quantity that you have entered does not meet the Order Parameters set\n"
                                     "for the parent Item Site for this Work Order.  In order to meet the Item Site Order\n"
                                     "Parameters the new Order Quantity must be increased to %1.\n"
                                     "Do you want to change the Order Quantity for this Work Order to %2?" )
                                 .arg(formatQty(q.value("qty").toDouble()))
                                 .arg(formatQty(q.value("qty").toDouble())),
                                 tr("&Yes"), tr("&No"), QString::null, 0, 1 ) == 1 )
        return;
      else
        newQty = q.value("qty").toDouble();
    }

    q.prepare("SELECT changeWoQty(:wo_id, :qty, TRUE);");
    q.bindValue(":wo_id", _wo->id());
    q.bindValue(":qty", newQty);
    q.exec();

    if (_postComment->isChecked())
    {
      q.prepare("SELECT postComment(:cmnttype_id, 'W', :wo_id, :comment) AS _result");
      q.bindValue(":cmnttype_id", _cmnttype->id());
      q.bindValue(":wo_id", _wo->id());
      q.bindValue(":comment", _comment->text());
      q.exec();
    }

    omfgThis->sWorkOrdersUpdated(_wo->id(), TRUE);
  }
//  ToDo
  
  accept();
}
示例#7
0
void task::populate()
{
  q.prepare( "SELECT prjtask.* "
             "FROM prjtask "
             "WHERE (prjtask_id=:prjtask_id);" );
  q.bindValue(":prjtask_id", _prjtaskid);
  q.exec();
  if (q.first())
  {
    _number->setText(q.value("prjtask_number"));
    _name->setText(q.value("prjtask_name"));
    _descrip->setText(q.value("prjtask_descrip").toString());
    _owner->setUsername(q.value("prjtask_owner_username").toString());
    _assignedTo->setUsername(q.value("prjtask_username").toString());
    _started->setDate(q.value("prjtask_start_date").toDate());
    _assigned->setDate(q.value("prjtask_assigned_date").toDate());
    _due->setDate(q.value("prjtask_due_date").toDate());
    _completed->setDate(q.value("prjtask_completed_date").toDate());

    QString status = q.value("prjtask_status").toString();
    if("P" == status)
      _status->setCurrentIndex(0);
    else if("O" == status)
      _status->setCurrentIndex(1);
    else if("C" == status)
      _status->setCurrentIndex(2);

    _budgetHours->setText(formatQty(q.value("prjtask_hours_budget").toDouble()));
    _actualHours->setText(formatQty(q.value("prjtask_hours_actual").toDouble()));
    _budgetExp->setText(formatCost(q.value("prjtask_exp_budget").toDouble()));
    _actualExp->setText(formatCost(q.value("prjtask_exp_actual").toDouble()));

    _alarms->setId(_prjtaskid);
    _comments->setId(_prjtaskid);    
    sHoursAdjusted();
    sExpensesAdjusted();

    //if (q.value("prjtask_anyuser").toBool())
    //  _anyUser->setChecked(TRUE);
    //else
    //  _userList->setChecked(TRUE);
  }
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  //sFillUserList();
}
示例#8
0
void changePoitemQty::sQtyChanged()
{
  double qtyBalance = (_newQty->toDouble() - _newQtyReceived->text().toDouble());
  if (qtyBalance < 0)
    qtyBalance = 0;

  _newQtyBalance->setText(formatQty(qtyBalance));
}
示例#9
0
void changeWoQty::sQtyChanged(const QString &pNewQty)
{
  double qtyBalance = (pNewQty.toFloat() - _newQtyReceived->text().toFloat());
  if (qtyBalance < 0)
    qtyBalance = 0;

  _newQtyBalance->setText(formatQty(qtyBalance));
}
示例#10
0
void dspBacklogByItem::sFillList()
{
  _soitem->clear();
  if (_item->isValid())
  {
    MetaSQLQuery mql = mqlLoad(":/so/displays/SalesOrderItems.mql");
    ParameterList params;
    _dates->appendValue(params);
    _warehouse->appendValue(params);
    params.append("item_id", _item->id());
    params.append("openOnly");
    params.append("orderByScheddate");
    q = mql.toQuery(params);

    XTreeWidgetItem *last = 0;
    double totalBacklog = 0.0;
    while (q.next())
    {
      last = new XTreeWidgetItem(_soitem, last,
				 q.value("cohead_id").toInt(),
				 q.value("coitem_id").toInt(),
				 q.value("cohead_number"),
				 q.value("coitem_linenumber"),
				 q.value("cust_name"),
				 formatDate(q.value("cohead_orderdate").toDate()),
				 formatDate(q.value("coitem_scheddate").toDate()),
         q.value("uom_name"),
				 formatQty(q.value("coitem_qtyord").toDouble()),
				 formatQty(q.value("coitem_qtyshipped").toDouble()),
				 formatQty(q.value("qtybalance").toDouble()),
				 formatMoney(q.value("baseextpricebalance").toDouble()) );
      totalBacklog += q.value("baseextpricebalance").toDouble();
    }

    if (_showPrices->isChecked())
    {
      last = new XTreeWidgetItem(_soitem, last, -1, -1,
				 "", "", tr("Total Backlog"), "", "", "", "", "",
				 formatMoney(totalBacklog) );
    }
  }
  else
    _soitem->clear();
}
示例#11
0
enum SetResponse priceList::set(const ParameterList &pParams)
{
  QVariant param;
  bool     valid;

  param = pParams.value("cust_id", &valid);
  if (valid)
  {
    _cust->setId(param.toInt());
    _cust->setReadOnly(TRUE);
  }

  param = pParams.value("shipto_id", &valid);
  if (valid)
    _shiptoid = param.toInt();

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

  param = pParams.value("curr_id", &valid);
  if (valid)
  {
    _curr_id = param.toInt();
    if (! omfgThis->singleCurrency())
    {
      QString _currConcat;
      q.prepare("SELECT currConcat(:curr_id) AS currConcat;");
      q.bindValue(":curr_id", _curr_id);
      q.exec();
      if (q.first())
        _currConcat = q.value("currConcat").toString();
      else
        _currConcat = tr("?????");
      _price->headerItem()->setText(5, tr("Price\n(in %1)").arg(_currConcat));
    }
  }

  param = pParams.value("effective", &valid);
  _effective = (valid) ? param.toDate() : QDate::currentDate();

  param = pParams.value("qty", &valid);
  if (valid)
  {
    _qty->setText(formatQty(param.toDouble()));
    _qty->setEnabled(FALSE);
  }

  sFillList();

  return NoError;
}
示例#12
0
void dspReservations::sFillList()
{
  _allocations->clear();

  if (_item->isValid())
  {
    MetaSQLQuery mql = mqlLoad(":so/displays/Reservations/FillListDetail.mql");


    ParameterList params;
    params.append("warehous_id", _warehouse->id());
    params.append("item_id",	   _item->id());

    q = mql.toQuery(params);

    double runningBal = 0;
    XTreeWidgetItem *last = 0;

    while (q.next())
    {
      runningBal += q.value("coitem_qtyreserved").toDouble();

      last = new XTreeWidgetItem(_allocations, last,
				 q.value("source_id").toInt(),
				 q.value("order_number"),
				 q.value("totalqty"),
				 q.value("relievedqty"), q.value("balanceqty"),
				 formatQty(runningBal), q.value("duedate") );
      last->setTextColor(5, "red");
    }
    if (q.lastError().type() != QSqlError::None)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }

    QString avails("SELECT formatQty(itemsite_qtyonhand) AS f_qoh,"
		   "       formatQty(qtyunreserved(itemsite_id)) AS f_unreserved "
		   "FROM itemsite "
		   "WHERE ((itemsite_item_id=<? value(\"item_id\") ?>)"
		   "  AND  (itemsite_warehous_id=<? value(\"warehous_id\") ?>));");
    MetaSQLQuery availm(avails);
    q = availm.toQuery(params);
    if (q.first())
    {
      _qoh->setText(q.value("f_qoh").toString());
      _available->setText(q.value("f_unreserved").toString());
    }
    else if (q.lastError().type() != QSqlError::None)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
}
示例#13
0
void task::populate()
{
  q.prepare( "SELECT prjtask_number, prjtask_name, prjtask_descrip, prjtask_status,"
             "       prjtask_hours_budget, prjtask_hours_actual,"
             "       prjtask_exp_budget, prjtask_exp_actual "
             "FROM prjtask "
             "WHERE (prjtask_id=:prjtask_id);" );
  q.bindValue(":prjtask_id", _prjtaskid);
  q.exec();
  if (q.first())
  {
    _number->setText(q.value("prjtask_number"));
    _name->setText(q.value("prjtask_name"));
    _descrip->setText(q.value("prjtask_descrip").toString());

    QString status = q.value("prjtask_status").toString();
    if("P" == status)
      _status->setCurrentItem(0);
    else if("O" == status)
      _status->setCurrentItem(1);
    else if("C" == status)
      _status->setCurrentItem(2);

    _budgetHours->setText(formatQty(q.value("prjtask_hours_budget").toDouble()));
    _actualHours->setText(formatQty(q.value("prjtask_hours_actual").toDouble()));
    _budgetExp->setText(formatCost(q.value("prjtask_exp_budget").toDouble()));
    _actualExp->setText(formatCost(q.value("prjtask_exp_actual").toDouble()));

    sHoursAdjusted();
    sExpensesAdjusted();

    //if (q.value("prjtask_anyuser").toBool())
    //  _anyUser->setChecked(TRUE);
    //else
    //  _userList->setChecked(TRUE);
  }

  //sFillUserList();
}
示例#14
0
void salesHistoryInformation::populate()
{
  q.prepare( "SELECT cohist_ordernumber, cohist_invcnumber,"
             "       cohist_orderdate, cohist_invcdate,"
             "       cohist_billtoname, cohist_billtoaddress1,"
             "       cohist_billtoaddress2, cohist_billtoaddress3,"
             "       cohist_billtocity, cohist_billtostate, cohist_billtozip,"
             "       cohist_shiptoname, cohist_shiptoaddress1,"
             "       cohist_shiptoaddress2, cohist_shiptoaddress3,"
             "       cohist_shiptocity, cohist_shiptostate, cohist_shiptozip,"
             "       cohist_itemsite_id, cohist_salesrep_id, cohist_commissionpaid,"
             "       cohist_qtyshipped, cohist_unitprice, cohist_unitcost,"
             "       formatMoney(cohist_qtyshipped * cohist_unitprice) AS extprice,"
             "       formatMoney(cohist_qtyshipped * cohist_unitcost) AS extcost,"
             "       formatMoney(cohist_commission) AS f_commission "
             "FROM cohist "
             "WHERE (cohist_id=:sohist_id);" );
  q.bindValue(":sohist_id", _sohistid);
  q.exec();
  if (q.first())
  {
    _orderNumber->setText(q.value("cohist_ordernumber"));
    _invoiceNumber->setText(q.value("cohist_invcnumber"));
    _orderDate->setDate(q.value("cohist_orderdate").toDate());
    _invoiceDate->setDate(q.value("cohist_invcdate").toDate());
    _billtoName->setText(q.value("cohist_billtoname"));
    _billtoAddress1->setText(q.value("cohist_billtoaddress1"));
    _billtoAddress2->setText(q.value("cohist_billtoaddress2"));
    _billtoAddress3->setText(q.value("cohist_billtoaddress3"));
    _billtoCity->setText(q.value("cohist_billtocity"));
    _billtoState->setText(q.value("cohist_billtostate"));
    _billtoZip->setText(q.value("cohist_billtozip"));
    _shiptoName->setText(q.value("cohist_shiptoname"));
    _shiptoAddress1->setText(q.value("cohist_shiptoaddress1"));
    _shiptoAddress2->setText(q.value("cohist_shiptoaddress2"));
    _shiptoAddress3->setText(q.value("cohist_shiptoaddress3"));
    _shiptoCity->setText(q.value("cohist_shiptocity"));
    _shiptoState->setText(q.value("cohist_shiptostate"));
    _shiptoZip->setText(q.value("cohist_shiptozip"));

    _item->setItemsiteid(q.value("cohist_itemsite_id").toInt());
    _shipped->setText(formatQty(q.value("cohist_qtyshipped").toDouble()));
    _unitPrice->setText(formatSalesPrice(q.value("cohist_unitprice").toDouble()));
    _unitCost->setText(formatSalesPrice(q.value("cohist_unitcost").toDouble()));
    _extendedPrice->setText(q.value("extprice").toString());
    _extendedCost->setText(q.value("extcost").toString());
    _salesrep->setId(q.value("cohist_salesrep_id").toInt());
    _commission->setText(q.value("f_commission"));
    _commissionPaid->setChecked(q.value("cohist_commissionpaid").toBool());
  }
}
示例#15
0
void dspOrders::sFillList()
{
  _orders->clear();

  if ( (_item->isValid()) &&
       ( (_leadTime->isChecked()) || (_byDays->isChecked()) ||
         ((_byDate->isChecked()) && (_date->isValid())) ||
         (_byRange->isChecked() && _startDate->isValid() && _endDate->isValid()) ) )
  {
    MetaSQLQuery mql = mqlLoad(":/im/displays/Orders/FillListDetail.mql");
    ParameterList params;
    params.append("warehous_id", _warehouse->id());
    params.append("item_id",     _item->id());
    params.append("itemType",    _item->itemType());
    if (_leadTime->isChecked())
      params.append("useLeadTime");
    else if (_byDays->isChecked())
      params.append("days",      _days->value());
    else if (_byDate->isChecked())
      params.append("date",      _date->date());
    else if (_byRange->isChecked())
    {
      params.append("startDate", _startDate->date());
      params.append("endDate",   _endDate->date());
    }

    q = mql.toQuery(params);
    double          runningBal = 0;
    XTreeWidgetItem *last = 0;
    while (q.next())
    {
      runningBal += q.value("balanceqty").toDouble();

      last = new XTreeWidgetItem(_orders, last,
				 q.value("source_id").toInt(),
				 q.value("type").toInt(),
				 q.value("order_type"), q.value("order_number"),
				 q.value("totalqty"), q.value("relievedqty"),
				 q.value("balanceqty"), formatQty(runningBal),
				 q.value("duedate") );
      if (q.value("late").toBool())
	last->setTextColor(6, "red");
    }
  }
}
示例#16
0
enum SetResponse changeWoQty::set(const ParameterList &pParams)
{
  _captive = TRUE;

  QVariant param;
  bool     valid;

  param = pParams.value("wo_id", &valid);
  if (valid)
  {
    _wo->setId(param.toInt());
    _wo->setReadOnly(TRUE);
    _newQtyOrdered->setFocus();
  }

  param = pParams.value("newQty", &valid);
  if (valid)
    _newQtyOrdered->setText(formatQty(param.toDouble()));

  return NoError;
}
示例#17
0
enum SetResponse changePoitemQty::set(const ParameterList &pParams)
{
  _captive = TRUE;

  QVariant param;
  bool     valid;

  param = pParams.value("pohead_id", &valid);
  if (valid)
  {
    _po->setId(param.toInt());
    _po->setReadOnly(TRUE);
    _newQty->setFocus();
  }

  param = pParams.value("poitem_id", &valid);
  if (valid)
  {
    q.prepare( "SELECT poitem_pohead_id "
               "FROM poitem "
               "WHERE (poitem_id=:poitem_id);" );
    q.bindValue(":poitem_id", param.toInt());
    q.exec();
    if (q.first())
    {
      _po->setId(q.value("poitem_pohead_id").toInt());
      _po->setReadOnly(TRUE);
      _poitem->setId(param.toInt());
    }

    _newQty->setFocus();
  }

  param = pParams.value("newQty", &valid);
  if (valid)
    _newQty->setText(formatQty(param.toDouble()));

  return NoError;
}
示例#18
0
void dspBookingsByProductCategory::sFillList()
{
  if (!checkParameters())
      return;

  _soitem->clear();
  
  MetaSQLQuery mql = mqlLoad(":/so/displays/SalesOrderItems.mql");
  ParameterList params;
  _dates->appendValue(params);
  _warehouse->appendValue(params);
  _productCategory->appendValue(params);
  params.append("orderByOrderdate");
  q = mql.toQuery(params);

  XTreeWidgetItem *last = 0;
  bool exchangeError = false;
  while (q.next())
  {
    if (q.value("baseunitprice").toDouble() < 0.0)
      exchangeError = true;
    last = new XTreeWidgetItem(_soitem, last,
         q.value("coitem_id").toInt(),
         q.value("cohead_number"),
         formatDate(q.value("cohead_orderdate").toDate()),
         q.value("cust_number"),
         q.value("cust_name"),
         q.value("item_number"),
         formatQty(q.value("coitem_qtyord").toDouble()),
         formatSalesPrice(q.value("baseunitprice").toDouble()),
         formatMoney(q.value("baseextprice").toDouble()) );
  }
  if (exchangeError)
    QMessageBox::warning( this, tr("Currency Exchange Rate Error"),
                          tr("One or more of the Prices could not be converted to Base Currency.\n"
                             "These Prices have been set to a negative value.") );
}
示例#19
0
void dspQuotesByItem::sFillList()
{
  _so->clear();

  if ((_item->isValid()) && (_dates->allValid()))
  {
    MetaSQLQuery mql = mqlLoad(":/so/displays/QuoteItems.mql");
    ParameterList params;
    _dates->appendValue(params);
    params.append("item_id", _item->id());

    q = mql.toQuery(params);
    XTreeWidgetItem *last = 0;
    while (q.next())
    {
      last = new XTreeWidgetItem(_so, last,
				 q.value("quhead_id").toInt(),
				 q.value("quhead_number"),
				 formatDate(q.value("quhead_quotedate").toDate()),
				 q.value("cust_name"),
				 formatQty(q.value("quitem_qtyord").toDouble()) );
    }
  }
}
示例#20
0
void workOrder::sCreate()
{
  if(cRelease == _mode || cNew == _mode)
  {
    if (!_woNumber->text().length())
    {
      QMessageBox::information( this, tr("Cannot Create Work Order"),
                                tr("You must enter a valid Work Order number before creating this Work Order")  );
      _woNumber->setFocus();
      return;
    }
  
    if (!(_item->isValid()))
    {
      QMessageBox::information( this, tr("Cannot Create Work Order"),
                                tr("You must enter or select a valid Item number before creating this Work Order")  );
      return;
    }
  
    if ((!_qty->text().length()) || (_qty->toDouble() == 0.0))
    {
      QMessageBox::information( this, tr("Cannot Create Work Order"),
                                tr( "You have entered an invalid Qty. Ordered.\n"
                                    "Please correct before creating this Work Order"  ) );
      _qty->setFocus();
      return;
    }
  
    if (!_dueDate->isValid())
    {
      QMessageBox::information( this, tr("Cannot Create Work Order"),
                                tr( "You have entered an invalid Due Date.\n"
                                    "Please correct before creating this Work Order"  ) );
      _dueDate->setFocus();
      return;
    }
  
    q.prepare( "SELECT itemsite_id "
               "FROM itemsite "
               "WHERE ( (itemsite_item_id=:item_id)"
               " AND (itemsite_warehous_id=:warehous_id) );" );
    q.bindValue(":item_id", _item->id());
    q.bindValue(":warehous_id", _warehouse->id());
    q.exec();
    if (!q.first())
    {
      QMessageBox::warning(this, tr("Invalid Warehouse"),
          tr("The Warehouse which you selected for this Item is not\n"
             "a \"Supplied At\" Warehouse. You must select a different\n"
             " Warehouse before creating this Work Order.") );
      return;
    }
  
    int itemsiteid = q.value("itemsite_id").toInt();
  
    q.prepare("SELECT validateOrderQty(:itemsite_id, :qty, TRUE) AS qty;");
    q.bindValue(":itemsite_id", itemsiteid);
    q.bindValue(":qty", _qty->toDouble());
    q.exec();
    if (!q.first())
    {
      systemError(this, tr("A System Error occurred at %1::%2.")
                        .arg(__FILE__)
                        .arg(__LINE__) );
      return;
    }
  
    double orderQty = q.value("qty").toDouble();
    if (orderQty != _qty->toDouble())
    {
      if ( QMessageBox::warning( this, tr("Invalid Order Quantitiy"),
                                 tr( "Order Parameters for this Item do not allow a quantitiy of %1 to be created.\n"
                                     "You must create an order for at least %2 of this item.\n"
                                     "Do you want to update the order quantity and create the order?" )
                                 .arg(formatQty(_qty->toDouble()))
                                 .arg(formatQty(orderQty)),
                                 tr("&Yes"), tr("&No"), 0, 1 ) == 1)
        return; 
    }
  
    q.prepare( "SELECT createWo( :woNumber, :itemsite_id, :priority, :orderQty,"
               "                 :leadTime, :dueDate, :productionNotes, :ordtype, :ordid, :prj_id,"
			   "                 :bom_rev_id, :boo_rev_id) AS result;" );
    q.bindValue(":woNumber", _woNumber->text().toInt());
    q.bindValue(":itemsite_id", itemsiteid);
    q.bindValue(":priority", _priority->value());
    q.bindValue(":orderQty", orderQty);
    q.bindValue(":leadTime", _leadTime->value());
    q.bindValue(":dueDate", _dueDate->date());
    q.bindValue(":productionNotes", _productionNotes->text());
    q.bindValue(":prj_id", _project->id());
	q.bindValue(":bom_rev_id", _bomRevision->id());
	q.bindValue(":boo_rev_id", _booRevision->id());
    if(cRelease == _mode)
    {
      q.bindValue(":ordtype", _planordtype);
      q.bindValue(":ordid", _sourceid);
    }
    else
    {
      q.bindValue(":ordtype", QString(""));
      q.bindValue(":ordid", -1);
    }
    q.exec();
    if (!q.first())
    {
      systemError(this, tr("A System Error occurred at %1::%2.")
                        .arg(__FILE__)
                        .arg(__LINE__) );
      return;
    }
  
    int _woid = q.value("result").toInt();
  
    q.prepare("SELECT updateCharAssignment('W', :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", _woid);
      q.bindValue(":char_id", _itemchar->data(idx1, Qt::UserRole));
      q.bindValue(":char_value", _itemchar->data(idx2, Qt::DisplayRole));
      q.exec();
    }
  
  
    if (_mode == cRelease)
    {
      q.prepare("SELECT releasePlannedOrder(:planord_id, FALSE) AS result;");
      q.bindValue(":planord_id", _planordid);
      q.exec();
    }
  
    if (_woid == -1)
      QMessageBox::critical( this, tr("Work Order not Exploded"),
                             tr( "The Work 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 Work Order." ));
    else if (_woid == -2)
      QMessageBox::critical( this, tr("Work Order not Exploded"),
                             tr( "The Work Order was created but not Exploded as Component Items defined in the Bill of Materials for\n"
                                 "the selected Work Order Item do not exist in the selected  Work Order Warehouse.\n"
                                 "You must create Item Sites for these Component Items before you may explode this Work Order." ));
    else
    {
      if (_printTraveler->isChecked())
      {
        ParameterList params;
        params.append("wo_id", _woid);
  
        printWoTraveler newdlg(this, "", TRUE);
        newdlg.set(params);
        newdlg.exec();
      }
    }
  }
  else if(cEdit == _mode)
  {
    if ((!_qty->text().length()) || (_qty->toDouble() == 0.0))
    {
      QMessageBox::information( this, tr("Cannot Create Work Order"),
                                tr( "You have entered an invalid Qty. Ordered.\n"
                                    "Please correct before creating this Work Order"  ) );
      _qty->setFocus();
      return;
    }
  
    if (!_dueDate->isValid())
    {
      QMessageBox::information( this, tr("Cannot Create Work Order"),
                                tr( "You have entered an invalid Due Date.\n"
                                    "Please correct before updating this Work Order"  ) );
      _dueDate->setFocus();
      return;
    }
  
    if (!_startDate->isValid())
    {
      QMessageBox::information( this, tr("Cannot Create Work Order"),
                                tr( "You have entered an invalid Start Date.\n"
                                    "Please correct before updating this Work Order"  ) );
      _dueDate->setFocus();
      return;
    }

    q.prepare("UPDATE wo"
              "   SET wo_prodnotes=:productionNotes,"
              "       wo_prj_id=:prj_id,"
			  "       wo_bom_rev_id=:bom_rev_id,"
			  "       wo_boo_rev_id=:boo_rev_id,"
			  "       wo_cosmethod=:wo_cosmethod"
              " WHERE (wo_id=:wo_id); ");
    q.bindValue(":wo_id", _woid);
    q.bindValue(":productionNotes", _productionNotes->text());
    q.bindValue(":prj_id", _project->id());
	q.bindValue(":bom_rev_id", _bomRevision->id());
	q.bindValue(":boo_rev_id", _booRevision->id());
	if (_todate->isChecked() && _jobCosGroup->isEnabled())
		q.bindValue(":wo_cosmethod",QString("D"));
	else if (_proportional->isChecked() && _jobCosGroup->isEnabled())
		q.bindValue(":wo_cosmethod",QString("P"));
    q.exec();

    q.prepare("SELECT updateCharAssignment('W', :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", _woid);
      q.bindValue(":char_id", _itemchar->data(idx1, Qt::UserRole));
      q.bindValue(":char_value", _itemchar->data(idx2, Qt::DisplayRole));
      q.exec();
    }

    if(_startDate->date() != _oldStartDate || _dueDate->date() != _oldDueDate)
    {
      q.prepare("SELECT changeWoDates(:wo_id, :startDate, :dueDate, :rescheduleChildren);");
      q.bindValue(":wo_id", _woid);
      q.bindValue(":startDate", _startDate->date());
      q.bindValue(":dueDate", _dueDate->date());
      q.bindValue(":rescheduleChildren", QVariant(true, 0));
      q.exec();
    }

    if(_priority->value() != _oldPriority)
    {
      q.prepare("SELECT reprioritizeWo(:wo_id, :newPriority, :reprioritizeChildren);");
      q.bindValue(":wo_id", _woid);
      q.bindValue(":newPriority", _priority->value());
      q.bindValue(":reprioritizeChildren", QVariant(true, 0));
      q.exec();
    }

    if(_qty->text() != _oldQty)
    {
      double newQty = _qty->toDouble();
      q.prepare( "SELECT validateOrderQty(wo_itemsite_id, :qty, TRUE) AS qty "
                 "FROM wo "
                 "WHERE (wo_id=:wo_id);" );
      q.bindValue(":wo_id", _woid);
      q.bindValue(":qty", newQty);
      q.exec();
      if (q.first())
      {
        if (q.value("qty").toDouble() != newQty)
        {
          if ( QMessageBox::warning( this, tr("Invalid Order Qty"),
                                     tr( "The new Order Quantity that you have entered does not meet the Order Parameters set\n"
                                         "for the parent Item Site for this Work Order.  In order to meet the Item Site Order\n"
                                         "Parameters the new Order Quantity must be increased to %1.\n"
                                         "Do you want to change the Order Quantity for this Work Order to %2?" )
                                     .arg(formatQty(q.value("qty").toDouble()))
                                     .arg(formatQty(q.value("qty").toDouble())),
                                     tr("&Yes"), tr("&No"), QString::null, 0, 1 ) == 1 )
            return;
          else
            newQty = q.value("qty").toDouble();
        }

        q.prepare("SELECT changeWoQty(:wo_id, :qty, TRUE);");
        q.bindValue(":wo_id", _woid);
        q.bindValue(":qty", newQty);
        q.exec();
      }
    }
  }
  
  omfgThis->sWorkOrdersUpdated(_woid, TRUE);
  
  if (_captive)
    close();
  else
  {
    populateWoNumber();
    _item->setId(-1);
    _qty->clear();
    _dueDate->setNull();
    _leadTime->setValue(0);
    _startDate->clear();
    _productionNotes->clear();
    _itemchar->removeRows(0, _itemchar->rowCount());
    _close->setText(tr("&Close"));

    _item->setFocus();
  }

}
示例#21
0
enum SetResponse workOrder::set(const ParameterList &pParams)
{
  _captive = TRUE;

  QString  returnValue;
  QVariant param;
  bool     valid;

  param = pParams.value("itemsite_id", &valid);
  if (valid)
  {
    _item->setItemsiteid(param.toInt());
    _item->setEnabled(FALSE);
    _warehouse->setEnabled(FALSE);

    _qty->setFocus();
  }

  param = pParams.value("qty", &valid);
  if (valid)
    _qty->setText(formatQty(param.toDouble()));

  param = pParams.value("dueDate", &valid);
  if (valid)
  {
    _dueDate->setDate(param.toDate());
    sUpdateStartDate();
  }

  param = pParams.value("wo_id", &valid);
  if (valid)
    _woid = param.toInt();

  param = pParams.value("planord_id", &valid);
  if (valid)
    _planordid = param.toInt();

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

	  _item->setQuery("SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2,"
                      "       item_active, item_config, item_type, uom_name "
                      "FROM item JOIN uom ON (item_inv_uom_id=uom_id) "
                      "WHERE (item_type IN ('M', 'B') "
					  "AND (item_active)) ");
      _qtyReceivedLit->clear();
      _tabs->removePage(_tabs->page(3));

      populateWoNumber();
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;

     _item->setQuery("SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2,"
                     "       item_active, item_config, item_type, uom_name "
                     "FROM item JOIN uom ON (item_inv_uom_id=uom_id) "
                     "WHERE (item_type IN ('M', 'B', 'J')) ");
      XSqlQuery wo;
      wo.prepare( "SELECT wo_itemsite_id, wo_priority, wo_status,"
                  "       formatWoNumber(wo_id) AS f_wonumber,"
                  "       formatQty(wo_qtyord) AS f_ordered,"
                  "       formatQty(wo_qtyrcv) AS f_received,"
                  "       wo_startdate, wo_duedate,"
                  "       formatMoney(wo_wipvalue) AS f_wipvalue,"
				  "       formatMoney(wo_postedvalue) AS f_postedvalue,"
				  "       formatMoney(wo_postedvalue-wo_wipvalue) AS f_rcvdvalue,"
                  "       wo_prodnotes, wo_prj_id, "
				  "       wo_bom_rev_id, wo_boo_rev_id, "
				  "       wo_cosmethod "
                  "FROM wo "
                  "WHERE (wo_id=:wo_id);" );
      wo.bindValue(":wo_id", _woid);
      wo.exec();
      if (wo.first())
      {
        _oldPriority = wo.value("wo_priority").toInt();
        _oldStartDate = wo.value("wo_startdate").toDate();
        _oldDueDate = wo.value("wo_duedate").toDate();
        _oldQty = wo.value("f_ordered").toString();

        _woNumber->setText(wo.value("f_wonumber").toString());
        _item->setItemsiteid(wo.value("wo_itemsite_id").toInt());
        _priority->setValue(_oldPriority);
		_postedValue->setText(wo.value("f_postedvalue").toString());
		_rcvdValue->setText(wo.value("f_rcvdvalue").toString());
        _wipValue->setText(wo.value("f_wipvalue").toString());
        _qty->setText(wo.value("f_ordered").toString());
        _qtyReceived->setText(wo.value("f_received").toString());
        _startDate->setDate(_oldStartDate);
        _dueDate->setDate(_oldDueDate);
        _productionNotes->setText(wo.value("wo_prodnotes").toString());
        _comments->setId(_woid);
        _project->setId(wo.value("wo_prj_id").toInt());
		_bomRevision->setId(wo.value("wo_bom_rev_id").toInt());
		_booRevision->setId(wo.value("wo_boo_rev_id").toInt());

		if (wo.value("wo_cosmethod").toString() == "D")
		  _todate->setChecked(TRUE);
		else if (wo.value("wo_cosmethod").toString() == "P")
		  _proportional->setChecked(TRUE);
		else
	      _jobCosGroup->hide();

        // If the W/O is closed or Released don't allow changing some items.
        if(wo.value("wo_status").toString() == "C" || wo.value("wo_status") == "R")
        {
          _priority->setEnabled(false);
          _qty->setEnabled(false);
          _dueDate->setEnabled(false);
          _startDate->setEnabled(false);
        }

        _startDate->setEnabled(true);
        _woNumber->setEnabled(false);
        _item->setReadOnly(true);
	    _bomRevision->setEnabled(wo.value("wo_status").toString() == "O");
        _booRevision->setEnabled(wo.value("wo_status").toString() == "O");
        _warehouse->setEnabled(false);
        _comments->setReadOnly(false);
        _leadTimeLit->hide();
        _leadTime->hide();
        _daysLit->hide();
        _printTraveler->hide();
        _bottomSpacer->hide();
        _create->setText(tr("&Save"));

        _close->setFocus();
      }
      else
      {
        systemError(this, tr("A System Error occurred at %1::%2, W/O ID %3.")
                          .arg(__FILE__)
                          .arg(__LINE__)
                          .arg(_woid) );
        close();
      }
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _item->setQuery("SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2,"
                      "       item_active, item_config, item_type, uom_name "
                      "FROM item JOIN uom ON (item_inv_uom_id=uom_id) "
                      "WHERE (item_type IN ('M', 'B', 'J')) ");
      XSqlQuery wo;
      wo.prepare( "SELECT wo_itemsite_id, wo_priority,"
                  "       formatWoNumber(wo_id) AS f_wonumber,"
                  "       formatQty(wo_qtyord) AS f_ordered,"
                  "       formatQty(wo_qtyrcv) AS f_received,"
                  "       wo_startdate, wo_duedate,"
                  "       formatMoney(wo_wipvalue) AS f_wipvalue,"
				  "       formatMoney(wo_postedvalue) AS f_postedvalue,"
				  "       formatMoney(wo_postedvalue-wo_wipvalue) AS f_rcvdvalue,"
                  "       wo_prodnotes, wo_prj_id, wo_bom_rev_id, "
				  "       wo_boo_rev_id, wo_cosmethod "
                  "FROM wo "
                  "WHERE (wo_id=:wo_id);" );
      wo.bindValue(":wo_id", _woid);
      wo.exec();
      if (wo.first())
      {
        _mode = cView;

        _woNumber->setText(wo.value("f_wonumber").toString());
        _item->setItemsiteid(wo.value("wo_itemsite_id").toInt());
        _priority->setValue(wo.value("wo_priority").toInt());
		_postedValue->setText(wo.value("f_postedvalue").toString());
		_rcvdValue->setText(wo.value("f_rcvdvalue").toString());
        _wipValue->setText(wo.value("f_wipvalue").toString());
        _qty->setText(wo.value("f_ordered").toString());
        _qtyReceived->setText(wo.value("f_received").toString());
        _startDate->setDate(wo.value("wo_startdate").toDate());
        _dueDate->setDate(wo.value("wo_duedate").toDate());
        _productionNotes->setText(wo.value("wo_prodnotes").toString());
        _comments->setId(_woid);
        _project->setId(wo.value("wo_prj_id").toInt());
		_bomRevision->setId(wo.value("wo_bom_rev_id").toInt());
		_booRevision->setId(wo.value("wo_boo_rev_id").toInt());

		if (wo.value("wo_cosmethod").toString() == "D")
		  _todate->setChecked(TRUE);
		else if (wo.value("wo_cosmethod").toString() == "P")
		  _proportional->setChecked(TRUE);
		else
	      _jobCosGroup->hide();
 
        _woNumber->setEnabled(FALSE);
        _item->setReadOnly(TRUE);
        _bomRevision->setEnabled(FALSE);
        _booRevision->setEnabled(FALSE);
        _warehouse->setEnabled(FALSE);
        _priority->setEnabled(FALSE);
        _qty->setEnabled(FALSE);
        _startDate->setEnabled(FALSE);
        _dueDate->setEnabled(FALSE);
        _productionNotes->setReadOnly(TRUE);
        _create->hide();
        _leadTimeLit->hide();
        _leadTime->hide();
        _daysLit->hide();
        _printTraveler->hide();
        _bottomSpacer->hide();
        _close->setText(tr("&Close"));
        _project->setEnabled(FALSE);
        _itemcharView->setEnabled(false);
		_jobCosGroup->setEnabled(FALSE);
        
        _close->setFocus();
      }
      else
      {
        systemError(this, tr("A System Error occurred at %1::%2, W/O ID %3.")
                          .arg(__FILE__)
                          .arg(__LINE__)
                          .arg(_woid) );
        close();
      }
    }
    else if (param.toString() == "release")
    {
      _mode = cRelease;
      _tabs->removePage(_tabs->page(3));

      q.prepare( "SELECT planord_itemsite_id, planord_duedate,"
                 "       CASE WHEN(planord_mps) THEN 'P'"
                 "            ELSE 'M'"
                 "       END AS sourcetype,"
                 "       CASE WHEN(planord_mps) THEN planord_pschitem_id"
                 "            ELSE planord_id"
                 "       END AS sourceid,"
                 "       formatQty(planord_qty) AS qty "
                 "FROM planord "
                 "WHERE (planord_id=:planord_id);" );
      q.bindValue(":planord_id", _planordid);
      q.exec();
      if (q.first())
      {
        _item->setReadOnly(TRUE);
        _warehouse->setEnabled(FALSE);

        _planordtype=q.value("sourcetype").toString();
        _sourceid=q.value("sourceid").toInt();
        _qty->setText(q.value("qty").toString());
        _dueDate->setDate(q.value("planord_duedate").toDate());
        _item->setItemsiteid(q.value("planord_itemsite_id").toInt());

        sUpdateStartDate();
        populateWoNumber();

        _qty->setEnabled(FALSE);
        _qtyReceivedLit->clear();
        _startDate->setEnabled(FALSE);
        _dueDate->setEnabled(FALSE);
        _wipValueLit->hide();
        _wipValue->hide();
        _leadTimeLit->hide();
        _leadTime->hide();
        _daysLit->hide();

        _create->setFocus();
      }
      else
      {
        systemError(this, tr("A System Error occurred at %1::%2, Planned Order ID %3.")
                          .arg(__FILE__)
                          .arg(__LINE__)
                          .arg(_planordid) );
        close();
      }
    }
  }
  
  return NoError;
}
示例#22
0
void selectOrderForBilling::sFillList()
{
  _soitem->clear();

  if (_so->isValid())
  {
    QString sql( "SELECT coitem_id, coitem_linenumber,"
                 "       item_number, iteminvpricerat(item_id) AS invpricerat,"
                 "       warehous_code, coitem_price,"
                 "       uom_name,"
                 "       formatQty(coitem_qtyord) AS f_qtyord,"
                 "       formatQty(coitem_qtyshipped) AS f_qtyshipped,"
                 "       formatQty(coitem_qtyreturned) AS f_qtyreturned,"
                 "       formatQty( ( SELECT COALESCE(SUM(coship_qty), 0)"
                 "                    FROM coship "
                 "                    WHERE ( (coship_coitem_id=coitem_id)"
                 "                     AND (NOT coship_invoiced) ) )"
                 "                 ) AS f_qtyatship,"
                 "       ( SELECT COALESCE(SUM(cobill_qty), 0)"
                 "         FROM cobill, cobmisc "
                 "         WHERE ( (cobill_cobmisc_id=cobmisc_id)"
                 "          AND (cobill_coitem_id=coitem_id)"
                 "          AND (NOT cobmisc_posted) ) ) AS qtytobill,"
                 "       round(( "
                 "         ( SELECT COALESCE(SUM(cobill_qty), 0)"
                 "           FROM cobill, cobmisc "
                 "           WHERE ( (cobill_cobmisc_id=cobmisc_id)"
                 "            AND (cobill_coitem_id=coitem_id)"
                 "            AND (NOT cobmisc_posted) ) ) * coitem_qty_invuomratio "
                 "           * ( coitem_price / coitem_price_invuomratio)), 2) AS extended, "
                 "       formatMoney(round(( "
                 "         ( SELECT COALESCE(SUM(cobill_qty), 0)"
                 "           FROM cobill, cobmisc "
                 "           WHERE ( (cobill_cobmisc_id=cobmisc_id)"
                 "            AND (cobill_coitem_id=coitem_id)"
                 "            AND (NOT cobmisc_posted) ) ) * coitem_qty_invuomratio "
                 "          * (coitem_price / coitem_price_invuomratio)), 2)) AS f_extended, "
                 "       formatBoolYN( ( SELECT COALESCE(cobill_toclose, FALSE)"
                 "                       FROM cobill, cobmisc "
                 "                       WHERE ((cobill_cobmisc_id=cobmisc_id)"
                 "                        AND (cobill_coitem_id=coitem_id)"
                 "                        AND (NOT cobmisc_posted))"
                 "                       ORDER BY cobill_toclose DESC"
                 "                       LIMIT 1) ) AS toclose "
                 "FROM coitem, itemsite, item, warehous, uom "
                 "WHERE ( (coitem_itemsite_id=itemsite_id)"
                 " AND (coitem_status <> 'X')"
                 " AND (coitem_qty_uom_id=uom_id)"
                 " AND (itemsite_item_id=item_id)"
                 " AND (itemsite_warehous_id=warehous_id)"
		 " <? if exists(\"showOpenOnly\") ?>"
		 " AND (coitem_status <> 'C')"
		 " <? endif ?>"
		 " AND (coitem_cohead_id=<? value(\"sohead_id\") ?>) ) "
		 "ORDER BY coitem_linenumber;" );

    ParameterList params;
    if (!_showClosed->isChecked())
      params.append("showOpenOnly");
    params.append("sohead_id", _so->id());
    MetaSQLQuery mql(sql);
    q = mql.toQuery(params);
    if (q.first())
    {
      double subtotal = 0.0;

      XTreeWidgetItem* last = 0;
      do
      {
        subtotal += q.value("extended").toDouble();

        last = new XTreeWidgetItem(_soitem, last, q.value("coitem_id").toInt(),
                            q.value("coitem_linenumber"), q.value("item_number"),
                            q.value("warehous_code"), q.value("uom_name"), q.value("f_qtyord"),
                            q.value("f_qtyshipped"), q.value("f_qtyreturned"),
                            q.value("f_qtyatship"), formatQty(q.value("qtytobill").toDouble()),
                            q.value("f_extended"), q.value("toclose") );
      }
      while (q.next());

      _subtotal->setLocalValue(subtotal);
    }
    else
    {
      if (q.lastError().type() != QSqlError::None)
	systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      _subtotal->clear();
    }

    recalculateTax();
  }
}
示例#23
0
void PoitemTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *pModel, const QModelIndex &index) const
{
  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, new QVariant());
	  model->setData(model->index(index.row(), ITEM_ID_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), new QVariant());
	  model->setData(model->index(index.row(), WAREHOUS_ID_COL), new QVariant());
	  model->setData(model->index(index.row(), WAREHOUS_CODE_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_ITEMSRC_ID_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_ITEM_NUMBER_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_ITEM_DESCRIP_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_UOM_COL), new QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_MINORDQTY_COL), new QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_MULTORDQTY_COL), new QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_INVVENDORUOMRATIO_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_INVVENDUOMRATIO_COL), new QVariant());
	  model->setData(model->index(index.row(), EARLIESTDATE_COL), new 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 (itemq.lastError().type() != QSqlError::None)
	    {
	      systemError(0, itemq.lastError().databaseText(), __FILE__, __LINE__);
	      hitError = true;
	      break;
	    }
	    else
	    {
	      systemError(0, QString("Could not find Item Site for %1 (%2).")
			      .arg(item->itemNumber()).arg(item->id()));
	      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, new QString());
		model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), new QVariant());
		model->setData(model->index(index.row(), WAREHOUS_ID_COL), new QVariant());
		model->setData(model->index(index.row(), WAREHOUS_CODE_COL), new QString());
		model->setData(index, new QString());
		hitError = true;
		break;
	      }
	      else if (stdcostq.lastError().type() != QSqlError::None)
	      {
		systemError(0, stdcostq.lastError().databaseText(), __FILE__, __LINE__);
		hitError = true;
		break;
	      }
	    }

	    XSqlQuery itemsrcq;
	    itemsrcq.prepare( "SELECT itemsrc_id, itemsrc_vend_item_number,"
		       "       itemsrc_vend_item_descrip, itemsrc_vend_uom,"
		       "       itemsrc_minordqty,"
		       "       itemsrc_multordqty,"
		       "       itemsrc_invvendoruomratio,"
		       "       (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.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(), 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 (itemsrcq.lastError().type() != QSqlError::None)
	    {
	      systemError(0, itemsrcq.lastError().databaseText(), __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 (itemq.lastError().type() != QSqlError::None)
	  {
	    systemError(0, itemq.lastError().databaseText(), __FILE__, __LINE__);
	    hitError = true;
	    break;
	  }
	  else
	  {
	    systemError(0, QString("Could not find Item Site for %1 in %2.")
			    .arg(model->index(index.row(), ITEM_NUMBER_COL).data().toString())
			    .arg(whs->currentText()));
	    hitError = true;
	    break;
	  }
	}
      }
      break;
    }

    case POITEM_VEND_ITEM_NUMBER_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text() != oldval.toString())
	model->setData(index, lineedit->text());
      break;
    }
    
    case POITEM_FREIGHT_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text().toDouble() != oldval.toDouble())
	model->setData(index, formatPurchPrice(lineedit->text().toDouble()));
      break;
    }


    case POITEM_QTY_ORDERED_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text().isEmpty())
      {
	model->setData(index, QVariant());
	model->setData(model->index(index.row(), EXTPRICE_COL), QVariant());
	break;
      }
      double qty = lineedit->text().toDouble();
      if (qty != oldval.toDouble())
      {
	model->setData(index, formatQty(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)
	{
	  q.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;" );
	  q.bindValue(":itemsrc_id", model->data(model->index(index.row(), POITEM_ITEMSRC_ID_COL)).toInt());
	  q.bindValue(":qty", model->data(model->index(index.row(), POITEM_QTY_ORDERED_COL)).toDouble());
	  q.bindValue(":curr_id", model->currId());
	  q.bindValue(":effective", model->transDate().toString());
	  q.bindValue(":prec", omfgThis->priceVal()->decimals());
	  q.exec();
	  if (q.first())
	  {
	    model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), q.value("new_itemsrcp_price").toDouble());
	  }
	  else if (q.lastError().type() != QSqlError::None)
	  {
	    systemError(0, q.lastError().databaseText(), __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), formatPurchPrice(qty * prc));
      }
      break;
    }
    
    case POITEM_UNITPRICE_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(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), formatPurchPrice(qty * prc));
      }
      break;
    }

    case POITEM_DUEDATE_COL:
    {
      DLineEdit *duedate = static_cast<DLineEdit*>(editor);
      if (duedate->date() != oldval.toDate())
      {
	model->setData(index, duedate->date());
      }

      break;
    }

#ifdef QE_PROJECT
    case PRJ_NUMBER_COL:
    {
      ProjectLineEdit *prj = static_cast<ProjectLineEdit*>(editor);
      if (prj->id() != oldval.toInt())
      {
	model->setData(model->index(index.row(), POITEM_PRJ_ID_COL), prj->id());
	model->setData(index, prj->text());
      }
      break;
    }
#endif

#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;
}
示例#24
0
void dspQOHByParameterList::sFillList()
{
  int itemsiteid = _qoh->id();

  _qoh->clear();
  
  QString sql( "SELECT itemsite_id, detail,"
               "       warehous_code, classcode_code, item_number, uom_name,"
               "       (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,"
               "       defaultlocation,"
               "       formatQty(reorderlevel) AS f_reorderlevel,"
               "       formatQty(qoh) AS f_qoh,"
               "       formatQty(nnqoh) AS f_nnqoh,"
               "       formatCost(cost) AS f_cost,"
               "       formatMoney(noNeg(cost * qoh)) AS f_value,"
               "       formatMoney(noNeg(cost * nnqoh)) AS f_nnvalue,"
               "       cost, reorderlevel, qoh, nnqoh "
               "FROM ( SELECT itemsite_id,"
               "              ( (itemsite_loccntrl) OR (itemsite_controlmethod IN ('L', 'S')) ) AS detail,"
               "              warehous_code, classcode_code, item_number, uom_name, item_descrip1, item_descrip2,"
               "              CASE WHEN (NOT useDefaultLocation(itemsite_id)) THEN :none"
               "                   ELSE defaultLocationName(itemsite_id)"
               "              END AS defaultlocation,"
               "              CASE WHEN (itemsite_useparams) THEN itemsite_reorderlevel ELSE 0.0 END AS reorderlevel,"
               "              itemsite_qtyonhand AS qoh,"
               "              itemsite_nnqoh AS nnqoh," );

  if (_useStandardCosts->isChecked())
    sql += " stdcost(item_id) AS cost ";
  else if (_useActualCosts->isChecked())
    sql += " actcost(item_id) AS cost ";

  sql += "FROM itemsite, item, classcode, warehous, uom "
         "WHERE ( (itemsite_item_id=item_id)"
         " AND (item_inv_uom_id=uom_id)"
         " AND (item_classcode_id=classcode_id)"
         " AND (itemsite_warehous_id=warehous_id)"
         " AND (itemsite_active)";

  if (_warehouse->isSelected())
    sql += " AND (itemsite_warehous_id=:warehous_id)";

  if (_parameter->isSelected())
  {
    if (_parameter->type() == ClassCode)
      sql += " AND (classcode_id=:classcode_id)";
    else if (_parameter->type() == ItemGroup)
      sql += " AND (item_id IN (SELECT itemgrpitem_item_id FROM itemgrpitem WHERE (itemgrpitem_itemgrp_id=:itemgrp_id)))";
  }
  else if (_parameter->isPattern())
  {
    if (_parameter->type() == ClassCode)
      sql += " AND (classcode_id IN (SELECT classcode_id FROM classcode WHERE classcode_code ~ :classcode_pattern))";
    else if (_parameter->type() == ItemGroup)
      sql += " AND (item_id IN (SELECT itemgrpitem_item_id FROM itemgrpitem, itemgrp WHERE ( (itemgrpitem_itemgrp_id=itemgrp_id) AND (itemgrp_name ~ :itemgrp_pattern) ) ))";
  }
  else if(_parameter->type() == ItemGroup)
    sql += " AND (item_id IN (SELECT DISTINCT itemgrpitem_item_id FROM itemgrpitem))";

  if (_showPositive->isChecked())
    sql += " AND (itemsite_qtyonhand>0)";
  else if (_showNegative->isChecked())
    sql += " AND (itemsite_qtyonhand<0)";

  sql += ") ) AS data "
         "ORDER BY warehous_code";

  if (_byItemNumber->isChecked())
    sql += ", item_number;";
  else
    sql += ", noNeg(cost * qoh) DESC;";

  q.prepare(sql);
  q.bindValue(":none", tr("None"));
  q.bindValue(":na", tr("N/A"));
  _warehouse->bindValue(q);
  _parameter->bindValue(q);
  q.exec();
  if (q.first())
  {
    XTreeWidgetItem *selected     = 0;
    XTreeWidgetItem *last         = 0;
    double        netable         = 0.0;
    double        netableValue    = 0.0;
    double        nonNetable      = 0.0;
    double        nonNetableValue = 0.0;

    do
    {
      last = new XTreeWidgetItem( _qoh, last, q.value("itemsite_id").toInt(), q.value("detail").toInt(),
                                  q.value("warehous_code"), q.value("classcode_code"), q.value("item_number"),
                                  q.value("itemdescrip"), q.value("uom_name"),
                                  q.value("defaultlocation"), q.value("f_reorderlevel"),
                                  q.value("f_qoh"), q.value("f_nnqoh") );

      last->setText(9, q.value("f_cost").toString());
      last->setText(10, q.value("f_value").toString());
      last->setText(11, q.value("f_nnvalue").toString());

      if (q.value("qoh").toDouble() < 0) 
        last->setTextColor(7, "red");
      else if (q.value("reorderlevel").toDouble() > q.value("qoh").toDouble())
        last->setTextColor(7, "orange");

      if (q.value("itemsite_id") == itemsiteid)
        selected = last;

      if (q.value("qoh").toDouble() > 0.0)
      {
        netable += q.value("qoh").toDouble();
        netableValue += (q.value("cost").toDouble() * q.value("qoh").toDouble());
      }

      if (q.value("nnqoh").toDouble() > 0.0)
      {
        nonNetable += q.value("nnqoh").toDouble();
        nonNetableValue += (q.value("cost").toDouble() * q.value("nnqoh").toDouble());
      }
    }
    while (q.next());

    XTreeWidgetItem *totals = new XTreeWidgetItem(_qoh, last, -1, 0, tr("Totals"));
    totals->setText(7, formatQty(netable));
    totals->setText(8, formatQty(nonNetable));

    totals->setText(10, formatMoney(netableValue));
    totals->setText(11, formatMoney(nonNetableValue));

    if (selected != NULL)
    {
      _qoh->setCurrentItem(selected);
      _qoh->scrollTo(_qoh->currentIndex());
    }
  }
}
示例#25
0
void task::sHoursAdjusted()
{
  _balanceHours->setText(formatQty(_budgetHours->text().toDouble() - _actualHours->text().toDouble()));
}
示例#26
0
void dspSalesHistoryByShipTo::sFillList()
{
  if (!checkParameters())
    return;

  _sohist->clear();
  
  MetaSQLQuery mql = mqlLoad(":/so/displays/SalesHistory.mql");
  ParameterList params;
  _dates->appendValue(params);
  _warehouse->appendValue(params);
  _productCategory->appendValue(params);
  params.append("shipto_id", _shipTo->id());
  params.append("orderByInvcdateItem");
  q = mql.toQuery(params);

  if (q.first())
  {
    double totalUnits = 0.0;
    double totalSales = 0.0;
    double totalCosts = 0.0;
    bool exchangeError = false;
    XTreeWidgetItem *last = 0;

    do
    {
      if (q.value("baseunitprice").toDouble() < 0.0)
        exchangeError = true;
      QString invoicedate = tr("Return");
      if (q.value("cohist_invcdate").toString() != "")
        invoicedate = formatDate(q.value("cohist_invcdate").toDate());
        
      last = new XTreeWidgetItem( _sohist, last, q.value("cohist_id").toInt(),
				 q.value("cohist_ordernumber"),
				 q.value("invoicenumber"),
				 formatDate(q.value("cohist_orderdate").toDate()),
				 invoicedate,
				 q.value("item_number"),
				 q.value("itemdescription"),
				 formatQty(q.value("cohist_qtyshipped").toDouble()),
				 formatSalesPrice(q.value("baseunitprice").toDouble()),
				 formatMoney(q.value("baseextprice").toDouble()),
				 formatCost(q.value("cohist_unitcost").toDouble()),
				 formatMoney(q.value("extcost").toDouble()) );
 
      totalUnits += q.value("cohist_qtyshipped").toDouble();
      totalSales += q.value("baseextprice").toDouble();
      totalCosts += q.value("extcost").toDouble();
    }
    while (q.next());

    XTreeWidgetItem *totals = new XTreeWidgetItem(_sohist, last, -1);
    totals->setText(5, tr("Totals"));
    totals->setText(6, formatQty(totalUnits));
    totals->setText(EXTPRICE_COL, formatMoney(totalSales));
    totals->setText(EXTCOST_COL, formatCost(totalCosts));

    if ( (exchangeError) && (_showPrices->isChecked()) )
      QMessageBox::warning( this, tr("Currency Exchange Rate Error"),
                            tr("One or more of the Prices could not be converted to Base Currency.\n"
                               "These Prices have been set to a negative value.") );
  }
}
示例#27
0
enum SetResponse purchaseRequest::set(ParameterList &pParams)
{
  QVariant param;
  bool     valid;
  int      prid = -1;

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

  param = pParams.value("qty", &valid);
  if (valid)
    _qty->setText(formatQty(param.toDouble()));

  param = pParams.value("dueDate", &valid);
  if (valid)
    _dueDate->setDate(param.toDate());

  param = pParams.value("planord_id", &valid);
  if (valid)
    _planordid = param.toInt();

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

      populateNumber();
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _number->setEnabled(FALSE);
      _item->setReadOnly(TRUE);
      _warehouse->setEnabled(FALSE);
      _qty->setEnabled(FALSE);
      _dueDate->setEnabled(FALSE);
      _notes->setEnabled(FALSE);
      _project->setEnabled(FALSE);
      _create->hide();

      q.prepare( "SELECT pr_itemsite_id,"
                 "       pr_number,"
                 "       formatQty(wo_qtyreq) AS ordered,"
                 "       pr_duedate,"
                 "       pr_prj_id "
                 "FROM pr "
                 "WHERE (pr_id=:pr_id);" );
      q.bindValue(":pr_id", prid);
      if (q.first())
      {
        _number->setText(q.value("pr_number").toString());
        _item->setItemsiteid(q.value("pr_itemsite_id").toInt());
        _qty->setText(q.value("ordered").toString());
        _dueDate->setDate(q.value("pr_duedate").toDate());
        _project->setId(q.value("pr_prj_id").toInt());
      }
    }
    else if (param.toString() == "release")
    {
      _mode = cRelease;
      _captive = TRUE;

      _number->setEnabled(FALSE);
      _item->setReadOnly(TRUE);
      _warehouse->setEnabled(FALSE);
      _qty->setEnabled(FALSE);
      _dueDate->setEnabled(FALSE);

      q.prepare( "SELECT planord_itemsite_id, planord_duedate,"
                 "       formatQty(planord_qty) AS qty "
                 "FROM planord "
                 "WHERE (planord_id=:planord_id);" );
      q.bindValue(":planord_id", _planordid);
      q.exec();
      if (q.first())
      {
        _item->setItemsiteid(q.value("planord_itemsite_id").toInt());
        _qty->setText(q.value("qty").toString());
        _dueDate->setDate(q.value("planord_duedate").toDate());

        populateNumber();
      }

      _create->setFocus();
    }
  }

  return NoError;
}
void changeWoQty::sChangeQty()
{
  XSqlQuery changeChangeQty;
  if (_wo->status() == 'R')
  {
    QMessageBox::warning( this, tr("Cannot Reschedule Released W/O"),
                          tr( "<p>The selected Work Order has been Released. "
			  "Rescheduling it." ) );
    return;
  }

  double newQty = 0.0;
  if (_wo->method() == "D")
    newQty = _newQtyOrdered->toDouble() * -1.0;
  else
    newQty = _newQtyOrdered->toDouble();

  if(newQty == 0 && QMessageBox::question(this, tr("Zero Qty. Value"), tr("The current value specified is 0. Are you sure you want to continue?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)
    return;

  if (newQty > 0.0)
  {
    changeChangeQty.prepare( "SELECT validateOrderQty(wo_itemsite_id, :qty, TRUE) AS qty "
               "FROM wo "
               "WHERE (wo_id=:wo_id);" );
    changeChangeQty.bindValue(":wo_id", _wo->id());
    changeChangeQty.bindValue(":qty", _newQtyOrdered->toDouble());
    changeChangeQty.exec();
    if (changeChangeQty.first())
    {
      if (changeChangeQty.value("qty").toDouble() != newQty)
      {
        if ( QMessageBox::warning( this, tr("Invalid Order Qty"),
                                   tr("<p>The new Order Quantity that you have "
                                   "entered does not meet the Order Parameters "
                                   "set for the parent Item Site for this Work "
                                   "Order.  In order to meet the Item Site "
                                   "Order Parameters the new Order Quantity "
                                   "must be increased to %1. Do you want to "
                                   "change the Order Quantity for this Work "
                                   "Order to %2?" )
                                   .arg(formatQty(changeChangeQty.value("qty").toDouble()))
                                   .arg(formatQty(changeChangeQty.value("qty").toDouble())),
                                   tr("&Yes"), tr("&No"), QString::null, 0, 1 ) == 1 )
          return;
        else
          newQty = changeChangeQty.value("qty").toDouble();
      }
    }
    else if (changeChangeQty.lastError().type() != QSqlError::NoError)
    {
      systemError(this, changeChangeQty.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }

  changeChangeQty.prepare("SELECT changeWoQty(:wo_id, :qty, TRUE);");
  changeChangeQty.bindValue(":wo_id", _wo->id());
  changeChangeQty.bindValue(":qty", newQty);
  changeChangeQty.exec();

  if (_postComment->isChecked())
  {
    changeChangeQty.prepare("SELECT postComment(:cmnttype_id, 'W', :wo_id, :comment) AS result");
    changeChangeQty.bindValue(":cmnttype_id", _cmnttype->id());
    changeChangeQty.bindValue(":wo_id", _wo->id());
    changeChangeQty.bindValue(":comment", _comment->toPlainText());
    changeChangeQty.exec();
    if (changeChangeQty.first())
    {
      int result = changeChangeQty.value("result").toInt();
      if (result < 0)
      {
        systemError(this, storedProcErrorLookup("postComment", result),
                    __FILE__, __LINE__);
        return;
      }
    }
    else if (changeChangeQty.lastError().type() != QSqlError::NoError)
    {
      systemError(this, changeChangeQty.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }

  omfgThis->sWorkOrdersUpdated(_wo->id(), TRUE);

  accept();
}
示例#29
0
enum SetResponse itemSite::set(const ParameterList &pParams)
{
  QVariant param;
  bool     valid;
  bool     check;
    
  param = pParams.value("itemsite_id", &valid);
  if (valid)
  {
    _captive = TRUE;
    _itemsiteid = param.toInt();
	
    _item->setReadOnly(TRUE);

    populate();
  }
    
  param = pParams.value("item_id", &valid);
  if (valid)
  {
    check = TRUE;
	
    _item->setId(param.toInt());
    _item->setReadOnly(TRUE);
  }
  else
    check = FALSE;
    
  param = pParams.value("warehous_id", &valid);
  if (valid)
  {
    _captive = TRUE;
    _warehouse->setId(param.toInt());
    _warehouse->setEnabled(FALSE);
  }
  else if (check)
    check = FALSE;
    
  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "new")
    {
      if (check)
      {
        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())
        {
          _mode = cEdit;
          
          _itemsiteid = itemsiteid.value("itemsite_id").toInt();
          populate();
          
          _item->setReadOnly(TRUE);
          _warehouse->setEnabled(FALSE);
        }
        else
        {
          _mode = cNew;
          _reorderLevel->setText(formatQty(0.0));
          _orderUpToQty->setText(formatQty(0.0));
          _minimumOrder->setText(formatQty(0.0));
          _maximumOrder->setText(formatQty(0.0));
          _orderMultiple->setText(formatQty(0.0));
          _safetyStock->setText(formatQty(0.0));
          _cycleCountFreq->setValue(0);
          _leadTime->setValue(0);
          _eventFence->setValue(_metrics->value("DefaultEventFence").toInt());
          _tab->setTabEnabled(_tab->indexOf(_expirationTab),FALSE);
        } 
      }
    }
    else if (param.toString() == "edit")
    {
	_mode = cEdit;
	
	_item->setReadOnly(TRUE);
    }
    else if (param.toString() == "view")
    {
	_mode = cView;

	_item->setReadOnly(TRUE);
	_warehouse->setEnabled(FALSE);
	_useParameters->setEnabled(FALSE);
	_useParametersOnManual->setEnabled(FALSE);
	_reorderLevel->setEnabled(FALSE);
	_orderUpToQty->setEnabled(FALSE);
	_minimumOrder->setEnabled(FALSE);
	_maximumOrder->setEnabled(FALSE);
	_orderMultiple->setEnabled(FALSE);
	_safetyStock->setEnabled(FALSE);
	_abcClass->setEnabled(FALSE);
	_autoUpdateABCClass->setEnabled(FALSE);
	_cycleCountFreq->setEnabled(FALSE);
	_leadTime->setEnabled(FALSE);
	_eventFence->setEnabled(FALSE);
	_active->setEnabled(FALSE);
	_supply->setEnabled(FALSE);
	_createPr->setEnabled(FALSE);
	_createWo->setEnabled(FALSE);
	_sold->setEnabled(FALSE);
	_soldRanking->setEnabled(FALSE);
	_stocked->setEnabled(FALSE);
	_controlMethod->setEnabled(FALSE);
	_perishable->setEnabled(FALSE);
	_locationControl->setEnabled(FALSE);
	_disallowBlankWIP->setEnabled(FALSE);
	_useDefaultLocation->setEnabled(FALSE);
	_location->setEnabled(FALSE);
	_locations->setEnabled(FALSE);
	_miscLocation->setEnabled(FALSE);
	_miscLocationName->setEnabled(FALSE);
	_locationComments->setEnabled(FALSE);
	_plannerCode->setEnabled(FALSE);
	_costcat->setEnabled(FALSE);
	_eventFence->setEnabled(FALSE);
	_notes->setReadOnly(TRUE);
	_orderGroup->setEnabled(FALSE);
	_mpsTimeFence->setEnabled(FALSE);
	_close->setText(tr("&Close"));
	_save->hide();
	_comments->setReadOnly(TRUE);
	
	_close->setFocus();
    }
  }

  return NoError;
}
示例#30
0
void dspTimePhasedSalesByProductCategory::sCalculate()
{
  if (!_periods->isPeriodSelected())
  {
    if (isVisible())
      QMessageBox::warning( this, tr("Select Calendar Periods"),
                            tr("Please select one or more Calendar Periods") );
    return;
  }

  _sohist->clear();
  _sohist->setColumnCount(3);

  _columnDates.clear();

  QString sql("SELECT prodcat_id, warehous_id, prodcat_code, warehous_code");

  if (_salesDollars->isChecked())
    sql += ", TEXT('$') AS uom";
  
  else if (_inventoryUnits->isChecked())
    sql += ", uom_name AS uom";

  else if (_capacityUnits->isChecked())
    sql += ", itemcapuom(item_id) AS uom";

  else if (_altCapacityUnits->isChecked())
    sql += ", itemaltcapuom(item_id) AS uom";

  int columns = 1;
  QList<QTreeWidgetItem*> selected = _periods->selectedItems();
  for (int i = 0; i < selected.size(); i++)
  {
    PeriodListViewItem *cursor = (PeriodListViewItem*)selected[i];
    if (_salesDollars->isChecked())
      sql += QString(", SUM(shipmentsByItemValue(itemsite_id, %2)) AS bucket%1")
	     .arg(columns++)
	     .arg(cursor->id());

    else if (_inventoryUnits->isChecked())
      sql += QString(", SUM(shipmentsByItemQty(itemsite_id, %2)) AS bucket%1")
	     .arg(columns++)
	     .arg(cursor->id());

    else if (_capacityUnits->isChecked())
      sql += QString(", SUM(shipmentsByItemQty(itemsite_id, %2) * itemcapinvrat(item_id)) AS bucket%1")
	     .arg(columns++)
	     .arg(cursor->id());

    else if (_altCapacityUnits->isChecked())
      sql += QString(", SUM(shipmentsByItemQty(itemsite_id, %2) * itemaltcapinvrat(item_id)) AS bucket%1")
	     .arg(columns++)
	     .arg(cursor->id());

    _sohist->addColumn(formatDate(cursor->startDate()), _qtyColumn, Qt::AlignRight);
    _columnDates.append(DatePair(cursor->startDate(), cursor->endDate()));
  }

  sql += " FROM itemsite, item, uom, warehous, prodcat "
         "WHERE ( (itemsite_item_id=item_id)"
         " AND (item_inv_uom_id=uom_id)"
         " AND (itemsite_warehous_id=warehous_id)"
         " AND (item_prodcat_id=prodcat_id)";

  if (_warehouse->isSelected())
    sql += " AND (itemsite_warehous_id=:warehous_id)";
 
  if (_productCategory->isSelected())
    sql += "AND (prodcat_id=:prodcat_id)";
  else if (_productCategory->isPattern())
    sql += "AND (prodcat_code ~ :prodcat_pattern) ";

  sql += ") "
         "GROUP BY prodcat_id, warehous_id, prodcat_code, uom, warehous_code;";

  q.prepare(sql);
  _warehouse->bindValue(q);
  _productCategory->bindValue(q);
  q.exec();
  if (q.first())
  {
    Q3ValueVector<Numeric> totals(columns);;
    XTreeWidgetItem *last = 0;

    do
    {
      last = new XTreeWidgetItem( _sohist, last,
				 q.value("prodcat_id").toInt(),
				 q.value("warehous_id").toInt(),
				 q.value("prodcat_code"),
				 q.value("uom"),
				 q.value("warehous_code") );

      for (int column = 1; column < columns; column++)
      {
        QString bucketName = QString("bucket%1").arg(column);
        totals[column] += q.value(bucketName).toDouble();

        if ( (_inventoryUnits->isChecked()) || (_capacityUnits->isChecked()) || (_altCapacityUnits->isChecked()) )
          last->setText((column + 2), formatQty(q.value(bucketName).toDouble()));
        else if (_salesDollars->isChecked())
          last->setText((column + 2), formatMoney(q.value(bucketName).toDouble()));
      }
    }
    while (q.next());

//  Add the totals row
    XTreeWidgetItem *total = new XTreeWidgetItem(_sohist, last, -1, QVariant(tr("Totals:")));
    for (int column = 1; column < columns; column++)
    {
      if ( (_inventoryUnits->isChecked()) || (_capacityUnits->isChecked()) || (_altCapacityUnits->isChecked()) )
        total->setText((column + 2), formatQty(totals[column].toDouble()));
      else if (_salesDollars->isChecked())
        total->setText((column + 2), formatMoney(totals[column].toDouble()));
    }
  }
}