Skip to content

Commit

Permalink
feat: [#194] Sponsored reductions (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
ursjoss authored May 4, 2024
1 parent 87a923f commit 5ec289b
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 93 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ The columns of the resulting summary file are defined as follows:
- `Net MiTi (LoLa)`: Net total income Mittagstisch with LoLa items w/o commission [`Gross MiTi (LoLa)` - `LoLa_Commission_MiTi`]
- `Contribution MiTi`: Share MiTi from selling LoLa items [20% * `Net MiTi (LoLa)`]
- `Net MiTi (LoLA) - Share LoLa`: 80% of Net total income Mittagstisch with LoLa items w/o commission [`Net MiTi (LoLa)` * 0.8]
- `Debt to MiTi`: Net amount LoLa needs to pay out to Mittagstisch [`Net Payment SumUp MiTi` - `Net MiTi (LoLA) - Share LoLa`]
- `Sponsored Reductions`: Reductions sponsored by LoLa [2 * (`MealCount_Reduced` + `MealCount_Regular`)]
- `Debt to MiTi`: Net amount LoLa needs to pay out to Mittagstisch [`Net Payment SumUp MiTi` - `Net MiTi (LoLA) - Share LoLa` + `Sponsored Reductions`]
- `Income LoLa MiTi`: Income LoLa from MiTi selling LoLa [`Gross MiTi (LoLa)` - `Contribution MiTi`]
- Statistics relevant for Mittagstisch:
- `MealCount_Regular`: Number of regular meals per day
- `MealCount_Reduced`: Number of meals with reductions sponsored by LoLa per day
- `MealCount_Regular`: Number of meals for stagaire sponsored by LoLA per day
- `MealCount_Children`: Number of children meals per day

### Mittagstisch Report
Expand All @@ -231,6 +234,7 @@ The columns of the resulting file are defined as follows:
- `Datum`: [`Date`]
- Count of Menus
- `Hauptgang`: Number of regular meals per day [`MealCount_Regular`]
- `Reduziert`: Number of regular meals per day [`MealCount_Reduced` + `MealCount_Praktikum`]
- `Kind`: Number of children meals per day [`MealCount_Children`]
- Income by ownership (MiTi or LoLa):
- `Küche`: Gross income from menus [`Gross MiTi (MiTi)`]
Expand All @@ -252,6 +256,7 @@ The columns of the resulting file are defined as follows:
- Netting with LoLa
- `Net Total Karte`: Net card payments concerning Mittagstisch (Sales from meals, tips, sales of LoLa goods paid via card) [`Net Paymnet SumUp MiTi`]
- `Verkauf LoLa (80%)` 80% of net sales lola goods [-`Net MiTi (LoLA) - Share LoLa`]
- `Gesponsort` LoLa sponsored reductions (2.00 per Meal) [`Sponsored Reductions`]
- `Überweisung`: Net Payment LoLa to Mittagstisch [`Debt to MiTi`]

### Accounting Report
Expand Down Expand Up @@ -282,6 +287,7 @@ The columns of the resulting accounting.csv file are defined as follows:
- `10920/20051`: Net Card income + tips (card) Mittagstisch [`Net Card MiTi` + `MiTi_Tips_Card`]
- `10920/10910`: Tips LoLa paid via Card [`Tips_Card` - `MiTi_Tips_Card`]
- `68450/10920`: Commission for Café, Vermietung, summer party, Deposit, Rental, Cultural Payments, and `PaidOut`, i.e. w/o Mittagstisch [`Commission LoLa`]
- `59991/20051`: LoLa sponsored reductions (`Sponsored Reductions`)
- `20051/10930`: Amount LoLa owes to Mittagstisch (`Debt to MiTi`)
- `20051/30500`: Income LoLa from MiTi selling LoLa [`Gross MiTi (LoLa)` - `Contribution MiTi` = `Income LoLa MiTi`]

Expand All @@ -295,4 +301,4 @@ They serve for consolidation purposes:

Where the absolute net sum for the transitory accounts must not be > 0.05, i.e.:
- for `10920`: abs(`10920/30200` + `10920/30700` + `10920/30800` + `10920/23050` + `10920/46000` + `10920/31000` + `10920/32000` +`10920/20051` + `10920/10000` + `10920/10910` - `Payment SumUp` - `68450/10920`) < 0.05
- for `20051`: abs(`10920/20051` - `20051/10930` - `20051/30200`) < 0.05
- for `20051`: abs(`10920/20051` - `20051/10930` - `20051/30200` + `59991/20051`) < 0.05
89 changes: 54 additions & 35 deletions src/export/export_accounting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn gather_df_accounting(df: &DataFrame) -> PolarsResult<DataFrame> {
col("Net Card Total MiTi").alias("10920/20051"),
col("Tips Card LoLa").alias("10920/10910"),
col("LoLa_Commission").alias("68450/10920"),
col("Sponsored Reductions").alias("59991/20051"),
col("Debt to MiTi").alias("20051/10930"),
col("Income LoLa MiTi").alias("20051/30500"),
])
Expand Down Expand Up @@ -87,7 +88,8 @@ fn validate_acc_constraint_10920(df_acc: &DataFrame) -> Result<(), Box<dyn Error

