Exemplo n.º 1
0
bool MyMoneyReport::includes( const MyMoneyAccount& acc ) const
{
  bool result = false;

  if ( includesAccountGroup ( acc.accountGroup() ) )
  {
    switch ( acc.accountGroup() )
    {
      case MyMoneyAccount::Income:
      case MyMoneyAccount::Expense:
        if ( isTax() )
          result = ( acc.value ( "Tax" ) == "Yes" ) && includesCategory ( acc.id() );
        else
          result = includesCategory ( acc.id() );
        break;
      case MyMoneyAccount::Asset:
      case MyMoneyAccount::Liability:
        if ( isLoansOnly() )
          result = acc.isLoan() && includesAccount ( acc.id() );
        else if ( isInvestmentsOnly() )
          result = acc.isInvest() && includesAccount ( acc.id() );
        else if ( isIncludingTransfers() && m_rowType == MyMoneyReport::eExpenseIncome )
          // If transfers are included, ONLY include this account if it is NOT
          // included in the report itself!!
          result = ! includesAccount ( acc.id() );
        else
          result = includesAccount ( acc.id() );
        break;
      default:
        result = includesAccount ( acc.id() );
    }
  }
  return result;
}
Exemplo n.º 2
0
/**
	connexion a la base de donnees
  */
char database::connect(){
	db = QSqlDatabase::addDatabase("Q"+m_bdd);
	db.setHostName( m_hostName );
	db.setPort( m_port );
	db.setDatabaseName( m_name);
	db.setUserName( m_login );
	db.setPassword( m_password );

	if (!db.open()) {
		QMessageBox mBox(QMessageBox::Critical, tr("Erreur"), tr("<b>La connexion avec la base de donnees n a pas pu etre etablie!</b>"),QMessageBox::Ok);
		mBox.setDetailedText ( db.lastError().text() );
		mBox.exec();
		m_connected = false;
		return DB_CON_ERR;
	}
	else m_connected = true;

	// Si pas de tables on les crees
	QStringList tList = db.tables();
	if((!tList.contains("TAB_INFORMATIONS"))||(tList.count()< 14)){
		 // Demande si on creer une nouvelle base de donnees
		QString mess;
		if(db.driverName() == "QSQLITE")mess = tr("Voulez-vous créer une nouvelle base de données ?\n\n")+ db.databaseName();
		else mess = tr("Voulez-vous créer de nouvelles tables dans la base de données ?\n\n") + db.databaseName();
		QMessageBox mBox(QMessageBox::Question, tr("Question"), mess ,QMessageBox::Yes | QMessageBox::No);
		mBox.setDefaultButton(QMessageBox::No);
		int ret = mBox.exec();

		if(ret == QMessageBox::Yes){
			if( !create() ){
				m_connected = false;
				return DB_CON_ERR;
			}
		}else{
			m_connected = false;
			return DB_CON_ERR;
		}
	}
	else m_connected = true;

	//DI SQLITE activation des foreign Keys
	if(db.driverName() == "QSQLITE"){
		QSqlQuery query;
		query.prepare("PRAGMA foreign_keys = ON;");

		if(!query.exec()) {
			QMessageBox::critical(m_parent, tr("Erreur"), query.lastError().text());
			return false;
		}
	}

	// AVOIR: SI DEFAUT LES RETURN PRECEDENT QUI ZAPP LA CREATION DES CLASS NE POSE PAS SOUCIS!?
	m_databaseVersion = databaseVersion();
	m_isTax = isTax();
	//Creation des sous class
	m_customer = new customer(db, m_parent);
	//instanciation de la class product
	m_product = new product(db, m_lang, m_parent);
	//class de la gestion des tax
	m_tax = new tax(m_parent);

	//Test de la version de la base de donnees... !!
	if(m_databaseVersion > MCERCLE::Dbase_support){
		QString mess = tr("Version de mcercle: ") + MCERCLE::Version;
		mess += tr("\nVersion de la base de données: ") + QString::number(m_databaseVersion);
		mess += tr("\n\nVersions des bases de données compatibles: <= ") + QString::number(MCERCLE::Dbase_support);
		QMessageBox mBox(QMessageBox::Warning, tr("Attention"), tr("mcercle ne support pas cette version de base de données...\nMerci de faire évoluer mcercle."),QMessageBox::Ok);
		mBox.setDetailedText ( mess );
		mBox.exec();
		this->close();
		return DB_CON_ERR;
	}
	qDebug() << "version base:" <<QString::number(m_databaseVersion);
	
	// Mise a jour de la base de donnees
	if(m_databaseVersion < MCERCLE::Dbase_support){
		int ret = QMessageBox::warning(
								this->m_parent,
								tr("Attention"),
								tr("Cette version de mcercle doit mettre à jour la base de donnée pour fonctionner.\n\nVoulez-vous mettre à jour la base de donnée ?\n(Ceci peut prendre quelques minutes...)"),
								QMessageBox::Yes, QMessageBox::No | QMessageBox::Default
								);
	
		if(ret == QMessageBox::Yes){
			update_db upDatabase(this);

			QString logAll, log, mess;
			bool upgradeOk=true;
			if(m_databaseVersion <= 1) {
				if(!upDatabase.upgradeToV2(&log)) upgradeOk = false;
			}
			logAll += log;
			if(m_databaseVersion <= 2 ) {
				if(!upDatabase.upgradeToV3(&log)) upgradeOk = false;
			}
			logAll += log;
			if(m_databaseVersion <= 3 ) {
				if(!upDatabase.upgradeToV4(&log)) upgradeOk = false;
			}
			logAll += log;
			if(m_databaseVersion <= 4 ) {
				if(!upDatabase.upgradeToV5(&log)) upgradeOk = false;
			}
			logAll += log;
			if(m_databaseVersion <= 5 ) {
				if(!upDatabase.upgradeToV6(&log)) upgradeOk = false;
			}
			logAll += log;
			if(m_databaseVersion <= 6 ) {
				if(!upDatabase.upgradeToV7(&log)) upgradeOk = false;
			}
			logAll += log;
			if(m_databaseVersion <= 7 ) {
				if(!upDatabase.upgradeToV8(&log)) upgradeOk = false;
			}
			logAll += log;
			if(m_databaseVersion <= 8 ) {
				if(!upDatabase.upgradeToV9(&log)) upgradeOk = false;
			}
			logAll += log;

			QMessageBox mBox(QMessageBox::Information, tr("Information"), mess, QMessageBox::Ok);
			if(upgradeOk){
				mess += tr("La mise à jour de la base de données a réussi !\n");
				mBox.setIcon( QMessageBox::Information );
			}
			else{
				mess += tr("La mise à jour contient des erreurs :-(\nAfficher les détails pour voir ce qui ne va pas.");
				mBox.setIcon( QMessageBox::Critical );
			}
			mBox.setText( mess );
			mBox.setDetailedText(logAll);
			mBox.exec();
		}
		else{
			this->close();
			return DB_CON_ERR;
		}
	}
	
	return DB_CON_OK;
}