diff --git a/documents/LaTexTemplate b/documents/LaTexTemplate index 34fcc24..5c18e6e 160000 --- a/documents/LaTexTemplate +++ b/documents/LaTexTemplate @@ -1 +1 @@ -Subproject commit 34fcc2473d13eb55e40235562fe4da67b5bf83e6 +Subproject commit 5c18e6e55e09a899cc44aa7db8d4ae8c98824376 diff --git a/fact-team.github.io b/fact-team.github.io index 845a343..77871cb 160000 --- a/fact-team.github.io +++ b/fact-team.github.io @@ -1 +1 @@ -Subproject commit 845a34366127f4999b650aa7f812f209600564d2 +Subproject commit 77871cb8dec4e9b1528d982a1fcfd13777a1314c diff --git a/src/database/billingdatabase.cpp b/src/database/billingdatabase.cpp index 533a0f7..a0222cf 100644 --- a/src/database/billingdatabase.cpp +++ b/src/database/billingdatabase.cpp @@ -385,4 +385,46 @@ QList BillingDatabase::getBillings(const int projectId) return bills; } +QList BillingDatabase::getAllBillingsOnly(const int idProject) +{ + QList 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 BillingDatabase::getBillingsBetweenDates(QList bills, QDate begin, QDate end) +{ + QList billings; + for (Billing b : bills) { + if (b.getDate() >= begin && b.getDate() <= end) { + billings.append(b); + } + } + return billings; +} + } diff --git a/src/database/billingdatabase.h b/src/database/billingdatabase.h index e050252..2684244 100644 --- a/src/database/billingdatabase.h +++ b/src/database/billingdatabase.h @@ -146,6 +146,23 @@ class BillingDatabase : public Database */ QList getBillings(const int projectId); + /** + * @brief BillingDatabase::getAllBillingsOnly get all billings which aren't + * quotes for the project p + * @param p + * @return the list of Billing + */ + QList getAllBillingsOnly(const int idProject); + + /** + * @brief BillingDatabase::getBillingsBetweenDates get billings in the list + * between begin and end dates + * @param begin + * @param end + * @return the list of Billing + */ + QList getBillingsBetweenDates(QList bills, QDate begin, QDate end); + private: static BillingDatabase* _instance;//!< Singleton instance of BillingDatabase diff --git a/src/database/projectdatabase.cpp b/src/database/projectdatabase.cpp index 77da3d7..9788f42 100644 --- a/src/database/projectdatabase.cpp +++ b/src/database/projectdatabase.cpp @@ -72,6 +72,15 @@ QList ProjectDatabase::getAllProjects() return list; } +double ProjectDatabase::getCostProjects(QList projects) +{ + double cost = 0; + for (Project *p: projects) { + cost+= p->getCost(); + } + return cost; +} + Models::Project* ProjectDatabase::getProject(const int pId) { diff --git a/src/database/projectdatabase.h b/src/database/projectdatabase.h index b25613f..d9442e7 100644 --- a/src/database/projectdatabase.h +++ b/src/database/projectdatabase.h @@ -117,6 +117,14 @@ class ProjectDatabase : public Database */ QList 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 projects); + private: static ProjectDatabase* _instance;//!< Singleton instance of ProjectDatabase diff --git a/src/gui/dialogs/computeturnoverdialog.cpp b/src/gui/dialogs/computeturnoverdialog.cpp new file mode 100644 index 0000000..462612f --- /dev/null +++ b/src/gui/dialogs/computeturnoverdialog.cpp @@ -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 projects; + QList 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()); + } +} +} +} diff --git a/src/gui/dialogs/computeturnoverdialog.h b/src/gui/dialogs/computeturnoverdialog.h new file mode 100644 index 0000000..876ba37 --- /dev/null +++ b/src/gui/dialogs/computeturnoverdialog.h @@ -0,0 +1,63 @@ +#ifndef COMPUTETURNOVERDIALOG_H +#define COMPUTETURNOVERDIALOG_H + +#include "database/billingdatabase.h" +#include "database/contributorydatabase.h" +#include "database/ratedatabase.h" +#include + +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 nbBillings and turnover + * @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 end date field is valid + * @param end + */ + void endDateControl(const QDate end); + + /** + * @brief ComputeTurnoverDialog::beginDateControl controls + * if the begin date field is valid + * @param begin + */ + void beginDateControl(const QDate begin); + +private: + Ui::ComputeTurnoverDialog *ui; +}; +} +} + +#endif // COMPUTETURNOVERDIALOG_H diff --git a/src/gui/dialogs/computeturnoverdialog.ui b/src/gui/dialogs/computeturnoverdialog.ui new file mode 100644 index 0000000..5270ffc --- /dev/null +++ b/src/gui/dialogs/computeturnoverdialog.ui @@ -0,0 +1,230 @@ + + + ComputeTurnoverDialog + + + + 0 + 0 + 700 + 350 + + + + + 650 + 340 + + + + + 700 + 350 + + + + Calcul du chiffre d'affaires + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Calculer + + + + :/icons/img/rate.png:/icons/img/rate.png + + + + + + + + + + 291 + 0 + + + + Période + + + + + + + + Fin + + + + + + + Début + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + + + + + + + + + + Qt::AlignCenter + + + + + + + 0 + + + + + CA + + + + + + + true + + + + + + + € (euros) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + Qt::AlignCenter + + + + + + + + + + + + + + btnCompute + released() + ComputeTurnoverDialog + computeTurnover() + + + 610 + 339 + + + 361 + 235 + + + + + clBeginPeriod + clicked(QDate) + ComputeTurnoverDialog + beginDateControl(QDate) + + + 184 + 147 + + + 503 + 296 + + + + + clEndPeriod + clicked(QDate) + ComputeTurnoverDialog + endDateControl(QDate) + + + 411 + 165 + + + 580 + 270 + + + + + + computeTurnover() + endDateControl(QDate) + beginDateControl(QDate) + + diff --git a/src/gui/mainwindow/mainwindow.cpp b/src/gui/mainwindow/mainwindow.cpp index 590a724..a70927f 100644 --- a/src/gui/mainwindow/mainwindow.cpp +++ b/src/gui/mainwindow/mainwindow.cpp @@ -288,6 +288,13 @@ void MainWindow::openPdf() } +void MainWindow::computeTurnover() +{ + ComputeTurnoverDialog cp; + + cp.exec(); +} + void MainWindow::search(QString text) { updateUI(text); diff --git a/src/gui/mainwindow/mainwindow.h b/src/gui/mainwindow/mainwindow.h index 6c9d173..5644302 100644 --- a/src/gui/mainwindow/mainwindow.h +++ b/src/gui/mainwindow/mainwindow.h @@ -24,8 +24,10 @@ #include "gui/dialogs/dialogaddcustomer.h" #include "gui/dialogs/addprojectdialog.h" #include "gui/dialogs/addquotedialog.h" +#include "gui/dialogs/computeturnoverdialog.h" #include "gui/docks/searchdock.h" + #include "exceptions/fileexception.h" #include "utils/pointers.h" @@ -198,6 +200,12 @@ public slots: */ void openPdf(); + /** + * @brief MainWindow::computeTurnover open window to allow computation + * of a period turnover + */ + void computeTurnover(); + private slots: /** * @brief MainWindow::openContextualMenuTable open contextual menu diff --git a/src/gui/mainwindow/mainwindow.ui b/src/gui/mainwindow/mainwindow.ui index b1cf9ec..d9085a2 100644 --- a/src/gui/mainwindow/mainwindow.ui +++ b/src/gui/mainwindow/mainwindow.ui @@ -368,7 +368,7 @@ 0 0 1413 - 22 + 19 @@ -384,9 +384,9 @@ Client - + @@ -403,9 +403,16 @@ + + + Statistiques + + + + @@ -679,6 +686,11 @@ Nouveau projet + + + Calculer CA d'une période + + @@ -967,8 +979,8 @@ addProject() - 499 - 130 + 483 + 114 797 @@ -983,8 +995,8 @@ editProject() - 499 - 130 + 483 + 114 738 @@ -999,8 +1011,8 @@ removeProject() - 499 - 130 + 483 + 114 0 @@ -1095,8 +1107,8 @@ editDoc() - 411 - 542 + 576 + 677 319 @@ -1111,8 +1123,8 @@ removeDoc() - 525 - 529 + 756 + 677 609 @@ -1143,8 +1155,8 @@ openPdf() - 828 - 522 + 1091 + 677 827 @@ -1191,8 +1203,8 @@ billingIsPaid() - 742 - 533 + 978 + 677 733 @@ -1207,8 +1219,8 @@ copyDoc() - 645 - 527 + 892 + 676 666 @@ -1216,6 +1228,22 @@ + + actComputeTurnover + triggered() + MainWindow + computeTurnover() + + + -1 + -1 + + + 706 + 359 + + + addCustomer() @@ -1251,5 +1279,6 @@ openPdf() billingIsPaid() copyDoc() + computeTurnover() diff --git a/src/src.pro b/src/src.pro index 98e323c..d59e06e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -90,7 +90,8 @@ SOURCES += gui/mainwindow/mainwindow.cpp \ gui/widgets/checkfields/checkipaddress.cpp \ gui/widgets/checkfields/checklogin.cpp \ gui/widgets/checkfields/checkportnumber.cpp \ - models/people.cpp + models/people.cpp \ + gui/dialogs/computeturnoverdialog.cpp HEADERS += gui/mainwindow/mainwindow.h \ utils/log.h\ @@ -196,7 +197,8 @@ HEADERS += gui/mainwindow/mainwindow.h \ gui/widgets/checkfields/checkipaddress.h \ gui/widgets/checkfields/checklogin.h \ gui/widgets/checkfields/checkportnumber.h \ - models/people.h + models/people.h \ + gui/dialogs/computeturnoverdialog.h FORMS += gui/mainwindow/mainwindow.ui \ @@ -214,7 +216,8 @@ FORMS += gui/mainwindow/mainwindow.ui \ gui/dialogs/messagebox.ui \ gui/docks/searchdock.ui \ gui/dialogs/startedwindowsdialog.ui \ - gui/widgets/databasesettingswidget.ui + gui/widgets/databasesettingswidget.ui \ + gui/dialogs/computeturnoverdialog.ui RESOURCES += \ icons.qrc \ diff --git a/tests/QTestRunner b/tests/QTestRunner index 7a32d32..0b1b7b6 160000 --- a/tests/QTestRunner +++ b/tests/QTestRunner @@ -1 +1 @@ -Subproject commit 7a32d323d064ad362ea398b575f9f48482ad3a82 +Subproject commit 0b1b7b6d02fb304c6a15d944afcb57d176f32ab0 diff --git a/tests/database/billingdatabasetest.cpp b/tests/database/billingdatabasetest.cpp index 9cf1aa5..cc20951 100644 --- a/tests/database/billingdatabasetest.cpp +++ b/tests/database/billingdatabasetest.cpp @@ -169,3 +169,38 @@ void BillingDatabaseTest::getBilling() } +void BillingDatabaseTest::getAllBillingsOnly() +{ + bool billing = true; + + for (Billing b : Databases::BillingDatabase::instance()->getAllBillingsOnly(23)) { + if (!b.isBilling()) { + billing = false; + } + } + + QVERIFY(billing); + +} + +void BillingDatabaseTest::getBillingsBetweenDates() +{ + QList bills; + QList 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"); +} + diff --git a/tests/database/billingdatabasetest.h b/tests/database/billingdatabasetest.h index 34acddb..1363bb0 100644 --- a/tests/database/billingdatabasetest.h +++ b/tests/database/billingdatabasetest.h @@ -26,6 +26,8 @@ private slots: void getMaxBillingNumberOfCustomer(); void getMaxQuoteNumberOfCustomer(); void getBilling(); + void getAllBillingsOnly(); + void getBillingsBetweenDates(); private: Billing* b1; int _lastInsert;