Merge pull request #7068 from firefly-iii/cleanup-comments

Cleanup comments
This commit is contained in:
James Cole
2023-02-22 18:16:02 +01:00
committed by GitHub
321 changed files with 949 additions and 1263 deletions

View File

@@ -261,6 +261,7 @@ class AccountRepository implements AccountRepositoryInterface
* @return Account
*
* @throws FireflyException
* @throws JsonException
*/
public function getCashAccount(): Account
{

View File

@@ -123,6 +123,8 @@ class AccountTasker implements AccountTaskerInterface
* @param Collection $accounts
*
* @return array
* @throws FireflyException
* @throws JsonException
*/
public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): array
{
@@ -221,6 +223,8 @@ class AccountTasker implements AccountTaskerInterface
* @param Collection $accounts
*
* @return array
* @throws FireflyException
* @throws JsonException
*/
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): array
{

View File

@@ -36,8 +36,8 @@ use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\UnableToDeleteFile;
use LogicException;
use Log;
use LogicException;
/**
* Class AttachmentRepository.

View File

@@ -188,6 +188,7 @@ class BillRepository implements BillRepositoryInterface
*
* @return Bill
* @throws FireflyException
* @throws JsonException
*/
public function store(array $data): Bill
{
@@ -911,6 +912,8 @@ class BillRepository implements BillRepositoryInterface
* @param array $data
*
* @return Bill
* @throws FireflyException
* @throws JsonException
*/
public function update(Bill $bill, array $data): Bill
{

View File

@@ -203,6 +203,61 @@ class BudgetRepository implements BudgetRepositoryInterface
return 0;
}
/**
* @inheritDoc
*/
public function budgetedInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array
{
Log::debug(sprintf('Now in budgetedInPeriod(#%d, "%s", "%s")', $budget->id, $start->format('Y-m-d'), $end->format('Y-m-d')));
$return = [];
/** @var BudgetLimitRepository $limitRepository */
$limitRepository = app(BudgetLimitRepository::class);
$limitRepository->setUser($this->user);
Log::debug(sprintf('Budget #%d: "%s"', $budget->id, $budget->name));
$limits = $limitRepository->getBudgetLimits($budget, $start, $end);
/** @var BudgetLimit $limit */
foreach ($limits as $limit) {
Log::debug(sprintf('Budget limit #%d', $limit->id));
$currency = $limit->transactionCurrency;
$return[$currency->id] = $return[$currency->id] ?? [
'id' => (string)$currency->id,
'name' => $currency->name,
'symbol' => $currency->symbol,
'code' => $currency->code,
'decimal_places' => $currency->decimal_places,
'sum' => '0',
];
// same period
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) {
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string)$limit->amount);
Log::debug(sprintf('Add full amount [1]: %s', $limit->amount));
continue;
}
// limit is inside of date range
if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) {
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string)$limit->amount);
Log::debug(sprintf('Add full amount [2]: %s', $limit->amount));
continue;
}
$total = $limit->start_date->diffInDays($limit->end_date) + 1; // include the day itself.
$days = $this->daysInOverlap($limit, $start, $end);
$amount = bcmul(bcdiv((string)$limit->amount, (string)$total), (string)$days);
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
Log::debug(
sprintf(
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',
bcdiv((string)$limit->amount, (string)$total),
$limit->amount,
$total,
$days,
$amount
)
);
}
return $return;
}
/**
* @return bool
*/
@@ -230,6 +285,8 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param array $data
*
* @return Budget
* @throws FireflyException
* @throws JsonException
*/
public function update(Budget $budget, array $data): Budget
{
@@ -662,6 +719,69 @@ class BudgetRepository implements BudgetRepositoryInterface
return $array;
}
/**
* @inheritDoc
*/
public function spentInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
$start->startOfDay();
$end->endOfDay();
// exclude specific liabilities
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
$selection = new Collection();
/** @var Account $account */
foreach ($subset as $account) {
if ('credit' === $repository->getMetaValue($account, 'liability_direction')) {
$selection->push($account);
}
}
// start collecting:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)
->setRange($start, $end)
->excludeDestinationAccounts($selection)
->setTypes([TransactionType::WITHDRAWAL])
->setBudget($budget);
$journals = $collector->getExtractedJournals();
$array = [];
foreach ($journals as $journal) {
$currencyId = (int)$journal['currency_id'];
$array[$currencyId] = $array[$currencyId] ?? [
'id' => (string)$currencyId,
'name' => $journal['currency_name'],
'symbol' => $journal['currency_symbol'],
'code' => $journal['currency_code'],
'decimal_places' => $journal['currency_decimal_places'],
'sum' => '0',
];
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
// also do foreign amount:
$foreignId = (int)$journal['foreign_currency_id'];
if (0 !== $foreignId) {
$array[$foreignId] = $array[$foreignId] ?? [
'id' => (string)$foreignId,
'name' => $journal['foreign_currency_name'],
'symbol' => $journal['foreign_currency_symbol'],
'code' => $journal['foreign_currency_code'],
'decimal_places' => $journal['foreign_currency_decimal_places'],
'sum' => '0',
];
$array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->negative($journal['foreign_amount']));
}
}
return $array;
}
/**
* @param array $data
*
@@ -754,122 +874,4 @@ class BudgetRepository implements BudgetRepositoryInterface
{
return (int)$this->user->budgets()->max('order');
}
/**
* @inheritDoc
*/
public function spentInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
$start->startOfDay();
$end->endOfDay();
// exclude specific liabilities
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
$selection = new Collection();
/** @var Account $account */
foreach ($subset as $account) {
if ('credit' === $repository->getMetaValue($account, 'liability_direction')) {
$selection->push($account);
}
}
// start collecting:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)
->setRange($start, $end)
->excludeDestinationAccounts($selection)
->setTypes([TransactionType::WITHDRAWAL])
->setBudget($budget);
$journals = $collector->getExtractedJournals();
$array = [];
foreach ($journals as $journal) {
$currencyId = (int)$journal['currency_id'];
$array[$currencyId] = $array[$currencyId] ?? [
'id' => (string)$currencyId,
'name' => $journal['currency_name'],
'symbol' => $journal['currency_symbol'],
'code' => $journal['currency_code'],
'decimal_places' => $journal['currency_decimal_places'],
'sum' => '0',
];
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
// also do foreign amount:
$foreignId = (int)$journal['foreign_currency_id'];
if (0 !== $foreignId) {
$array[$foreignId] = $array[$foreignId] ?? [
'id' => (string)$foreignId,
'name' => $journal['foreign_currency_name'],
'symbol' => $journal['foreign_currency_symbol'],
'code' => $journal['foreign_currency_code'],
'decimal_places' => $journal['foreign_currency_decimal_places'],
'sum' => '0',
];
$array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->negative($journal['foreign_amount']));
}
}
return $array;
}
/**
* @inheritDoc
*/
public function budgetedInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array
{
Log::debug(sprintf('Now in budgetedInPeriod(#%d, "%s", "%s")', $budget->id, $start->format('Y-m-d'), $end->format('Y-m-d')));
$return = [];
/** @var BudgetLimitRepository $limitRepository */
$limitRepository = app(BudgetLimitRepository::class);
$limitRepository->setUser($this->user);
Log::debug(sprintf('Budget #%d: "%s"', $budget->id, $budget->name));
$limits = $limitRepository->getBudgetLimits($budget, $start, $end);
/** @var BudgetLimit $limit */
foreach ($limits as $limit) {
Log::debug(sprintf('Budget limit #%d', $limit->id));
$currency = $limit->transactionCurrency;
$return[$currency->id] = $return[$currency->id] ?? [
'id' => (string)$currency->id,
'name' => $currency->name,
'symbol' => $currency->symbol,
'code' => $currency->code,
'decimal_places' => $currency->decimal_places,
'sum' => '0',
];
// same period
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) {
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string)$limit->amount);
Log::debug(sprintf('Add full amount [1]: %s', $limit->amount));
continue;
}
// limit is inside of date range
if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) {
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string)$limit->amount);
Log::debug(sprintf('Add full amount [2]: %s', $limit->amount));
continue;
}
$total = $limit->start_date->diffInDays($limit->end_date) + 1; // include the day itself.
$days = $this->daysInOverlap($limit, $start, $end);
$amount = bcmul(bcdiv((string)$limit->amount, (string)$total), (string)$days);
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
Log::debug(
sprintf(
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',
bcdiv((string)$limit->amount, (string)$total),
$limit->amount,
$total,
$days,
$amount
)
);
}
return $return;
}
}

