Skip to content
Snippets Groups Projects
Unverified Commit 5f38b579 authored by youngcw's avatar youngcw Committed by GitHub
Browse files

Template: Apply schedule template only on needed month (#1052)

Add option to schedule templates to budget the full amount only in the
needed month. Default behavior stays the same of spreading the expense
out over the available range.

To use the option, use a template like `#template schedule full
SCHEDULE_NAME`


Also some minor cleanup.
parent 1e2bc29a
No related branches found
No related tags found
No related merge requests found
// https://peggyjs.org
expr expr
= priority: priority? _? percent: percent _ of _ category: name = priority: priority? percent: percent _ of _ category: name
{ return { type: 'percentage', percent: +percent, category, priority: +priority }} { return { type: 'percentage', percent: +percent, category, priority: +priority }}
/ priority: priority? _? amount: amount _ repeatEvery _ weeks: weekCount _ starting _ starting: date limit: limit? / priority: priority? amount: amount _ repeatEvery _ weeks: weekCount _ starting _ starting: date limit: limit?
{ return { type: 'week', amount, weeks, starting, limit, priority: +priority }} { return { type: 'week', amount, weeks, starting, limit, priority: +priority }}
/ priority: priority? _? amount: amount _ by _ month: month from: spendFrom? repeat: (_ repeatEvery _ repeat)? / priority: priority? amount: amount _ by _ month: month from: spendFrom? repeat: (_ repeatEvery _ repeat)?
{ return { { return {
type: from ? 'spend' : 'by', type: from ? 'spend' : 'by',
amount, amount,
...@@ -14,12 +12,13 @@ expr ...@@ -14,12 +12,13 @@ expr
from, from,
priority: +priority priority: +priority
} } } }
/ priority: priority? _? monthly: amount limit: limit? / priority: priority? monthly: amount limit: limit?
{ return { type: 'simple', monthly, limit, priority: +priority } } { return { type: 'simple', monthly, limit, priority: +priority } }
/ priority: priority? _? limit: limit / priority: priority? limit: limit
{ return { type: 'simple', limit , priority: +priority } } { return { type: 'simple', limit , priority: +priority } }
/ priority: priority? _? schedule _ name: name / priority: priority? schedule _ full:full? name: name
{ return { type: 'schedule', name, priority: +priority } } { return { type: 'schedule', name, priority: +priority, full } }
repeat 'repeat interval' repeat 'repeat interval'
= 'month'i { return { annual: false } } = 'month'i { return { annual: false } }
...@@ -28,7 +27,7 @@ repeat 'repeat interval' ...@@ -28,7 +27,7 @@ repeat 'repeat interval'
/ years: d _ 'years'i { return { annual: true, repeat: +years } } / years: d _ 'years'i { return { annual: true, repeat: +years } }
limit = _? upTo _ amount: amount _ 'hold'i { return {amount: amount, hold: true } } limit = _? upTo _ amount: amount _ 'hold'i { return {amount: amount, hold: true } }
/ _? upTo _ amount: amount { return {amount: amount, hold: false } } / _? upTo _ amount: amount { return {amount: amount, hold: false } }
weekCount weekCount
...@@ -45,6 +44,7 @@ repeatEvery = 'repeat'i _ 'every'i ...@@ -45,6 +44,7 @@ repeatEvery = 'repeat'i _ 'every'i
starting = 'starting'i starting = 'starting'i
upTo = 'up'i _ 'to'i upTo = 'up'i _ 'to'i
schedule = 'schedule'i schedule = 'schedule'i
full = 'full'i _ {return true}
priority = '-'i number: number _ {return number} priority = '-'i number: number _ {return number}
_ 'space' = ' '+ _ 'space' = ' '+
...@@ -59,3 +59,4 @@ date = $(month '-' day) ...@@ -59,3 +59,4 @@ date = $(month '-' day)
currencySymbol 'currency symbol' = symbol: . & { return /\p{Sc}/u.test(symbol) } currencySymbol 'currency symbol' = symbol: . & { return /\p{Sc}/u.test(symbol) }
name 'Name' = $([^\r\n\t]+) name 'Name' = $([^\r\n\t]+)
...@@ -489,9 +489,6 @@ async function applyCategoryTemplate( ...@@ -489,9 +489,6 @@ async function applyCategoryTemplate(
} }
break; break;
} }
case 'error':
return { errors };
default:
case 'schedule': { case 'schedule': {
let { id: schedule_id } = await db.first( let { id: schedule_id } = await db.first(
'SELECT id FROM schedules WHERE name = ?', 'SELECT id FROM schedules WHERE name = ?',
...@@ -506,6 +503,14 @@ async function applyCategoryTemplate( ...@@ -506,6 +503,14 @@ async function applyCategoryTemplate(
new Date(next_date_string), new Date(next_date_string),
current_month, current_month,
); );
if (template.full === true) {
if (num_months === 1) {
to_budget = -getScheduledAmount(amountCond.value);
}
break;
}
if (l === 0) remainder = last_month_balance; if (l === 0) remainder = last_month_balance;
remainder = -getScheduledAmount(amountCond.value) - remainder; remainder = -getScheduledAmount(amountCond.value) - remainder;
let target = 0; let target = 0;
...@@ -537,6 +542,9 @@ async function applyCategoryTemplate( ...@@ -537,6 +542,9 @@ async function applyCategoryTemplate(
} }
break; break;
} }
case 'error':
return { errors };
default:
} }
} }
......
---
category: Enhancements
authors: [youngcw]
---
Templates: Add option to only apply schedule template to the month of the schedule instead of spreading out the charge.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment