mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-18 07:38:29 +00:00
Remove many references to (float)
This commit is contained in:
@@ -127,11 +127,11 @@ class AccountController extends Controller
|
|||||||
];
|
];
|
||||||
$currentStart = clone $start;
|
$currentStart = clone $start;
|
||||||
$range = app('steam')->balanceInRange($account, $start, clone $end);
|
$range = app('steam')->balanceInRange($account, $start, clone $end);
|
||||||
$previous = round((float) array_values($range)[0], 12);
|
$previous = $range[0] ?? '0';
|
||||||
while ($currentStart <= $end) {
|
while ($currentStart <= $end) {
|
||||||
$format = $currentStart->format('Y-m-d');
|
$format = $currentStart->format('Y-m-d');
|
||||||
$label = $currentStart->toAtomString();
|
$label = $currentStart->toAtomString();
|
||||||
$balance = array_key_exists($format, $range) ? round((float) $range[$format], 12) : $previous;
|
$balance = array_key_exists($format, $range) ? $range[$format] : $previous;
|
||||||
$previous = $balance;
|
$previous = $balance;
|
||||||
$currentStart->addDay();
|
$currentStart->addDay();
|
||||||
$currentSet['entries'][$label] = $balance;
|
$currentSet['entries'][$label] = $balance;
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class AccountController extends Controller
|
|||||||
'id' => (string) $expense['id'],
|
'id' => (string) $expense['id'],
|
||||||
'name' => $expense['name'],
|
'name' => $expense['name'],
|
||||||
'difference' => $expense['sum'],
|
'difference' => $expense['sum'],
|
||||||
'difference_float' => (float) $expense['sum'],
|
'difference_float' => (float) $expense['sum'], // intentional float
|
||||||
'currency_id' => (string) $expense['currency_id'],
|
'currency_id' => (string) $expense['currency_id'],
|
||||||
'currency_code' => $expense['currency_code'],
|
'currency_code' => $expense['currency_code'],
|
||||||
];
|
];
|
||||||
@@ -126,7 +126,7 @@ class AccountController extends Controller
|
|||||||
'id' => (string) $expense['id'],
|
'id' => (string) $expense['id'],
|
||||||
'name' => $expense['name'],
|
'name' => $expense['name'],
|
||||||
'difference' => $expense['sum'],
|
'difference' => $expense['sum'],
|
||||||
'difference_float' => (float) $expense['sum'],
|
'difference_float' => (float) $expense['sum'], // intentional float
|
||||||
'currency_id' => (string) $expense['currency_id'],
|
'currency_id' => (string) $expense['currency_id'],
|
||||||
'currency_code' => $expense['currency_code'],
|
'currency_code' => $expense['currency_code'],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class BillController extends Controller
|
|||||||
'currency_code' => $journal['currency_code'],
|
'currency_code' => $journal['currency_code'],
|
||||||
];
|
];
|
||||||
$response[$key]['difference'] = bcadd($response[$key]['difference'], $journal['amount']);
|
$response[$key]['difference'] = bcadd($response[$key]['difference'], $journal['amount']);
|
||||||
$response[$key]['difference_float'] = (float) $response[$key]['difference'];
|
$response[$key]['difference_float'] = (float) $response[$key]['difference']; // intentional float
|
||||||
}
|
}
|
||||||
if (0 !== $foreignCurrencyId) {
|
if (0 !== $foreignCurrencyId) {
|
||||||
$response[$foreignKey] = $response[$foreignKey] ?? [
|
$response[$foreignKey] = $response[$foreignKey] ?? [
|
||||||
@@ -111,7 +111,7 @@ class BillController extends Controller
|
|||||||
'currency_code' => $journal['foreign_currency_code'],
|
'currency_code' => $journal['foreign_currency_code'],
|
||||||
];
|
];
|
||||||
$response[$foreignKey]['difference'] = bcadd($response[$foreignKey]['difference'], $journal['foreign_amount']);
|
$response[$foreignKey]['difference'] = bcadd($response[$foreignKey]['difference'], $journal['foreign_amount']);
|
||||||
$response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference'];
|
$response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference']; // intentional float
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ class BillController extends Controller
|
|||||||
'currency_code' => $journal['currency_code'],
|
'currency_code' => $journal['currency_code'],
|
||||||
];
|
];
|
||||||
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']);
|
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']);
|
||||||
$response[$currencyId]['difference_float'] = (float) $response[$currencyId]['difference'];
|
$response[$currencyId]['difference_float'] = (float) $response[$currencyId]['difference']; // intentional float
|
||||||
}
|
}
|
||||||
if (0 !== $foreignCurrencyId) {
|
if (0 !== $foreignCurrencyId) {
|
||||||
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
|
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
|
||||||
@@ -164,7 +164,7 @@ class BillController extends Controller
|
|||||||
'currency_code' => $journal['foreign_currency_code'],
|
'currency_code' => $journal['foreign_currency_code'],
|
||||||
];
|
];
|
||||||
$response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']);
|
$response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']);
|
||||||
$response[$foreignCurrencyId]['difference_float'] = (float) $response[$foreignCurrencyId]['difference'];
|
$response[$foreignCurrencyId]['difference_float'] = (float) $response[$foreignCurrencyId]['difference']; // intentional float
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class BudgetController extends Controller
|
|||||||
'id' => (string) $budget->id,
|
'id' => (string) $budget->id,
|
||||||
'name' => $budget->name,
|
'name' => $budget->name,
|
||||||
'difference' => $expense['sum'],
|
'difference' => $expense['sum'],
|
||||||
'difference_float' => (float) $expense['sum'],
|
'difference_float' => (float) $expense['sum'], // intentional float
|
||||||
'currency_id' => (string) $expense['currency_id'],
|
'currency_id' => (string) $expense['currency_id'],
|
||||||
'currency_code' => $expense['currency_code'],
|
'currency_code' => $expense['currency_code'],
|
||||||
];
|
];
|
||||||
@@ -120,7 +120,7 @@ class BudgetController extends Controller
|
|||||||
foreach ($expenses as $expense) {
|
foreach ($expenses as $expense) {
|
||||||
$result[] = [
|
$result[] = [
|
||||||
'difference' => $expense['sum'],
|
'difference' => $expense['sum'],
|
||||||
'difference_float' => (float) $expense['sum'],
|
'difference_float' => (float) $expense['sum'], // intentional float
|
||||||
'currency_id' => (string) $expense['currency_id'],
|
'currency_id' => (string) $expense['currency_id'],
|
||||||
'currency_code' => $expense['currency_code'],
|
'currency_code' => $expense['currency_code'],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class CategoryController extends Controller
|
|||||||
'id' => (string) $category->id,
|
'id' => (string) $category->id,
|
||||||
'name' => $category->name,
|
'name' => $category->name,
|
||||||
'difference' => $expense['sum'],
|
'difference' => $expense['sum'],
|
||||||
'difference_float' => (float) $expense['sum'],
|
'difference_float' => (float) $expense['sum'], // intentional float
|
||||||
'currency_id' => (string) $expense['currency_id'],
|
'currency_id' => (string) $expense['currency_id'],
|
||||||
'currency_code' => $expense['currency_code'],
|
'currency_code' => $expense['currency_code'],
|
||||||
];
|
];
|
||||||
@@ -121,7 +121,7 @@ class CategoryController extends Controller
|
|||||||
foreach ($expenses as $expense) {
|
foreach ($expenses as $expense) {
|
||||||
$result[] = [
|
$result[] = [
|
||||||
'difference' => $expense['sum'],
|
'difference' => $expense['sum'],
|
||||||
'difference_float' => (float) $expense['sum'],
|
'difference_float' => (float) $expense['sum'], // intentional float
|
||||||
'currency_id' => (string) $expense['currency_id'],
|
'currency_id' => (string) $expense['currency_id'],
|
||||||
'currency_code' => $expense['currency_code'],
|
'currency_code' => $expense['currency_code'],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class PeriodController extends Controller
|
|||||||
'currency_code' => $journal['currency_code'],
|
'currency_code' => $journal['currency_code'],
|
||||||
];
|
];
|
||||||
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']);
|
$response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']);
|
||||||
$response[$currencyId]['difference_float'] = (float) $response[$currencyId]['difference'];
|
$response[$currencyId]['difference_float'] = (float) $response[$currencyId]['difference']; // intentional float
|
||||||
}
|
}
|
||||||
if (0 !== $foreignCurrencyId) {
|
if (0 !== $foreignCurrencyId) {
|
||||||
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
|
$response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [
|
||||||
@@ -76,7 +76,7 @@ class PeriodController extends Controller
|
|||||||
'currency_code' => $journal['foreign_currency_code'],
|
'currency_code' => $journal['foreign_currency_code'],
|
||||||
];
|
];
|
||||||
$response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']);
|
$response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']);
|
||||||
$response[$foreignCurrencyId]['difference_float'] = (float) $response[$foreignCurrencyId]['difference'];
|
$response[$foreignCurrencyId]['difference_float'] = (float) $response[$foreignCurrencyId]['difference']; // intentional float
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class TagController extends Controller
|
|||||||
$response[$foreignKey]['difference'] = bcadd(
|
$response[$foreignKey]['difference'] = bcadd(
|
||||||
$response[$foreignKey]['difference'], app('steam')->positive($journal['foreign_amount'])
|
$response[$foreignKey]['difference'], app('steam')->positive($journal['foreign_amount'])
|
||||||
);
|
);
|
||||||
$response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference'];
|
$response[$foreignKey]['difference_float'] = (float) $response[$foreignKey]['difference']; // intentional float
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ class BasicController extends Controller
|
|||||||
$return[] = [
|
$return[] = [
|
||||||
'key' => sprintf('balance-in-%s', $currency->code),
|
'key' => sprintf('balance-in-%s', $currency->code),
|
||||||
'title' => trans('firefly.box_balance_in_currency', ['currency' => $currency->symbol]),
|
'title' => trans('firefly.box_balance_in_currency', ['currency' => $currency->symbol]),
|
||||||
'monetary_value' => round((float) $sums[$currencyId] ?? 0, $currency->decimal_places),
|
'monetary_value' => $sums[$currencyId] ?? '0',
|
||||||
'currency_id' => $currency->id,
|
'currency_id' => $currency->id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
'currency_symbol' => $currency->symbol,
|
'currency_symbol' => $currency->symbol,
|
||||||
@@ -201,7 +201,7 @@ class BasicController extends Controller
|
|||||||
$return[] = [
|
$return[] = [
|
||||||
'key' => sprintf('spent-in-%s', $currency->code),
|
'key' => sprintf('spent-in-%s', $currency->code),
|
||||||
'title' => trans('firefly.box_spent_in_currency', ['currency' => $currency->symbol]),
|
'title' => trans('firefly.box_spent_in_currency', ['currency' => $currency->symbol]),
|
||||||
'monetary_value' => round((float) ($expenses[$currencyId] ?? 0), $currency->decimal_places),
|
'monetary_value' => $expenses[$currencyId] ?? '0',
|
||||||
'currency_id' => $currency->id,
|
'currency_id' => $currency->id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
'currency_symbol' => $currency->symbol,
|
'currency_symbol' => $currency->symbol,
|
||||||
@@ -213,7 +213,7 @@ class BasicController extends Controller
|
|||||||
$return[] = [
|
$return[] = [
|
||||||
'key' => sprintf('earned-in-%s', $currency->code),
|
'key' => sprintf('earned-in-%s', $currency->code),
|
||||||
'title' => trans('firefly.box_earned_in_currency', ['currency' => $currency->symbol]),
|
'title' => trans('firefly.box_earned_in_currency', ['currency' => $currency->symbol]),
|
||||||
'monetary_value' => round((float) ($incomes[$currencyId] ?? 0), $currency->decimal_places),
|
'monetary_value' => $incomes[$currencyId] ?? '0',
|
||||||
'currency_id' => $currency->id,
|
'currency_id' => $currency->id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
'currency_symbol' => $currency->symbol,
|
'currency_symbol' => $currency->symbol,
|
||||||
@@ -251,7 +251,7 @@ class BasicController extends Controller
|
|||||||
$return[] = [
|
$return[] = [
|
||||||
'key' => sprintf('bills-paid-in-%s', $currency->code),
|
'key' => sprintf('bills-paid-in-%s', $currency->code),
|
||||||
'title' => trans('firefly.box_bill_paid_in_currency', ['currency' => $currency->symbol]),
|
'title' => trans('firefly.box_bill_paid_in_currency', ['currency' => $currency->symbol]),
|
||||||
'monetary_value' => round((float) $amount, $currency->decimal_places),
|
'monetary_value' => $amount,
|
||||||
'currency_id' => $currency->id,
|
'currency_id' => $currency->id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
'currency_symbol' => $currency->symbol,
|
'currency_symbol' => $currency->symbol,
|
||||||
@@ -271,7 +271,7 @@ class BasicController extends Controller
|
|||||||
$return[] = [
|
$return[] = [
|
||||||
'key' => sprintf('bills-unpaid-in-%s', $currency->code),
|
'key' => sprintf('bills-unpaid-in-%s', $currency->code),
|
||||||
'title' => trans('firefly.box_bill_unpaid_in_currency', ['currency' => $currency->symbol]),
|
'title' => trans('firefly.box_bill_unpaid_in_currency', ['currency' => $currency->symbol]),
|
||||||
'monetary_value' => round((float) $amount, $currency->decimal_places),
|
'monetary_value' => $amount,
|
||||||
'currency_id' => $currency->id,
|
'currency_id' => $currency->id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
'currency_symbol' => $currency->symbol,
|
'currency_symbol' => $currency->symbol,
|
||||||
@@ -315,7 +315,7 @@ class BasicController extends Controller
|
|||||||
$return[] = [
|
$return[] = [
|
||||||
'key' => sprintf('left-to-spend-in-%s', $row['currency_code']),
|
'key' => sprintf('left-to-spend-in-%s', $row['currency_code']),
|
||||||
'title' => trans('firefly.box_left_to_spend_in_currency', ['currency' => $row['currency_symbol']]),
|
'title' => trans('firefly.box_left_to_spend_in_currency', ['currency' => $row['currency_symbol']]),
|
||||||
'monetary_value' => round((float) $leftToSpend, $row['currency_decimal_places']),
|
'monetary_value' => $leftToSpend,
|
||||||
'currency_id' => $row['currency_id'],
|
'currency_id' => $row['currency_id'],
|
||||||
'currency_code' => $row['currency_code'],
|
'currency_code' => $row['currency_code'],
|
||||||
'currency_symbol' => $row['currency_symbol'],
|
'currency_symbol' => $row['currency_symbol'],
|
||||||
@@ -373,8 +373,8 @@ class BasicController extends Controller
|
|||||||
foreach ($netWorthSet as $data) {
|
foreach ($netWorthSet as $data) {
|
||||||
/** @var TransactionCurrency $currency */
|
/** @var TransactionCurrency $currency */
|
||||||
$currency = $data['currency'];
|
$currency = $data['currency'];
|
||||||
$amount = round((float) $data['balance'], $currency->decimal_places);
|
$amount = $data['balance'];
|
||||||
if (0.0 === $amount) {
|
if (0 === bccomp($amount, '0')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// return stuff
|
// return stuff
|
||||||
|
|||||||
@@ -104,9 +104,10 @@ class StoreRequest extends FormRequest
|
|||||||
$validator->after(
|
$validator->after(
|
||||||
static function (Validator $validator) {
|
static function (Validator $validator) {
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
$min = (float) ($data['amount_min'] ?? 0);
|
$min = $data['amount_min'] ?? '0';
|
||||||
$max = (float) ($data['amount_max'] ?? 0);
|
$max = $data['amount_max'] ?? '0';
|
||||||
if ($min > $max) {
|
|
||||||
|
if (1 === bccomp($min, $max)) {
|
||||||
$validator->errors()->add('amount_min', (string) trans('validation.amount_min_over_max'));
|
$validator->errors()->add('amount_min', (string) trans('validation.amount_min_over_max'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,9 +105,10 @@ class UpdateRequest extends FormRequest
|
|||||||
static function (Validator $validator) {
|
static function (Validator $validator) {
|
||||||
$data = $validator->getData();
|
$data = $validator->getData();
|
||||||
if (array_key_exists('amount_min', $data) && array_key_exists('amount_max', $data)) {
|
if (array_key_exists('amount_min', $data) && array_key_exists('amount_max', $data)) {
|
||||||
$min = (float) ($data['amount_min'] ?? 0);
|
$min = $data['amount_min'] ?? '0';
|
||||||
$max = (float) ($data['amount_max'] ?? 0);
|
$max = $data['amount_max'] ?? '0';
|
||||||
if ($min > $max) {
|
|
||||||
|
if (1 === bccomp($min, $max)) {
|
||||||
$validator->errors()->add('amount_min', (string) trans('validation.amount_min_over_max'));
|
$validator->errors()->add('amount_min', (string) trans('validation.amount_min_over_max'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class PreferenceStoreRequest extends FormRequest
|
|||||||
if ('false' === $array['data']) {
|
if ('false' === $array['data']) {
|
||||||
$array['data'] = false;
|
$array['data'] = false;
|
||||||
}
|
}
|
||||||
|
// TODO remove float
|
||||||
if (is_numeric($array['data'])) {
|
if (is_numeric($array['data'])) {
|
||||||
$array['data'] = (float) $array['data'];
|
$array['data'] = (float) $array['data'];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class PreferenceUpdateRequest extends FormRequest
|
|||||||
if ('false' === $array['data']) {
|
if ('false' === $array['data']) {
|
||||||
$array['data'] = false;
|
$array['data'] = false;
|
||||||
}
|
}
|
||||||
|
// TODO remove float
|
||||||
if (is_numeric($array['data'])) {
|
if (is_numeric($array['data'])) {
|
||||||
$array['data'] = (float) $array['data'];
|
$array['data'] = (float) $array['data'];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ class MigrateToGroups extends Command
|
|||||||
{
|
{
|
||||||
$set = $journal->transactions->filter(
|
$set = $journal->transactions->filter(
|
||||||
static function (Transaction $subject) use ($transaction) {
|
static function (Transaction $subject) use ($transaction) {
|
||||||
$amount = (float) $transaction->amount * -1 === (float) $subject->amount;
|
$amount = (float) $transaction->amount * -1 === (float) $subject->amount; // intentional float
|
||||||
$identifier = $transaction->identifier === $subject->identifier;
|
$identifier = $transaction->identifier === $subject->identifier;
|
||||||
Log::debug(sprintf('Amount the same? %s', var_export($amount, true)));
|
Log::debug(sprintf('Amount the same? %s', var_export($amount, true)));
|
||||||
Log::debug(sprintf('ID the same? %s', var_export($identifier, true)));
|
Log::debug(sprintf('ID the same? %s', var_export($identifier, true)));
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ class TagFactory
|
|||||||
public function create(array $data): ?Tag
|
public function create(array $data): ?Tag
|
||||||
{
|
{
|
||||||
$zoomLevel = 0 === (int) $data['zoom_level'] ? null : (int) $data['zoom_level'];
|
$zoomLevel = 0 === (int) $data['zoom_level'] ? null : (int) $data['zoom_level'];
|
||||||
$latitude = 0.0 === (float) $data['latitude'] ? null : (float) $data['latitude'];
|
$latitude = 0.0 === (float) $data['latitude'] ? null : (float) $data['latitude']; // intentional float
|
||||||
$longitude = 0.0 === (float) $data['longitude'] ? null : (float) $data['longitude'];
|
$longitude = 0.0 === (float) $data['longitude'] ? null : (float) $data['longitude']; // intentional float
|
||||||
$array = [
|
$array = [
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'tag' => trim($data['tag']),
|
'tag' => trim($data['tag']),
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class ChartJsGenerator implements GeneratorInterface
|
|||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($data as $key => $valueArray) {
|
foreach ($data as $key => $valueArray) {
|
||||||
// make larger than 0
|
// make larger than 0
|
||||||
$chartData['datasets'][0]['data'][] = (float) app('steam')->positive((string) $valueArray['amount']);
|
$chartData['datasets'][0]['data'][] = app('steam')->positive((string) $valueArray['amount']);
|
||||||
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
|
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
|
||||||
$chartData['datasets'][0]['currency_symbol'][] = $valueArray['currency_symbol'];
|
$chartData['datasets'][0]['currency_symbol'][] = $valueArray['currency_symbol'];
|
||||||
$chartData['labels'][] = $key;
|
$chartData['labels'][] = $key;
|
||||||
@@ -174,7 +174,7 @@ class ChartJsGenerator implements GeneratorInterface
|
|||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
// make larger than 0
|
// make larger than 0
|
||||||
$chartData['datasets'][0]['data'][] = (float) app('steam')->positive((string) $value);
|
$chartData['datasets'][0]['data'][] = app('steam')->positive((string) $value);
|
||||||
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
|
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
|
||||||
|
|
||||||
$chartData['labels'][] = $key;
|
$chartData['labels'][] = $key;
|
||||||
|
|||||||
@@ -143,9 +143,9 @@ class EditController extends Controller
|
|||||||
'BIC' => $repository->getMetaValue($account, 'BIC'),
|
'BIC' => $repository->getMetaValue($account, 'BIC'),
|
||||||
'opening_balance_date' => $openingBalanceDate,
|
'opening_balance_date' => $openingBalanceDate,
|
||||||
'liability_type_id' => $account->account_type_id,
|
'liability_type_id' => $account->account_type_id,
|
||||||
'opening_balance' => number_format((float) $openingBalanceAmount, $currency->decimal_places, '.', ''),
|
'opening_balance' => app('steam')->bcround($openingBalanceAmount, $currency->decimal_places),
|
||||||
'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'),
|
'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'),
|
||||||
'virtual_balance' => number_format((float) $account->virtual_balance, $currency->decimal_places, '.', ''),
|
'virtual_balance' => app('steam')->bcround($account->virtual_balance, $currency->decimal_places),
|
||||||
'currency_id' => $currency->id,
|
'currency_id' => $currency->id,
|
||||||
'include_net_worth' => $includeNetWorth,
|
'include_net_worth' => $includeNetWorth,
|
||||||
'interest' => $repository->getMetaValue($account, 'interest'),
|
'interest' => $repository->getMetaValue($account, 'interest'),
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class IndexController extends Controller
|
|||||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||||
$account->interest = number_format((float) $this->repository->getMetaValue($account, 'interest'), 4, '.', '');
|
$account->interest = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4);
|
||||||
$account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
|
$account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
|
||||||
$account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type));
|
$account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type));
|
||||||
$account->current_debt = '0';
|
$account->current_debt = '0';
|
||||||
@@ -174,7 +174,7 @@ class IndexController extends Controller
|
|||||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||||
$account->interest = number_format((float) $this->repository->getMetaValue($account, 'interest'), 4, '.', '');
|
$account->interest = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4);
|
||||||
$account->interestPeriod = (string) trans(
|
$account->interestPeriod = (string) trans(
|
||||||
sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))
|
sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -128,8 +128,8 @@ class ReconcileController extends Controller
|
|||||||
|
|
||||||
$startDate = clone $start;
|
$startDate = clone $start;
|
||||||
$startDate->subDay();
|
$startDate->subDay();
|
||||||
$startBalance = number_format((float) app('steam')->balance($account, $startDate), $currency->decimal_places, '.', '');
|
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
|
||||||
$endBalance = number_format((float) app('steam')->balance($account, $end), $currency->decimal_places, '.', '');
|
$endBalance = app('steam')->bcround( app('steam')->balance($account, $end), $currency->decimal_places);
|
||||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
||||||
$subTitle = (string) trans('firefly.reconcile_account', ['account' => $account->name]);
|
$subTitle = (string) trans('firefly.reconcile_account', ['account' => $account->name]);
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ class EditController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$currency = app('amount')->getDefaultCurrency();
|
$currency = app('amount')->getDefaultCurrency();
|
||||||
$bill->amount_min = round((float) $bill->amount_min, $currency->decimal_places);
|
$bill->amount_min = app('steam')->bcround($bill->amount_min, $currency->decimal_places);
|
||||||
$bill->amount_max = round((float) $bill->amount_max, $currency->decimal_places);
|
$bill->amount_max = app('steam')->bcround($bill->amount_max, $currency->decimal_places);
|
||||||
$rules = $this->repository->getRulesForBill($bill);
|
$rules = $this->repository->getRulesForBill($bill);
|
||||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ class AvailableBudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end)
|
public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
$availableBudget->amount = number_format((float) $availableBudget->amount, $availableBudget->transactionCurrency->decimal_places, '.', '');
|
$availableBudget->amount = app('steam')->bcround($availableBudget->amount, $availableBudget->transactionCurrency->decimal_places);
|
||||||
|
|
||||||
return view('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end'));
|
return view('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class BudgetLimitController extends Controller
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', (string) trans('firefly.budgets'));
|
app('view')->share('title', (string)trans('firefly.budgets'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-pie-chart');
|
app('view')->share('mainTitleIcon', 'fa-pie-chart');
|
||||||
$this->repository = app(BudgetRepositoryInterface::class);
|
$this->repository = app(BudgetRepositoryInterface::class);
|
||||||
$this->opsRepository = app(OperationsRepositoryInterface::class);
|
$this->opsRepository = app(OperationsRepositoryInterface::class);
|
||||||
@@ -130,14 +130,14 @@ class BudgetLimitController extends Controller
|
|||||||
{
|
{
|
||||||
Log::debug('Going to store new budget-limit.', $request->all());
|
Log::debug('Going to store new budget-limit.', $request->all());
|
||||||
// first search for existing one and update it if necessary.
|
// first search for existing one and update it if necessary.
|
||||||
$currency = $this->currencyRepos->find((int) $request->get('transaction_currency_id'));
|
$currency = $this->currencyRepos->find((int)$request->get('transaction_currency_id'));
|
||||||
$budget = $this->repository->find((int) $request->get('budget_id'));
|
$budget = $this->repository->find((int)$request->get('budget_id'));
|
||||||
if (null === $currency || null === $budget) {
|
if (null === $currency || null === $budget) {
|
||||||
throw new FireflyException('No valid currency or budget.');
|
throw new FireflyException('No valid currency or budget.');
|
||||||
}
|
}
|
||||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||||
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
||||||
$amount = (string) $request->get('amount');
|
$amount = (string)$request->get('amount');
|
||||||
$start->startOfDay();
|
$start->startOfDay();
|
||||||
$end->startOfDay();
|
$end->startOfDay();
|
||||||
|
|
||||||
@@ -150,17 +150,17 @@ class BudgetLimitController extends Controller
|
|||||||
$limit = $this->blRepository->find($budget, $currency, $start, $end);
|
$limit = $this->blRepository->find($budget, $currency, $start, $end);
|
||||||
|
|
||||||
// sanity check on amount:
|
// sanity check on amount:
|
||||||
if ((float) $amount === 0.0) {
|
if (0 === bccomp($amount, '0')) {
|
||||||
if (null !== $limit) {
|
if (null !== $limit) {
|
||||||
$this->blRepository->destroyBudgetLimit($limit);
|
$this->blRepository->destroyBudgetLimit($limit);
|
||||||
}
|
}
|
||||||
// return empty=ish array:
|
// return empty=ish array:
|
||||||
return response()->json([]);
|
return response()->json([]);
|
||||||
}
|
}
|
||||||
if ((int) $amount > 268435456) {
|
if ((int)$amount > 268435456) { // intentional cast to integer
|
||||||
$amount = '268435456';
|
$amount = '268435456';
|
||||||
}
|
}
|
||||||
if((float) $amount < 0.0) {
|
if (-1 === bccomp($amount, '0')) {
|
||||||
$amount = bcmul($amount, '-1');
|
$amount = bcmul($amount, '-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ class BudgetLimitController extends Controller
|
|||||||
$limit = $this->blRepository->store(
|
$limit = $this->blRepository->store(
|
||||||
[
|
[
|
||||||
'budget_id' => $request->get('budget_id'),
|
'budget_id' => $request->get('budget_id'),
|
||||||
'currency_id' => (int) $request->get('transaction_currency_id'),
|
'currency_id' => (int)$request->get('transaction_currency_id'),
|
||||||
'start_date' => $start,
|
'start_date' => $start,
|
||||||
'end_date' => $end,
|
'end_date' => $end,
|
||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
@@ -187,7 +187,7 @@ class BudgetLimitController extends Controller
|
|||||||
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
|
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
|
||||||
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
|
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
|
||||||
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
|
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
|
||||||
$array['days_left'] = (string) $this->activeDaysLeft($start, $end);
|
$array['days_left'] = (string)$this->activeDaysLeft($start, $end);
|
||||||
// left per day:
|
// left per day:
|
||||||
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
|
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
|
||||||
|
|
||||||
@@ -208,13 +208,13 @@ class BudgetLimitController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function update(Request $request, BudgetLimit $budgetLimit): JsonResponse
|
public function update(Request $request, BudgetLimit $budgetLimit): JsonResponse
|
||||||
{
|
{
|
||||||
$amount = (string) $request->get('amount');
|
$amount = (string)$request->get('amount');
|
||||||
if ('' === $amount) {
|
if ('' === $amount) {
|
||||||
$amount = '0';
|
$amount = '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// sanity check on amount:
|
// sanity check on amount:
|
||||||
if ((float) $amount === 0.0) {
|
if (0 === bccomp($amount, '0')) {
|
||||||
$budgetId = $budgetLimit->budget_id;
|
$budgetId = $budgetLimit->budget_id;
|
||||||
$currency = $budgetLimit->transactionCurrency;
|
$currency = $budgetLimit->transactionCurrency;
|
||||||
$this->blRepository->destroyBudgetLimit($budgetLimit);
|
$this->blRepository->destroyBudgetLimit($budgetLimit);
|
||||||
@@ -226,10 +226,10 @@ class BudgetLimitController extends Controller
|
|||||||
];
|
];
|
||||||
return response()->json($array);
|
return response()->json($array);
|
||||||
}
|
}
|
||||||
if ((int) $amount > 268435456) { // 268 million
|
if ((int)$amount > 268435456) { // 268 million, intentional integer
|
||||||
$amount = '268435456';
|
$amount = '268435456';
|
||||||
}
|
}
|
||||||
if((float) $amount < 0.0) {
|
if (-1 === bccomp($amount, '0')) {
|
||||||
$amount = bcmul($amount, '-1');
|
$amount = bcmul($amount, '-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,12 +246,12 @@ class BudgetLimitController extends Controller
|
|||||||
$array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0';
|
$array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0';
|
||||||
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
|
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
|
||||||
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
|
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
|
||||||
$array['days_left'] = (string) $this->activeDaysLeft($limit->start_date, $limit->end_date);
|
$array['days_left'] = (string)$this->activeDaysLeft($limit->start_date, $limit->end_date);
|
||||||
// left per day:
|
// left per day:
|
||||||
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
|
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
|
||||||
|
|
||||||
// left per day formatted.
|
// left per day formatted.
|
||||||
$array['amount'] = number_format((float) $limit['amount'], $limit->transactionCurrency->decimal_places, '.', '');
|
$array['amount'] = app('steam')->bcround($limit['amount'], $limit->transactionCurrency->decimal_places);
|
||||||
$array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']);
|
$array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']);
|
||||||
|
|
||||||
return response()->json($array);
|
return response()->json($array);
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class EditController extends Controller
|
|||||||
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', (string) trans('firefly.budgets'));
|
app('view')->share('title', (string)trans('firefly.budgets'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-pie-chart');
|
app('view')->share('mainTitleIcon', 'fa-pie-chart');
|
||||||
$this->repository = app(BudgetRepositoryInterface::class);
|
$this->repository = app(BudgetRepositoryInterface::class);
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
@@ -76,34 +76,34 @@ class EditController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(Request $request, Budget $budget)
|
public function edit(Request $request, Budget $budget)
|
||||||
{
|
{
|
||||||
$subTitle = (string) trans('firefly.edit_budget', ['name' => $budget->name]);
|
$subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]);
|
||||||
$autoBudget = $this->repository->getAutoBudget($budget);
|
$autoBudget = $this->repository->getAutoBudget($budget);
|
||||||
|
|
||||||
// auto budget types
|
// auto budget types
|
||||||
$autoBudgetTypes = [
|
$autoBudgetTypes = [
|
||||||
0 => (string) trans('firefly.auto_budget_none'),
|
0 => (string)trans('firefly.auto_budget_none'),
|
||||||
AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'),
|
AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'),
|
||||||
AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'),
|
AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'),
|
||||||
];
|
];
|
||||||
$autoBudgetPeriods = [
|
$autoBudgetPeriods = [
|
||||||
'daily' => (string) trans('firefly.auto_budget_period_daily'),
|
'daily' => (string)trans('firefly.auto_budget_period_daily'),
|
||||||
'weekly' => (string) trans('firefly.auto_budget_period_weekly'),
|
'weekly' => (string)trans('firefly.auto_budget_period_weekly'),
|
||||||
'monthly' => (string) trans('firefly.auto_budget_period_monthly'),
|
'monthly' => (string)trans('firefly.auto_budget_period_monthly'),
|
||||||
'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'),
|
'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'),
|
||||||
'half_year' => (string) trans('firefly.auto_budget_period_half_year'),
|
'half_year' => (string)trans('firefly.auto_budget_period_half_year'),
|
||||||
'yearly' => (string) trans('firefly.auto_budget_period_yearly'),
|
'yearly' => (string)trans('firefly.auto_budget_period_yearly'),
|
||||||
];
|
];
|
||||||
|
|
||||||
// code to handle active-checkboxes
|
// code to handle active-checkboxes
|
||||||
$hasOldInput = null !== $request->old('_token');
|
$hasOldInput = null !== $request->old('_token');
|
||||||
$currency = app('amount')->getDefaultCurrency();
|
$currency = app('amount')->getDefaultCurrency();
|
||||||
$preFilled = [
|
$preFilled = [
|
||||||
'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active,
|
'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active,
|
||||||
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id,
|
'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id,
|
||||||
];
|
];
|
||||||
if ($autoBudget) {
|
if ($autoBudget) {
|
||||||
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
|
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
|
||||||
$preFilled['auto_budget_amount'] = number_format((float) $amount, $autoBudget->transactionCurrency->decimal_places, '.', '');
|
$preFilled['auto_budget_amount'] = app('steam')->bcround($amount, $autoBudget->transactionCurrency->decimal_places);
|
||||||
}
|
}
|
||||||
|
|
||||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||||
@@ -129,7 +129,7 @@ class EditController extends Controller
|
|||||||
$data = $request->getBudgetData();
|
$data = $request->getBudgetData();
|
||||||
$this->repository->update($budget, $data);
|
$this->repository->update($budget, $data);
|
||||||
|
|
||||||
$request->session()->flash('success', (string) trans('firefly.updated_budget', ['name' => $budget->name]));
|
$request->session()->flash('success', (string)trans('firefly.updated_budget', ['name' => $budget->name]));
|
||||||
$this->repository->cleanupBudgets();
|
$this->repository->cleanupBudgets();
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
|
|
||||||
@@ -141,19 +141,17 @@ class EditController extends Controller
|
|||||||
$this->attachments->saveAttachmentsForModel($budget, $files);
|
$this->attachments->saveAttachmentsForModel($budget, $files);
|
||||||
}
|
}
|
||||||
if (null !== $files && auth()->user()->hasRole('demo')) {
|
if (null !== $files && auth()->user()->hasRole('demo')) {
|
||||||
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
|
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||||
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1 === (int) $request->get('return_to_edit')) {
|
if (1 === (int)$request->get('return_to_edit')) {
|
||||||
|
|
||||||
$request->session()->put('budgets.edit.fromUpdate', true);
|
$request->session()->put('budgets.edit.fromUpdate', true);
|
||||||
|
|
||||||
$redirect = redirect(route('budgets.edit', [$budget->id]))->withInput(['return_to_edit' => 1]);
|
$redirect = redirect(route('budgets.edit', [$budget->id]))->withInput(['return_to_edit' => 1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $redirect;
|
return $redirect;
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ class IndexController extends Controller
|
|||||||
$currency = $limit->transactionCurrency ?? $defaultCurrency;
|
$currency = $limit->transactionCurrency ?? $defaultCurrency;
|
||||||
$array['budgeted'][] = [
|
$array['budgeted'][] = [
|
||||||
'id' => $limit->id,
|
'id' => $limit->id,
|
||||||
'amount' => number_format((float) $limit->amount, $currency->decimal_places, '.', ''),
|
'amount' => app('steam')->bcround($limit->amount, $currency->decimal_places),
|
||||||
'start_date' => $limit->start_date->isoFormat($this->monthAndDayFormat),
|
'start_date' => $limit->start_date->isoFormat($this->monthAndDayFormat),
|
||||||
'end_date' => $limit->end_date->isoFormat($this->monthAndDayFormat),
|
'end_date' => $limit->end_date->isoFormat($this->monthAndDayFormat),
|
||||||
'in_range' => $limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end),
|
'in_range' => $limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end),
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class AccountController extends Controller
|
|||||||
$tempData[] = [
|
$tempData[] = [
|
||||||
'name' => $accountNames[$accountId],
|
'name' => $accountNames[$accountId],
|
||||||
'difference' => $diff,
|
'difference' => $diff,
|
||||||
'diff_float' => (float) $diff,
|
'diff_float' => (float) $diff, // intentional float
|
||||||
'currency_id' => $currencyId,
|
'currency_id' => $currencyId,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -492,7 +492,7 @@ class AccountController extends Controller
|
|||||||
$theDate = $current->format('Y-m-d');
|
$theDate = $current->format('Y-m-d');
|
||||||
$balance = $range[$theDate] ?? $previous;
|
$balance = $range[$theDate] ?? $previous;
|
||||||
$label = $current->isoFormat($format);
|
$label = $current->isoFormat($format);
|
||||||
$entries[$label] = (float) $balance;
|
$entries[$label] = $balance;
|
||||||
$previous = $balance;
|
$previous = $balance;
|
||||||
$current->addDay();
|
$current->addDay();
|
||||||
}
|
}
|
||||||
@@ -502,7 +502,7 @@ class AccountController extends Controller
|
|||||||
case '1M':
|
case '1M':
|
||||||
case '1Y':
|
case '1Y':
|
||||||
while ($end >= $current) {
|
while ($end >= $current) {
|
||||||
$balance = (float) app('steam')->balance($account, $current, $currency);
|
$balance = app('steam')->balance($account, $current, $currency);
|
||||||
$label = app('navigation')->periodShow($current, $step);
|
$label = app('navigation')->periodShow($current, $step);
|
||||||
$entries[$label] = $balance;
|
$entries[$label] = $balance;
|
||||||
$current = app('navigation')->addPeriod($current, $step, 0);
|
$current = app('navigation')->addPeriod($current, $step, 0);
|
||||||
@@ -586,7 +586,7 @@ class AccountController extends Controller
|
|||||||
$tempData[] = [
|
$tempData[] = [
|
||||||
'name' => $accountNames[$accountId],
|
'name' => $accountNames[$accountId],
|
||||||
'difference' => $diff,
|
'difference' => $diff,
|
||||||
'diff_float' => (float) $diff,
|
'diff_float' => (float) $diff, // intentional float
|
||||||
'currency_id' => $currencyId,
|
'currency_id' => $currencyId,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -483,13 +483,13 @@ class BudgetController extends Controller
|
|||||||
// get budget limit in this period for this currency.
|
// get budget limit in this period for this currency.
|
||||||
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
|
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
|
||||||
if (null !== $limit) {
|
if (null !== $limit) {
|
||||||
$chartData[1]['entries'][$title] = round((float) $limit->amount, $currency->decimal_places);
|
$chartData[1]['entries'][$title] = app('steam')->bcround($limit->amount, $currency->decimal_places);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get spent amount in this period for this currency.
|
// get spent amount in this period for this currency.
|
||||||
$sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection([$budget]), $currency);
|
$sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection([$budget]), $currency);
|
||||||
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
|
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
|
||||||
$chartData[0]['entries'][$title] = round((float) $amount, $currency->decimal_places);
|
$chartData[0]['entries'][$title] = app('steam')->bcround($amount, $currency->decimal_places);
|
||||||
|
|
||||||
$currentStart = clone $currentEnd;
|
$currentStart = clone $currentEnd;
|
||||||
$currentStart->addDay()->startOfDay();
|
$currentStart->addDay()->startOfDay();
|
||||||
@@ -534,7 +534,7 @@ class BudgetController extends Controller
|
|||||||
$title = $currentStart->isoFormat($titleFormat);
|
$title = $currentStart->isoFormat($titleFormat);
|
||||||
$sum = $this->nbRepository->sumExpenses($currentStart, $currentEnd, $accounts, $currency);
|
$sum = $this->nbRepository->sumExpenses($currentStart, $currentEnd, $accounts, $currency);
|
||||||
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
|
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
|
||||||
$chartData[$title] = round((float) $amount, $currency->decimal_places);
|
$chartData[$title] = app('steam')->bcround($amount, $currency->decimal_places);
|
||||||
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -243,8 +243,8 @@ class ReportController extends Controller
|
|||||||
while ($currentStart <= $end) {
|
while ($currentStart <= $end) {
|
||||||
$key = $currentStart->format($format);
|
$key = $currentStart->format($format);
|
||||||
$title = $currentStart->isoFormat($titleFormat);
|
$title = $currentStart->isoFormat($titleFormat);
|
||||||
$income['entries'][$title] = round((float) ($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']);
|
$income['entries'][$title] = app('steam')->bcround(($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']);
|
||||||
$expense['entries'][$title] = round((float) ($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']);
|
$expense['entries'][$title] = app('steam')->bcround(($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']);
|
||||||
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FrontpageController.php
|
* FrontpageController.php
|
||||||
* Copyright (c) 2019 james@firefly-iii.org
|
* Copyright (c) 2019 james@firefly-iii.org
|
||||||
@@ -51,7 +52,7 @@ class FrontpageController extends Controller
|
|||||||
if (1 === bccomp($amount, '0')) {
|
if (1 === bccomp($amount, '0')) {
|
||||||
// percentage!
|
// percentage!
|
||||||
$pct = 0;
|
$pct = 0;
|
||||||
if (0.0 !== (float) $piggyBank->targetamount) {
|
if (0 !== bccomp($piggyBank->targetamount, '0')) {
|
||||||
$pct = round(($amount / $piggyBank->targetamount) * 100);
|
$pct = round(($amount / $piggyBank->targetamount) * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,12 +71,10 @@ class FrontpageController extends Controller
|
|||||||
if (!empty($info)) {
|
if (!empty($info)) {
|
||||||
try {
|
try {
|
||||||
$html = view('json.piggy-banks', compact('info'))->render();
|
$html = view('json.piggy-banks', compact('info'))->render();
|
||||||
|
|
||||||
} catch (Throwable $e) { // @phpstan-ignore-line
|
} catch (Throwable $e) { // @phpstan-ignore-line
|
||||||
Log::error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage()));
|
Log::error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage()));
|
||||||
$html = 'Could not render view.';
|
$html = 'Could not render view.';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['html' => $html]);
|
return response()->json(['html' => $html]);
|
||||||
|
|||||||
@@ -238,8 +238,8 @@ class ReconcileController extends Controller
|
|||||||
$startDate->subDay();
|
$startDate->subDay();
|
||||||
|
|
||||||
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||||
$startBalance = round((float) app('steam')->balance($account, $startDate), $currency->decimal_places);
|
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
|
||||||
$endBalance = round((float) app('steam')->balance($account, $end), $currency->decimal_places);
|
$endBalance = app('steam')->bcround(app('steam')->balance($account, $end), $currency->decimal_places);
|
||||||
|
|
||||||
// get the transactions
|
// get the transactions
|
||||||
$selectionStart = clone $start;
|
$selectionStart = clone $start;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class AmountController extends Controller
|
|||||||
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, today(config('app.timezone')));
|
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, today(config('app.timezone')));
|
||||||
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||||
$maxAmount = $leftOnAccount;
|
$maxAmount = $leftOnAccount;
|
||||||
if (0.000 !== (float) $piggyBank->targetamount) {
|
if (0 !== bccomp($piggyBank->targetamount,'0')) {
|
||||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ class AmountController extends Controller
|
|||||||
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||||
$maxAmount = $leftOnAccount;
|
$maxAmount = $leftOnAccount;
|
||||||
|
|
||||||
if (0.000 !== (float) $piggyBank->targetamount) {
|
if (0 !== bccomp($piggyBank->targetamount,'0')) {
|
||||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ class AmountController extends Controller
|
|||||||
|
|
||||||
return redirect(route('piggy-banks.index'));
|
return redirect(route('piggy-banks.index'));
|
||||||
}
|
}
|
||||||
$amount = number_format((float) $request->get('amount'), 12, '.', '');
|
$amount = (string) $request->get('amount');
|
||||||
|
|
||||||
session()->flash(
|
session()->flash(
|
||||||
'error',
|
'error',
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class EditController extends Controller
|
|||||||
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', (string) trans('firefly.piggyBanks'));
|
app('view')->share('title', (string)trans('firefly.piggyBanks'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-bullseye');
|
app('view')->share('mainTitleIcon', 'fa-bullseye');
|
||||||
|
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
@@ -76,7 +76,7 @@ class EditController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(PiggyBank $piggyBank)
|
public function edit(PiggyBank $piggyBank)
|
||||||
{
|
{
|
||||||
$subTitle = (string) trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
|
$subTitle = (string)trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
|
||||||
$subTitleIcon = 'fa-pencil';
|
$subTitleIcon = 'fa-pencil';
|
||||||
$note = $piggyBank->notes()->first();
|
$note = $piggyBank->notes()->first();
|
||||||
// Flash some data to fill the form.
|
// Flash some data to fill the form.
|
||||||
@@ -87,15 +87,16 @@ class EditController extends Controller
|
|||||||
$currency = Amount::getDefaultCurrency();
|
$currency = Amount::getDefaultCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
$preFilled = ['name' => $piggyBank->name,
|
$preFilled = [
|
||||||
|
'name' => $piggyBank->name,
|
||||||
'account_id' => $piggyBank->account_id,
|
'account_id' => $piggyBank->account_id,
|
||||||
'targetamount' => number_format((float) $piggyBank->targetamount, $currency->decimal_places, '.', ''),
|
'targetamount' => app('steam')->bcround($piggyBank->targetamount, $currency->decimal_places),
|
||||||
'targetdate' => $targetDate,
|
'targetdate' => $targetDate,
|
||||||
'startdate' => $startDate,
|
'startdate' => $startDate,
|
||||||
'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '',
|
'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '',
|
||||||
'notes' => null === $note ? '' : $note->text,
|
'notes' => null === $note ? '' : $note->text,
|
||||||
];
|
];
|
||||||
if (0.0 === (float) $piggyBank->targetamount) {
|
if (0 === bccomp($piggyBank->targetamount, '0')) {
|
||||||
$preFilled['targetamount'] = '';
|
$preFilled['targetamount'] = '';
|
||||||
}
|
}
|
||||||
session()->flash('preFilled', $preFilled);
|
session()->flash('preFilled', $preFilled);
|
||||||
@@ -122,7 +123,7 @@ class EditController extends Controller
|
|||||||
$data = $request->getPiggyBankData();
|
$data = $request->getPiggyBankData();
|
||||||
$piggyBank = $this->piggyRepos->update($piggyBank, $data);
|
$piggyBank = $this->piggyRepos->update($piggyBank, $data);
|
||||||
|
|
||||||
session()->flash('success', (string) trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name]));
|
session()->flash('success', (string)trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name]));
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
|
|
||||||
// store new attachment(s):
|
// store new attachment(s):
|
||||||
@@ -132,7 +133,7 @@ class EditController extends Controller
|
|||||||
$this->attachments->saveAttachmentsForModel($piggyBank, $files);
|
$this->attachments->saveAttachmentsForModel($piggyBank, $files);
|
||||||
}
|
}
|
||||||
if (null !== $files && auth()->user()->hasRole('demo')) {
|
if (null !== $files && auth()->user()->hasRole('demo')) {
|
||||||
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
|
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||||
@@ -140,12 +141,10 @@ class EditController extends Controller
|
|||||||
}
|
}
|
||||||
$redirect = redirect($this->getPreviousUrl('piggy-banks.edit.url'));
|
$redirect = redirect($this->getPreviousUrl('piggy-banks.edit.url'));
|
||||||
|
|
||||||
if (1 === (int) $request->get('return_to_edit')) {
|
if (1 === (int)$request->get('return_to_edit')) {
|
||||||
|
|
||||||
session()->put('piggy-banks.edit.fromUpdate', true);
|
session()->put('piggy-banks.edit.fromUpdate', true);
|
||||||
|
|
||||||
$redirect = redirect(route('piggy-banks.edit', [$piggyBank->id]));
|
$redirect = redirect(route('piggy-banks.edit', [$piggyBank->id]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $redirect;
|
return $redirect;
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ class BudgetController extends Controller
|
|||||||
$result[$key]['transactions']++;
|
$result[$key]['transactions']++;
|
||||||
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
|
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
|
||||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
|
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
|
||||||
$result[$key]['avg_float'] = (float) $result[$key]['avg'];
|
$result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ class BudgetController extends Controller
|
|||||||
$total = $sums[$currencyId]['sum'] ?? '0';
|
$total = $sums[$currencyId]['sum'] ?? '0';
|
||||||
$pct = '0';
|
$pct = '0';
|
||||||
if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) {
|
if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) {
|
||||||
$pct = round((float) bcmul(bcdiv($sum, $total), '100'));
|
$pct = round((float) bcmul(bcdiv($sum, $total), '100')); // intentional float
|
||||||
}
|
}
|
||||||
$report[$budgetId]['currencies'][$currencyId]['sum_pct'] = $pct;
|
$report[$budgetId]['currencies'][$currencyId]['sum_pct'] = $pct;
|
||||||
}
|
}
|
||||||
@@ -383,7 +383,7 @@ class BudgetController extends Controller
|
|||||||
$result[] = [
|
$result[] = [
|
||||||
'description' => $journal['description'],
|
'description' => $journal['description'],
|
||||||
'transaction_group_id' => $journal['transaction_group_id'],
|
'transaction_group_id' => $journal['transaction_group_id'],
|
||||||
'amount_float' => (float) $journal['amount'],
|
'amount_float' => (float) $journal['amount'], // intentional float
|
||||||
'amount' => $journal['amount'],
|
'amount' => $journal['amount'],
|
||||||
'date' => $journal['date']->isoFormat($this->monthAndDayFormat),
|
'date' => $journal['date']->isoFormat($this->monthAndDayFormat),
|
||||||
'date_sort' => $journal['date']->format('Y-m-d'),
|
'date_sort' => $journal['date']->format('Y-m-d'),
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ class CategoryController extends Controller
|
|||||||
$result[$key]['transactions']++;
|
$result[$key]['transactions']++;
|
||||||
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
|
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
|
||||||
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
|
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']);
|
||||||
$result[$key]['avg_float'] = (float) $result[$key]['avg'];
|
$result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ class MassController extends Controller
|
|||||||
|
|
||||||
// reverse amounts
|
// reverse amounts
|
||||||
foreach ($journals as $index => $journal) {
|
foreach ($journals as $index => $journal) {
|
||||||
$journals[$index]['amount'] = number_format((float) app('steam')->positive($journal['amount']), $journal['currency_decimal_places'], '.', '');
|
$journals[$index]['amount'] = app('steam')->bcround(app('steam')->positive($journal['amount']), $journal['currency_decimal_places']);
|
||||||
$journals[$index]['foreign_amount'] = null === $journal['foreign_amount'] ?
|
$journals[$index]['foreign_amount'] = null === $journal['foreign_amount'] ?
|
||||||
null : app('steam')->positive($journal['foreign_amount']);
|
null : app('steam')->positive($journal['foreign_amount']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class AccountTasker implements AccountTaskerInterface
|
|||||||
// Obtain a list of columns
|
// Obtain a list of columns
|
||||||
$sum = [];
|
$sum = [];
|
||||||
foreach ($report['accounts'] as $accountId => $row) {
|
foreach ($report['accounts'] as $accountId => $row) {
|
||||||
$sum[$accountId] = (float) $row['sum'];
|
$sum[$accountId] = (float) $row['sum']; // intentional float
|
||||||
}
|
}
|
||||||
|
|
||||||
array_multisort($sum, SORT_ASC, $report['accounts']);
|
array_multisort($sum, SORT_ASC, $report['accounts']);
|
||||||
@@ -235,7 +235,7 @@ class AccountTasker implements AccountTaskerInterface
|
|||||||
// Obtain a list of columns
|
// Obtain a list of columns
|
||||||
$sum = [];
|
$sum = [];
|
||||||
foreach ($report['accounts'] as $accountId => $row) {
|
foreach ($report['accounts'] as $accountId => $row) {
|
||||||
$sum[$accountId] = (float) $row['sum'];
|
$sum[$accountId] = (float) $row['sum']; // intentional float
|
||||||
}
|
}
|
||||||
|
|
||||||
array_multisort($sum, SORT_DESC, $report['accounts']);
|
array_multisort($sum, SORT_DESC, $report['accounts']);
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
|||||||
'currency_name' => $currency['name'],
|
'currency_name' => $currency['name'],
|
||||||
'currency_symbol' => $currency['symbol'],
|
'currency_symbol' => $currency['symbol'],
|
||||||
'currency_decimal_places' => $currency['decimal_places'],
|
'currency_decimal_places' => $currency['decimal_places'],
|
||||||
'amount' => number_format((float) $spent, $currency['decimal_places'], '.', ''),
|
'amount' => app('steam')->bcround($spent, $currency['decimal_places']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
'currency_name' => $currency['name'],
|
'currency_name' => $currency['name'],
|
||||||
'currency_symbol' => $currency['symbol'],
|
'currency_symbol' => $currency['symbol'],
|
||||||
'currency_decimal_places' => $currency['decimal_places'],
|
'currency_decimal_places' => $currency['decimal_places'],
|
||||||
'amount' => number_format((float) $spent, $currency['decimal_places'], '.', ''),
|
'amount' => app('steam')->bcround($spent, $currency['decimal_places']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ trait ModifiesPiggyBanks
|
|||||||
$savedSoFar = (string)$this->getRepetition($piggyBank)->currentamount;
|
$savedSoFar = (string)$this->getRepetition($piggyBank)->currentamount;
|
||||||
$maxAmount = $leftOnAccount;
|
$maxAmount = $leftOnAccount;
|
||||||
$leftToSave = null;
|
$leftToSave = null;
|
||||||
if (0.0 !== (float)$piggyBank->targetamount) {
|
if (0 !== bccomp($piggyBank->targetamount, '0')) {
|
||||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||||
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
||||||
}
|
}
|
||||||
@@ -383,7 +383,7 @@ trait ModifiesPiggyBanks
|
|||||||
// if the piggy bank is now smaller than the current relevant rep,
|
// if the piggy bank is now smaller than the current relevant rep,
|
||||||
// remove money from the rep.
|
// remove money from the rep.
|
||||||
$repetition = $this->getRepetition($piggyBank);
|
$repetition = $this->getRepetition($piggyBank);
|
||||||
if (null !== $repetition && $repetition->currentamount > $piggyBank->targetamount && 0.0 !== (float)$piggyBank->targetamount) {
|
if (null !== $repetition && $repetition->currentamount > $piggyBank->targetamount && 0 !== bccomp($piggyBank->targetamount, '0')) {
|
||||||
$difference = bcsub($piggyBank->targetamount, $repetition->currentamount);
|
$difference = bcsub($piggyBank->targetamount, $repetition->currentamount);
|
||||||
|
|
||||||
// an amount will be removed, create "negative" event:
|
// an amount will be removed, create "negative" event:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amount.php
|
* Amount.php
|
||||||
* Copyright (c) 2019 james@firefly-iii.org
|
* Copyright (c) 2019 james@firefly-iii.org
|
||||||
@@ -51,7 +52,7 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function formatAnything(TransactionCurrency $format, string $amount, bool $coloured = null): string
|
public function formatAnything(TransactionCurrency $format, string $amount, bool $coloured = null): string
|
||||||
{
|
{
|
||||||
return $this->formatFlat($format->symbol, (int) $format->decimal_places, $amount, $coloured);
|
return $this->formatFlat($format->symbol, (int)$format->decimal_places, $amount, $coloured);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,13 +79,13 @@ class Amount
|
|||||||
$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
||||||
$fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
$fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
||||||
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
||||||
$result = $fmt->format((float) $amount);
|
$result = $fmt->format((float)app('steam')->bcround($amount, $decimalPlaces)); // intentional float
|
||||||
|
|
||||||
if (true === $coloured) {
|
if (true === $coloured) {
|
||||||
if ($amount > 0) {
|
if (1 === bccomp($amount, '0')) {
|
||||||
return sprintf('<span class="text-success">%s</span>', $result);
|
return sprintf('<span class="text-success">%s</span>', $result);
|
||||||
}
|
}
|
||||||
if ($amount < 0) {
|
if (-1 === bccomp($amount, '0')) {
|
||||||
return sprintf('<span class="text-danger">%s</span>', $result);
|
return sprintf('<span class="text-danger">%s</span>', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +134,7 @@ class Amount
|
|||||||
}
|
}
|
||||||
$cache->store(config('firefly.default_currency', 'EUR'));
|
$cache->store(config('firefly.default_currency', 'EUR'));
|
||||||
|
|
||||||
return (string) config('firefly.default_currency', 'EUR');
|
return (string)config('firefly.default_currency', 'EUR');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,7 +168,7 @@ class Amount
|
|||||||
$currencyPrefStr = $currencyPreference ? $currencyPreference->data : 'EUR';
|
$currencyPrefStr = $currencyPreference ? $currencyPreference->data : 'EUR';
|
||||||
|
|
||||||
// at this point the currency preference could be encrypted, if coming from an old version.
|
// at this point the currency preference could be encrypted, if coming from an old version.
|
||||||
$currencyCode = $this->tryDecrypt((string) $currencyPrefStr);
|
$currencyCode = $this->tryDecrypt((string)$currencyPrefStr);
|
||||||
|
|
||||||
// could still be json encoded:
|
// could still be json encoded:
|
||||||
/** @var TransactionCurrency|null $currency */
|
/** @var TransactionCurrency|null $currency */
|
||||||
@@ -326,11 +327,11 @@ class Amount
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default is amount before currency
|
// default is amount before currency
|
||||||
$format = $posA . $posD . '%v' . $space . $posB . '%s' . $posC . $posE;
|
$format = $posA.$posD.'%v'.$space.$posB.'%s'.$posC.$posE;
|
||||||
|
|
||||||
if ($csPrecedes) {
|
if ($csPrecedes) {
|
||||||
// alternative is currency before amount
|
// alternative is currency before amount
|
||||||
$format = $posA . $posB . '%s' . $posC . $space . $posD . '%v' . $posE;
|
$format = $posA.$posB.'%s'.$posC.$space.$posD.'%v'.$posE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $format;
|
return $format;
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ class WholePeriodChartGenerator
|
|||||||
$earnedInfoKey = sprintf('earned-in-%s', $code);
|
$earnedInfoKey = sprintf('earned-in-%s', $code);
|
||||||
$spentAmount = $spent[$key][$currencyId]['sum'] ?? '0';
|
$spentAmount = $spent[$key][$currencyId]['sum'] ?? '0';
|
||||||
$earnedAmount = $earned[$key][$currencyId]['sum'] ?? '0';
|
$earnedAmount = $earned[$key][$currencyId]['sum'] ?? '0';
|
||||||
$chartData[$spentInfoKey]['entries'][$label] = round((float) $spentAmount, $currency['currency_decimal_places']);
|
$chartData[$spentInfoKey]['entries'][$label] = app('steam')->bcround($spentAmount, $currency['currency_decimal_places']);
|
||||||
$chartData[$earnedInfoKey]['entries'][$label] = round((float) $earnedAmount, $currency['currency_decimal_places']);
|
$chartData[$earnedInfoKey]['entries'][$label] = app('steam')->bcround($earnedAmount, $currency['currency_decimal_places']);
|
||||||
}
|
}
|
||||||
$current = app('navigation')->addPeriod($current, $step, 0);
|
$current = app('navigation')->addPeriod($current, $step, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class CurrencyForm
|
|||||||
|
|
||||||
// make sure value is formatted nicely:
|
// make sure value is formatted nicely:
|
||||||
if (null !== $value && '' !== $value) {
|
if (null !== $value && '' !== $value) {
|
||||||
$value = round((float) $value, $defaultCurrency->decimal_places);
|
$value = app('steam')->bcround($value, $defaultCurrency->decimal_places);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
@@ -161,7 +161,7 @@ class CurrencyForm
|
|||||||
|
|
||||||
// make sure value is formatted nicely:
|
// make sure value is formatted nicely:
|
||||||
if (null !== $value && '' !== $value) {
|
if (null !== $value && '' !== $value) {
|
||||||
$value = round((float) $value, $defaultCurrency->decimal_places);
|
$value = app('steam')->bcround($value, $defaultCurrency->decimal_places);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
$html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Steam.php
|
* Steam.php
|
||||||
* Copyright (c) 2019 james@firefly-iii.org
|
* Copyright (c) 2019 james@firefly-iii.org
|
||||||
@@ -56,7 +57,7 @@ class Steam
|
|||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
$repository->setUser($account->user);
|
$repository->setUser($account->user);
|
||||||
|
|
||||||
$currencyId = (int) $repository->getMetaValue($account, 'currency_id');
|
$currencyId = (int)$repository->getMetaValue($account, 'currency_id');
|
||||||
$transactions = $account->transactions()
|
$transactions = $account->transactions()
|
||||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||||
@@ -87,7 +88,7 @@ class Steam
|
|||||||
$sum = '0';
|
$sum = '0';
|
||||||
/** @var array $transaction */
|
/** @var array $transaction */
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
$value = (string) ($transaction[$key] ?? '0');
|
$value = (string)($transaction[$key] ?? '0');
|
||||||
$value = '' === $value ? '0' : $value;
|
$value = '' === $value ? '0' : $value;
|
||||||
$sum = bcadd($sum, $value);
|
$sum = bcadd($sum, $value);
|
||||||
}
|
}
|
||||||
@@ -95,6 +96,26 @@ class Steam
|
|||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://stackoverflow.com/questions/1642614/how-to-ceil-floor-and-round-bcmath-numbers
|
||||||
|
*
|
||||||
|
* @param string $number
|
||||||
|
* @param int $precision
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function bcround(string $number, int $precision = 0): string
|
||||||
|
{
|
||||||
|
if (str_contains($number, '.')) {
|
||||||
|
if ($number[0] !== '-') {
|
||||||
|
return bcadd($number, '0.'.str_repeat('0', $precision).'5', $precision);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bcsub($number, '0.'.str_repeat('0', $precision).'5', $precision);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the balance for the given account during the whole range, using this format:.
|
* Gets the balance for the given account during the whole range, using this format:.
|
||||||
*
|
*
|
||||||
@@ -134,7 +155,7 @@ class Steam
|
|||||||
$repository->setUser($account->user);
|
$repository->setUser($account->user);
|
||||||
$currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user);
|
$currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user);
|
||||||
}
|
}
|
||||||
$currencyId = (int) $currency->id;
|
$currencyId = (int)$currency->id;
|
||||||
|
|
||||||
$start->addDay();
|
$start->addDay();
|
||||||
|
|
||||||
@@ -162,14 +183,14 @@ class Steam
|
|||||||
/** @var Transaction $entry */
|
/** @var Transaction $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
// normal amount and foreign amount
|
// normal amount and foreign amount
|
||||||
$modified = null === $entry->modified ? '0' : (string) $entry->modified;
|
$modified = null === $entry->modified ? '0' : (string)$entry->modified;
|
||||||
$foreignModified = null === $entry->modified_foreign ? '0' : (string) $entry->modified_foreign;
|
$foreignModified = null === $entry->modified_foreign ? '0' : (string)$entry->modified_foreign;
|
||||||
$amount = '0';
|
$amount = '0';
|
||||||
if ($currencyId === (int) $entry->transaction_currency_id || 0 === $currencyId) {
|
if ($currencyId === (int)$entry->transaction_currency_id || 0 === $currencyId) {
|
||||||
// use normal amount:
|
// use normal amount:
|
||||||
$amount = $modified;
|
$amount = $modified;
|
||||||
}
|
}
|
||||||
if ($currencyId === (int) $entry->foreign_currency_id) {
|
if ($currencyId === (int)$entry->foreign_currency_id) {
|
||||||
// use foreign amount:
|
// use foreign amount:
|
||||||
$amount = $foreignModified;
|
$amount = $foreignModified;
|
||||||
}
|
}
|
||||||
@@ -228,7 +249,7 @@ class Steam
|
|||||||
->get(['transactions.foreign_amount'])->toArray();
|
->get(['transactions.foreign_amount'])->toArray();
|
||||||
$foreignBalance = $this->sumTransactions($transactions, 'foreign_amount');
|
$foreignBalance = $this->sumTransactions($transactions, 'foreign_amount');
|
||||||
$balance = bcadd($nativeBalance, $foreignBalance);
|
$balance = bcadd($nativeBalance, $foreignBalance);
|
||||||
$virtual = null === $account->virtual_balance ? '0' : (string) $account->virtual_balance;
|
$virtual = null === $account->virtual_balance ? '0' : (string)$account->virtual_balance;
|
||||||
$balance = bcadd($balance, $virtual);
|
$balance = bcadd($balance, $virtual);
|
||||||
|
|
||||||
$cache->store($balance);
|
$cache->store($balance);
|
||||||
@@ -326,7 +347,7 @@ class Steam
|
|||||||
$return = [];
|
$return = [];
|
||||||
/** @var stdClass $entry */
|
/** @var stdClass $entry */
|
||||||
foreach ($balances as $entry) {
|
foreach ($balances as $entry) {
|
||||||
$return[(int) $entry->transaction_currency_id] = (string) $entry->sum_for_currency;
|
$return[(int)$entry->transaction_currency_id] = (string)$entry->sum_for_currency;
|
||||||
}
|
}
|
||||||
$cache->store($return);
|
$cache->store($return);
|
||||||
|
|
||||||
@@ -409,7 +430,7 @@ class Steam
|
|||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$date = new Carbon($entry->max_date, config('app.timezone'));
|
$date = new Carbon($entry->max_date, config('app.timezone'));
|
||||||
$date->setTimezone(config('app.timezone'));
|
$date->setTimezone(config('app.timezone'));
|
||||||
$list[(int) $entry->account_id] = $date;
|
$list[(int)$entry->account_id] = $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
@@ -554,11 +575,11 @@ class Steam
|
|||||||
$post = strlen(substr($number, strpos($number, '.') + 1));
|
$post = strlen(substr($number, strpos($number, '.') + 1));
|
||||||
$mantis = substr($value, strpos($value, 'E') + 1);
|
$mantis = substr($value, strpos($value, 'E') + 1);
|
||||||
if ($mantis < 0) {
|
if ($mantis < 0) {
|
||||||
$post += abs((int) $mantis);
|
$post += abs((int)$mantis);
|
||||||
}
|
}
|
||||||
return number_format((float) $value, $post, '.', '');
|
return number_format((float)$value, $post, '.', '');
|
||||||
}
|
}
|
||||||
return number_format((float) $value, 0, '.', '');
|
return number_format((float)$value, 0, '.', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -588,24 +609,24 @@ class Steam
|
|||||||
// has a K in it, remove the K and multiply by 1024.
|
// has a K in it, remove the K and multiply by 1024.
|
||||||
$bytes = bcmul(rtrim($string, 'k'), '1024');
|
$bytes = bcmul(rtrim($string, 'k'), '1024');
|
||||||
|
|
||||||
return (int) $bytes;
|
return (int)$bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false !== stripos($string, 'm')) {
|
if (false !== stripos($string, 'm')) {
|
||||||
// has a M in it, remove the M and multiply by 1048576.
|
// has a M in it, remove the M and multiply by 1048576.
|
||||||
$bytes = bcmul(rtrim($string, 'm'), '1048576');
|
$bytes = bcmul(rtrim($string, 'm'), '1048576');
|
||||||
|
|
||||||
return (int) $bytes;
|
return (int)$bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false !== stripos($string, 'g')) {
|
if (false !== stripos($string, 'g')) {
|
||||||
// has a G in it, remove the G and multiply by (1024)^3.
|
// has a G in it, remove the G and multiply by (1024)^3.
|
||||||
$bytes = bcmul(rtrim($string, 'g'), '1073741824');
|
$bytes = bcmul(rtrim($string, 'g'), '1073741824');
|
||||||
|
|
||||||
return (int) $bytes;
|
return (int)$bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $string;
|
return (int)$string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user