View File

@@ -64,7 +64,7 @@ interface BudgetRepositoryInterface
/**
* Returns the amount that is budgeted in a period.
*
* @param Budget $budget
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
* @return array
@@ -209,10 +209,7 @@ interface BudgetRepositoryInterface
/**
* Used in the v2 API to calculate the amount of money spent in a single budget..
*
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
public function spentInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array;

View File

@@ -205,6 +205,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$this->user = $user;
}
}
/**
* @param Category $category
*/

View File

@@ -34,6 +34,7 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log;
use JsonException;
/**
* Trait ModifiesPiggyBanks
@@ -42,12 +43,6 @@ trait ModifiesPiggyBanks
{
use CreatesObjectGroups;
/**
* @param PiggyBankRepetition $repetition
* @param string $amount
*
* @return void
*/
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void
{
Log::debug(sprintf('addAmountToRepetition: %s', $amount));
@@ -61,12 +56,6 @@ trait ModifiesPiggyBanks
}
}
/**
* @param PiggyBank $piggyBank
* @param string $amount
*
* @return bool
*/
public function removeAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool
{
$repetition = $this->getRepetition($piggyBank);
@@ -109,6 +98,7 @@ trait ModifiesPiggyBanks
* @param string $amount
*
* @return bool
* @throws JsonException
*/
public function canAddAmount(PiggyBank $piggyBank, string $amount): bool
{

View File

@@ -336,12 +336,14 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
public function getPiggyBanks(): Collection
{
return $this->user // @phpstan-ignore-line (phpstan does not recognize objectGroups)
->piggyBanks()
->with(
['account',
'objectGroups']
)
->orderBy('order', 'ASC')->get();
->piggyBanks()
->with(
[
'account',
'objectGroups',
]
)
->orderBy('order', 'ASC')->get();
}
/**

View File

@@ -45,10 +45,6 @@ interface PiggyBankRepositoryInterface
*/
public function addAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool;
/**
* @param PiggyBankRepetition $repetition
* @param string $amount
*/
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void;
/**

View File

@@ -92,6 +92,21 @@ class RecurringRepository implements RecurringRepositoryInterface
return false;
}
/**
* Returns all of the user's recurring transactions.
*
* @return Collection
*/
public function get(): Collection
{
return $this->user->recurrences()
->with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions'])
->orderBy('active', 'DESC')
->orderBy('transaction_type_id', 'ASC')
->orderBy('title', 'ASC')
->get();
}
/**
* Destroy a recurring transaction.
*
@@ -126,21 +141,6 @@ class RecurringRepository implements RecurringRepositoryInterface
->get();
}
/**
* Returns all of the user's recurring transactions.
*
* @return Collection
*/
public function get(): Collection
{
return $this->user->recurrences()
->with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions'])
->orderBy('active', 'DESC')
->orderBy('transaction_type_id', 'ASC')
->orderBy('title', 'ASC')
->get();
}
/**
* @inheritDoc
*/

View File

@@ -53,6 +53,8 @@ class OperationsRepository implements OperationsRepositoryInterface
* @param Collection|null $tags
*
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $tags = null): array
{
@@ -150,6 +152,8 @@ class OperationsRepository implements OperationsRepositoryInterface
* @param Collection|null $tags
*
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $tags = null): array
{

View File

@@ -176,11 +176,11 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
$result = [];
/** @var Attachment $attachment */
foreach ($set as $attachment) {
$journalId = (int)$attachment->attachable_id;
$result[$journalId] = $result[$journalId] ?? [];
$current = $attachment->toArray();
$current['file_exists'] = true;
$current['notes'] = $repository->getNoteText($attachment);
$journalId = (int)$attachment->attachable_id;
$result[$journalId] = $result[$journalId] ?? [];
$current = $attachment->toArray();
$current['file_exists'] = true;
$current['notes'] = $repository->getNoteText($attachment);
// already determined that this attachable is a TransactionJournal.
$current['journal_title'] = $attachment->attachable->description; // @phpstan-ignore-line
$result[$journalId][] = $current;
@@ -470,6 +470,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
* @return TransactionGroup
* @throws DuplicateTransactionException
* @throws FireflyException
* @throws JsonException
*/
public function store(array $data): TransactionGroup
{
@@ -495,6 +496,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
*
* @return TransactionGroup
*
* @throws DuplicateTransactionException
* @throws FireflyException
*/
public function update(TransactionGroup $transactionGroup, array $data): TransactionGroup

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\User;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\BudgetLimit;
@@ -168,16 +167,6 @@ class UserRepository implements UserRepositoryInterface
return User::orderBy('id', 'DESC')->get(['users.*']);
}
/**
* @param int $userId
*
* @return User|null
*/
public function find(int $userId): ?User
{
return User::find($userId);
}
/**
* @param string $email
*
@@ -222,6 +211,37 @@ class UserRepository implements UserRepositoryInterface
return null;
}
/**
* @inheritDoc
* @throws FireflyException
*/
public function getRolesInGroup(User $user, int $groupId): array
{
/** @var UserGroup $group */
$group = UserGroup::find($groupId);
if (null === $group) {
throw new FireflyException(sprintf('Could not find group #%d', $groupId));
}
$memberships = $group->groupMemberships()->where('user_id', $user->id)->get();
$roles = [];
/** @var GroupMembership $membership */
foreach ($memberships as $membership) {
$role = $membership->userRole;
$roles[] = $role->title;
}
return $roles;
}
/**
* @param int $userId
*
* @return User|null
*/
public function find(int $userId): ?User
{
return User::find($userId);
}
/**
* Return basic user information.
*
@@ -467,25 +487,4 @@ class UserRepository implements UserRepositoryInterface
$invitee = InvitedUser::where('invite_code', $code)->where('expires', '>', $now->format('Y-m-d H:i:s'))->where('redeemed', 0)->first();
return null !== $invitee;
}
/**
* @inheritDoc
* @throws FireflyException
*/
public function getRolesInGroup(User $user, int $groupId): array
{
/** @var UserGroup $group */
$group = UserGroup::find($groupId);
if (null === $group) {
throw new FireflyException(sprintf('Could not find group #%d', $groupId));
}
$memberships = $group->groupMemberships()->where('user_id', $user->id)->get();
$roles = [];
/** @var GroupMembership $membership */
foreach ($memberships as $membership) {
$role = $membership->userRole;
$roles[] = $role->title;
}
return $roles;
}
}

View File

@@ -40,13 +40,6 @@ interface UserRepositoryInterface
*/
public function all(): Collection;
/**
* @param User $user
* @param int $groupId
* @return array
*/
public function getRolesInGroup(User $user, int $groupId): array;
/**
* Gives a user a role.
*
@@ -155,6 +148,13 @@ interface UserRepositoryInterface
*/
public function getRoleByUser(User $user): ?string;
/**
* @param User $user
* @param int $groupId
* @return array
*/
public function getRolesInGroup(User $user, int $groupId): array;
/**
* Return basic user information.
*