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