mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Some small updates to various classes to support new stuff.
This commit is contained in:
@@ -17,7 +17,7 @@ class Account implements AccountInterface
|
||||
public function openingBalanceTransaction(\Account $account)
|
||||
{
|
||||
return \TransactionJournal::withRelevantData()
|
||||
->account($account)
|
||||
->accountIs($account)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=',
|
||||
'transaction_journals.transaction_type_id')
|
||||
->where('transaction_types.type', 'Opening balance')
|
||||
@@ -54,7 +54,7 @@ class Account implements AccountInterface
|
||||
// build a query:
|
||||
$query = \TransactionJournal::withRelevantData()
|
||||
->defaultSorting()
|
||||
->account($account)
|
||||
->accountIs($account)
|
||||
->after($start)
|
||||
->before($end);
|
||||
// filter some:
|
||||
@@ -110,16 +110,16 @@ class Account implements AccountInterface
|
||||
|
||||
|
||||
// statistics (transactions)
|
||||
$trIn = floatval(\Transaction::before($end)->after($start)->account($account)->moreThan(0)
|
||||
$trIn = floatval(\Transaction::before($end)->after($start)->accountIs($account)->moreThan(0)
|
||||
->transactionTypes(['Deposit', 'Withdrawal'])->sum('transactions.amount'));
|
||||
$trOut = floatval(\Transaction::before($end)->after($start)->account($account)->lessThan(0)
|
||||
$trOut = floatval(\Transaction::before($end)->after($start)->accountIs($account)->lessThan(0)
|
||||
->transactionTypes(['Deposit', 'Withdrawal'])->sum('transactions.amount'));
|
||||
$trDiff = $trIn + $trOut;
|
||||
|
||||
// statistics (transfers)
|
||||
$trfIn = floatval(\Transaction::before($end)->after($start)->account($account)->moreThan(0)
|
||||
$trfIn = floatval(\Transaction::before($end)->after($start)->accountIs($account)->moreThan(0)
|
||||
->transactionTypes(['Transfer'])->sum('transactions.amount'));
|
||||
$trfOut = floatval(\Transaction::before($end)->after($start)->account($account)->lessThan(0)
|
||||
$trfOut = floatval(\Transaction::before($end)->after($start)->accountIs($account)->lessThan(0)
|
||||
->transactionTypes(['Transfer'])->sum('transactions.amount'));
|
||||
$trfDiff = $trfIn + $trfOut;
|
||||
|
||||
|
@@ -3,6 +3,8 @@
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class Toolkit
|
||||
@@ -140,4 +142,41 @@ class Toolkit implements ToolkitInterface
|
||||
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes any collection and tries to make a sensible select list compatible array of it.
|
||||
*
|
||||
* @param Collection $set
|
||||
* @param null $titleField
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function makeSelectList(Collection $set, $titleField = null)
|
||||
{
|
||||
$selectList = [];
|
||||
/** @var Model $entry */
|
||||
foreach ($set as $entry) {
|
||||
$id = intval($entry->id);
|
||||
$title = null;
|
||||
if (is_null($titleField)) {
|
||||
// try 'title' field.
|
||||
if (isset($entry->title)) {
|
||||
$title = $entry->title;
|
||||
}
|
||||
// try 'name' field
|
||||
if (is_null($title)) {
|
||||
$title = $entry->name;
|
||||
}
|
||||
|
||||
// try 'description' field
|
||||
if (is_null($title)) {
|
||||
$title = $entry->description;
|
||||
}
|
||||
} else {
|
||||
$title = $entry->$titleField;
|
||||
}
|
||||
$selectList[$id] = $title;
|
||||
}
|
||||
return $selectList;
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface ToolkitInterface
|
||||
@@ -17,4 +18,14 @@ interface ToolkitInterface
|
||||
*/
|
||||
public function getDateRange();
|
||||
|
||||
/**
|
||||
* Takes any collection and tries to make a sensible select list compatible array of it.
|
||||
*
|
||||
* @param Collection $set
|
||||
* @param null $titleField
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function makeSelectList(Collection $set, $titleField = null);
|
||||
|
||||
}
|
Reference in New Issue
Block a user