mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some code cleanup.
This commit is contained in:
@@ -97,37 +97,43 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
*/
|
||||
public function storeInitialBalance(\Account $account, array $data)
|
||||
{
|
||||
|
||||
// make opposing a revenue / expense account depending on bla bla.
|
||||
$balance = floatval($data['openingBalance']);
|
||||
$date = new Carbon($data['openingBalanceDate']);
|
||||
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journals */
|
||||
$journals = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */
|
||||
$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journals */
|
||||
$journals = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
|
||||
|
||||
// some initial variables:
|
||||
$balance = floatval($data['openingBalance']);
|
||||
$date = new Carbon($data['openingBalanceDate']);
|
||||
|
||||
// some dynamic variables:
|
||||
if ($balance < 0) {
|
||||
// to is expense account.
|
||||
$opposingData = ['name' => $account->name . ' Initial Balance Account', 'active' => 1, 'what' => 'expense'];
|
||||
$toAccount = $this->store($opposingData);
|
||||
$fromAccount = $account;
|
||||
$type = $typeRepository->findByWhat('withdrawal');
|
||||
$opposingType = 'expense';
|
||||
$transactionType = $typeRepository->findByWhat('withdrawal');
|
||||
$toAccount = $this->store(['name' => $account->name . ' Initial Balance Account', 'active' => 1, 'what' => $opposingType]);
|
||||
$fromAccount = $account;
|
||||
} else {
|
||||
// from is revenue account.
|
||||
$opposingData = ['name' => $account->name . ' Initial Balance Account', 'active' => 1, 'what' => 'revenue'];
|
||||
$fromAccount = $this->store($opposingData);
|
||||
$toAccount = $account;
|
||||
$type = $typeRepository->findByWhat('deposit');
|
||||
$opposingType = 'revenue';
|
||||
$transactionType = $typeRepository->findByWhat('deposit');
|
||||
$fromAccount = $this->store(['name' => $account->name . ' Initial Balance Account', 'active' => 1, 'what' => $opposingType]);
|
||||
$toAccount = $account;
|
||||
}
|
||||
|
||||
// data for transaction journal:
|
||||
$balance = $balance < 0 ? $balance * -1 : $balance;
|
||||
$currency = $journals->getJournalCurrencyById(intval($data['balance_currency_id']));
|
||||
|
||||
$opening = ['transaction_type_id' => $type->id, 'transaction_currency_id' => $currency->id, 'amount' => $balance, 'from' => $fromAccount,
|
||||
'completed' => 0, 'what' => 'opening', 'to' => $toAccount, 'date' => $date,
|
||||
'description' => 'Opening balance for new account ' . $account->name,];
|
||||
$opening = [
|
||||
'transaction_type_id' => $transactionType->id,
|
||||
'transaction_currency_id' => $currency->id,
|
||||
'amount' => $balance,
|
||||
'from' => $fromAccount,
|
||||
'completed' => 0,
|
||||
'what' => 'opening',
|
||||
'to' => $toAccount,
|
||||
'date' => $date,
|
||||
'description' => 'Opening balance for new account ' . $account->name
|
||||
];
|
||||
|
||||
$validation = $journals->validate($opening);
|
||||
if ($validation['errors']->count() == 0) {
|
||||
|
||||
@@ -76,6 +76,8 @@ class PiggyBankShared
|
||||
/**
|
||||
* @param array $ids
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return Collection
|
||||
* @throws NotImplementedException
|
||||
* @codeCoverageIgnore
|
||||
@@ -108,7 +110,6 @@ class PiggyBankShared
|
||||
* @param array $data
|
||||
*
|
||||
* @return \Eloquent
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ class Form
|
||||
$options['step'] = 'any';
|
||||
$options['min'] = '0.01';
|
||||
$defaultCurrency = isset($options['currency']) ? $options['currency'] : \Amount::getDefaultCurrency();
|
||||
$currencies = \TransactionCurrency::orderBy('code','ASC')->get();
|
||||
$currencies = \TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||
$html = \View::make('form.amount', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
||||
|
||||
return $html;
|
||||
@@ -141,8 +141,9 @@ class Form
|
||||
$value = self::fillFieldValue($name, $value);
|
||||
$options['step'] = 'any';
|
||||
$defaultCurrency = isset($options['currency']) ? $options['currency'] : \Amount::getDefaultCurrency();
|
||||
$currencies = \TransactionCurrency::orderBy('code','ASC')->get();
|
||||
$currencies = \TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||
$html = \View::make('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,9 +59,7 @@ class Related implements RelatedInterface
|
||||
/** @var Collection $collection */
|
||||
$collection = $this->getUser()->transactionjournals()
|
||||
->withRelevantData()
|
||||
->before($end)
|
||||
->where('encrypted', 0)
|
||||
->after($start)
|
||||
->before($end)->after($start)->where('encrypted', 0)
|
||||
->whereNotIn('id', $exclude)
|
||||
->where('description', 'LIKE', '%' . $query . '%')
|
||||
->get();
|
||||
@@ -70,9 +68,8 @@ class Related implements RelatedInterface
|
||||
/** @var Collection $encryptedCollection */
|
||||
$encryptedCollection = $this->getUser()->transactionjournals()
|
||||
->withRelevantData()
|
||||
->before($end)
|
||||
->before($end)->after($start)
|
||||
->where('encrypted', 1)
|
||||
->after($start)
|
||||
->whereNotIn('id', $exclude)
|
||||
->get();
|
||||
$encrypted = $encryptedCollection->filter(
|
||||
@@ -81,11 +78,11 @@ class Related implements RelatedInterface
|
||||
if ($strPos !== false) {
|
||||
return $journal;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
$collected = $collection->merge($encrypted);
|
||||
|
||||
|
||||
return $collected;
|
||||
return $collection->merge($encrypted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,13 +364,12 @@ class Report implements ReportInterface
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function revenueGroupedByAccount(Carbon $start, Carbon $end, $limit = 15)
|
||||
public function revenueGroupedByAccount(Carbon $start, Carbon $end)
|
||||
{
|
||||
return $this->_queries->journalsByRevenueAccount($start, $end, $limit);
|
||||
return $this->_queries->journalsByRevenueAccount($start, $end);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -94,11 +94,10 @@ interface ReportInterface
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function revenueGroupedByAccount(Carbon $start, Carbon $end, $limit = 15);
|
||||
public function revenueGroupedByAccount(Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
|
||||
@@ -404,11 +404,10 @@ class ReportQuery implements ReportQueryInterface
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function journalsByRevenueAccount(Carbon $start, Carbon $end, $limit = 15)
|
||||
public function journalsByRevenueAccount(Carbon $start, Carbon $end)
|
||||
{
|
||||
return \TransactionJournal::
|
||||
leftJoin(
|
||||
|
||||
Reference in New Issue
Block a user