Skip to content

Commit

Permalink
fix(moneymanagerex#6827): encapsulate auto execute values (moneymanag…
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeef authored Aug 22, 2024
1 parent a4c1295 commit 1472ec1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 92 deletions.
47 changes: 21 additions & 26 deletions src/billsdepositsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,39 +232,37 @@ void mmBDDialog::dataToControls()
field_date.ParseDate(m_bill_data.NEXTOCCURRENCEDATE);
m_date_due->SetValue(field_date);

// Have used repeatSel to multiplex auto repeat fields.
if (m_bill_data.REPEATS >= 2 * BD_REPEATS_MULTIPLEX_BASE)
autoExecuteSilent_ = true;
else if (m_bill_data.REPEATS >= BD_REPEATS_MULTIPLEX_BASE)
autoExecuteUserAck_ = true;
m_bill_data.REPEATS %= BD_REPEATS_MULTIPLEX_BASE;
// demultiplex m_bill_data.REPEATS
int autoExecute = m_bill_data.REPEATS / BD_REPEATS_MULTIPLEX_BASE;
int repeats = m_bill_data.REPEATS % BD_REPEATS_MULTIPLEX_BASE;

// fix m_bill_data.REPEATS
if (m_bill_data.REPEATS < Model_Billsdeposits::REPEAT_ONCE || m_bill_data.REPEATS > Model_Billsdeposits::REPEAT_MONTHLY_LAST_BUSINESS_DAY)
// fix repeats
if (repeats < Model_Billsdeposits::REPEAT_ONCE || repeats > Model_Billsdeposits::REPEAT_MONTHLY_LAST_BUSINESS_DAY)
{
wxFAIL;
m_bill_data.REPEATS = Model_Billsdeposits::REPEAT_MONTHLY;
repeats = Model_Billsdeposits::REPEAT_MONTHLY;
}
if (m_bill_data.REPEATS >= Model_Billsdeposits::REPEAT_IN_X_DAYS && m_bill_data.REPEATS <= Model_Billsdeposits::REPEAT_EVERY_X_MONTHS && m_bill_data.NUMOCCURRENCES < 1)
if (repeats >= Model_Billsdeposits::REPEAT_IN_X_DAYS && repeats <= Model_Billsdeposits::REPEAT_EVERY_X_MONTHS && m_bill_data.NUMOCCURRENCES < 1)
{
// old inactive entry. transform to REPEAT_ONCE and turn off automatic execution.
m_bill_data.REPEATS = Model_Billsdeposits::REPEAT_ONCE;
autoExecuteSilent_ = false;
autoExecuteUserAck_ = false;
repeats = Model_Billsdeposits::REPEAT_ONCE;
autoExecute = Model_Billsdeposits::REPEAT_AUTO_NONE;
}
setRepeatType(m_bill_data.REPEATS);
setRepeatType(repeats);

if (m_bill_data.REPEATS != Model_Billsdeposits::REPEAT_ONCE && m_bill_data.NUMOCCURRENCES > 0) {
if (repeats != Model_Billsdeposits::REPEAT_ONCE && m_bill_data.NUMOCCURRENCES > 0) {
textNumRepeats_->SetValue(wxString::Format("%d", m_bill_data.NUMOCCURRENCES));
}

if (autoExecuteSilent_)
if (autoExecute == Model_Billsdeposits::REPEAT_AUTO_SILENT)
{
autoExecuteSilent_ = true;
itemCheckBoxAutoExeSilent_->SetValue(true);
itemCheckBoxAutoExeUserAck_->Enable(false);
}
else if (autoExecuteUserAck_)
else if (autoExecute == Model_Billsdeposits::REPEAT_AUTO_MANUAL)
{
autoExecuteUserAck_ = true;
itemCheckBoxAutoExeUserAck_->SetValue(true);
itemCheckBoxAutoExeSilent_->Enable(false);
}
Expand Down Expand Up @@ -1006,16 +1004,13 @@ void mmBDDialog::OnOk(wxCommandEvent& WXUNUSED(event))
}
}

// store repeats (it is used again later)
int autoExecute =
autoExecuteSilent_ ? Model_Billsdeposits::REPEAT_AUTO_SILENT :
autoExecuteUserAck_ ? Model_Billsdeposits::REPEAT_AUTO_MANUAL :
Model_Billsdeposits::REPEAT_AUTO_NONE;
int repeats = getRepeatType();
// Multiplex Auto executable onto the repeat field of the database.
m_bill_data.REPEATS = repeats;
if (autoExecuteUserAck_) {
m_bill_data.REPEATS += BD_REPEATS_MULTIPLEX_BASE;
}
else if (autoExecuteSilent_) {
m_bill_data.REPEATS += 2 * BD_REPEATS_MULTIPLEX_BASE;
}
// multiplex autoExecute and repeats
m_bill_data.REPEATS = autoExecute * BD_REPEATS_MULTIPLEX_BASE + repeats;

