Skip to content

Commit

Permalink
feat: Added source groups in the filtered plans obtaining
Browse files Browse the repository at this point in the history
  • Loading branch information
EMunozMobbex committed Jan 2, 2024
1 parent ea6226a commit 75d9129
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,25 @@ public static function getInstallmentsQuery($total, $installments = [])
*/
public static function getPlansFilterFields($id, $checkedCommonPlans = [], $checkedAdvancedPlans = [])
{
$commonFields = $advancedFields = $sourceNames = [];
$commonFields = $advancedFields = $sourceNames = $sourceGroups = [];

// Create common plan fields
foreach (self::getSources() as $source) {
// Only if have installments
if (empty($source['installments']['list']))
continue;
continue;

// Create field array data
foreach ($source['installments']['list'] as $plan) {
$commonFields[$plan['reference']] = [
'id' => 'common_plan_' . $plan['reference'],
'value' => !in_array($plan['reference'], $checkedCommonPlans),
'label' => $plan['name'] ?: $plan['description'],
'id' => 'common_plan_' . $plan['reference'],
'value' => !in_array($plan['reference'], $checkedCommonPlans),
'label' => $plan['name'],
'description' => $plan['description'],
];

$sourceGroups[$plan['name']][] = $source['source']['reference'];
$sourceGroups[$plan['name']] = array_unique($sourceGroups[$plan['name']]);
}
}

Expand All @@ -105,14 +109,15 @@ public static function getPlansFilterFields($id, $checkedCommonPlans = [], $chec
// Create field array data
foreach ($source['installments'] as $plan) {
$advancedFields[$source['source']['reference']][] = [
'id' => 'advanced_plan_' . $plan['uid'],
'value' => in_array($plan['uid'], $checkedAdvancedPlans),
'label' => $plan['name'] ?: $plan['description'],
'id' => 'advanced_plan_' . $plan['uid'],
'value' => in_array($plan['uid'], $checkedAdvancedPlans),
'label' => $plan['name'],
'description' => $plan['description'],
];
}
}

return compact('commonFields', 'advancedFields', 'sourceNames');
return compact('commonFields', 'advancedFields', 'sourceNames', 'sourceGroups');
}

/**
Expand Down

0 comments on commit 75d9129

Please sign in to comment.