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.
This commit is contained in:
Jan 2025-10-28 18:40:06 +01:00
parent d840b05da2
commit e1c1b2918f

View file

@ -581,7 +581,7 @@ SELECT
FROM `country` c, `country_property_type` cpt FROM `country` c, `country_property_type` cpt
WHERE cpt.external_mapping_id = 'SAFETY_STOCK'; 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` INSERT INTO `country_property`
(`country_id`, `country_property_type_id`, `property_set_id`, `property_value`) (`country_id`, `country_property_type_id`, `property_set_id`, `property_value`)
SELECT SELECT
@ -593,8 +593,26 @@ SELECT
AND (ps.end_date IS NULL OR ps.end_date > NOW()) AND (ps.end_date IS NULL OR ps.end_date > NOW())
ORDER BY ps.start_date DESC ORDER BY ps.start_date DESC
LIMIT 1), LIMIT 1),
'0' CASE
FROM `country` c, `country_property_type` cpt 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'; WHERE cpt.external_mapping_id = 'AIR_SHARE';
-- Wage Factor Properties (only for countries with defined values) -- Wage Factor Properties (only for countries with defined values)