Refactor production cost calculation in DirectorWorker: Updated the cost formula to depend on product category rather than certificate level, introducing a base cost and headroom discount mechanism. Modified SQL queries to retrieve product category and user certificate for accurate cost assessment. Enhanced documentation for clarity on the new cost structure and its implications for production management.

This commit is contained in:
Torsten Schulz (local)
2026-03-25 12:16:52 +01:00
parent 65772fb7de
commit 3289a0c129
3 changed files with 78 additions and 36 deletions

View File

@@ -48,11 +48,22 @@ INSERT INTO falukant_log.notification (user_id, tr, shown, created_at, updated_a
VALUES ($1, $2, FALSE, NOW(), NOW());
"#;
// Product pricing
// Product pricing (nur sell_cost; für Produktions-Stückkosten siehe QUERY_GET_PRODUCT_CATEGORY_AND_USER_CERTIFICATE)
#[allow(dead_code)]
pub const QUERY_GET_PRODUCT_COST: &str = r#"
SELECT sell_cost FROM falukant_type.product WHERE id = $1;
"#;
/// Produktklasse + Spieler-Zertifikat für Stückkosten (kein „teurer wegen höherem Zertifikat“).
pub const QUERY_GET_PRODUCT_CATEGORY_AND_USER_CERTIFICATE: &str = r#"
SELECT COALESCE(p.category, 1)::int AS category,
COALESCE(u.certificate, 1)::int AS certificate
FROM falukant_type.product p
CROSS JOIN falukant_data.falukant_user u
WHERE p.id = $1::int
AND u.id = $2::int;
"#;
pub const QUERY_GET_DIRECTORS: &str = r#"
SELECT d.may_produce, d.may_sell, d.may_start_transport, b.id AS branch_id, fu.id AS falukantUserId, d.id
FROM falukant_data.director d
@@ -63,7 +74,8 @@ WHERE current_time BETWEEN '08:00:00' AND '17:00:00';
"#;
pub const QUERY_GET_BEST_PRODUCTION: &str = r#"
SELECT fdu.id falukant_user_id, CAST(fdu.money AS text) AS money, fdu.certificate, ftp.id product_id, ftp.label_tr, fdb.region_id,
SELECT fdu.id falukant_user_id, CAST(fdu.money AS text) AS money, fdu.certificate, ftp.id product_id, ftp.label_tr,
COALESCE(ftp.category, 1)::int AS product_category, fdb.region_id,
(SELECT SUM(quantity) FROM falukant_data.stock fds WHERE fds.branch_id = fdb.id) AS stock_size,
COALESCE((SELECT SUM(COALESCE(fdi.quantity, 0)) FROM falukant_data.stock fds JOIN falukant_data.inventory fdi ON fdi.stock_id = fds.id WHERE fds.branch_id = fdb.id), 0) AS used_in_stock,
(ftp.sell_cost * (fdtpw.worth_percent + (fdk_character.knowledge * 2 + fdk_director.knowledge) / 3) / 100 - 6 * ftp.category) / (300.0 * ftp.production_time) AS worth,