Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fact-team.github.io
42 changes: 42 additions & 0 deletions src/database/billingdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,46 @@ QList<Billing> BillingDatabase::getBillings(const int projectId)
return bills;
}

QList<Billing> BillingDatabase::getAllBillingsOnly(const int idProject)
{
QList<Billing> bills;
QSqlQuery q;
q.prepare(
"SELECT DISTINCT b.idBilling, title, description, number, "
"isBilling, date, isPaid "
"FROM Billing b, BillingProject bp "
"WHERE idProject=:idProject "
"AND b.idBilling = bp.idBilling "
"AND isPaid = 1 "
"AND isBilling = 1 "
);

q.bindValue(":idProject",idProject);


if(!q.exec()) {
throw new DbException(
"Impossible de récupérer les Factures",
"BddCustomer::getBillings",
lastError(q),
1.3);
}

while(q.next()) {
bills.append(*getBilling(q));
}
return bills;
}

QList<Billing> BillingDatabase::getBillingsBetweenDates(QList<Billing> bills, QDate begin, QDate end)
{
QList<Billing> billings;
for (Billing b : bills) {
if (b.getDate() >= begin && b.getDate() <= end) {
billings.append(b);
}
}
return billings;
}

}
17 changes: 17 additions & 0 deletions src/database/billingdatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ class BillingDatabase : public Database
*/
QList<Billing> getBillings(const int projectId);

/**
* @brief BillingDatabase::getAllBillingsOnly get all billings which aren't
* quotes for the project <i>p</i>
* @param p
* @return the list of <b>Billing</b>
*/
QList<Billing> getAllBillingsOnly(const int idProject);

/**
* @brief BillingDatabase::getBillingsBetweenDates get billings in the list
* between <i>begin</i> and <i>end</i> dates
* @param begin
* @param end
* @return the list of <b>Billing</b>
*/
QList<Billing> getBillingsBetweenDates(QList<Billing> bills, QDate begin, QDate end);

private:
static BillingDatabase* _instance;//!< Singleton instance of BillingDatabase

Expand Down
9 changes: 9 additions & 0 deletions src/database/projectdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ QList<Project*> ProjectDatabase::getAllProjects()
return list;
}

double ProjectDatabase::getCostProjects(QList<Project *> projects)
{
double cost = 0;
for (Project *p: projects) {
cost+= p->getCost();
}
return cost;
}


Models::Project* ProjectDatabase::getProject(const int pId)
{
Expand Down
8 changes: 8 additions & 0 deletions src/database/projectdatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ class ProjectDatabase : public Database
*/
QList<Project*> getAllProjects();

/**
* @brief ProjectDatabase::getCostProjects compute the cost of
* the project list given in parameter
* @param projects the list of projects
* @return the cost of the list given
*/
double getCostProjects(QList<Project*> projects);

private:
static ProjectDatabase* _instance;//!< Singleton instance of ProjectDatabase

Expand Down
76 changes: 76 additions & 0 deletions src/gui/dialogs/computeturnoverdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "computeturnoverdialog.h"
#include "ui_computeturnoverdialog.h"


namespace Gui {
namespace Dialogs {
ComputeTurnoverDialog::ComputeTurnoverDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ComputeTurnoverDialog)
{
ui->setupUi(this);
ui->clBeginPeriod->setSelectedDate(QDate(QDate::currentDate().year(),1,1));
ui->clEndPeriod->setSelectedDate(QDate::currentDate());
}

ComputeTurnoverDialog::~ComputeTurnoverDialog()
{
delete ui;
}

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

void ComputeTurnoverDialog::computeTurnover()
{
QList<Project*> projects;
QList<Billing> bills;
double turnover = 0;
int nbBillings = 0;

projects = Databases::ProjectDatabase::instance()->getAllProjects();

for (Project *p : projects) {
bills = Databases::BillingDatabase::instance()
->getAllBillingsOnly(p->getId());
for (Billing b : Databases::BillingDatabase::instance()
->getBillingsBetweenDates(bills,
ui->clBeginPeriod->selectedDate(),
ui->clEndPeriod->selectedDate())) {
ContributoriesList cl = Databases::ContributoryDatabase::instance()
->getContributoriesByBillingAndProject(b.getId(),
p->getId());
Rate rate = Databases::RateDatabase::instance()->getRate(b.getId(),
p->getId());
turnover += (cl.getSumQuantity()) * rate.getHourlyRate();
++nbBillings;
}
}
fillLabels(nbBillings,turnover);
}

void ComputeTurnoverDialog::endDateControl(const QDate end)
{
if (end < ui->clBeginPeriod->selectedDate()) {
ui->clBeginPeriod->setSelectedDate(ui->clEndPeriod->selectedDate());
}
}

void ComputeTurnoverDialog::beginDateControl(const QDate begin)
{
if (begin > ui->clEndPeriod->selectedDate()) {
ui->clEndPeriod->setSelectedDate(ui->clBeginPeriod->selectedDate());
}
}
}
}
63 changes: 63 additions & 0 deletions src/gui/dialogs/computeturnoverdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef COMPUTETURNOVERDIALOG_H
#define COMPUTETURNOVERDIALOG_H

#include "database/billingdatabase.h"
#include "database/contributorydatabase.h"
#include "database/ratedatabase.h"
#include <QDialog>

namespace Ui {
class ComputeTurnoverDialog;
}

namespace Gui {
namespace Dialogs {
/**
* @author Manantsoa Razanajatovo
* @brief The ComputeTurnoverDialog class window
* to compute a turnover with a period
*/
class ComputeTurnoverDialog : public QDialog
{
Q_OBJECT

public:
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
* the turnover between chosen dates in the window
*/
void computeTurnover();

/**
* @brief ComputeTurnoverDialog::endDateControl controls if
* the <i>end</i> date field is valid
* @param end
*/
void endDateControl(const QDate end);

/**
* @brief ComputeTurnoverDialog::beginDateControl controls
* if the <i>begin</i> date field is valid
* @param begin
*/
void beginDateControl(const QDate begin);

private:
Ui::ComputeTurnoverDialog *ui;
};
}
}

#endif // COMPUTETURNOVERDIALOG_H
Loading