Various code cleanup.

This commit is contained in:
James Cole
2016-04-27 19:21:47 +02:00
parent 84f299c33b
commit e3437ba697
9 changed files with 154 additions and 107 deletions

View File

@@ -20,31 +20,6 @@ use Session;
class ExpandedForm
{
/**
* @param $name
* @param null $value
* @param array $options
*
* @return string
*/
public function amountSmall(string $name, $value = null, array $options = []): string
{
$label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value);
$options['step'] = 'any';
$options['min'] = '0.01';
$defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency();
$currencies = Amt::getAllCurrencies();
unset($options['currency']);
unset($options['placeholder']);
$html = view('form.amount-small', compact('defaultCurrency', 'currencies', 'classes', 'name', 'value', 'options'))->render();
return $html;
}
/**
* @param $name
* @param null $value
@@ -70,6 +45,31 @@ class ExpandedForm
}
/**
* @param $name
* @param null $value
* @param array $options
*
* @return string
*/
public function amountSmall(string $name, $value = null, array $options = []): string
{
$label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value);
$options['step'] = 'any';
$options['min'] = '0.01';
$defaultCurrency = isset($options['currency']) ? $options['currency'] : Amt::getDefaultCurrency();
$currencies = Amt::getAllCurrencies();
unset($options['currency']);
unset($options['placeholder']);
$html = view('form.amount-small', compact('defaultCurrency', 'currencies', 'classes', 'name', 'value', 'options'))->render();
return $html;
}
/**
* @param $name
* @param null $value
@@ -196,17 +196,38 @@ class ExpandedForm
* Takes any collection and tries to make a sensible select list compatible array of it.
*
* @param \Illuminate\Support\Collection $set
* @param bool $addEmpty
*
* @return array
*/
public function makeSelectList(Collection $set, bool $addEmpty = false): array
public function makeSelectList(Collection $set): array
{
$selectList = [];
if ($addEmpty) {
$selectList[0] = '(none)';
$fields = ['title', 'name', 'description'];
/** @var Eloquent $entry */
foreach ($set as $entry) {
$entryId = intval($entry->id);
$title = null;
foreach ($fields as $field) {
if (isset($entry->$field) && is_null($title)) {
$title = $entry->$field;
}
}
$selectList[$entryId] = $title;
}
$fields = ['title', 'name', 'description'];
return $selectList;
}
/**
* @param Collection $set
*
* @return array
*/
public function makeSelectListWithEmpty(Collection $set): array
{
$selectList[0] = '(none)';
$fields = ['title', 'name', 'description'];
/** @var Eloquent $entry */
foreach ($set as $entry) {
$entryId = intval($entry->id);

View File

@@ -16,7 +16,6 @@ use FireflyIII\Models\Transaction;
*/
class Steam
{
/**
*
* @param \FireflyIII\Models\Account $account
@@ -43,10 +42,39 @@ class Steam
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
);
$balance = bcadd($balance, $account->virtual_balance);
$cache->store($balance);
if (!$ignoreVirtualBalance) {
$balance = bcadd($balance, $account->virtual_balance);
return $balance;
}
/**
*
* @param \FireflyIII\Models\Account $account
* @param \Carbon\Carbon $date
* @param bool $ignoreVirtualBalance
*
* @return string
*/
public function balanceIgnoreVirtual(Account $account, Carbon $date, $ignoreVirtualBalance = false): string
{
// abuse chart properties:
$cache = new CacheProperties;
$cache->addProperty($account->id);
$cache->addProperty('balance-no-virtual');
$cache->addProperty($date);
$cache->addProperty($ignoreVirtualBalance);
if ($cache->has()) {
return $cache->get();
}
$balance = strval(
$account->transactions()->leftJoin(
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
);
$cache->store($balance);
return $balance;