public function addTransaction() { $accounts = array(); foreach (Auth::user()->accounts()->get() as $account) { $accounts[$account->id] = Crypt::decrypt($account->name); } $budgets = array(); $budgets[0] = '(no budget)'; foreach (Auth::user()->budgets()->orderBy('date', 'DESC')->take(20)->get() as $budget) { $date = new Carbon($budget->date); $budgets[$budget->id] = Crypt::decrypt($budget->name) . ' (' . $date->format('F Y') . ')'; } $categories = array(); foreach (Auth::user()->categories()->get() as $cat) { $categories[] = Crypt::decrypt($cat->name); } $beneficiaries = array(); foreach (Auth::user()->beneficiaries()->get() as $ben) { $beneficiaries[] = Crypt::decrypt($ben->name); } if (Holmes::isMobile()) { return View::make('mobile.transactions.add')->with('accounts', $accounts)->with('budgets', $budgets)->with('categories', $categories)->with('beneficiaries', $beneficiaries); } else { return View::make('transactions.add')->with('accounts', $accounts)->with('budgets', $budgets)->with('categories', $categories)->with('beneficiaries', $beneficiaries); } }
public function getHome() { $key = cacheKey('home', Session::get('period')); if (Cache::has($key)) { $data = Cache::get($key); } else { $max = 0; $min = 1000000; $data = array('accounts' => array(), 'budgets' => array(), 'targets' => array()); // we need this list: $accounts = Auth::user()->accounts()->get(); foreach ($accounts as $a) { $account = array('id' => intval($a->id), 'name' => Crypt::decrypt($a->name), 'currentbalance' => $a->balance()); $account['header'] = $account['currentbalance'] < 0 ? array('style' => 'color:red;', 'class' => 'tt', 'title' => $account['name'] . ' has a balance below zero. Try to fix this.') : array(); $min = $account['currentbalance'] < $min ? $account['currentbalance'] : $min; $max = $account['currentbalance'] > $max ? $account['currentbalance'] : $max; $data['accounts'][] = $account; } $min = $min > 0 ? 0 : $min; $max = $max < 0 ? 0 : $max; $min = floor($min / 1000) * 1000; $max = ceil($max / 1000) * 1000; $sum = 0; foreach ($data['accounts'] as $index => $account) { $sum += $account['currentbalance']; } $data['acc_data']['sum'] = $sum; // now everything for budgets: $data['budgets'] = Budget::getHomeOverview(); // some extra budget data: $monthlyAmount = Setting::getSetting('monthlyAmount', Session::get('period')->format('Y-m-') . '01'); if (is_null($monthlyAmount)) { $monthlyAmount = intval(Setting::getSetting('defaultAmount')); } $data['budget_data']['amount'] = $monthlyAmount; $data['budget_data']['spent_outside'] = floatval(Auth::user()->transactions()->where('amount', '<', 0)->whereNull('budget_id')->where(DB::Raw('DATE_FORMAT(`date`,"%m-%Y")'), '=', Session::get('period')->format('m-Y'))->sum('amount')) * -1; // targets, cant make it better im afraid. $data['targets'] = Target::getHomeOverview(); Cache::put($key, $data, 2440); } // flash some warnings: if (Auth::user()->transactions()->count() == 0) { Session::flash('warning', 'There are no transactions saved yet. Create some to make this overview less boring (Create → New transaction).'); } if (count($data['budgets']) == 0) { Session::flash('warning', 'You don\'t have any budgets defined.'); } if (count($data['accounts']) == 0) { Session::flash('warning', 'You do not have any accounts added. You should do this first (Create → New account)'); } if (Holmes::isMobile()) { return View::make('mobile.home.home')->with('data', $data); } else { return View::make('home.home')->with('data', $data); } }