Пример #1
0
 /**
  * @param $value
  * @param $route
  *
  * @return mixed
  */
 public static function routeBinder($value, $route) : Collection
 {
     if (auth()->check()) {
         $ids = explode(',', $value);
         /** @var \Illuminate\Support\Collection $object */
         $object = TransactionJournal::whereIn('transaction_journals.id', $ids)->expanded()->where('transaction_journals.user_id', auth()->user()->id)->get(TransactionJournal::queryFields());
         if ($object->count() > 0) {
             return $object;
         }
     }
     throw new NotFoundHttpException();
 }
Пример #2
0
 /**
  * This method will tell you if you still have a CC bill to pay. Amount will be positive if the amount
  * has been paid, otherwise it will be negative.
  *
  * @param Carbon $start
  * @param Carbon $end
  *
  * @return string
  */
 public function getCreditCardBill(Carbon $start, Carbon $end)
 {
     /** @var AccountRepositoryInterface $accountRepository */
     $accountRepository = app('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface');
     $amount = '0';
     $creditCards = $accountRepository->getCreditCards($end);
     // Find credit card accounts and possibly unpaid credit card bills.
     /** @var Account $creditCard */
     foreach ($creditCards as $creditCard) {
         if ($creditCard->balance == 0) {
             // find a transfer TO the credit card which should account for anything paid. If not, the CC is not yet used.
             $set = TransactionJournal::whereIn('transaction_journals.id', function (Builder $q) use($creditCard, $start, $end) {
                 $q->select('transaction_journals.id')->from('transactions')->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->where('transactions.account_id', $creditCard->id)->where('transactions.amount', '>', 0)->where('transaction_journals.user_id', Auth::user()->id)->where('transaction_journals.date', '>=', $start->format('Y-m-d'))->where('transaction_journals.date', '<=', $end->format('Y-m-d'))->where('transaction_types.type', TransactionType::TRANSFER);
             })->leftJoin('transactions', function (JoinClause $join) {
                 $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0);
             })->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
             $amount = bcadd($amount, $set->sum_amount);
         } else {
             $amount = bcadd($amount, $creditCard->balance);
         }
     }
     return $amount;
 }
Пример #3
0
 /**
  * Get all transfers TO this account in this range.
  *
  * @param Account $account
  * @param Carbon  $start
  * @param Carbon  $end
  *
  * @return Collection
  */
 public function getTransfersInRange(Account $account, Carbon $start, Carbon $end)
 {
     $set = TransactionJournal::whereIn('id', function (Builder $q) use($account, $start, $end) {
         $q->select('transaction_journals.id')->from('transactions')->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->where('transactions.account_id', $account->id)->where('transaction_journals.user_id', Auth::user()->id)->where('transaction_journals.date', '>=', $start->format('Y-m-d'))->where('transaction_journals.date', '<=', $end->format('Y-m-d'))->where('transaction_types.type', 'Transfer');
     })->get();
     $filtered = $set->filter(function (TransactionJournal $journal) use($account) {
         if ($journal->destination_account->id == $account->id) {
             return $journal;
         }
         return null;
     });
     return $filtered;
 }