From e1c1b2918fb27a798e8f50e89db72450ec5b37c8 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 28 Oct 2025 18:40:06 +0100 Subject: [PATCH] Updated `Air Freight Share Properties` logic: - Modified V4 migration to calculate `AIR_SHARE` as `0.03` for countries with `SAFETY_STOCK` value of 55, otherwise `0`. - Refactored SQL to use `CASE` expression and JOIN for safety stock lookup within property set constraints. --- .../resources/db/migration/V4__Country.sql | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/resources/db/migration/V4__Country.sql b/src/main/resources/db/migration/V4__Country.sql index e3806f5..5e0d4c1 100644 --- a/src/main/resources/db/migration/V4__Country.sql +++ b/src/main/resources/db/migration/V4__Country.sql @@ -581,7 +581,7 @@ SELECT FROM `country` c, `country_property_type` cpt WHERE cpt.external_mapping_id = 'SAFETY_STOCK'; --- Air Freight Share Properties (all countries have 0%) +-- Air Freight Share Properties (0.03 for countries with safety stock 55, otherwise 0%) INSERT INTO `country_property` (`country_id`, `country_property_type_id`, `property_set_id`, `property_value`) SELECT @@ -593,8 +593,26 @@ SELECT AND (ps.end_date IS NULL OR ps.end_date > NOW()) ORDER BY ps.start_date DESC LIMIT 1), - '0' -FROM `country` c, `country_property_type` cpt + CASE + WHEN cp_safety.property_value = '55' THEN '0.03' + ELSE '0' + END +FROM `country` c + CROSS JOIN `country_property_type` cpt + LEFT JOIN `country_property` cp_safety + ON cp_safety.country_id = c.id + AND cp_safety.country_property_type_id = ( + SELECT id FROM `country_property_type` + WHERE external_mapping_id = 'SAFETY_STOCK' + ) + AND cp_safety.property_set_id = ( + SELECT ps.id FROM `property_set` ps + WHERE ps.state = 'VALID' + AND ps.start_date <= NOW() + AND (ps.end_date IS NULL OR ps.end_date > NOW()) + ORDER BY ps.start_date DESC + LIMIT 1 + ) WHERE cpt.external_mapping_id = 'AIR_SHARE'; -- Wage Factor Properties (only for countries with defined values)