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

pressmanager.ui.h

00001 /****************************************************************************
00002 ** ui.h extension file, included from the uic-generated form implementation.
00003 **
00004 ** If you wish to add, delete or rename functions or slots use
00005 ** Qt Designer which will update this file, preserving your code. Create an
00006 ** init() function in place of a constructor, and a destroy() function in
00007 ** place of a destructor.
00008 *****************************************************************************/
00009 
00010 void PressManager::init()
00011 {
00012     prods = new QSqlCursor( "Inv_products", TRUE ) ;
00013     parts = new QSqlCursor( "Inv_parts", TRUE ) ;
00014     tmpx = new QSqlCursor( "Inv_pressio", TRUE ) ;
00015     readtxt->setText( "" ) ;
00016     historyTable->setLeftMargin( 0 ) ;
00017     historyTable->setColumnStretchable( 1, TRUE ) ;
00018     historyTable->setColumnWidth( 0, 150 ) ;
00019     historyTable->setColumnWidth( 1, 400 ) ;
00020     historyTable->setColumnWidth( 2, 100 ) ;
00021     historyTable->setColumnWidth( 3, 100 ) ;
00022     historyTable->setColumnWidth( 4, 0 ) ;
00023     historyTable->setColumnWidth( 5, 0 ) ;
00024     historyTable->refresh( QDataTable::RefreshAll ) ;
00025 }
00026 
00027 void PressManager::setMode( int mode )
00028 {
00029     md = mode ;
00030     switch ( mode ) {
00031     case 0 : activeMode->setText( tr( "Receive" ) ) ; break ;
00032     case 1 : activeMode->setText( tr( "Return" ) ) ; break ;
00033     default : break ;
00034 }
00035 }
00036 
00037 
00038 void PressManager::validateChanges()
00039 {
00040     QString action = QObject::sender()->name() ;
00041     if ( action == "closeButton" ) {
00042         bool receive = FALSE ; 
00043         int qx = 0 ;
00044         switch ( md ) {
00045         case 0 : // Receive
00046             receive = TRUE ;
00047             break ;
00048         case 1 : // Return
00049             receive = FALSE;
00050             break ;
00051         }
00052         tmpx->setFilter( "" ) ;
00053         tmpx->select() ;
00054         while ( tmpx->next() ) {
00055             parts->setFilter( QString( "recid='%1'" ).arg( tmpx->value( "partid" ).toString() ) ) ;
00056             parts->select() ;
00057             parts->next() ;
00058             QSqlRecord * buffer = parts->primeUpdate() ;
00059             qx = buffer->value( "stock" ).toInt() ;
00060             if ( receive ) {
00061                 qx += tmpx->value( "qty" ).toInt() ;
00062             } else {
00063                 qx -= tmpx->value( "qty" ).toInt() ;        
00064             }
00065             buffer->setValue( "retail", tmpx->value( "price" ).toString() ) ;
00066             buffer->setValue( "stock", qx ) ;
00067             parts->update() ;
00068         }
00069         QSqlQuery q( "TRUNCATE TABLE Inv_pressio" ) ;
00070         accept() ;
00071     } else {
00072         QSqlQuery q( "TRUNCATE TABLE Inv_pressio" ) ;
00073         reject() ;
00074     }
00075 }
00076 
00077 void PressManager::findItem()
00078 {
00079     QString want = reader->text().upper() ;
00080     readtxt->setText( want ) ;
00081     if ( want.left( 3 ) == "378" && want.length() >= 8 ) {
00082         // Found barcode
00083         QString serial = want.left( 8 ) ;
00084         // Do we have this ?
00085         if ( !getTmp( want ) && !getPart( want ) ) {
00086             // Must Create product & part...
00087         }
00088         title->setText( tmpx->value( "title" ).toString() ) ;
00089         qty->setValue( tmpx->value( "qty").toInt() ) ;
00090         retailShown->setText( tmpx->value( "price" ).toString() ) ;
00091     } else {
00092         // Should be a product ref.
00093         if ( !getProd( want ) ) {
00094         }
00095     }
00096     reader->setText( "" ) ;
00097 }
00098 
00099 
00100 void PressManager::mapQty( int newq )
00101 {
00102     QSqlRecord * buffer = tmpx->primeUpdate() ;
00103     int recid = buffer->value( "recid" ).toInt() ;
00104     buffer->setValue( "qty", newq ) ;
00105     tmpx->update() ;
00106     tmpx->setFilter( QString( "recid='%1'" ).arg( recid ) );
00107     tmpx->select() ;
00108     tmpx->next() ;
00109     historyTable->refresh() ;
00110 }
00111 
00112 
00113 bool PressManager::getPart( const QString & want )
00114 {
00115     parts->setFilter( QString( "serial LIKE '%1%'" ).arg( want.left( 8 ) ) ) ;
00116     parts->select() ;
00117     qDebug( parts->lastQuery() ) ;
00118     if ( parts->next() ) {
00119         qDebug( "Part Found..."  ) ;
00120         qDebug( QString( "%1, %2" ).arg( parts->value( "recid" ).toString() ).arg( parts->value( "serial" ).toString() ) ) ;
00121         // This part exists
00122         prods->setFilter( QString( "recid='%1'" ).arg( parts->value( "prodid" ).toString() ) ) ;
00123         prods->select() ;
00124         if( !prods->next() ) {
00125             qDebug( QString( "Product recid: %1 does not exist!" ).arg( parts->value( "recid" ).toString() ) ) ;
00126             QSqlRecord *dr = parts->primeDelete() ;
00127             parts->del() ;
00128             return getPart( want ) ;
00129         } else {
00130             QString retail = want.mid( 8, 4 ).insert( 2, "." ) ;
00131             retailShown->setText( retail ) ;
00132             QSqlRecord * buffer = tmpx->primeInsert() ;
00133             buffer->setValue( "serial", want ) ;
00134             buffer->setValue( "partid", parts->value( "recid" ).toInt() ) ;
00135             buffer->setValue( "reference", prods->value( "prod_ref" ).toString() ) ;
00136             buffer->setValue( "title", prods->value( "prod_name" ).toString() ) ;
00137             buffer->setValue( "price", retail ) ;
00138             buffer->setValue( "qty", 1 ) ;
00139             qDebug( buffer->value( "title" ).toString() ) ;
00140             tmpx->insert() ;
00141             historyTable->refresh() ;
00142             return getTmp( want ) ;
00143         }
00144     }
00145     return FALSE ;
00146 }
00147 
00148 
00149 
00150 bool PressManager::getTmp( const QString & want )
00151 {
00152     for ( int i = 0; i < historyTable->numRows(); i++ ) {
00153         if ( historyTable->text( i, 5 ) == want ) {
00154             historyTable->setCurrentCell( i, 0 ) ;
00155             historyTable->selectRow( i ) ;
00156         }
00157     }
00158     return FALSE ;
00159 }
00160 
00161 
00162 bool PressManager::getProd( const QString & prod )
00163 {
00164     prods->setFilter( QString( "prod_ref='%1'" ).arg( prod ) ) ;
00165     prods->select() ;
00166     if ( !prods->next() ) {
00167         return FALSE ;
00168     }
00169     parts->setFilter( QString( "prodid='%1'" ).arg( prods->value( "recid" ).toString() ) ) ;
00170     parts->select() ;
00171     if ( !parts->next() ) {
00172         return FALSE ;
00173     }
00174     reader->setText( parts->value( "serial" ).toString() ) ;
00175     findItem() ;
00176     return TRUE ;
00177 }
00178 
00179 
00180 void PressManager::recallOne( QSqlRecord * buffer )
00181 {
00182     QString pri = buffer->value( "price" ).toString() ;
00183     pri = pri.replace( ".", "" ).rightJustify( 4, '0' ) ;
00184     reader->setText( QString( "%1%2" )
00185                      .arg( buffer->value( "serial" ).toString() )
00186                      .arg( pri ) ) ;
00187     findItem() ;
00188 }
00189 
00190 
00191 void PressManager::editItem()
00192 {
00193 
00194 }

 

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