const wxString& numRepeatStr = textNumRepeats_->GetValue();
m_bill_data.NUMOCCURRENCES = -1;
Expand Down
89 changes: 26 additions & 63 deletions src/billsdepositspanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,11 @@ wxString mmBillsDepositsPanel::getItem(long item, long column)
}
case COL_AUTO:
{
int repeats = bill.REPEATS;
wxString repeatSTR = _("Manual");
if (repeats >= 2 * BD_REPEATS_MULTIPLEX_BASE)
{
repeatSTR = _("Automated");
}
else if (repeats >= BD_REPEATS_MULTIPLEX_BASE)
{
repeatSTR = _("Suggested");
}

int autoExecute = bill.REPEATS / BD_REPEATS_MULTIPLEX_BASE;
wxString repeatSTR =
(autoExecute == Model_Billsdeposits::REPEAT_AUTO_SILENT) ? _("Automated") :
(autoExecute == Model_Billsdeposits::REPEAT_AUTO_MANUAL) ? _("Suggested") :
_("Manual");
return repeatSTR;
}
case COL_DAYS:
Expand All @@ -527,7 +521,7 @@ const wxString mmBillsDepositsPanel::GetFrequency(const Model_Billsdeposits::Dat
int repeats = item->REPEATS % BD_REPEATS_MULTIPLEX_BASE; // DeMultiplex the Auto Executable fields.

wxString text = wxGetTranslation(BILLSDEPOSITS_REPEATS[repeats]);
if (repeats > 10 && repeats < 15)
if (repeats >= Model_Billsdeposits::REPEAT_IN_X_DAYS && repeats <= Model_Billsdeposits::REPEAT_EVERY_X_MONTHS)
text = wxString::Format(text, wxString::Format("%d", item->NUMOCCURRENCES));
return text;
}
Expand Down Expand Up @@ -555,32 +549,20 @@ const int mmBillsDepositsPanel::GetNumRepeats(const Model_Billsdeposits::Data* i
const wxString mmBillsDepositsPanel::GetRemainingDays(const Model_Billsdeposits::Data* item) const
{
int repeats = item->REPEATS % BD_REPEATS_MULTIPLEX_BASE; // DeMultiplex the Auto Executable fields.
if (repeats >= Model_Billsdeposits::REPEAT_IN_X_DAYS && repeats <= Model_Billsdeposits::REPEAT_EVERY_X_MONTHS && item->NUMOCCURRENCES < 0)
{
return _("Inactive");
}

int daysRemaining = Model_Billsdeposits::TRANSDATE(item)
.Subtract(this->getToday()).GetSeconds().GetValue() / 86400;
int daysOverdue = Model_Billsdeposits::NEXTOCCURRENCEDATE(item)
.Subtract(this->getToday()).GetSeconds().GetValue() / 86400;
wxString text = wxString::Format(wxPLURAL("%d day remaining", "%d days remaining", daysRemaining), daysRemaining);

if (daysRemaining == 0)
{
if (((repeats > 10) && (repeats < 15)) && (item->NUMOCCURRENCES < 0))
text = _("Inactive");
}

if (daysRemaining < 0)
{
text = wxString::Format(wxPLURAL("%d day delay!", "%d days delay!", -daysRemaining), -daysRemaining);
if (((repeats > 10) && (repeats < 15)) && (item->NUMOCCURRENCES < 0))
text = _("Inactive");
}

if (daysOverdue < 0)
{
text = wxString::Format(wxPLURAL("%d day overdue!", "%d days overdue!", -daysOverdue), -daysOverdue);
if (((repeats > 10) && (repeats < 15)) && (item->NUMOCCURRENCES < 0))
text = _("Inactive");
}
wxString text =
(daysOverdue < 0) ? wxString::Format(wxPLURAL("%d day overdue!", "%d days overdue!", -daysOverdue), -daysOverdue) :
(daysRemaining < 0) ? wxString::Format(wxPLURAL("%d day delay!", "%d days delay!", -daysRemaining), -daysRemaining) :
wxString::Format(wxPLURAL("%d day remaining", "%d days remaining", daysRemaining), daysRemaining);

return text;
}
Expand Down Expand Up @@ -610,44 +592,25 @@ void billsDepositsListCtrl::OnListLeftClick(wxMouseEvent& event)

int billsDepositsListCtrl::OnGetItemImage(long item) const
{
bool bd_repeat_user = false;
bool bd_repeat_auto = false;
int repeats = m_bdp->bills_[item].REPEATS;
// DeMultiplex the Auto Executable fields.
if (repeats >= 2 * BD_REPEATS_MULTIPLEX_BASE) // Auto Execute Silent mode
{
bd_repeat_auto = true;
}
else if (repeats >= BD_REPEATS_MULTIPLEX_BASE) // Auto Execute User Acknowlegement required
// demultiplex REPEATS
int autoExecute = m_bdp->bills_[item].REPEATS / BD_REPEATS_MULTIPLEX_BASE;
int repeats = m_bdp->bills_[item].REPEATS % BD_REPEATS_MULTIPLEX_BASE;
if (repeats >= Model_Billsdeposits::REPEAT_IN_X_DAYS && repeats <= Model_Billsdeposits::REPEAT_EVERY_X_MONTHS && m_bdp->bills_[item].NUMOCCURRENCES < 0)
{
bd_repeat_user = true;
// inactive
return -1;
}

repeats %= BD_REPEATS_MULTIPLEX_BASE;

int daysRemaining = Model_Billsdeposits::NEXTOCCURRENCEDATE(m_bdp->bills_[item])
.Subtract(m_bdp->getToday()).GetSeconds().GetValue() / 86400;
wxString daysRemainingStr = wxString::Format(wxPLURAL("%d day remaining", "%d days remaining", daysRemaining), daysRemaining);

if (daysRemaining == 0)
{
if (((repeats > 10) && (repeats < 15)) && (m_bdp->bills_[item].NUMOCCURRENCES < 0))
daysRemainingStr = _("Inactive");
}

if (daysRemaining < 0)
{
daysRemainingStr = wxString::Format(wxPLURAL("%d day overdue!", "%d days overdue!", std::abs(daysRemaining)), std::abs(daysRemaining));
if (((repeats > 10) && (repeats < 15)) && (m_bdp->bills_[item].NUMOCCURRENCES < 0))
daysRemainingStr = _("Inactive");
}

/* Returns the icon to be shown for each entry */
if (daysRemainingStr == _("Inactive")) return -1;
if (daysRemaining < 0) return mmBillsDepositsPanel::ICON_FOLLOWUP;
if (bd_repeat_auto) return mmBillsDepositsPanel::ICON_RUN_AUTO;
if (bd_repeat_user) return mmBillsDepositsPanel::ICON_RUN;

if (daysRemaining < 0)
return mmBillsDepositsPanel::ICON_FOLLOWUP;
if (autoExecute == Model_Billsdeposits::REPEAT_AUTO_SILENT)
return mmBillsDepositsPanel::ICON_RUN_AUTO;
if (autoExecute == Model_Billsdeposits::REPEAT_AUTO_MANUAL)
return mmBillsDepositsPanel::ICON_RUN;
return -1;
}

Expand Down
6 changes: 3 additions & 3 deletions src/mmhomepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ const wxString htmlWidgetBillsAndDeposits::getHTMLText()

int repeats = entry.REPEATS % BD_REPEATS_MULTIPLEX_BASE; // DeMultiplex the Auto Executable fields

if (daysPayment == 0 && repeats > 10 && repeats < 15 && entry.NUMOCCURRENCES < 0) {
continue; // Inactive
}
// ignore inactive entries
if (repeats >= Model_Billsdeposits::REPEAT_IN_X_DAYS && repeats <= Model_Billsdeposits::REPEAT_EVERY_X_MONTHS && entry.NUMOCCURRENCES < 0)
continue;

int daysOverdue = Model_Billsdeposits::NEXTOCCURRENCEDATE(&entry)
.Subtract(today).GetDays();
Expand Down
4 changes: 4 additions & 0 deletions src/reports/cashflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ void mmReportCashFlow::getTransactions()
int repeatsType = entry.REPEATS % BD_REPEATS_MULTIPLEX_BASE; // DeMultiplex the Auto Executable fields from the db entry: REPEATS
int numRepeats = entry.NUMOCCURRENCES;

// ignore inactive entries
if (repeatsType >= Model_Billsdeposits::REPEAT_IN_X_DAYS && repeatsType <= Model_Billsdeposits::REPEAT_EVERY_X_MONTHS && numRepeats < 0)
continue;

bool processNumRepeats = numRepeats != -1 || repeatsType == 0;
if (repeatsType == 0)
{
Expand Down

0 comments on commit 1472ec1

Please sign in to comment.