Update account amounts on account modification/add/deletion. Before it was only on generate new months and update next months

This commit is contained in:
Grégory Soutadé 2017-10-29 18:21:54 +01:00 committed by Grégory Soutadé
parent 6efa5183ab
commit b1ce5fc2a2

View File

@ -110,6 +110,11 @@ int KissCount::CalcAccountAmount(int id, int month, int year, bool* had_values)
void KissCount::UpdateOperation(Operation& op, bool checkTransfert)
{
Operation oldOp;
int accountAmount;
if(!op.meta)
// Unlink
if (checkTransfert)
{
@ -122,26 +127,59 @@ void KissCount::UpdateOperation(Operation& op, bool checkTransfert)
// Link
if (checkTransfert)
_user->LinkOrUnlinkOperation(op);
if(!op.meta)
{
_db->GetOperation(op.id, &oldOp);
accountAmount = _db->CalcAccountAmount(oldOp.account, oldOp.month, oldOp.year, 0);
_db->SetAccountAmount(oldOp.account, oldOp.month, oldOp.year, accountAmount);
accountAmount = _db->CalcAccountAmount(op.account, op.month, op.year, 0);
_db->SetAccountAmount(op.account, op.month, op.year, accountAmount);
}
_wxUI->NeedReload();
}
int KissCount::AddOperation(Operation& op, bool checkTransfert)
{
int accountAmount;
int ret = _db->AddOperation(_user, op, checkTransfert);
if (checkTransfert && op.transfert)
_user->LinkOrUnlinkOperation(op);
if (!op.meta)
{
accountAmount = _db->CalcAccountAmount(op.account, op.month, op.year, 0);
_db->SetAccountAmount(op.account, op.month, op.year, accountAmount);
}
_wxUI->NeedReload();
return ret;
}
void KissCount::DeleteOperation(Operation& op)
{
int accountAmount;
if (op.transfert)
{
op.transfert = 0;
_user->LinkOrUnlinkOperation(op);
}
_db->DeleteOperation(_user, op);
if (!op.meta)
{
accountAmount = _db->CalcAccountAmount(op.account, op.month, op.year, 0);
_db->SetAccountAmount(op.account, op.month, op.year, accountAmount);
}
_wxUI->NeedReload();
}
void KissCount::DeleteOperations(int month, int year)
@ -155,6 +193,7 @@ void KissCount::DeleteOperations(int month, int year)
delete _user->_operations[year];
_user->_operations.erase(year);
}
_wxUI->NeedReload();
}
int KissCount::MetaAmount(int id)