mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Auto commit for release 'branch-v6.2' on 2024-12-26
This commit is contained in:
		| @@ -167,34 +167,34 @@ class ShowController extends Controller | |||||||
|         if (!$this->isEditableAccount($account)) { |         if (!$this->isEditableAccount($account)) { | ||||||
|             return $this->redirectAccountToAccount($account); |             return $this->redirectAccountToAccount($account); | ||||||
|         } |         } | ||||||
|         $location     = $this->repository->getLocation($account); |         $location        = $this->repository->getLocation($account); | ||||||
|         $isLiability  = $this->repository->isLiability($account); |         $isLiability     = $this->repository->isLiability($account); | ||||||
|         $attachments  = $this->repository->getAttachments($account); |         $attachments     = $this->repository->getAttachments($account); | ||||||
|         $objectType   = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); |         $objectType      = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); | ||||||
|         $end          = today(config('app.timezone')); |         $end             = today(config('app.timezone')); | ||||||
|         $today        = today(config('app.timezone')); |         $today           = today(config('app.timezone')); | ||||||
|         $accountCurrency = $this->repository->getAccountCurrency($account); |         $accountCurrency = $this->repository->getAccountCurrency($account); | ||||||
|         $start        = $this->repository->oldestJournalDate($account) ?? today(config('app.timezone'))->startOfMonth(); |         $start           = $this->repository->oldestJournalDate($account) ?? today(config('app.timezone'))->startOfMonth(); | ||||||
|         $subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type); |         $subTitleIcon    = config('firefly.subIconsByIdentifier.'.$account->accountType->type); | ||||||
|         $page         = (int) $request->get('page'); |         $page            = (int) $request->get('page'); | ||||||
|         $pageSize     = (int) app('preferences')->get('listPageSize', 50)->data; |         $pageSize        = (int) app('preferences')->get('listPageSize', 50)->data; | ||||||
|         $currency     = $this->repository->getAccountCurrency($account) ?? Amount::getDefaultCurrency(); |         $currency        = $this->repository->getAccountCurrency($account) ?? Amount::getDefaultCurrency(); | ||||||
|         $subTitle     = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]); |         $subTitle        = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]); | ||||||
|         $periods      = new Collection(); |         $periods         = new Collection(); | ||||||
| 
 | 
 | ||||||
|         /** @var GroupCollectorInterface $collector */ |         /** @var GroupCollectorInterface $collector */ | ||||||
|         $collector    = app(GroupCollectorInterface::class); |         $collector       = app(GroupCollectorInterface::class); | ||||||
|         $collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page)->withAccountInformation()->withCategoryInformation(); |         $collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page)->withAccountInformation()->withCategoryInformation(); | ||||||
| 
 | 
 | ||||||
|         // this search will not include transaction groups where this asset account (or liability)
 |         // this search will not include transaction groups where this asset account (or liability)
 | ||||||
|         // is just part of ONE of the journals. To force this:
 |         // is just part of ONE of the journals. To force this:
 | ||||||
|         $collector->setExpandGroupSearch(true); |         $collector->setExpandGroupSearch(true); | ||||||
| 
 | 
 | ||||||
|         $groups       = $collector->getPaginatedGroups(); |         $groups          = $collector->getPaginatedGroups(); | ||||||
|         $groups->setPath(route('accounts.show.all', [$account->id])); |         $groups->setPath(route('accounts.show.all', [$account->id])); | ||||||
|         $chartUrl     = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); |         $chartUrl        = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); | ||||||
|         $showAll      = true; |         $showAll         = true; | ||||||
|         $balances          = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency); |         $balances        = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency); | ||||||
| 
 | 
 | ||||||
