1,I can get my current year income but don't know how to show all monthly income of current year.
2, if I want to create $selectYear as pick one of the random year then show the specific year monthly income of $selectYear just like question 1.
What I have try only the current/select year income but show monthly income of year, i still stuck there.
this my controller
public function index(){
$selectYear= 2017;
$this->getYearRevenue($selectYear);
//customPickYearRevenue is for totalIncome of $selectYear
$customPickYearRevenue = $this->getYearRevenue($selectYear);
}
private function getYearRevenue($selectYear){
$yearPickRevenue = Order::whereYear('created_at', '=', $selectYear)
->where('order_status', 'Accepted')
->sum('amount');
return $yearPickRevenue;
}
I want to show month with amount(revenue of year)
sorry about hard code $selectYear
Maybe something like this:
private function getRevenue($selectYear, $selectMonth){
return Order::whereYear('created_at', '=', $selectYear)
->whereMonth('created_at', '=', $selectMonth)
->where('order_status', 'Accepted')
->sum('amount');
}
And then you can use a loop to get the revenue for each month:
$year = 20019;
$months = ['1', '2', '3',];
$revenues = [];
foreach($months as $month){
array_push($revenues, getRevenue($year, $month);
}