mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -55,15 +55,15 @@ class Amount
|
||||
*/
|
||||
public function formatFlat(string $symbol, int $decimalPlaces, string $amount, bool $coloured = null): string
|
||||
{
|
||||
$locale = app('steam')->getLocale();
|
||||
$rounded = app('steam')->bcround($amount, $decimalPlaces);
|
||||
$locale = app('steam')->getLocale();
|
||||
$rounded = app('steam')->bcround($amount, $decimalPlaces);
|
||||
$coloured ??= true;
|
||||
|
||||
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
||||
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
||||
$fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
||||
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
||||
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
||||
$result = (string) $fmt->format((float) $rounded); // intentional float
|
||||
$result = (string) $fmt->format((float) $rounded); // intentional float
|
||||
|
||||
if (true === $coloured) {
|
||||
if (1 === bccomp($rounded, '0')) {
|
||||
@@ -102,7 +102,7 @@ class Amount
|
||||
|
||||
public function getDefaultCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('getDefaultCurrencyByGroup');
|
||||
$cache->addProperty($userGroup->id);
|
||||
if ($cache->has()) {
|
||||
@@ -166,7 +166,7 @@ class Amount
|
||||
public static function getAmountJsConfig(bool $sepBySpace, int $signPosn, string $sign, bool $csPrecedes): string
|
||||
{
|
||||
// negative first:
|
||||
$space = ' ';
|
||||
$space = ' ';
|
||||
|
||||
// require space between symbol and amount?
|
||||
if (false === $sepBySpace) {
|
||||
@@ -175,11 +175,11 @@ class Amount
|
||||
|
||||
// there are five possible positions for the "+" or "-" sign (if it is even used)
|
||||
// pos_a and pos_e could be the ( and ) symbol.
|
||||
$posA = ''; // before everything
|
||||
$posB = ''; // before currency symbol
|
||||
$posC = ''; // after currency symbol
|
||||
$posD = ''; // before amount
|
||||
$posE = ''; // after everything
|
||||
$posA = ''; // before everything
|
||||
$posB = ''; // before currency symbol
|
||||
$posC = ''; // after currency symbol
|
||||
$posD = ''; // before amount
|
||||
$posE = ''; // after everything
|
||||
|
||||
// format would be (currency before amount)
|
||||
// AB%sC_D%vE
|
||||
@@ -239,20 +239,20 @@ class Amount
|
||||
private function getLocaleInfo(): array
|
||||
{
|
||||
// get config from preference, not from translation:
|
||||
$locale = app('steam')->getLocale();
|
||||
$array = app('steam')->getLocaleArray($locale);
|
||||
$locale = app('steam')->getLocale();
|
||||
$array = app('steam')->getLocaleArray($locale);
|
||||
|
||||
setlocale(LC_MONETARY, $array);
|
||||
$info = localeconv();
|
||||
$info = localeconv();
|
||||
|
||||
// correct variables
|
||||
$info['n_cs_precedes'] = $this->getLocaleField($info, 'n_cs_precedes');
|
||||
$info['p_cs_precedes'] = $this->getLocaleField($info, 'p_cs_precedes');
|
||||
$info['n_cs_precedes'] = $this->getLocaleField($info, 'n_cs_precedes');
|
||||
$info['p_cs_precedes'] = $this->getLocaleField($info, 'p_cs_precedes');
|
||||
|
||||
$info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');
|
||||
$info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');
|
||||
$info['n_sep_by_space'] = $this->getLocaleField($info, 'n_sep_by_space');
|
||||
$info['p_sep_by_space'] = $this->getLocaleField($info, 'p_sep_by_space');
|
||||
|
||||
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
||||
$fmt = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
|
||||
|
||||
$info['mon_decimal_point'] = $fmt->getSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL);
|
||||
$info['mon_thousands_sep'] = $fmt->getSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL);
|
||||
|
||||
@@ -47,7 +47,7 @@ class RemoteUserGuard implements Guard
|
||||
public function __construct(UserProvider $provider, Application $app)
|
||||
{
|
||||
/** @var null|Request $request */
|
||||
$request = $app->get('request');
|
||||
$request = $app->get('request');
|
||||
app('log')->debug(sprintf('Created RemoteUserGuard for %s "%s"', $request?->getMethod(), $request?->getRequestUri()));
|
||||
$this->application = $app;
|
||||
$this->provider = $provider;
|
||||
@@ -63,8 +63,8 @@ class RemoteUserGuard implements Guard
|
||||
return;
|
||||
}
|
||||
// Get the user identifier from $_SERVER or apache filtered headers
|
||||
$header = config('auth.guard_header', 'REMOTE_USER');
|
||||
$userID = request()->server($header) ?? null;
|
||||
$header = config('auth.guard_header', 'REMOTE_USER');
|
||||
$userID = request()->server($header) ?? null;
|
||||
|
||||
if (function_exists('apache_request_headers')) {
|
||||
app('log')->debug('Use apache_request_headers to find user ID.');
|
||||
@@ -83,7 +83,7 @@ class RemoteUserGuard implements Guard
|
||||
$retrievedUser = $this->provider->retrieveById($userID);
|
||||
|
||||
// store email address if present in header and not already set.
|
||||
$header = config('auth.guard_email');
|
||||
$header = config('auth.guard_email');
|
||||
|
||||
if (null !== $header) {
|
||||
$emailAddress = (string)(request()->server($header) ?? apache_request_headers()[$header] ?? null);
|
||||
@@ -99,7 +99,7 @@ class RemoteUserGuard implements Guard
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Result of getting user from provider: %s', $retrievedUser->email));
|
||||
$this->user = $retrievedUser;
|
||||
$this->user = $retrievedUser;
|
||||
}
|
||||
|
||||
public function guest(): bool
|
||||
|
||||
@@ -50,8 +50,8 @@ class AccountList implements BinderInterface
|
||||
;
|
||||
}
|
||||
if ('allAssetAccounts' !== $value) {
|
||||
$incoming = array_map('\intval', explode(',', $value));
|
||||
$list = array_merge(array_unique($incoming), [0]);
|
||||
$incoming = array_map('\intval', explode(',', $value));
|
||||
$list = array_merge(array_unique($incoming), [0]);
|
||||
|
||||
/** @var Collection $collection */
|
||||
$collection = auth()->user()->accounts()
|
||||
|
||||
@@ -47,7 +47,7 @@ class BudgetList implements BinderInterface
|
||||
;
|
||||
}
|
||||
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
|
||||
if (0 === count($list)) { // @phpstan-ignore-line
|
||||
app('log')->warning('Budget list count is zero, return 404.');
|
||||
|
||||
@@ -46,7 +46,7 @@ class CategoryList implements BinderInterface
|
||||
;
|
||||
}
|
||||
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
if (0 === count($list)) { // @phpstan-ignore-line
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
@@ -43,16 +43,16 @@ class Date implements BinderInterface
|
||||
/** @var FiscalHelperInterface $fiscalHelper */
|
||||
$fiscalHelper = app(FiscalHelperInterface::class);
|
||||
|
||||
$magicWords = [
|
||||
'currentMonthStart' => today(config('app.timezone'))->startOfMonth(),
|
||||
'currentMonthEnd' => today(config('app.timezone'))->endOfMonth(),
|
||||
'currentYearStart' => today(config('app.timezone'))->startOfYear(),
|
||||
'currentYearEnd' => today(config('app.timezone'))->endOfYear(),
|
||||
$magicWords = [
|
||||
'currentMonthStart' => today(config('app.timezone'))->startOfMonth(),
|
||||
'currentMonthEnd' => today(config('app.timezone'))->endOfMonth(),
|
||||
'currentYearStart' => today(config('app.timezone'))->startOfYear(),
|
||||
'currentYearEnd' => today(config('app.timezone'))->endOfYear(),
|
||||
|
||||
'previousMonthStart' => today(config('app.timezone'))->startOfMonth()->subDay()->startOfMonth(),
|
||||
'previousMonthEnd' => today(config('app.timezone'))->startOfMonth()->subDay()->endOfMonth(),
|
||||
'previousYearStart' => today(config('app.timezone'))->startOfYear()->subDay()->startOfYear(),
|
||||
'previousYearEnd' => today(config('app.timezone'))->startOfYear()->subDay()->endOfYear(),
|
||||
'previousMonthStart' => today(config('app.timezone'))->startOfMonth()->subDay()->startOfMonth(),
|
||||
'previousMonthEnd' => today(config('app.timezone'))->startOfMonth()->subDay()->endOfMonth(),
|
||||
'previousYearStart' => today(config('app.timezone'))->startOfYear()->subDay()->startOfYear(),
|
||||
'previousYearEnd' => today(config('app.timezone'))->startOfYear()->subDay()->endOfYear(),
|
||||
|
||||
'currentFiscalYearStart' => $fiscalHelper->startOfFiscalYear(today(config('app.timezone'))),
|
||||
'currentFiscalYearEnd' => $fiscalHelper->endOfFiscalYear(today(config('app.timezone'))),
|
||||
|
||||
@@ -39,7 +39,7 @@ class JournalList implements BinderInterface
|
||||
public static function routeBinder(string $value, Route $route): array
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$list = self::parseList($value);
|
||||
$list = self::parseList($value);
|
||||
|
||||
// get the journals by using the collector.
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
@@ -47,7 +47,7 @@ class JournalList implements BinderInterface
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER, TransactionType::RECONCILIATION]);
|
||||
$collector->withCategoryInformation()->withBudgetInformation()->withTagInformation()->withAccountInformation();
|
||||
$collector->setJournalIds($list);
|
||||
$result = $collector->getExtractedJournals();
|
||||
$result = $collector->getExtractedJournals();
|
||||
if (0 === count($result)) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class TagList implements BinderInterface
|
||||
->get()
|
||||
;
|
||||
}
|
||||
$list = array_unique(array_map('\strtolower', explode(',', $value)));
|
||||
$list = array_unique(array_map('\strtolower', explode(',', $value)));
|
||||
app('log')->debug('List of tags is', $list);
|
||||
|
||||
if (0 === count($list)) { // @phpstan-ignore-line
|
||||
@@ -59,7 +59,7 @@ class TagList implements BinderInterface
|
||||
/** @var TagRepositoryInterface $repository */
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$repository->setUser(auth()->user());
|
||||
$allTags = $repository->get();
|
||||
$allTags = $repository->get();
|
||||
|
||||
$collection = $allTags->filter(
|
||||
static function (Tag $tag) use ($list) {
|
||||
|
||||
@@ -40,7 +40,7 @@ class TagOrId implements BinderInterface
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$repository->setUser(auth()->user());
|
||||
|
||||
$result = $repository->findByTag($value);
|
||||
$result = $repository->findByTag($value);
|
||||
if (null === $result) {
|
||||
$result = $repository->find((int)$value);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class CacheProperties
|
||||
|
||||
private function hash(): void
|
||||
{
|
||||
$content = '';
|
||||
$content = '';
|
||||
foreach ($this->properties as $property) {
|
||||
try {
|
||||
$content .= json_encode($property, JSON_THROW_ON_ERROR);
|
||||
|
||||
@@ -32,7 +32,7 @@ use FireflyIII\Exceptions\IntervalException;
|
||||
*/
|
||||
class Calculator
|
||||
{
|
||||
public const int DEFAULT_INTERVAL = 1;
|
||||
public const int DEFAULT_INTERVAL = 1;
|
||||
private static ?\SplObjectStorage $intervalMap = null;
|
||||
private static array $intervals = [];
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ class FrontpageChartGenerator
|
||||
*/
|
||||
private function processRow(array $data, Budget $budget, BudgetLimit $limit, array $entry): array
|
||||
{
|
||||
$title = sprintf('%s (%s)', $budget->name, $entry['currency_name']);
|
||||
$title = sprintf('%s (%s)', $budget->name, $entry['currency_name']);
|
||||
if ($limit->start_date->startOfDay()->ne($this->start->startOfDay()) || $limit->end_date->startOfDay()->ne($this->end->startOfDay())) {
|
||||
$title = sprintf(
|
||||
'%s (%s) (%s - %s)',
|
||||
@@ -188,7 +188,7 @@ class FrontpageChartGenerator
|
||||
$limit->end_date->isoFormat($this->monthAndDayFormat)
|
||||
);
|
||||
}
|
||||
$sumSpent = bcmul($entry['sum'], '-1'); // spent
|
||||
$sumSpent = bcmul($entry['sum'], '-1'); // spent
|
||||
|
||||
$data[0]['entries'][$title] = 1 === bccomp($sumSpent, $limit->amount) ? $limit->amount : $sumSpent; // spent
|
||||
$data[1]['entries'][$title] = 1 === bccomp($limit->amount, $sumSpent) ? bcadd($entry['sum'], $limit->amount) : '0'; // left to spent
|
||||
|
||||
@@ -65,13 +65,13 @@ class FrontpageChartGenerator
|
||||
|
||||
public function generate(): array
|
||||
{
|
||||
$categories = $this->repository->getCategories();
|
||||
$accounts = $this->accountRepos->getAccountsByType(
|
||||
$categories = $this->repository->getCategories();
|
||||
$accounts = $this->accountRepos->getAccountsByType(
|
||||
[AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::ASSET, AccountType::DEFAULT]
|
||||
);
|
||||
|
||||
// get expenses + income per category:
|
||||
$collection = [];
|
||||
$collection = [];
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
@@ -82,10 +82,10 @@ class FrontpageChartGenerator
|
||||
// collect for no-category:
|
||||
$collection[] = $this->collectNoCatExpenses($accounts);
|
||||
|
||||
$tempData = array_merge(...$collection);
|
||||
$tempData = array_merge(...$collection);
|
||||
|
||||
// sort temp array by amount.
|
||||
$amounts = array_column($tempData, 'sum_float');
|
||||
$amounts = array_column($tempData, 'sum_float');
|
||||
array_multisort($amounts, SORT_ASC, $tempData);
|
||||
|
||||
$currencyData = $this->createCurrencyGroups($tempData);
|
||||
|
||||
@@ -37,22 +37,22 @@ class WholePeriodChartGenerator
|
||||
{
|
||||
public function generate(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$collection = new Collection([$category]);
|
||||
$collection = new Collection([$category]);
|
||||
|
||||
/** @var OperationsRepositoryInterface $opsRepository */
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
|
||||
$types = [AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
||||
$accounts = $accountRepository->getAccountsByType($types);
|
||||
$step = $this->calculateStep($start, $end);
|
||||
$chartData = [];
|
||||
$spent = [];
|
||||
$earned = [];
|
||||
$types = [AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
||||
$accounts = $accountRepository->getAccountsByType($types);
|
||||
$step = $this->calculateStep($start, $end);
|
||||
$chartData = [];
|
||||
$spent = [];
|
||||
$earned = [];
|
||||
|
||||
$current = clone $start;
|
||||
$current = clone $start;
|
||||
|
||||
while ($current <= $end) {
|
||||
$key = $current->format('Y-m-d');
|
||||
@@ -62,14 +62,14 @@ class WholePeriodChartGenerator
|
||||
$current = app('navigation')->addPeriod($current, $step, 0);
|
||||
}
|
||||
|
||||
$currencies = $this->extractCurrencies($spent) + $this->extractCurrencies($earned);
|
||||
$currencies = $this->extractCurrencies($spent) + $this->extractCurrencies($earned);
|
||||
|
||||
// generate chart data (for each currency)
|
||||
/** @var array $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
$code = $currency['currency_code'];
|
||||
$name = $currency['currency_name'];
|
||||
$chartData[sprintf('spent-in-%s', $code)] = [
|
||||
$code = $currency['currency_code'];
|
||||
$name = $currency['currency_name'];
|
||||
$chartData[sprintf('spent-in-%s', $code)] = [
|
||||
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $name]),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
@@ -84,11 +84,11 @@ class WholePeriodChartGenerator
|
||||
];
|
||||
}
|
||||
|
||||
$current = clone $start;
|
||||
$current = clone $start;
|
||||
|
||||
while ($current <= $end) {
|
||||
$key = $current->format('Y-m-d');
|
||||
$label = app('navigation')->periodShow($current, $step);
|
||||
$key = $current->format('Y-m-d');
|
||||
$label = app('navigation')->periodShow($current, $step);
|
||||
|
||||
/** @var array $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
|
||||
@@ -55,7 +55,7 @@ class ChartColour
|
||||
public static function getColour(int $index): string
|
||||
{
|
||||
$index %= count(self::$colours);
|
||||
$row = self::$colours[$index];
|
||||
$row = self::$colours[$index];
|
||||
|
||||
return sprintf('rgba(%d, %d, %d, 0.7)', $row[0], $row[1], $row[2]);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class AutoBudgetCronjob extends AbstractCronjob
|
||||
app('log')->info(sprintf('Will now fire auto budget cron job task for date "%s".', $this->date->format('Y-m-d')));
|
||||
|
||||
/** @var CreateAutoBudgetLimits $job */
|
||||
$job = app(CreateAutoBudgetLimits::class, [$this->date]);
|
||||
$job = app(CreateAutoBudgetLimits::class, [$this->date]);
|
||||
$job->setDate($this->date);
|
||||
$job->handle();
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class BillWarningCronjob extends AbstractCronjob
|
||||
app('log')->info(sprintf('Will now fire bill warning job task for date "%s".', $this->date->format('Y-m-d H:i:s')));
|
||||
|
||||
/** @var WarnAboutBills $job */
|
||||
$job = app(WarnAboutBills::class);
|
||||
$job = app(WarnAboutBills::class);
|
||||
$job->setDate($this->date);
|
||||
$job->setForce($this->force);
|
||||
$job->handle();
|
||||
|
||||
@@ -69,7 +69,7 @@ class ExchangeRatesCronjob extends AbstractCronjob
|
||||
app('log')->info(sprintf('Will now fire exchange rates cron job task for date "%s".', $this->date->format('Y-m-d')));
|
||||
|
||||
/** @var DownloadExchangeRates $job */
|
||||
$job = app(DownloadExchangeRates::class);
|
||||
$job = app(DownloadExchangeRates::class);
|
||||
$job->setDate($this->date);
|
||||
$job->handle();
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class RecurringCronjob extends AbstractCronjob
|
||||
app('log')->info(sprintf('Will now fire recurring cron job task for date "%s".', $this->date->format('Y-m-d H:i:s')));
|
||||
|
||||
/** @var CreateRecurringTransactions $job */
|
||||
$job = app(CreateRecurringTransactions::class);
|
||||
$job = app(CreateRecurringTransactions::class);
|
||||
$job->setDate($this->date);
|
||||
$job->setForce($this->force);
|
||||
$job->handle();
|
||||
|
||||
@@ -42,7 +42,7 @@ class ExpandedForm
|
||||
*/
|
||||
public function amountNoCurrency(string $name, $value = null, array $options = null): string
|
||||
{
|
||||
$options ??= [];
|
||||
$options ??= [];
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
@@ -73,8 +73,8 @@ class ExpandedForm
|
||||
*/
|
||||
public function checkbox(string $name, int $value = null, $checked = null, array $options = null): string
|
||||
{
|
||||
$options ??= [];
|
||||
$value ??= 1;
|
||||
$options ??= [];
|
||||
$value ??= 1;
|
||||
$options['checked'] = true === $checked;
|
||||
|
||||
if (app('session')->has('preFilled')) {
|
||||
@@ -82,10 +82,10 @@ class ExpandedForm
|
||||
$options['checked'] = $preFilled[$name] ?? $options['checked'];
|
||||
}
|
||||
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
|
||||
unset($options['placeholder'], $options['autocomplete'], $options['class']);
|
||||
|
||||
@@ -156,10 +156,10 @@ class ExpandedForm
|
||||
public function integer(string $name, $value = null, array $options = null): string
|
||||
{
|
||||
$options ??= [];
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$value = $this->fillFieldValue($name, $value);
|
||||
$options['step'] ??= '1';
|
||||
|
||||
try {
|
||||
@@ -208,9 +208,9 @@ class ExpandedForm
|
||||
/** @var \Eloquent $entry */
|
||||
foreach ($set as $entry) {
|
||||
// All Eloquent models have an ID
|
||||
$entryId = $entry->id; // @phpstan-ignore-line
|
||||
$current = $entry->toArray();
|
||||
$title = null;
|
||||
$entryId = $entry->id; // @phpstan-ignore-line
|
||||
$current = $entry->toArray();
|
||||
$title = null;
|
||||
foreach ($fields as $field) {
|
||||
if (array_key_exists($field, $current) && null === $title) {
|
||||
$title = $current[$field];
|
||||
|
||||
@@ -82,8 +82,8 @@ class ExportDataGenerator
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->accounts = new Collection();
|
||||
$this->start = today(config('app.timezone'));
|
||||
$this->accounts = new Collection();
|
||||
$this->start = today(config('app.timezone'));
|
||||
$this->start->subYear();
|
||||
$this->end = today(config('app.timezone'));
|
||||
$this->exportTransactions = false;
|
||||
@@ -222,7 +222,7 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function exportAccounts(): string
|
||||
{
|
||||
$header = [
|
||||
$header = [
|
||||
'user_id',
|
||||
'account_id',
|
||||
'created_at',
|
||||
@@ -243,7 +243,7 @@ class ExportDataGenerator
|
||||
];
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$allAccounts = $repository->getAccountsByType([]);
|
||||
$records = [];
|
||||
@@ -273,7 +273,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -306,8 +306,8 @@ class ExportDataGenerator
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$bills = $repository->getBills();
|
||||
$header = [
|
||||
$bills = $repository->getBills();
|
||||
$header = [
|
||||
'user_id',
|
||||
'bill_id',
|
||||
'created_at',
|
||||
@@ -321,7 +321,7 @@ class ExportDataGenerator
|
||||
'skip',
|
||||
'active',
|
||||
];
|
||||
$records = [];
|
||||
$records = [];
|
||||
|
||||
/** @var Bill $bill */
|
||||
foreach ($bills as $bill) {
|
||||
@@ -342,7 +342,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -372,7 +372,7 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function exportBudgets(): string
|
||||
{
|
||||
$header = [
|
||||
$header = [
|
||||
'user_id',
|
||||
'budget_id',
|
||||
'name',
|
||||
@@ -386,9 +386,9 @@ class ExportDataGenerator
|
||||
|
||||
$budgetRepos = app(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->setUser($this->user);
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$budgets = $budgetRepos->getBudgets();
|
||||
$records = [];
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$budgets = $budgetRepos->getBudgets();
|
||||
$records = [];
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
@@ -411,7 +411,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -441,10 +441,10 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function exportCategories(): string
|
||||
{
|
||||
$header = ['user_id', 'category_id', 'created_at', 'updated_at', 'name'];
|
||||
$header = ['user_id', 'category_id', 'created_at', 'updated_at', 'name'];
|
||||
|
||||
/** @var CategoryRepositoryInterface $catRepos */
|
||||
$catRepos = app(CategoryRepositoryInterface::class);
|
||||
$catRepos = app(CategoryRepositoryInterface::class);
|
||||
$catRepos->setUser($this->user);
|
||||
|
||||
$records = [];
|
||||
@@ -462,7 +462,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -493,14 +493,14 @@ class ExportDataGenerator
|
||||
private function exportPiggies(): string
|
||||
{
|
||||
/** @var PiggyBankRepositoryInterface $piggyRepos */
|
||||
$piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||
$piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||
$piggyRepos->setUser($this->user);
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepos */
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$accountRepos->setUser($this->user);
|
||||
|
||||
$header = [
|
||||
$header = [
|
||||
'user_id',
|
||||
'piggy_bank_id',
|
||||
'created_at',
|
||||
@@ -516,8 +516,8 @@ class ExportDataGenerator
|
||||
'order',
|
||||
'active',
|
||||
];
|
||||
$records = [];
|
||||
$piggies = $piggyRepos->getPiggyBanks();
|
||||
$records = [];
|
||||
$piggies = $piggyRepos->getPiggyBanks();
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($piggies as $piggy) {
|
||||
@@ -542,7 +542,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -575,7 +575,7 @@ class ExportDataGenerator
|
||||
/** @var RecurringRepositoryInterface $recurringRepos */
|
||||
$recurringRepos = app(RecurringRepositoryInterface::class);
|
||||
$recurringRepos->setUser($this->user);
|
||||
$header = [
|
||||
$header = [
|
||||
// recurrence:
|
||||
'user_id', 'recurrence_id', 'row_contains', 'created_at', 'updated_at', 'type', 'title', 'description', 'first_date', 'repeat_until', 'latest_date', 'repetitions', 'apply_rules', 'active',
|
||||
|
||||
@@ -584,8 +584,8 @@ class ExportDataGenerator
|
||||
// transactions + meta:
|
||||
'currency_code', 'foreign_currency_code', 'source_name', 'source_type', 'destination_name', 'destination_type', 'amount', 'foreign_amount', 'category', 'budget', 'piggy_bank', 'tags',
|
||||
];
|
||||
$records = [];
|
||||
$recurrences = $recurringRepos->getAll();
|
||||
$records = [];
|
||||
$recurrences = $recurringRepos->getAll();
|
||||
|
||||
/** @var Recurrence $recurrence */
|
||||
foreach ($recurrences as $recurrence) {
|
||||
@@ -618,7 +618,7 @@ class ExportDataGenerator
|
||||
$piggyBankId = $recurringRepos->getPiggyBank($transaction);
|
||||
$tags = $recurringRepos->getTags($transaction);
|
||||
|
||||
$records[] = [
|
||||
$records[] = [
|
||||
// recurrence
|
||||
$this->user->id,
|
||||
$recurrence->id,
|
||||
@@ -634,7 +634,7 @@ class ExportDataGenerator
|
||||
}
|
||||
}
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -667,8 +667,8 @@ class ExportDataGenerator
|
||||
$header = ['user_id', 'rule_id', 'row_contains', 'created_at', 'updated_at', 'group_id', 'title', 'description', 'order', 'active', 'stop_processing', 'strict', 'trigger_type', 'trigger_value', 'trigger_order', 'trigger_active', 'trigger_stop_processing', 'action_type', 'action_value', 'action_order', 'action_active', 'action_stop_processing'];
|
||||
$ruleRepos = app(RuleRepositoryInterface::class);
|
||||
$ruleRepos->setUser($this->user);
|
||||
$rules = $ruleRepos->getAll();
|
||||
$records = [];
|
||||
$rules = $ruleRepos->getAll();
|
||||
$records = [];
|
||||
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
@@ -702,7 +702,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -732,12 +732,12 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function exportTags(): string
|
||||
{
|
||||
$header = ['user_id', 'tag_id', 'created_at', 'updated_at', 'tag', 'date', 'description', 'latitude', 'longitude', 'zoom_level'];
|
||||
$header = ['user_id', 'tag_id', 'created_at', 'updated_at', 'tag', 'date', 'description', 'latitude', 'longitude', 'zoom_level'];
|
||||
|
||||
$tagRepos = app(TagRepositoryInterface::class);
|
||||
$tagRepos->setUser($this->user);
|
||||
$tags = $tagRepos->get();
|
||||
$records = [];
|
||||
$tags = $tagRepos->get();
|
||||
$records = [];
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
@@ -756,7 +756,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -787,12 +787,12 @@ class ExportDataGenerator
|
||||
private function exportTransactions(): string
|
||||
{
|
||||
// TODO better place for keys?
|
||||
$header = ['user_id', 'group_id', 'journal_id', 'created_at', 'updated_at', 'group_title', 'type', 'amount', 'foreign_amount', 'currency_code', 'foreign_currency_code', 'description', 'date', 'source_name', 'source_iban', 'source_type', 'destination_name', 'destination_iban', 'destination_type', 'reconciled', 'category', 'budget', 'bill', 'tags', 'notes'];
|
||||
$header = ['user_id', 'group_id', 'journal_id', 'created_at', 'updated_at', 'group_title', 'type', 'amount', 'foreign_amount', 'currency_code', 'foreign_currency_code', 'description', 'date', 'source_name', 'source_iban', 'source_type', 'destination_name', 'destination_iban', 'destination_type', 'reconciled', 'category', 'budget', 'bill', 'tags', 'notes'];
|
||||
|
||||
$metaFields = config('firefly.journal_meta_fields');
|
||||
$header = array_merge($header, $metaFields);
|
||||
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($this->start, $this->end)->withAccountInformation()->withCategoryInformation()->withBillInformation()
|
||||
->withBudgetInformation()->withTagInformation()->withNotes()
|
||||
@@ -801,13 +801,13 @@ class ExportDataGenerator
|
||||
$collector->setAccounts($this->accounts);
|
||||
}
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// get repository for meta data:
|
||||
$repository = app(TransactionGroupRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
|
||||
$records = [];
|
||||
$records = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
@@ -832,7 +832,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
|
||||
@@ -60,9 +60,9 @@ class AccountForm
|
||||
*/
|
||||
public function activeWithdrawalDestinations(string $name, mixed $value = null, array $options = null): string
|
||||
{
|
||||
$types = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN, AccountType::EXPENSE];
|
||||
$repository = $this->getAccountRepository();
|
||||
$grouped = $this->getAccountsGrouped($types, $repository);
|
||||
$types = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN, AccountType::EXPENSE];
|
||||
$repository = $this->getAccountRepository();
|
||||
$grouped = $this->getAccountsGrouped($types, $repository);
|
||||
|
||||
$cash = $repository->getCashAccount();
|
||||
$key = (string)trans('firefly.cash_account_type');
|
||||
@@ -78,15 +78,15 @@ class AccountForm
|
||||
*/
|
||||
public function assetAccountCheckList(string $name, array $options = null): string
|
||||
{
|
||||
$options ??= [];
|
||||
$options ??= [];
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$selected = request()->old($name) ?? [];
|
||||
|
||||
// get all asset accounts:
|
||||
$types = [AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::DEBT];
|
||||
$grouped = $this->getAccountsGrouped($types);
|
||||
$types = [AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::DEBT];
|
||||
$grouped = $this->getAccountsGrouped($types);
|
||||
|
||||
unset($options['class']);
|
||||
|
||||
@@ -139,7 +139,7 @@ class AccountForm
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$role = (string)$repository->getMetaValue($account, 'account_role');
|
||||
$role = (string)$repository->getMetaValue($account, 'account_role');
|
||||
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
||||
$role = sprintf('l_%s', $account->accountType->type);
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ class CurrencyForm
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
// get all currencies:
|
||||
$list = $currencyRepos->get();
|
||||
$array = [];
|
||||
$list = $currencyRepos->get();
|
||||
$array = [];
|
||||
|
||||
/** @var TransactionCurrency $currency */
|
||||
foreach ($list as $currency) {
|
||||
@@ -92,8 +92,8 @@ class CurrencyForm
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
// get all currencies:
|
||||
$list = $currencyRepos->get();
|
||||
$array = [
|
||||
$list = $currencyRepos->get();
|
||||
$array = [
|
||||
0 => (string)trans('firefly.no_currency'),
|
||||
];
|
||||
|
||||
@@ -118,15 +118,15 @@ class CurrencyForm
|
||||
$defaultCurrency = $options['currency'] ?? app('amount')->getDefaultCurrency();
|
||||
|
||||
/** @var Collection $currencies */
|
||||
$currencies = app('amount')->getCurrencies();
|
||||
$currencies = app('amount')->getCurrencies();
|
||||
unset($options['currency'], $options['placeholder']);
|
||||
// perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
|
||||
$preFilled = session('preFilled');
|
||||
$preFilled = session('preFilled');
|
||||
if (!is_array($preFilled)) {
|
||||
$preFilled = [];
|
||||
}
|
||||
$key = 'amount_currency_id_'.$name;
|
||||
$sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $defaultCurrency->id;
|
||||
$key = 'amount_currency_id_'.$name;
|
||||
$sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $defaultCurrency->id;
|
||||
|
||||
app('log')->debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
|
||||
|
||||
@@ -174,16 +174,16 @@ class CurrencyForm
|
||||
$defaultCurrency = $options['currency'] ?? app('amount')->getDefaultCurrency();
|
||||
|
||||
/** @var Collection $currencies */
|
||||
$currencies = app('amount')->getAllCurrencies();
|
||||
$currencies = app('amount')->getAllCurrencies();
|
||||
unset($options['currency'], $options['placeholder']);
|
||||
|
||||
// perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
|
||||
$preFilled = session('preFilled');
|
||||
$preFilled = session('preFilled');
|
||||
if (!is_array($preFilled)) {
|
||||
$preFilled = [];
|
||||
}
|
||||
$key = 'amount_currency_id_'.$name;
|
||||
$sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $defaultCurrency->id;
|
||||
$key = 'amount_currency_id_'.$name;
|
||||
$sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $defaultCurrency->id;
|
||||
|
||||
app('log')->debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ trait FormSupport
|
||||
*/
|
||||
public function select(string $name, array $list = null, $selected = null, array $options = null): string
|
||||
{
|
||||
$list ??= [];
|
||||
$list ??= [];
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
@@ -71,7 +71,7 @@ trait FormSupport
|
||||
*/
|
||||
protected function expandOptionArray(string $name, $label, array $options = null): array
|
||||
{
|
||||
$options ??= [];
|
||||
$options ??= [];
|
||||
$name = str_replace('[]', '', $name);
|
||||
$options['class'] = 'form-control';
|
||||
$options['id'] = 'ffInput_'.$name;
|
||||
|
||||
@@ -61,14 +61,14 @@ class PiggyBankForm
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($piggyBanks as $piggy) {
|
||||
$group = $piggy->objectGroups->first();
|
||||
$groupTitle = null;
|
||||
$groupOrder = 0;
|
||||
$group = $piggy->objectGroups->first();
|
||||
$groupTitle = null;
|
||||
$groupOrder = 0;
|
||||
if (null !== $group) {
|
||||
$groupTitle = $group->title;
|
||||
$groupOrder = $group->order;
|
||||
}
|
||||
$subList[$groupOrder] ??= [
|
||||
$subList[$groupOrder] ??= [
|
||||
'group' => [
|
||||
'title' => $groupTitle,
|
||||
],
|
||||
|
||||
@@ -40,8 +40,8 @@ class RuleForm
|
||||
$groupRepos = app(RuleGroupRepositoryInterface::class);
|
||||
|
||||
// get all currencies:
|
||||
$list = $groupRepos->get();
|
||||
$array = [];
|
||||
$list = $groupRepos->get();
|
||||
$array = [];
|
||||
|
||||
/** @var RuleGroup $group */
|
||||
foreach ($list as $group) {
|
||||
@@ -56,15 +56,15 @@ class RuleForm
|
||||
*/
|
||||
public function ruleGroupListWithEmpty(string $name, $value = null, array $options = null): string
|
||||
{
|
||||
$options ??= [];
|
||||
$options ??= [];
|
||||
$options['class'] = 'form-control';
|
||||
|
||||
/** @var RuleGroupRepositoryInterface $groupRepos */
|
||||
$groupRepos = app(RuleGroupRepositoryInterface::class);
|
||||
$groupRepos = app(RuleGroupRepositoryInterface::class);
|
||||
|
||||
// get all currencies:
|
||||
$list = $groupRepos->get();
|
||||
$array = [
|
||||
$list = $groupRepos->get();
|
||||
$array = [
|
||||
0 => (string)trans('firefly.none_in_select_list'),
|
||||
];
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class AccountBalanceGrouped
|
||||
/** @var array $currency */
|
||||
foreach ($this->data as $currency) {
|
||||
// income and expense array prepped:
|
||||
$income = [
|
||||
$income = [
|
||||
'label' => 'earned',
|
||||
'currency_id' => (string) $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -72,7 +72,7 @@ class AccountBalanceGrouped
|
||||
'entries' => [],
|
||||
'native_entries' => [],
|
||||
];
|
||||
$expense = [
|
||||
$expense = [
|
||||
'label' => 'spent',
|
||||
'currency_id' => (string) $currency['currency_id'],
|
||||
'currency_symbol' => $currency['currency_symbol'],
|
||||
@@ -91,22 +91,22 @@ class AccountBalanceGrouped
|
||||
// loop all possible periods between $start and $end, and add them to the correct dataset.
|
||||
$currentStart = clone $this->start;
|
||||
while ($currentStart <= $this->end) {
|
||||
$key = $currentStart->format($this->carbonFormat);
|
||||
$label = $currentStart->toAtomString();
|
||||
$key = $currentStart->format($this->carbonFormat);
|
||||
$label = $currentStart->toAtomString();
|
||||
// normal entries
|
||||
$income['entries'][$label] = app('steam')->bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
|
||||
$expense['entries'][$label] = app('steam')->bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
|
||||
$income['entries'][$label] = app('steam')->bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
|
||||
$expense['entries'][$label] = app('steam')->bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
|
||||
|
||||
// converted entries
|
||||
$income['native_entries'][$label] = app('steam')->bcround($currency[$key]['native_earned'] ?? '0', $currency['native_currency_decimal_places']);
|
||||
$expense['native_entries'][$label] = app('steam')->bcround($currency[$key]['native_spent'] ?? '0', $currency['native_currency_decimal_places']);
|
||||
|
||||
// next loop
|
||||
$currentStart = app('navigation')->addPeriod($currentStart, $this->preferredRange, 0);
|
||||
$currentStart = app('navigation')->addPeriod($currentStart, $this->preferredRange, 0);
|
||||
}
|
||||
|
||||
$chartData[] = $income;
|
||||
$chartData[] = $expense;
|
||||
$chartData[] = $income;
|
||||
$chartData[] = $expense;
|
||||
}
|
||||
|
||||
return $chartData;
|
||||
@@ -125,13 +125,13 @@ class AccountBalanceGrouped
|
||||
/** @var array $journal */
|
||||
foreach ($this->journals as $journal) {
|
||||
// format the date according to the period
|
||||
$period = $journal['date']->format($this->carbonFormat);
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currency = $this->currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
||||
$this->currencies[$currencyId] = $currency; // may just re-assign itself, don't mind.
|
||||
$period = $journal['date']->format($this->carbonFormat);
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currency = $this->currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
||||
$this->currencies[$currencyId] = $currency; // may just re-assign itself, don't mind.
|
||||
|
||||
// set the array with monetary info, if it does not exist.
|
||||
$this->data[$currencyId] ??= [
|
||||
$this->data[$currencyId] ??= [
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
@@ -153,8 +153,8 @@ class AccountBalanceGrouped
|
||||
'native_earned' => '0',
|
||||
];
|
||||
// is this journal's amount in- our outgoing?
|
||||
$key = 'spent';
|
||||
$amount = app('steam')->negative($journal['amount']);
|
||||
$key = 'spent';
|
||||
$amount = app('steam')->negative($journal['amount']);
|
||||
// deposit = incoming
|
||||
// transfer or reconcile or opening balance, and these accounts are the destination.
|
||||
if (
|
||||
@@ -180,7 +180,7 @@ class AccountBalanceGrouped
|
||||
app('log')->error($e->getMessage());
|
||||
$rate = '1';
|
||||
}
|
||||
$amountConverted = bcmul($amount, $rate);
|
||||
$amountConverted = bcmul($amount, $rate);
|
||||
|
||||
// perhaps transaction already has the foreign amount in the native currency.
|
||||
if ((int) $journal['foreign_currency_id'] === $this->default->id) {
|
||||
@@ -189,7 +189,7 @@ class AccountBalanceGrouped
|
||||
}
|
||||
|
||||
// add normal entry
|
||||
$this->data[$currencyId][$period][$key] = bcadd($this->data[$currencyId][$period][$key], $amount);
|
||||
$this->data[$currencyId][$period][$key] = bcadd($this->data[$currencyId][$period][$key], $amount);
|
||||
|
||||
// add converted entry
|
||||
$convertedKey = sprintf('native_%s', $key);
|
||||
|
||||
@@ -45,7 +45,7 @@ trait ConvertsExchangeRates
|
||||
|
||||
// if not enabled, return the same array but without conversion:
|
||||
return $set;
|
||||
$this->enabled = false;
|
||||
$this->enabled = false;
|
||||
if (false === $this->enabled) {
|
||||
$set['converted'] = false;
|
||||
|
||||
@@ -55,8 +55,8 @@ trait ConvertsExchangeRates
|
||||
$set['converted'] = true;
|
||||
|
||||
/** @var TransactionCurrency $native */
|
||||
$native = app('amount')->getDefaultCurrency();
|
||||
$currency = $this->getCurrency((int)$set['currency_id']);
|
||||
$native = app('amount')->getDefaultCurrency();
|
||||
$currency = $this->getCurrency((int)$set['currency_id']);
|
||||
if ($native->id === $currency->id) {
|
||||
$set['native_currency_id'] = (string)$currency->id;
|
||||
$set['native_currency_code'] = $currency->code;
|
||||
@@ -66,9 +66,9 @@ trait ConvertsExchangeRates
|
||||
return $set;
|
||||
}
|
||||
foreach ($set['entries'] as $date => $entry) {
|
||||
$carbon = Carbon::createFromFormat(\DateTimeInterface::ATOM, $date);
|
||||
$rate = $this->getRate($currency, $native, $carbon);
|
||||
$rate = '0' === $rate ? '1' : $rate;
|
||||
$carbon = Carbon::createFromFormat(\DateTimeInterface::ATOM, $date);
|
||||
$rate = $this->getRate($currency, $native, $carbon);
|
||||
$rate = '0' === $rate ? '1' : $rate;
|
||||
app('log')->debug(sprintf('bcmul("%s", "%s")', (string)$entry, $rate));
|
||||
$set['entries'][$date] = (float)bcmul((string)$entry, $rate);
|
||||
}
|
||||
@@ -109,9 +109,9 @@ trait ConvertsExchangeRates
|
||||
foreach ($entries as $entry) {
|
||||
$currency = $this->getCurrency((int)$entry['id']);
|
||||
if ($currency->id !== $native->id) {
|
||||
$amount = $this->convertAmount($entry['sum'], $currency, $native);
|
||||
$entry['converted'] = true;
|
||||
$entry['native_sum'] = $amount;
|
||||
$amount = $this->convertAmount($entry['sum'], $currency, $native);
|
||||
$entry['converted'] = true;
|
||||
$entry['native_sum'] = $amount;
|
||||
$entry['native_currency_id'] = (string)$native->id;
|
||||
$entry['native_currency_name'] = $native->name;
|
||||
$entry['native_currency_symbol'] = $native->symbol;
|
||||
@@ -119,8 +119,8 @@ trait ConvertsExchangeRates
|
||||
$entry['native_currency_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
if ($currency->id === $native->id) {
|
||||
$entry['converted'] = false;
|
||||
$entry['native_sum'] = $entry['sum'];
|
||||
$entry['converted'] = false;
|
||||
$entry['native_sum'] = $entry['sum'];
|
||||
$entry['native_currency_id'] = (string)$native->id;
|
||||
$entry['native_currency_name'] = $native->name;
|
||||
$entry['native_currency_symbol'] = $native->symbol;
|
||||
|
||||
@@ -63,7 +63,7 @@ class ExchangeRateConverter
|
||||
$start->startOfDay();
|
||||
$end->endOfDay();
|
||||
Log::debug(sprintf('Preparing for %s to %s between %s and %s', $from->code, $to->code, $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
$set = auth()->user()
|
||||
$set = auth()->user()
|
||||
->currencyExchangeRates()
|
||||
->where('from_currency_id', $from->id)
|
||||
->where('to_currency_id', $to->id)
|
||||
@@ -76,7 +76,7 @@ class ExchangeRateConverter
|
||||
Log::debug('No prepared rates found in this period, use the fallback');
|
||||
$this->fallback($from, $to, $start);
|
||||
$this->noPreparedRates = true;
|
||||
$this->isPrepared = true;
|
||||
$this->isPrepared = true;
|
||||
Log::debug('prepare DONE()');
|
||||
|
||||
return;
|
||||
@@ -84,10 +84,10 @@ class ExchangeRateConverter
|
||||
$this->isPrepared = true;
|
||||
|
||||
// so there is a fallback just in case. Now loop the set of rates we DO have.
|
||||
$temp = [];
|
||||
$count = 0;
|
||||
$temp = [];
|
||||
$count = 0;
|
||||
foreach ($set as $rate) {
|
||||
$date = $rate->date->format('Y-m-d');
|
||||
$date = $rate->date->format('Y-m-d');
|
||||
$temp[$date] ??= [
|
||||
$from->id => [
|
||||
$to->id => $rate->rate,
|
||||
@@ -96,11 +96,11 @@ class ExchangeRateConverter
|
||||
++$count;
|
||||
}
|
||||
Log::debug(sprintf('Found %d rates in this period.', $count));
|
||||
$currentStart = clone $start;
|
||||
$currentStart = clone $start;
|
||||
while ($currentStart->lte($end)) {
|
||||
$currentDate = $currentStart->format('Y-m-d');
|
||||
$currentDate = $currentStart->format('Y-m-d');
|
||||
$this->prepared[$currentDate] ??= [];
|
||||
$fallback = $temp[$currentDate][$from->id][$to->id] ?? $this->fallback[$from->id][$to->id] ?? '0';
|
||||
$fallback = $temp[$currentDate][$from->id][$to->id] ?? $this->fallback[$from->id][$to->id] ?? '0';
|
||||
if (0 === count($this->prepared[$currentDate]) && 0 !== bccomp('0', $fallback)) {
|
||||
// fill from temp or fallback or from temp (see before)
|
||||
$this->prepared[$currentDate][$from->id][$to->id] = $fallback;
|
||||
@@ -138,12 +138,12 @@ class ExchangeRateConverter
|
||||
return $fallback;
|
||||
}
|
||||
// first attempt:
|
||||
$rate = $this->getFromDB($from->id, $to->id, $date->format('Y-m-d'));
|
||||
$rate = $this->getFromDB($from->id, $to->id, $date->format('Y-m-d'));
|
||||
if (null !== $rate) {
|
||||
return $rate;
|
||||
}
|
||||
// no result. perhaps the other way around?
|
||||
$rate = $this->getFromDB($to->id, $from->id, $date->format('Y-m-d'));
|
||||
$rate = $this->getFromDB($to->id, $from->id, $date->format('Y-m-d'));
|
||||
if (null !== $rate) {
|
||||
return bcdiv('1', $rate);
|
||||
}
|
||||
@@ -170,7 +170,7 @@ class ExchangeRateConverter
|
||||
if ($from === $to) {
|
||||
return '1';
|
||||
}
|
||||
$key = sprintf('cer-%d-%d-%s', $from, $to, $date);
|
||||
$key = sprintf('cer-%d-%d-%s', $from, $to, $date);
|
||||
|
||||
// perhaps the rate has been cached during this particular run
|
||||
$preparedRate = $this->prepared[$date][$from][$to] ?? null;
|
||||
@@ -180,7 +180,7 @@ class ExchangeRateConverter
|
||||
return $preparedRate;
|
||||
}
|
||||
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($key);
|
||||
if ($cache->has()) {
|
||||
$rate = $cache->get();
|
||||
@@ -193,7 +193,7 @@ class ExchangeRateConverter
|
||||
}
|
||||
|
||||
/** @var null|CurrencyExchangeRate $result */
|
||||
$result = auth()->user()
|
||||
$result = auth()->user()
|
||||
->currencyExchangeRates()
|
||||
->where('from_currency_id', $from)
|
||||
->where('to_currency_id', $to)
|
||||
@@ -202,7 +202,7 @@ class ExchangeRateConverter
|
||||
->first()
|
||||
;
|
||||
++$this->queryCount;
|
||||
$rate = (string) $result?->rate;
|
||||
$rate = (string) $result?->rate;
|
||||
|
||||
if ('' === $rate) {
|
||||
app('log')->debug(sprintf('Found no rate for #%d->#%d (%s) in the DB.', $from, $to, $date));
|
||||
@@ -243,13 +243,13 @@ class ExchangeRateConverter
|
||||
if ($euroId === $currency->id) {
|
||||
return '1';
|
||||
}
|
||||
$rate = $this->getFromDB($currency->id, $euroId, $date->format('Y-m-d'));
|
||||
$rate = $this->getFromDB($currency->id, $euroId, $date->format('Y-m-d'));
|
||||
|
||||
if (null !== $rate) {
|
||||
// app('log')->debug(sprintf('Rate for %s to EUR is %s.', $currency->code, $rate));
|
||||
return $rate;
|
||||
}
|
||||
$rate = $this->getFromDB($euroId, $currency->id, $date->format('Y-m-d'));
|
||||
$rate = $this->getFromDB($euroId, $currency->id, $date->format('Y-m-d'));
|
||||
if (null !== $rate) {
|
||||
return bcdiv('1', $rate);
|
||||
// app('log')->debug(sprintf('Inverted rate for %s to EUR is %s.', $currency->code, $rate));
|
||||
@@ -278,7 +278,7 @@ class ExchangeRateConverter
|
||||
if ($cache->has()) {
|
||||
return (int) $cache->get();
|
||||
}
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
||||
++$this->queryCount;
|
||||
if (null === $euro) {
|
||||
throw new FireflyException('Cannot find EUR in system, cannot do currency conversion.');
|
||||
|
||||
@@ -29,7 +29,7 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SummaryBalanceGrouped
|
||||
{
|
||||
private const string SUM = 'sum';
|
||||
private const string SUM = 'sum';
|
||||
private TransactionCurrency $default;
|
||||
private array $amounts = [];
|
||||
private array $keys;
|
||||
@@ -54,11 +54,11 @@ class SummaryBalanceGrouped
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
// transaction info:
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$amount = bcmul($journal['amount'], $multiplier);
|
||||
$currency = $this->currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
||||
$this->currencies[$currencyId] = $currency;
|
||||
$nativeAmount = $converter->convert($currency, $this->default, $journal['date'], $amount);
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$amount = bcmul($journal['amount'], $multiplier);
|
||||
$currency = $this->currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
||||
$this->currencies[$currencyId] = $currency;
|
||||
$nativeAmount = $converter->convert($currency, $this->default, $journal['date'], $amount);
|
||||
if ((int)$journal['foreign_currency_id'] === $this->default->id) {
|
||||
// use foreign amount instead
|
||||
$nativeAmount = $journal['foreign_amount'];
|
||||
@@ -82,7 +82,7 @@ class SummaryBalanceGrouped
|
||||
public function groupData(): array
|
||||
{
|
||||
\Log::debug('Now going to group data.');
|
||||
$return = [];
|
||||
$return = [];
|
||||
foreach ($this->keys as $key) {
|
||||
$title = match ($key) {
|
||||
'sum' => 'balance',
|
||||
|
||||
@@ -48,14 +48,14 @@ trait ValidatesUserGroupTrait
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
if (!$request->has('user_group_id')) {
|
||||
$group = $user->userGroup;
|
||||
app('log')->debug(sprintf('validateUserGroup: no user group submitted, return default group #%d.', $group?->id));
|
||||
|
||||
return $group;
|
||||
}
|
||||
$groupId = (int)$request->get('user_group_id');
|
||||
$groupId = (int)$request->get('user_group_id');
|
||||
|
||||
/** @var null|GroupMembership $membership */
|
||||
$membership = $user->groupMemberships()->where('user_group_id', $groupId)->first();
|
||||
|
||||
@@ -54,10 +54,10 @@ trait AugumentData
|
||||
|
||||
/** @var Account $expenseAccount */
|
||||
foreach ($accounts as $expenseAccount) {
|
||||
$collection = new Collection();
|
||||
$collection = new Collection();
|
||||
$collection->push($expenseAccount);
|
||||
|
||||
$revenue = $repository->findByName($expenseAccount->name, [AccountType::REVENUE]);
|
||||
$revenue = $repository->findByName($expenseAccount->name, [AccountType::REVENUE]);
|
||||
if (null !== $revenue) {
|
||||
$collection->push($revenue);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ trait AugumentData
|
||||
$return[$accountId] = $grouped[$accountId][0]['name'];
|
||||
}
|
||||
}
|
||||
$return[0] = '(no name)';
|
||||
$return[0] = '(no name)';
|
||||
|
||||
return $return;
|
||||
}
|
||||
@@ -134,7 +134,7 @@ trait AugumentData
|
||||
$return[$budgetId] = $grouped[$budgetId][0]['name'];
|
||||
}
|
||||
}
|
||||
$return[0] = (string)trans('firefly.no_budget');
|
||||
$return[0] = (string)trans('firefly.no_budget');
|
||||
|
||||
return $return;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ trait AugumentData
|
||||
$return[$categoryId] = $grouped[$categoryId][0]['name'];
|
||||
}
|
||||
}
|
||||
$return[0] = (string)trans('firefly.no_category');
|
||||
$return[0] = (string)trans('firefly.no_category');
|
||||
|
||||
return $return;
|
||||
}
|
||||
@@ -167,12 +167,12 @@ trait AugumentData
|
||||
protected function getLimits(Budget $budget, Carbon $start, Carbon $end): Collection // get data + augment with info
|
||||
{
|
||||
/** @var OperationsRepositoryInterface $opsRepository */
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
|
||||
/** @var BudgetLimitRepositoryInterface $blRepository */
|
||||
$blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||
$blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||
// properties for cache
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($budget->id);
|
||||
@@ -188,7 +188,7 @@ trait AugumentData
|
||||
|
||||
/** @var BudgetLimit $entry */
|
||||
foreach ($set as $entry) {
|
||||
$currency = $entry->transactionCurrency;
|
||||
$currency = $entry->transactionCurrency;
|
||||
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
@@ -224,7 +224,7 @@ trait AugumentData
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
$name = '(no name)';
|
||||
$name = '(no name)';
|
||||
if (TransactionType::WITHDRAWAL === $journal['transaction_type_type']) {
|
||||
$name = $journal['destination_account_name'];
|
||||
}
|
||||
@@ -247,16 +247,16 @@ trait AugumentData
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$total = $assets->merge($opposing);
|
||||
$total = $assets->merge($opposing);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAccounts($total);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = [
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = [
|
||||
'grand_sum' => '0',
|
||||
'per_currency' => [],
|
||||
];
|
||||
// loop to support multi currency
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
|
||||
// if not set, set to zero:
|
||||
if (!array_key_exists($currencyId, $sum['per_currency'])) {
|
||||
|
||||
@@ -44,7 +44,7 @@ trait ChartGeneration
|
||||
protected function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array // chart helper method.
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('chart.account.account-balance-chart');
|
||||
@@ -53,25 +53,25 @@ trait ChartGeneration
|
||||
return $cache->get();
|
||||
}
|
||||
app('log')->debug('Regenerate chart.account.account-balance-chart from scratch.');
|
||||
$locale = app('steam')->getLocale();
|
||||
$locale = app('steam')->getLocale();
|
||||
|
||||
/** @var GeneratorInterface $generator */
|
||||
$generator = app(GeneratorInterface::class);
|
||||
$generator = app(GeneratorInterface::class);
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepos */
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
$chartData = [];
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
$chartData = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
// TODO we can use getAccountCurrency instead.
|
||||
$currency = $accountRepos->getAccountCurrency($account);
|
||||
$currency = $accountRepos->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = $default;
|
||||
}
|
||||
$currentSet = [
|
||||
$currentSet = [
|
||||
'label' => $account->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'entries' => [],
|
||||
@@ -81,16 +81,16 @@ trait ChartGeneration
|
||||
$range = app('steam')->balanceInRange($account, $start, clone $end);
|
||||
$previous = array_values($range)[0];
|
||||
while ($currentStart <= $end) {
|
||||
$format = $currentStart->format('Y-m-d');
|
||||
$label = trim($currentStart->isoFormat((string)trans('config.month_and_day_js', [], $locale)));
|
||||
$balance = $range[$format] ?? $previous;
|
||||
$previous = $balance;
|
||||
$format = $currentStart->format('Y-m-d');
|
||||
$label = trim($currentStart->isoFormat((string)trans('config.month_and_day_js', [], $locale)));
|
||||
$balance = $range[$format] ?? $previous;
|
||||
$previous = $balance;
|
||||
$currentStart->addDay();
|
||||
$currentSet['entries'][$label] = $balance;
|
||||
}
|
||||
$chartData[] = $currentSet;
|
||||
$chartData[] = $currentSet;
|
||||
}
|
||||
$data = $generator->multiSet($chartData);
|
||||
$data = $generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -101,7 +101,7 @@ trait CreateStuff
|
||||
return;
|
||||
}
|
||||
|
||||
$key = RSA::createKey(4096);
|
||||
$key = RSA::createKey(4096);
|
||||
|
||||
Log::alert('NO OAuth keys were found. They have been created.');
|
||||
|
||||
|
||||
@@ -90,19 +90,19 @@ trait DateCalculation
|
||||
protected function getNextPeriods(Carbon $date, string $range): array
|
||||
{
|
||||
// select thing for next 12 periods:
|
||||
$loop = [];
|
||||
$loop = [];
|
||||
|
||||
/** @var Carbon $current */
|
||||
$current = app('navigation')->startOfPeriod($date, $range);
|
||||
$current = app('navigation')->endOfPeriod($current, $range);
|
||||
$current->addDay();
|
||||
$count = 0;
|
||||
$count = 0;
|
||||
|
||||
while ($count < 12) {
|
||||
$current = app('navigation')->endOfPeriod($current, $range);
|
||||
$currentStart = app('navigation')->startOfPeriod($current, $range);
|
||||
|
||||
$loop[] = [
|
||||
$loop[] = [
|
||||
'label' => $current->format('Y-m-d'),
|
||||
'title' => app('navigation')->periodShow($current, $range),
|
||||
'start' => clone $currentStart,
|
||||
@@ -122,7 +122,7 @@ trait DateCalculation
|
||||
protected function getPreviousPeriods(Carbon $date, string $range): array
|
||||
{
|
||||
// select thing for last 12 periods:
|
||||
$loop = [];
|
||||
$loop = [];
|
||||
|
||||
/** @var Carbon $current */
|
||||
$current = app('navigation')->startOfPeriod($date, $range);
|
||||
|
||||
@@ -59,13 +59,13 @@ trait GetConfigurationData
|
||||
$steps = [];
|
||||
if (is_array($elements) && count($elements) > 0) {
|
||||
foreach ($elements as $key => $options) {
|
||||
$currentStep = $options;
|
||||
$currentStep = $options;
|
||||
|
||||
// get the text:
|
||||
$currentStep['intro'] = (string)trans('intro.'.$route.'_'.$key);
|
||||
|
||||
// save in array:
|
||||
$steps[] = $currentStep;
|
||||
$steps[] = $currentStep;
|
||||
}
|
||||
}
|
||||
app('log')->debug(sprintf('Total basic steps for %s is %d', $routeKey, count($steps)));
|
||||
@@ -80,20 +80,20 @@ trait GetConfigurationData
|
||||
*/
|
||||
protected function getDateRangeConfig(): array // get configuration + get preferences.
|
||||
{
|
||||
$viewRange = app('navigation')->getViewRange(false);
|
||||
$viewRange = app('navigation')->getViewRange(false);
|
||||
|
||||
/** @var Carbon $start */
|
||||
$start = session('start');
|
||||
$start = session('start');
|
||||
|
||||
/** @var Carbon $end */
|
||||
$end = session('end');
|
||||
$end = session('end');
|
||||
|
||||
/** @var Carbon $first */
|
||||
$first = session('first');
|
||||
$title = sprintf('%s - %s', $start->isoFormat($this->monthAndDayFormat), $end->isoFormat($this->monthAndDayFormat));
|
||||
$isCustom = true === session('is_custom_range', false);
|
||||
$today = today(config('app.timezone'));
|
||||
$ranges = [
|
||||
$first = session('first');
|
||||
$title = sprintf('%s - %s', $start->isoFormat($this->monthAndDayFormat), $end->isoFormat($this->monthAndDayFormat));
|
||||
$isCustom = true === session('is_custom_range', false);
|
||||
$today = today(config('app.timezone'));
|
||||
$ranges = [
|
||||
// first range is the current range:
|
||||
$title => [$start, $end],
|
||||
];
|
||||
@@ -122,10 +122,10 @@ trait GetConfigurationData
|
||||
|
||||
// today:
|
||||
/** @var Carbon $todayStart */
|
||||
$todayStart = app('navigation')->startOfPeriod($today, $viewRange);
|
||||
$todayStart = app('navigation')->startOfPeriod($today, $viewRange);
|
||||
|
||||
/** @var Carbon $todayEnd */
|
||||
$todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
|
||||
$todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
|
||||
if ($todayStart->ne($start) || $todayEnd->ne($end)) {
|
||||
$ranges[ucfirst((string)trans('firefly.today'))] = [$todayStart, $todayEnd];
|
||||
}
|
||||
@@ -183,13 +183,13 @@ trait GetConfigurationData
|
||||
$elements = config(sprintf('intro.%s', $routeKey.'_'.$specificPage));
|
||||
if (is_array($elements) && count($elements) > 0) {
|
||||
foreach ($elements as $key => $options) {
|
||||
$currentStep = $options;
|
||||
$currentStep = $options;
|
||||
|
||||
// get the text:
|
||||
$currentStep['intro'] = (string)trans('intro.'.$route.'_'.$specificPage.'_'.$key);
|
||||
|
||||
// save in array:
|
||||
$steps[] = $currentStep;
|
||||
$steps[] = $currentStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,14 +72,14 @@ trait ModelInformation
|
||||
protected function getLiabilityTypes(): array
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
// types of liability:
|
||||
/** @var AccountType $debt */
|
||||
$debt = $repository->getAccountTypeByType(AccountType::DEBT);
|
||||
$debt = $repository->getAccountTypeByType(AccountType::DEBT);
|
||||
|
||||
/** @var AccountType $loan */
|
||||
$loan = $repository->getAccountTypeByType(AccountType::LOAN);
|
||||
$loan = $repository->getAccountTypeByType(AccountType::LOAN);
|
||||
|
||||
/** @var AccountType $mortgage */
|
||||
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
|
||||
@@ -111,8 +111,8 @@ trait ModelInformation
|
||||
protected function getTriggersForBill(Bill $bill): array // get info and augument
|
||||
{
|
||||
// TODO duplicate code
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
@@ -162,8 +162,8 @@ trait ModelInformation
|
||||
private function getTriggersForJournal(TransactionJournal $journal): array
|
||||
{
|
||||
// TODO duplicated code.
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
@@ -171,18 +171,18 @@ trait ModelInformation
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
$result = [];
|
||||
$journalTriggers = [];
|
||||
$values = [];
|
||||
$index = 0;
|
||||
$result = [];
|
||||
$journalTriggers = [];
|
||||
$values = [];
|
||||
$index = 0;
|
||||
|
||||
// amount, description, category, budget, tags, source, destination, notes, currency type
|
||||
// ,type
|
||||
/** @var null|Transaction $source */
|
||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
|
||||
/** @var null|Transaction $destination */
|
||||
$destination = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$destination = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
if (null === $destination || null === $source) {
|
||||
return $result;
|
||||
}
|
||||
@@ -217,21 +217,21 @@ trait ModelInformation
|
||||
++$index;
|
||||
|
||||
// category (if)
|
||||
$category = $journal->categories()->first();
|
||||
$category = $journal->categories()->first();
|
||||
if (null !== $category) {
|
||||
$journalTriggers[$index] = 'category_is';
|
||||
$values[$index] = $category->name;
|
||||
++$index;
|
||||
}
|
||||
// budget (if)
|
||||
$budget = $journal->budgets()->first();
|
||||
$budget = $journal->budgets()->first();
|
||||
if (null !== $budget) {
|
||||
$journalTriggers[$index] = 'budget_is';
|
||||
$values[$index] = $budget->name;
|
||||
++$index;
|
||||
}
|
||||
// tags (if)
|
||||
$tags = $journal->tags()->get();
|
||||
$tags = $journal->tags()->get();
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
@@ -240,7 +240,7 @@ trait ModelInformation
|
||||
++$index;
|
||||
}
|
||||
// notes (if)
|
||||
$notes = $journal->notes()->first();
|
||||
$notes = $journal->notes()->first();
|
||||
if (null !== $notes) {
|
||||
$journalTriggers[$index] = 'notes_are';
|
||||
$values[$index] = $notes->text;
|
||||
|
||||
@@ -74,11 +74,11 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
||||
|
||||
// properties for cache
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('account-show-period-entries');
|
||||
@@ -88,32 +88,32 @@ trait PeriodOverview
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
|
||||
// collect all expenses in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]));
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::DEPOSIT]);
|
||||
$earnedSet = $collector->getExtractedJournals();
|
||||
$earnedSet = $collector->getExtractedJournals();
|
||||
|
||||
// collect all income in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]));
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$spentSet = $collector->getExtractedJournals();
|
||||
$spentSet = $collector->getExtractedJournals();
|
||||
|
||||
// collect all transfers in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]));
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::TRANSFER]);
|
||||
$transferSet = $collector->getExtractedJournals();
|
||||
$transferSet = $collector->getExtractedJournals();
|
||||
|
||||
// loop dates
|
||||
foreach ($dates as $currentDate) {
|
||||
@@ -124,8 +124,8 @@ trait PeriodOverview
|
||||
$transferredIn = $this->filterTransferredIn($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' => route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'title' => $title,
|
||||
'route' => route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
@@ -146,11 +146,11 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
||||
|
||||
// properties for entries with their amounts.
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty($range);
|
||||
@@ -162,32 +162,32 @@ trait PeriodOverview
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
|
||||
// collect all expenses in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setCategory($category);
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::DEPOSIT]);
|
||||
$earnedSet = $collector->getExtractedJournals();
|
||||
$earnedSet = $collector->getExtractedJournals();
|
||||
|
||||
// collect all income in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setCategory($category);
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$spentSet = $collector->getExtractedJournals();
|
||||
$spentSet = $collector->getExtractedJournals();
|
||||
|
||||
// collect all transfers in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setCategory($category);
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::TRANSFER]);
|
||||
$transferSet = $collector->getExtractedJournals();
|
||||
$transferSet = $collector->getExtractedJournals();
|
||||
foreach ($dates as $currentDate) {
|
||||
$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
|
||||
$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
|
||||
@@ -221,11 +221,11 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array
|
||||
{
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
|
||||
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
||||
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('no-budget-period-entries');
|
||||
@@ -235,14 +235,14 @@ trait PeriodOverview
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
|
||||
// get all expenses without a budget.
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->withoutBudget()->withAccountInformation()->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
foreach ($dates as $currentDate) {
|
||||
$set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);
|
||||
@@ -273,37 +273,37 @@ trait PeriodOverview
|
||||
protected function getNoCategoryPeriodOverview(Carbon $theDate): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
$first = $this->journalRepos->firstNull();
|
||||
$start = null === $first ? new Carbon() : $first->date;
|
||||
$end = clone $theDate;
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
$first = $this->journalRepos->firstNull();
|
||||
$start = null === $first ? new Carbon() : $first->date;
|
||||
$end = clone $theDate;
|
||||
|
||||
app('log')->debug(sprintf('Start for getNoCategoryPeriodOverview() is %s', $start->format('Y-m-d')));
|
||||
app('log')->debug(sprintf('End for getNoCategoryPeriodOverview() is %s', $end->format('Y-m-d')));
|
||||
|
||||
// properties for cache
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
|
||||
// collect all expenses in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->withoutCategory();
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::DEPOSIT]);
|
||||
$earnedSet = $collector->getExtractedJournals();
|
||||
$earnedSet = $collector->getExtractedJournals();
|
||||
|
||||
// collect all income in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->withoutCategory();
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$spentSet = $collector->getExtractedJournals();
|
||||
$spentSet = $collector->getExtractedJournals();
|
||||
|
||||
// collect all transfers in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->withoutCategory();
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::TRANSFER]);
|
||||
@@ -337,11 +337,11 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getTagPeriodOverview(Tag $tag, Carbon $start, Carbon $end): array // period overview for tags.
|
||||
{
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
||||
|
||||
// properties for cache
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('tag-period-entries');
|
||||
@@ -351,37 +351,37 @@ trait PeriodOverview
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
|
||||
// collect all expenses in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setTag($tag);
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::DEPOSIT]);
|
||||
$earnedSet = $collector->getExtractedJournals();
|
||||
$earnedSet = $collector->getExtractedJournals();
|
||||
|
||||
// collect all income in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setTag($tag);
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$spentSet = $collector->getExtractedJournals();
|
||||
$spentSet = $collector->getExtractedJournals();
|
||||
|
||||
// collect all transfers in this period:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setTag($tag);
|
||||
$collector->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::TRANSFER]);
|
||||
$transferSet = $collector->getExtractedJournals();
|
||||
$transferSet = $collector->getExtractedJournals();
|
||||
|
||||
// filer all of them:
|
||||
$earnedSet = $this->filterJournalsByTag($earnedSet, $tag);
|
||||
$spentSet = $this->filterJournalsByTag($spentSet, $tag);
|
||||
$transferSet = $this->filterJournalsByTag($transferSet, $tag);
|
||||
$earnedSet = $this->filterJournalsByTag($earnedSet, $tag);
|
||||
$spentSet = $this->filterJournalsByTag($spentSet, $tag);
|
||||
$transferSet = $this->filterJournalsByTag($transferSet, $tag);
|
||||
|
||||
foreach ($dates as $currentDate) {
|
||||
$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
|
||||
@@ -411,12 +411,12 @@ trait PeriodOverview
|
||||
*/
|
||||
protected function getTransactionPeriodOverview(string $transactionType, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
$types = config(sprintf('firefly.transactionTypesByType.%s', $transactionType));
|
||||
$range = app('navigation')->getViewRange(true);
|
||||
$types = config(sprintf('firefly.transactionTypesByType.%s', $transactionType));
|
||||
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
||||
|
||||
// properties for cache
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('transactions-period-entries');
|
||||
@@ -426,13 +426,13 @@ trait PeriodOverview
|
||||
}
|
||||
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
$entries = [];
|
||||
|
||||
// collect all journals in this period (regardless of type)
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setTypes($types)->setRange($start, $end);
|
||||
$genericSet = $collector->getExtractedJournals();
|
||||
$genericSet = $collector->getExtractedJournals();
|
||||
|
||||
foreach ($dates as $currentDate) {
|
||||
$spent = [];
|
||||
@@ -451,7 +451,7 @@ trait PeriodOverview
|
||||
$transferred = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']);
|
||||
}
|
||||
$entries[]
|
||||
= [
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' => route('transactions.index', [$transactionType, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
@@ -521,8 +521,8 @@ trait PeriodOverview
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
if (!array_key_exists($currencyId, $return)) {
|
||||
$return[$currencyId] = [
|
||||
'amount' => '0',
|
||||
@@ -561,7 +561,7 @@ trait PeriodOverview
|
||||
{
|
||||
$return = [];
|
||||
foreach ($set as $entry) {
|
||||
$found = false;
|
||||
$found = false;
|
||||
|
||||
/** @var array $localTag */
|
||||
foreach ($entry['tags'] as $localTag) {
|
||||
|
||||
@@ -50,20 +50,20 @@ trait RenderPartialViews
|
||||
protected function budgetEntry(array $attributes): string // generate view for report.
|
||||
{
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
|
||||
/** @var BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = app(BudgetRepositoryInterface::class);
|
||||
$budget = $budgetRepository->find((int)$attributes['budgetId']);
|
||||
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$account = $accountRepos->find((int)$attributes['accountId']);
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$account = $accountRepos->find((int)$attributes['accountId']);
|
||||
|
||||
if (null === $budget || null === $account) {
|
||||
throw new FireflyException('Could not render popup.report.balance-amount because budget or account is null.');
|
||||
}
|
||||
|
||||
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
|
||||
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
|
||||
|
||||
try {
|
||||
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
|
||||
@@ -111,13 +111,13 @@ trait RenderPartialViews
|
||||
$budgetRepository = app(BudgetRepositoryInterface::class);
|
||||
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
|
||||
$budget = $budgetRepository->find((int)$attributes['budgetId']);
|
||||
$budget = $budgetRepository->find((int)$attributes['budgetId']);
|
||||
if (null === $budget) {
|
||||
$budget = new Budget();
|
||||
}
|
||||
$journals = $popupHelper->byBudget($budget, $attributes);
|
||||
$journals = $popupHelper->byBudget($budget, $attributes);
|
||||
|
||||
try {
|
||||
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();
|
||||
@@ -139,7 +139,7 @@ trait RenderPartialViews
|
||||
protected function categoryEntry(array $attributes): string // generate view for report.
|
||||
{
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
|
||||
/** @var CategoryRepositoryInterface $categoryRepository */
|
||||
$categoryRepository = app(CategoryRepositoryInterface::class);
|
||||
@@ -234,15 +234,15 @@ trait RenderPartialViews
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
|
||||
$account = $accountRepository->find((int)$attributes['accountId']);
|
||||
$account = $accountRepository->find((int)$attributes['accountId']);
|
||||
|
||||
if (null === $account) {
|
||||
return 'This is an unknown account. Apologies.';
|
||||
}
|
||||
|
||||
$journals = $popupHelper->byExpenses($account, $attributes);
|
||||
$journals = $popupHelper->byExpenses($account, $attributes);
|
||||
|
||||
try {
|
||||
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
|
||||
@@ -263,8 +263,8 @@ trait RenderPartialViews
|
||||
*/
|
||||
protected function getCurrentActions(Rule $rule): array // get info from object and present.
|
||||
{
|
||||
$index = 0;
|
||||
$actions = [];
|
||||
$index = 0;
|
||||
$actions = [];
|
||||
// must be repos
|
||||
$currentActions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
|
||||
|
||||
@@ -303,8 +303,8 @@ trait RenderPartialViews
|
||||
protected function getCurrentTriggers(Rule $rule): array // get info from object and present.
|
||||
{
|
||||
// TODO duplicated code.
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
@@ -322,7 +322,7 @@ trait RenderPartialViews
|
||||
$count = ($index + 1);
|
||||
|
||||
try {
|
||||
$rootOperator = OperatorQuerySearch::getRootOperator((string)$entry->trigger_type);
|
||||
$rootOperator = OperatorQuerySearch::getRootOperator((string)$entry->trigger_type);
|
||||
if (str_starts_with($rootOperator, '-')) {
|
||||
$rootOperator = substr($rootOperator, 1);
|
||||
}
|
||||
@@ -362,14 +362,14 @@ trait RenderPartialViews
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
$account = $accountRepository->find((int)$attributes['accountId']);
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
$account = $accountRepository->find((int)$attributes['accountId']);
|
||||
|
||||
if (null === $account) {
|
||||
return 'This is an unknown category. Apologies.';
|
||||
}
|
||||
|
||||
$journals = $popupHelper->byIncome($account, $attributes);
|
||||
$journals = $popupHelper->byIncome($account, $attributes);
|
||||
|
||||
try {
|
||||
$view = view('popup.report.income-entry', compact('journals', 'account'))->render();
|
||||
|
||||
@@ -81,13 +81,13 @@ trait RequestInformation
|
||||
$page = $this->getPageName();
|
||||
$specificPage = $this->getSpecificPageName();
|
||||
// indicator if user has seen the help for this page ( + special page):
|
||||
$key = sprintf('shown_demo_%s%s', $page, $specificPage);
|
||||
$key = sprintf('shown_demo_%s%s', $page, $specificPage);
|
||||
// is there an intro for this route?
|
||||
$intro = config(sprintf('intro.%s', $page)) ?? [];
|
||||
$specialIntro = config(sprintf('intro.%s%s', $page, $specificPage)) ?? [];
|
||||
// some routes have a "what" parameter, which indicates a special page:
|
||||
|
||||
$shownDemo = true;
|
||||
$shownDemo = true;
|
||||
// both must be array and either must be > 0
|
||||
if (count($intro) > 0 || count($specialIntro) > 0) {
|
||||
$shownDemo = app('preferences')->get($key, false)->data;
|
||||
@@ -121,7 +121,7 @@ trait RequestInformation
|
||||
final protected function notInSessionRange(Carbon $date): bool // Validate a preference
|
||||
{
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
@@ -143,20 +143,20 @@ trait RequestInformation
|
||||
final protected function parseAttributes(array $attributes): array // parse input + return result
|
||||
{
|
||||
$attributes['location'] ??= '';
|
||||
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));
|
||||
$date = Carbon::createFromFormat('Ymd', $attributes['startDate']);
|
||||
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));
|
||||
$date = Carbon::createFromFormat('Ymd', $attributes['startDate']);
|
||||
if (false === $date) {
|
||||
$date = today(config('app.timezone'));
|
||||
}
|
||||
$date->startOfMonth();
|
||||
$attributes['startDate'] = $date;
|
||||
|
||||
$date2 = Carbon::createFromFormat('Ymd', $attributes['endDate']);
|
||||
$date2 = Carbon::createFromFormat('Ymd', $attributes['endDate']);
|
||||
if (false === $date2) {
|
||||
$date2 = today(config('app.timezone'));
|
||||
}
|
||||
$date2->endOfDay();
|
||||
$attributes['endDate'] = $date2;
|
||||
$attributes['endDate'] = $date2;
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ trait RuleManagement
|
||||
protected function getPreviousTriggers(Request $request): array
|
||||
{
|
||||
// TODO duplicated code.
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
@@ -127,7 +127,7 @@ trait RuleManagement
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
$index = 0;
|
||||
$index = 0;
|
||||
foreach ($submittedOperators as $operator) {
|
||||
$rootOperator = OperatorQuerySearch::getRootOperator($operator['type']);
|
||||
$needsContext = (bool)config(sprintf('search.operators.%s.needs_context', $rootOperator));
|
||||
|
||||
@@ -38,7 +38,7 @@ trait TransactionCalculation
|
||||
*/
|
||||
protected function getExpensesForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$total = $accounts->merge($opposing);
|
||||
$total = $accounts->merge($opposing);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
@@ -117,7 +117,7 @@ trait TransactionCalculation
|
||||
*/
|
||||
protected function getIncomeForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$total = $accounts->merge($opposing);
|
||||
$total = $accounts->merge($opposing);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
@@ -68,7 +68,7 @@ trait UserNavigation
|
||||
final protected function isEditableGroup(TransactionGroup $group): bool
|
||||
{
|
||||
/** @var null|TransactionJournal $journal */
|
||||
$journal = $group->transactionJournals()->first();
|
||||
$journal = $group->transactionJournals()->first();
|
||||
if (null === $journal) {
|
||||
return false;
|
||||
}
|
||||
@@ -95,10 +95,10 @@ trait UserNavigation
|
||||
|
||||
return redirect(route('index'));
|
||||
}
|
||||
$journal = $transaction->transactionJournal;
|
||||
$journal = $transaction->transactionJournal;
|
||||
|
||||
/** @var null|Transaction $other */
|
||||
$other = $journal->transactions()->where('id', '!=', $transaction->id)->first();
|
||||
$other = $journal->transactions()->where('id', '!=', $transaction->id)->first();
|
||||
if (null === $other) {
|
||||
app('log')->error(sprintf('Account #%d has no valid journals. Dont know where it belongs.', $account->id));
|
||||
session()->flash('error', trans('firefly.cant_find_redirect_account'));
|
||||
@@ -118,7 +118,7 @@ trait UserNavigation
|
||||
final protected function redirectGroupToAccount(TransactionGroup $group)
|
||||
{
|
||||
/** @var null|TransactionJournal $journal */
|
||||
$journal = $group->transactionJournals()->first();
|
||||
$journal = $group->transactionJournals()->first();
|
||||
if (null === $journal) {
|
||||
app('log')->error(sprintf('No journals in group #%d', $group->id));
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class BillDateCalculator
|
||||
|
||||
// 2023-06-23 subDay to fix 7655
|
||||
$currentStart->subDay();
|
||||
$loop = 0;
|
||||
$loop = 0;
|
||||
Log::debug('Start of loop');
|
||||
while ($currentStart <= $latest) {
|
||||
Log::debug(sprintf('Current start is %s', $currentStart->format('Y-m-d')));
|
||||
@@ -82,7 +82,7 @@ class BillDateCalculator
|
||||
// 2023-10
|
||||
// for the next loop, go to end of period, THEN add day.
|
||||
$nextExpectedMatch->addDay();
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
|
||||
++$loop;
|
||||
if ($loop > 12) {
|
||||
@@ -92,7 +92,7 @@ class BillDateCalculator
|
||||
}
|
||||
}
|
||||
Log::debug('end of loop');
|
||||
$simple = $set->map(
|
||||
$simple = $set->map(
|
||||
static function (Carbon $date) {
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class Navigation
|
||||
if ($end < $start) {
|
||||
[$start, $end] = [$end, $start];
|
||||
}
|
||||
$periods = [];
|
||||
$periods = [];
|
||||
// first, 13 periods of [range]
|
||||
$loopCount = 0;
|
||||
$loopDate = clone $end;
|
||||
@@ -160,7 +160,7 @@ class Navigation
|
||||
|
||||
public function startOfPeriod(Carbon $theDate, string $repeatFreq): Carbon
|
||||
{
|
||||
$date = clone $theDate;
|
||||
$date = clone $theDate;
|
||||
|
||||
$functionMap = [
|
||||
'1D' => 'startOfDay',
|
||||
@@ -191,7 +191,7 @@ class Navigation
|
||||
return $date;
|
||||
}
|
||||
|
||||
$result = match ($repeatFreq) {
|
||||
$result = match ($repeatFreq) {
|
||||
'last7' => $date->subDays(7)->startOfDay(),
|
||||
'last30' => $date->subDays(30)->startOfDay(),
|
||||
'last90' => $date->subDays(90)->startOfDay(),
|
||||
@@ -215,7 +215,7 @@ class Navigation
|
||||
|
||||
public function endOfPeriod(Carbon $end, string $repeatFreq): Carbon
|
||||
{
|
||||
$currentEnd = clone $end;
|
||||
$currentEnd = clone $end;
|
||||
|
||||
$functionMap = [
|
||||
'1D' => 'endOfDay',
|
||||
@@ -245,14 +245,14 @@ class Navigation
|
||||
'6M' => 6,
|
||||
];
|
||||
|
||||
$subDay = ['week', 'weekly', '1W', 'month', 'monthly', '1M', '3M', 'quarter', 'quarterly', '6M', 'half-year', 'half_year', '1Y', 'year', 'yearly'];
|
||||
$subDay = ['week', 'weekly', '1W', 'month', 'monthly', '1M', '3M', 'quarter', 'quarterly', '6M', 'half-year', 'half_year', '1Y', 'year', 'yearly'];
|
||||
|
||||
// if the range is custom, the end of the period
|
||||
// is another X days (x is the difference between start)
|
||||
// and end added to $theCurrentEnd
|
||||
if ('custom' === $repeatFreq) {
|
||||
/** @var Carbon $tStart */
|
||||
$tStart = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$tStart = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
|
||||
/** @var Carbon $tEnd */
|
||||
$tEnd = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
@@ -262,7 +262,7 @@ class Navigation
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
$result = match ($repeatFreq) {
|
||||
$result = match ($repeatFreq) {
|
||||
'last7' => $currentEnd->addDays(7)->startOfDay(),
|
||||
'last30' => $currentEnd->addDays(30)->startOfDay(),
|
||||
'last90' => $currentEnd->addDays(90)->startOfDay(),
|
||||
@@ -282,7 +282,7 @@ class Navigation
|
||||
|
||||
return $end;
|
||||
}
|
||||
$function = $functionMap[$repeatFreq];
|
||||
$function = $functionMap[$repeatFreq];
|
||||
|
||||
if (array_key_exists($repeatFreq, $modifierMap)) {
|
||||
$currentEnd->{$function}($modifierMap[$repeatFreq]); // @phpstan-ignore-line
|
||||
@@ -311,7 +311,7 @@ class Navigation
|
||||
$beginning->format('Y-m-d'),
|
||||
$end->format('Y-m-d')
|
||||
));
|
||||
$map = [
|
||||
$map = [
|
||||
'daily' => 'floatDiffInDays',
|
||||
'weekly' => 'floatDiffInWeeks',
|
||||
'monthly' => 'floatDiffInMonths',
|
||||
@@ -324,7 +324,7 @@ class Navigation
|
||||
|
||||
return 1;
|
||||
}
|
||||
$func = $map[$period];
|
||||
$func = $map[$period];
|
||||
// first do the diff
|
||||
$floatDiff = $beginning->{$func}($end); // @phpstan-ignore-line
|
||||
|
||||
@@ -339,7 +339,7 @@ class Navigation
|
||||
}
|
||||
|
||||
// then do ceil()
|
||||
$diff = ceil($floatDiff);
|
||||
$diff = ceil($floatDiff);
|
||||
|
||||
Log::debug(sprintf('Diff is %f periods (%d rounded up)', $floatDiff, $diff));
|
||||
|
||||
@@ -376,7 +376,7 @@ class Navigation
|
||||
'yearly' => 'endOfYear',
|
||||
];
|
||||
|
||||
$currentEnd = clone $theCurrentEnd;
|
||||
$currentEnd = clone $theCurrentEnd;
|
||||
|
||||
if (array_key_exists($repeatFreq, $functionMap)) {
|
||||
$function = $functionMap[$repeatFreq];
|
||||
@@ -431,7 +431,7 @@ class Navigation
|
||||
*/
|
||||
public function listOfPeriods(Carbon $start, Carbon $end): array
|
||||
{
|
||||
$locale = app('steam')->getLocale();
|
||||
$locale = app('steam')->getLocale();
|
||||
// define period to increment
|
||||
$increment = 'addDay';
|
||||
$format = $this->preferredCarbonFormat($start, $end);
|
||||
@@ -447,8 +447,8 @@ class Navigation
|
||||
$increment = 'addYear';
|
||||
$displayFormat = (string)trans('config.year_js');
|
||||
}
|
||||
$begin = clone $start;
|
||||
$entries = [];
|
||||
$begin = clone $start;
|
||||
$entries = [];
|
||||
while ($begin < $end) {
|
||||
$formatted = $begin->format($format);
|
||||
$displayed = $begin->isoFormat($displayFormat);
|
||||
@@ -606,7 +606,7 @@ class Navigation
|
||||
public function subtractPeriod(Carbon $theDate, string $repeatFreq, int $subtract = null): Carbon
|
||||
{
|
||||
$subtract ??= 1;
|
||||
$date = clone $theDate;
|
||||
$date = clone $theDate;
|
||||
// 1D 1W 1M 3M 6M 1Y
|
||||
$functionMap = [
|
||||
'1D' => 'subDays',
|
||||
@@ -645,7 +645,7 @@ class Navigation
|
||||
// this is then subtracted from $theDate (* $subtract).
|
||||
if ('custom' === $repeatFreq) {
|
||||
/** @var Carbon $tStart */
|
||||
$tStart = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
$tStart = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
|
||||
/** @var Carbon $tEnd */
|
||||
$tEnd = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
@@ -737,7 +737,7 @@ class Navigation
|
||||
|
||||
return $fiscalHelper->endOfFiscalYear($end);
|
||||
}
|
||||
$list = [
|
||||
$list = [
|
||||
'last7',
|
||||
'last30',
|
||||
'last90',
|
||||
|
||||
@@ -76,15 +76,15 @@ class ParseDateString
|
||||
public function parseDate(string $date): Carbon
|
||||
{
|
||||
app('log')->debug(sprintf('parseDate("%s")', $date));
|
||||
$date = strtolower($date);
|
||||
$date = strtolower($date);
|
||||
// parse keywords:
|
||||
if (in_array($date, $this->keywords, true)) {
|
||||
return $this->parseKeyword($date);
|
||||
}
|
||||
|
||||
// if regex for YYYY-MM-DD:
|
||||
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
|
||||
$result = preg_match($pattern, $date);
|
||||
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
|
||||
$result = preg_match($pattern, $date);
|
||||
if (false !== $result && 0 !== $result) {
|
||||
return $this->parseDefaultDate($date);
|
||||
}
|
||||
@@ -222,11 +222,11 @@ class ParseDateString
|
||||
|
||||
foreach ($parts as $part) {
|
||||
app('log')->debug(sprintf('Now parsing part "%s"', $part));
|
||||
$part = trim($part);
|
||||
$part = trim($part);
|
||||
|
||||
// verify if correct
|
||||
$pattern = '/[+-]\d+[wqmdy]/';
|
||||
$result = preg_match($pattern, $part);
|
||||
$pattern = '/[+-]\d+[wqmdy]/';
|
||||
$result = preg_match($pattern, $part);
|
||||
if (0 === $result || false === $result) {
|
||||
app('log')->error(sprintf('Part "%s" does not match regular expression. Will be skipped.', $part));
|
||||
|
||||
@@ -240,7 +240,7 @@ class ParseDateString
|
||||
|
||||
continue;
|
||||
}
|
||||
$func = $functions[$direction][$period];
|
||||
$func = $functions[$direction][$period];
|
||||
app('log')->debug(sprintf('Will now do %s(%d) on %s', $func, $number, $today->format('Y-m-d')));
|
||||
$today->{$func}($number); // @phpstan-ignore-line
|
||||
app('log')->debug(sprintf('Resulting date is %s', $today->format('Y-m-d')));
|
||||
|
||||
@@ -129,11 +129,11 @@ class Preferences
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
$fullName = sprintf('preference%s%s', $user->id, $name);
|
||||
$fullName = sprintf('preference%s%s', $user->id, $name);
|
||||
\Cache::forget($fullName);
|
||||
|
||||
/** @var null|Preference $pref */
|
||||
$pref = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']);
|
||||
$pref = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']);
|
||||
|
||||
if (null !== $pref && null === $value) {
|
||||
$pref->delete();
|
||||
|
||||
@@ -76,7 +76,7 @@ class BudgetReportGenerator
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($this->accounts as $account) {
|
||||
$accountId = $account->id;
|
||||
$accountId = $account->id;
|
||||
$this->report[$accountId] ??= [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
@@ -177,7 +177,7 @@ class BudgetReportGenerator
|
||||
??= '0';
|
||||
|
||||
$this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId]
|
||||
= bcadd($this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId], $journal['amount']);
|
||||
= bcadd($this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId], $journal['amount']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ class BudgetReportGenerator
|
||||
*/
|
||||
private function processBudget(Budget $budget): void
|
||||
{
|
||||
$budgetId = $budget->id;
|
||||
$budgetId = $budget->id;
|
||||
$this->report['budgets'][$budgetId] ??= [
|
||||
'budget_id' => $budgetId,
|
||||
'budget_name' => $budget->name,
|
||||
@@ -208,7 +208,7 @@ class BudgetReportGenerator
|
||||
];
|
||||
|
||||
// get all budget limits for budget in period:
|
||||
$limits = $this->blRepository->getBudgetLimits($budget, $this->start, $this->end);
|
||||
$limits = $this->blRepository->getBudgetLimits($budget, $this->start, $this->end);
|
||||
|
||||
/** @var BudgetLimit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
@@ -221,14 +221,14 @@ class BudgetReportGenerator
|
||||
*/
|
||||
private function processLimit(Budget $budget, BudgetLimit $limit): void
|
||||
{
|
||||
$budgetId = $budget->id;
|
||||
$limitId = $limit->id;
|
||||
$limitCurrency = $limit->transactionCurrency ?? $this->currency;
|
||||
$currencyId = $limitCurrency->id;
|
||||
$expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $this->accounts, new Collection([$budget]));
|
||||
$spent = $expenses[$currencyId]['sum'] ?? '0';
|
||||
$left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent);
|
||||
$overspent = 1 === bccomp(bcmul($spent, '-1'), $limit->amount) ? bcadd($spent, $limit->amount) : '0';
|
||||
$budgetId = $budget->id;
|
||||
$limitId = $limit->id;
|
||||
$limitCurrency = $limit->transactionCurrency ?? $this->currency;
|
||||
$currencyId = $limitCurrency->id;
|
||||
$expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $this->accounts, new Collection([$budget]));
|
||||
$spent = $expenses[$currencyId]['sum'] ?? '0';
|
||||
$left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent);
|
||||
$overspent = 1 === bccomp(bcmul($spent, '-1'), $limit->amount) ? bcadd($spent, $limit->amount) : '0';
|
||||
|
||||
$this->report['budgets'][$budgetId]['budget_limits'][$limitId] ??= [
|
||||
'budget_limit_id' => $limitId,
|
||||
@@ -249,7 +249,7 @@ class BudgetReportGenerator
|
||||
|
||||
// make sum information:
|
||||
$this->report['sums'][$currencyId]
|
||||
??= [
|
||||
??= [
|
||||
'budgeted' => '0',
|
||||
'spent' => '0',
|
||||
'left' => '0',
|
||||
@@ -279,16 +279,16 @@ class BudgetReportGenerator
|
||||
'budget_limits' => [],
|
||||
];
|
||||
|
||||
$noBudget = $this->nbRepository->sumExpenses($this->start, $this->end, $this->accounts);
|
||||
$noBudget = $this->nbRepository->sumExpenses($this->start, $this->end, $this->accounts);
|
||||
foreach ($noBudget as $noBudgetEntry) {
|
||||
// currency information:
|
||||
$nbCurrencyId = (int)($noBudgetEntry['currency_id'] ?? $this->currency->id);
|
||||
$nbCurrencyCode = $noBudgetEntry['currency_code'] ?? $this->currency->code;
|
||||
$nbCurrencyName = $noBudgetEntry['currency_name'] ?? $this->currency->name;
|
||||
$nbCurrencySymbol = $noBudgetEntry['currency_symbol'] ?? $this->currency->symbol;
|
||||
$nbCurrencyDp = $noBudgetEntry['currency_decimal_places'] ?? $this->currency->decimal_places;
|
||||
$nbCurrencyId = (int)($noBudgetEntry['currency_id'] ?? $this->currency->id);
|
||||
$nbCurrencyCode = $noBudgetEntry['currency_code'] ?? $this->currency->code;
|
||||
$nbCurrencyName = $noBudgetEntry['currency_name'] ?? $this->currency->name;
|
||||
$nbCurrencySymbol = $noBudgetEntry['currency_symbol'] ?? $this->currency->symbol;
|
||||
$nbCurrencyDp = $noBudgetEntry['currency_decimal_places'] ?? $this->currency->decimal_places;
|
||||
|
||||
$this->report['budgets'][0]['budget_limits'][] = [
|
||||
$this->report['budgets'][0]['budget_limits'][] = [
|
||||
'budget_limit_id' => null,
|
||||
'start_date' => $this->start,
|
||||
'end_date' => $this->end,
|
||||
@@ -304,7 +304,7 @@ class BudgetReportGenerator
|
||||
'currency_symbol' => $nbCurrencySymbol,
|
||||
'currency_decimal_places' => $nbCurrencyDp,
|
||||
];
|
||||
$this->report['sums'][$nbCurrencyId]['spent'] = bcadd($this->report['sums'][$nbCurrencyId]['spent'] ?? '0', $noBudgetEntry['sum']);
|
||||
$this->report['sums'][$nbCurrencyId]['spent'] = bcadd($this->report['sums'][$nbCurrencyId]['spent'] ?? '0', $noBudgetEntry['sum']);
|
||||
// append currency info because it may be missing:
|
||||
$this->report['sums'][$nbCurrencyId]['currency_id'] = $nbCurrencyId;
|
||||
$this->report['sums'][$nbCurrencyId]['currency_code'] = $nbCurrencyCode;
|
||||
@@ -327,15 +327,15 @@ class BudgetReportGenerator
|
||||
// make percentages based on total amount.
|
||||
foreach ($this->report['budgets'] as $budgetId => $data) {
|
||||
foreach ($data['budget_limits'] as $limitId => $entry) {
|
||||
$budgetId = (int)$budgetId;
|
||||
$limitId = (int)$limitId;
|
||||
$currencyId = (int)$entry['currency_id'];
|
||||
$spent = $entry['spent'];
|
||||
$totalSpent = $this->report['sums'][$currencyId]['spent'] ?? '0';
|
||||
$spentPct = '0';
|
||||
$budgeted = $entry['budgeted'];
|
||||
$totalBudgeted = $this->report['sums'][$currencyId]['budgeted'] ?? '0';
|
||||
$budgetedPct = '0';
|
||||
$budgetId = (int)$budgetId;
|
||||
$limitId = (int)$limitId;
|
||||
$currencyId = (int)$entry['currency_id'];
|
||||
$spent = $entry['spent'];
|
||||
$totalSpent = $this->report['sums'][$currencyId]['spent'] ?? '0';
|
||||
$spentPct = '0';
|
||||
$budgeted = $entry['budgeted'];
|
||||
$totalBudgeted = $this->report['sums'][$currencyId]['budgeted'] ?? '0';
|
||||
$budgetedPct = '0';
|
||||
|
||||
if (0 !== bccomp($spent, '0') && 0 !== bccomp($totalSpent, '0')) {
|
||||
$spentPct = round((float)bcmul(bcdiv($spent, $totalSpent), '100'));
|
||||
@@ -343,7 +343,7 @@ class BudgetReportGenerator
|
||||
if (0 !== bccomp($budgeted, '0') && 0 !== bccomp($totalBudgeted, '0')) {
|
||||
$budgetedPct = round((float)bcmul(bcdiv($budgeted, $totalBudgeted), '100'));
|
||||
}
|
||||
$this->report['sums'][$currencyId]['budgeted'] ??= '0';
|
||||
$this->report['sums'][$currencyId]['budgeted'] ??= '0';
|
||||
$this->report['budgets'][$budgetId]['budget_limits'][$limitId]['spent_pct'] = $spentPct;
|
||||
$this->report['budgets'][$budgetId]['budget_limits'][$limitId]['budgeted_pct'] = $budgetedPct;
|
||||
}
|
||||
|
||||
@@ -61,17 +61,17 @@ class CategoryReportGenerator
|
||||
*/
|
||||
public function operations(): void
|
||||
{
|
||||
$earnedWith = $this->opsRepository->listIncome($this->start, $this->end, $this->accounts);
|
||||
$spentWith = $this->opsRepository->listExpenses($this->start, $this->end, $this->accounts);
|
||||
$earnedWith = $this->opsRepository->listIncome($this->start, $this->end, $this->accounts);
|
||||
$spentWith = $this->opsRepository->listExpenses($this->start, $this->end, $this->accounts);
|
||||
|
||||
// also transferred out and transferred into these accounts in this category:
|
||||
$transferredIn = $this->opsRepository->listTransferredIn($this->start, $this->end, $this->accounts);
|
||||
$transferredOut = $this->opsRepository->listTransferredOut($this->start, $this->end, $this->accounts);
|
||||
|
||||
$earnedWithout = $this->noCatRepository->listIncome($this->start, $this->end, $this->accounts);
|
||||
$spentWithout = $this->noCatRepository->listExpenses($this->start, $this->end, $this->accounts);
|
||||
$earnedWithout = $this->noCatRepository->listIncome($this->start, $this->end, $this->accounts);
|
||||
$spentWithout = $this->noCatRepository->listExpenses($this->start, $this->end, $this->accounts);
|
||||
|
||||
$this->report = [
|
||||
$this->report = [
|
||||
'categories' => [],
|
||||
'sums' => [],
|
||||
];
|
||||
@@ -141,7 +141,7 @@ class CategoryReportGenerator
|
||||
|
||||
private function processCategoryRow(int $currencyId, array $currencyRow, int $categoryId, array $categoryRow): void
|
||||
{
|
||||
$key = sprintf('%s-%s', $currencyId, $categoryId);
|
||||
$key = sprintf('%s-%s', $currencyId, $categoryId);
|
||||
$this->report['categories'][$key] ??= [
|
||||
'id' => $categoryId,
|
||||
'title' => $categoryRow['name'],
|
||||
@@ -157,9 +157,9 @@ class CategoryReportGenerator
|
||||
// loop journals:
|
||||
foreach ($categoryRow['transaction_journals'] as $journal) {
|
||||
// sum of sums
|
||||
$this->report['sums'][$currencyId]['sum'] = bcadd($this->report['sums'][$currencyId]['sum'], $journal['amount']);
|
||||
$this->report['sums'][$currencyId]['sum'] = bcadd($this->report['sums'][$currencyId]['sum'], $journal['amount']);
|
||||
// sum of spent:
|
||||
$this->report['sums'][$currencyId]['spent'] = -1 === bccomp($journal['amount'], '0') ? bcadd(
|
||||
$this->report['sums'][$currencyId]['spent'] = -1 === bccomp($journal['amount'], '0') ? bcadd(
|
||||
$this->report['sums'][$currencyId]['spent'],
|
||||
$journal['amount']
|
||||
) : $this->report['sums'][$currencyId]['spent'];
|
||||
@@ -170,14 +170,14 @@ class CategoryReportGenerator
|
||||
) : $this->report['sums'][$currencyId]['earned'];
|
||||
|
||||
// sum of category
|
||||
$this->report['categories'][$key]['sum'] = bcadd($this->report['categories'][$key]['sum'], $journal['amount']);
|
||||
$this->report['categories'][$key]['sum'] = bcadd($this->report['categories'][$key]['sum'], $journal['amount']);
|
||||
// total spent in category
|
||||
$this->report['categories'][$key]['spent'] = -1 === bccomp($journal['amount'], '0') ? bcadd(
|
||||
$this->report['categories'][$key]['spent'] = -1 === bccomp($journal['amount'], '0') ? bcadd(
|
||||
$this->report['categories'][$key]['spent'],
|
||||
$journal['amount']
|
||||
) : $this->report['categories'][$key]['spent'];
|
||||
// total earned in category
|
||||
$this->report['categories'][$key]['earned'] = 1 === bccomp($journal['amount'], '0') ? bcadd(
|
||||
$this->report['categories'][$key]['earned'] = 1 === bccomp($journal['amount'], '0') ? bcadd(
|
||||
$this->report['categories'][$key]['earned'],
|
||||
$journal['amount']
|
||||
) : $this->report['categories'][$key]['earned'];
|
||||
|
||||
@@ -82,8 +82,8 @@ trait CalculateRangeOccurrences
|
||||
*/
|
||||
protected function getNdomInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
|
||||
{
|
||||
$return = [];
|
||||
$attempts = 0;
|
||||
$return = [];
|
||||
$attempts = 0;
|
||||
$start->startOfMonth();
|
||||
// this feels a bit like a cop out but why reinvent the wheel?
|
||||
$counters = [1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth'];
|
||||
@@ -108,12 +108,12 @@ trait CalculateRangeOccurrences
|
||||
*/
|
||||
protected function getWeeklyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
|
||||
{
|
||||
$return = [];
|
||||
$attempts = 0;
|
||||
$return = [];
|
||||
$attempts = 0;
|
||||
app('log')->debug('Rep is weekly.');
|
||||
// monday = 1
|
||||
// sunday = 7
|
||||
$dayOfWeek = (int)$moment;
|
||||
$dayOfWeek = (int)$moment;
|
||||
app('log')->debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $start->dayOfWeekIso));
|
||||
if ($start->dayOfWeekIso > $dayOfWeek) {
|
||||
// day has already passed this week, add one week:
|
||||
@@ -154,8 +154,8 @@ trait CalculateRangeOccurrences
|
||||
}
|
||||
|
||||
// is $date between $start and $end?
|
||||
$obj = clone $date;
|
||||
$count = 0;
|
||||
$obj = clone $date;
|
||||
$count = 0;
|
||||
while ($obj <= $end && $obj >= $start && $count < 10) {
|
||||
if (0 === $attempts % $skipMod) {
|
||||
$return[] = clone $obj;
|
||||
|
||||
@@ -89,10 +89,10 @@ trait CalculateXOccurrences
|
||||
*/
|
||||
protected function getXNDomOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
|
||||
{
|
||||
$return = [];
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$mutator = clone $date;
|
||||
$return = [];
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$mutator = clone $date;
|
||||
$mutator->addDay(); // always assume today has passed.
|
||||
$mutator->startOfMonth();
|
||||
// this feels a bit like a cop out but why reinvent the wheel?
|
||||
@@ -120,14 +120,14 @@ trait CalculateXOccurrences
|
||||
*/
|
||||
protected function getXWeeklyOccurrences(Carbon $date, int $count, int $skipMod, string $moment): array
|
||||
{
|
||||
$return = [];
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$mutator = clone $date;
|
||||
$return = [];
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$mutator = clone $date;
|
||||
// monday = 1
|
||||
// sunday = 7
|
||||
$mutator->addDay(); // always assume today has passed.
|
||||
$dayOfWeek = (int)$moment;
|
||||
$dayOfWeek = (int)$moment;
|
||||
if ($mutator->dayOfWeekIso > $dayOfWeek) {
|
||||
// day has already passed this week, add one week:
|
||||
$mutator->addWeek();
|
||||
@@ -164,7 +164,7 @@ trait CalculateXOccurrences
|
||||
if ($mutator > $date) {
|
||||
$date->addYear();
|
||||
}
|
||||
$obj = clone $date;
|
||||
$obj = clone $date;
|
||||
while ($total < $count) {
|
||||
if (0 === $attempts % $skipMod) {
|
||||
$return[] = clone $obj;
|
||||
|
||||
@@ -84,7 +84,7 @@ trait CalculateXOccurrencesSince
|
||||
++$total;
|
||||
}
|
||||
++$attempts;
|
||||
$mutator = $mutator->endOfMonth()->addDay();
|
||||
$mutator = $mutator->endOfMonth()->addDay();
|
||||
app('log')->debug(sprintf('Mutator is now %s', $mutator->format('Y-m-d')));
|
||||
}
|
||||
|
||||
@@ -100,10 +100,10 @@ trait CalculateXOccurrencesSince
|
||||
protected function getXNDomOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
$return = [];
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$mutator = clone $date;
|
||||
$return = [];
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$mutator = clone $date;
|
||||
$mutator->addDay(); // always assume today has passed.
|
||||
$mutator->startOfMonth();
|
||||
// this feels a bit like a cop out but why reinvent the wheel?
|
||||
@@ -134,15 +134,15 @@ trait CalculateXOccurrencesSince
|
||||
protected function getXWeeklyOccurrencesSince(Carbon $date, Carbon $afterDate, int $count, int $skipMod, string $moment): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
$return = [];
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$mutator = clone $date;
|
||||
$return = [];
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
$mutator = clone $date;
|
||||
// monday = 1
|
||||
// sunday = 7
|
||||
// Removed assumption today has passed, see issue https://github.com/firefly-iii/firefly-iii/issues/4798
|
||||
// $mutator->addDay(); // always assume today has passed.
|
||||
$dayOfWeek = (int)$moment;
|
||||
$dayOfWeek = (int)$moment;
|
||||
if ($mutator->dayOfWeekIso > $dayOfWeek) {
|
||||
// day has already passed this week, add one week:
|
||||
$mutator->addWeek();
|
||||
@@ -186,7 +186,7 @@ trait CalculateXOccurrencesSince
|
||||
$date->addYear();
|
||||
app('log')->debug(sprintf('Date is now %s', $date->format('Y-m-d')));
|
||||
}
|
||||
$obj = clone $date;
|
||||
$obj = clone $date;
|
||||
while ($total < $count) {
|
||||
app('log')->debug(sprintf('total (%d) < count (%d) so go.', $total, $count));
|
||||
app('log')->debug(sprintf('attempts (%d) %% skipmod (%d) === %d', $attempts, $skipMod, $attempts % $skipMod));
|
||||
|
||||
@@ -44,7 +44,7 @@ trait FiltersWeekends
|
||||
|
||||
return $dates;
|
||||
}
|
||||
$return = [];
|
||||
$return = [];
|
||||
|
||||
/** @var Carbon $date */
|
||||
foreach ($dates as $date) {
|
||||
@@ -58,7 +58,7 @@ trait FiltersWeekends
|
||||
|
||||
// is weekend and must set back to Friday?
|
||||
if (RecurrenceRepetition::WEEKEND_TO_FRIDAY === $repetition->weekend) {
|
||||
$clone = clone $date;
|
||||
$clone = clone $date;
|
||||
$clone->addDays(5 - $date->dayOfWeekIso);
|
||||
app('log')->debug(
|
||||
sprintf('Date is %s, and this is in the weekend, so corrected to %s (Friday).', $date->format('D d M Y'), $clone->format('D d M Y'))
|
||||
@@ -70,7 +70,7 @@ trait FiltersWeekends
|
||||
|
||||
// postpone to Monday?
|
||||
if (RecurrenceRepetition::WEEKEND_TO_MONDAY === $repetition->weekend) {
|
||||
$clone = clone $date;
|
||||
$clone = clone $date;
|
||||
$clone->addDays(8 - $date->dayOfWeekIso);
|
||||
app('log')->debug(
|
||||
sprintf('Date is %s, and this is in the weekend, so corrected to %s (Monday).', $date->format('D d M Y'), $clone->format('D d M Y'))
|
||||
|
||||
@@ -57,7 +57,7 @@ trait UserGroupTrait
|
||||
public function setUser(null|Authenticatable|User $user): void
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$this->user = $user;
|
||||
$this->user = $user;
|
||||
if (null === $user->userGroup) {
|
||||
throw new FireflyException(sprintf('User #%d has no user group.', $user->id));
|
||||
}
|
||||
@@ -70,7 +70,7 @@ trait UserGroupTrait
|
||||
*/
|
||||
public function setUserGroupById(int $userGroupId): void
|
||||
{
|
||||
$memberships = GroupMembership::where('user_id', $this->user->id)
|
||||
$memberships = GroupMembership::where('user_id', $this->user->id)
|
||||
->where('user_group_id', $userGroupId)
|
||||
->count()
|
||||
;
|
||||
@@ -79,7 +79,7 @@ trait UserGroupTrait
|
||||
}
|
||||
|
||||
/** @var null|UserGroup $userGroup */
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
if (null === $userGroup) {
|
||||
throw new FireflyException(sprintf('Cannot find administration for user #%d', $this->user->id));
|
||||
}
|
||||
|
||||
@@ -78,12 +78,12 @@ trait AppendsLocationData
|
||||
$data['latitude'] = null;
|
||||
$data['zoom_level'] = null;
|
||||
|
||||
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
|
||||
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
||||
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
||||
$isValidPOST = $this->isValidPost($prefix);
|
||||
$isValidPUT = $this->isValidPUT($prefix);
|
||||
$isValidEmptyPUT = $this->isValidEmptyPUT($prefix);
|
||||
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
|
||||
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
||||
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
||||
$isValidPOST = $this->isValidPost($prefix);
|
||||
$isValidPUT = $this->isValidPUT($prefix);
|
||||
$isValidEmptyPUT = $this->isValidEmptyPUT($prefix);
|
||||
|
||||
// for a POST (store), all fields must be present and not NULL.
|
||||
if ($isValidPOST) {
|
||||
|
||||
@@ -39,7 +39,7 @@ trait ChecksLogin
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
// Only allow logged-in users
|
||||
$check = auth()->check();
|
||||
$check = auth()->check();
|
||||
if (!$check) {
|
||||
return false;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ trait ChecksLogin
|
||||
public function getUserGroup(): ?UserGroup
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
app('log')->debug('Now in getUserGroup()');
|
||||
|
||||
/** @var null|UserGroup $userGroup */
|
||||
@@ -89,7 +89,7 @@ trait ChecksLogin
|
||||
app('log')->debug(sprintf('Request class has no user_group_id parameter, grab default from user (group #%d).', $user->user_group_id));
|
||||
$userGroupId = (int)$user->user_group_id;
|
||||
}
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
if (null === $userGroup) {
|
||||
app('log')->error(sprintf('Request class has user_group_id (#%d), but group does not exist.', $userGroupId));
|
||||
|
||||
|
||||
@@ -35,16 +35,16 @@ use Illuminate\Support\Collection;
|
||||
class AccountSearch implements GenericSearchInterface
|
||||
{
|
||||
/** @var string */
|
||||
public const string SEARCH_ALL = 'all';
|
||||
public const string SEARCH_ALL = 'all';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_IBAN = 'iban';
|
||||
public const string SEARCH_IBAN = 'iban';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_ID = 'id';
|
||||
public const string SEARCH_ID = 'id';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_NAME = 'name';
|
||||
public const string SEARCH_NAME = 'name';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_NUMBER = 'number';
|
||||
|
||||
@@ -172,7 +172,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$operator = substr($operator, 1);
|
||||
}
|
||||
|
||||
$config = config(sprintf('search.operators.%s', $operator));
|
||||
$config = config(sprintf('search.operators.%s', $operator));
|
||||
if (null === $config) {
|
||||
throw new FireflyException(sprintf('No configuration for search operator "%s"', $operator));
|
||||
}
|
||||
@@ -274,7 +274,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case Emoticon::class:
|
||||
case Emoji::class:
|
||||
case Mention::class:
|
||||
$allWords = (string) $searchNode->getValue();
|
||||
$allWords = (string) $searchNode->getValue();
|
||||
app('log')->debug(sprintf('Add words "%s" to search string, because Node class is "%s"', $allWords, $class));
|
||||
$this->words[] = $allWords;
|
||||
|
||||
@@ -285,10 +285,10 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
/** @var Field $searchNode */
|
||||
// used to search for x:y
|
||||
$operator = strtolower($searchNode->getValue());
|
||||
$value = $searchNode->getNode()->getValue();
|
||||
$prohibited = BoolOperator::PROHIBITED === $searchNode->getBoolOperator();
|
||||
$context = config(sprintf('search.operators.%s.needs_context', $operator));
|
||||
$operator = strtolower($searchNode->getValue());
|
||||
$value = $searchNode->getNode()->getValue();
|
||||
$prohibited = BoolOperator::PROHIBITED === $searchNode->getBoolOperator();
|
||||
$context = config(sprintf('search.operators.%s.needs_context', $operator));
|
||||
|
||||
// is an operator that needs no context, and value is false, then prohibited = true.
|
||||
if ('false' === $value && in_array($operator, $this->validOperators, true) && false === $context && !$prohibited) {
|
||||
@@ -518,7 +518,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'source_account_id':
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->setSourceAccounts(new Collection([$account]));
|
||||
}
|
||||
@@ -530,7 +530,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-source_account_id':
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->excludeSourceAccounts(new Collection([$account]));
|
||||
}
|
||||
@@ -542,25 +542,25 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'journal_id':
|
||||
$parts = explode(',', $value);
|
||||
$parts = explode(',', $value);
|
||||
$this->collector->setJournalIds($parts);
|
||||
|
||||
break;
|
||||
|
||||
case '-journal_id':
|
||||
$parts = explode(',', $value);
|
||||
$parts = explode(',', $value);
|
||||
$this->collector->excludeJournalIds($parts);
|
||||
|
||||
break;
|
||||
|
||||
case 'id':
|
||||
$parts = explode(',', $value);
|
||||
$parts = explode(',', $value);
|
||||
$this->collector->setIds($parts);
|
||||
|
||||
break;
|
||||
|
||||
case '-id':
|
||||
$parts = explode(',', $value);
|
||||
$parts = explode(',', $value);
|
||||
$this->collector->excludeIds($parts);
|
||||
|
||||
break;
|
||||
@@ -646,7 +646,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'destination_account_id':
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->setDestinationAccounts(new Collection([$account]));
|
||||
}
|
||||
@@ -657,7 +657,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-destination_account_id':
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
$account = $this->accountRepository->find((int) $value);
|
||||
if (null !== $account) {
|
||||
$this->collector->excludeDestinationAccounts(new Collection([$account]));
|
||||
}
|
||||
@@ -668,8 +668,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'account_id':
|
||||
$parts = explode(',', $value);
|
||||
$collection = new Collection();
|
||||
$parts = explode(',', $value);
|
||||
$collection = new Collection();
|
||||
foreach ($parts as $accountId) {
|
||||
$account = $this->accountRepository->find((int) $accountId);
|
||||
if (null !== $account) {
|
||||
@@ -686,8 +686,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-account_id':
|
||||
$parts = explode(',', $value);
|
||||
$collection = new Collection();
|
||||
$parts = explode(',', $value);
|
||||
$collection = new Collection();
|
||||
foreach ($parts as $accountId) {
|
||||
$account = $this->accountRepository->find((int) $accountId);
|
||||
if (null !== $account) {
|
||||
@@ -707,37 +707,37 @@ class OperatorQuerySearch implements SearchInterface
|
||||
// cash account
|
||||
//
|
||||
case 'source_is_cash':
|
||||
$account = $this->getCashAccount();
|
||||
$account = $this->getCashAccount();
|
||||
$this->collector->setSourceAccounts(new Collection([$account]));
|
||||
|
||||
break;
|
||||
|
||||
case '-source_is_cash':
|
||||
$account = $this->getCashAccount();
|
||||
$account = $this->getCashAccount();
|
||||
$this->collector->excludeSourceAccounts(new Collection([$account]));
|
||||
|
||||
break;
|
||||
|
||||
case 'destination_is_cash':
|
||||
$account = $this->getCashAccount();
|
||||
$account = $this->getCashAccount();
|
||||
$this->collector->setDestinationAccounts(new Collection([$account]));
|
||||
|
||||
break;
|
||||
|
||||
case '-destination_is_cash':
|
||||
$account = $this->getCashAccount();
|
||||
$account = $this->getCashAccount();
|
||||
$this->collector->excludeDestinationAccounts(new Collection([$account]));
|
||||
|
||||
break;
|
||||
|
||||
case 'account_is_cash':
|
||||
$account = $this->getCashAccount();
|
||||
$account = $this->getCashAccount();
|
||||
$this->collector->setAccounts(new Collection([$account]));
|
||||
|
||||
break;
|
||||
|
||||
case '-account_is_cash':
|
||||
$account = $this->getCashAccount();
|
||||
$account = $this->getCashAccount();
|
||||
$this->collector->excludeAccounts(new Collection([$account]));
|
||||
|
||||
break;
|
||||
@@ -766,7 +766,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'description_contains':
|
||||
$this->words[] = $value;
|
||||
$this->words[] = $value;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -789,7 +789,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
// currency
|
||||
//
|
||||
case 'currency_is':
|
||||
$currency = $this->findCurrency($value);
|
||||
$currency = $this->findCurrency($value);
|
||||
if (null !== $currency) {
|
||||
$this->collector->setCurrency($currency);
|
||||
}
|
||||
@@ -800,7 +800,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-currency_is':
|
||||
$currency = $this->findCurrency($value);
|
||||
$currency = $this->findCurrency($value);
|
||||
if (null !== $currency) {
|
||||
$this->collector->excludeCurrency($currency);
|
||||
}
|
||||
@@ -811,7 +811,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'foreign_currency_is':
|
||||
$currency = $this->findCurrency($value);
|
||||
$currency = $this->findCurrency($value);
|
||||
if (null !== $currency) {
|
||||
$this->collector->setForeignCurrency($currency);
|
||||
}
|
||||
@@ -822,7 +822,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-foreign_currency_is':
|
||||
$currency = $this->findCurrency($value);
|
||||
$currency = $this->findCurrency($value);
|
||||
if (null !== $currency) {
|
||||
$this->collector->excludeForeignCurrency($currency);
|
||||
}
|
||||
@@ -864,7 +864,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'category_is':
|
||||
$category = $this->categoryRepository->findByName($value);
|
||||
$category = $this->categoryRepository->findByName($value);
|
||||
if (null !== $category) {
|
||||
$this->collector->setCategory($category);
|
||||
|
||||
@@ -875,7 +875,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-category_is':
|
||||
$category = $this->categoryRepository->findByName($value);
|
||||
$category = $this->categoryRepository->findByName($value);
|
||||
if (null !== $category) {
|
||||
$this->collector->excludeCategory($category);
|
||||
|
||||
@@ -885,7 +885,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'category_ends':
|
||||
$result = $this->categoryRepository->categoryEndsWith($value, 1337);
|
||||
$result = $this->categoryRepository->categoryEndsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setCategories($result);
|
||||
}
|
||||
@@ -896,7 +896,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-category_ends':
|
||||
$result = $this->categoryRepository->categoryEndsWith($value, 1337);
|
||||
$result = $this->categoryRepository->categoryEndsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeCategories($result);
|
||||
}
|
||||
@@ -907,7 +907,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'category_starts':
|
||||
$result = $this->categoryRepository->categoryStartsWith($value, 1337);
|
||||
$result = $this->categoryRepository->categoryStartsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setCategories($result);
|
||||
}
|
||||
@@ -918,7 +918,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-category_starts':
|
||||
$result = $this->categoryRepository->categoryStartsWith($value, 1337);
|
||||
$result = $this->categoryRepository->categoryStartsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeCategories($result);
|
||||
}
|
||||
@@ -929,7 +929,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'category_contains':
|
||||
$result = $this->categoryRepository->searchCategory($value, 1337);
|
||||
$result = $this->categoryRepository->searchCategory($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setCategories($result);
|
||||
}
|
||||
@@ -940,7 +940,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-category_contains':
|
||||
$result = $this->categoryRepository->searchCategory($value, 1337);
|
||||
$result = $this->categoryRepository->searchCategory($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeCategories($result);
|
||||
}
|
||||
@@ -966,7 +966,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'budget_contains':
|
||||
$result = $this->budgetRepository->searchBudget($value, 1337);
|
||||
$result = $this->budgetRepository->searchBudget($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setBudgets($result);
|
||||
}
|
||||
@@ -977,7 +977,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-budget_contains':
|
||||
$result = $this->budgetRepository->searchBudget($value, 1337);
|
||||
$result = $this->budgetRepository->searchBudget($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeBudgets($result);
|
||||
}
|
||||
@@ -988,7 +988,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'budget_is':
|
||||
$budget = $this->budgetRepository->findByName($value);
|
||||
$budget = $this->budgetRepository->findByName($value);
|
||||
if (null !== $budget) {
|
||||
$this->collector->setBudget($budget);
|
||||
|
||||
@@ -999,7 +999,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-budget_is':
|
||||
$budget = $this->budgetRepository->findByName($value);
|
||||
$budget = $this->budgetRepository->findByName($value);
|
||||
if (null !== $budget) {
|
||||
$this->collector->excludeBudget($budget);
|
||||
|
||||
@@ -1010,7 +1010,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'budget_ends':
|
||||
$result = $this->budgetRepository->budgetEndsWith($value, 1337);
|
||||
$result = $this->budgetRepository->budgetEndsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setBudgets($result);
|
||||
}
|
||||
@@ -1021,7 +1021,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-budget_ends':
|
||||
$result = $this->budgetRepository->budgetEndsWith($value, 1337);
|
||||
$result = $this->budgetRepository->budgetEndsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeBudgets($result);
|
||||
}
|
||||
@@ -1032,7 +1032,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'budget_starts':
|
||||
$result = $this->budgetRepository->budgetStartsWith($value, 1337);
|
||||
$result = $this->budgetRepository->budgetStartsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setBudgets($result);
|
||||
}
|
||||
@@ -1043,7 +1043,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-budget_starts':
|
||||
$result = $this->budgetRepository->budgetStartsWith($value, 1337);
|
||||
$result = $this->budgetRepository->budgetStartsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeBudgets($result);
|
||||
}
|
||||
@@ -1069,7 +1069,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'bill_contains':
|
||||
$result = $this->billRepository->searchBill($value, 1337);
|
||||
$result = $this->billRepository->searchBill($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setBills($result);
|
||||
|
||||
@@ -1080,7 +1080,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-bill_contains':
|
||||
$result = $this->billRepository->searchBill($value, 1337);
|
||||
$result = $this->billRepository->searchBill($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeBills($result);
|
||||
|
||||
@@ -1091,7 +1091,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'bill_is':
|
||||
$bill = $this->billRepository->findByName($value);
|
||||
$bill = $this->billRepository->findByName($value);
|
||||
if (null !== $bill) {
|
||||
$this->collector->setBill($bill);
|
||||
|
||||
@@ -1102,7 +1102,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-bill_is':
|
||||
$bill = $this->billRepository->findByName($value);
|
||||
$bill = $this->billRepository->findByName($value);
|
||||
if (null !== $bill) {
|
||||
$this->collector->excludeBills(new Collection([$bill]));
|
||||
|
||||
@@ -1113,7 +1113,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'bill_ends':
|
||||
$result = $this->billRepository->billEndsWith($value, 1337);
|
||||
$result = $this->billRepository->billEndsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setBills($result);
|
||||
}
|
||||
@@ -1124,7 +1124,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-bill_ends':
|
||||
$result = $this->billRepository->billEndsWith($value, 1337);
|
||||
$result = $this->billRepository->billEndsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeBills($result);
|
||||
}
|
||||
@@ -1135,7 +1135,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'bill_starts':
|
||||
$result = $this->billRepository->billStartsWith($value, 1337);
|
||||
$result = $this->billRepository->billStartsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->setBills($result);
|
||||
}
|
||||
@@ -1146,7 +1146,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-bill_starts':
|
||||
$result = $this->billRepository->billStartsWith($value, 1337);
|
||||
$result = $this->billRepository->billStartsWith($value, 1337);
|
||||
if ($result->count() > 0) {
|
||||
$this->collector->excludeBills($result);
|
||||
}
|
||||
@@ -1173,7 +1173,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
case '-tag_is_not':
|
||||
case 'tag_is':
|
||||
$result = $this->tagRepository->findByTag($value);
|
||||
$result = $this->tagRepository->findByTag($value);
|
||||
if (null !== $result) {
|
||||
$this->includeTags[] = $result->id;
|
||||
$this->includeTags = array_unique($this->includeTags);
|
||||
@@ -1187,7 +1187,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'tag_contains':
|
||||
$tags = $this->tagRepository->searchTag($value);
|
||||
$tags = $this->tagRepository->searchTag($value);
|
||||
if (0 === $tags->count()) {
|
||||
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
|
||||
$this->collector->findNothing();
|
||||
@@ -1200,7 +1200,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'tag_starts':
|
||||
$tags = $this->tagRepository->tagStartsWith($value);
|
||||
$tags = $this->tagRepository->tagStartsWith($value);
|
||||
if (0 === $tags->count()) {
|
||||
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
|
||||
$this->collector->findNothing();
|
||||
@@ -1213,7 +1213,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-tag_starts':
|
||||
$tags = $this->tagRepository->tagStartsWith($value);
|
||||
$tags = $this->tagRepository->tagStartsWith($value);
|
||||
if (0 === $tags->count()) {
|
||||
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
|
||||
$this->collector->findNothing();
|
||||
@@ -1226,7 +1226,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case 'tag_ends':
|
||||
$tags = $this->tagRepository->tagEndsWith($value);
|
||||
$tags = $this->tagRepository->tagEndsWith($value);
|
||||
if (0 === $tags->count()) {
|
||||
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
|
||||
$this->collector->findNothing();
|
||||
@@ -1239,7 +1239,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-tag_ends':
|
||||
$tags = $this->tagRepository->tagEndsWith($value);
|
||||
$tags = $this->tagRepository->tagEndsWith($value);
|
||||
if (0 === $tags->count()) {
|
||||
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
|
||||
$this->collector->findNothing();
|
||||
@@ -1252,7 +1252,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
break;
|
||||
|
||||
case '-tag_contains':
|
||||
$tags = $this->tagRepository->searchTag($value)->keyBy('id');
|
||||
$tags = $this->tagRepository->searchTag($value)->keyBy('id');
|
||||
|
||||
if (0 === $tags->count()) {
|
||||
app('log')->info(sprintf('No valid tags in "%s"-operator, so search will not return ANY results.', $operator));
|
||||
@@ -1267,7 +1267,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
case '-tag_is':
|
||||
case 'tag_is_not':
|
||||
$result = $this->tagRepository->findByTag($value);
|
||||
$result = $this->tagRepository->findByTag($value);
|
||||
if (null !== $result) {
|
||||
$this->excludeTags[] = $result->id;
|
||||
$this->excludeTags = array_unique($this->excludeTags);
|
||||
@@ -1346,8 +1346,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'amount_is':
|
||||
// strip comma's, make dots.
|
||||
app('log')->debug(sprintf('Original value "%s"', $value));
|
||||
$value = str_replace(',', '.', $value);
|
||||
$amount = app('steam')->positive($value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
$amount = app('steam')->positive($value);
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
|
||||
$this->collector->amountIs($amount);
|
||||
|
||||
@@ -1356,8 +1356,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case '-amount_is':
|
||||
// strip comma's, make dots.
|
||||
app('log')->debug(sprintf('Original value "%s"', $value));
|
||||
$value = str_replace(',', '.', $value);
|
||||
$amount = app('steam')->positive($value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
$amount = app('steam')->positive($value);
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
|
||||
$this->collector->amountIsNot($amount);
|
||||
|
||||
@@ -1365,9 +1365,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
case 'foreign_amount_is':
|
||||
// strip comma's, make dots.
|
||||
$value = str_replace(',', '.', $value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
|
||||
$amount = app('steam')->positive($value);
|
||||
$amount = app('steam')->positive($value);
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
|
||||
$this->collector->foreignAmountIs($amount);
|
||||
|
||||
@@ -1375,9 +1375,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
case '-foreign_amount_is':
|
||||
// strip comma's, make dots.
|
||||
$value = str_replace(',', '.', $value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
|
||||
$amount = app('steam')->positive($value);
|
||||
$amount = app('steam')->positive($value);
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
|
||||
$this->collector->foreignAmountIsNot($amount);
|
||||
|
||||
@@ -1386,9 +1386,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case '-amount_more':
|
||||
case 'amount_less':
|
||||
// strip comma's, make dots.
|
||||
$value = str_replace(',', '.', $value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
|
||||
$amount = app('steam')->positive($value);
|
||||
$amount = app('steam')->positive($value);
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
|
||||
$this->collector->amountLess($amount);
|
||||
|
||||
@@ -1397,9 +1397,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case '-foreign_amount_more':
|
||||
case 'foreign_amount_less':
|
||||
// strip comma's, make dots.
|
||||
$value = str_replace(',', '.', $value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
|
||||
$amount = app('steam')->positive($value);
|
||||
$amount = app('steam')->positive($value);
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
|
||||
$this->collector->foreignAmountLess($amount);
|
||||
|
||||
@@ -1409,8 +1409,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'amount_more':
|
||||
app('log')->debug(sprintf('Now handling operator "%s"', $operator));
|
||||
// strip comma's, make dots.
|
||||
$value = str_replace(',', '.', $value);
|
||||
$amount = app('steam')->positive($value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
$amount = app('steam')->positive($value);
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
|
||||
$this->collector->amountMore($amount);
|
||||
|
||||
@@ -1420,8 +1420,8 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'foreign_amount_more':
|
||||
app('log')->debug(sprintf('Now handling operator "%s"', $operator));
|
||||
// strip comma's, make dots.
|
||||
$value = str_replace(',', '.', $value);
|
||||
$amount = app('steam')->positive($value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
$amount = app('steam')->positive($value);
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));
|
||||
$this->collector->foreignAmountMore($amount);
|
||||
|
||||
@@ -1447,147 +1447,147 @@ class OperatorQuerySearch implements SearchInterface
|
||||
//
|
||||
case '-date_on':
|
||||
case 'date_on':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactDateParams($range, $prohibited);
|
||||
|
||||
return false;
|
||||
|
||||
case 'date_before':
|
||||
case '-date_after':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setDateBeforeParams($range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'date_after':
|
||||
case '-date_before':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setDateAfterParams($range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'interest_date_on':
|
||||
case '-interest_date_on':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactMetaDateParams('interest_date', $range, $prohibited);
|
||||
|
||||
return false;
|
||||
|
||||
case 'interest_date_before':
|
||||
case '-interest_date_after':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateBeforeParams('interest_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'interest_date_after':
|
||||
case '-interest_date_before':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateAfterParams('interest_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'book_date_on':
|
||||
case '-book_date_on':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactMetaDateParams('book_date', $range, $prohibited);
|
||||
|
||||
return false;
|
||||
|
||||
case 'book_date_before':
|
||||
case '-book_date_after':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateBeforeParams('book_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'book_date_after':
|
||||
case '-book_date_before':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateAfterParams('book_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'process_date_on':
|
||||
case '-process_date_on':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactMetaDateParams('process_date', $range, $prohibited);
|
||||
|
||||
return false;
|
||||
|
||||
case 'process_date_before':
|
||||
case '-process_date_after':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateBeforeParams('process_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'process_date_after':
|
||||
case '-process_date_before':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateAfterParams('process_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'due_date_on':
|
||||
case '-due_date_on':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactMetaDateParams('due_date', $range, $prohibited);
|
||||
|
||||
return false;
|
||||
|
||||
case 'due_date_before':
|
||||
case '-due_date_after':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateBeforeParams('due_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'due_date_after':
|
||||
case '-due_date_before':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateAfterParams('due_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'payment_date_on':
|
||||
case '-payment_date_on':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactMetaDateParams('payment_date', $range, $prohibited);
|
||||
|
||||
return false;
|
||||
|
||||
case 'payment_date_before':
|
||||
case '-payment_date_after':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateBeforeParams('payment_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'payment_date_after':
|
||||
case '-payment_date_before':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateAfterParams('payment_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'invoice_date_on':
|
||||
case '-invoice_date_on':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactMetaDateParams('invoice_date', $range, $prohibited);
|
||||
|
||||
return false;
|
||||
|
||||
case 'invoice_date_before':
|
||||
case '-invoice_date_after':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateBeforeParams('invoice_date', $range);
|
||||
|
||||
return false;
|
||||
|
||||
case 'invoice_date_after':
|
||||
case '-invoice_date_before':
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setMetaDateAfterParams('invoice_date', $range);
|
||||
|
||||
return false;
|
||||
@@ -1595,7 +1595,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'created_at_on':
|
||||
case '-created_at_on':
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactObjectDateParams('created_at', $range, $prohibited);
|
||||
|
||||
return false;
|
||||
@@ -1603,7 +1603,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'created_at_before':
|
||||
case '-created_at_after':
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setObjectDateBeforeParams('created_at', $range);
|
||||
|
||||
return false;
|
||||
@@ -1611,7 +1611,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'created_at_after':
|
||||
case '-created_at_before':
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setObjectDateAfterParams('created_at', $range);
|
||||
|
||||
return false;
|
||||
@@ -1619,7 +1619,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'updated_at_on':
|
||||
case '-updated_at_on':
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setExactObjectDateParams('updated_at', $range, $prohibited);
|
||||
|
||||
return false;
|
||||
@@ -1627,7 +1627,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'updated_at_before':
|
||||
case '-updated_at_after':
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setObjectDateBeforeParams('updated_at', $range);
|
||||
|
||||
return false;
|
||||
@@ -1635,7 +1635,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
case 'updated_at_after':
|
||||
case '-updated_at_before':
|
||||
app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$range = $this->parseDateRange($operator, $value);
|
||||
$this->setObjectDateAfterParams('updated_at', $range);
|
||||
|
||||
return false;
|
||||
@@ -1934,7 +1934,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
}
|
||||
// string position (default): starts with:
|
||||
$stringMethod = 'str_starts_with';
|
||||
$stringMethod = 'str_starts_with';
|
||||
|
||||
// string position: ends with:
|
||||
if (StringPosition::ENDS === $stringPosition) {
|
||||
@@ -1948,7 +1948,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
|
||||
// get accounts:
|
||||
$accounts = $this->accountRepository->searchAccount($value, $searchTypes, 1337);
|
||||
$accounts = $this->accountRepository->searchAccount($value, $searchTypes, 1337);
|
||||
if (0 === $accounts->count()) {
|
||||
app('log')->debug('Found zero accounts, search for non existing account, NO results will be returned.');
|
||||
$this->collector->findNothing();
|
||||
@@ -1956,7 +1956,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
return;
|
||||
}
|
||||
app('log')->debug(sprintf('Found %d accounts, will filter.', $accounts->count()));
|
||||
$filtered = $accounts->filter(
|
||||
$filtered = $accounts->filter(
|
||||
static function (Account $account) use ($value, $stringMethod) {
|
||||
return $stringMethod(strtolower($account->name), strtolower($value));
|
||||
}
|
||||
@@ -2011,7 +2011,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
|
||||
// string position (default): starts with:
|
||||
$stringMethod = 'str_starts_with';
|
||||
$stringMethod = 'str_starts_with';
|
||||
|
||||
// string position: ends with:
|
||||
if (StringPosition::ENDS === $stringPosition) {
|
||||
@@ -2025,7 +2025,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
|
||||
// search for accounts:
|
||||
$accounts = $this->accountRepository->searchAccountNr($value, $searchTypes, 1337);
|
||||
$accounts = $this->accountRepository->searchAccountNr($value, $searchTypes, 1337);
|
||||
if (0 === $accounts->count()) {
|
||||
app('log')->debug('Found zero accounts, search for invalid account.');
|
||||
$this->collector->findNothing();
|
||||
@@ -2035,7 +2035,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
// if found, do filter
|
||||
app('log')->debug(sprintf('Found %d accounts, will filter.', $accounts->count()));
|
||||
$filtered = $accounts->filter(
|
||||
$filtered = $accounts->filter(
|
||||
static function (Account $account) use ($value, $stringMethod) {
|
||||
// either IBAN or account number
|
||||
$ibanMatch = $stringMethod(strtolower((string) $account->iban), strtolower($value));
|
||||
|
||||
@@ -41,20 +41,20 @@ class Steam
|
||||
public function balanceIgnoreVirtual(Account $account, Carbon $date): string
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
|
||||
$currencyId = (int) $repository->getMetaValue($account, 'currency_id');
|
||||
$transactions = $account->transactions()
|
||||
$currencyId = (int) $repository->getMetaValue($account, 'currency_id');
|
||||
$transactions = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
->where('transactions.transaction_currency_id', $currencyId)
|
||||
->get(['transactions.amount'])->toArray()
|
||||
;
|
||||
$nativeBalance = $this->sumTransactions($transactions, 'amount');
|
||||
$nativeBalance = $this->sumTransactions($transactions, 'amount');
|
||||
|
||||
// get all balances in foreign currency:
|
||||
$transactions = $account->transactions()
|
||||
$transactions = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
->where('transactions.foreign_currency_id', $currencyId)
|
||||
@@ -90,7 +90,7 @@ class Steam
|
||||
*/
|
||||
public function balanceInRange(Account $account, Carbon $start, Carbon $end, ?TransactionCurrency $currency = null): array
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty('balance-in-range');
|
||||
$cache->addProperty(null !== $currency ? $currency->id : 0);
|
||||
@@ -102,22 +102,22 @@ class Steam
|
||||
|
||||
$start->subDay();
|
||||
$end->addDay();
|
||||
$balances = [];
|
||||
$formatted = $start->format('Y-m-d');
|
||||
$startBalance = $this->balance($account, $start, $currency);
|
||||
$balances = [];
|
||||
$formatted = $start->format('Y-m-d');
|
||||
$startBalance = $this->balance($account, $start, $currency);
|
||||
|
||||
$balances[$formatted] = $startBalance;
|
||||
if (null === $currency) {
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
$currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||
$currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
$currencyId = $currency->id;
|
||||
$currencyId = $currency->id;
|
||||
|
||||
$start->addDay();
|
||||
|
||||
// query!
|
||||
$set = $account->transactions()
|
||||
$set = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59'))
|
||||
@@ -137,7 +137,7 @@ class Steam
|
||||
)
|
||||
;
|
||||
|
||||
$currentBalance = $startBalance;
|
||||
$currentBalance = $startBalance;
|
||||
|
||||
/** @var Transaction $entry */
|
||||
foreach ($set as $entry) {
|
||||
@@ -173,7 +173,7 @@ class Steam
|
||||
public function balance(Account $account, Carbon $date, ?TransactionCurrency $currency = null): string
|
||||
{
|
||||
// abuse chart properties:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty('balance');
|
||||
$cache->addProperty($date);
|
||||
@@ -183,18 +183,18 @@ class Steam
|
||||
}
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
if (null === $currency) {
|
||||
$currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
// first part: get all balances in own currency:
|
||||
$transactions = $account->transactions()
|
||||
$transactions = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
->where('transactions.transaction_currency_id', $currency->id)
|
||||
->get(['transactions.amount'])->toArray()
|
||||
;
|
||||
$nativeBalance = $this->sumTransactions($transactions, 'amount');
|
||||
$nativeBalance = $this->sumTransactions($transactions, 'amount');
|
||||
// get all balances in foreign currency:
|
||||
$transactions = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
@@ -220,7 +220,7 @@ class Steam
|
||||
*/
|
||||
public function balanceInRangeConverted(Account $account, Carbon $start, Carbon $end, TransactionCurrency $native): array
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty('balance-in-range-converted');
|
||||
$cache->addProperty($native->id);
|
||||
@@ -240,13 +240,13 @@ class Steam
|
||||
|
||||
Log::debug(sprintf('Start balance on %s is %s', $formatted, $startBalance));
|
||||
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter = new ExchangeRateConverter();
|
||||
|
||||
// not sure why this is happening:
|
||||
$start->addDay();
|
||||
|
||||
// grab all transactions between start and end:
|
||||
$set = $account->transactions()
|
||||
$set = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59'))
|
||||
@@ -264,15 +264,15 @@ class Steam
|
||||
;
|
||||
|
||||
// loop the set and convert if necessary:
|
||||
$currentBalance = $startBalance;
|
||||
$currentBalance = $startBalance;
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$day = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date'], config('app.timezone'));
|
||||
$day = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date'], config('app.timezone'));
|
||||
if (false === $day) {
|
||||
$day = today(config('app.timezone'));
|
||||
}
|
||||
$format = $day->format('Y-m-d');
|
||||
$format = $day->format('Y-m-d');
|
||||
// if the transaction is in the expected currency, change nothing.
|
||||
if ((int) $transaction['transaction_currency_id'] === $native->id) {
|
||||
// change the current balance, set it to today, continue the loop.
|
||||
@@ -295,10 +295,10 @@ class Steam
|
||||
$currency = $currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
||||
$currencies[$currencyId] = $currency;
|
||||
|
||||
$rate = $converter->getCurrencyRate($currency, $native, $day);
|
||||
$convertedAmount = bcmul($transaction['amount'], $rate);
|
||||
$currentBalance = bcadd($currentBalance, $convertedAmount);
|
||||
$balances[$format] = $currentBalance;
|
||||
$rate = $converter->getCurrencyRate($currency, $native, $day);
|
||||
$convertedAmount = bcmul($transaction['amount'], $rate);
|
||||
$currentBalance = bcadd($currentBalance, $convertedAmount);
|
||||
$balances[$format] = $currentBalance;
|
||||
|
||||
Log::debug(sprintf(
|
||||
'%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',
|
||||
@@ -340,7 +340,7 @@ class Steam
|
||||
public function balanceConverted(Account $account, Carbon $date, TransactionCurrency $native): string
|
||||
{
|
||||
Log::debug(sprintf('Now in balanceConverted (%s) for account #%d, converting to %s', $date->format('Y-m-d'), $account->id, $native->code));
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty('balance');
|
||||
$cache->addProperty($date);
|
||||
@@ -361,9 +361,9 @@ class Steam
|
||||
return $this->balance($account, $date);
|
||||
}
|
||||
|
||||
$new = [];
|
||||
$existing = [];
|
||||
$new[] = $account->transactions() // 1
|
||||
$new = [];
|
||||
$existing = [];
|
||||
$new[] = $account->transactions() // 1
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
->where('transactions.transaction_currency_id', $currency->id)
|
||||
@@ -379,7 +379,7 @@ class Steam
|
||||
->get(['transactions.amount'])->toArray()
|
||||
;
|
||||
Log::debug(sprintf('%d transaction(s) in set #2', count($existing[0])));
|
||||
$new[] = $account->transactions() // 3
|
||||
$new[] = $account->transactions() // 3
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
->where('transactions.transaction_currency_id', '!=', $currency->id)
|
||||
@@ -396,7 +396,7 @@ class Steam
|
||||
->get(['transactions.foreign_amount'])->toArray()
|
||||
;
|
||||
Log::debug(sprintf('%d transactions in set #4', count($existing[1])));
|
||||
$new[] = $account->transactions()// 5
|
||||
$new[] = $account->transactions()// 5
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
->where('transactions.transaction_currency_id', $currency->id)
|
||||
@@ -405,7 +405,7 @@ class Steam
|
||||
->get(['transaction_journals.date', 'transactions.amount'])->toArray()
|
||||
;
|
||||
Log::debug(sprintf('%d transactions in set #5', count($new[2])));
|
||||
$new[] = $account->transactions()// 6
|
||||
$new[] = $account->transactions()// 6
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
->where('transactions.transaction_currency_id', '!=', $currency->id)
|
||||
@@ -416,17 +416,17 @@ class Steam
|
||||
Log::debug(sprintf('%d transactions in set #6', count($new[3])));
|
||||
|
||||
// process both sets of transactions. Of course, no need to convert set "existing".
|
||||
$balance = $this->sumTransactions($existing[0], 'amount');
|
||||
$balance = bcadd($balance, $this->sumTransactions($existing[1], 'foreign_amount'));
|
||||
$balance = $this->sumTransactions($existing[0], 'amount');
|
||||
$balance = bcadd($balance, $this->sumTransactions($existing[1], 'foreign_amount'));
|
||||
Log::debug(sprintf('Balance from set #2 and #4 is %f', $balance));
|
||||
|
||||
// need to convert the others. All sets use the "amount" value as their base (that's easy)
|
||||
// but we need to convert each transaction separately because the date difference may
|
||||
// incur huge currency changes.
|
||||
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
|
||||
$start = clone $date;
|
||||
$end = clone $date;
|
||||
$converter = new ExchangeRateConverter();
|
||||
$start = clone $date;
|
||||
$end = clone $date;
|
||||
$converter = new ExchangeRateConverter();
|
||||
foreach ($new as $set) {
|
||||
foreach ($set as $transaction) {
|
||||
$currentDate = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date']);
|
||||
@@ -443,7 +443,7 @@ class Steam
|
||||
|
||||
foreach ($new as $set) {
|
||||
foreach ($set as $transaction) {
|
||||
$currentDate = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date']);
|
||||
$currentDate = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date']);
|
||||
if (false === $currentDate) {
|
||||
$currentDate = today(config('app.timezone'));
|
||||
}
|
||||
@@ -454,9 +454,9 @@ class Steam
|
||||
}
|
||||
|
||||
// add virtual balance (also needs conversion)
|
||||
$virtual = null === $account->virtual_balance ? '0' : $account->virtual_balance;
|
||||
$virtual = $converter->convert($currency, $native, $account->created_at, $virtual);
|
||||
$balance = bcadd($balance, $virtual);
|
||||
$virtual = null === $account->virtual_balance ? '0' : $account->virtual_balance;
|
||||
$virtual = $converter->convert($currency, $native, $account->created_at, $virtual);
|
||||
$balance = bcadd($balance, $virtual);
|
||||
$converter->summarize();
|
||||
|
||||
$cache->store($balance);
|
||||
@@ -472,9 +472,9 @@ class Steam
|
||||
*/
|
||||
public function balancesByAccounts(Collection $accounts, Carbon $date): array
|
||||
{
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
// cache this property.
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($ids);
|
||||
$cache->addProperty('balances');
|
||||
$cache->addProperty($date);
|
||||
@@ -502,9 +502,9 @@ class Steam
|
||||
*/
|
||||
public function balancesByAccountsConverted(Collection $accounts, Carbon $date): array
|
||||
{
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
// cache this property.
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($ids);
|
||||
$cache->addProperty('balances-converted');
|
||||
$cache->addProperty($date);
|
||||
@@ -535,9 +535,9 @@ class Steam
|
||||
*/
|
||||
public function balancesPerCurrencyByAccounts(Collection $accounts, Carbon $date): array
|
||||
{
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
// cache this property.
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($ids);
|
||||
$cache->addProperty('balances-per-currency');
|
||||
$cache->addProperty($date);
|
||||
@@ -561,7 +561,7 @@ class Steam
|
||||
public function balancePerCurrency(Account $account, Carbon $date): array
|
||||
{
|
||||
// abuse chart properties:
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($account->id);
|
||||
$cache->addProperty('balance-per-currency');
|
||||
$cache->addProperty($date);
|
||||
@@ -688,7 +688,7 @@ class Steam
|
||||
{
|
||||
$list = [];
|
||||
|
||||
$set = auth()->user()->transactions()
|
||||
$set = auth()->user()->transactions()
|
||||
->whereIn('transactions.account_id', $accounts)
|
||||
->groupBy(['transactions.account_id', 'transaction_journals.user_id'])
|
||||
->get(['transactions.account_id', \DB::raw('MAX(transaction_journals.date) AS max_date')]) // @phpstan-ignore-line
|
||||
@@ -696,7 +696,7 @@ class Steam
|
||||
|
||||
/** @var Transaction $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'));
|
||||
$list[$entry->account_id] = $date;
|
||||
}
|
||||
@@ -771,9 +771,9 @@ class Steam
|
||||
public function getSafeUrl(string $unknownUrl, string $safeUrl): string
|
||||
{
|
||||
// Log::debug(sprintf('getSafeUrl(%s, %s)', $unknownUrl, $safeUrl));
|
||||
$returnUrl = $safeUrl;
|
||||
$unknownHost = parse_url($unknownUrl, PHP_URL_HOST);
|
||||
$safeHost = parse_url($safeUrl, PHP_URL_HOST);
|
||||
$returnUrl = $safeUrl;
|
||||
$unknownHost = parse_url($unknownUrl, PHP_URL_HOST);
|
||||
$safeHost = parse_url($safeUrl, PHP_URL_HOST);
|
||||
|
||||
if (null !== $unknownHost && $unknownHost === $safeHost) {
|
||||
$returnUrl = $unknownUrl;
|
||||
@@ -810,7 +810,7 @@ class Steam
|
||||
*/
|
||||
public function floatalize(string $value): string
|
||||
{
|
||||
$value = strtoupper($value);
|
||||
$value = strtoupper($value);
|
||||
if (!str_contains($value, 'E')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ class OAuthKeys
|
||||
|
||||
return false;
|
||||
}
|
||||
$private = storage_path('oauth-private.key');
|
||||
$public = storage_path('oauth-public.key');
|
||||
$private = storage_path('oauth-private.key');
|
||||
$public = storage_path('oauth-public.key');
|
||||
file_put_contents($private, $privateContent);
|
||||
file_put_contents($public, $publicContent);
|
||||
|
||||
|
||||
@@ -109,8 +109,8 @@ class AmountFormat extends AbstractExtension
|
||||
return new TwigFunction(
|
||||
'formatAmountBySymbol',
|
||||
static function (string $amount, string $symbol, int $decimalPlaces = null, bool $coloured = null): string {
|
||||
$decimalPlaces ??= 2;
|
||||
$coloured ??= true;
|
||||
$decimalPlaces ??= 2;
|
||||
$coloured ??= true;
|
||||
$currency = new TransactionCurrency();
|
||||
$currency->symbol = $symbol;
|
||||
$currency->decimal_places = $decimalPlaces;
|
||||
|
||||
@@ -293,7 +293,7 @@ class General extends AbstractExtension
|
||||
'activeRoutePartialObjectType',
|
||||
static function ($context): string {
|
||||
[, $route, $objectType] = func_get_args();
|
||||
$activeObjectType = $context['objectType'] ?? false;
|
||||
$activeObjectType = $context['objectType'] ?? false;
|
||||
|
||||
if ($objectType === $activeObjectType
|
||||
&& false !== stripos(
|
||||
|
||||
@@ -165,7 +165,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
$colored = false;
|
||||
}
|
||||
|
||||
$result = app('amount')->formatFlat($array['currency_symbol'], (int)$array['currency_decimal_places'], $amount, $colored);
|
||||
$result = app('amount')->formatFlat($array['currency_symbol'], (int)$array['currency_decimal_places'], $amount, $colored);
|
||||
if (TransactionType::TRANSFER === $type) {
|
||||
$result = sprintf('<span class="text-info money-transfer">%s</span>', $result);
|
||||
}
|
||||
@@ -198,9 +198,9 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
*/
|
||||
private function foreignJournalArrayAmount(array $array): string
|
||||
{
|
||||
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||
$amount = $array['foreign_amount'] ?? '0';
|
||||
$colored = true;
|
||||
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||
$amount = $array['foreign_amount'] ?? '0';
|
||||
$colored = true;
|
||||
|
||||
$sourceType = $array['source_account_type'] ?? 'invalid';
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
@@ -208,7 +208,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
if (TransactionType::TRANSFER === $type) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int)$array['foreign_currency_decimal_places'], $amount, $colored);
|
||||
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int)$array['foreign_currency_decimal_places'], $amount, $colored);
|
||||
if (TransactionType::TRANSFER === $type) {
|
||||
$result = sprintf('<span class="text-info money-transfer">%s</span>', $result);
|
||||
}
|
||||
@@ -228,12 +228,12 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
$colored = true;
|
||||
$sourceType = $first->account()->first()->accountType()->first()->type;
|
||||
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
|
||||
if (TransactionType::TRANSFER === $type) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored);
|
||||
$result = app('amount')->formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored);
|
||||
if (TransactionType::TRANSFER === $type) {
|
||||
$result = sprintf('<span class="text-info money-transfer">%s</span>', $result);
|
||||
}
|
||||
@@ -254,7 +254,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
*/
|
||||
private function foreignJournalObjectAmount(TransactionJournal $journal): string
|
||||
{
|
||||
$type = $journal->transactionType->type;
|
||||
$type = $journal->transactionType->type;
|
||||
|
||||
/** @var Transaction $first */
|
||||
$first = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
@@ -263,12 +263,12 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
$colored = true;
|
||||
$sourceType = $first->account()->first()->accountType()->first()->type;
|
||||
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
|
||||
if (TransactionType::TRANSFER === $type) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored);
|
||||
$result = app('amount')->formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored);
|
||||
if (TransactionType::TRANSFER === $type) {
|
||||
$result = sprintf('<span class="text-info money-transfer">%s</span>', $result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user