{{-- This blade template displays a revenue overview dashboard. It calculates the growth percentages of monthly transactions and displays them along with the transaction amounts. --}}
@php
$previous = null; // holds the sum of the previous month's transaction
$growthPercentages = [];
// Calculate growth percentages
foreach($transactions as $index => $transaction) {
$percentage = 0;
if ($previous !== null && $previous != 0) { // Check if previous sum is not zero
$percentage = (($transaction->sum - $previous) / $previous) * 100;
}
$growthPercentages[] = $percentage;
$previous = $transaction->sum; // update the previous sum for the next iteration
}
@endphp
@foreach($transactions as $index => $transaction)
@php
$percentage = $growthPercentages[$index];
@endphp