mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Final touches for the balance and transactions.
This commit is contained in:
@@ -331,17 +331,21 @@ class AccountFactory
|
|||||||
*/
|
*/
|
||||||
private function storeCreditLiability(Account $account, array $data)
|
private function storeCreditLiability(Account $account, array $data)
|
||||||
{
|
{
|
||||||
|
Log::debug('storeCreditLiability');
|
||||||
$account->refresh();
|
$account->refresh();
|
||||||
$accountType = $account->accountType->type;
|
$accountType = $account->accountType->type;
|
||||||
$direction = $this->accountRepository->getMetaValue($account, 'liability_direction');
|
$direction = $this->accountRepository->getMetaValue($account, 'liability_direction');
|
||||||
$valid = config('firefly.valid_liabilities');
|
$valid = config('firefly.valid_liabilities');
|
||||||
if (in_array($accountType, $valid, true) && 'credit' === $direction) {
|
if (in_array($accountType, $valid, true) && 'credit' === $direction) {
|
||||||
|
Log::debug('Is a liability with credit direction.');
|
||||||
if ($this->validOBData($data)) {
|
if ($this->validOBData($data)) {
|
||||||
|
Log::debug('Has valid CL data.');
|
||||||
$openingBalance = $data['opening_balance'];
|
$openingBalance = $data['opening_balance'];
|
||||||
$openingBalanceDate = $data['opening_balance_date'];
|
$openingBalanceDate = $data['opening_balance_date'];
|
||||||
$this->updateCreditTransaction($account, $openingBalance, $openingBalanceDate);
|
$this->updateCreditTransaction($account, $openingBalance, $openingBalanceDate);
|
||||||
}
|
}
|
||||||
if (!$this->validOBData($data)) {
|
if (!$this->validOBData($data)) {
|
||||||
|
Log::debug('Has NOT valid CL data.');
|
||||||
$this->deleteCreditTransaction($account);
|
$this->deleteCreditTransaction($account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,10 +45,8 @@ class EditController extends Controller
|
|||||||
use ModelInformation;
|
use ModelInformation;
|
||||||
|
|
||||||
private AttachmentHelperInterface $attachments;
|
private AttachmentHelperInterface $attachments;
|
||||||
/** @var CurrencyRepositoryInterface The currency repository */
|
private CurrencyRepositoryInterface $currencyRepos;
|
||||||
private $currencyRepos;
|
private AccountRepositoryInterface $repository;
|
||||||
/** @var AccountRepositoryInterface The account repository */
|
|
||||||
private $repository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EditController constructor.
|
* EditController constructor.
|
||||||
@@ -106,6 +104,11 @@ class EditController extends Controller
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$liabilityDirections = [
|
||||||
|
'debit' => trans('firefly.liability_direction_debit'),
|
||||||
|
'credit' => trans('firefly.liability_direction_credit'),
|
||||||
|
];
|
||||||
|
|
||||||
// interest calculation periods:
|
// interest calculation periods:
|
||||||
$interestPeriods = [
|
$interestPeriods = [
|
||||||
'daily' => (string)trans('firefly.interest_calc_daily'),
|
'daily' => (string)trans('firefly.interest_calc_daily'),
|
||||||
@@ -119,7 +122,7 @@ class EditController extends Controller
|
|||||||
}
|
}
|
||||||
$request->session()->forget('accounts.edit.fromUpdate');
|
$request->session()->forget('accounts.edit.fromUpdate');
|
||||||
|
|
||||||
$openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account);
|
$openingBalanceAmount = app('steam')->positive((string)$repository->getOpeningBalanceAmount($account));
|
||||||
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
|
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
|
||||||
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||||
|
|
||||||
@@ -138,6 +141,7 @@ class EditController extends Controller
|
|||||||
'opening_balance_date' => $openingBalanceDate,
|
'opening_balance_date' => $openingBalanceDate,
|
||||||
'liability_type_id' => $account->account_type_id,
|
'liability_type_id' => $account->account_type_id,
|
||||||
'opening_balance' => $openingBalanceAmount,
|
'opening_balance' => $openingBalanceAmount,
|
||||||
|
'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'),
|
||||||
'virtual_balance' => $account->virtual_balance,
|
'virtual_balance' => $account->virtual_balance,
|
||||||
'currency_id' => $currency->id,
|
'currency_id' => $currency->id,
|
||||||
'include_net_worth' => $includeNetWorth,
|
'include_net_worth' => $includeNetWorth,
|
||||||
@@ -157,6 +161,7 @@ class EditController extends Controller
|
|||||||
'subTitle',
|
'subTitle',
|
||||||
'subTitleIcon',
|
'subTitleIcon',
|
||||||
'locations',
|
'locations',
|
||||||
|
'liabilityDirections',
|
||||||
'objectType',
|
'objectType',
|
||||||
'roles',
|
'roles',
|
||||||
'preFilled',
|
'preFilled',
|
||||||
|
@@ -103,7 +103,7 @@ class IndexController extends Controller
|
|||||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||||
$account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 6, '.', '');
|
$account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 4, '.', '');
|
||||||
$account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
|
$account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
|
||||||
$account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));
|
$account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ class IndexController extends Controller
|
|||||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||||
$account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 6, '.', '');
|
$account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 4, '.', '');
|
||||||
$account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
|
$account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
|
||||||
$account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));
|
$account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));
|
||||||
$account->location = $this->repository->getLocation($account);
|
$account->location = $this->repository->getLocation($account);
|
||||||
|
@@ -226,6 +226,24 @@ trait AccountServiceTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete TransactionGroup with liability credit in it.
|
||||||
|
*
|
||||||
|
* @param Account $account
|
||||||
|
*/
|
||||||
|
protected function deleteCreditTransaction(Account $account): void
|
||||||
|
{
|
||||||
|
Log::debug(sprintf('deleteCreditTransaction() for account #%d', $account->id));
|
||||||
|
$creditGroup = $this->getCreditTransaction($account);
|
||||||
|
|
||||||
|
if (null !== $creditGroup) {
|
||||||
|
Log::debug('Credit journal found, delete journal.');
|
||||||
|
/** @var TransactionGroupDestroyService $service */
|
||||||
|
$service = app(TransactionGroupDestroyService::class);
|
||||||
|
$service->destroy($creditGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the opening balance group, or NULL if it does not exist.
|
* Returns the opening balance group, or NULL if it does not exist.
|
||||||
*
|
*
|
||||||
|
@@ -306,20 +306,25 @@ class AccountUpdateService
|
|||||||
*/
|
*/
|
||||||
private function updateCreditLiability(Account $account, array $data): void
|
private function updateCreditLiability(Account $account, array $data): void
|
||||||
{
|
{
|
||||||
$type = $account->accountType;
|
$type = $account->accountType;
|
||||||
$valid = config('firefly.valid_liabilities');
|
$valid = config('firefly.valid_liabilities');
|
||||||
if (in_array($type->type, $valid, true)) {
|
if (in_array($type->type, $valid, true)) {
|
||||||
|
$direction = array_key_exists('liability_direction', $data) ? $data['liability_direction'] : 'empty';
|
||||||
// check if is submitted as empty, that makes it valid:
|
// check if is submitted as empty, that makes it valid:
|
||||||
if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {
|
if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {
|
||||||
$openingBalance = $data['opening_balance'];
|
$openingBalance = $data['opening_balance'];
|
||||||
$openingBalanceDate = $data['opening_balance_date'];
|
$openingBalanceDate = $data['opening_balance_date'];
|
||||||
|
if ('credit' === $data['liability_direction']) {
|
||||||
$this->updateCreditTransaction($account, $openingBalance, $openingBalanceDate);
|
$this->updateCreditTransaction($account, $openingBalance, $openingBalanceDate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {
|
if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {
|
||||||
$this->deleteCreditTransaction($account);
|
$this->deleteCreditTransaction($account);
|
||||||
}
|
}
|
||||||
|
if ($this->validOBData($data) && !$this->isEmptyOBData($data) && 'credit' !== $direction) {
|
||||||
|
$this->deleteCreditTransaction($account);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
{% if objectType == 'liabilities' %}
|
{% if objectType == 'liabilities' %}
|
||||||
{{ ExpandedForm.select('liability_type_id', liabilityTypes) }}
|
{{ ExpandedForm.select('liability_type_id', liabilityTypes) }}
|
||||||
{{ ExpandedForm.amountNoCurrency('opening_balance', null, {label:'debt_start_amount'|_, helpText: 'debt_start_amount_help'|_}) }}
|
{{ ExpandedForm.amountNoCurrency('opening_balance', null, {label:'debt_start_amount'|_, helpText: 'debt_start_amount_help'|_}) }}
|
||||||
|
{{ ExpandedForm.select('liability_direction', liabilityDirections) }}
|
||||||
{{ ExpandedForm.date('opening_balance_date', null, {label:'debt_start_date'|_}) }}
|
{{ ExpandedForm.date('opening_balance_date', null, {label:'debt_start_date'|_}) }}
|
||||||
{{ ExpandedForm.percentage('interest') }}
|
{{ ExpandedForm.percentage('interest') }}
|
||||||
{{ ExpandedForm.select('interest_period', interestPeriods) }}
|
{{ ExpandedForm.select('interest_period', interestPeriods) }}
|
||||||
|
Reference in New Issue
Block a user