/// validates the transitory account 10920 nets to 0
fn validate_acc_constraint_20051(df_acc: &DataFrame) -> Result<(), Box<dyn Error>> {
let net_expr = col("10920/20051") - col("20051/10930") - col("20051/30500");
let net_expr =
col("10920/20051") - col("20051/10930") - col("20051/30500") + col("59991/20051");
validate_constraint(df_acc, net_expr, "20051")?
}

Expand Down Expand Up @@ -134,80 +136,80 @@ mod tests {
// fully valid case
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
// still valid, as we accept a deviation of 0.05/-0.05
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 19.98, 12.0, 20.0, 10.0,
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.02, 12.0, 20.0, 10.0,
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.01, 20.0, 10.0,
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 11.99, 20.0, 10.0,
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.01, 10.0,
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 19.99, 10.0,
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.01,
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 9.99, 100.0,
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0,
100.01, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
100.01, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 99.99,
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
500.01, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
500.01, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
499.99, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
499.99, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
500.0, 400.01, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
500.0, 400.01, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
500.0, 399.99, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
500.0, 399.99, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
500.0, 400.0, 100.01, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
500.0, 400.0, 100.01, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
500.0, 400.0, 99.99, 189.25, 1.0, 17.99, 146.76, 42.49, None, ""
500.0, 400.0, 99.99, 189.25, 1.0, 17.99, 2.00, 148.76, 42.49, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.48, None, ""
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.48, None, ""
)]
#[case(
1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0,
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.50, None, ""
500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 2.00, 148.76, 42.50, None, ""
)]
// violations of account 10920
#[case(
Expand All @@ -232,7 +234,8 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(0.1),
"10920"
Expand All @@ -259,7 +262,8 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(0.1),
"10920"
Expand All @@ -286,7 +290,8 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(0.1),
"10920"
Expand All @@ -313,7 +318,8 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(0.1),
"10920"
Expand All @@ -340,7 +346,8 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(0.1),
"10920"
Expand All @@ -367,7 +374,8 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(0.1),
"10920"
Expand All @@ -394,7 +402,8 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(0.1),
"10920"
Expand All @@ -421,13 +430,16 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(0.1),
"10920"
)]
#[case(1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0, 500.0, 400.0, 100.0, 188.15, 1.0, 17.99, 146.76, 42.49, Some(-1.1), "10920")]
#[case(1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0, 500.0, 400.0, 100.0, 189.25, 0.5, 17.99, 146.76, 42.49, Some(-0.5), "10920")]
#[case(1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0, 500.0, 400.0, 100.0, 188.15, 1.0, 17.99,
2.0, 148.76, 42.49, Some(-1.1), "10920")]
#[case(1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0, 500.0, 400.0, 100.0, 189.25, 0.5, 17.99,
2.0, 148.76, 42.49, Some(-0.5), "10920")]
#[case(
1234.06,
552.0,
Expand All @@ -450,12 +462,14 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.49,
Some(100.2),
"10920"
)]
#[case(1343.36, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.49, Some(-9.1), "10920")]
#[case(1343.36, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99,
2.0, 148.76, 42.49, Some(-9.1), "10920")]
// violations of account 20051
#[case(
1334.26,
Expand All @@ -479,7 +493,8 @@ mod tests {
189.25,
1.0,
17.99,
146.70,
2.0,
148.70,
42.49,
Some(0.06),
"20051"
Expand All @@ -506,12 +521,14 @@ mod tests {
189.25,
1.0,
17.99,
146.76,
2.0,
148.76,
42.43,
Some(0.06),
"20051"
)]
#[case(1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99, 146.76, 42.55, Some(-0.06), "20051")]
#[case(1334.26, 552.0, 1162.0, 0.0, 0.0, 10.0, 20.0, 0.0, 0.0, 0.0, 20.0, 12.0, 20.0, 10.0, 100.0, 500.0, 400.0, 100.0, 189.25, 1.0, 17.99,
2.0, 148.76, 42.55, Some(-0.06), "20051")]
fn test_violations(
#[case] payment_sumup: f64,
#[case] total_cash_debit: f64,
Expand All @@ -534,6 +551,7 @@ mod tests {
#[case] net_card_income_plus_tips_miti_card: f64,
#[case] tips_lola_paid_via_card: f64,
#[case] commission_lola: f64,
#[case] sponsored_reductions: f64,
#[case] debt_to_miti: f64,
#[case] income_lola_miti: f64,
#[case] delta: Option<f64>,
Expand Down Expand Up @@ -563,6 +581,7 @@ mod tests {
"10920/20051" => &[net_card_income_plus_tips_miti_card],
"10920/10910" => &[tips_lola_paid_via_card],
"68450/10920" => &[Some(commission_lola)],
"59991/20051" => &[sponsored_reductions],
"20051/10930" => &[debt_to_miti],
"20051/30500" => &[income_lola_miti],
)?;
Expand Down
6 changes: 6 additions & 0 deletions src/export/export_miti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use polars::prelude::*;
pub fn gather_df_miti(df: &DataFrame) -> PolarsResult<DataFrame> {
df.clone()
.lazy()
.with_column(
(col("MealCount_Reduced").fill_null(0) + col("MealCount_Praktikum").fill_null(0))
.alias("MealCount_ReducedPraktikum"),
)
.with_column(
(col("MiTi_Cash").fill_null(0.0) + col("MiTi_Tips_Cash").fill_null(0.0))
.round(2)
Expand Down Expand Up @@ -47,6 +51,7 @@ pub fn gather_df_miti(df: &DataFrame) -> PolarsResult<DataFrame> {
.select([
col("Date").alias("Datum"),
col("MealCount_Regular").alias("Hauptgang"),
col("MealCount_ReducedPraktikum").alias("Reduziert"),
col("MealCount_Children").alias("Kind"),
col("Gross MiTi (MiTi)").alias("Küche"),
col("Gross MiTi (LoLa)").alias("Total Bar"),
Expand All @@ -64,6 +69,7 @@ pub fn gather_df_miti(df: &DataFrame) -> PolarsResult<DataFrame> {
col("Net MiTi (MiTi) Card").alias("Netto Karte MiTi"),
col("Net Payment SumUp MiTi").alias("Net Total Karte"),
col("Verkauf LoLa (80%)"),
col("Sponsored Reductions").alias("Gesponsort"),
col("Debt to MiTi").alias("Überweisung"),
])
.collect()
Expand Down
Loading

0 comments on commit 5ec289b

Please sign in to comment.