mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Merge branch 'feature/credit_calc' into develop
This commit is contained in:
@@ -80,14 +80,14 @@ class CreateController extends Controller
|
||||
*/
|
||||
public function create(Request $request, string $objectType = null)
|
||||
{
|
||||
$objectType = $objectType ?? 'asset';
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
|
||||
$subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType));
|
||||
$roles = $this->getRoles();
|
||||
$liabilityTypes = $this->getLiabilityTypes();
|
||||
$hasOldInput = null !== $request->old('_token');
|
||||
$locations = [
|
||||
$objectType = $objectType ?? 'asset';
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
|
||||
$subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType));
|
||||
$roles = $this->getRoles();
|
||||
$liabilityTypes = $this->getLiabilityTypes();
|
||||
$hasOldInput = null !== $request->old('_token');
|
||||
$locations = [
|
||||
'location' => [
|
||||
'latitude' => $hasOldInput ? old('location_latitude') : config('firefly.default_location.latitude'),
|
||||
'longitude' => $hasOldInput ? old('location_longitude') : config('firefly.default_location.longitude'),
|
||||
@@ -95,6 +95,10 @@ class CreateController extends Controller
|
||||
'has_location' => $hasOldInput ? 'true' === old('location_has_location') : false,
|
||||
],
|
||||
];
|
||||
$liabilityDirections = [
|
||||
'debit' => trans('firefly.liability_direction_debit'),
|
||||
'credit' => trans('firefly.liability_direction_credit'),
|
||||
];
|
||||
|
||||
// interest calculation periods:
|
||||
$interestPeriods = [
|
||||
@@ -119,7 +123,10 @@ class CreateController extends Controller
|
||||
$request->session()->forget('accounts.create.fromStore');
|
||||
Log::channel('audit')->info('Creating new account.');
|
||||
|
||||
return prefixView('accounts.create', compact('subTitleIcon', 'locations', 'objectType', 'interestPeriods', 'subTitle', 'roles', 'liabilityTypes'));
|
||||
return prefixView(
|
||||
'accounts.create',
|
||||
compact('subTitleIcon', 'liabilityDirections', 'locations', 'objectType', 'interestPeriods', 'subTitle', 'roles', 'liabilityTypes')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +163,7 @@ class CreateController extends Controller
|
||||
}
|
||||
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
|
@@ -45,10 +45,8 @@ class EditController extends Controller
|
||||
use ModelInformation;
|
||||
|
||||
private AttachmentHelperInterface $attachments;
|
||||
/** @var CurrencyRepositoryInterface The currency repository */
|
||||
private $currencyRepos;
|
||||
/** @var AccountRepositoryInterface The account repository */
|
||||
private $repository;
|
||||
private CurrencyRepositoryInterface $currencyRepos;
|
||||
private AccountRepositoryInterface $repository;
|
||||
|
||||
/**
|
||||
* 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:
|
||||
$interestPeriods = [
|
||||
'daily' => (string)trans('firefly.interest_calc_daily'),
|
||||
@@ -119,7 +122,10 @@ class EditController extends Controller
|
||||
}
|
||||
$request->session()->forget('accounts.edit.fromUpdate');
|
||||
|
||||
$openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account);
|
||||
$openingBalanceAmount = app('steam')->positive((string)$repository->getOpeningBalanceAmount($account));
|
||||
if('0' === $openingBalanceAmount) {
|
||||
$openingBalanceAmount = '';
|
||||
}
|
||||
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
|
||||
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||
|
||||
@@ -138,6 +144,7 @@ class EditController extends Controller
|
||||
'opening_balance_date' => $openingBalanceDate,
|
||||
'liability_type_id' => $account->account_type_id,
|
||||
'opening_balance' => $openingBalanceAmount,
|
||||
'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'),
|
||||
'virtual_balance' => $account->virtual_balance,
|
||||
'currency_id' => $currency->id,
|
||||
'include_net_worth' => $includeNetWorth,
|
||||
@@ -157,6 +164,7 @@ class EditController extends Controller
|
||||
'subTitle',
|
||||
'subTitleIcon',
|
||||
'locations',
|
||||
'liabilityDirections',
|
||||
'objectType',
|
||||
'roles',
|
||||
'preFilled',
|
||||
|
@@ -103,7 +103,7 @@ class IndexController extends Controller
|
||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||
$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->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));
|
||||
}
|
||||
@@ -160,14 +160,16 @@ class IndexController extends Controller
|
||||
$accounts->each(
|
||||
function (Account $account) use ($activities, $startBalances, $endBalances) {
|
||||
// TODO lots of queries executed in this block.
|
||||
$account->lastActivityDate = $this->isInArray($activities, $account->id);
|
||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||
$account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 6, '.', '');
|
||||
$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->location = $this->repository->getLocation($account);
|
||||
$account->lastActivityDate = $this->isInArray($activities, $account->id);
|
||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||
$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->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));
|
||||
$account->location = $this->repository->getLocation($account);
|
||||
$account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction');
|
||||
$account->current_debt = $this->repository->getMetaValue($account, 'current_debt') ?? '-';
|
||||
}
|
||||
);
|
||||
// make paginator:
|
||||
|
@@ -85,6 +85,7 @@ class InstallController extends Controller
|
||||
'firefly-iii:migrate-recurrence-meta' => [],
|
||||
'firefly-iii:migrate-tag-locations' => [],
|
||||
'firefly-iii:migrate-recurrence-type' => [],
|
||||
'firefly-iii:upgrade-liabilities' => [],
|
||||
|
||||
// verify commands
|
||||
'firefly-iii:fix-piggies' => [],
|
||||
|
@@ -62,6 +62,7 @@ class AccountFormRequest extends FormRequest
|
||||
'interest' => $this->string('interest'),
|
||||
'interest_period' => $this->string('interest_period'),
|
||||
'include_net_worth' => '1',
|
||||
'liability_direction' => $this->string('liability_direction'),
|
||||
];
|
||||
|
||||
$data = $this->appendLocationData($data, 'location');
|
||||
@@ -74,6 +75,9 @@ class AccountFormRequest extends FormRequest
|
||||
if ('liabilities' === $data['account_type_name']) {
|
||||
$data['account_type_name'] = null;
|
||||
$data['account_type_id'] = $this->integer('liability_type_id');
|
||||
if ('' !== $data['opening_balance']) {
|
||||
$data['opening_balance'] = app('steam')->negative($data['opening_balance']);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -108,11 +112,6 @@ class AccountFormRequest extends FormRequest
|
||||
];
|
||||
$rules = Location::requestRules($rules);
|
||||
|
||||
if ('liabilities' === $this->get('objectType')) {
|
||||
$rules['opening_balance'] = ['numeric', 'required', 'max:1000000000'];
|
||||
$rules['opening_balance_date'] = 'date|required';
|
||||
}
|
||||
|
||||
/** @var Account $account */
|
||||
$account = $this->route()->parameter('account');
|
||||
if (null !== $account) {
|
||||
|
Reference in New Issue
Block a user