diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php index 16ab897861..c31c66c354 100644 --- a/app/controllers/GoogleChartController.php +++ b/app/controllers/GoogleChartController.php @@ -1,6 +1,7 @@ _chart->addColumn('Day of month', 'date'); $this->_chart->addColumn('Balance for ' . $account->name, 'number'); - $start = Session::get('start',Carbon::now()->startOfMonth()); + // TODO this can be combined in some method, it's + $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end'); $count = $account->transactions()->count(); @@ -59,150 +61,6 @@ class GoogleChartController extends BaseController return Response::json($this->_chart->getData()); } - /** - * @param Account $account - * @param string $view - * - * @return \Illuminate\Http\JsonResponse - */ - public function accountSankeyInChart(Account $account, $view = 'session') - { - // collect all relevant entries. - $set = []; - - /** @var \Grumpydictator\Gchart\GChart $chart */ - $chart = App::make('gchart'); - $chart->addColumn('From', 'string'); - $chart->addColumn('To', 'string', 'domain'); - $chart->addColumn('Weight', 'number'); - - switch ($view) { - default: - case 'session': - $start = Session::get('start',Carbon::now()->startOfMonth()); - $end = Session::get('end'); - break; - case 'all': - $first = $account->transactionjournals()->orderBy('date', 'DESC')->first(); - $last = $account->transactionjournals()->orderBy('date', 'ASC')->first(); - if (is_null($first)) { - $start = Session::get('start',Carbon::now()->startOfMonth()); - } else { - $start = clone $first->date; - } - if (is_null($last)) { - $end = Session::get('end'); - } else { - $end = clone $last->date; - } - break; - } - - - $transactions = $account->transactions()->with( - ['transactionjournal', 'transactionjournal.transactions' => function ($q) { - $q->where('amount', '<', 0); - }, 'transactionjournal.budgets', 'transactionjournal.transactiontype', 'transactionjournal.categories'] - )->before($end)->after($start)->get(); - - /** @var Transaction $transaction */ - foreach ($transactions as $transaction) { - $amount = floatval($transaction->amount); - $type = $transaction->transactionJournal->transactionType->type; - - if ($amount > 0 && $type != 'Transfer') { - - $otherAccount = $transaction->transactionJournal->transactions[0]->account->name; - $categoryName = isset($transaction->transactionJournal->categories[0]) ? $transaction->transactionJournal->categories[0]->name : '(no cat)'; - $set[] = [$otherAccount, $categoryName, $amount]; - $set[] = [$categoryName, $account->name, $amount]; - } - } - // loop the set, group everything together: - $grouped = []; - foreach ($set as $entry) { - $key = $entry[0] . $entry[1]; - if (isset($grouped[$key])) { - $grouped[$key][2] += $entry[2]; - } else { - $grouped[$key] = $entry; - } - } - - // add rows to the chart: - foreach ($grouped as $entry) { - $chart->addRow($entry[0], $entry[1], $entry[2]); - } - - $chart->generate(); - - return Response::json($chart->getData()); - - } - - /** - * @param Account $account - * @param string $view - * - * @return \Illuminate\Http\JsonResponse - */ - public function accountSankeyOutChart(Account $account, $view = 'session') - { - // collect all relevant entries. - $set = []; - - /** @var \Grumpydictator\Gchart\GChart $chart */ - $chart = App::make('gchart'); - $chart->addColumn('From', 'string'); - $chart->addColumn('To', 'string', 'domain'); - $chart->addColumn('Weight', 'number'); - - $transactions = $account->transactions()->with( - ['transactionjournal', 'transactionjournal.transactions', 'transactionjournal.budgets', 'transactionjournal.transactiontype', - 'transactionjournal.categories'] - )->before(Session::get('end'))->after( - Session::get('start',Carbon::now()->startOfMonth()) - )->get(); - - /** @var Transaction $transaction */ - foreach ($transactions as $transaction) { - $amount = floatval($transaction->amount); - $type = $transaction->transactionJournal->transactionType->type; - - if ($amount < 0 && $type != 'Transfer') { - - // from account to a budget (if present). - $budgetName = isset($transaction->transactionJournal->budgets[0]) ? $transaction->transactionJournal->budgets[0]->name : '(no budget)'; - $set[] = [$account->name, $budgetName, $amount * -1]; - - // from budget to category. - $categoryName = isset($transaction->transactionJournal->categories[0]) ? ' ' . $transaction->transactionJournal->categories[0]->name - : '(no cat)'; - $set[] = [$budgetName, $categoryName, $amount * -1]; - } - } - // loop the set, group everything together: - $grouped = []; - foreach ($set as $entry) { - $key = $entry[0] . $entry[1]; - if (isset($grouped[$key])) { - $grouped[$key][2] += $entry[2]; - } else { - $grouped[$key] = $entry; - } - } - - // add rows to the chart: - foreach ($grouped as $entry) { - $chart->addRow($entry[0], $entry[1], $entry[2]); - } - - $chart->generate(); - - return Response::json($chart->getData()); - - } - /** * This method renders the b */ @@ -235,7 +93,7 @@ class GoogleChartController extends BaseController /* * Loop the date, then loop the accounts, then add balance. */ - $start = Session::get('start',Carbon::now()->startOfMonth()); + $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end'); $current = clone $start; @@ -281,14 +139,14 @@ class GoogleChartController extends BaseController * Is there a repetition starting on this particular date? We can use that. */ /** @var \LimitRepetition $repetition */ - $repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start',Carbon::now()->startOfMonth())); + $repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start', Carbon::now()->startOfMonth())); /* * If there is, use it. Otherwise, forget it. */ if (is_null($repetition)) { // use the session start and end for our search query - $searchStart = Session::get('start',Carbon::now()->startOfMonth()); + $searchStart = Session::get('start', Carbon::now()->startOfMonth()); $searchEnd = Session::get('end'); // the limit is zero: $limit = 0; @@ -315,7 +173,7 @@ class GoogleChartController extends BaseController * Finally, get all transactions WITHOUT a budget and add those as well. * (yes this method is oddly specific). */ - $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start',Carbon::now()->startOfMonth()), Session::get('end')); + $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start', Carbon::now()->startOfMonth()), Session::get('end')); $sum = $noBudgetSet->sum('amount') * -1; $chart->addRow('No budget', 0, $sum); @@ -343,7 +201,7 @@ class GoogleChartController extends BaseController /* * Get the journals: */ - $journals = $tj->getInDateRange(Session::get('start',Carbon::now()->startOfMonth()), Session::get('end')); + $journals = $tj->getInDateRange(Session::get('start', Carbon::now()->startOfMonth()), Session::get('end')); /** @var \TransactionJournal $journal */ foreach ($journals as $journal) { @@ -627,7 +485,7 @@ class GoogleChartController extends BaseController /* * In the current session range? */ - if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start',Carbon::now()->startOfMonth())) { + if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start', Carbon::now()->startOfMonth())) { /* * Lets see if we've already spent money on this recurring transaction (it hath recurred). */ diff --git a/app/lib/Firefly/Database/SingleTableInheritanceEntity.php b/app/lib/Firefly/Database/SingleTableInheritanceEntity.php deleted file mode 100644 index 762ee14ad6..0000000000 --- a/app/lib/Firefly/Database/SingleTableInheritanceEntity.php +++ /dev/null @@ -1,121 +0,0 @@ -mapData((array)$attributes)->newInstance([], true); - $instance->setRawAttributes((array)$attributes, true); - - return $instance; - } - - - /** - * if no subclass is defined, function as normal - * - * @param array $attributes - * - * @return \Illuminate\Database\Eloquent\Model|static - */ - public function mapData(array $attributes) - { - if (!$this->subclassField) { - return $this->newInstance(); - } - - return new $attributes[$this->subclassField]; - } - - - /** - * - * instead of using $this->newInstance(), call - * newInstance() on the object from mapData - * - * @param bool $excludeDeleted - * - * @return \Illuminate\Database\Eloquent\Builder|static - */ - public function newQuery($excludeDeleted = true) - { - // If using Laravel 4.0.x then use the following commented version of this command - // $builder = new Builder($this->newBaseQueryBuilder()); - // newEloquentBuilder() was added in 4.1 - $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder()); - - // Once Firefly has the query builders, it will set the model instances so the - // builder can easily access any information it may need from the model - // while it is constructing and executing various queries against it. - $builder->setModel($this)->with($this->with); - - if ($excludeDeleted && $this->softDelete) { - $builder->whereNull($this->getQualifiedDeletedAtColumn()); - } - - if ($this->subclassField && $this->isSubclass()) { - $builder->where($this->subclassField, '=', get_class($this)); - } - - return $builder; - } - - /** - * @return bool - */ - public function isSubclass() - { - return $this->isSubclass; - } - - /** - * ensure that the subclass field is assigned on save - * - * @param array $rules - * @param array $customMessages - * @param array $options - * @param callable $beforeSave - * @param callable $afterSave - * - * @return bool - */ - public function save( - array $rules = [], - array $customMessages = [], - array $options = [], - \Closure $beforeSave = null, - \Closure $afterSave = null - ) { - if ($this->subclassField) { - $this->attributes[$this->subclassField] = get_class($this); - } - - return parent::save($rules, $customMessages, $options, $beforeSave, $afterSave); - } -} \ No newline at end of file diff --git a/app/lib/Firefly/Exception/FireflyException.php b/app/lib/Firefly/Exception/FireflyException.php deleted file mode 100644 index eb0f038fa3..0000000000 --- a/app/lib/Firefly/Exception/FireflyException.php +++ /dev/null @@ -1,14 +0,0 @@ - 'Amount (min)', - 'amount_max' => 'Amount (max)', - 'match' => 'Matches on', - 'repeat_freq' => 'Repetition', - 'account_from_id' => 'Account from', - 'account_to_id' => 'Account to', - 'account_id' => 'Asset account' - ]; - - return isset($labels[$name]) ? $labels[$name] : str_replace('_', ' ', ucfirst($name)); - - } - - /** - * Return buttons for update/validate/return. - * - * @param $type - * @param $name - */ - public static function ffOptionsList($type, $name) - { - $previousValue = \Input::old('post_submit_action'); - $previousValue = is_null($previousValue) ? 'store' : $previousValue; - /* - * Store. - */ - $store = ''; - switch ($type) { - case 'create': - $store = '
' . e($errors->first($name)) . '
'; - } - } - unset($errors); - /* - * If warnings, respond to them: - */ - - if (!is_null($warnings)) { - if ($warnings->has($name)) { - $html .= ''; - $html .= '' . e($warnings->first($name)) . '
'; - } - } - unset($warnings); - - /* - * If successes, respond to them: - */ - - if (!is_null($successes)) { - if ($successes->has($name)) { - $html .= ''; - $html .= '' . e($successes->first($name)) . '
'; - } - } - unset($successes); - - $html .= '