[insight] Projects: spent by line and unplanned, income without VAT and never twice, profit and margin, progress, the forecast, late, time by task and week, billed and unbilled; Project on budget and Finished on time medals
This commit is contained in:
@@ -32,6 +32,10 @@ pub enum Medal {
|
||||
GoalMilestone { goal: String, name: String, permille: u32 },
|
||||
/// Money put aside in this many complete months running (3 or more), up to `until`'s month.
|
||||
SavingStreak { months: u32, until: Date },
|
||||
/// A project done within its budget (it had one).
|
||||
ProjectOnBudget { project: String, name: String },
|
||||
/// A project done by its end date (it had one).
|
||||
FinishedOnTime { project: String, name: String },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
|
||||
@@ -332,6 +336,20 @@ pub fn rewards(state: &State, insight: &Insight, shared: &BTreeSet<BudgetId>, to
|
||||
medals.push(Earned { medal: Medal::SavingStreak { months: n, until: last }, on: last.month_end() });
|
||||
}
|
||||
|
||||
// Projects done: within their budget, by their end date.
|
||||
let summaries = crate::projects::projects(state, today);
|
||||
for p in state.projects.projects.values().filter(|p| !p.is_open()) {
|
||||
let Some(on) = p.status_on else { continue };
|
||||
if let Some(s) = summaries.iter().find(|s| s.id == p.id) {
|
||||
if s.planned.0 > 0 && s.spent <= s.planned {
|
||||
medals.push(Earned { medal: Medal::ProjectOnBudget { project: p.id.clone(), name: p.name.clone() }, on });
|
||||
}
|
||||
}
|
||||
if p.ends.is_some_and(|e| on <= e) {
|
||||
medals.push(Earned { medal: Medal::FinishedOnTime { project: p.id.clone(), name: p.name.clone() }, on });
|
||||
}
|
||||
}
|
||||
|
||||
medals.sort_by_key(|m| std::cmp::Reverse(m.on));
|
||||
let month = today.month_start();
|
||||
Rewards {
|
||||
|
||||
Reference in New Issue
Block a user