Logo Search packages:      
Sourcecode: lemonpos version File versions  Download package

void lemonView::insertItem ( QString  code  )  [private, slot]

Slot used to get a product info from the database and insert it to the table

FIXME after 0.7 release! : Tell how many items are available at stock.

Definition at line 794 of file lemonview.cpp.

References displayItemInfo(), doInsertItem(), Azahar::getProductInfo(), incrementTableItemQty(), and Azahar::setDatabase().

Referenced by itemSearchDoubleClicked().

{
  double qty  = 1;
  QString codeX = code;
  ProductInfo info;
  info.code = 0;
  info.desc = "[INVALID]";

  //now code could contain number of items to insert,example: 10x12345678990
  QStringList list = code.split(QRegExp("[xX]{1,1}"),QString::SkipEmptyParts);
  if (list.count()==2) {
    qty =   list.takeAt(0).toDouble();
    codeX = list.takeAt(0);
  }

  //verify item units and qty..
  if (productsHash.contains(codeX.toULongLong())) {
    info = productsHash.value(codeX.toULongLong());
  
    if (info.units == uPiece) { 
     unsigned int intqty = qty;
     qty = intqty;
    }
  }

  if (!incrementTableItemQty(codeX, qty) ) {
    //As it was not incremented on tableView, so there is not in the productsHash... so we get it from db.
    Azahar *myDb = new Azahar;
    myDb->setDatabase(db);
    info = myDb->getProductInfo(codeX.toULongLong()); //includes discount and validdiscount

    //verify item units and qty..
    if (info.units == uPiece) { 
      unsigned int intqty = qty;
      qty = intqty;
    }
    
    info.qtyOnList = qty;

    QString msg;
    int insertedAtRow = -1;
    bool productFound = false;
    if (info.code > 0) productFound = true;
    double descuento=0.0;
    if (info.validDiscount) descuento = info.disc;
    if ( !productFound )  msg = i18n("<html><font color=red><b>Product not found in database.</b></font></html>");
    else if ( productFound && info.stockqty >=  qty )
      insertedAtRow = doInsertItem(codeX, info.desc, qty, info.price, descuento, info.unitStr);
    ///FIXME after 0.7 release! : Tell how many items are available at stock.
    else msg = i18n("<html><font color=red><b>Product not available in stock.</b></font></html>");
    
    if (!msg.isEmpty()) {
        if (ui_mainview.mainPanel->currentIndex() == pageMain) {
          ui_mainview.labelInsertCodeMsg->setText(msg);
          ui_mainview.labelInsertCodeMsg->show();
          QTimer::singleShot(3000, this, SLOT(clearLabelInsertCodeMsg()));
        }
        if (ui_mainview.mainPanel->currentIndex() == pageSearch) {
          ui_mainview.labelSearchMsg->setText(msg);
          ui_mainview.labelInsertCodeMsg->show();
          QTimer::singleShot(3000, this, SLOT(clearLabelSearchMsg()) );
        }
    ui_mainview.editItemCode->clear();
    }
    info.row = insertedAtRow;
    if (info.row >-1 && info.desc != "[INVALID]" && info.code>0){
      productsHash.insert(codeX.toULongLong(), info);
//       qDebug()<<"INSERTED AT ROW:"<<insertedAtRow;
      QTableWidgetItem *item = ui_mainview.tableWidget->item(info.row, colCode);
      displayItemInfo(item);
    }
  }//if !increment...
}//insertItem


Generated by  Doxygen 1.6.0   Back to index