|         return view( |         return view( | ||||||
|             'accounts.show', |             'accounts.show', | ||||||
|   | |||||||
| @@ -71,29 +71,30 @@ class IndexController extends Controller | |||||||
|     { |     { | ||||||
|         $this->cleanupObjectGroups(); |         $this->cleanupObjectGroups(); | ||||||
|         $this->repository->correctOrder(); |         $this->repository->correctOrder(); | ||||||
|         $start           = session('start'); |         $start       = session('start'); | ||||||
|         $end             = session('end'); |         $end         = session('end'); | ||||||
|         $collection      = $this->repository->getBills(); |         $collection  = $this->repository->getBills(); | ||||||
|         $total           = $collection->count(); |         $total       = $collection->count(); | ||||||
| 
 | 
 | ||||||
|         $parameters      = new ParameterBag(); |         $parameters  = new ParameterBag(); | ||||||
|         // sub one day from temp start so the last paid date is one day before it should be.
 |         // sub one day from temp start so the last paid date is one day before it should be.
 | ||||||
|         $tempStart       = clone $start; |         $tempStart   = clone $start; | ||||||
|         // 2023-06-23 do not sub one day from temp start, fix is in BillTransformer::payDates instead
 |         // 2023-06-23 do not sub one day from temp start, fix is in BillTransformer::payDates instead
 | ||||||
|         // $tempStart->subDay();
 |         // $tempStart->subDay();
 | ||||||
|         $parameters->set('start', $tempStart); |         $parameters->set('start', $tempStart); | ||||||
|         $parameters->set('end', $end); |         $parameters->set('end', $end); | ||||||
|         $parameters->set('convertToNative', $this->convertToNative); |         $parameters->set('convertToNative', $this->convertToNative); | ||||||
|         $parameters->set('defaultCurrency', $this->defaultCurrency); |         $parameters->set('defaultCurrency', $this->defaultCurrency); | ||||||
|  | 
 | ||||||
|         /** @var BillTransformer $transformer */ |         /** @var BillTransformer $transformer */ | ||||||
|         $transformer     = app(BillTransformer::class); |         $transformer = app(BillTransformer::class); | ||||||
|         $transformer->setParameters($parameters); |         $transformer->setParameters($parameters); | ||||||
| 
 | 
 | ||||||
|         // loop all bills, convert to array and add rules and stuff.
 |         // loop all bills, convert to array and add rules and stuff.
 | ||||||
|         $rules           = $this->repository->getRulesForBills($collection); |         $rules       = $this->repository->getRulesForBills($collection); | ||||||
| 
 | 
 | ||||||
|         // make bill groups:
 |         // make bill groups:
 | ||||||
|         $bills           = [ |         $bills       = [ | ||||||
|             0 => [ // the index is the order, not the ID.
 |             0 => [ // the index is the order, not the ID.
 | ||||||
|                 'object_group_id'    => 0, |                 'object_group_id'    => 0, | ||||||
|                 'object_group_title' => (string) trans('firefly.default_group_title_name'), |                 'object_group_title' => (string) trans('firefly.default_group_title_name'), | ||||||
| @@ -126,9 +127,9 @@ class IndexController extends Controller | |||||||
|         ksort($bills); |         ksort($bills); | ||||||
| 
 | 
 | ||||||
|         // summarise per currency / per group.
 |         // summarise per currency / per group.
 | ||||||
|         $sums            = $this->getSums($bills); |         $sums        = $this->getSums($bills); | ||||||
|         $totals          = $this->getTotals($sums); |         $totals      = $this->getTotals($sums); | ||||||
|         $today           = now()->startOfDay(); |         $today       = now()->startOfDay(); | ||||||
| 
 | 
 | ||||||
|         return view('bills.index', compact('bills', 'sums', 'total', 'totals', 'today')); |         return view('bills.index', compact('bills', 'sums', 'total', 'totals', 'today')); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -418,8 +418,8 @@ class AccountController extends Controller | |||||||
|     public function period(Account $account, Carbon $start, Carbon $end): JsonResponse |     public function period(Account $account, Carbon $start, Carbon $end): JsonResponse | ||||||
|     { |     { | ||||||
|         Log::debug('Now in period()'); |         Log::debug('Now in period()'); | ||||||
|         $chartData         = []; |         $chartData       = []; | ||||||
|         $cache             = new CacheProperties(); |         $cache           = new CacheProperties(); | ||||||
|         $cache->addProperty('chart.account.period'); |         $cache->addProperty('chart.account.period'); | ||||||
|         $cache->addProperty($start); |         $cache->addProperty($start); | ||||||
|         $cache->addProperty($end); |         $cache->addProperty($end); | ||||||
| @@ -430,23 +430,23 @@ class AccountController extends Controller | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // collect and filter balances for the entire period.
 |         // collect and filter balances for the entire period.
 | ||||||
|         $step = $this->calculateStep($start, $end); |         $step            = $this->calculateStep($start, $end); | ||||||
|         Log::debug(sprintf('Step is %s', $step)); |         Log::debug(sprintf('Step is %s', $step)); | ||||||
|         $locale = app('steam')->getLocale(); |         $locale          = app('steam')->getLocale(); | ||||||
|         $return = []; |         $return          = []; | ||||||
| 
 | 
 | ||||||
|         // fix for issue https://github.com/firefly-iii/firefly-iii/issues/8041
 |         // fix for issue https://github.com/firefly-iii/firefly-iii/issues/8041
 | ||||||
|         // have to make sure this chart is always based on the balance at the END of the period.
 |         // have to make sure this chart is always based on the balance at the END of the period.
 | ||||||
|         // This period depends on the size of the chart
 |         // This period depends on the size of the chart
 | ||||||
|         $current           = clone $start; |         $current         = clone $start; | ||||||
|         $current           = app('navigation')->endOfX($current, $step, null); |         $current         = app('navigation')->endOfX($current, $step, null); | ||||||
|         $format            = (string) trans('config.month_and_day_js', [], $locale); |         $format          = (string) trans('config.month_and_day_js', [], $locale); | ||||||
|         $accountCurrency   = $this->accountRepository->getAccountCurrency($account); |         $accountCurrency = $this->accountRepository->getAccountCurrency($account); | ||||||
| 
 | 
 | ||||||
|         Log::debug('One'); |         Log::debug('One'); | ||||||
|         $range             = Steam::finalAccountBalanceInRange($account, $start, $end, $this->convertToNative); |         $range           = Steam::finalAccountBalanceInRange($account, $start, $end, $this->convertToNative); | ||||||
|         Log::debug('Two'); |         Log::debug('Two'); | ||||||
|         $range = Steam::filterAccountBalances($range, $account, $this->convertToNative, $accountCurrency); |         $range           = Steam::filterAccountBalances($range, $account, $this->convertToNative, $accountCurrency); | ||||||
|         Log::debug('Three'); |         Log::debug('Three'); | ||||||
| 
 | 
 | ||||||
|         // temp, get end balance.
 |         // temp, get end balance.
 | ||||||
| @@ -455,29 +455,29 @@ class AccountController extends Controller | |||||||
|         Log::debug('END temp get end balance done'); |         Log::debug('END temp get end balance done'); | ||||||
| 
 | 
 | ||||||
|         $previous        = array_values($range)[0]; |         $previous        = array_values($range)[0]; | ||||||
|         $accountCurrency = $accountCurrency ?? $this->defaultCurrency; // do this AFTER getting the balances.
 |         $accountCurrency ??= $this->defaultCurrency; // do this AFTER getting the balances.
 | ||||||
|         Log::debug('Start chart loop.'); |         Log::debug('Start chart loop.'); | ||||||
| 
 | 
 | ||||||
|         $newRange      = []; |         $newRange        = []; | ||||||
|         $expectedIndex = 0; |         $expectedIndex   = 0; | ||||||
|         Log::debug('Balances exist at:'); |         Log::debug('Balances exist at:'); | ||||||
|         foreach ($range as $key => $value) { |         foreach ($range as $key => $value) { | ||||||
|             $newRange[] = ['date' => $key, 'info' => $value]; |             $newRange[] = ['date' => $key, 'info' => $value]; | ||||||
|             Log::debug(sprintf(' - %s', $key)); |             Log::debug(sprintf(' - %s', $key)); | ||||||
|         } |         } | ||||||
|         $carbon = Carbon::createFromFormat('Y-m-d', $newRange[0]['date']); |         $carbon          = Carbon::createFromFormat('Y-m-d', $newRange[0]['date']); | ||||||
|         while ($end->gte($current)) { |         while ($end->gte($current)) { | ||||||
|             $momentBalance = $previous; |             $momentBalance = $previous; | ||||||
|             $theDate = $current->format('Y-m-d'); |             $theDate       = $current->format('Y-m-d'); | ||||||
|             while ($carbon->lte($current) && array_key_exists($expectedIndex, $newRange)) { |             while ($carbon->lte($current) && array_key_exists($expectedIndex, $newRange)) { | ||||||
|                 $momentBalance = $newRange[$expectedIndex]['info']; |                 $momentBalance = $newRange[$expectedIndex]['info']; | ||||||
|                 Log::debug(sprintf('Expected index is %d!, date is %s, current is %s', $expectedIndex, $carbon->format('Y-m-d'), $current->format('Y-m-d'))); |                 Log::debug(sprintf('Expected index is %d!, date is %s, current is %s', $expectedIndex, $carbon->format('Y-m-d'), $current->format('Y-m-d'))); | ||||||
|                 $carbon = Carbon::createFromFormat('Y-m-d', $newRange[$expectedIndex]['date']); |                 $carbon        = Carbon::createFromFormat('Y-m-d', $newRange[$expectedIndex]['date']); | ||||||
|                 $expectedIndex++; |                 ++$expectedIndex; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             $return   = $this->updateChartKeys($return, $momentBalance); |             $return        = $this->updateChartKeys($return, $momentBalance); | ||||||
|             $previous = $momentBalance; |             $previous      = $momentBalance; | ||||||
| 
 | 
 | ||||||
|             Log::debug(sprintf('Now at %s', $theDate), $momentBalance); |             Log::debug(sprintf('Now at %s', $theDate), $momentBalance); | ||||||
| 
 | 
 | ||||||
| @@ -487,15 +487,15 @@ class AccountController extends Controller | |||||||
|                 $label                           = $current->isoFormat($format); |                 $label                           = $current->isoFormat($format); | ||||||
|                 $return[$key]['entries'][$label] = $amount; |                 $return[$key]['entries'][$label] = $amount; | ||||||
|             } |             } | ||||||
|             $current = app('navigation')->addPeriod($current, $step, 0); |             $current       = app('navigation')->addPeriod($current, $step, 0); | ||||||
|             // here too, to fix #8041, the data is corrected to the end of the period.
 |             // here too, to fix #8041, the data is corrected to the end of the period.
 | ||||||
|             $current = app('navigation')->endOfX($current, $step, null); |             $current       = app('navigation')->endOfX($current, $step, null); | ||||||
|             Log::debug(sprintf('Next moment is %s', $current->format('Y-m-d'))); |             Log::debug(sprintf('Next moment is %s', $current->format('Y-m-d'))); | ||||||
| 
 | 
 | ||||||
|         } |         } | ||||||
|         Log::debug('End of chart loop.'); |         Log::debug('End of chart loop.'); | ||||||
|         // second loop (yes) to create nice array with info! Yay!
 |         // second loop (yes) to create nice array with info! Yay!
 | ||||||
|         $chartData = []; |         $chartData       = []; | ||||||
| 
 | 
 | ||||||
|         foreach ($return as $key => $info) { |         foreach ($return as $key => $info) { | ||||||
|             if (3 === strlen($key)) { |             if (3 === strlen($key)) { | ||||||
| @@ -518,7 +518,7 @@ class AccountController extends Controller | |||||||
|             $chartData[] = $info; |             $chartData[] = $info; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $data              = $this->generator->multiSet($chartData); |         $data            = $this->generator->multiSet($chartData); | ||||||
|         $cache->store($data); |         $cache->store($data); | ||||||
| 
 | 
 | ||||||
|         return response()->json($data); |         return response()->json($data); | ||||||
|   | |||||||
| @@ -123,7 +123,7 @@ class ReconcileController extends Controller | |||||||
|         Log::debug(sprintf('End balance: "%s"', $endBalance)); |         Log::debug(sprintf('End balance: "%s"', $endBalance)); | ||||||
|         Log::debug(sprintf('Cleared amount: "%s"', $clearedAmount)); |         Log::debug(sprintf('Cleared amount: "%s"', $clearedAmount)); | ||||||
|         Log::debug(sprintf('Amount: "%s"', $amount)); |         Log::debug(sprintf('Amount: "%s"', $amount)); | ||||||
|         $difference      = bcadd(bcadd(bcsub($startBalance ?? '0', $endBalance ?? '0'), $clearedAmount?? '0'), $amount); |         $difference      = bcadd(bcadd(bcsub($startBalance ?? '0', $endBalance ?? '0'), $clearedAmount ?? '0'), $amount); | ||||||
|         $diffCompare     = bccomp($difference, '0'); |         $diffCompare     = bccomp($difference, '0'); | ||||||
|         $countCleared    = count($clearedJournals); |         $countCleared    = count($clearedJournals); | ||||||
|         $reconSum        = bcadd(bcadd($startBalance ?? '0', $amount ?? '0'), $clearedAmount ?? '0'); |         $reconSum        = bcadd(bcadd($startBalance ?? '0', $amount ?? '0'), $clearedAmount ?? '0'); | ||||||
|   | |||||||
| @@ -47,19 +47,19 @@ class Bill extends Model | |||||||
| 
 | 
 | ||||||
|     protected $casts |     protected $casts | ||||||
|                       = [ |                       = [ | ||||||
|             'created_at'      => 'datetime', |             'created_at'             => 'datetime', | ||||||
|             'updated_at'      => 'datetime', |             'updated_at'             => 'datetime', | ||||||
|             'deleted_at'      => 'datetime', |             'deleted_at'             => 'datetime', | ||||||
|             'date'            => SeparateTimezoneCaster::class, |             'date'                   => SeparateTimezoneCaster::class, | ||||||
|             'end_date'        => SeparateTimezoneCaster::class, |             'end_date'               => SeparateTimezoneCaster::class, | ||||||
|             'extension_date'  => SeparateTimezoneCaster::class, |             'extension_date'         => SeparateTimezoneCaster::class, | ||||||
|             'skip'            => 'int', |             'skip'                   => 'int', | ||||||
|             'automatch'       => 'boolean', |             'automatch'              => 'boolean', | ||||||
|             'active'          => 'boolean', |             'active'                 => 'boolean', | ||||||
|             'name_encrypted'  => 'boolean', |             'name_encrypted'         => 'boolean', | ||||||
|             'match_encrypted' => 'boolean', |             'match_encrypted'        => 'boolean', | ||||||
|             'amount_min'      => 'string', |             'amount_min'             => 'string', | ||||||
|             'amount_max'      => 'string', |             'amount_max'             => 'string', | ||||||
|             'native_amount_min'      => 'string', |             'native_amount_min'      => 'string', | ||||||
|             'native_amount_max'      => 'string', |             'native_amount_max'      => 'string', | ||||||
|         ]; |         ]; | ||||||
|   | |||||||
| @@ -111,25 +111,26 @@ class Steam | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         // sums up the balance changes per day, for foreign, native and normal amounts.
 |         // sums up the balance changes per day, for foreign, native and normal amounts.
 | ||||||
|         $set = $account->transactions() |         $set                  = $account->transactions() | ||||||
|                        ->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') |             ->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') | ||||||
|                        ->where('transaction_journals.date', '>=', $start->format('Y-m-d H:i:s')) |             ->where('transaction_journals.date', '>=', $start->format('Y-m-d H:i:s')) | ||||||
|                        ->where('transaction_journals.date', '<=', $end->format('Y-m-d  H:i:s')) |             ->where('transaction_journals.date', '<=', $end->format('Y-m-d  H:i:s')) | ||||||
|                        ->groupBy('transaction_journals.date') |             ->groupBy('transaction_journals.date') | ||||||
|                        ->groupBy('transactions.transaction_currency_id') |             ->groupBy('transactions.transaction_currency_id') | ||||||
|                        ->groupBy('transactions.foreign_currency_id') |             ->groupBy('transactions.foreign_currency_id') | ||||||
|                        ->orderBy('transaction_journals.date', 'ASC') |             ->orderBy('transaction_journals.date', 'ASC') | ||||||
|                        ->whereNull('transaction_journals.deleted_at') |             ->whereNull('transaction_journals.deleted_at') | ||||||
|                        ->get( |             ->get( | ||||||
|                            [ // @phpstan-ignore-line
 |                 [ // @phpstan-ignore-line
 | ||||||
|                              'transaction_journals.date', |                     'transaction_journals.date', | ||||||
|                              'transactions.transaction_currency_id', |                     'transactions.transaction_currency_id', | ||||||
|                              DB::raw('SUM(transactions.amount) AS modified'), |                     DB::raw('SUM(transactions.amount) AS modified'), | ||||||
|                              'transactions.foreign_currency_id', |                     'transactions.foreign_currency_id', | ||||||
|                              DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'), |                     DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'), | ||||||
|                              DB::raw('SUM(transactions.native_amount) AS modified_native'), |                     DB::raw('SUM(transactions.native_amount) AS modified_native'), | ||||||
|                            ] |                 ] | ||||||
|                        ); |             ) | ||||||
|  |         ; | ||||||
| 
 | 
 | ||||||
|         $currentBalance       = $startBalance; |         $currentBalance       = $startBalance; | ||||||
| 
 | 
 | ||||||
| @@ -148,22 +149,22 @@ class Steam | |||||||
|             Log::debug(sprintf('Processing transaction(s) on date %s', $carbon->format('Y-m-d H:i:s'))); |             Log::debug(sprintf('Processing transaction(s) on date %s', $carbon->format('Y-m-d H:i:s'))); | ||||||
| 
 | 
 | ||||||
|             // if convert to native, if NOT convert to native.
 |             // if convert to native, if NOT convert to native.
 | ||||||
|             if($convertToNative) { |             if ($convertToNative) { | ||||||
|                 Log::debug(sprintf('Amount is %s %s, foreign amount is %s, native amount is %s', $entryCurrency->code, $this->bcround($modified,2), $this->bcround($foreignModified,2), $this->bcround($nativeModified,2))); |                 Log::debug(sprintf('Amount is %s %s, foreign amount is %s, native amount is %s', $entryCurrency->code, $this->bcround($modified, 2), $this->bcround($foreignModified, 2), $this->bcround($nativeModified, 2))); | ||||||
|                 // if the currency is the default currency add to native balance + currency balance
 |                 // if the currency is the default currency add to native balance + currency balance
 | ||||||
|                 if($entry->transaction_currency_id === $defaultCurrency->id) { |                 if ($entry->transaction_currency_id === $defaultCurrency->id) { | ||||||
|                     Log::debug('Add amount to native.'); |                     Log::debug('Add amount to native.'); | ||||||
|                     $currentBalance['native_balance']       = bcadd($currentBalance['native_balance'], $modified); |                     $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $modified); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 // add to native balance.
 |                 // add to native balance.
 | ||||||
|                 if($entry->foreign_currency_id !== $defaultCurrency->id) { |                 if ($entry->foreign_currency_id !== $defaultCurrency->id) { | ||||||
|                     // this check is not necessary, because if the foreign currency is the same as the default currency, the native amount is zero.
 |                     // this check is not necessary, because if the foreign currency is the same as the default currency, the native amount is zero.
 | ||||||
|                     // so adding this would mean nothing.
 |                     // so adding this would mean nothing.
 | ||||||
|                     $currentBalance['native_balance']       = bcadd($currentBalance['native_balance'], $nativeModified); |                     $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $nativeModified); | ||||||
|                 } |                 } | ||||||
|                 if($entry->foreign_currency_id === $defaultCurrency->id) { |                 if ($entry->foreign_currency_id === $defaultCurrency->id) { | ||||||
|                     $currentBalance['native_balance']       = bcadd($currentBalance['native_balance'], $foreignModified); |                     $currentBalance['native_balance'] = bcadd($currentBalance['native_balance'], $foreignModified); | ||||||
|                 } |                 } | ||||||
|                 // add to balance if is the same.
 |                 // add to balance if is the same.
 | ||||||
|                 if ($entry->transaction_currency_id === $accountCurrency?->id) { |                 if ($entry->transaction_currency_id === $accountCurrency?->id) { | ||||||
| @@ -329,7 +330,7 @@ class Steam | |||||||
|             if ($native->id === $accountCurrency?->id) { |             if ($native->id === $accountCurrency?->id) { | ||||||
|                 $return['balance'] = bcadd('' === (string) $account->virtual_balance ? '0' : $account->virtual_balance, $return['balance']); |                 $return['balance'] = bcadd('' === (string) $account->virtual_balance ? '0' : $account->virtual_balance, $return['balance']); | ||||||
|             } |             } | ||||||
|             Log::debug(sprintf('balance is (%s only) %s (with virtual balance)', $native->code, $this->bcround($return['balance'],2))); |             Log::debug(sprintf('balance is (%s only) %s (with virtual balance)', $native->code, $this->bcround($return['balance'], 2))); | ||||||
| 
 | 
 | ||||||
|             // native balance
 |             // native balance
 | ||||||
|             $return['native_balance'] = (string) $account->transactions() |             $return['native_balance'] = (string) $account->transactions() | ||||||
| @@ -340,7 +341,7 @@ class Steam | |||||||
|             ; |             ; | ||||||
|             // plus native virtual balance.
 |             // plus native virtual balance.
 | ||||||
|             $return['native_balance'] = bcadd('' === (string) $account->native_virtual_balance ? '0' : $account->native_virtual_balance, $return['native_balance']); |             $return['native_balance'] = bcadd('' === (string) $account->native_virtual_balance ? '0' : $account->native_virtual_balance, $return['native_balance']); | ||||||
|             Log::debug(sprintf('native_balance is (all transactions to %s) %s (with virtual balance)', $native->code,$this->bcround( $return['native_balance']))); |             Log::debug(sprintf('native_balance is (all transactions to %s) %s (with virtual balance)', $native->code, $this->bcround($return['native_balance']))); | ||||||
| 
 | 
 | ||||||
|             // plus foreign transactions in THIS currency.
 |             // plus foreign transactions in THIS currency.
 | ||||||
|             $sum                      = (string) $account->transactions() |             $sum                      = (string) $account->transactions() | ||||||
|   | |||||||
| @@ -59,23 +59,23 @@ class BillTransformer extends AbstractTransformer | |||||||
|      */ |      */ | ||||||
|     public function transform(Bill $bill): array |     public function transform(Bill $bill): array | ||||||
|     { |     { | ||||||
|         $defaultCurrency = $this->parameters->get('defaultCurrency') ?? Amount::getDefaultCurrency(); |         $defaultCurrency   = $this->parameters->get('defaultCurrency') ?? Amount::getDefaultCurrency(); | ||||||
| 
 | 
 | ||||||
|         $paidData         = $this->paidData($bill); |         $paidData          = $this->paidData($bill); | ||||||
|         $lastPaidDate     = $this->getLastPaidDate($paidData); |         $lastPaidDate      = $this->getLastPaidDate($paidData); | ||||||
|         $start            = $this->parameters->get('start') ?? today()->subYears(10); |         $start             = $this->parameters->get('start') ?? today()->subYears(10); | ||||||
|         $end              = $this->parameters->get('end') ?? today()->addYears(10); |         $end               = $this->parameters->get('end') ?? today()->addYears(10); | ||||||
|         $payDates         = $this->calculator->getPayDates($start, $end, $bill->date, $bill->repeat_freq, $bill->skip, $lastPaidDate); |         $payDates          = $this->calculator->getPayDates($start, $end, $bill->date, $bill->repeat_freq, $bill->skip, $lastPaidDate); | ||||||
|         $currency         = $bill->transactionCurrency; |         $currency          = $bill->transactionCurrency; | ||||||
|         $notes            = $this->repository->getNoteText($bill); |         $notes             = $this->repository->getNoteText($bill); | ||||||
|         $notes            = '' === $notes ? null : $notes; |         $notes             = '' === $notes ? null : $notes; | ||||||
|         $objectGroupId    = null; |         $objectGroupId     = null; | ||||||
|         $objectGroupOrder = null; |         $objectGroupOrder  = null; | ||||||
|         $objectGroupTitle = null; |         $objectGroupTitle  = null; | ||||||
|         $this->repository->setUser($bill->user); |         $this->repository->setUser($bill->user); | ||||||
| 
 | 
 | ||||||
|         /** @var null|ObjectGroup $objectGroup */ |         /** @var null|ObjectGroup $objectGroup */ | ||||||
|         $objectGroup = $bill->objectGroups->first(); |         $objectGroup       = $bill->objectGroups->first(); | ||||||
|         if (null !== $objectGroup) { |         if (null !== $objectGroup) { | ||||||
|             $objectGroupId    = $objectGroup->id; |             $objectGroupId    = $objectGroup->id; | ||||||
|             $objectGroupOrder = $objectGroup->order; |             $objectGroupOrder = $objectGroup->order; | ||||||
| @@ -85,7 +85,7 @@ class BillTransformer extends AbstractTransformer | |||||||
|         $paidDataFormatted = []; |         $paidDataFormatted = []; | ||||||
|         $payDatesFormatted = []; |         $payDatesFormatted = []; | ||||||
|         foreach ($paidData as $object) { |         foreach ($paidData as $object) { | ||||||
|             $date = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone')); |             $date                = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone')); | ||||||
|             if (null === $date) { |             if (null === $date) { | ||||||
|                 $date = today(config('app.timezone')); |                 $date = today(config('app.timezone')); | ||||||
|             } |             } | ||||||
| @@ -94,24 +94,24 @@ class BillTransformer extends AbstractTransformer | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         foreach ($payDates as $string) { |         foreach ($payDates as $string) { | ||||||
|             $date = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone')); |             $date                = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone')); | ||||||
|             if (null === $date) { |             if (null === $date) { | ||||||
|                 $date = today(config('app.timezone')); |                 $date = today(config('app.timezone')); | ||||||
|             } |             } | ||||||
|             $payDatesFormatted[] = $date->toAtomString(); |             $payDatesFormatted[] = $date->toAtomString(); | ||||||
|         } |         } | ||||||
|         // next expected match
 |         // next expected match
 | ||||||
|         $nem          = null; |         $nem               = null; | ||||||
|         $nemDate      = null; |         $nemDate           = null; | ||||||
|         $nemDiff      = trans('firefly.not_expected_period'); |         $nemDiff           = trans('firefly.not_expected_period'); | ||||||
|         $firstPayDate = $payDates[0] ?? null; |         $firstPayDate      = $payDates[0] ?? null; | ||||||
| 
 | 
 | ||||||
|         if (null !== $firstPayDate) { |         if (null !== $firstPayDate) { | ||||||
|             $nemDate = Carbon::createFromFormat('!Y-m-d', $firstPayDate, config('app.timezone')); |             $nemDate = Carbon::createFromFormat('!Y-m-d', $firstPayDate, config('app.timezone')); | ||||||
|             if (null === $nemDate) { |             if (null === $nemDate) { | ||||||
|                 $nemDate = today(config('app.timezone')); |                 $nemDate = today(config('app.timezone')); | ||||||
|             } |             } | ||||||
|             $nem = $nemDate->toAtomString(); |             $nem     = $nemDate->toAtomString(); | ||||||
| 
 | 
 | ||||||
|             // nullify again when it's outside the current view range.
 |             // nullify again when it's outside the current view range.
 | ||||||
|             if ( |             if ( | ||||||
| @@ -132,7 +132,7 @@ class BillTransformer extends AbstractTransformer | |||||||
| 
 | 
 | ||||||
|             $current = $payDatesFormatted[0] ?? null; |             $current = $payDatesFormatted[0] ?? null; | ||||||
|             if (null !== $current && !$nemDate->isToday()) { |             if (null !== $current && !$nemDate->isToday()) { | ||||||
|                 $temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current); |                 $temp2   = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current); | ||||||
|                 if (null === $temp2) { |                 if (null === $temp2) { | ||||||
|                     $temp2 = today(config('app.timezone')); |                     $temp2 = today(config('app.timezone')); | ||||||
|                 } |                 } | ||||||
| @@ -174,7 +174,7 @@ class BillTransformer extends AbstractTransformer | |||||||
|             'links'                    => [ |             'links'                    => [ | ||||||
|                 [ |                 [ | ||||||
|                     'rel' => 'self', |                     'rel' => 'self', | ||||||
|                     'uri' => '/bills/' . $bill->id, |                     'uri' => '/bills/'.$bill->id, | ||||||
|                 ], |                 ], | ||||||
|             ], |             ], | ||||||
|         ]; |         ]; | ||||||
| @@ -196,13 +196,13 @@ class BillTransformer extends AbstractTransformer | |||||||
|         // 2023-07-18 this particular date is used to search for the last paid date.
 |         // 2023-07-18 this particular date is used to search for the last paid date.
 | ||||||
|         // 2023-07-18 the cloned $searchDate is used to grab the correct transactions.
 |         // 2023-07-18 the cloned $searchDate is used to grab the correct transactions.
 | ||||||
|         /** @var Carbon $start */ |         /** @var Carbon $start */ | ||||||
|         $start       = clone $this->parameters->get('start'); |         $start        = clone $this->parameters->get('start'); | ||||||
|         $searchStart = clone $start; |         $searchStart  = clone $start; | ||||||
|         $start->subDay(); |         $start->subDay(); | ||||||
| 
 | 
 | ||||||
|         /** @var Carbon $end */ |         /** @var Carbon $end */ | ||||||
|         $end       = clone $this->parameters->get('end'); |         $end          = clone $this->parameters->get('end'); | ||||||
|         $searchEnd = clone $end; |         $searchEnd    = clone $end; | ||||||
| 
 | 
 | ||||||
|         // move the search dates to the start of the day.
 |         // move the search dates to the start of the day.
 | ||||||
|         $searchStart->startOfDay(); |         $searchStart->startOfDay(); | ||||||
| @@ -212,7 +212,7 @@ class BillTransformer extends AbstractTransformer | |||||||
|         app('log')->debug(sprintf('Search parameters are: start: %s', $searchStart->format('Y-m-d'))); |         app('log')->debug(sprintf('Search parameters are: start: %s', $searchStart->format('Y-m-d'))); | ||||||
| 
 | 
 | ||||||
|         // Get from database when bill was paid.
 |         // Get from database when bill was paid.
 | ||||||
|         $set = $this->repository->getPaidDatesInRange($bill, $searchStart, $searchEnd); |         $set          = $this->repository->getPaidDatesInRange($bill, $searchStart, $searchEnd); | ||||||
|         app('log')->debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count())); |         app('log')->debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count())); | ||||||
| 
 | 
 | ||||||
|         // Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date.
 |         // Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date.
 | ||||||
| @@ -221,7 +221,7 @@ class BillTransformer extends AbstractTransformer | |||||||
|         app('log')->debug(sprintf('Result of lastPaidDate is %s', $lastPaidDate->format('Y-m-d'))); |         app('log')->debug(sprintf('Result of lastPaidDate is %s', $lastPaidDate->format('Y-m-d'))); | ||||||
| 
 | 
 | ||||||
|         // At this point the "next match" is exactly after the last time the bill was paid.
 |         // At this point the "next match" is exactly after the last time the bill was paid.
 | ||||||
|         $result = []; |         $result       = []; | ||||||
|         foreach ($set as $entry) { |         foreach ($set as $entry) { | ||||||
|             $result[] = [ |             $result[] = [ | ||||||
|                 'transaction_group_id'   => (string) $entry->transaction_group_id, |                 'transaction_group_id'   => (string) $entry->transaction_group_id, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user