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

void lemonView::createNewTransaction ( TransactionType  type  )  [private, slot]

Slot used to create a new transaction. It gets last transaction number from database, and creates a new one.

Definition at line 1132 of file lemonview.cpp.

References signalUpdateTransactionInfo().

Referenced by cancelTransaction(), and startOperation().

{
  //If there is an operation started, doit...
  if ( operationStarted ) {
    if (!db.isOpen()) db.open();
    bool ok = db.isOpen();
    if (ok) {
      QDateTime datetime = QDateTime::currentDateTime();
      QString day, month, year, hour, minute;
      day    = datetime.toString("d");
      month  = datetime.toString("M");
      year   = datetime.toString("yyyy");
      hour   = datetime.toString("h");
      minute = datetime.toString("m");
      QSqlQuery query(db);
      //TODO:Add client id to the transaction!
      query.prepare("INSERT INTO transactions (type, amount, day, month, year, hour, minute, paidwith, changegiven, paymethod, state, userid, cardnumber, itemcount, itemslist, cardauthnumber, utility, terminalnum) VALUES (:type, :amount, :day, :month, :year, :hour, :minute, :paidwith, :changegiven, :paymethod, :state, :userid, :cardnumber, :itemcount, :itemslist, :cardauthnumber, :utility, :terminalnum)");
      query.bindValue(":type", type);
      query.bindValue(":amount", 0.0);
      query.bindValue(":day", day);
      query.bindValue(":month", month);
      query.bindValue(":year", year);
      query.bindValue(":hour", hour);
      query.bindValue(":minute", minute);
      query.bindValue(":paidwith",0.0 );
      query.bindValue(":changegiven", 0.0);
      query.bindValue(":paymethod", pCash);
      query.bindValue(":state", tNotCompleted);
      query.bindValue(":userid", loggedUserId);
      query.bindValue(":cardnumber", "---");
      query.bindValue(":itemcount", 0);
      query.bindValue(":itemslist", "");
      query.bindValue(":cardauthnumber","---");
      query.bindValue(":utility", 0);
      query.bindValue(":terminalnum", Settings::editTerminalNumber());
      if (!query.exec() ) {
        int errNum = query.lastError().number();
        QSqlError::ErrorType errType = query.lastError().type();
        QString errStr = query.lastError().text();
        QString details = i18n("Error #%1, Type:%2\n'%3'",QString::number(errNum), QString::number(errType),errStr);
        KMessageBox::detailedError(this, i18n("Lemon has encountered an error when querying the database, click details to see the error details."), details, i18n("Error"));
      }
      //TODO:Could be necesary to move from int to qulonglong the transaction number??
      currentTransaction = query.lastInsertId().toInt();
      transactionInProgress = true;
      emit signalUpdateTransactionInfo();
    }
    else { //error openning database
      int errNum = db.lastError().number();
      QSqlError::ErrorType errType = db.lastError().type();
      QString errStr = db.lastError().text();
      QString details = i18n("Error #%1, Type:%2\n'%3'",QString::number(errNum), QString::number(errType),errStr);
      KMessageBox::detailedError(this, i18n("Lemon has encountered an error when openning database, click details to see the error details."), details, i18n("Create New Transaction: Error"));
    }
  }
  productsHash.clear();
}


Generated by  Doxygen 1.6.0   Back to index