From 9155c13e082958ba08f37db6dc5a3c9efd6d7661 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 27 Jan 2016 18:31:44 +0100 Subject: [PATCH] A set of small fixes, courtesy of scrutinizer-ci --- .../Commands/UpgradeFireflyInstructions.php | 1 - app/Exceptions/Handler.php | 28 +- .../Account/ChartJsAccountChartGenerator.php | 2 +- .../ChartJsPiggyBankChartGenerator.php | 2 +- app/Helpers/Attachments/AttachmentHelper.php | 8 +- .../Csv/Specifix/AbnAmroDescription.php | 70 ++--- app/Helpers/FiscalHelperInterface.php | 4 +- app/Helpers/Report/ReportHelper.php | 2 +- app/Http/Controllers/Auth/AuthController.php | 2 +- app/Http/Controllers/BudgetController.php | 2 +- app/Http/breadcrumbs.php | 4 +- app/Models/Account.php | 37 +-- app/Models/Budget.php | 33 +-- app/Models/Category.php | 33 +-- app/Models/LimitRepetition.php | 36 +-- app/Models/TransactionJournal.php | 253 +++++++++--------- 16 files changed, 261 insertions(+), 256 deletions(-) diff --git a/app/Console/Commands/UpgradeFireflyInstructions.php b/app/Console/Commands/UpgradeFireflyInstructions.php index a61ffaee7b..bb99309c05 100644 --- a/app/Console/Commands/UpgradeFireflyInstructions.php +++ b/app/Console/Commands/UpgradeFireflyInstructions.php @@ -28,7 +28,6 @@ class UpgradeFireflyInstructions extends Command /** * Create a new command instance. * - * @return void */ public function __construct() { diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 9b449ff362..99c87fc1b0 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -6,7 +6,6 @@ use Exception; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; -use Illuminate\Foundation\Validation\ValidationException; use Symfony\Component\HttpKernel\Exception\HttpException; /** @@ -26,9 +25,21 @@ class Handler extends ExceptionHandler AuthorizationException::class, HttpException::class, ModelNotFoundException::class, - ValidationException::class, ]; + /** + * Render an exception into an HTTP response. + * + * @param \Illuminate\Http\Request $request + * @param \Exception $exception + * + * @return \Illuminate\Http\Response + */ + public function render($request, Exception $exception) + { + return parent::render($request, $exception); + } + /** * Report or log an exception. * @@ -42,17 +53,4 @@ class Handler extends ExceptionHandler { parent::report($exception); } - - /** - * Render an exception into an HTTP response. - * - * @param \Illuminate\Http\Request $request - * @param \Exception $exception - * - * @return \Illuminate\Http\Response - */ - public function render($request, Exception $exception) - { - return parent::render($request, $exception); - } } diff --git a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php index b9807954c5..4006ff2c6e 100644 --- a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php +++ b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php @@ -72,7 +72,7 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator public function frontpage(Collection $accounts, Carbon $start, Carbon $end) { // language: - $format = trans('config.month_and_day'); + $format = (string)trans('config.month_and_day'); $data = ['count' => 0, 'labels' => [], 'datasets' => [],]; $current = clone $start; while ($current <= $end) { diff --git a/app/Generator/Chart/PiggyBank/ChartJsPiggyBankChartGenerator.php b/app/Generator/Chart/PiggyBank/ChartJsPiggyBankChartGenerator.php index a33b867911..b62640f9f0 100644 --- a/app/Generator/Chart/PiggyBank/ChartJsPiggyBankChartGenerator.php +++ b/app/Generator/Chart/PiggyBank/ChartJsPiggyBankChartGenerator.php @@ -23,7 +23,7 @@ class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator { // language: - $format = trans('config.month_and_day'); + $format = (string)trans('config.month_and_day'); $data = [ 'count' => 1, diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.php index 692287d0f7..a64f7ac1c2 100644 --- a/app/Helpers/Attachments/AttachmentHelper.php +++ b/app/Helpers/Attachments/AttachmentHelper.php @@ -105,7 +105,7 @@ class AttachmentHelper implements AttachmentHelperInterface $count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count(); if ($count > 0) { - $msg = trans('validation.file_already_attached', ['name' => $name]); + $msg = (string)trans('validation.file_already_attached', ['name' => $name]); $this->errors->add('attachments', $msg); return true; @@ -151,7 +151,7 @@ class AttachmentHelper implements AttachmentHelperInterface $attachment->save(); $name = e($file->getClientOriginalName()); // add message: - $msg = trans('validation.file_attached', ['name' => $name]); + $msg = (string)trans('validation.file_attached', ['name' => $name]); $this->messages->add('attachments', $msg); // return it. @@ -171,7 +171,7 @@ class AttachmentHelper implements AttachmentHelperInterface $name = e($file->getClientOriginalName()); if (!in_array($mime, $this->allowedMimes)) { - $msg = trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]); + $msg = (string)trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]); $this->errors->add('attachments', $msg); return false; @@ -190,7 +190,7 @@ class AttachmentHelper implements AttachmentHelperInterface $size = $file->getSize(); $name = e($file->getClientOriginalName()); if ($size > $this->maxUploadSize) { - $msg = trans('validation.file_too_large', ['name' => $name]); + $msg = (string)trans('validation.file_too_large', ['name' => $name]); $this->errors->add('attachments', $msg); return false; diff --git a/app/Helpers/Csv/Specifix/AbnAmroDescription.php b/app/Helpers/Csv/Specifix/AbnAmroDescription.php index 1f47db072a..dac1899557 100644 --- a/app/Helpers/Csv/Specifix/AbnAmroDescription.php +++ b/app/Helpers/Csv/Specifix/AbnAmroDescription.php @@ -73,7 +73,7 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface if (preg_match('/ABN AMRO.{24} (.*)/', $this->data['description'], $matches)) { Log::debug('AbnAmroSpecifix: Description is structured as costs from ABN AMRO itself.'); - $this->data['opposing-account-name'] = "ABN AMRO"; + $this->data['opposing-account-name'] = 'ABN AMRO'; $this->data['description'] = $matches[1]; return true; @@ -117,22 +117,24 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface // SEPA plain descriptions contain several key-value pairs, split by a colon preg_match_all('/([A-Za-z]+(?=:\s)):\s([A-Za-z 0-9._#-]+(?=\s))/', $this->data['description'], $matches, PREG_SET_ORDER); - foreach ($matches as $match) { - $key = $match[1]; - $value = trim($match[2]); + if (is_array($matches)) { + foreach ($matches as $match) { + $key = $match[1]; + $value = trim($match[2]); - switch (strtoupper($key)) { - case 'OMSCHRIJVING': - $this->data['description'] = $value; - break; - case 'NAAM': - $this->data['opposing-account-name'] = $value; - break; - case 'IBAN': - $this->data['opposing-account-iban'] = $value; - break; - default: - // Ignore the rest + switch (strtoupper($key)) { + case 'OMSCHRIJVING': + $this->data['description'] = $value; + break; + case 'NAAM': + $this->data['opposing-account-name'] = $value; + break; + case 'IBAN': + $this->data['opposing-account-iban'] = $value; + break; + default: + // Ignore the rest + } } } @@ -153,26 +155,24 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface if (preg_match_all('!\/([A-Z]{3,4})\/([^/]*)!', $this->data['description'], $matches, PREG_SET_ORDER)) { Log::debug('AbnAmroSpecifix: Description is structured as TRTP format.'); - foreach ($matches as $match) { - $key = $match[1]; - $value = trim($match[2]); + if (is_array($matches)) { + foreach ($matches as $match) { + $key = $match[1]; + $value = trim($match[2]); - switch (strtoupper($key)) { - // is not being used. - // case 'TRTP': - // $type = $value; - // break; - case 'NAME': - $this->data['opposing-account-name'] = $value; - break; - case 'REMI': - $this->data['description'] = $value; - break; - case 'IBAN': - $this->data['opposing-account-iban'] = $value; - break; - default: - // Ignore the rest + switch (strtoupper($key)) { + case 'NAME': + $this->data['opposing-account-name'] = $value; + break; + case 'REMI': + $this->data['description'] = $value; + break; + case 'IBAN': + $this->data['opposing-account-iban'] = $value; + break; + default: + // Ignore the rest + } } } diff --git a/app/Helpers/FiscalHelperInterface.php b/app/Helpers/FiscalHelperInterface.php index 55fc8b7d5e..f4ec6fba1a 100644 --- a/app/Helpers/FiscalHelperInterface.php +++ b/app/Helpers/FiscalHelperInterface.php @@ -16,7 +16,7 @@ interface FiscalHelperInterface * This method produces a clone of the Carbon date object passed, checks preferences * and calculates the first day of the fiscal year. * - * @param Carbon $start + * @param Carbon $date * * @return Carbon date object */ @@ -30,6 +30,6 @@ interface FiscalHelperInterface * * @return Carbon date object */ - public function endOfFiscalYear(Carbon $start); + public function endOfFiscalYear(Carbon $date); } diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index bedafc34ca..e34284444f 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -91,7 +91,7 @@ class ReportHelper implements ReportHelperInterface ->groupBy('accounts.id') ->get(['accounts.id', DB::Raw('SUM(`transactions`.`amount`) as `balance`')]); - // and for end: + // and end: $endSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->whereIn('accounts.id', $ids) diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index fb248a267b..79c24d30c2 100755 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -111,7 +111,7 @@ class AuthController extends Controller // is user email domain blocked? if ($this->isBlockedDomain($data['email'])) { - $validator->getMessageBag()->add('email', trans('validation.invalid_domain')); + $validator->getMessageBag()->add('email', (string)trans('validation.invalid_domain')); $this->throwValidationException( $request, $validator ); diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 144cd44693..e86d95bb46 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -68,7 +68,7 @@ class BudgetController extends Controller Session::forget('budgets.create.fromStore'); Session::flash('gaEventCategory', 'budgets'); Session::flash('gaEventAction', 'create'); - $subTitle = trans('firefly.create_new_budget'); + $subTitle = (string)trans('firefly.create_new_budget'); return view('budgets.create', compact('subTitle')); } diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 6ae979f176..fed6bd4844 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -354,8 +354,8 @@ Breadcrumbs::register( 'reports.report', function (BreadCrumbGenerator $breadcrumbs, Carbon $start, Carbon $end, $reportType, $accountIds) { $breadcrumbs->parent('reports.index'); - $monthFormat = trans('config.month_and_day'); - $title = trans('firefly.report_' . $reportType, ['start' => $start->formatLocalized($monthFormat), 'end' => $end->formatLocalized($monthFormat)]); + $monthFormat = (string)trans('config.month_and_day'); + $title = (string)trans('firefly.report_' . $reportType, ['start' => $start->formatLocalized($monthFormat), 'end' => $end->formatLocalized($monthFormat)]); $breadcrumbs->push($title, route('reports.report', [$reportType, $start->format('Ymd'), $end->format('Ymd'), $accountIds])); } diff --git a/app/Models/Account.php b/app/Models/Account.php index ecfc6825ea..ee271f7f67 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1,6 +1,7 @@ 'required|exists:users,id', @@ -109,6 +112,22 @@ class Account extends Model return null; } + /** + * @param Account $value + * + * @return Account + */ + public static function routeBinder(Account $value) + { + + if (Auth::check()) { + if ($value->user_id == Auth::user()->id) { + return $value; + } + } + throw new NotFoundHttpException; + } + /** * @codeCoverageIgnore * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -284,20 +303,4 @@ class Account extends Model { return $this->belongsTo('FireflyIII\User'); } - - /** - * @param Account $value - * - * @return Account - */ - public static function routeBinder(Account $value) - { - - if (Auth::check()) { - if ($value->user_id == Auth::user()->id) { - return $value; - } - } - throw new NotFoundHttpException; - } } diff --git a/app/Models/Budget.php b/app/Models/Budget.php index ed72b0b1e8..7fccdec4f9 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -25,15 +25,16 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property-read User $user * @property string $dateFormatted * @property string $budgeted + * @property float $amount */ class Budget extends Model { use SoftDeletes; + protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'enddate']; protected $fillable = ['user_id', 'name', 'active']; protected $hidden = ['encrypted']; - protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'enddate']; /** * @param array $fields @@ -63,6 +64,21 @@ class Budget extends Model } + /** + * @param Budget $value + * + * @return Budget + */ + public static function routeBinder(Budget $value) + { + if (Auth::check()) { + if ($value->user_id == Auth::user()->id) { + return $value; + } + } + throw new NotFoundHttpException; + } + /** * * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -120,20 +136,5 @@ class Budget extends Model return $this->belongsTo('FireflyIII\User'); } - /** - * @param Budget $value - * - * @return Budget - */ - public static function routeBinder(Budget $value) - { - if (Auth::check()) { - if ($value->user_id == Auth::user()->id) { - return $value; - } - } - throw new NotFoundHttpException; - } - } diff --git a/app/Models/Category.php b/app/Models/Category.php index 84e79ae404..78f0611283 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -22,14 +22,15 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property-read Collection|TransactionJournal[] $transactionjournals * @property-read User $user * @property string $dateFormatted + * @property float $spent */ class Category extends Model { use SoftDeletes; + protected $dates = ['created_at', 'updated_at', 'deleted_at']; protected $fillable = ['user_id', 'name']; protected $hidden = ['encrypted']; - protected $dates = ['created_at', 'updated_at', 'deleted_at']; /** * @param array $fields @@ -59,6 +60,21 @@ class Category extends Model } + /** + * @param Category $value + * + * @return Category + */ + public static function routeBinder(Category $value) + { + if (Auth::check()) { + if ($value->user_id == Auth::user()->id) { + return $value; + } + } + throw new NotFoundHttpException; + } + /** * @codeCoverageIgnore * @@ -105,19 +121,4 @@ class Category extends Model return $this->belongsTo('FireflyIII\User'); } - /** - * @param Category $value - * - * @return Category - */ - public static function routeBinder(Category $value) - { - if (Auth::check()) { - if ($value->user_id == Auth::user()->id) { - return $value; - } - } - throw new NotFoundHttpException; - } - } diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php index bcb778f773..6cc57c28f9 100644 --- a/app/Models/LimitRepetition.php +++ b/app/Models/LimitRepetition.php @@ -16,29 +16,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property Carbon $enddate * @property float $amount * @property-read BudgetLimit $budgetLimit + * @property int $budget_id */ class LimitRepetition extends Model { - protected $hidden = ['amount_encrypted']; protected $dates = ['created_at', 'updated_at', 'startdate', 'enddate']; - - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function budgetLimit() - { - return $this->belongsTo('FireflyIII\Models\BudgetLimit'); - } - - /** - * @param $value - */ - public function setAmountAttribute($value) - { - $this->attributes['amount'] = strval(round($value, 2)); - } - + protected $hidden = ['amount_encrypted']; /** * @param $value @@ -60,4 +44,20 @@ class LimitRepetition extends Model throw new NotFoundHttpException; } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function budgetLimit() + { + return $this->belongsTo('FireflyIII\Models\BudgetLimit'); + } + + /** + * @param $value + */ + public function setAmountAttribute($value) + { + $this->attributes['amount'] = strval(round($value, 2)); + } + } diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index c69f4c02b7..b49f65bc3f 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -46,6 +46,9 @@ use Watson\Validating\ValidatingTrait; * @property-read TransactionType $transactionType * @property-read Collection|TransactionGroup[] $transactiongroups * @property-read User $user + * @property float $journalAmount + * @property int $account_id + * @property int $budget_id * @method static Builder|TransactionJournal accountIs($account) * @method static Builder|TransactionJournal after($date) * @method static Builder|TransactionJournal before($date) @@ -58,10 +61,10 @@ class TransactionJournal extends Model use SoftDeletes, ValidatingTrait; + protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at']; protected $fillable = ['user_id', 'transaction_type_id', 'bill_id', 'transaction_currency_id', 'description', 'completed', 'date', 'encrypted', 'tag_count']; protected $hidden = ['encrypted']; - protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at']; protected $rules = [ 'user_id' => 'required|exists:users,id', @@ -74,6 +77,36 @@ class TransactionJournal extends Model 'encrypted' => 'required|boolean', ]; + /** + * @param $value + * + * @return mixed + * @throws NotFoundHttpException + */ + public static function routeBinder($value) + { + if (Auth::check()) { + $validTypes = [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]; + $object = TransactionJournal::where('transaction_journals.id', $value) + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->whereIn('transaction_types.type', $validTypes) + ->where('user_id', Auth::user()->id)->first(['transaction_journals.*']); + if ($object) { + return $object; + } + } + + throw new NotFoundHttpException; + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\MorphMany + */ + public function attachments() + { + return $this->morphMany('FireflyIII\Models\Attachment', 'attachable'); + } + /** * @codeCoverageIgnore * @return \Illuminate\Database\Eloquent\Relations\BelongsTo @@ -101,22 +134,6 @@ class TransactionJournal extends Model return $this->belongsToMany('FireflyIII\Models\Category'); } - /** - * @return string - */ - public function getAmountPositiveAttribute() - { - $amount = '0'; - /** @var Transaction $t */ - foreach ($this->transactions as $t) { - if ($t->amount > 0) { - $amount = $t->amount; - } - } - - return $amount; - } - /** * @return float */ @@ -142,36 +159,19 @@ class TransactionJournal extends Model } /** - * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return string */ - public function tags() + public function getAmountPositiveAttribute() { - return $this->belongsToMany('FireflyIII\Models\Tag'); - } + $amount = '0'; + /** @var Transaction $t */ + foreach ($this->transactions as $t) { + if ($t->amount > 0) { + $amount = $t->amount; + } + } - /** - * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function transactions() - { - return $this->hasMany('FireflyIII\Models\Transaction'); - } - - /** - * Save the model to the database. - * - * @param array $options - * - * @return bool - */ - public function save(array $options = []) - { - $count = $this->tags()->count(); - $this->tag_count = $count; - - return parent::save($options); + return $amount; } /** @@ -210,6 +210,62 @@ class TransactionJournal extends Model return $account; } + /** + * @return string + */ + public function getTransactionType() + { + return $this->transactionType->type; + } + + /** + * @return bool + */ + public function isDeposit() + { + if (!is_null($this->type)) { + return $this->type == TransactionType::DEPOSIT; + } + + return $this->transactionType->isDeposit(); + } + + /** + * @return bool + */ + public function isOpeningBalance() + { + if (!is_null($this->type)) { + return $this->type == TransactionType::OPENING_BALANCE; + } + + return $this->transactionType->isOpeningBalance(); + } + + /** + * @return bool + */ + public function isTransfer() + { + if (!is_null($this->type)) { + return $this->type == TransactionType::TRANSFER; + } + + return $this->transactionType->isTransfer(); + } + + /** + * @return bool + */ + public function isWithdrawal() + { + if (!is_null($this->type)) { + return $this->type == TransactionType::WITHDRAWAL; + } + + return $this->transactionType->isWithdrawal(); + } + /** * @codeCoverageIgnore * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -219,6 +275,21 @@ class TransactionJournal extends Model return $this->hasMany('FireflyIII\Models\PiggyBankEvent'); } + /** + * Save the model to the database. + * + * @param array $options + * + * @return bool + */ + public function save(array $options = []) + { + $count = $this->tags()->count(); + $this->tag_count = $count; + + return parent::save($options); + } + /** * @codeCoverageIgnore * @@ -290,11 +361,12 @@ class TransactionJournal extends Model } /** - * @return \Illuminate\Database\Eloquent\Relations\MorphMany + * @codeCoverageIgnore + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function attachments() + public function tags() { - return $this->morphMany('FireflyIII\Models\Attachment', 'attachable'); + return $this->belongsToMany('FireflyIII\Models\Tag'); } /** @@ -324,6 +396,15 @@ class TransactionJournal extends Model return $this->belongsToMany('FireflyIII\Models\TransactionGroup'); } + /** + * @codeCoverageIgnore + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function transactions() + { + return $this->hasMany('FireflyIII\Models\Transaction'); + } + /** * @codeCoverageIgnore * @return \Illuminate\Database\Eloquent\Relations\BelongsTo @@ -332,82 +413,4 @@ class TransactionJournal extends Model { return $this->belongsTo('FireflyIII\User'); } - - /** - * @return string - */ - public function getTransactionType() - { - return $this->transactionType->type; - } - - /** - * @return bool - */ - public function isWithdrawal() - { - if (!is_null($this->type)) { - return $this->type == TransactionType::WITHDRAWAL; - } - - return $this->transactionType->isWithdrawal(); - } - - /** - * @return bool - */ - public function isDeposit() - { - if (!is_null($this->type)) { - return $this->type == TransactionType::DEPOSIT; - } - - return $this->transactionType->isDeposit(); - } - - /** - * @return bool - */ - public function isTransfer() - { - if (!is_null($this->type)) { - return $this->type == TransactionType::TRANSFER; - } - - return $this->transactionType->isTransfer(); - } - - /** - * @return bool - */ - public function isOpeningBalance() - { - if (!is_null($this->type)) { - return $this->type == TransactionType::OPENING_BALANCE; - } - - return $this->transactionType->isOpeningBalance(); - } - - /** - * @param $value - * - * @return mixed - * @throws NotFoundHttpException - */ - public static function routeBinder($value) - { - if (Auth::check()) { - $validTypes = [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]; - $object = TransactionJournal::where('transaction_journals.id', $value) - ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->whereIn('transaction_types.type', $validTypes) - ->where('user_id', Auth::user()->id)->first(['transaction_journals.*']); - if ($object) { - return $object; - } - } - - throw new NotFoundHttpException; - } }