Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

labcashbox.ui.h

00001 
00002 static QMap< QString, QString > pgBtns ;
00003 static QMap< QString, int > directActions ;
00004 static QMap< QString, int > payStrategies ;
00005 
00009 void LabCashbox::init()
00010 {
00011         ticketViewTable->setLeftMargin( 0 ) ;
00012         ticketViewTable->setReadOnly( TRUE ) ;
00013         ticketViewTable->setColumnWidth( PRODID, 0 ) ; 
00014         ticketViewTable->setColumnWidth( SERIAL, 0 ) ; 
00015         ticketViewTable->setColumnWidth( PRODNAME, 150 ) ; 
00016         ticketViewTable->setColumnWidth( RETAIL, 50 ) ; 
00017         ticketViewTable->setColumnWidth( QTY, 50 ) ; 
00018         ticketViewTable->setColumnWidth( REBATE, 0 ) ; 
00019         ticketViewTable->setColumnWidth( TOTAL, 50 ) ; 
00020         ticketViewTable->setColumnWidth( VALID, 0 ) ; 
00021         ticketViewTable->setColumnWidth( LINE_TYPE, 0 ) ; 
00022         ticketViewTable->setColumnWidth( TWHEN, 0 ) ; 
00023         ticketViewTable->setColumnStretchable( PRODNAME, TRUE ) ;
00024         totalLCDNumber->display( currency( 0.00 ) ) ;
00025         PriceLCDNumber->display( currency( 0.00 ) ) ;
00026         quantity = 0 ;
00027         QObjectList  * paymodes = programmableGroup->queryList( "QButton", "paymode*" ) ;
00028         QObjectListIterator it( * paymodes ) ;
00029         QObject * obj ;
00030         while ( ( obj = it.current() ) != 0 ) {
00031                 ++it ;
00032                 QString accel = tr( (QString)( ( (QButton * )obj )->accel() ) ) ;
00033                 QString label = tr( ( (QButton *)obj )->text() ) ;
00034                 ( (QButton *)obj )->setText( QString( "%1\n[%2]" )
00035                                                                          .arg( label )
00036                                                                          .arg( accel ) ) ;
00037                 ( (QButton *)obj )->setAccel( QKeySequence( accel ) ) ;
00038         }
00039         delete it ;
00040         QObjectList  * actbtns = stdactionGroup->queryList( "QButton" ) ;
00041         QObjectListIterator it2( * actbtns ) ;
00042         while ( ( obj = it2.current() ) != 0 ) {
00043                 ++it2 ;
00044                 QString accel = tr( (QString)( ( (QButton * )obj )->accel() ) ) ;
00045                 QString label = tr( ( (QButton *)obj )->text() ) ;
00046                 ( (QButton *)obj )->setText( QString( "%1\n[%2]" )
00047                                                                          .arg( label )
00048                                                                          .arg( accel ) ) ;
00049                 ( (QButton *)obj )->setAccel( QKeySequence( accel ) ) ;
00050         }       
00051         parts = new QSqlCursor( "Inv_parts", TRUE ) ;
00052         prods = new QSqlCursor( "Inv_products", TRUE ) ;
00053         
00054         userID = LabUser->value( "recid" ).toInt() ;
00055         cashboxID = GetIniVar( "Cashbox", "ident" ).toInt() ;
00056         
00057         setFreeButtons() ;
00058         inInit = TRUE ;
00059         newTicket() ;
00060         inInit = FALSE ;
00061         resetGetter() ;
00062 }
00063 
00064 void LabCashbox::CloseBox()
00065 {
00066         if ( QMessageBox::question( this, tr( "Cashbox Closing" ),
00067                                                                 tr( "You asked for Closing your cashbox\n"
00068                                                                         "First, you'll have to count the values in box."
00069                                                                         "Are You Sure ?" ),
00070                                                                 tr( "No" ), tr( "Yes" ), 0, 0, -1 ) == 1 ) {
00071                 countBox( "Closing" ) ;
00072                 close() ;
00073         }
00074 }
00075 
00076 
00077 void LabCashbox::PauseBox()
00078 {
00079         if ( ticketViewTable->numRows() == 0 ) {
00080                 activeMode = "Pause" ;
00081                 currLineTextLabel->setText( tr( "Paused Cashbox" ) ) ;
00082                 CurProd1TextLabel->setText( tr( "Password needed to resume" ) ) ;
00083                 stdGetterLineEdit->setEchoMode( QLineEdit::Password ) ;
00084         }       
00085 }
00086 
00087 
00088 void LabCashbox::countBox( const QString & mode)
00089 {
00090         CashboxCount * dialog = new CashboxCount( this, "Count Box", TRUE ) ;    
00091         dialog->setMode( mode ) ;
00092         dialog->exec() ;
00093 }
00094 
00095 
00096 void LabCashbox::withdrawalBox()
00097 {
00098         countBox( "Withdrawal" ) ;
00099 }
00100 
00101 
00102 void LabCashbox::optionsBox()
00103 {
00104         qDebug( "Specific options will be inserted here. Not yet implemented" ) ;
00105 }
00106 
00107 
00108 void LabCashbox::superviseMode()
00109 {
00110         
00111 }
00112 
00113 
00114 void LabCashbox::doAction()
00115 {
00116         QString line = stdGetterLineEdit->text().stripWhiteSpace() ;
00117         if ( line.isEmpty() ) return ;
00118         if ( activeMode == "Line" ) {
00119                 findPart() ;
00120         } else if ( activeMode ==  "Payment" ) {
00121                 if ( paymode == "Cashin" ) {
00122                         addPayLine( line.toDouble(), paymode ) ;
00123                         if ( paidval >= netvalue ) {
00124                                 currLineTextLabel->setText( tr( "Refund" ) ) ;
00125                                 CurProd1TextLabel->setText( tr( "Monney to refund to customer" ) ) ;
00126                                 totalLCDNumber->display( currency( paidval - netvalue ) ) ;
00127                                 addPayLine( paidval - netvalue, "Refund" ) ;
00128                                 ticketEnd() ;
00129                         } else {
00130                                 // We eceived less than wanted. Need another get
00131                                 paymode = "" ;
00132                         }
00133                 } else if ( paymode == "Cheque" || paymode == "CreditCard" || paymode == "Moneo" ) {
00134                         if ( fullPartial == "" ) {
00135                                 if ( line == "1" || line == "2" ) {
00136                                         fullPartial = ( line == "1" ) ? "Full" : "Partial" ;
00137                                         if ( fullPartial == "Full" ) {
00138                                                 addPayLine( netvalue - paidval, paymode ) ;
00139                                                 ticketEnd() ;
00140                                         }
00141                                 } else {
00142                                         CurProd1TextLabel->setText( tr( "Error! Type 1 for Full payment or 2 for Partial" ) ) ;
00143                                 }
00144                         } else {
00145                                 addPayLine( line.toDouble(), paymode ) ;
00146                                 if ( paidval == netvalue ) {
00147                                         ticketEnd() ;
00148                                 } else {
00149                                         paymode = "" ;
00150                                         fullPartial = "" ;
00151                                 }
00152                         }
00153                 } else if ( paymode == "Delayed" ) {
00154                         if ( line == "?" || line.isEmpty() ) {
00155                                 line = "ZZZZZZZZZZZZZZZZ" ;
00156                         }
00157                         int cust = getCustomer( line ) ;
00158                         QString ordernum = "" ;
00159                         QString comment = "" ;
00160                         if ( cust == 0 ) {
00161                                 CustDialog * dialog = new CustDialog( this, "CustomerSearch", TRUE ) ;
00162                                 if ( dialog->exec() == QDialog::Accepted ) {
00163                                         cust = dialog->selected() ;
00164                                         ordernum = dialog->ordernum->text() ;
00165                                         comment = dialog->comment->text() ;
00166                                 }
00167                                 delete dialog ;
00168                         }
00169                         if ( cust > 0 ) {
00170                                 addDelayedPayLine( cust, ordernum, comment ) ;
00171                                 ticketEnd() ;
00172                         } else {
00173                                 paymode = "" ;
00174                                 fullPartial = "" ;
00175                         }
00176                 }
00177         } else if ( activeMode == "Pause" ) {
00178                 checkPass() ;
00179         }
00180         resetGetter() ;
00181 }
00182 
00183 void LabCashbox::doCount()
00184 {
00185         countBox( "Cash Counting" ) ;
00186 }
00187 
00188 
00194 void LabCashbox::evalPayStrategy()
00195 {
00196         QString mode = QObject::sender()->name() ;
00197         mode = mode.replace( "Button", "" ) ;
00198         if ( activeMode != "Payment" ) {
00199                 activeMode = "Payment" ;
00200                 addTotalLine() ;
00201                 currLineTextLabel->setText( tr( "Grand Total" ) ) ;
00202         }
00203         CurProd1TextLabel->setText( "" ) ;
00204         if ( mode == "paymode1" ) {
00205                 // Cash
00206                 paymode = "Cashin" ;
00207                 if ( totalLCDNumber->value() < 0.00 ) {
00208                         // sounds like a lottery refund...
00209                         currLineTextLabel->setText( tr( "Refund" ) ) ;
00210                         CurProd1TextLabel->setText( tr( "Negative total. You MUST refund the customer." ) ) ;
00211                         addPayLine( - totalLCDNumber->value(), "Refund" ) ;
00212                         ticketEnd() ;
00213                 }
00214                 CurProd1TextLabel->setText( tr( "Enter Pay Value" ) ) ;
00215         } else if ( mode == "paymode2" ) {
00216                 // Cheque
00217                 paymode = "Cheque" ;
00218                 CurProd1TextLabel->setText( tr( "1 for Full, 2 for partial" ) ) ;
00219         } else if ( mode == "paymode3" ) {
00220                 // CC
00221                 paymode = "CreditCard" ;
00222                 CurProd1TextLabel->setText( tr( "1 for Full, 2 for partial" ) ) ;
00223         } else if ( mode == "paymode4" ) {
00224                 // Moneo
00225                 paymode = "Moneo" ;
00226                 CurProd1TextLabel->setText( tr( "1 for Full, 2 for partial" ) ) ;
00227         } else if ( mode == "paymode5" ) {
00228                 // Deffered
00229                 paymode = "Delayed" ;
00230                 CurProd1TextLabel->setText( tr( "Customer Code, ? for search" ) ) ;
00231         }
00232 }
00233 
00234 
00241 void LabCashbox::evalFreeBtns()
00242 {
00243         QString btn = QObject::sender()->name() ;
00244         stdGetterLineEdit->setText( pgBtns[btn] ) ;
00245         findPart() ;
00246 }
00247 
00251 void LabCashbox::newTicket()
00252 {
00253         ticketViewTable->setNumRows( 0 ) ;
00254         currLineTextLabel->setText( tr( "Next Customer" ) ) ;
00255         CurProd1TextLabel->setText( "" ) ;
00256         qtyLabel->setText( "0" ) ;
00257         quantity = 1 ;
00258         QSqlCursor * tinfo = new QSqlCursor( "Cashbox_sequence", TRUE ) ;
00259         tinfo->select() ;
00260         tinfo->next() ;
00261         ticketID = tinfo->value( "seq_no" ).toInt() + 1 ;
00262         QSqlQuery q( QString( "UPDATE Cashbox_sequence SET seq_no='%1' ;" ).arg( ticketID ) ) ;
00263         ticketInfoLabel->setText( QString( "%1-%2-%3-%4" )
00264                                                           .arg( cashboxID ).arg( userID )
00265                                                           .arg( ( QString( "%1" ).arg( ticketID ) ).rightJustify( 7, '0' ) )
00266                                                           .arg( QDateTime::currentDateTime().toString( "yyyy.MM.dd hh:mm:ss" ) ) ) ;
00267         if ( !inInit ) {
00268                 PriceLCDNumber->display( currency( 0.00 ) ) ;
00269                 objectsLCDNumber->display( 0 ) ;
00270                 totalLCDNumber->display( currency( 0.00 ) ) ;
00271         }
00272         stdGetterLineEdit->setText( "" ) ;
00273         netvalue = 0.0 ;
00274         paidval = 0.0 ;
00275         paymode = "" ;
00276         activeMode = "Line" ;
00277         fullPartial = "" ;
00278         showTotal() ;
00279 }
00280 
00281 
00296 void LabCashbox::setFreeButtons()
00297 {
00298         QSqlCursor * opts = new QSqlCursor( "Cashbox_options", TRUE ) ;
00299         opts->setFilter( QString( "cashboxgroup='%1'" ).arg( GetIniVar( "Cashbox", "PrinterGroup" ) ) ) ;
00300         opts->select() ;
00301         opts->next() ;
00302         QStringList btns = QStringList::split( '|', opts->value( "bprogs" ).toString() ) ;
00303         // Initialize Free Buttons to some known state
00304         for ( int i = 0; i < 24; i++ ) {
00305                 QPushButton * btn = (QPushButton *)this->child( QString( "free%1" ).arg( i + 1 ) );
00306                 QFont free_font(  btn->font() );
00307                 free_font.setBold( TRUE ) ;
00308                 btn->setFont( free_font ) ; 
00309                 btn->setEnabled( FALSE ) ;
00310                 btn->setText( "" ) ;
00311         }
00312         for ( QStringList::Iterator it = btns.begin(); it != btns.end(); ++it ) {
00313                 QString entry = *it ;
00314                 // Set Button Name and grab widget
00315                 QString btnname = entry.section( "=", 0, 0 ) ;
00316                 // Grab button data
00317                 QPushButton * btn = (QPushButton * )this->child( btnname ) ;
00318                 QStringList btndata = QStringList::split( ';', entry.section( "{", 1, 1 ).replace( "}", "" ) ) ;
00319                 for ( QStringList::Iterator it = btndata.begin(); it != btndata.end(); ++it ) {
00320                         QString item = *it ;
00321                         if ( item.left( 5 ) == "label" ) {
00322                                 btn->setText( item.mid( 6 ) ) ;
00323                         } else if ( item.left( 5 ) == "value" ) {
00324                                 connect( btn, SIGNAL( clicked() ), this, SLOT( evalFreeBtns() ) );
00325                                 pgBtns.replace( btnname, item.mid( 6 ) ) ;                              
00326                         } else if ( item.left( 6 ) == "prefix" ) {
00327                                 connect( btn, SIGNAL( clicked() ), this, SLOT( evalPrefixBtns() ) );
00328                                 pgBtns.replace( btnname, item.mid( 7 ) ) ;                                                      
00329                         } else if ( item.left( 3 ) == "day" ) {
00330                                 int today = QDate::currentDate().dayOfWeek() ;
00331                                 int dd = item.mid( 4, 1 ).toInt() ;
00332                                 if ( dd == today ) {
00333                                         connect( btn, SIGNAL( clicked() ), this, SLOT( evalFreeBtns() ) );
00334                                         pgBtns.replace( btnname, item.mid( 6, 255 ) ) ;
00335                                         break ; ;
00336                                 }                               
00337                         } else if ( item.left( 3 ) == "def" ) {
00338                                 connect( btn, SIGNAL( clicked() ), this, SLOT( evalFreeBtns() ) );
00339                                 pgBtns.replace( btnname, item.mid( 4, 255 ) ) ;                         
00340                         } else if ( item.left( 6 ) == "action" ) {
00341                                 pgBtns.replace( btnname, item.mid( 7, 255 ) ) ;                                                 
00342                                 connect( btn, SIGNAL( clicked() ), this, SLOT( evalActionBtns() ) );
00343                         }
00344                 }
00345                 btn->setEnabled( TRUE ) ;
00346         }       
00347 }
00348 
00349 
00353 bool LabCashbox::findPart()
00354 {
00355         bool unknownPress = FALSE ;
00356         QString want = stdGetterLineEdit->text().stripWhiteSpace().lower() ;
00357         parts->setFilter( QString( "serial='%1'" ).arg( want ) );
00358         parts->select() ;
00359         if ( parts->size() != 1 ) {
00360                 // This is a problem... Let's tweak the fuckin' thing
00361                 if ( want.left( 3 ) == "378" || want.left( 3 ) == "379" ) {
00362                         // Is this some press item ?
00363                         parts->setFilter( QString( "left( serial, 13 )='%1'" ).arg( want.left( 13 ) ) ) ;
00364                         parts->select() ;
00365                         if ( parts->size() != 1 ) {
00366                                 // Sounds like this press item has not yet been created.
00367                                 CurProd1TextLabel->setText( tr( "Unknow press Title... Doing my best." ) ) ;
00368                                 unknownPress = TRUE ;
00369                                 resetGetter() ;
00370                         }
00371                 } else {
00372                         // Standard product. Must know why not here...
00373                         CurProd1TextLabel->setText( tr( "Unknow Product Code. Going to manual search." ) ) ;
00374                         resetGetter() ;
00375                         activateSearch() ;
00376                         return TRUE ;
00377                 }
00378         }
00379         // Populate the Table.
00380         int row = numRows() ;
00381         if ( quantity == 0 ) quantity = 1 ;
00382         ticketViewTable->insertRows( row, 1 ) ;
00383         if ( unknownPress ) {
00384                 ticketViewTable->setText( row, PRODID, "0" ) ;
00385                 ticketViewTable->setText( row, SERIAL, want ) ;
00386                 ticketViewTable->setText( row, PRODNAME, QString( "%1 - %2" ).arg( tr( "Press" ) ).arg( want ) ) ;
00387                 ticketViewTable->setText( row, QTY, QString( "%1").arg( quantity ) ) ;
00388                 double rprice = want.mid( 8, 4 ).insert( 2, "." ).toDouble()  ;
00389                 ticketViewTable->setText( row, RETAIL, currency( rprice ) ) ;
00390                 ticketViewTable->setText( row, TOTAL, currency( rprice * (double)quantity ) ) ;
00391                 ticketViewTable->setText( row, REBATE, "0" ) ;
00392                 ticketViewTable->setText( row, VALID, "1" ) ;
00393                 ticketViewTable->setText( row, LINE_TYPE, "Line" ) ;
00394                 ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ;                
00395         } else {
00396                 parts->next() ;
00397                 // Get assoc product
00398                 prods->setFilter( QString( "recid='%1'" ).arg( parts->value( "prodid" ).toInt() ) ) ;
00399                 prods->select() ;
00400                 if ( !prods->next() ) {
00401                         // bug ! Should not occur...
00402                         resetGetter() ;
00403                 }
00404                 ticketViewTable->setText( row, PRODID, parts->value( "prodid" ).toString() ) ;
00405                 ticketViewTable->setText( row, SERIAL, parts->value( "serial" ).toString() ) ;
00406                 ticketViewTable->setText( row, PRODNAME, prods->value( "prod_name" ).toString() ) ;
00407                 ticketViewTable->setText( row, QTY, QString( "%1").arg( quantity ) ) ;
00408                 if ( want.left( 3 ) == "378" || want.left( 3 ) == "379" ) {
00409                         double rprice = want.mid( 8, 4 ).insert( 2, "." ).toDouble()  ;
00410                         ticketViewTable->setText( row, RETAIL, currency( rprice ) ) ;
00411                         ticketViewTable->setText( row, TOTAL, currency( rprice * (double)quantity ) ) ;
00412                         if ( want.length() == 18 ) {
00413                                 int release = want.mid( 14, 3 ).toInt() ;
00414                                 ticketViewTable->setText( row, PRODNAME, QString( "%1 - %2 %3" )
00415                                                                           .arg( prods->value( "prod_name" ).toString().left( 20 ) )
00416                                                                           .arg( tr( "Num." ) )
00417                                                                           .arg( release ) );
00418                         }
00419                 } else {
00420                         ticketViewTable->setText( row, RETAIL, currency( parts->value( "retail" ).toDouble() ) ) ;
00421                         ticketViewTable->setText( row, TOTAL, currency( parts->value( "retail" ).toDouble() * (double)quantity ) ) ;
00422                 }
00423                 ticketViewTable->setText( row, REBATE, parts->value( "savings" ).toString() ) ;
00424                 ticketViewTable->setText( row, VALID, "1" ) ;
00425                 ticketViewTable->setText( row, LINE_TYPE, "Line" ) ;
00426                 ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ;
00427         }
00428         ticketViewTable->ensureVisible( row, 0 ) ;
00429         ticketViewTable->selectRow( row ) ;
00430         currLineTextLabel->setText( ticketViewTable->text( row, PRODNAME ) ) ;
00431         PriceLCDNumber->display( currency( ticketViewTable->text( row, TOTAL ).toDouble() ) ) ;
00432         qtyLabel->setText( ticketViewTable->text( row, QTY ) ) ;
00433         showTotal() ;
00434         showItems() ;
00435         quantity = 1 ;
00436         resetGetter() ;
00437         return TRUE ;
00438 }
00439 
00440 
00441 
00445 void LabCashbox::showTotal()
00446 {
00447         double ntot = calcTotal( "Line" ) ;
00448         totalLCDNumber->display( currency( ntot ) ) ;
00449         bool enable = ntot > 0 ;
00450         subTotalButton->setEnabled( enable ) ;
00451         totalButton->setEnabled( enable ) ;
00452         ticketCancelButton->setEnabled( numRows() > 0 ) ;
00453         immCancelButton->setEnabled( numRows() > 0 ) ;
00454         QObjectList  * paymodes = programmableGroup->queryList( "QButton", "paymode*" ) ;
00455         QObjectListIterator it( * paymodes ) ;
00456         QObject * obj ;
00457         while ( ( obj = it.current() ) != 0 ) {
00458                 ++it ;
00459                 ( (QButton *)obj )->setEnabled( numRows() > 0 ) ;
00460         }       
00461 }
00462 
00466 void LabCashbox::showItems()
00467 {
00468         int items = 0 ;
00469         for ( int i = 0; i < numRows(); i++ ) {
00470                 items += ticketViewTable->text( i, QTY ).toInt() ;
00471         }
00472         objectsLCDNumber->display( items ) ;
00473 }
00474 
00478 void LabCashbox::resetGetter()
00479 {
00480         stdGetterLineEdit->setText( "" ) ;
00481         stdGetterLineEdit->setFocus() ;
00482 }
00483 
00487 void LabCashbox::setQuantity()
00488 {
00489         QString qs = stdGetterLineEdit->text().stripWhiteSpace() ;
00490         if ( qs.right( 1 ) == "*" ) {
00491                 qs = qs.left( qs.length() -1 ) ;
00492         }
00493         if ( qs.isEmpty() ) {
00494                 quantity = 1 ;
00495         } else {
00496                 quantity = qs.toInt() ;
00497                 if ( QString( "%1" ).arg( quantity ) != qs ) {
00498                         quantity = 1 ;
00499                 }
00500         }
00501         qtyLabel->setText( QString( "%1" ).arg( quantity ) ) ;
00502         CurProd1TextLabel->setText( "" ) ;
00503         resetGetter() ;
00504 }
00505 
00509 void LabCashbox::captureEvents( const QString & evt )
00510 {
00511         if ( evt.isEmpty() ) return ;
00512         QString want = evt.right( 1 ) ;
00513         if ( want == "*" ) {
00514                 setQuantity() ;
00515         } else if ( evt == "+" ) {
00516                 duplicateLine( numRows() -1 ) ;
00517         }
00518 }
00519 
00520 // Specific Event Manager
00521 
00522 
00523 void LabCashbox::addStaticLine()
00524 {
00525         QString want = QObject::sender()->name() ;
00526         want = want.replace( "Button", "" ) ;
00527         double subt = 0.0 ;
00528         int nbsubs = 0 ;
00529         double tticket = 0.0 ;
00530         double res = 0.0 ;
00531         if ( want == "subTotal" ) {
00532                 want = "Subtotal" ;
00533                 // Calculate real subtotal
00534                 subt = calcTotal( "Subtotal" ) ;
00535                 nbsubs = countLines( "Subtotal" ) ;
00536                 tticket = calcTotal( "Line" ) ;
00537                 res = tticket - subt ;
00538         } else if ( want == "total" ) {
00539                 want = "Total" ;
00540                 subt = calcTotal( "Total" ) ;
00541                 nbsubs = countLines( "Total" ) ;
00542                 tticket = calcTotal( "Line" ) ;
00543                 res = tticket ;
00544         } else {
00545                 return ;
00546         }
00547         int row = numRows() ;
00548         ticketViewTable->insertRows( row, 1 ) ;
00549         ticketViewTable->setText( row, PRODID, "0" ) ;
00550         ticketViewTable->setText( row, SERIAL, "" ) ;
00551         ticketViewTable->setText( row, PRODNAME, QString( tr( "%1 %2" ) ).arg( want ).arg( nbsubs + 1 ) ) ;
00552         ticketViewTable->setText( row, RETAIL, "" ) ;
00553         ticketViewTable->setText( row, QTY, "" ) ;
00554         ticketViewTable->setText( row, REBATE, "0" ) ;
00555         ticketViewTable->setText( row, TOTAL, currency( res ) ) ;
00556         ticketViewTable->setText( row, VALID, "1" ) ;
00557         ticketViewTable->setText( row, LINE_TYPE, want ) ;
00558         ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ;   
00559 }
00560 
00561 
00562 void LabCashbox::cancelTicket()
00563 {
00564         if ( QMessageBox::question( this, tr( "Cancel Ticket" ),
00565                                                                 tr( "You called me for cancelling all information\n"
00566                                                                         "from current ticket.\n\n"
00567                                                                         "Are you really sure you want to cancel this ticket" ),
00568                                                                 tr( "No" ), tr( "Yes" ), 0, 0, 0 ) == 1 ) {
00569                 int numlines = numRows() ;
00570                 for ( int i = 0; i < numlines; i++ ) {
00571                         ticketViewTable->selectRow( i ) ;
00572                         cancelLine() ;
00573                 }       
00574                 int row = numRows() ;
00575                 ticketViewTable->insertRows( row, 1 ) ;
00576                 ticketViewTable->setText( row, PRODID, "0" ) ;
00577                 ticketViewTable->setText( row, SERIAL, "" ) ;
00578                 ticketViewTable->setText( row, PRODNAME, tr( "Cancelled Ticket" ) ) ;
00579                 ticketViewTable->setText( row, RETAIL, "" ) ;
00580                 ticketViewTable->setText( row, QTY, "" ) ;
00581                 ticketViewTable->setText( row, REBATE, "0" ) ;
00582                 ticketViewTable->setText( row, TOTAL, "0" ) ;
00583                 ticketViewTable->setText( row, VALID, "1" ) ;
00584                 ticketViewTable->setText( row, LINE_TYPE, "TicketCancel" ) ;
00585                 ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ;   
00586                 
00587                 CurProd1TextLabel->setText( tr( "<b>Ticket Cancel<b>: Informing Master Server" ) ) ;
00588                 informMaster() ;
00589                 CurProd1TextLabel->setText( "" ) ;
00590         }
00591 }
00592 
00593 
00594 void LabCashbox::cancelTransaction()
00595 {
00596         TicketHistory * dialog = new TicketHistory( this, "TicketHistory", TRUE ) ;
00597         dialog->setDateValues( QDate::currentDate() ) ;
00598         dialog->setMessage( tr( "Select the transaction you want to cancel" ) ) ;
00599         if ( dialog->exec() == QDialog::Accepted ) {
00600         
00601         }
00602         delete dialog ;
00603 }
00604 
00605 
00606 void LabCashbox::addDirectEntry()
00607 {
00608         DirectEntry * dialog = new DirectEntry( this, "DirectEntry", TRUE ) ;
00609         if ( dialog->exec() == QDialog::Accepted ) {
00610                 int row = numRows() ;
00611                 ticketViewTable->insertRows( row, 1 ) ;
00612                 
00613                 ticketViewTable->setText( row, PRODID, "0" ) ;
00614                 ticketViewTable->setText( row, SERIAL, "manual_entry" ) ;
00615                 ticketViewTable->setText( row, PRODNAME, dialog->designation->text() ) ;
00616                 ticketViewTable->setText( row, RETAIL, dialog->retail->text() ) ;
00617                 ticketViewTable->setText( row, QTY, dialog->qty->text() ) ;
00618                 ticketViewTable->setText( row, REBATE, "0" ) ;
00619                 ticketViewTable->setText( row, TOTAL, dialog->total->text() ) ;
00620                 ticketViewTable->setText( row, VALID, "1" ) ;
00621                 ticketViewTable->setText( row, LINE_TYPE, "Line" ) ;
00622                 ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ;
00623                 if ( dialog->rebateSet() ) {
00624                         negateRow( row ) ;
00625                         ticketViewTable->setText( row, REBATE, "Rebate" ) ;
00626                 }
00627                 ticketViewTable->ensureVisible( row, 0 ) ;
00628                 ticketViewTable->selectRow( row ) ;
00629                 currLineTextLabel->setText( ticketViewTable->text( row, PRODNAME ) ) ;
00630                 PriceLCDNumber->display( ticketViewTable->text( row, TOTAL ).toDouble() ) ;
00631                 showTotal() ;
00632                 showItems() ;
00633         }
00634         delete dialog ;
00635         resetGetter() ;
00636 }
00637 
00638 
00639 void LabCashbox::activateSearch()
00640 {
00641         QuickSearcher * dialog = new QuickSearcher( this, "ProductSearch", TRUE ) ;
00642         if ( dialog->exec() == QDialog::Accepted ) {
00643                 stdGetterLineEdit->setText( dialog->currBarcode->text() ) ;
00644                 delete dialog ;
00645                 findPart() ;
00646         } else {
00647                 delete dialog ;
00648                 
00649         }
00650 }
00651 
00652 void LabCashbox::cancelLine()
00653 {
00654         int row = numRows() ;
00655         int todel = ticketViewTable->currentRow() ;
00656         if ( row > 0 ) {
00657                 ticketViewTable->insertRows( row, 1 ) ;
00658                 for ( int i = 0; i < ticketViewTable->numCols(); i++ ) {
00659                         ticketViewTable->setText( row, i, ticketViewTable->text( todel, i ) ) ;
00660                 }
00661                 ticketViewTable->setText( row, VALID, "0" ) ;
00662                 ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ;
00663                 negateRow( row ) ;
00664                 if ( activeMode == "Payment" ) {
00665                         QString lt = ticketViewTable->text( row, LINE_TYPE ) ;
00666                         if ( lt == "Refund" ) {
00667                                 ticketViewTable->setText( row, PRODNAME, tr( "Refund Cancel" ) ) ;
00668                         } else if ( lt == "PayCancel" ) {
00669                                 ticketViewTable->setText( row, LINE_TYPE, ticketViewTable->text( row, SERIAL ) ) ;
00670                                 ticketViewTable->setText( row, PRODNAME, tr( ticketViewTable->text( row, SERIAL ) ) ) ;
00671                                 paidval += ticketViewTable->text( row, TOTAL ).toDouble() ;
00672                         } else if ( lt == "LineCancel" ) {
00673                                 showTotal() ;
00674                                 showItems() ;
00675                         } else {
00676                                 ticketViewTable->setText( row, SERIAL, ticketViewTable->text( row, LINE_TYPE ) ) ;
00677                                 ticketViewTable->setText( row, LINE_TYPE, "PayCancel" ) ;
00678                                 paidval += ticketViewTable->text( row, TOTAL ).toDouble() ;
00679                         }
00680                 }
00681                 resetGetter() ;
00682         }
00683 }
00684 
00690 void LabCashbox::negateRow( int row )
00691 {
00692         if ( ticketViewTable->text( row, QTY ).left( 1 ) == "-" ) {
00693                 ticketViewTable->setText( row, QTY, ticketViewTable->text( row, 4 ).remove( 0, 1 ) ) ;
00694                 ticketViewTable->setText( row, TOTAL, ticketViewTable->text( row, 6 ).remove( 0, 1 ) ) ;
00695         } else {
00696                 if ( ticketViewTable->text( row, QTY ) != "-" ) {
00697                         ticketViewTable->setText( row, QTY, ticketViewTable->text( row, 4 ).prepend( "-" ) ) ;
00698                 }
00699                 ticketViewTable->setText( row, TOTAL, ticketViewTable->text( row, 6 ).prepend( "-" ) ) ;
00700         }
00701         ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh mm ss" ) ) ;
00702         ticketViewTable->ensureVisible( row, 0 ) ;
00703         ticketViewTable->selectRow( row ) ;
00704         currLineTextLabel->setText( ticketViewTable->text( row, PRODNAME ) ) ;
00705         PriceLCDNumber->display( ticketViewTable->text( row, TOTAL ).toDouble() ) ;
00706         qtyLabel->setText( ticketViewTable->text( row, QTY ) ) ;
00707         showTotal() ;
00708         showItems() ;
00709         resetGetter() ;
00710 }
00711 
00717 void LabCashbox::duplicateLine( int dup )
00718 {
00719         int row = numRows() ;
00720         ticketViewTable->insertRows( row, 1 ) ;
00721         for ( int i = 0; i < ticketViewTable->numCols(); i++ ) {
00722                 ticketViewTable->setText( row, i, ticketViewTable->text( dup, i ) ) ;
00723         }
00724         ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ;
00725         currLineTextLabel->setText( ticketViewTable->text( row, PRODNAME ) ) ;
00726         PriceLCDNumber->display( ticketViewTable->text( row, TOTAL ).toDouble() ) ;
00727         qtyLabel->setText( ticketViewTable->text( row, QTY ) ) ;
00728         showTotal() ;
00729         showItems() ;
00730         resetGetter() ;
00731 }
00732 
00738 QString LabCashbox::currency( double val )
00739 {
00740         return QString( "%1" ).arg( val, 0, 'f', 2 ) ;
00741 }
00742 
00743 
00744 double LabCashbox::calcTotal( const QString & md )
00745 {
00746         double tx = 0.00 ;
00747         int rows = numRows() ;
00748         for ( int i = 0; i < rows; i++ ) {
00749                 if ( ticketViewTable->text( i, LINE_TYPE ) == md ) {
00750                         tx += ticketViewTable->text( i, TOTAL ).toDouble() ;
00751                 }
00752         }
00753         return tx ;
00754 }
00755 
00756 
00757 int LabCashbox::countItems( const QString & md )
00758 {
00759         int ret = 0 ;
00760         int rows = numRows() ;
00761         for ( int i = 0; i < rows; i++ ) {
00762                 if ( ticketViewTable->text( i, LINE_TYPE ) == md ) {
00763                         ret += ticketViewTable->text( i, QTY ).toInt() ;
00764                 }
00765         }
00766         return ret ;    
00767 }
00768 
00769 
00770 int LabCashbox::countLines( const QString & md )
00771 {
00772         int ret = 0 ;
00773         int rows = numRows() ;
00774         for ( int i = 0; i < rows; i++ ) {
00775                 if ( ticketViewTable->text( i, LINE_TYPE ) == md ) {
00776                         ret++ ;
00777                 }
00778         }
00779         return ret ;
00780 }
00781 
00782 
00783 int LabCashbox::numRows()
00784 {
00785         return ticketViewTable->numRows() ;
00786 }
00787 
00788 
00789 void LabCashbox::informMaster()
00790 {
00791         QSqlCursor * master = new QSqlCursor( "Ticket_receipts", TRUE ) ;
00792         int rows = numRows() ;
00793         for ( int i = 0; i < rows; i++ ) {
00794                 QSqlRecord * buffer = master->primeInsert() ;
00795                 buffer->setValue( "recid", SequenceGetNextValue( "Ticket_receipts" ) ) ;
00796                 buffer->setValue( "cashbox", cashboxID ) ;
00797                 buffer->setValue( "cashier", userID ) ;
00798                 buffer->setValue( "ticket_num", ticketInfoLabel->text() ) ;
00799                 buffer->setValue( "line_num", i + 1 ) ;
00800                 buffer->setValue( "prodid", ticketViewTable->text( i, PRODID ).toInt() ) ;
00801                 buffer->setValue( "serial", ticketViewTable->text( i, SERIAL ) ) ;
00802                 buffer->setValue( "prodname", ticketViewTable->text( i, PRODNAME ) ) ;
00803                 QString retail = ticketViewTable->text( i, RETAIL ) ;
00804                 if ( retail.isEmpty() || retail == "-" ) {
00805                         retail = "0" ;
00806                 }
00807                 buffer->setValue( "retail", retail ) ;
00808                 QString qty = ticketViewTable->text( i, QTY ) ;
00809                 if ( qty.isEmpty() || qty == "-" ) {
00810                         qty = "0" ;
00811                 }
00812                 buffer->setValue( "qty", qty ) ;
00813                 buffer->setValue( "rebate", ticketViewTable->text( i, REBATE ) ) ;
00814                 buffer->setValue( "total", ticketViewTable->text( i, TOTAL ) ) ;
00815                 buffer->setValue( "valid", ticketViewTable->text( i, VALID ) )  ;
00816                 buffer->setValue( "line_type", ticketViewTable->text( i, LINE_TYPE ) ) ;
00817                 buffer->setValue( "twhen", ticketViewTable->text( i, TWHEN ) ) ;
00818                 buffer->setValue( "received", QDateTime::currentDateTime() ) ;
00819                 master->insert() ;
00820         }
00821         newTicket() ;
00822 }
00823 
00824 
00825 
00826 void LabCashbox::addTotalLine()
00827 {
00828         double res = calcTotal( "Line" ) ;
00829         
00830         int row = numRows() ;
00831         ticketViewTable->insertRows( row, 1 ) ;
00832         ticketViewTable->setText( row, PRODID, "0" ) ;
00833         ticketViewTable->setText( row, SERIAL, "" ) ;
00834         ticketViewTable->setText( row, PRODNAME, tr( "Grand Total" ) ) ;
00835         ticketViewTable->setText( row, RETAIL, "" ) ;
00836         ticketViewTable->setText( row, QTY, "" ) ;
00837         ticketViewTable->setText( row, REBATE, "0" ) ;
00838         ticketViewTable->setText( row, TOTAL, currency( res ) ) ;
00839         ticketViewTable->setText( row, VALID, "1" ) ;
00840         ticketViewTable->setText( row, LINE_TYPE, "Total" ) ;
00841         ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ; 
00842         netvalue = res ;
00843 }
00844 
00845 
00846 void LabCashbox::addPayLine( double val, const QString & md )
00847 {
00848         paidval += val ;
00849         int row = ticketViewTable->numRows() ;
00850         ticketViewTable->insertRows( row, 1 ) ;
00851         ticketViewTable->setText( row, PRODID, "0" ) ;
00852         ticketViewTable->setText( row, SERIAL, md ) ;
00853         ticketViewTable->setText( row, PRODNAME, tr( md ) ) ;
00854         ticketViewTable->setText( row, RETAIL, "" ) ;
00855         ticketViewTable->setText( row, QTY, "" ) ;
00856         ticketViewTable->setText( row, REBATE, "0" ) ;
00857         ticketViewTable->setText( row, TOTAL, currency( val ) ) ;
00858         ticketViewTable->setText( row, VALID, "1" ) ;
00859         ticketViewTable->setText( row, LINE_TYPE, md ) ;
00860         ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ; 
00861 
00862 }
00863 
00864                 
00865 void LabCashbox::ticketEnd()
00866 {
00867         if ( QMessageBox::question( this, tr( "Ticket Validation" ),
00868                                                                 tr( "Ticket Ready for Validation\n"
00869                                                                         "No will allow you to change paymode."
00870                                                                         "Validate ticket ?" ),
00871                                                                 tr( "Yes" ), tr( "No" ), 0, 0, -1 ) == 0 ) {
00872                 informMaster() ;
00873         } else {
00874                 paymode = "" ;
00875                 fullPartial = "" ;
00876         }
00877 }
00878 
00879 
00880 void LabCashbox::addDelayedPayLine( int cust, const QString ordernum, const QString comment )
00881 {
00882         int row = ticketViewTable->numRows() ;
00883         ticketViewTable->insertRows( row, 1 ) ;
00884         ticketViewTable->setText( row, PRODID, QString( "%1" ).arg( cust ) ) ;
00885         ticketViewTable->setText( row, SERIAL,  QString( "%1 - %2" ).arg( ordernum ).arg( comment ) ) ;
00886         ticketViewTable->setText( row, PRODNAME, tr( "Delayed" ) ) ;
00887         ticketViewTable->setText( row, RETAIL, "" ) ;
00888         ticketViewTable->setText( row, QTY, "" ) ;
00889         ticketViewTable->setText( row, REBATE, "0" ) ;
00890         ticketViewTable->setText( row, TOTAL, currency( netvalue - paidval ) ) ;
00891         ticketViewTable->setText( row, VALID, "1" ) ;
00892         ticketViewTable->setText( row, LINE_TYPE, "Delayed" ) ;
00893         ticketViewTable->setText( row, TWHEN, QDateTime::currentDateTime().toString( "yyyy-MM-dd hh:mm:ss" ) ) ; 
00894 }
00895 
00896 
00897 
00898 
00899 int LabCashbox::getCustomer( const QString & want )
00900 {
00901         QSqlCursor * cust = new QSqlCursor( "Contacts", TRUE ) ;
00902         cust->setFilter( QString( "contact_qa='%1' AND contact_xtype='Customer'" ).arg( want.upper() ) ) ;
00903         cust->select() ;
00904         if ( cust->next() ) {
00905                 return cust->value( "recid" ).toInt() ;
00906         }
00907         return 0 ;
00908 }
00909 
00910 
00911 void LabCashbox::checkPass()
00912 {
00913         QString want = stdGetterLineEdit->text().stripWhiteSpace() ;
00914         //SqlCursor * log = new QSqlCursor( "System_users", TRUE ) ;
00915         QSqlQuery md( QString( "SELECT md5( '%1' );" ).arg( want ) ) ;
00916         md.next() ;
00917         QString md5p = md.value( 0 ).toString() ;
00918         if ( LabUser->value( "password" ).toString() == md5p ) {
00919                 stdGetterLineEdit->setEchoMode( QLineEdit::Normal ) ;
00920                 activeMode = "Line" ;
00921                 CurProd1TextLabel->setText( "" ) ;
00922                 currLineTextLabel->setText( tr( "Box Open" ) ) ;
00923                 newTicket() ;
00924         } else {
00925                 CurProd1TextLabel->setText( tr( "***** ERROR ***** Bad pass. Retry" ) ) ;
00926                 //for ( int i = 0; i < 1500000; i++ ) {
00927                 //}
00928                 //CurProd1TextLabel->setText( tr( "Password needed to resume" ) ) ;
00929         }
00930         resetGetter() ;
00931 }
00932 
00933 
00934 void LabCashbox::evalPrefixBtns()
00935 {
00936         QString btn = QObject::sender()->name() ;
00937         QString prefix = pgBtns[btn] ;
00938         
00939         parts->setFilter( QString( "left( serial, %1 ) = '%2'" ).arg( prefix.length() ).arg( prefix ) ) ;
00940         parts->select() ;
00941         
00942         parts->setFilter( "" ) ;
00943 }
00944 
00945 
00946 void LabCashbox::evalActionBtns()
00947 {
00948 
00949 }

 

L.A.B. Project © 2001-2004 LAB Project & DJ Anubis