/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $bars = \App\Center::find(\Config::get('place.center'))->place->bars; $bars->load('photos', 'reviews'); return $bars; }
/** * Gets the monthly balance of each account. If there is only a date passed, * it gets the sum of all accounts for that month. If only a center id * is passed, then it gets a whole year for that center. If both a * date and center id are passed, it gets that center's average * balance for that month. If no parameter is passed, it gets * the average monthly balance for the entire organization. * * @param bool $date = false * @param bool $center_id = false * @return array|string */ public static function getMonthlyBalance($date = false, $center_id = false) { if ($date && $center_id) { $output = []; $balance = Balance::select('availableBalance')->where('center_id', '=', $center_id)->where('date', '<=', $date)->orderBy('date', 'dec')->first(); $center_name = Center::find($center_id)->codeName; $output['center_id'] = $center_id; $output['center_name'] = $center_name; $output['balance'] = $balance; return $output; } elseif ($date && !$center_id) { $output = Balance::where('date', '=', $date)->sum('availableBalance'); while ($output == 0) { $date = Carbon::parse($date)->subDay()->toDateString(); $output = Balance::where('date', '=', $date)->sum('availableBalance'); } return $output; } elseif ($center_id && !$date) { $date = Carbon::now(); $centers = Fund::getSeparateCenterAccounts($center_id); $date_array = self::getArrayOfMonths($date->toDateString(), 12); $accounts_array = []; $counter = 0; $output = []; foreach ($centers as $center) { foreach ($center['accounts'] as $account) { array_push($accounts_array, $account['account_name']); for ($i = 0; $i < 12; $i++) { $balance = Balance::select('availableBalance')->where('center_id', '=', $account['account_id'])->where('date', '=', $date_array[$i])->get(); if ($i < 12) { $output[$counter]['this_year'][$i] = [Carbon::parse($date_array[$i])->format('M Y'), (int) $balance[0]->availableBalance]; } else { if (empty($balance[0])) { $output[$counter]['last_year'][$i - 12] = [Carbon::parse($date_array[$i])->format('M Y'), 0]; } else { $output[$counter]['last_year'][$i - 12] = [Carbon::parse($date_array[$i])->format('M Y'), (int) $balance[0]->availableBalance]; } } } $counter++; } } return json_encode(['output' => array_reverse($output), 'accounts' => array_reverse($accounts_array)]); } else { $date = Carbon::now(); $current_months_array = []; $last_years_months_array = []; $current_months_balance_array = []; $last_years_balance_array = []; $date_array = self::getArrayOfMonths($date->toDateString(), 24); for ($i = 0; $i < count($date_array); $i++) { $balance = Balance::where('date', '=', $date_array[$i])->sum('availableBalance'); if ($i < 12) { array_push($current_months_array, Carbon::parse($date_array[$i])->format('M Y')); array_push($current_months_balance_array, (int) $balance); } else { array_push($last_years_months_array, Carbon::parse($date_array[$i])->format('M Y')); array_push($last_years_balance_array, (int) $balance); } } return json_encode(['current_years_months' => array_reverse($current_months_array), 'current_years_balance' => array_reverse($current_months_balance_array), 'last_years_balance' => array_reverse($last_years_balance_array), 'last_years_months' => array_reverse($last_years_months_array)]); } }