Skip to content

Commit

Permalink
Refactoring, deleting and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
manantsoa committed Mar 17, 2015
1 parent ca813a5 commit 8453329
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 28 deletions.
12 changes: 0 additions & 12 deletions src/database/projectdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ QList<Project*> ProjectDatabase::getAllProjects()
return list;
}

QList<Project *> ProjectDatabase::getAllProjectsBetweenDates(QDate begin, QDate end)
{
QList<Project*> list;

for (Project *p: getAllProjects()) {
if (p->getBeginDate() >= begin) {
list.append(p);
}
}
return list;
}

double ProjectDatabase::getCostProjects(QList<Project *> projects)
{
double cost = 0;
Expand Down
9 changes: 0 additions & 9 deletions src/database/projectdatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ class ProjectDatabase : public Database
*/
QList<Project*> getAllProjects();

/**
* @brief ProjectDatabase::getAllProjectsBetweenDates Return the list of
* projects between a <i>begin</i> date and an <i>end</i> date
* @param begin the beginning date where projects can start
* @param end the end date until where the projects can finish
* @return the list of <b>Project</b> in the set
*/
QList<Project*> getAllProjectsBetweenDates(QDate begin, QDate end);

/**
* @brief ProjectDatabase::getCostProjects compute the cost of
* the project list given in parameter
Expand Down
16 changes: 9 additions & 7 deletions src/gui/dialogs/computeturnoverdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ ComputeTurnoverDialog::~ComputeTurnoverDialog()
delete ui;
}

void ComputeTurnoverDialog::fillLabels(const int nbBillings, const int turnover)
{
ui->lbCompute->setText("Votre CA du "+ui->dtBeginPeriod->date().toString("dd/MM/yyyy") +
" au " + ui->dtEndPeriod->date().toString("dd/MM/yyyy") +
" est de " + QString::number(turnover) + " euro(s)");
ui->lbBillingNb->setText(QString::number(nbBillings) + " Facture(s) trouvée(s)");
}

void ComputeTurnoverDialog::computeTurnover()
{
QList<Project*> projects;
Expand All @@ -34,13 +42,7 @@ void ComputeTurnoverDialog::computeTurnover()
++nbBillings;
}
}
ui->lbCompute->setAlignment(Qt::AlignCenter);
ui->lbCompute->setText("Votre CA du "+ui->dtBeginPeriod->date().toString("dd/MM/yyyy") +
" au " + ui->dtEndPeriod->date().toString("dd/MM/yyyy") +
" est de " + QString::number(turnover) + " euro(s)");
ui->lbBillingNb->setAlignment(Qt::AlignCenter);
ui->lbBillingNb->setText(QString::number(nbBillings) + " Facture(s) trouvée(s)");

fillLabels(nbBillings,turnover);
}

void ComputeTurnoverDialog::endDateControl(QDate end)
Expand Down
8 changes: 8 additions & 0 deletions src/gui/dialogs/computeturnoverdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class ComputeTurnoverDialog : public QDialog
explicit ComputeTurnoverDialog(QWidget *parent = 0);
~ComputeTurnoverDialog();

/**
* @brief ComputeTurnoverDialog::fillLabels Fills the
* labels with <i>nbBillings</i> and <i>turnover</i>
* @param nbBillings the number of Billings
* @param turnover the turnover computed
*/
void fillLabels(const int nbBillings,const int turnover);

public slots:
/**
* @brief ComputeTurnoverDialog::computeTurnover compute
Expand Down
6 changes: 6 additions & 0 deletions src/gui/dialogs/computeturnoverdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="lbBillingNb">
<property name="geometry">
Expand All @@ -117,6 +120,9 @@
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
<resources/>
Expand Down
35 changes: 35 additions & 0 deletions tests/database/billingdatabasetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,38 @@ void BillingDatabaseTest::getBilling()

}

void BillingDatabaseTest::getAllBillingsOnly()
{
bool billing = true;

for (Billing b : Databases::BillingDatabase::instance()->getAllBillingsOnly(1)) {
if (!b.isBilling()) {
billing = false;
}
}

QVERIFY(billing);

}

void BillingDatabaseTest::getBillingsBetweenDates()
{
QList<Billing> bills;
QList<Billing> bills2;
bills.append(Billing(1));
bills.append(Billing(2));

bills2 = Databases::BillingDatabase::instance()
->getBillingsBetweenDates(bills,QDate(2015,2,13),QDate(2035,2,13));


QVERIFY(bills2.count() == 2
&& bills2.first().getDate() == QDate(2015,2,13)
&& bills2.first().getTitle() == "Coucou"
&& bills2.first().getDescription() == "Mon super devis de la "
"mort qui rox du poulet"
&& bills2.last().getDate() == QDate(2015,2,13)
&& bills2.last().getTitle() == "Bonjour"
&& bills2.last().getDescription() == "Manger du poney");
}

2 changes: 2 additions & 0 deletions tests/database/billingdatabasetest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private slots:
void getMaxBillingNumberOfCustomer();
void getMaxQuoteNumberOfCustomer();
void getBilling();
void getAllBillingsOnly();
void getBillingsBetweenDates();
private:
Billing* b1;
int _lastInsert;
Expand Down

0 comments on commit 8453329

Please sign in to comment.