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

qlabproductmanager.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 QlabProductManager::init()
00011 {
00012         defFilter = "active='1'" ;
00013         activeFlag = TRUE ;
00014         srchFlds << "prod_ref" << "prod_name" ;
00015         vndr = new QSqlCursor( "Contacts", TRUE ) ;
00016         prodsDataTable->setLeftMargin( 0 ) ;
00017         prodsDataTable->setColumnWidth( 1, 150 ) ;
00018         prodsDataTable->setFilter( "recid='0'" ) ;
00019         prodsDataTable->refresh( QDataTable::RefreshAll ) ;
00020 }
00021 
00022 void QlabProductManager::searchIt( const QString & srch )
00023 {
00024         if ( !srch.stripWhiteSpace().isEmpty() ) {
00025                 QString srlist = "active ='1' AND ( " ;
00026                 QString needle = srch.stripWhiteSpace().upper() ;
00027                 //needle = needle.replace( "'", "\\'" ).upper() ;
00028                 qDebug( needle ) ;
00029                 bool start = FALSE ;
00030                 if ( !needle.isEmpty() ) {
00031                         for ( QStringList::Iterator it = srchFlds.begin(); it != srchFlds.end(); ++it ) {
00032                                 QString fl = *it ;
00033                                 if ( start ) {
00034                                         srlist.append( " OR " ) ;
00035                                 } else {
00036                                         start = TRUE ;
00037                                 }
00038                                 srlist.append( QString( " %1 LIKE '%" ).arg( fl ) ) ;
00039                                 srlist.append( needle ) ;
00040                                 srlist.append( "%'" ) ;
00041                         }
00042                         srlist.append( " )" ) ;
00043                         qDebug( srlist ) ;
00044                         prodsDataTable->setFilter( srlist ) ;
00045                         prodsDataTable->refresh() ;
00046                 } else {
00047                         resetFilter() ;
00048                 }
00049         }
00050 }
00051 
00052 
00053 void QlabProductManager::resetFilter()
00054 {
00055         prodsDataTable->setFilter( defFilter ) ;
00056         prodsDataTable->refresh() ;
00057         searcher->setText( "" ) ;
00058         if ( prodsDataTable->numRows() > 0 ) {
00059                 prodsDataTable->selectRow( 0 ) ;
00060                 prodsDataTable->setCurrentCell( 0, 0 ) ;
00061                 prodsDataTable->ensureVisible( 0, 0 ) ;
00062                 productChanged( prodsDataTable->currentRecord() ) ;
00063         } else {
00064                 catPath->setText( BuildCategoryPath( QString( "%1" ).arg( activecat ) ) ) ;
00065                 prod_ref->setText( "" ) ;
00066                 prod_vendor_ref->setText( "" ) ;
00067                 prod_name->setText( "" ) ;
00068                 prod_description->setText( "" ) ;
00069                 vendorName->setText( "" ) ;
00070                 quick_rate->setText( "1.000" ) ;
00071                 base_buy_price->setText( currency( 0 ) ) ;
00072                 base_sell_price->setText( currency( 0 ) ) ;
00073                 prod_base_retail->setText( currency( 0 ) ) ;
00074         }
00075 }
00076 
00077 
00078 void QlabProductManager::setCatFilter( int catid )
00079 {
00080         activecat = catid ;
00081         defFilter = QString( "active='%1' AND main_category='%2'" ).arg( activeFlag ? 1 : 0 ).arg( catid ) ;
00082         resetFilter() ;
00083 }
00084 
00085 
00086 void QlabProductManager::productChanged( QSqlRecord * buffer )
00087 {
00088         catPath->setText( BuildCategoryPath( QString( "%1" ).arg( buffer->value( "main_category" ).toString() ) ) ) ;
00089         prod_ref->setText( buffer->value( "prod_ref" ).toString() ) ;
00090         prod_vendor_ref->setText( buffer->value( "prod_vendor_ref" ).toString() ) ;
00091         prod_name->setText( buffer->value( "prod_name" ).toString() ) ;
00092         prod_description->setText( buffer->value( "prod_description" ).toString() ) ;
00093         vendorName->setText( getVendor( buffer->value( "vendor_id" ).toInt() ) ) ;
00094         prod_description->setText( buffer->value( "prod_description" ).toString() ) ;
00095         quick_rate->setText( QString( "" ).setNum( buffer->value( "quick_rate" ).toDouble(), 'f', 3 ) ) ;
00096         base_buy_price->setText( currency( buffer->value( "base_buy_price" ).toDouble() ) ) ;
00097         base_sell_price->setText( currency( buffer->value( "base_sell_price" ).toDouble() ) ) ;
00098         prod_base_retail->setText( currency( buffer->value( "prod_base_retail" ).toDouble() ) ) ;
00099 }
00100 
00101 
00102 void QlabProductManager::evalAction()
00103 {
00104         QString action = QObject::sender()->name() ;
00105         qDebug( action ) ;
00106         if ( action == "prodNew" ) {
00107                 // new product creation
00108                 QSqlCursor * what = new QSqlCursor( "Inv_products", TRUE ) ;
00109                 QSqlCursor * catopts = new QSqlCursor( "System_categories", TRUE ) ;
00110                 catopts->setFilter( QString( "recid='%1'" ).arg( activecat ) ) ;
00111                 catopts->select() ;
00112                 catopts->next() ;               
00113                 QString options = catopts->value( "cat_data" ).toString() ;
00114                 QString vat = options.section( '\n', 0, 0 ) ;
00115                 QString defrate = options.section( '\n', 1, 1 ) ;
00116                 vat = vat.section( '|', 2, 2 ) ;
00117                 vat = vat.section( "=", 1, 1 ) ;
00118                 defrate = defrate.section( '|', 2, 2 ) ;
00119                 defrate = defrate.section( '=', 1, 1 ) ;
00120                 qDebug( vat ); qDebug( defrate ) ;
00121                 what->select() ;
00122                 QSqlRecord * buffer = what->primeInsert() ;
00123                 buffer->setValue( "recid", SequenceGetNextValue( "Inv_products" ) ) ;
00124                 buffer->setValue( "main_category", activecat ) ;
00125                 buffer->setValue( "quick_rate", defrate.toDouble() ) ;
00126                 buffer->setValue( "currency_id", 1 ) ;
00127                 buffer->setValue( "tax_id", vat.toInt() ) ;
00128                 buffer->setValue( "created", QDateTime::currentDateTime() ) ;
00129                 productDetailDialog * dialog = new productDetailDialog( this, "ProductDetail", TRUE ) ;
00130                 dialog->setBuffer( buffer ) ;
00131                 if ( dialog->exec() == QDialog::Accepted ) {
00132                         buffer->setValue( "lastchanged", QDateTime::currentDateTime() ) ;
00133                         buffer->setValue( "lastchangedID", LabUser->value( "recid" ).toInt() ) ;
00134                         buffer->setValue( "lastchangedreason", tr( "Creation" ) ) ;
00135                         what->insert() ;
00136                         qDebug( what->lastQuery() ) ;
00137                         prodsDataTable->refresh() ;
00138                 }               
00139                 delete dialog ;
00140         } else if ( action == "prodEdit" ) {
00141                 // edit product
00142                 QSqlCursor * what = new QSqlCursor( "Inv_products", TRUE ) ;
00143                 what->setFilter( QString( "recid='%1'" ).arg( prodsDataTable->currentRecord()->value( "recid" ).toString() ) ) ;
00144                 what->select() ;
00145                 what->next() ;
00146                 qDebug( what->lastQuery() ) ;
00147                 QSqlRecord * buffer = what->primeUpdate() ;
00148                 productDetailDialog * dialog = new productDetailDialog( this, "ProductDetail", TRUE ) ;
00149                 dialog->setBuffer( buffer ) ;
00150                 if( dialog->exec() == QDialog::Accepted ) {
00151                         buffer->setValue( "lastchanged", QDateTime::currentDateTime() ) ;
00152                         buffer->setValue( "lastchangedID", LabUser->value( "recid" ).toInt() ) ;
00153                         buffer->setValue( "lastchangedreason", tr( "Modification" ) ) ;
00154                         what->update() ;
00155                         qDebug( what->lastQuery() ) ;
00156                         prodsDataTable->refresh() ;
00157                 }
00158                 delete dialog ;
00159         } else if ( action == "prodDel" ) {
00160                 // Want to delete?
00161                 if ( QMessageBox::question( this, tr( "Delete Product?" ),
00162                                                                         tr( "You asked for a record deletion\n"
00163                                                                                 "This action will disable this record and all "
00164                                                                                 "associated parts.\n"
00165                                                                                 "Are you really sure you want to doo this?" ),
00166                                                                         tr( "No" ), tr( "Yes" ), 0, 0, 0 ) == 1 ) {
00167                         QSqlRecord * buffer = prodsDataTable->currentRecord() ;
00168                         QSqlQuery q( QString( "UPDATE Inv_products SET active=0 WHERE recid='%1' ;" )
00169                                                  .arg( buffer->value( "recid" ).toString() ) ) ;
00170                         prodsDataTable->refresh() ;
00171                 }
00172         }
00173 }
00174 
00175 
00176 QString QlabProductManager::currency( double val )
00177 {
00178         return QString( "" ).setNum( val, 'f', 2 ) ;
00179 }
00180 
00181 
00182 QString QlabProductManager::getVendor( int vid )
00183 {
00184         vndr->setFilter( QString( "recid='%1'" ).arg( vid ) ) ;
00185         vndr->select() ;
00186         if ( vndr->next() ) {
00187                 return vndr->value( "contact_name" ).toString() ;
00188         } else {
00189                 return tr( "Unknown" ) ;
00190         }
00191 }
00192 
00193 
00194 void QlabProductManager::printList()
00195 {
00196         QString bgcolor = "#e9fffe" ;
00197         bool odd = FALSE ;
00198         QString resultTable ;
00199         resultTable.append( "<table width=\"100%\" border=\"0\">" ) ;
00200         int nrows = prodsDataTable->numRows() ;
00201         for ( int i = 0; i < nrows; i++ ) {
00202                 odd = !odd ;
00203                 if ( odd ) {
00204                         resultTable.append( QString( "<tr bgcolor=\"%1\">" ).arg( bgcolor ) ) ;
00205                 } else {
00206                         resultTable.append( "<tr>" ) ;
00207                 }
00208                 resultTable.append( QString( "<td width=\"20%\">%1</td>" ).arg( prodsDataTable->text( i, 0 ) ) ) ;
00209                 resultTable.append( QString( "<td width=\"50%\">%1</td>" ).arg( prodsDataTable->text( i, 1 ) ) ) ;
00210                 resultTable.append( QString( "<td width=\"10%\" align=\"right\">%1</td>" ).arg( prodsDataTable->text( i, 2 ) ) ) ;
00211                 resultTable.append( QString( "<td width=\"10%\" align=\"right\">%1</td>" ).arg( prodsDataTable->text( i, 3 ) ) ) ;
00212                 resultTable.append( "<td width=\"10%\" align=\"right\">&nbsp;</td>" ) ;
00213                 resultTable.append( "</tr>" ) ;
00214         }
00215         resultTable.append( "</table>" ) ;
00216         QPrinter * printer = new QPrinter( QPrinter::ScreenResolution ) ;
00217         printer->setFullPage( TRUE ) ;
00218         if ( printer->setup( this ) ) {
00219                 QPainter p ;
00220                 if ( !p.begin( printer ) ) {
00221                         return ;
00222                 }
00223                 QPaintDeviceMetrics metrics( p.device() ) ;
00224                 int dpiy = metrics.logicalDpiY() ;
00225                 margin = (int)( ( 1 / 2.54 ) * dpiy ) ; // 1 cm margins
00226                 QRect body( margin, margin * 3, 
00227                                         metrics.width() - 2 * margin, 
00228                                         metrics.height() - 5 * margin ) ;
00229                 QSimpleRichText richText( resultTable, 
00230                                                                   prodsDataTable->font(), 
00231                                                                   0, 0, 0, body.height() ) ;
00232                 richText.setWidth( &p, body.width() ) ;
00233                 QRect view( body ) ;
00234                 
00235                 page = 1;
00236                 do {
00237                         // Draw Page
00238                         richText.draw( &p, body.left(), body.top(), view, colorGroup() ) ;
00239                         printHeader( p, view ) ;
00240                         printFooter( p, view ) ;
00241                         if ( view.top() >= richText.height() )
00242                                 break ;
00243                         printer->newPage() ;
00244                         page++ ;
00245                 } while (TRUE) ;
00246                 
00247         }
00248 }
00249 
00250 
00251 void QlabProductManager::printHeader( QPainter &p, QRect & view )
00252 {
00253         QString header = "Le Maryland" ;
00254         QString reportTitle = QString( tr( "Result List " ) ) ;
00255         QString rhead = QString( "%1: %2" ) 
00256                                         .arg( reportTitle )
00257                                         .arg( QDateTime::currentDateTime().toString( "dddd dd MMMM yyyy" ) ) ;
00258         QString tblh = "<table width=\"100%\">" ;
00259         tblh.append( QString( "<tr bgcolor=\"#e0e0e0\"><td width=\"20%\">%1</td><td width=\"50%\">%2</td>"
00260                                  "<td width=\"10%\">%3</td><td width=\"10%\">%4</td><td width=\"10%\">%5</td></tr></table>" )
00261                                  .arg( tr( "Reference" ) ).arg( tr( "Designation" ) )
00262                                  .arg( tr( "Public" ) ).arg( tr( "Available" ) ).arg( tr( "Notes" ) ) ) ;
00263         view.moveBy( 0, view.height() ) ;
00264         p.translate( 0 , - view.height() ) ;
00265         QSimpleRichText richtext( tblh, prodsDataTable->font(), 0, 0, 0, p.fontMetrics().ascent() + 20 ) ;
00266         richtext.setWidth( &p, view.width() ) ;
00267         
00268         p.drawText( view.left() , 
00269                                 view.top() - ( 2 * p.fontMetrics().ascent() ) - 10, 
00270                                 header ) ;
00271         p.drawText( view.right() - p.fontMetrics().width( rhead ) ,
00272                                 view.top() - ( 2 * p.fontMetrics().ascent() ) - 10, 
00273                                 rhead ) ;
00274         QPaintDeviceMetrics metrics( p.device() ) ;
00275         QRect titlerect( view.left(), view.top() - p.fontMetrics().ascent() - 20,
00276                                          metrics.width() - 2 * margin, p.fontMetrics().ascent() + 20 ) ;
00277         richtext.draw( &p, view.left(), view.top() - p.fontMetrics().ascent() - 20, titlerect, colorGroup() ) ;
00278         /*
00279         p.drawText( view.left() , 
00280                                 view.top() - p.fontMetrics().ascent() - 5, 
00281                                 header ) ;
00282         p.drawText( view.right() - p.fontMetrics().width( rhead ) ,
00283                                 view.top() - p.fontMetrics().ascent() - 5, 
00284                                 rhead ) ;
00285         */
00286 }
00287 
00288 
00289 void QlabProductManager::printFooter( QPainter & p, QRect & view )
00290 {
00291         view.moveBy( 0, view.height() ) ;
00292         p.translate( 0 , - view.height() ) ;
00293         p.drawText( view.left(),
00294                                 view.bottom() + margin - p.fontMetrics().ascent() - 5,
00295                                 QString( tr( "Printed on: " ) + 
00296                                                  QDateTime::currentDateTime().toString( "dddd dd MMMM yyyy - hh:mm:ss" ) ) ) ;
00297         
00298         p.drawText( view.right() - p.fontMetrics().width( QString( "Page: " ) + QString::number( page ) ),
00299                                 view.bottom() + margin - p.fontMetrics().ascent() - 5,
00300                                 QString( "Page: " ) + QString::number( page ) ) ;
00301 
00302 }

 

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