mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -94,14 +94,14 @@ trait AccountServiceTrait
|
||||
*/
|
||||
public function updateMetaData(Account $account, array $data): void
|
||||
{
|
||||
$fields = $this->validFields;
|
||||
$fields = $this->validFields;
|
||||
if (AccountType::ASSET === $account->accountType->type) {
|
||||
$fields = $this->validAssetFields;
|
||||
}
|
||||
|
||||
// remove currency_id if necessary.
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
if (!in_array($type, $list, true)) {
|
||||
$pos = array_search('currency_id', $fields, true);
|
||||
if (false !== $pos) {
|
||||
@@ -150,7 +150,7 @@ trait AccountServiceTrait
|
||||
|
||||
public function updateNote(Account $account, string $note): bool
|
||||
{
|
||||
$dbNote = $account->notes()->first();
|
||||
$dbNote = $account->notes()->first();
|
||||
if ('' === $note) {
|
||||
if (null !== $dbNote) {
|
||||
$dbNote->delete();
|
||||
@@ -196,7 +196,7 @@ trait AccountServiceTrait
|
||||
protected function createOBGroup(Account $account, array $data): TransactionGroup
|
||||
{
|
||||
app('log')->debug('Now going to create an OB group.');
|
||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||
if (is_array($language)) {
|
||||
$language = 'en_US';
|
||||
}
|
||||
@@ -227,10 +227,10 @@ trait AccountServiceTrait
|
||||
}
|
||||
|
||||
// make amount positive, regardless:
|
||||
$amount = app('steam')->positive($amount);
|
||||
$amount = app('steam')->positive($amount);
|
||||
|
||||
// get or grab currency:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
@@ -268,7 +268,7 @@ trait AccountServiceTrait
|
||||
app('log')->debug('Going for submission in createOBGroup', $submission);
|
||||
|
||||
/** @var TransactionGroupFactory $factory */
|
||||
$factory = app(TransactionGroupFactory::class);
|
||||
$factory = app(TransactionGroupFactory::class);
|
||||
$factory->setUser($account->user);
|
||||
|
||||
try {
|
||||
@@ -343,10 +343,10 @@ trait AccountServiceTrait
|
||||
{
|
||||
// find currency, or use default currency instead.
|
||||
/** @var TransactionCurrencyFactory $factory */
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
|
||||
/** @var null|TransactionCurrency $currency */
|
||||
$currency = $factory->find($currencyId, $currencyCode);
|
||||
$currency = $factory->find($currencyId, $currencyCode);
|
||||
|
||||
if (null === $currency) {
|
||||
// use default currency:
|
||||
@@ -374,7 +374,7 @@ trait AccountServiceTrait
|
||||
}
|
||||
// if direction is "debit" (i owe this debt), amount is negative.
|
||||
// which means the liability will have a negative balance which the user must fill.
|
||||
$openingBalance = app('steam')->negative($openingBalance);
|
||||
$openingBalance = app('steam')->negative($openingBalance);
|
||||
|
||||
// if direction is "credit" (I am owed this debt), amount is positive.
|
||||
// which means the liability will have a positive balance which is drained when its paid back into any asset.
|
||||
@@ -383,21 +383,21 @@ trait AccountServiceTrait
|
||||
}
|
||||
|
||||
// create if not exists:
|
||||
$clGroup = $this->getCreditTransaction($account);
|
||||
$clGroup = $this->getCreditTransaction($account);
|
||||
if (null === $clGroup) {
|
||||
return $this->createCreditTransaction($account, $openingBalance, $openingBalanceDate);
|
||||
}
|
||||
// if exists, update:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
|
||||
// simply grab the first journal and change it:
|
||||
$journal = $this->getObJournal($clGroup);
|
||||
$clTransaction = $this->getOBTransaction($journal, $account);
|
||||
$accountTransaction = $this->getNotOBTransaction($journal, $account);
|
||||
$journal->date = $openingBalanceDate;
|
||||
$journal = $this->getObJournal($clGroup);
|
||||
$clTransaction = $this->getOBTransaction($journal, $account);
|
||||
$accountTransaction = $this->getNotOBTransaction($journal, $account);
|
||||
$journal->date = $openingBalanceDate;
|
||||
$journal->transactionCurrency()->associate($currency);
|
||||
|
||||
// account always gains money:
|
||||
@@ -405,8 +405,8 @@ trait AccountServiceTrait
|
||||
$accountTransaction->transaction_currency_id = $currency->id;
|
||||
|
||||
// CL account always loses money:
|
||||
$clTransaction->amount = app('steam')->negative($openingBalance);
|
||||
$clTransaction->transaction_currency_id = $currency->id;
|
||||
$clTransaction->amount = app('steam')->negative($openingBalance);
|
||||
$clTransaction->transaction_currency_id = $currency->id;
|
||||
// save both
|
||||
$accountTransaction->save();
|
||||
$clTransaction->save();
|
||||
@@ -429,11 +429,11 @@ trait AccountServiceTrait
|
||||
throw new FireflyException('Amount for new liability credit was unexpectedly 0.');
|
||||
}
|
||||
|
||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||
if (is_array($language)) {
|
||||
$language = 'en_US';
|
||||
}
|
||||
$language = (string)$language;
|
||||
$language = (string)$language;
|
||||
|
||||
// set source and/or destination based on whether the amount is positive or negative.
|
||||
// first, assume the amount is positive and go from there:
|
||||
@@ -451,10 +451,10 @@ trait AccountServiceTrait
|
||||
}
|
||||
|
||||
// amount must be positive for the transaction to work.
|
||||
$amount = app('steam')->positive($openingBalance);
|
||||
$amount = app('steam')->positive($openingBalance);
|
||||
|
||||
// get or grab currency:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
@@ -492,7 +492,7 @@ trait AccountServiceTrait
|
||||
app('log')->debug('Going for submission in createCreditTransaction', $submission);
|
||||
|
||||
/** @var TransactionGroupFactory $factory */
|
||||
$factory = app(TransactionGroupFactory::class);
|
||||
$factory = app(TransactionGroupFactory::class);
|
||||
$factory->setUser($account->user);
|
||||
|
||||
try {
|
||||
@@ -517,14 +517,14 @@ trait AccountServiceTrait
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
// create if not exists:
|
||||
$obGroup = $this->getOBGroup($account);
|
||||
$obGroup = $this->getOBGroup($account);
|
||||
if (null === $obGroup) {
|
||||
return $this->createOBGroupV2($account, $openingBalance, $openingBalanceDate);
|
||||
}
|
||||
app('log')->debug('Update OB group');
|
||||
|
||||
// if exists, update:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
@@ -544,8 +544,8 @@ trait AccountServiceTrait
|
||||
$accountTransaction->transaction_currency_id = $currency->id;
|
||||
|
||||
// OB account transaction gains money
|
||||
$obTransaction->amount = app('steam')->positive($openingBalance);
|
||||
$obTransaction->transaction_currency_id = $currency->id;
|
||||
$obTransaction->amount = app('steam')->positive($openingBalance);
|
||||
$obTransaction->transaction_currency_id = $currency->id;
|
||||
}
|
||||
if (-1 === bccomp('0', $openingBalance)) {
|
||||
app('log')->debug('Amount is positive.');
|
||||
@@ -554,8 +554,8 @@ trait AccountServiceTrait
|
||||
$accountTransaction->transaction_currency_id = $currency->id;
|
||||
|
||||
// OB account loses money:
|
||||
$obTransaction->amount = app('steam')->negative($openingBalance);
|
||||
$obTransaction->transaction_currency_id = $currency->id;
|
||||
$obTransaction->amount = app('steam')->negative($openingBalance);
|
||||
$obTransaction->transaction_currency_id = $currency->id;
|
||||
}
|
||||
// save both
|
||||
$accountTransaction->save();
|
||||
@@ -572,7 +572,7 @@ trait AccountServiceTrait
|
||||
protected function createOBGroupV2(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
|
||||
{
|
||||
app('log')->debug('Now going to create an OB group.');
|
||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||
if (is_array($language)) {
|
||||
$language = 'en_US';
|
||||
}
|
||||
@@ -602,10 +602,10 @@ trait AccountServiceTrait
|
||||
}
|
||||
|
||||
// make amount positive, regardless:
|
||||
$amount = app('steam')->positive($openingBalance);
|
||||
$amount = app('steam')->positive($openingBalance);
|
||||
|
||||
// get or grab currency:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
@@ -643,7 +643,7 @@ trait AccountServiceTrait
|
||||
app('log')->debug('Going for submission in createOBGroupV2', $submission);
|
||||
|
||||
/** @var TransactionGroupFactory $factory */
|
||||
$factory = app(TransactionGroupFactory::class);
|
||||
$factory = app(TransactionGroupFactory::class);
|
||||
$factory->setUser($account->user);
|
||||
|
||||
try {
|
||||
|
Reference in New Issue
Block a user