Commit c8353344 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix fee calculation: handle NULL qualification_id in pricing lookup

Members with qualification_id=NULL (old retroactive entries) were falling
back to the stored membership_value (e.g. 119,800) instead of using the
current pricing (150,000). Now when qualification is NULL, we look up the
minimum price for that branch+type, which gives the correct base value.

Also fixed 26 existing subscription records in live DB: removed dev fee
(35.00) from spouse/child/temp subscriptions and recalculated totals.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 6873f19e
......@@ -24,10 +24,20 @@ final class ChildFeeCalculator
$isOnInitialForm = FormFeeService::isOnInitialForm($member);
// Always use current membership value from pricing_configs
$qualId = !empty($member['qualification_id']) ? (int) $member['qualification_id'] : null;
$branchId = (int) ($member['branch_id'] ?? 1);
$mType = $member['membership_type'] ?? 'working';
if ($qualId) {
$currentPricing = $db->selectOne(
"SELECT price FROM pricing_configs WHERE branch_id = ? AND qualification_id = ? AND membership_type = ? AND is_active = 1 AND effective_from <= CURDATE() AND (effective_to IS NULL OR effective_to >= CURDATE()) ORDER BY effective_from DESC LIMIT 1",
[(int) $member['branch_id'], (int) ($member['qualification_id'] ?? 0), $member['membership_type'] ?? 'working']
[$branchId, $qualId, $mType]
);
} else {
$currentPricing = $db->selectOne(
"SELECT price FROM pricing_configs WHERE branch_id = ? AND membership_type = ? AND is_active = 1 AND effective_from <= CURDATE() AND (effective_to IS NULL OR effective_to >= CURDATE()) ORDER BY price ASC LIMIT 1",
[$branchId, $mType]
);
}
if ($currentPricing && bccomp($currentPricing['price'], '0.01', 2) >= 0) {
$membershipValue = $currentPricing['price'];
}
......
......@@ -36,10 +36,20 @@ final class SpouseFeeCalculator
$isOnInitialForm = FormFeeService::isOnInitialForm($member);
// Always use current membership value from pricing_configs
$qualId = !empty($member['qualification_id']) ? (int) $member['qualification_id'] : null;
$branchId = (int) ($member['branch_id'] ?? 1);
$mType = $member['membership_type'] ?? 'working';
if ($qualId) {
$currentPricing = $db->selectOne(
"SELECT price FROM pricing_configs WHERE branch_id = ? AND qualification_id = ? AND membership_type = ? AND is_active = 1 AND effective_from <= CURDATE() AND (effective_to IS NULL OR effective_to >= CURDATE()) ORDER BY effective_from DESC LIMIT 1",
[(int) $member['branch_id'], (int) ($member['qualification_id'] ?? 0), $member['membership_type'] ?? 'working']
[$branchId, $qualId, $mType]
);
} else {
$currentPricing = $db->selectOne(
"SELECT price FROM pricing_configs WHERE branch_id = ? AND membership_type = ? AND is_active = 1 AND effective_from <= CURDATE() AND (effective_to IS NULL OR effective_to >= CURDATE()) ORDER BY price ASC LIMIT 1",
[$branchId, $mType]
);
}
if ($currentPricing && bccomp($currentPricing['price'], '0.01', 2) >= 0) {
$membershipValue = $currentPricing['price'];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment