Calculate remaning amounts
This commit is contained in:
parent
1f24117e96
commit
d0fcedee2a
1 changed files with 102 additions and 8 deletions
110
src/main.rs
110
src/main.rs
|
|
@ -13,7 +13,7 @@ use iced::{
|
||||||
button, column, component, horizontal_rule, horizontal_space, row, rule, scrollable, text,
|
button, column, component, horizontal_rule, horizontal_space, row, rule, scrollable, text,
|
||||||
text_input,
|
text_input,
|
||||||
},
|
},
|
||||||
window, Application, Command, Event, Length, Renderer, Settings, Theme,
|
window, Alignment, Application, Command, Event, Length, Renderer, Settings, Theme,
|
||||||
};
|
};
|
||||||
use iced_aw::{card, modal};
|
use iced_aw::{card, modal};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
@ -667,6 +667,103 @@ impl Application for Glaurung {
|
||||||
.values()
|
.values()
|
||||||
.chain(self.variable.values().flat_map(|(_, f)| f))
|
.chain(self.variable.values().flat_map(|(_, f)| f))
|
||||||
.sum::<f64>();
|
.sum::<f64>();
|
||||||
|
let total_earnings = self.earnings_1 + self.earnings_2;
|
||||||
|
|
||||||
|
let main_account = total_spendings;
|
||||||
|
let main_factor = main_account / total_earnings;
|
||||||
|
|
||||||
|
let mut remaining_1 = self.earnings_1;
|
||||||
|
let mut remaining_2 = self.earnings_2;
|
||||||
|
|
||||||
|
let mut same_percent = column![
|
||||||
|
text("Same percent").size(TEXT_H2),
|
||||||
|
text("Main account").size(TEXT_EMPH2),
|
||||||
|
text(format!(
|
||||||
|
"{}: {:.2} €",
|
||||||
|
self.config.person_1,
|
||||||
|
self.earnings_1 * main_factor
|
||||||
|
)),
|
||||||
|
text(format!(
|
||||||
|
"{}: {:.2} €",
|
||||||
|
self.config.person_2,
|
||||||
|
self.earnings_2 * main_factor
|
||||||
|
)),
|
||||||
|
];
|
||||||
|
|
||||||
|
remaining_1 -= self.earnings_1 * main_factor;
|
||||||
|
remaining_2 -= self.earnings_2 * main_factor;
|
||||||
|
|
||||||
|
let mut total_depositing = main_account;
|
||||||
|
|
||||||
|
for (account, amount) in &self.savings {
|
||||||
|
let factor = amount / total_earnings;
|
||||||
|
same_percent = same_percent
|
||||||
|
.push(text(account).size(TEXT_EMPH2))
|
||||||
|
.push(text(format!(
|
||||||
|
"{}: {:.2} €",
|
||||||
|
self.config.person_1,
|
||||||
|
self.earnings_1 * factor
|
||||||
|
)))
|
||||||
|
.push(text(format!(
|
||||||
|
"{}: {:.2} €",
|
||||||
|
self.config.person_2,
|
||||||
|
self.earnings_2 * factor
|
||||||
|
)));
|
||||||
|
|
||||||
|
remaining_1 -= self.earnings_1 * factor;
|
||||||
|
remaining_2 -= self.earnings_2 * factor;
|
||||||
|
total_depositing += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
let remaining_per_person = (total_earnings - total_depositing) / 2.;
|
||||||
|
|
||||||
|
let mut same_remaining = column![
|
||||||
|
text("Same remaining").size(TEXT_H2),
|
||||||
|
text("Main account").size(TEXT_EMPH2),
|
||||||
|
text(format!(
|
||||||
|
"{}: {:.2} €",
|
||||||
|
self.config.person_1,
|
||||||
|
self.earnings_1 - remaining_per_person
|
||||||
|
)),
|
||||||
|
text(format!(
|
||||||
|
"{}: {:.2} €",
|
||||||
|
self.config.person_2,
|
||||||
|
self.earnings_2 - remaining_per_person
|
||||||
|
)),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (account, amount) in &self.savings {
|
||||||
|
same_remaining = same_remaining
|
||||||
|
.push(text(account).size(TEXT_EMPH2))
|
||||||
|
.push(text(format!(
|
||||||
|
"{}: {:.2} €",
|
||||||
|
self.config.person_1,
|
||||||
|
amount / 2.,
|
||||||
|
)))
|
||||||
|
.push(text(format!(
|
||||||
|
"{}: {:.2} €",
|
||||||
|
self.config.person_2,
|
||||||
|
amount / 2.,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let per_person = row![
|
||||||
|
same_percent
|
||||||
|
.push(text("Remaining").size(TEXT_EMPH2))
|
||||||
|
.push(text(format!(
|
||||||
|
"{}: {remaining_1:.2} €",
|
||||||
|
self.config.person_1,
|
||||||
|
)))
|
||||||
|
.push(text(format!(
|
||||||
|
"{}: {remaining_2:.2} €",
|
||||||
|
self.config.person_2,
|
||||||
|
)),),
|
||||||
|
horizontal_space(Length::Fill),
|
||||||
|
same_remaining
|
||||||
|
.push(text("Remaining").size(TEXT_EMPH2))
|
||||||
|
.push(text(format!("{remaining_per_person:.2} € per person"))),
|
||||||
|
]
|
||||||
|
.align_items(Alignment::Start);
|
||||||
|
|
||||||
scrollable(
|
scrollable(
|
||||||
column![
|
column![
|
||||||
|
|
@ -710,21 +807,18 @@ impl Application for Glaurung {
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
.align_items(iced::Alignment::Center),
|
.align_items(iced::Alignment::Center),
|
||||||
text(&format!(
|
text(&format!("Total earnings: {total_earnings} €",)).size(TEXT_EMPH2),
|
||||||
"Total earnings: {} €",
|
|
||||||
self.earnings_1 + self.earnings_2,
|
|
||||||
))
|
|
||||||
.size(TEXT_EMPH2),
|
|
||||||
text("Outputs").size(TEXT_H1),
|
text("Outputs").size(TEXT_H1),
|
||||||
text(&format!("Main account: {total_spendings} €")).size(TEXT_EMPH2),
|
text(&format!("Main account: {main_account} €")).size(TEXT_EMPH2),
|
||||||
component(FixedAmounts {
|
component(FixedAmounts {
|
||||||
items: &self.savings,
|
items: &self.savings,
|
||||||
title: "Savings",
|
title: "Savings",
|
||||||
add_label: "Add a saving output",
|
add_label: "Add a saving output",
|
||||||
on_add: Message::AddSaving,
|
on_add: Message::AddSaving,
|
||||||
}),
|
}),
|
||||||
|
per_person,
|
||||||
]
|
]
|
||||||
.padding(5),
|
.padding(15),
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue