#26 - Loading animation + success message fix
This commit was merged in pull request #31.
This commit is contained in:
@@ -2,18 +2,9 @@
|
||||
|
||||
class RsvMembershipService {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Total membership discount for a submission.
|
||||
*
|
||||
* Each binding names a form field whose submitted value must match a key
|
||||
* in the bound program. Matching bindings' discounts are combined per the
|
||||
* definition's combine mode: the best single discount, or all summed and
|
||||
* capped at 100%.
|
||||
*/
|
||||
public function discount_for(RsvFormDefinition $def, RsvFormData $data): float {
|
||||
public function discount_detail_for(RsvFormDefinition $def, RsvFormData $data): array {
|
||||
$repo = new RsvMembershipProgramRepository();
|
||||
$matched_programs = [];
|
||||
$matched_discounts = [];
|
||||
|
||||
foreach ($def->getMembershipBindings() as $binding) {
|
||||
@@ -33,18 +24,37 @@ class RsvMembershipService {
|
||||
}
|
||||
|
||||
if ($repo->key_exists($program_id, $value)) {
|
||||
$program = $repo->get($program_id);
|
||||
if ($program) {
|
||||
$matched_programs[] = $program['name'];
|
||||
}
|
||||
$matched_discounts[] = $discount;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($matched_discounts)) {
|
||||
return 0.0;
|
||||
return ['percent' => 0.0, 'reason' => ''];
|
||||
}
|
||||
|
||||
if ($def->getMembershipCombine() === 'sum') {
|
||||
return min(100.0, array_sum($matched_discounts));
|
||||
$reason = implode(', ', $matched_programs);
|
||||
return ['percent' => min(100.0, array_sum($matched_discounts)), 'reason' => $reason];
|
||||
}
|
||||
|
||||
return max($matched_discounts);
|
||||
$max_idx = array_search(max($matched_discounts), $matched_discounts, true);
|
||||
$reason = $matched_programs[$max_idx] ?? '';
|
||||
return ['percent' => max($matched_discounts), 'reason' => $reason];
|
||||
}
|
||||
|
||||
/**
|
||||
* Total membership discount for a submission.
|
||||
*
|
||||
* Each binding names a form field whose submitted value must match a key
|
||||
* in the bound program. Matching bindings' discounts are combined per the
|
||||
* definition's combine mode: the best single discount, or all summed and
|
||||
* capped at 100%.
|
||||
*/
|
||||
public function discount_for(RsvFormDefinition $def, RsvFormData $data): float {
|
||||
return $this->discount_detail_for($def, $data)['percent'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user