From 9022b58dc78f4da600f5cb1250e4d12b6afd66bb Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 6 May 2026 11:09:42 +0200 Subject: [PATCH] Refactor revenue and tax handling in DirectorWorker: Updated logic to separately account for gross revenue and tax deductions during product sales. Enhanced monetary transactions to ensure accurate tax income distribution, particularly when the seller differs from the treasury user, improving financial tracking and compliance. --- src/worker/director.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/worker/director.rs b/src/worker/director.rs index a63ac60..9cc3d88 100644 --- a/src/worker/director.rs +++ b/src/worker/director.rs @@ -802,15 +802,28 @@ impl DirectorWorker { total_payout = (total_payout * 100.0).round() / 100.0; total_tax = (total_tax * 100.0).round() / 100.0; + // Für eine nachvollziehbare History buchen wir Brutto-Verkauf und Steuer getrennt: + // - Spieler: +Bruttoerlös, dann -Steuer + // - Treasury: +Steuer (nur wenn anderer User als Verkäufer) + let total_revenue = ((total_payout + total_tax) * 100.0).round() / 100.0; + if total_revenue != 0.0 { + let _ = self + .base + .change_falukant_user_money(falukant_user_id, total_revenue, "sell products"); + } if total_tax > 0.0 { let _ = self.base.change_falukant_user_money( - DEFAULT_TREASURY_USER_ID, - total_tax, + falukant_user_id, + -total_tax, &format!("tax from sales branch {}", director.branch_id), ); - } - if total_payout != 0.0 { - let _ = self.base.change_falukant_user_money(falukant_user_id, total_payout, "sell products"); + if DEFAULT_TREASURY_USER_ID != falukant_user_id { + let _ = self.base.change_falukant_user_money( + DEFAULT_TREASURY_USER_ID, + total_tax, + &format!("tax income from sales branch {}", director.branch_id), + ); + } } if sold_any { let message = format!(