Skip to content

Commit

Permalink
#1414 minor change style code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganes556 committed Feb 5, 2025
1 parent 82873d7 commit 2ac6b26
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/Actions/UI/Dashboards/ShowGroupDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ public function getDashboardInterval(Group $group, array $userSettings): array
'total_refunds' => 0,
];

$visualData = [];

if ($this->tabDashboardInterval == GroupDashboardIntervalTabsEnum::SALES->value) {
$total['total_sales'] = $organisations->sum(fn ($organisation) => $organisation->salesIntervals->{"sales_grp_currency_$selectedInterval"} ?? 0);
$dashboard['table'][0]['data'] = $this->getSales($group, $selectedInterval, $selectedCurrency, $organisations, $dashboard, $visualData, $total);
$dashboard['table'][0]['data'] = $this->getSales($group, $selectedInterval, $selectedCurrency, $organisations, $dashboard, $total);
} elseif ($this->tabDashboardInterval == GroupDashboardIntervalTabsEnum::SHOPS->value) {
$shops = $group->shops->whereIn('organisation_id', $organisations->pluck('id')->toArray());
$total['total_sales'] = $shops->sum(fn ($shop) => $shop->salesIntervals->{"sales_grp_currency_$selectedInterval"} ?? 0);
$dashboard['table'][1]['data'] = $this->getShops($group, $shops, $selectedInterval, $dashboard, $selectedCurrency, $visualData, $total);
$dashboard['table'][1]['data'] = $this->getShops($group, $shops, $selectedInterval, $dashboard, $selectedCurrency, $total);
}

return $dashboard;
}

public function getSales(Group $group, $selectedInterval, $selectedCurrency, $organisations, &$dashboard, &$visualData, &$total): array
public function getSales(Group $group, $selectedInterval, $selectedCurrency, $organisations, &$dashboard, &$total): array
{
$visualData = [];

$data = $organisations->map(function (Organisation $organisation) use ($selectedInterval, $group, &$dashboard, $selectedCurrency, &$visualData, &$total) {
$keyCurrency = $dashboard['settings']['key_currency'];
$currencyCode = $selectedCurrency === $keyCurrency ? $group->currency->code : $organisation->currency->code;
Expand All @@ -137,6 +137,7 @@ public function getSales(Group $group, $selectedInterval, $selectedCurrency, $or
$salesCurrency,
$selectedInterval,
);
// visual sales
$visualData['sales_data']['labels'][] = $organisation->code;
$visualData['sales_data']['currency_codes'][] = $currencyCode;
$visualData['sales_data']['datasets'][0]['data'][] = $responseData['interval_percentages']['sales']['amount'];
Expand Down Expand Up @@ -285,8 +286,10 @@ public function getSales(Group $group, $selectedInterval, $selectedCurrency, $or
return $data;
}

public function getShops(Group $group, $shops, $selectedInterval, &$dashboard, $selectedCurrency, &$visualData, &$total): array
public function getShops(Group $group, $shops, $selectedInterval, &$dashboard, $selectedCurrency, &$total): array
{
$visualData = [];

$data = $shops->map(function (Shop $shop) use ($selectedInterval, $group, &$dashboard, $selectedCurrency, &$visualData, &$total) {
$keyCurrency = $dashboard['settings']['key_currency'];
$currencyCode = $selectedCurrency === $keyCurrency ? $group->currency->code : $shop->organisation->currency->code;
Expand All @@ -305,14 +308,14 @@ public function getShops(Group $group, $shops, $selectedInterval, &$dashboard, $
]
];


if ($shop->salesIntervals !== null) {
// data sales
$responseData['interval_percentages']['sales'] = $this->getIntervalPercentage(
$shop->salesIntervals,
$salesCurrency,
$selectedInterval,
);

// visual sales
$visualData['sales_data']['labels'][] = $shop->code;
$visualData['sales_data']['currency_codes'][] = $currencyCode;
Expand Down

0 comments on commit 2ac6b26

Please sign in to comment.