mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for #3554
This commit is contained in:
parent
0c9a25a073
commit
c4979bdd27
@ -151,7 +151,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
'currency_name' => $currency['name'],
|
||||
'currency_symbol' => $currency['symbol'],
|
||||
'currency_decimal_places' => $currency['decimal_places'],
|
||||
'amount' => $spent,
|
||||
'amount' => number_format((float)$spent,$currency['decimal_places'], '.',''),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
'currency_name' => $currency['name'],
|
||||
'currency_symbol' => $currency['symbol'],
|
||||
'currency_decimal_places' => $currency['decimal_places'],
|
||||
'amount' => $spent,
|
||||
'amount' => number_format((float) $spent, $currency['decimal_places'], '.', ''),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
[$openingBalance, $openingBalanceDate] = $this->getOpeningBalance($account, $accountType, $decimalPlaces);
|
||||
[$interest, $interestPeriod] = $this->getInterest($account, $accountType);
|
||||
|
||||
$openingBalance = number_format((float) $openingBalance, $decimalPlaces, '.', '');
|
||||
$liabilityAmount = null;
|
||||
$liabilityStart = null;
|
||||
if (null !== $liabilityType) {
|
||||
@ -94,7 +95,6 @@ class AccountTransformer extends AbstractTransformer
|
||||
$latitude = $location->latitude;
|
||||
$zoomLevel = $location->zoom_level;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (int)$account->id,
|
||||
'created_at' => $account->created_at->toAtomString(),
|
||||
@ -107,7 +107,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
'currency_code' => $currencyCode,
|
||||
'currency_symbol' => $currencySymbol,
|
||||
'currency_decimal_places' => $decimalPlaces,
|
||||
'current_balance' => (string) round(app('steam')->balance($account, $date), $decimalPlaces),
|
||||
'current_balance' => number_format((float) app('steam')->balance($account, $date), $decimalPlaces, '.', ''),
|
||||
'current_balance_date' => $date->format('Y-m-d'),
|
||||
'notes' => $this->repository->getNoteText($account),
|
||||
'monthly_payment_date' => $monthlyPaymentDate,
|
||||
@ -115,7 +115,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
'account_number' => $this->repository->getMetaValue($account, 'account_number'),
|
||||
'iban' => '' === $account->iban ? null : $account->iban,
|
||||
'bic' => $this->repository->getMetaValue($account, 'BIC'),
|
||||
'virtual_balance' => round($account->virtual_balance, $decimalPlaces),
|
||||
'virtual_balance' => number_format((float) $account->virtual_balance, $decimalPlaces, '.', ''),
|
||||
'opening_balance' => $openingBalance,
|
||||
'opening_balance_date' => $openingBalanceDate,
|
||||
'liability_type' => $liabilityType,
|
||||
@ -240,7 +240,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
$openingBalanceDate = null;
|
||||
if (in_array($accountType, ['asset', 'liabilities'], true)) {
|
||||
$amount = $this->repository->getOpeningBalanceAmount($account);
|
||||
$openingBalance = null === $amount ? null : round($amount, $decimalPlaces);
|
||||
$openingBalance = $amount;
|
||||
$openingBalanceDate = $this->repository->getOpeningBalanceDate($account);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ class AvailableBudgetTransformer extends AbstractTransformer
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'amount' => round($availableBudget->amount, $currency->decimal_places),
|
||||
'amount' => number_format((float) $availableBudget->amount, $currency->decimal_places, '.', ''),
|
||||
'start' => $availableBudget->start_date->format('Y-m-d'),
|
||||
'end' => $availableBudget->end_date->format('Y-m-d'),
|
||||
'spent_in_budgets' => [],
|
||||
|
@ -89,8 +89,8 @@ class BillTransformer extends AbstractTransformer
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'name' => $bill->name,
|
||||
'amount_min' => round((float) $bill->amount_min, $currency->decimal_places),
|
||||
'amount_max' => round((float) $bill->amount_max, $currency->decimal_places),
|
||||
'amount_min' => number_format((float) $bill->amount_min, $currency->decimal_places, '.', ''),
|
||||
'amount_max' => number_format((float) $bill->amount_max, $currency->decimal_places, '.', ''),
|
||||
'date' => $bill->date->format('Y-m-d'),
|
||||
'repeat_freq' => $bill->repeat_freq,
|
||||
'skip' => (int) $bill->skip,
|
||||
|
@ -52,32 +52,36 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(BudgetLimit $budgetLimit): array
|
||||
{
|
||||
$currency = $budgetLimit->transactionCurrency;
|
||||
$amount = $budgetLimit->amount;
|
||||
$currencyId = null;
|
||||
$currencyName = null;
|
||||
$currencyCode = null;
|
||||
$currencySymbol = null;
|
||||
$currency = $budgetLimit->transactionCurrency;
|
||||
$amount = $budgetLimit->amount;
|
||||
$currencyDecimalPlaces = 2;
|
||||
$currencyId = null;
|
||||
$currencyName = null;
|
||||
$currencyCode = null;
|
||||
$currencySymbol = null;
|
||||
if (null !== $currency) {
|
||||
$amount = round($budgetLimit->amount, $budgetLimit->transactionCurrency->decimal_places);
|
||||
$currencyId = $currency->id;
|
||||
$currencyName = $currency->name;
|
||||
$currencyCode = $currency->code;
|
||||
$currencySymbol = $currency->symbol;
|
||||
$amount = $budgetLimit->amount;
|
||||
$currencyId = $currency->id;
|
||||
$currencyName = $currency->name;
|
||||
$currencyCode = $currency->code;
|
||||
$currencySymbol = $currency->symbol;
|
||||
$currencyDecimalPlaces = $currency->decimal_places;
|
||||
}
|
||||
$data = [
|
||||
'id' => (int)$budgetLimit->id,
|
||||
'created_at' => $budgetLimit->created_at->toAtomString(),
|
||||
'updated_at' => $budgetLimit->updated_at->toAtomString(),
|
||||
'start' => $budgetLimit->start_date->format('Y-m-d'),
|
||||
'end' => $budgetLimit->end_date->format('Y-m-d'),
|
||||
'budget_id' => $budgetLimit->budget_id,
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $currencyCode,
|
||||
'currency_name' => $currencyName,
|
||||
'currency_symbol' => $currencySymbol,
|
||||
'amount' => $amount,
|
||||
'links' => [
|
||||
$amount = number_format((float) $amount, $currencyDecimalPlaces, '.', '');
|
||||
$data = [
|
||||
'id' => (int) $budgetLimit->id,
|
||||
'created_at' => $budgetLimit->created_at->toAtomString(),
|
||||
'updated_at' => $budgetLimit->updated_at->toAtomString(),
|
||||
'start' => $budgetLimit->start_date->format('Y-m-d'),
|
||||
'end' => $budgetLimit->end_date->format('Y-m-d'),
|
||||
'budget_id' => $budgetLimit->budget_id,
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $currencyCode,
|
||||
'currency_name' => $currencyName,
|
||||
'currency_decimal_places' => $currencyName,
|
||||
'currency_symbol' => $currencySymbol,
|
||||
'amount' => $amount,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/budgets/limits/' . $budgetLimit->id,
|
||||
|
@ -70,7 +70,7 @@ class BudgetTransformer extends AbstractTransformer
|
||||
$autoBudget = $this->repository->getAutoBudget($budget);
|
||||
$spent = [];
|
||||
if (null !== $start && null !== $end) {
|
||||
$spent = array_values($this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget])));
|
||||
$spent = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget])));
|
||||
}
|
||||
|
||||
$abCurrencyId = null;
|
||||
@ -88,7 +88,7 @@ class BudgetTransformer extends AbstractTransformer
|
||||
$abCurrencyId = $autoBudget->transactionCurrency->id;
|
||||
$abCurrencyCode = $autoBudget->transactionCurrency->code;
|
||||
$abType = $types[$autoBudget->auto_budget_type];
|
||||
$abAmount = $autoBudget->amount;
|
||||
$abAmount = number_format((float) $autoBudget->amount, $autoBudget->transactionCurrency->decimal_places, '.', '');
|
||||
$abPeriod = $autoBudget->period;
|
||||
}
|
||||
|
||||
@ -115,4 +115,20 @@ class BudgetTransformer extends AbstractTransformer
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function beautify(array $array): array
|
||||
{
|
||||
$return = [];
|
||||
foreach ($array as $data) {
|
||||
$data['sum'] = number_format((float) $data['sum'], (int) $data['currency_decimal_places'], '.', '');
|
||||
$return[] = $data;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class CategoryTransformer extends AbstractTransformer
|
||||
{
|
||||
$return = [];
|
||||
foreach ($array as $data) {
|
||||
$data['sum'] = round($data['sum'], (int)$data['currency_decimal_places']);
|
||||
$data['sum'] = number_format((float) $data['sum'], (int) $data['currency_decimal_places'], '.', '');
|
||||
$return[] = $data;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ class CurrencyExchangeRateTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(CurrencyExchangeRate $rate): array
|
||||
{
|
||||
$result = round((float)$rate->rate * (float)$this->parameters->get('amount'), $rate->toCurrency->decimal_places);
|
||||
$result = number_format((float) $rate->rate * (float) $this->parameters->get('amount'), $rate->toCurrency->decimal_places, '.', '');
|
||||
$result = 0.0 === $result ? null : $result;
|
||||
$data = [
|
||||
'id' => (int)$rate->id,
|
||||
|
@ -58,7 +58,7 @@ class CurrencyTransformer extends AbstractTransformer
|
||||
$isDefault = (int) $defaultCurrency->id === (int) $currency->id;
|
||||
}
|
||||
$data = [
|
||||
'id' => (int)$currency->id,
|
||||
'id' => (int) $currency->id,
|
||||
'created_at' => $currency->created_at->toAtomString(),
|
||||
'updated_at' => $currency->updated_at->toAtomString(),
|
||||
'default' => $isDefault,
|
||||
@ -66,7 +66,7 @@ class CurrencyTransformer extends AbstractTransformer
|
||||
'name' => $currency->name,
|
||||
'code' => $currency->code,
|
||||
'symbol' => $currency->symbol,
|
||||
'decimal_places' => (int)$currency->decimal_places,
|
||||
'decimal_places' => (int) $currency->decimal_places,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
|
@ -75,12 +75,7 @@ class PiggyBankEventTransformer extends AbstractTransformer
|
||||
$this->piggyRepos->setUser($account->user);
|
||||
|
||||
// get associated currency or fall back to the default:
|
||||
// TODO we can use getAccountCurrency() instead
|
||||
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
|
||||
$currency = $this->currencyRepos->findNull($currencyId);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUser($account->user);
|
||||
}
|
||||
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user);
|
||||
|
||||
// get associated journal and transaction, if any:
|
||||
$journalId = (int)$event->transaction_journal_id;
|
||||
@ -89,10 +84,10 @@ class PiggyBankEventTransformer extends AbstractTransformer
|
||||
$groupId = (int)$event->transactionJournal->transaction_group_id;
|
||||
}
|
||||
$data = [
|
||||
'id' => (int)$event->id,
|
||||
'id' => (int) $event->id,
|
||||
'created_at' => $event->created_at->toAtomString(),
|
||||
'updated_at' => $event->updated_at->toAtomString(),
|
||||
'amount' => round($event->amount, $currency->decimal_places),
|
||||
'amount' => number_format((float) $event->amount, $currency->decimal_places, '.', ''),
|
||||
'currency_id' => $currency->id,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
|
@ -97,7 +97,7 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
|
||||
// get currently saved amount:
|
||||
$currentAmountStr = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||
$currentAmount = round($currentAmountStr, $currency->decimal_places);
|
||||
$currentAmount = number_format((float) $currentAmountStr, $currency->decimal_places, '.', '');
|
||||
|
||||
// left to save:
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $currentAmountStr);
|
||||
@ -105,11 +105,11 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
$targetDate = null === $piggyBank->targetdate ? null : $piggyBank->targetdate->format('Y-m-d');
|
||||
|
||||
// target and percentage:
|
||||
$targetAmount = round($piggyBank->targetamount, $currency->decimal_places);
|
||||
$targetAmount = 1 === bccomp('0.01', (string)$targetAmount) ? '0.01' : $targetAmount;
|
||||
$percentage = (int)(0 !== bccomp('0', $currentAmountStr) ? $currentAmount / $targetAmount * 100 : 0);
|
||||
$targetAmount = $piggyBank->targetamount;
|
||||
$targetAmount = 1 === bccomp('0.01', (string) $targetAmount) ? '0.01' : $targetAmount;
|
||||
$percentage = (int) (0 !== bccomp('0', $currentAmountStr) ? $currentAmountStr / $targetAmount * 100 : 0);
|
||||
$data = [
|
||||
'id' => (int)$piggyBank->id,
|
||||
'id' => (int) $piggyBank->id,
|
||||
'created_at' => $piggyBank->created_at->toAtomString(),
|
||||
'updated_at' => $piggyBank->updated_at->toAtomString(),
|
||||
'account_id' => $piggyBank->account_id,
|
||||
@ -119,11 +119,11 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'target_amount' => $targetAmount,
|
||||
'target_amount' => number_format((float) $targetAmount, $currency->decimal_places, '.', ''),
|
||||
'percentage' => $percentage,
|
||||
'current_amount' => $currentAmount,
|
||||
'left_to_save' => round($leftToSave, $currency->decimal_places),
|
||||
'save_per_month' => round($this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places),
|
||||
'left_to_save' => number_format((float) $leftToSave, $currency->decimal_places, '.', ''),
|
||||
'save_per_month' => number_format((float) $this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places, '.', ''),
|
||||
'start_date' => $startDate,
|
||||
'target_date' => $targetDate,
|
||||
'order' => (int) $piggyBank->order,
|
||||
|
@ -260,10 +260,10 @@ class RecurrenceTransformer extends AbstractTransformer
|
||||
}
|
||||
|
||||
|
||||
$amount = round($transaction->amount, $transaction->transactionCurrency->decimal_places);
|
||||
$amount = number_format((float) $transaction->amount, $transaction->transactionCurrency->decimal_places, '.', '');
|
||||
$foreignAmount = null;
|
||||
if (null !== $transaction->foreign_currency_id && null !== $transaction->foreign_amount) {
|
||||
$foreignAmount = round($transaction->foreign_amount, $foreignCurrencyDp);
|
||||
$foreignAmount = number_format($transaction->foreign_amount, $foreignCurrencyDp, '.', '');
|
||||
}
|
||||
$transactionArray = [
|
||||
'currency_id' => $transaction->transaction_currency_id,
|
||||
|
@ -335,8 +335,12 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
$category = $this->getCategory($journal->categories->first());
|
||||
$bill = $this->getBill($journal->bill);
|
||||
|
||||
if (null !== $foreignAmount && null !== $foreignCurrency) {
|
||||
$foreignAmount = number_format($foreignAmount, $foreignCurrency['decimal_places'], '.', '');
|
||||
}
|
||||
|
||||
return [
|
||||
'user' => (int)$journal->user_id,
|
||||
'user' => (int) $journal->user_id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'type' => strtolower($type),
|
||||
'date' => $journal->date->toAtomString(),
|
||||
@ -352,7 +356,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'foreign_currency_symbol' => $foreignCurrency['symbol'],
|
||||
'foreign_currency_decimal_places' => $foreignCurrency['decimal_places'],
|
||||
|
||||
'amount' => $amount,
|
||||
'amount' => number_format((float) $amount, $currency->decimal_places, '.', ''),
|
||||
'foreign_amount' => $foreignAmount,
|
||||
|
||||
'description' => $journal->description,
|
||||
@ -390,7 +394,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'sepa_cc' => $metaFieldData['sepa_cc'],
|
||||
'sepa_ct_op' => $metaFieldData['sepa_ct_op'],
|
||||
'sepa_ct_id' => $metaFieldData['sepa_ct_id'],
|
||||
'sepa_db' => $metaFieldData['sepa_ddb'],
|
||||
'sepa_db' => $metaFieldData['sepa_db'],
|
||||
'sepa_country' => $metaFieldData['sepa_country'],
|
||||
'sepa_ep' => $metaFieldData['sepa_ep'],
|
||||
'sepa_ci' => $metaFieldData['sepa_ci'],
|
||||
|
Loading…
Reference in New Issue
Block a user