示例#1
0
enum SetResponse plannedOrder::set(const ParameterList &pParams)
{
  XSqlQuery plannedet;
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("itemsite_id", &valid);
  if (valid)
  {
    _captive = TRUE;

    _item->setItemsiteid(param.toInt());
    _item->setReadOnly(TRUE);
    _warehouse->setEnabled(FALSE);
  }

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

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

      populateFoNumber();
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;
      populate();
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _number->setEnabled(FALSE);
      _item->setReadOnly(TRUE);
      _warehouse->setEnabled(FALSE);
      _typeGroup->setEnabled(FALSE);
      _qty->setEnabled(FALSE);
      _startDate->setEnabled(FALSE);
      _dueDate->setEnabled(FALSE);
      _leadTimeLit->hide();
      _leadTime->hide();
      _daysLit->hide();

      populate();
    }
  }

  return NoError;
}
示例#2
0
enum SetResponse plannedOrder::set(const ParameterList &pParams)
{
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("itemsite_id", &valid);
  if (valid)
  {
    _captive = TRUE;

    _item->setItemsiteid(param.toInt());
    _item->setReadOnly(TRUE);
    _warehouse->setEnabled(FALSE);

    _qty->setFocus();
  }
  else
  {
    _captive = FALSE;

    _item->setFocus();
  }

  param = pParams.value("planord_id", &valid);
  if (valid)
  {
    _captive = TRUE;

    _planordid = param.toInt();
  }

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

