mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Rename from "native" to "primary".
This commit is contained in:
		| @@ -40,8 +40,8 @@ use Symfony\Component\HttpFoundation\ParameterBag; | ||||
|  */ | ||||
| class AccountTransformer extends AbstractTransformer | ||||
| { | ||||
|     protected bool                       $convertToNative; | ||||
|     protected TransactionCurrency        $native; | ||||
|     protected bool                       $convertToPrimary; | ||||
|     protected TransactionCurrency        $primary; | ||||
|     protected AccountRepositoryInterface $repository; | ||||
| 
 | ||||
|     /** | ||||
| @@ -51,8 +51,8 @@ class AccountTransformer extends AbstractTransformer | ||||
|     { | ||||
|         $this->parameters      = new ParameterBag(); | ||||
|         $this->repository      = app(AccountRepositoryInterface::class); | ||||
|         $this->convertToNative = Amount::convertToPrimary(); | ||||
|         $this->native          = Amount::getPrimaryCurrency(); | ||||
|         $this->convertToPrimary = Amount::convertToPrimary(); | ||||
|         $this->primary          = Amount::getPrimaryCurrency(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @@ -80,13 +80,13 @@ class AccountTransformer extends AbstractTransformer | ||||
|         $date->endOfDay(); | ||||
| 
 | ||||
|         [$creditCardType, $monthlyPaymentDate]                        = $this->getCCInfo($account, $accountRole, $accountType); | ||||
|         [$openingBalance, $nativeOpeningBalance, $openingBalanceDate] = $this->getOpeningBalance($account, $accountType); | ||||
|         [$openingBalance, $pcOpeningBalance, $openingBalanceDate] = $this->getOpeningBalance($account, $accountType); | ||||
|         [$interest, $interestPeriod]                                  = $this->getInterest($account, $accountType); | ||||
| 
 | ||||
|         $native                                                       = $this->native; | ||||
|         if (!$this->convertToNative) { | ||||
|             // reset native currency to NULL, not interesting.
 | ||||
|             $native = null; | ||||
|         $primary                                                       = $this->primary; | ||||
|         if (!$this->convertToPrimary) { | ||||
|             // reset primary currency to NULL, not interesting.
 | ||||
|             $primary = null; | ||||
|         } | ||||
| 
 | ||||
|         $decimalPlaces                                                = (int)$account->meta['currency']?->decimal_places; | ||||
| @@ -102,15 +102,14 @@ class AccountTransformer extends AbstractTransformer | ||||
|         if (!in_array(strtolower($accountType), ['liability', 'liabilities', 'asset'], true)) { | ||||
|             $order = null; | ||||
|         } | ||||
|         // balance, native balance, virtual balance, native virtual balance?
 | ||||
|         Log::debug(sprintf('transform: Call finalAccountBalance with date/time "%s"', $date->toIso8601String())); | ||||
|         $finalBalance                                                 = Steam::finalAccountBalance($account, $date, $this->native, $this->convertToNative); | ||||
|         if ($this->convertToNative) { | ||||
|         $finalBalance                                                 = Steam::finalAccountBalance($account, $date, $this->primary, $this->convertToPrimary); | ||||
|         if ($this->convertToPrimary) { | ||||
|             $finalBalance['balance'] = $finalBalance[$account->meta['currency']?->code] ?? '0'; | ||||
|         } | ||||
| 
 | ||||
|         $currentBalance                                               = Steam::bcround($finalBalance['balance'] ?? '0', $decimalPlaces); | ||||
|         $nativeCurrentBalance                                         = $this->convertToNative ? Steam::bcround($finalBalance['native_balance'] ?? '0', $native->decimal_places) : null; | ||||
|         $pcCurrentBalance                                         = $this->convertToPrimary ? Steam::bcround($finalBalance['pc_balance'] ?? '0', $primary->decimal_places) : null; | ||||
| 
 | ||||
|         // set up balances array:
 | ||||
|         $balances                                                     = []; | ||||
| @@ -124,14 +123,14 @@ class AccountTransformer extends AbstractTransformer | ||||
|                                                                           'currency_decimal_places' => $account->meta['currency']?->decimal_places, | ||||
|                                                                           'date'                    => $date->toAtomString(), | ||||
|                                                                       ]; | ||||
|         if (null !== $nativeCurrentBalance) { | ||||
|         if (null !== $pcCurrentBalance) { | ||||
|             $balances[] = [ | ||||
|                 'type'                     => 'native_current', | ||||
|                 'amount'                   => $nativeCurrentBalance, | ||||
|                 'currency_id'              => $native instanceof TransactionCurrency ? (string)$native->id : null, | ||||
|                 'currency_code'            => $native?->code, | ||||
|                 'currency_symbol'          => $native?->symbol, | ||||
|                 'ccurrency_decimal_places' => $native?->decimal_places, | ||||
|                 'type'                     => 'pc_current', | ||||
|                 'amount'                   => $pcCurrentBalance, | ||||
|                 'currency_id'              => $primary instanceof TransactionCurrency ? (string)$primary->id : null, | ||||
|                 'currency_code'            => $primary?->code, | ||||
|                 'currency_symbol'          => $primary?->symbol, | ||||
|                 'ccurrency_decimal_places' => $primary?->decimal_places, | ||||
|                 'date'                     => $date->toAtomString(), | ||||
| 
 | ||||
|             ]; | ||||
| @@ -172,12 +171,12 @@ class AccountTransformer extends AbstractTransformer | ||||
|             'currency_code'                  => $account->meta['currency']?->code, | ||||
|             'currency_symbol'                => $account->meta['currency']?->symbol, | ||||
|             'currency_decimal_places'        => $account->meta['currency']?->decimal_places, | ||||
|             'native_currency_id'             => $native instanceof TransactionCurrency ? (string)$native->id : null, | ||||
|             'native_currency_code'           => $native?->code, | ||||
|             'native_currency_symbol'         => $native?->symbol, | ||||
|             'native_currency_decimal_places' => $native?->decimal_places, | ||||
|             'primary_currency_id'             => $primary instanceof TransactionCurrency ? (string)$primary->id : null, | ||||
|             'primary_currency_code'           => $primary?->code, | ||||
|             'primary_currency_symbol'         => $primary?->symbol, | ||||
|             'primary_currency_decimal_places' => $primary?->decimal_places, | ||||
|             'current_balance'                => $currentBalance, | ||||
|             'native_current_balance'         => $nativeCurrentBalance, | ||||
|             'pc_current_balance'         => $pcCurrentBalance, | ||||
|             'current_balance_date'           => $date->toAtomString(), | ||||
|             'notes'                          => $account->meta['notes'] ?? null, | ||||
|             'monthly_payment_date'           => $monthlyPaymentDate, | ||||
| @@ -186,9 +185,9 @@ class AccountTransformer extends AbstractTransformer | ||||
|             'iban'                           => '' === $account->iban ? null : $account->iban, | ||||
|             'bic'                            => $account->meta['BIC'] ?? null, | ||||
|             'virtual_balance'                => Steam::bcround($account->virtual_balance, $decimalPlaces), | ||||
|             'native_virtual_balance'         => $this->convertToNative ? Steam::bcround($account->native_virtual_balance, $native->decimal_places) : null, | ||||
|             'pc_virtual_balance'         => $this->convertToPrimary ? Steam::bcround($account->native_virtual_balance, $primary->decimal_places) : null, | ||||
|             'opening_balance'                => $openingBalanceRounded, | ||||
|             'native_opening_balance'         => $nativeOpeningBalance, | ||||
|             'pc_opening_balance'         => $pcOpeningBalance, | ||||
|             'opening_balance_date'           => $openingBalanceDate, | ||||
|             'liability_type'                 => $liabilityType, | ||||
|             'liability_direction'            => $liabilityDirection, | ||||
| @@ -261,11 +260,11 @@ class AccountTransformer extends AbstractTransformer | ||||
|     { | ||||
|         $openingBalance       = null; | ||||
|         $openingBalanceDate   = null; | ||||
|         $nativeOpeningBalance = null; | ||||
|         $pcOpeningBalance = null; | ||||
|         if (in_array($accountType, ['asset', 'liabilities'], true)) { | ||||
|             // grab from meta.
 | ||||
|             $openingBalance       = $account->meta['opening_balance_amount'] ?? null; | ||||
|             $nativeOpeningBalance = null; | ||||
|             $pcOpeningBalance = null; | ||||
|             $openingBalanceDate   = $account->meta['opening_balance_date'] ?? null; | ||||
|         } | ||||
|         if (null !== $openingBalanceDate) { | ||||
| @@ -276,14 +275,14 @@ class AccountTransformer extends AbstractTransformer | ||||
|             $openingBalanceDate = $object->toAtomString(); | ||||
| 
 | ||||
|             // NOW do conversion.
 | ||||
|             if ($this->convertToNative && null !== $account->meta['currency']) { | ||||
|             if ($this->convertToPrimary && null !== $account->meta['currency']) { | ||||
|                 $converter            = new ExchangeRateConverter(); | ||||
|                 $nativeOpeningBalance = $converter->convert($account->meta['currency'], $this->native, $object, $openingBalance); | ||||
|                 $pcOpeningBalance = $converter->convert($account->meta['currency'], $this->primary, $object, $openingBalance); | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         return [$openingBalance, $nativeOpeningBalance, $openingBalanceDate]; | ||||
|         return [$openingBalance, $pcOpeningBalance, $openingBalanceDate]; | ||||
|     } | ||||
| 
 | ||||
|     private function getInterest(Account $account, string $accountType): array | ||||
|   | ||||
| @@ -36,8 +36,8 @@ use FireflyIII\Support\Facades\Amount; | ||||
|  */ | ||||
| class AvailableBudgetTransformer extends AbstractTransformer | ||||
| { | ||||
|     private readonly bool                          $convertToNative; | ||||
|     private readonly TransactionCurrency           $default; | ||||
|     private readonly bool                          $convertToPrimary; | ||||
|     private readonly TransactionCurrency           $primary; | ||||
|     private readonly NoBudgetRepositoryInterface   $noBudgetRepository; | ||||
|     private readonly OperationsRepositoryInterface $opsRepository; | ||||
|     private readonly BudgetRepositoryInterface     $repository; | ||||
| @@ -50,8 +50,8 @@ class AvailableBudgetTransformer extends AbstractTransformer | ||||
|         $this->repository         = app(BudgetRepositoryInterface::class); | ||||
|         $this->opsRepository      = app(OperationsRepositoryInterface::class); | ||||
|         $this->noBudgetRepository = app(NoBudgetRepositoryInterface::class); | ||||
|         $this->default            = Amount::getPrimaryCurrency(); | ||||
|         $this->convertToNative    = Amount::convertToPrimary(); | ||||
|         $this->primary            = Amount::getPrimaryCurrency(); | ||||
|         $this->convertToPrimary   = Amount::convertToPrimary(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @@ -62,37 +62,37 @@ class AvailableBudgetTransformer extends AbstractTransformer | ||||
|         $this->repository->setUser($availableBudget->user); | ||||
| 
 | ||||
|         $currency = $availableBudget->transactionCurrency; | ||||
|         $default  = $this->default; | ||||
|         if (!$this->convertToNative) { | ||||
|             $default = null; | ||||
|         $primary  = $this->primary; | ||||
|         if (!$this->convertToPrimary) { | ||||
|             $primary = null; | ||||
|         } | ||||
|         $data     = [ | ||||
|             'id'                             => (string) $availableBudget->id, | ||||
|             'created_at'                     => $availableBudget->created_at->toAtomString(), | ||||
|             'updated_at'                     => $availableBudget->updated_at->toAtomString(), | ||||
|             'currency_id'                    => (string) $currency->id, | ||||
|             'currency_code'                  => $currency->code, | ||||
|             'currency_symbol'                => $currency->symbol, | ||||
|             'currency_decimal_places'        => $currency->decimal_places, | ||||
|             'native_currency_id'             => $default instanceof TransactionCurrency ? (string) $default->id : null, | ||||
|             'native_currency_code'           => $default?->code, | ||||
|             'native_currency_symbol'         => $default?->symbol, | ||||
|             'native_currency_decimal_places' => $default?->decimal_places, | ||||
|             'amount'                         => app('steam')->bcround($availableBudget->amount, $currency->decimal_places), | ||||
|             'native_amount'                  => $this->convertToNative ? app('steam')->bcround($availableBudget->native_amount, $currency->decimal_places) : null, | ||||
|             'start'                          => $availableBudget->start_date->toAtomString(), | ||||
|             'end'                            => $availableBudget->end_date->endOfDay()->toAtomString(), | ||||
|             'spent_in_budgets'               => [], | ||||
|             'spent_no_budget'                => [], | ||||
|             'links'                          => [ | ||||
|         $data  = [ | ||||
|             'id'                              => (string)$availableBudget->id, | ||||
|             'created_at'                      => $availableBudget->created_at->toAtomString(), | ||||
|             'updated_at'                      => $availableBudget->updated_at->toAtomString(), | ||||
|             'currency_id'                     => (string)$currency->id, | ||||
|             'currency_code'                   => $currency->code, | ||||
|             'currency_symbol'                 => $currency->symbol, | ||||
|             'currency_decimal_places'         => $currency->decimal_places, | ||||
|             'primary_currency_id'             => $primary instanceof TransactionCurrency ? (string)$primary->id : null, | ||||
|             'primary_currency_code'           => $primary?->code, | ||||
|             'primary_currency_symbol'         => $primary?->symbol, | ||||
|             'primary_currency_decimal_places' => $primary?->decimal_places, | ||||
|             'amount'                          => app('steam')->bcround($availableBudget->amount, $currency->decimal_places), | ||||
|             'pc_amount'                       => $this->convertToPrimary ? app('steam')->bcround($availableBudget->native_amount, $currency->decimal_places) : null, | ||||
|             'start'                           => $availableBudget->start_date->toAtomString(), | ||||
|             'end'                             => $availableBudget->end_date->endOfDay()->toAtomString(), | ||||
|             'spent_in_budgets'                => [], | ||||
|             'spent_no_budget'                 => [], | ||||
|             'links'                           => [ | ||||
|                 [ | ||||
|                     'rel' => 'self', | ||||
|                     'uri' => '/available_budgets/'.$availableBudget->id, | ||||
|                     'uri' => '/available_budgets/' . $availableBudget->id, | ||||
|                 ], | ||||
|             ], | ||||
|         ]; | ||||
|         $start    = $this->parameters->get('start'); | ||||
|         $end      = $this->parameters->get('end'); | ||||
|         $start = $this->parameters->get('start'); | ||||
|         $end   = $this->parameters->get('end'); | ||||
|         if (null !== $start && null !== $end) { | ||||
|             $data['spent_in_budgets'] = $this->getSpentInBudgets(); | ||||
|             $data['spent_no_budget']  = $this->spentOutsideBudgets(); | ||||
|   | ||||
| @@ -33,14 +33,14 @@ use FireflyIII\Support\Facades\Amount; | ||||
|  */ | ||||
| class BillTransformer extends AbstractTransformer | ||||
| { | ||||
|     private readonly TransactionCurrency $native; | ||||
|     private readonly TransactionCurrency $primary; | ||||
| 
 | ||||
|     /** | ||||
|      * BillTransformer constructor. | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->native = Amount::getPrimaryCurrency(); | ||||
|         $this->primary = Amount::getPrimaryCurrency(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @@ -60,10 +60,10 @@ class BillTransformer extends AbstractTransformer | ||||
|             'currency_symbol'                => $currency->symbol, | ||||
|             'currency_decimal_places'        => $currency->decimal_places, | ||||
| 
 | ||||
|             'native_currency_id'             => (string)$this->native->id, | ||||
|             'native_currency_code'           => $this->native->code, | ||||
|             'native_currency_symbol'         => $this->native->symbol, | ||||
|             'native_currency_decimal_places' => $this->native->decimal_places, | ||||
|             'primary_currency_id'             => (string)$this->primary->id, | ||||
|             'primary_currency_code'           => $this->primary->code, | ||||
|             'primary_currency_symbol'         => $this->primary->symbol, | ||||
|             'primary_currency_decimal_places' => $this->primary->decimal_places, | ||||
| 
 | ||||
|             'name'                           => $bill->name, | ||||
|             'amount_min'                     => $bill->amounts['amount_min'], | ||||
|   | ||||
| @@ -37,17 +37,17 @@ use League\Fractal\Resource\Item; | ||||
|  */ | ||||
| class BudgetLimitTransformer extends AbstractTransformer | ||||
| { | ||||
|     protected array $availableIncludes | ||||
|     protected array               $availableIncludes | ||||
|         = [ | ||||
|             'budget', | ||||
|         ]; | ||||
|     protected bool                $convertToNative; | ||||
|     protected TransactionCurrency $default; | ||||
|     protected bool                $convertToPrimary; | ||||
|     protected TransactionCurrency $primary; | ||||
| 
 | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->default         = Amount::getPrimaryCurrency(); | ||||
|         $this->convertToNative = Amount::convertToPrimary(); | ||||
|         $this->primary          = Amount::getPrimaryCurrency(); | ||||
|         $this->convertToPrimary = Amount::convertToPrimary(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @@ -65,8 +65,8 @@ class BudgetLimitTransformer extends AbstractTransformer | ||||
|      */ | ||||
|     public function transform(BudgetLimit $budgetLimit): array | ||||
|     { | ||||
|         $repository            = app(OperationsRepository::class); | ||||
|         $limitRepos            = app(BudgetLimitRepositoryInterface::class); | ||||
|         $repository = app(OperationsRepository::class); | ||||
|         $limitRepos = app(BudgetLimitRepositoryInterface::class); | ||||
|         $repository->setUser($budgetLimit->budget->user); | ||||
|         $limitRepos->setUser($budgetLimit->budget->user); | ||||
|         $expenses              = $repository->sumExpenses( | ||||
| @@ -92,38 +92,38 @@ class BudgetLimitTransformer extends AbstractTransformer | ||||
|             $currencySymbol        = $currency->symbol; | ||||
|             $currencyDecimalPlaces = $currency->decimal_places; | ||||
|         } | ||||
|         $amount                = app('steam')->bcround($amount, $currencyDecimalPlaces); | ||||
|         $default               = $this->default; | ||||
|         if (!$this->convertToNative) { | ||||
|             $default = null; | ||||
|         $amount  = app('steam')->bcround($amount, $currencyDecimalPlaces); | ||||
|         $primary = $this->primary; | ||||
|         if (!$this->convertToPrimary) { | ||||
|             $primary = null; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         return [ | ||||
|             'id'                             => (string) $budgetLimit->id, | ||||
|             'created_at'                     => $budgetLimit->created_at->toAtomString(), | ||||
|             'updated_at'                     => $budgetLimit->updated_at->toAtomString(), | ||||
|             'start'                          => $budgetLimit->start_date->toAtomString(), | ||||
|             'end'                            => $budgetLimit->end_date->endOfDay()->toAtomString(), | ||||
|             'budget_id'                      => (string) $budgetLimit->budget_id, | ||||
|             'currency_id'                    => (string) $currencyId, | ||||
|             'currency_code'                  => $currencyCode, | ||||
|             'currency_name'                  => $currencyName, | ||||
|             'currency_decimal_places'        => $currencyDecimalPlaces, | ||||
|             'currency_symbol'                => $currencySymbol, | ||||
|             'native_currency_id'             => $default instanceof TransactionCurrency ? (string) $default->id : null, | ||||
|             'native_currency_code'           => $default?->code, | ||||
|             'native_currency_symbol'         => $default?->symbol, | ||||
|             'native_currency_decimal_places' => $default?->decimal_places, | ||||
|             'amount'                         => $amount, | ||||
|             'native_amount'                  => $this->convertToNative ? app('steam')->bcround($budgetLimit->native_amount, $default->decimal_places) : null, | ||||
|             'period'                         => $budgetLimit->period, | ||||
|             'spent'                          => $expenses[$currencyId]['sum'] ?? '0', // will be in native if convertToNative.
 | ||||
|             'notes'                          => '' === $notes ? null : $notes, | ||||
|             'links'                          => [ | ||||
|             'id'                              => (string)$budgetLimit->id, | ||||
|             'created_at'                      => $budgetLimit->created_at->toAtomString(), | ||||
|             'updated_at'                      => $budgetLimit->updated_at->toAtomString(), | ||||
|             'start'                           => $budgetLimit->start_date->toAtomString(), | ||||
|             'end'                             => $budgetLimit->end_date->endOfDay()->toAtomString(), | ||||
|             'budget_id'                       => (string)$budgetLimit->budget_id, | ||||
|             'currency_id'                     => (string)$currencyId, | ||||
|             'currency_code'                   => $currencyCode, | ||||
|             'currency_name'                   => $currencyName, | ||||
|             'currency_decimal_places'         => $currencyDecimalPlaces, | ||||
|             'currency_symbol'                 => $currencySymbol, | ||||
|             'primary_currency_id'             => $primary instanceof TransactionCurrency ? (string)$primary->id : null, | ||||
|             'primary_currency_code'           => $primary?->code, | ||||
|             'primary_currency_symbol'         => $primary?->symbol, | ||||
|             'primary_currency_decimal_places' => $primary?->decimal_places, | ||||
|             'amount'                          => $amount, | ||||
|             'pc_amount'                       => $this->convertToPrimary ? app('steam')->bcround($budgetLimit->native_amount, $primary->decimal_places) : null, | ||||
|             'period'                          => $budgetLimit->period, | ||||
|             'spent'                           => $expenses[$currencyId]['sum'] ?? '0', // will be in native if convertToNative.
 | ||||
|             'notes'                           => '' === $notes ? null : $notes, | ||||
|             'links'                           => [ | ||||
|                 [ | ||||
|                     'rel' => 'self', | ||||
|                     'uri' => '/budgets/limits/'.$budgetLimit->id, | ||||
|                     'uri' => '/budgets/limits/' . $budgetLimit->id, | ||||
|                 ], | ||||
|             ], | ||||
|         ]; | ||||
|   | ||||
| @@ -38,8 +38,8 @@ use Symfony\Component\HttpFoundation\ParameterBag; | ||||
|  */ | ||||
| class BudgetTransformer extends AbstractTransformer | ||||
| { | ||||
|     private readonly bool                          $convertToNative; | ||||
|     private readonly TransactionCurrency           $default; | ||||
|     private readonly bool                          $convertToPrimary; | ||||
|     private readonly TransactionCurrency           $primary; | ||||
|     private readonly OperationsRepositoryInterface $opsRepository; | ||||
|     private readonly BudgetRepositoryInterface     $repository; | ||||
| 
 | ||||
| @@ -51,8 +51,8 @@ class BudgetTransformer extends AbstractTransformer | ||||
|         $this->opsRepository   = app(OperationsRepositoryInterface::class); | ||||
|         $this->repository      = app(BudgetRepositoryInterface::class); | ||||
|         $this->parameters      = new ParameterBag(); | ||||
|         $this->default         = Amount::getPrimaryCurrency(); | ||||
|         $this->convertToNative = Amount::convertToPrimary(); | ||||
|         $this->primary         = Amount::getPrimaryCurrency(); | ||||
|         $this->convertToPrimary = Amount::convertToPrimary(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @@ -72,7 +72,7 @@ class BudgetTransformer extends AbstractTransformer | ||||
|         // info for auto budget.
 | ||||
|         $abType     = null; | ||||
|         $abAmount   = null; | ||||
|         $abNative   = null; | ||||
|         $abPrimary   = null; | ||||
|         $abPeriod   = null; | ||||
|         $notes      = $this->repository->getNoteText($budget); | ||||
| 
 | ||||
| @@ -82,17 +82,17 @@ class BudgetTransformer extends AbstractTransformer | ||||
|             AutoBudgetType::AUTO_BUDGET_ADJUSTED->value => 'adjusted', | ||||
|         ]; | ||||
|         $currency   = $autoBudget?->transactionCurrency; | ||||
|         $default    = $this->default; | ||||
|         if (!$this->convertToNative) { | ||||
|             $default = null; | ||||
|         $primary    = $this->primary; | ||||
|         if (!$this->convertToPrimary) { | ||||
|             $primary = null; | ||||
|         } | ||||
|         if (null === $autoBudget) { | ||||
|             $currency = $default; | ||||
|             $currency = $primary; | ||||
|         } | ||||
|         if (null !== $autoBudget) { | ||||
|             $abType   = $types[$autoBudget->auto_budget_type]; | ||||
|             $abAmount = app('steam')->bcround($autoBudget->amount, $currency->decimal_places); | ||||
|             $abNative = $this->convertToNative ? app('steam')->bcround($autoBudget->native_amount, $default->decimal_places) : null; | ||||
|             $abPrimary = $this->convertToPrimary ? app('steam')->bcround($autoBudget->native_amount, $primary->decimal_places) : null; | ||||
|             $abPeriod = $autoBudget->period; | ||||
|         } | ||||
| 
 | ||||
| @@ -113,16 +113,16 @@ class BudgetTransformer extends AbstractTransformer | ||||
|             'currency_decimal_places'        => $autoBudget?->transactionCurrency->decimal_places, | ||||
|             'currency_symbol'                => $autoBudget?->transactionCurrency->symbol, | ||||
| 
 | ||||
|             'native_currency_id'             => $default instanceof TransactionCurrency ? (string) $default->id : null, | ||||
|             'native_currency_code'           => $default?->code, | ||||
|             'native_currency_symbol'         => $default?->symbol, | ||||
|             'native_currency_decimal_places' => $default?->decimal_places, | ||||
|             'primary_currency_id'             => $primary instanceof TransactionCurrency ? (string) $primary->id : null, | ||||
|             'primary_currency_code'           => $primary?->code, | ||||
|             'primary_currency_symbol'         => $primary?->symbol, | ||||
|             'primary_currency_decimal_places' => $primary?->decimal_places, | ||||
| 
 | ||||
|             // amount and native amount if present.
 | ||||
|             // amount and primary currency amount if present.
 | ||||
| 
 | ||||
|             'auto_budget_amount'             => $abAmount, | ||||
|             'native_auto_budget_amount'      => $abNative, | ||||
|             'spent'                          => $spent, // always in native.
 | ||||
|             'pc_auto_budget_amount'      => $abPrimary, | ||||
|             'spent'                          => $spent, // always in primary currency.
 | ||||
|             'links'                          => [ | ||||
|                 [ | ||||
|                     'rel' => 'self', | ||||
|   | ||||
| @@ -37,7 +37,7 @@ use Illuminate\Support\Collection; | ||||
| class CategoryTransformer extends AbstractTransformer | ||||
| { | ||||
|     private readonly bool                          $convertToNative; | ||||
|     private readonly TransactionCurrency           $default; | ||||
|     private readonly TransactionCurrency           $primary; | ||||
|     private readonly OperationsRepositoryInterface $opsRepository; | ||||
|     private readonly CategoryRepositoryInterface   $repository; | ||||
| 
 | ||||
| @@ -48,7 +48,7 @@ class CategoryTransformer extends AbstractTransformer | ||||
|     { | ||||
|         $this->opsRepository   = app(OperationsRepositoryInterface::class); | ||||
|         $this->repository      = app(CategoryRepositoryInterface::class); | ||||
|         $this->default         = Amount::getPrimaryCurrency(); | ||||
|         $this->primary         = Amount::getPrimaryCurrency(); | ||||
|         $this->convertToNative = Amount::convertToPrimary(); | ||||
|     } | ||||
| 
 | ||||
| @@ -60,36 +60,36 @@ class CategoryTransformer extends AbstractTransformer | ||||
|         $this->opsRepository->setUser($category->user); | ||||
|         $this->repository->setUser($category->user); | ||||
| 
 | ||||
|         $spent   = []; | ||||
|         $earned  = []; | ||||
|         $start   = $this->parameters->get('start'); | ||||
|         $end     = $this->parameters->get('end'); | ||||
|         $spent  = []; | ||||
|         $earned = []; | ||||
|         $start  = $this->parameters->get('start'); | ||||
|         $end    = $this->parameters->get('end'); | ||||
|         if (null !== $start && null !== $end) { | ||||
|             $earned = $this->beautify($this->opsRepository->sumIncome($start, $end, null, new Collection([$category]))); | ||||
|             $spent  = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$category]))); | ||||
|         } | ||||
|         $default = $this->default; | ||||
|         $primary = $this->primary; | ||||
|         if (!$this->convertToNative) { | ||||
|             $default = null; | ||||
|             $primary = null; | ||||
|         } | ||||
|         $notes   = $this->repository->getNoteText($category); | ||||
|         $notes = $this->repository->getNoteText($category); | ||||
| 
 | ||||
|         return [ | ||||
|             'id'                             => $category->id, | ||||
|             'created_at'                     => $category->created_at->toAtomString(), | ||||
|             'updated_at'                     => $category->updated_at->toAtomString(), | ||||
|             'name'                           => $category->name, | ||||
|             'notes'                          => $notes, | ||||
|             'native_currency_id'             => $default instanceof TransactionCurrency ? (string) $default->id : null, | ||||
|             'native_currency_code'           => $default?->code, | ||||
|             'native_currency_symbol'         => $default?->symbol, | ||||
|             'native_currency_decimal_places' => $default?->decimal_places, | ||||
|             'spent'                          => $spent, | ||||
|             'earned'                         => $earned, | ||||
|             'links'                          => [ | ||||
|             'id'                              => $category->id, | ||||
|             'created_at'                      => $category->created_at->toAtomString(), | ||||
|             'updated_at'                      => $category->updated_at->toAtomString(), | ||||
|             'name'                            => $category->name, | ||||
|             'notes'                           => $notes, | ||||
|             'primary_currency_id'             => $primary instanceof TransactionCurrency ? (string)$primary->id : null, | ||||
|             'primary_currency_code'           => $primary?->code, | ||||
|             'primary_currency_symbol'         => $primary?->symbol, | ||||
|             'primary_currency_decimal_places' => $primary?->decimal_places, | ||||
|             'spent'                           => $spent, | ||||
|             'earned'                          => $earned, | ||||
|             'links'                           => [ | ||||
|                 [ | ||||
|                     'rel' => 'self', | ||||
|                     'uri' => '/categories/'.$category->id, | ||||
|                     'uri' => '/categories/' . $category->id, | ||||
|                 ], | ||||
|             ], | ||||
|         ]; | ||||
| @@ -99,7 +99,7 @@ class CategoryTransformer extends AbstractTransformer | ||||
|     { | ||||
|         $return = []; | ||||
|         foreach ($array as $data) { | ||||
|             $data['sum'] = app('steam')->bcround($data['sum'], (int) $data['currency_decimal_places']); | ||||
|             $data['sum'] = app('steam')->bcround($data['sum'], (int)$data['currency_decimal_places']); | ||||
|             $return[]    = $data; | ||||
|         } | ||||
| 
 | ||||
|   | ||||
| @@ -135,7 +135,7 @@ class PiggyBankTransformer extends AbstractTransformer | ||||
|                 'id'                    => (string) $account->id, | ||||
|                 'name'                  => $account->name, | ||||
|                 'current_amount'        => (string) $account->pivot->current_amount, | ||||
|                 'native_current_amount' => (string) $account->pivot->native_current_amount, | ||||
|                 'pc_current_amount' => (string) $account->pivot->native_current_amount, | ||||
|                 // TODO add balance, add left to save.
 | ||||
|             ]; | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user