diff --git a/src/main.rs b/src/main.rs index 611b6b0..7328390 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::{ fs::{File, OpenOptions}, io::BufReader, num::NonZeroU8, - ops::{Mul, MulAssign, Sub, SubAssign}, + ops::{AddAssign, Mul, MulAssign, Sub, SubAssign}, path::PathBuf, }; @@ -11,7 +11,7 @@ use anyhow::anyhow; use calc::calc_parser; use compare::Compare; use directories::ProjectDirs; -use edit::{EditMessage, EditState, EditSaveFile}; +use edit::{EditMessage, EditSaveFile, EditState}; use either::Either; use iced::{ font, subscription, @@ -54,6 +54,13 @@ impl ContributionPoint { } } +impl AddAssign for ContributionPoint { + fn add_assign(&mut self, rhs: ContributionPoint) { + self.person_1 += rhs.person_1; + self.person_2 += rhs.person_2; + } +} + impl SubAssign for ContributionPoint { fn sub_assign(&mut self, rhs: ContributionPoint) { self.person_1 -= rhs.person_1; @@ -156,6 +163,10 @@ pub(crate) trait Spendings { remaining -= main; let mut total_depositing = main_account; + let mut total_savings = ContributionPoint { + person_1: 0., + person_2: 0., + }; let (savings_same_percent, saving_same_remaining) = self .savings() @@ -166,6 +177,12 @@ pub(crate) trait Spendings { total_depositing += amount; remaining -= contributions; + let savings = ContributionPoint { + person_1: amount / 2., + person_2: amount / 2., + }; + total_savings += savings; + ( (account.to_string(), contributions), ( @@ -192,7 +209,7 @@ pub(crate) trait Spendings { savings: savings_same_percent, }, same_remaining: Contribution { - main: self.earnings() - remaining_per_person, + main: self.earnings() - remaining_per_person - total_savings, remaining: remaining_per_person, savings: saving_same_remaining, },