      populateFoNumber();
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;
      populate();
      _close->setFocus();
    }
    else if (param.toString() == "view")
    {
      _mode = cView;

      _number->setEnabled(FALSE);
      _item->setReadOnly(TRUE);
      _warehouse->setEnabled(FALSE);
      _typeGroup->setEnabled(FALSE);
      _qty->setEnabled(FALSE);
      _startDate->setEnabled(FALSE);
      _dueDate->setEnabled(FALSE);
      _leadTimeLit->hide();
      _leadTime->hide();
      _daysLit->hide();

      q.prepare( "SELECT fo_itemsite_id,"
                 "       formatFoNumber(fo_id) AS fonumber,"
                 "       fo_qtyord,"
                 "       fo_startdate, fo_duedate "
                 "FROM fo "
                 "WHERE (fo_id=:fo_id);" );
      q.bindValue(":fo_id", _planordid);
      q.exec();
      if (q.first())
      {
        _number->setText(q.value("fonumber").toString());
        _qty->setDouble(q.value("fo_qtyord").toDouble());
        _startDate->setDate(q.value("fo_startdate").toDate());
        _dueDate->setDate(q.value("fo_duedate").toDate());
        _item->setItemsiteid(q.value("fo_itemsite_id").toInt());
      }
    }
  }

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

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

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

  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::information( this, tr("Invalid Item Site"),
                              tr("The Item and Site entered is and invalid Item Site combination.")  );
    return;
  }

  int itemsiteid = q.value("itemsite_id").toInt();
  int _supplyItemsiteId = -1;
  if (_toButton->isChecked())
  {
    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", _fromWarehouse->id());
    q.exec();
    if (q.first())
    {
      if (q.value("itemsite_id").toInt() == itemsiteid)
      { 
        QMessageBox::warning( this, tr("Cannot Save Planned Order"),
          tr("The Supplied From Site must be different from the Transfer To Site.") );
        return;
      }
      else
        _supplyItemsiteId = q.value("itemsite_id").toInt();
    }
    else
    { 
      QMessageBox::warning( this, tr("Cannot Save Planned"),
        tr("Cannot find Supplied From Item Site.") );
      return;
    }
  }


  if(cEdit == _mode)
  {
    q.prepare( "SELECT deletePlannedOrder(:planord_id, :deleteChildren);" );
    q.bindValue(":planord_id", _planordid);
    q.bindValue(":deleteChildren", TRUE);
    q.exec();
  }
  
  q.prepare( "SELECT createPlannedOrder( :orderNumber, :itemsite_id, :qty, "
             "                           (DATE(:dueDate) - :leadTime), :dueDate, "
             "                           :type, :supply_itemsite_id, :notes) AS result;" );
  q.bindValue(":orderNumber", _number->text().toInt());
  q.bindValue(":itemsite_id", itemsiteid);
  q.bindValue(":qty", _qty->toDouble());
  q.bindValue(":dueDate", _dueDate->date());
  q.bindValue(":leadTime", _leadTime->value());
  q.bindValue(":notes",    _notes->toPlainText());
  if (_poButton->isChecked())
    q.bindValue(":type", "P");
  else if (_woButton->isChecked())
    q.bindValue(":type", "W");
  else if (_toButton->isChecked())
  {
    q.bindValue(":type", "T");
    q.bindValue(":supply_itemsite_id", _supplyItemsiteId);
  }
  
  q.exec();
  if (!q.first())
  {
    systemError( this, tr("A System Error occurred at %1::%2.")
                       .arg(__FILE__)
                       .arg(__LINE__) );
    return;
  }

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

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

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

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

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

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

  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::information( this, tr("Invalid Item Site"),
                              tr("The Item and Site entered is and invalid Item Site combination.")  );
    return;
  }

  int itemsiteid = q.value("itemsite_id").toInt();

  q.prepare( "SELECT createPlannedOrder( :orderNumber, :itemsite_id, :qty, "
             "                           (DATE(:dueDate) - :leadTime), :dueDate) AS result;" );
  q.bindValue(":orderNumber", _number->text().toInt());
  q.bindValue(":itemsite_id", itemsiteid);
  q.bindValue(":qty", _qty->toDouble());
  q.bindValue(":dueDate", _dueDate->date());
  q.bindValue(":leadTime", _leadTime->value());
  q.exec();
  if (!q.first())
  {
    systemError( this, tr("A System Error occurred at %1::%2.")
                       .arg(__FILE__)
                       .arg(__LINE__) );
    return;
  }

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

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

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

    _item->setFocus();
  }
}
示例#5
0
void plannedOrder::sCreate()
{
  XSqlQuery plannedCreate;

  QList<GuiErrorCheck> errors;
  errors << GuiErrorCheck(!_item->isValid(), _item,
                          tr("You must enter or select a valid Item number before creating this Planned Order"))
         << GuiErrorCheck(!_qty->text().length(), _qty,
                          tr("You must enter a valid Qty. Ordered before creating this Planned Order"))
         << GuiErrorCheck(!_dueDate->isValid(), _dueDate,
                          tr("You must enter a valid Due Date before creating this Planned Order"))
     ;

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

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

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

  int foid = 0;

  if(cEdit == _mode)
    plannedCreate.prepare( "UPDATE planord "
               "SET planord_number=:planord_number, "
               "    planord_type=:planord_type, "
               "    planord_itemsite_id=:planord_itemsite_id, "
               "    planord_supply_itemsite_id=:planord_supply_itemsite_id, "
               "    planord_comments=:planord_comments, "
               "    planord_qty=:planord_qty, "
               "    planord_duedate=:planord_duedate, "
               "    planord_startdate=COALESCE(:planord_startdate, date(:planord_duedate) - :planord_leadtime) "
               "WHERE (planord_id=:planord_id);" );
  else
    plannedCreate.prepare( "SELECT createPlannedOrder( :planord_number, :planord_itemsite_id, :planord_qty, "
               "                   COALESCE(:planord_startdate, date(:planord_duedate) - :planord_leadtime), :planord_duedate, "
               "                   :planord_type, :planord_supply_itemsite_id, :planord_comments) AS result;" );

  plannedCreate.bindValue(":planord_number", _number->text().toInt());
  plannedCreate.bindValue(":planord_itemsite_id", itemsiteid);
  if (_poButton->isChecked())
    plannedCreate.bindValue(":planord_type", "P");
  else if (_woButton->isChecked())
    plannedCreate.bindValue(":planord_type", "W");
  else if (_toButton->isChecked())
  {
    plannedCreate.bindValue(":planord_type", "T");
    plannedCreate.bindValue(":planord_supply_itemsite_id", _supplyItemsiteId);
  }
  plannedCreate.bindValue(":planord_qty", _qty->toDouble());
  plannedCreate.bindValue(":planord_duedate", _dueDate->date());
  plannedCreate.bindValue(":planord_startdate", _startDate->date());
  plannedCreate.bindValue(":planord_leadtime", _leadTime->value());
  plannedCreate.bindValue(":planord_comments", _notes->toPlainText());
  plannedCreate.bindValue(":planord_id", _planordid);

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

  if(cEdit == _mode)
  {
    plannedCreate.prepare( "SELECT explodePlannedOrder( :planord_id, true) AS result;" );
    plannedCreate.bindValue(":planord_id", _planordid);
    plannedCreate.exec();
    if (plannedCreate.first())
    {
      double result = plannedCreate.value("result").toDouble();
      if (result < 0.0)
      {
        systemError(this, tr("ExplodePlannedOrder returned %, indicating an "
                             "error occurred.").arg(result),
                    __FILE__, __LINE__);
        return;
      }
    }
    else if (plannedCreate.lastError().type() != QSqlError::NoError)
    {
      systemError(this, plannedCreate.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else
  {
    if (!plannedCreate.first())
    {
      systemError( this, tr("A System Error occurred at %1::%2.")
                         .arg(__FILE__)
                         .arg(__LINE__) );
      return;
    }

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

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

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

    _item->setFocus();
  }
}