Skip to content

Commit

Permalink
Change statistics diff in percent (#378)
Browse files Browse the repository at this point in the history
* Change statistics diff in percent

* formatting

---------

Co-authored-by: Andrei Ioniță <hi@andrei.io>
  • Loading branch information
alexPopaCode4 and andreiio authored Jun 25, 2024
1 parent e55180c commit 7fdc51c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
24 changes: 8 additions & 16 deletions app/Filament/Widgets/StatisticsCards.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,10 @@ private function getProjectCard(string $cardLabel): Card
$color = $currentGrandThanLast ? 'success' : 'danger';
$icon = $currentGrandThanLast ? 'heroicon-s-trending-up' : 'heroicon-s-trending-down';

$description = $cardLabel === 'year' ?
(
$currentGrandThanLast ?
__('statistics.labels.current_year_grand_than_last_year', ['number' => $currentAvg - $lastAvg]) :
__('statistics.labels.current_year_less_than_last_year', ['number' => $lastAvg - $currentAvg])
) :
(
$currentGrandThanLast ?
__('statistics.labels.current_month_grand_than_last_month', ['number' => $currentAvg - $lastAvg]) :
__('statistics.labels.current_month_less_than_last_month', ['number' => $lastAvg - $currentAvg])
);
$diffPercent = round(($currentAvg * 100 / $lastAvg) - 100, 2);
$description = $cardLabel === 'year'
? __('statistics.labels.current_year_vs_last_year', ['number' => $diffPercent])
: __('statistics.labels.current_month_vs_last_month', ['number' => $diffPercent]);

$chart = array_map(function () use ($currentAvg, $lastAvg) {
return rand(min((int) $currentAvg, (int) $lastAvg), max((int) $currentAvg, (int) $lastAvg));
Expand Down Expand Up @@ -118,14 +111,13 @@ private function getDonationCard(string $string)
$color = $currentGrandThanLast ? 'success' : 'danger';
$icon = $currentGrandThanLast ? 'heroicon-s-trending-up' : 'heroicon-s-trending-down';

$description =
$currentGrandThanLast ?
__('statistics.labels.donation_grand_than_last_year', ['amount' => $currentYear - $lastYear]) :
__('statistics.labels.donation_less_than_last_year', ['amount' => $lastYear - $currentYear]);
$diffPercent = round(($currentYear * 100 / $lastYear) - 100, 2);

$description = __('statistics.labels.donation_vs_last_year', ['amount' => $diffPercent]);

return Card::make(
__('statistics.labels.donations_amount'),
__('statistics.labels.amount_in_currency', ['amount' => $currentYear])
__('statistics.labels.amount_in_currency', ['amount' => number_format($currentYear)])
)
->descriptionColor($color)
->descriptionIcon($icon)
Expand Down
9 changes: 3 additions & 6 deletions lang/ro/statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
'project_monthly' => 'Durata medie proiecte (lunar)',
'project_year' => 'Durata medie proiecte (anual)',
'no_of_days' => ':number zile',
'current_month_grand_than_last_month' => ':number zile crestere fata de luna trecuta',
'current_month_less_than_last_month' => ':number zile scadere fata de luna trecuta',
'current_year_grand_than_last_year' => ':number zile crestere fata de anul trecut',
'current_year_less_than_last_year' => ':number zile scadere fata de anul trecut',
'current_month_vs_last_month' => ':number% fata de luna trecuta',
'current_year_vs_last_year' => ':number% fata de anul trecut',
'donations_amount' => 'Valoarea totala a donatiilor in ultimul an',
'amount_in_currency' => ':amount LEI',
'donation_grand_than_last_year' => ':amount crestere fata de anul trecut',
'donation_less_than_last_year' => ':amount scadere fata de anul trecut',
'donation_vs_last_year' => ':amount% fata de anul trecut',
'donations_count' => 'Numar total de donatii (an curent)',
'projects_count' => 'Inscrieri proiecte (an curent)',
],
Expand Down

0 comments on commit 7fdc51c

Please sign in to comment.