mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
🤖 Auto commit for release 'develop' on 2025-06-08
This commit is contained in:
@@ -53,8 +53,8 @@ class PiggyBankFactory
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
$this->piggyBankRepository = app(PiggyBankRepositoryInterface::class);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class PiggyBankFactory
|
||||
public function store(array $data): PiggyBank
|
||||
{
|
||||
|
||||
$piggyBankData = $data;
|
||||
$piggyBankData = $data;
|
||||
|
||||
// unset some fields
|
||||
unset($piggyBankData['object_group_title'], $piggyBankData['transaction_currency_code'], $piggyBankData['transaction_currency_id'], $piggyBankData['accounts'], $piggyBankData['object_group_id'], $piggyBankData['notes']);
|
||||
@@ -82,11 +82,11 @@ class PiggyBankFactory
|
||||
$piggyBankData['target_amount'] = '0';
|
||||
}
|
||||
|
||||
$piggyBankData['start_date_tz'] = $piggyBankData['start_date']?->format('e');
|
||||
$piggyBankData['target_date_tz'] = $piggyBankData['target_date']?->format('e');
|
||||
$piggyBankData['account_id'] = null;
|
||||
$piggyBankData['start_date_tz'] = $piggyBankData['start_date']?->format('e');
|
||||
$piggyBankData['target_date_tz'] = $piggyBankData['target_date']?->format('e');
|
||||
$piggyBankData['account_id'] = null;
|
||||
$piggyBankData['transaction_currency_id'] = $this->getCurrency($data)->id;
|
||||
$piggyBankData['order'] = 131337;
|
||||
$piggyBankData['order'] = 131337;
|
||||
|
||||
try {
|
||||
/** @var PiggyBank $piggyBank */
|
||||
@@ -96,11 +96,11 @@ class PiggyBankFactory
|
||||
|
||||
throw new FireflyException('400005: Could not store new piggy bank.', 0, $e);
|
||||
}
|
||||
$piggyBank = $this->setOrder($piggyBank, $data);
|
||||
$piggyBank = $this->setOrder($piggyBank, $data);
|
||||
$this->linkToAccountIds($piggyBank, $data['accounts']);
|
||||
$this->piggyBankRepository->updateNote($piggyBank, $data['notes']);
|
||||
|
||||
$objectGroupTitle = $data['object_group_title'] ?? '';
|
||||
$objectGroupTitle = $data['object_group_title'] ?? '';
|
||||
if ('' !== $objectGroupTitle) {
|
||||
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
|
||||
if ($objectGroup instanceof ObjectGroup) {
|
||||
@@ -108,7 +108,7 @@ class PiggyBankFactory
|
||||
}
|
||||
}
|
||||
// try also with ID
|
||||
$objectGroupId = (int)($data['object_group_id'] ?? 0);
|
||||
$objectGroupId = (int)($data['object_group_id'] ?? 0);
|
||||
if (0 !== $objectGroupId) {
|
||||
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
||||
if ($objectGroup instanceof ObjectGroup) {
|
||||
@@ -116,7 +116,7 @@ class PiggyBankFactory
|
||||
}
|
||||
}
|
||||
Log::debug('Touch piggy bank');
|
||||
$piggyBank->encrypted = false;
|
||||
$piggyBank->encrypted = false;
|
||||
$piggyBank->save();
|
||||
$piggyBank->touch();
|
||||
|
||||
@@ -127,7 +127,7 @@ class PiggyBankFactory
|
||||
{
|
||||
// currency:
|
||||
$defaultCurrency = app('amount')->getNativeCurrency();
|
||||
$currency = null;
|
||||
$currency = null;
|
||||
if (array_key_exists('transaction_currency_code', $data)) {
|
||||
$currency = $this->currencyRepository->findByCode((string)($data['transaction_currency_code'] ?? ''));
|
||||
}
|
||||
@@ -141,7 +141,7 @@ class PiggyBankFactory
|
||||
|
||||
public function find(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank
|
||||
{
|
||||
$piggyBankId = (int)$piggyBankId;
|
||||
$piggyBankId = (int)$piggyBankId;
|
||||
$piggyBankName = (string)$piggyBankName;
|
||||
if ('' === $piggyBankName && 0 === $piggyBankId) {
|
||||
return null;
|
||||
@@ -152,7 +152,8 @@ class PiggyBankFactory
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||
->where('accounts.user_id', $this->user->id)
|
||||
->where('piggy_banks.id', $piggyBankId)
|
||||
->first(['piggy_banks.*']);
|
||||
->first(['piggy_banks.*'])
|
||||
;
|
||||
if (null !== $piggyBank) {
|
||||
return $piggyBank;
|
||||
}
|
||||
@@ -176,13 +177,14 @@ class PiggyBankFactory
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||
->where('accounts.user_id', $this->user->id)
|
||||
->where('piggy_banks.name', $name)
|
||||
->first(['piggy_banks.*']);
|
||||
->first(['piggy_banks.*'])
|
||||
;
|
||||
}
|
||||
|
||||
private function setOrder(PiggyBank $piggyBank, array $data): PiggyBank
|
||||
{
|
||||
$this->resetOrder();
|
||||
$order = $this->getMaxOrder() + 1;
|
||||
$order = $this->getMaxOrder() + 1;
|
||||
if (array_key_exists('order', $data)) {
|
||||
$order = $data['order'];
|
||||
}
|
||||
@@ -196,7 +198,7 @@ class PiggyBankFactory
|
||||
public function resetOrder(): void
|
||||
{
|
||||
// TODO duplicate code
|
||||
$set = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
$set = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||
->where('accounts.user_id', $this->user->id)
|
||||
->with(
|
||||
@@ -204,7 +206,8 @@ class PiggyBankFactory
|
||||
'objectGroups',
|
||||
]
|
||||
)
|
||||
->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']);
|
||||
->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*'])
|
||||
;
|
||||
$current = 1;
|
||||
foreach ($set as $piggyBank) {
|
||||
if ($piggyBank->order !== $current) {
|
||||
@@ -227,7 +230,7 @@ class PiggyBankFactory
|
||||
Log::debug(sprintf('Linking piggy bank #%d to %d accounts.', $piggyBank->id, count($accounts)), $accounts);
|
||||
// collect current current_amount so the sync does not remove them.
|
||||
// TODO this is a tedious check. Feels like a hack.
|
||||
$toBeLinked = [];
|
||||
$toBeLinked = [];
|
||||
$oldSavedAmount = $this->piggyBankRepository->getCurrentAmount($piggyBank);
|
||||
foreach ($piggyBank->accounts as $account) {
|
||||
Log::debug(sprintf('Checking account #%d', $account->id));
|
||||
@@ -250,8 +253,8 @@ class PiggyBankFactory
|
||||
}
|
||||
if (array_key_exists('current_amount', $info) && null !== $info['current_amount']) {
|
||||
// an amount is set, first check out if there is a difference with the previous amount.
|
||||
$previous = $toBeLinked[$account->id]['current_amount'] ?? '0';
|
||||
$diff = bcsub($info['current_amount'], $previous);
|
||||
$previous = $toBeLinked[$account->id]['current_amount'] ?? '0';
|
||||
$diff = bcsub($info['current_amount'], $previous);
|
||||
|
||||
// create event for difference.
|
||||
if (0 !== bccomp($diff, '0')) {
|
||||
@@ -264,8 +267,8 @@ class PiggyBankFactory
|
||||
}
|
||||
if (array_key_exists('current_amount', $info) && null === $info['current_amount']) {
|
||||
// an amount is set, first check out if there is a difference with the previous amount.
|
||||
$previous = $toBeLinked[$account->id]['current_amount'] ?? '0';
|
||||
$diff = bcsub('0', $previous);
|
||||
$previous = $toBeLinked[$account->id]['current_amount'] ?? '0';
|
||||
$diff = bcsub('0', $previous);
|
||||
|
||||
// create event for difference.
|
||||
if (0 !== bccomp($diff, '0')) {
|
||||
|
Reference in New Issue
Block a user