/** * @param $value * @param $route * * @return mixed */ public static function routeBinder($value, $route) { if (Auth::check()) { $ids = explode(',', $value); /** @var \Illuminate\Support\Collection $object */ $object = Budget::where('active', 1)->whereIn('id', $ids)->where('user_id', Auth::user()->id)->get(); // add empty budget if applicable. if (in_array('0', $ids)) { $object->push(new Budget()); } if ($object->count() > 0) { return $object; } } throw new NotFoundHttpException(); }
} } throw new NotFoundHttpException(); }); Route::bind('bill', function ($value) { if (Auth::check()) { $object = Bill::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { return $object; } } throw new NotFoundHttpException(); }); Route::bind('budget', function ($value) { if (Auth::check()) { $object = Budget::where('id', $value)->where('user_id', Auth::user()->id)->first(); if ($object) { return $object; } } throw new NotFoundHttpException(); }); Route::bind('limitrepetition', function ($value) { if (Auth::check()) { $object = LimitRepetition::where('limit_repetitions.id', $value)->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')->where('budgets.user_id', Auth::user()->id)->first(['limit_repetitions.*']); if ($object) { return $object; } } throw new NotFoundHttpException(); });
/** * @param TransactionJournal $journal * @param array $data * * @return TransactionJournal */ public function update(TransactionJournal $journal, array $data) : TransactionJournal { // update actual journal. $journal->transaction_currency_id = $data['amount_currency_id_amount']; $journal->description = $data['description']; $journal->date = $data['date']; // unlink all categories, recreate them: $journal->categories()->detach(); if (strlen($data['category']) > 0) { $category = Category::firstOrCreateEncrypted(['name' => $data['category'], 'user_id' => $data['user']]); $journal->categories()->save($category); } // unlink all budgets and recreate them: $journal->budgets()->detach(); if (intval($data['budget_id']) > 0 && $journal->transactionType->type !== TransactionType::TRANSFER) { /** @var \FireflyIII\Models\Budget $budget */ $budget = Budget::where('user_id', $this->user->id)->where('id', $data['budget_id'])->first(); $journal->budgets()->save($budget); } // store accounts (depends on type) list($fromAccount, $toAccount) = $this->storeAccounts($journal->transactionType, $data); // update the from and to transaction. /** @var Transaction $transaction */ foreach ($journal->transactions()->get() as $transaction) { if ($transaction->amount < 0) { // this is the from transaction, negative amount: $transaction->amount = $data['amount'] * -1; $transaction->account_id = $fromAccount->id; $transaction->save(); } if ($transaction->amount > 0) { $transaction->amount = $data['amount']; $transaction->account_id = $toAccount->id; $transaction->save(); } } $journal->save(); // update tags: if (isset($data['tags']) && is_array($data['tags'])) { $this->updateTags($journal, $data['tags']); } // update meta fields: $result = $journal->save(); if ($result) { foreach ($data as $key => $value) { if (in_array($key, $this->validMetaFields)) { $journal->setMeta($key, $value); continue; } Log::debug(sprintf('Could not store meta field "%s" with value "%s" for journal #%d', json_encode($key), json_encode($value), $journal->id)); } return $journal; } return $journal; }
/** * @covers FireflyIII\Repositories\Budget\BudgetRepository::destroy */ public function testDestroy() { $budget = FactoryMuffin::create('FireflyIII\\Models\\Budget'); $this->object->destroy($budget); $this->assertCount(0, Budget::where('id', $budget->id)->whereNull('deleted_at')->get()); }