diff --git a/app/Http/Controllers/RainfallController.php b/app/Http/Controllers/RainfallController.php index 011a1cd..431b35a 100644 --- a/app/Http/Controllers/RainfallController.php +++ b/app/Http/Controllers/RainfallController.php @@ -121,7 +121,7 @@ class RainfallController extends Controller $diff = now()->diffInMonths($firstOfLastYear); $result = []; - for ($i = $diff; $i >= 0; $i--) { + for ($i = -$diff; $i >= 0; $i--) { $date = now()->subMonths($i); $month = $date->month; $firstOfMonth = now()->subMonths($i)->firstOfMonth(); diff --git a/resources/js/components/rainfall/YearRainfaill.tsx b/resources/js/components/rainfall/YearRainfaill.tsx index 3bd7a6e..401211a 100644 --- a/resources/js/components/rainfall/YearRainfaill.tsx +++ b/resources/js/components/rainfall/YearRainfaill.tsx @@ -46,23 +46,23 @@ const YearRainfall: FC = ({loadedAt}) => { {months.find(m => m.year === ((new Date).getFullYear() - 1) && m.month === Number(month))?.values} )} - {/**/} - {/* Total*/} - {/* {Object.entries(data).at(0).at(1).map(i => i.year)*/} - {/* .sort((a,b) => b > a)*/} - {/* .map(year => */} - {/* {Object.entries(data).reduce((acc, item) => {*/} - {/* console.log(item.at(1), year)*/} - {/* item.at(1).forEach(month => {*/} - {/* console.log(month)*/} - {/* if(month.year === year) {*/} - {/* acc += month.values*/} - {/* }*/} - {/* })*/} - {/* return acc*/} - {/* }, 0)}*/} - {/* )}*/} - {/**/} + + Total + {Object.entries(data).at(0).at(1).map(i => i.year) + .sort((a,b) => b > a) + .map(year => + {Object.entries(data).reduce((acc, item) => { + console.log(item.at(1), year) + item.at(1).forEach(month => { + console.log(month) + if(month.year === year) { + acc += month.values + } + }) + return acc + }, 0)} + )} +