Skip to content

Commit

Permalink
Method to set all contributories id of a Billing
Browse files Browse the repository at this point in the history
  • Loading branch information
manantsoa committed Mar 8, 2015
1 parent d26c883 commit 27e3fa4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/gui/dialogs/addquotedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ AddQuoteDialog::AddQuoteDialog(bool isBilling, int idCustomer, int id, bool edit
}
else {
_quote->setId(0);
_quote->getContributories().setAllIdContributories(0);
_quote->setNumber(isBilling ? Databases::BillingDatabase::instance()->getMaxBillingNumberOfCustomer(idCustomer)+1
: Databases::BillingDatabase::instance()->getMaxQuoteNumberOfCustomer(idCustomer)+1);
//_quote->commit();
Expand Down Expand Up @@ -70,7 +71,9 @@ void AddQuoteDialog::accept() {
_quote->setDescription(ui->leDescription->toPlainText());
_quote->setDate(ui->dateEditQuote->date());

qDebug() << "accept";
_quote->setContributories(*((Widgets::ContributoriesWidget*)ui->wdgContributories)->getContributories());
//(_quote->getContributories()).setAllIdContributories(0);

_quote->commit();
_quote->generateTex();
Expand Down
1 change: 1 addition & 0 deletions src/models/billing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void Billing::commit()
bool insert = _id == 0;
if(insert) {
_id = BillingDatabase::instance()->addBilling(*this);
qDebug() << "INSERTION Billing: " << _id;
} else if(_toRemoved){
remove();
} else {
Expand Down
35 changes: 35 additions & 0 deletions src/models/contributorieslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void ContributoriesList::commit()
getRate(it.key()->first).getHourlyRate());
}
for(Contributory c : it.value()) {
qDebug() << "ContributoriesList::commit: " << c.getId();
// Fill trinary legs… :)
bool insertBillingProject = c.getId() == 0;
c.commit();
Expand Down Expand Up @@ -76,6 +77,7 @@ QList<Contributory>& ContributoriesList::getContributories(Project *p)
}
}

//(*this)[key].first().setId(0);
return (*this)[key];
}

Expand Down Expand Up @@ -170,6 +172,39 @@ void ContributoriesList::setIdBilling(int idBilling)
{
_idBilling = idBilling;
}

void ContributoriesList::setAllIdContributories(int idContributory)
{
/*for (auto it = getAllContributories()->begin();
it != getAllContributories()->end();++it) {
qDebug() << "setAllIdContributories" << (*it).getId();
//(Models::Contributory(*it)).setId(idContributory);
}*/
/*for(Contributory &c: *getAllContributories()) {
c.setId(idContributory);
}*/

/*for (auto it = cbegin(); it != cend(); ++it) {
for(Contributory c : it.value()) {
c.setId(idContributory);
}
}
for(Contributory &c: *getAllContributories()) {
qDebug() << "setAllIdContributories: "<< c.getId();
}*/

for(QPair<Project*, Models::Rate>* pair : keys()) {
for (Contributory &c : (*this)[pair])
c.setId(idContributory);
}

for(Contributory &c: *getAllContributories()) {
qDebug() << "setAllIdContributories 2 : "<< c.getId();
}
}

bool ContributoriesList::getInsert() const
{
return _insert;
Expand Down
6 changes: 6 additions & 0 deletions src/models/contributorieslist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class ContributoriesList : private QMap<QPair<Project*,Models::Rate>*,QList<Cont
QList<Contributory> &getContributories(Project* p);
int getIdBilling() const;
void setIdBilling(int getIdBilling);
/**
* @brief ContributoriesList::setAllIdContributories Change all
* Contributory id with the same id
* @param idContributory the new Contributory id
*/
void setAllIdContributories(int idContributory);

bool getInsert() const;
void setInsert(bool getInsert);
Expand Down

0 comments on commit 27e3fa4

Please sign in to comment.