mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
chore: reformat code.
This commit is contained in:
@@ -54,21 +54,11 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $types): int
|
||||
{
|
||||
return $this->user->accounts()->accountTypeIn($types)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moved here from account CRUD.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account|null $moveTo
|
||||
* @param Account $account
|
||||
* @param Account|null $moveTo
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
@@ -86,7 +76,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
/**
|
||||
* Find account with same name OR same IBAN or both, but not the same type or ID.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -117,16 +107,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function find(int $accountId): ?Account
|
||||
{
|
||||
return $this->user->accounts()->find($accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -153,8 +133,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
@@ -172,8 +152,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $types
|
||||
* @param string $name
|
||||
* @param array $types
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
@@ -200,32 +180,10 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
|
||||
// return null if not in this list.
|
||||
if (!in_array($type, $list, true)) {
|
||||
return null;
|
||||
}
|
||||
$currencyId = (int)$this->getMetaValue($account, 'currency_id');
|
||||
if ($currencyId > 0) {
|
||||
return TransactionCurrency::find($currencyId);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return account type or null if not found.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
*
|
||||
* @return AccountType|null
|
||||
*/
|
||||
@@ -235,7 +193,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountIds
|
||||
* @param array $accountIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -254,39 +212,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array|null $sort
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsByType(array $types, ?array $sort = []): Collection
|
||||
{
|
||||
$res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types);
|
||||
$query = $this->user->accounts();
|
||||
if (0 !== count($types)) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
|
||||
// add sort parameters. At this point they're filtered to allowed fields to sort by:
|
||||
if (0 !== count($sort)) {
|
||||
foreach ($sort as $param) {
|
||||
$query->orderBy($param[0], $param[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 === count($sort)) {
|
||||
if (0 !== count($res)) {
|
||||
$query->orderBy('accounts.order', 'ASC');
|
||||
}
|
||||
$query->orderBy('accounts.active', 'DESC');
|
||||
$query->orderBy('accounts.name', 'ASC');
|
||||
}
|
||||
|
||||
return $query->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -349,6 +275,16 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $factory->findOrCreate('Cash account', $type->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -362,7 +298,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -395,35 +331,10 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $account->locations()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return meta value for account. Null if not found.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getMetaValue(Account $account, string $field): ?string
|
||||
{
|
||||
$result = $account->accountMeta->filter(
|
||||
function (AccountMeta $meta) use ($field) {
|
||||
return strtolower($meta->name) === strtolower($field);
|
||||
}
|
||||
);
|
||||
if (0 === $result->count()) {
|
||||
return null;
|
||||
}
|
||||
if (1 === $result->count()) {
|
||||
return (string)$result->first()->data;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get note text or null.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -432,23 +343,10 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $account->notes()->first()?->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
public function getOpeningBalance(Account $account): ?TransactionJournal
|
||||
{
|
||||
return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->transactionTypes([TransactionType::OPENING_BALANCE])
|
||||
->first(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of the opening balance for this account.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -472,7 +370,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
/**
|
||||
* Return date of opening balance as string or null.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -485,7 +383,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
@@ -497,7 +395,20 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
public function getOpeningBalance(Account $account): ?TransactionJournal
|
||||
{
|
||||
return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->transactionTypes([TransactionType::OPENING_BALANCE])
|
||||
->first(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -507,7 +418,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Account|null
|
||||
*
|
||||
@@ -549,6 +460,73 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $factory->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
|
||||
// return null if not in this list.
|
||||
if (!in_array($type, $list, true)) {
|
||||
return null;
|
||||
}
|
||||
$currencyId = (int)$this->getMetaValue($account, 'currency_id');
|
||||
if ($currencyId > 0) {
|
||||
return TransactionCurrency::find($currencyId);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return meta value for account. Null if not found.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getMetaValue(Account $account, string $field): ?string
|
||||
{
|
||||
$result = $account->accountMeta->filter(
|
||||
function (AccountMeta $meta) use ($field) {
|
||||
return strtolower($meta->name) === strtolower($field);
|
||||
}
|
||||
);
|
||||
if (0 === $result->count()) {
|
||||
return null;
|
||||
}
|
||||
if (1 === $result->count()) {
|
||||
return (string)$result->first()->data;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $types): int
|
||||
{
|
||||
return $this->user->accounts()->accountTypeIn($types)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function find(int $accountId): ?Account
|
||||
{
|
||||
return $this->user->accounts()->find($accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -566,7 +544,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -602,10 +580,56 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array|null $sort
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsByType(array $types, ?array $sort = []): Collection
|
||||
{
|
||||
$res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types);
|
||||
$query = $this->user->accounts();
|
||||
if (0 !== count($types)) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
|
||||
// add sort parameters. At this point they're filtered to allowed fields to sort by:
|
||||
if (0 !== count($sort)) {
|
||||
foreach ($sort as $param) {
|
||||
$query->orderBy($param[0], $param[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 === count($sort)) {
|
||||
if (0 !== count($res)) {
|
||||
$query->orderBy('accounts.order', 'ASC');
|
||||
}
|
||||
$query->orderBy('accounts.active', 'DESC');
|
||||
$query->orderBy('accounts.name', 'ASC');
|
||||
}
|
||||
|
||||
return $query->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very first transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function oldestJournalDate(Account $account): ?Carbon
|
||||
{
|
||||
$journal = $this->oldestJournal($account);
|
||||
|
||||
return $journal?->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very first transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
@@ -625,20 +649,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very first transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function oldestJournalDate(Account $account): ?Carbon
|
||||
{
|
||||
$journal = $this->oldestJournal($account);
|
||||
|
||||
return $journal?->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -670,9 +680,9 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -739,17 +749,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
@@ -765,8 +765,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
|
@@ -42,7 +42,7 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Moved here from account CRUD.
|
||||
*
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -52,8 +52,8 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Moved here from account CRUD.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account|null $moveTo
|
||||
* @param Account $account
|
||||
* @param Account|null $moveTo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -62,45 +62,45 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Find account with same name OR same IBAN or both, but not the same type or ID.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function expandWithDoubles(Collection $accounts): Collection;
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function find(int $accountId): ?Account;
|
||||
|
||||
/**
|
||||
* @param string $number
|
||||
* @param array $types
|
||||
* @param string $number
|
||||
* @param array $types
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function findByAccountNumber(string $number, array $types): ?Account;
|
||||
|
||||
/**
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function findByIbanNull(string $iban, array $types): ?Account;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $types
|
||||
* @param string $name
|
||||
* @param array $types
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function findByName(string $name, array $types): ?Account;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -109,36 +109,36 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Return account type or null if not found.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
*
|
||||
* @return AccountType|null
|
||||
*/
|
||||
public function getAccountTypeByType(string $type): ?AccountType;
|
||||
|
||||
/**
|
||||
* @param array $accountIds
|
||||
* @param array $accountIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsById(array $accountIds): Collection;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array|null $sort
|
||||
* @param array $types
|
||||
* @param array|null $sort
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsByType(array $types, ?array $sort = []): Collection;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveAccountsByType(array $types): Collection;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -150,14 +150,14 @@ interface AccountRepositoryInterface
|
||||
public function getCashAccount(): Account;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
public function getCreditTransactionGroup(Account $account): ?TransactionGroup;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -166,7 +166,7 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Get account location, if any.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Location|null
|
||||
*/
|
||||
@@ -175,8 +175,8 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Return meta value for account. Null if not found.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param string $field
|
||||
* @param Account $account
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -185,14 +185,14 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Get note text or null.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getNoteText(Account $account): ?string;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*
|
||||
@@ -202,7 +202,7 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Returns the amount of the opening balance for this account.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -211,21 +211,21 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Return date of opening balance as string or null.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getOpeningBalanceDate(Account $account): ?string;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
public function getOpeningBalanceGroup(Account $account): ?TransactionGroup;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -234,28 +234,28 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Find or create the opposing reconciliation account.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
public function getReconciliation(Account $account): ?Account;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getUsedCurrencies(Account $account): Collection;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLiability(Account $account): bool;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -264,7 +264,7 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Returns the date of the very first transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
@@ -273,7 +273,7 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* Returns the date of the very first transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -285,38 +285,38 @@ interface AccountRepositoryInterface
|
||||
public function resetAccountOrder(): void;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchAccount(string $query, array $types, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchAccountNr(string $query, array $types, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function store(array $data): Account;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
|
@@ -43,9 +43,9 @@ class AccountTasker implements AccountTaskerInterface
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -116,9 +116,9 @@ class AccountTasker implements AccountTaskerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -153,51 +153,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): array
|
||||
{
|
||||
// get all incomes for the given accounts in the given period!
|
||||
// also transfers!
|
||||
// get all transactions:
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setDestinationAccounts($accounts)->setRange($start, $end);
|
||||
$collector->excludeSourceAccounts($accounts);
|
||||
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])->withAccountInformation();
|
||||
$report = $this->groupIncomeBySource($collector->getExtractedJournals());
|
||||
|
||||
// sort the result
|
||||
// Obtain a list of columns
|
||||
$sum = [];
|
||||
foreach ($report['accounts'] as $accountId => $row) {
|
||||
$sum[$accountId] = (float)$row['sum']; // intentional float
|
||||
}
|
||||
|
||||
array_multisort($sum, SORT_DESC, $report['accounts']);
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -260,7 +216,41 @@ class AccountTasker implements AccountTaskerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): array
|
||||
{
|
||||
// get all incomes for the given accounts in the given period!
|
||||
// also transfers!
|
||||
// get all transactions:
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setDestinationAccounts($accounts)->setRange($start, $end);
|
||||
$collector->excludeSourceAccounts($accounts);
|
||||
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])->withAccountInformation();
|
||||
$report = $this->groupIncomeBySource($collector->getExtractedJournals());
|
||||
|
||||
// sort the result
|
||||
// Obtain a list of columns
|
||||
$sum = [];
|
||||
foreach ($report['accounts'] as $accountId => $row) {
|
||||
$sum[$accountId] = (float)$row['sum']; // intentional float
|
||||
}
|
||||
|
||||
array_multisort($sum, SORT_DESC, $report['accounts']);
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -320,4 +310,14 @@ class AccountTasker implements AccountTaskerInterface
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,34 +34,34 @@ use Illuminate\Support\Collection;
|
||||
interface AccountTaskerInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAccountReport(Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExpenseReport(Carbon $start, Carbon $end, Collection $accounts): array;
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIncomeReport(Carbon $start, Carbon $end, Collection $accounts): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
}
|
||||
|
@@ -44,9 +44,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
* which have the specified accounts. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -57,141 +57,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
return $this->sortByCurrency($journals, 'negative');
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
|
||||
* which have the specified accounts. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null): array
|
||||
{
|
||||
$journals = $this->getTransactions($start, $end, $accounts, TransactionType::DEPOSIT);
|
||||
|
||||
return $this->sortByCurrency($journals, 'positive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumExpenses(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByCurrency($journals, 'negative');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumExpensesByDestination(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'destination', 'negative');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumExpensesBySource(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'source', 'negative');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumIncome(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByCurrency($journals, 'positive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumIncomeByDestination(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'destination', 'positive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumIncomeBySource(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'source', 'positive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumTransfers(Carbon $start, Carbon $end, ?Collection $accounts = null, ?TransactionCurrency $currency = null): array
|
||||
{
|
||||
$journals = $this->getTransactionsForSum(TransactionType::TRANSFER, $start, $end, $accounts, null, $currency);
|
||||
|
||||
return $this->groupByEither($journals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect transactions with some parameters
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param string $type
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -207,21 +79,107 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $opposing
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param string $type
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @param string $direction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function sortByCurrency(array $journals, string $direction): array
|
||||
{
|
||||
$array = [];
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$array[$currencyId] = $array[$currencyId] ?? [
|
||||
|
||||
'currency_id' => $journal['currency_id'],
|
||||
'currency_name' => $journal['currency_name'],
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
'transaction_journals' => [],
|
||||
];
|
||||
|
||||
$array[$currencyId]['transaction_journals'][$journalId] = [
|
||||
'amount' => app('steam')->$direction((string)$journal['amount']),
|
||||
'date' => $journal['date'],
|
||||
'transaction_journal_id' => $journalId,
|
||||
'budget_name' => $journal['budget_name'],
|
||||
'category_name' => $journal['category_name'],
|
||||
'source_account_id' => $journal['source_account_id'],
|
||||
'source_account_name' => $journal['source_account_name'],
|
||||
'source_account_iban' => $journal['source_account_iban'],
|
||||
'destination_account_id' => $journal['destination_account_id'],
|
||||
'destination_account_name' => $journal['destination_account_name'],
|
||||
'destination_account_iban' => $journal['destination_account_iban'],
|
||||
'tags' => $journal['tags'],
|
||||
'description' => $journal['description'],
|
||||
'transaction_group_id' => $journal['transaction_group_id'],
|
||||
];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
|
||||
* which have the specified accounts. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null): array
|
||||
{
|
||||
$journals = $this->getTransactions($start, $end, $accounts, TransactionType::DEPOSIT);
|
||||
|
||||
return $this->sortByCurrency($journals, 'positive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumExpenses(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByCurrency($journals, 'negative');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $opposing
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getTransactionsForSum(
|
||||
string $type,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $opposing = null,
|
||||
string $type,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $opposing = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$start->startOfDay();
|
||||
@@ -291,8 +249,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @param string $direction
|
||||
* @param array $journals
|
||||
* @param string $direction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -331,9 +289,24 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @param string $direction
|
||||
* @param string $method
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumExpensesByDestination(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'destination', 'negative');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @param string $direction
|
||||
* @param string $method
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -378,7 +351,77 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumExpensesBySource(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'source', 'negative');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumIncome(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByCurrency($journals, 'positive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumIncomeByDestination(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'destination', 'positive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumIncomeBySource(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'source', 'positive');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sumTransfers(Carbon $start, Carbon $end, ?Collection $accounts = null, ?TransactionCurrency $currency = null): array
|
||||
{
|
||||
$journals = $this->getTransactionsForSum(TransactionType::TRANSFER, $start, $end, $accounts, null, $currency);
|
||||
|
||||
return $this->groupByEither($journals);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -401,8 +444,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $return
|
||||
* @param array $journal
|
||||
* @param array $return
|
||||
* @param array $journal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -497,47 +540,4 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @param string $direction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function sortByCurrency(array $journals, string $direction): array
|
||||
{
|
||||
$array = [];
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$array[$currencyId] = $array[$currencyId] ?? [
|
||||
|
||||
'currency_id' => $journal['currency_id'],
|
||||
'currency_name' => $journal['currency_name'],
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
'transaction_journals' => [],
|
||||
];
|
||||
|
||||
$array[$currencyId]['transaction_journals'][$journalId] = [
|
||||
'amount' => app('steam')->$direction((string)$journal['amount']),
|
||||
'date' => $journal['date'],
|
||||
'transaction_journal_id' => $journalId,
|
||||
'budget_name' => $journal['budget_name'],
|
||||
'category_name' => $journal['category_name'],
|
||||
'source_account_id' => $journal['source_account_id'],
|
||||
'source_account_name' => $journal['source_account_name'],
|
||||
'source_account_iban' => $journal['source_account_iban'],
|
||||
'destination_account_id' => $journal['destination_account_id'],
|
||||
'destination_account_name' => $journal['destination_account_name'],
|
||||
'destination_account_iban' => $journal['destination_account_iban'],
|
||||
'tags' => $journal['tags'],
|
||||
'description' => $journal['description'],
|
||||
'transaction_group_id' => $journal['transaction_group_id'],
|
||||
];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
@@ -39,9 +39,9 @@ interface OperationsRepositoryInterface
|
||||
* which have the specified accounts. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -52,140 +52,144 @@ interface OperationsRepositoryInterface
|
||||
* which have the specified accounts. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of accounts, grouped per currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $expense
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $expense
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumExpenses(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of accounts, grouped per destination / currency. Amounts are always negative.
|
||||
* Sum of withdrawal journals in period for a set of accounts, grouped per destination / currency. Amounts are
|
||||
* always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $expense
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $expense
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumExpensesByDestination(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of accounts, grouped per source / currency. Amounts are always negative.
|
||||
* Sum of withdrawal journals in period for a set of accounts, grouped per source / currency. Amounts are always
|
||||
* negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $expense
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $expense
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumExpensesBySource(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $expense = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of income journals in period for a set of accounts, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $revenue
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $revenue
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumIncome(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of income journals in period for a set of accounts, grouped per destination + currency. Amounts are always positive.
|
||||
* Sum of income journals in period for a set of accounts, grouped per destination + currency. Amounts are always
|
||||
* positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $revenue
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $revenue
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumIncomeByDestination(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of income journals in period for a set of accounts, grouped per source + currency. Amounts are always positive.
|
||||
* Sum of income journals in period for a set of accounts, grouped per source + currency. Amounts are always
|
||||
* positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $revenue
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $revenue
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumIncomeBySource(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $revenue = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
|
||||
/**
|
||||
* Sum of transfers in period for a set of accounts, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -31,9 +31,9 @@ use Illuminate\Support\Collection;
|
||||
interface AccountRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param array $types
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
|
@@ -49,7 +49,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
@@ -71,28 +71,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(Attachment $attachment): bool
|
||||
{
|
||||
/** @var Storage $disk */
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $disk->exists($attachment->fileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->attachments()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -116,10 +95,31 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
return $unencryptedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(Attachment $attachment): bool
|
||||
{
|
||||
/** @var Storage $disk */
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $disk->exists($attachment->fileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->attachments()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment note text or empty string.
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -134,17 +134,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
* @throws FireflyException
|
||||
@@ -163,8 +153,18 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $data
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
*/
|
||||
@@ -194,8 +194,8 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param string $note
|
||||
* @param Attachment $attachment
|
||||
* @param string $note
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -35,14 +35,14 @@ use Illuminate\Support\Collection;
|
||||
interface AttachmentRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(Attachment $attachment): bool;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -54,7 +54,7 @@ interface AttachmentRepositoryInterface
|
||||
public function get(): Collection;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -63,19 +63,19 @@ interface AttachmentRepositoryInterface
|
||||
/**
|
||||
* Get attachment note text or empty string.
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(Attachment $attachment): ?string;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment
|
||||
* @throws FireflyException
|
||||
@@ -83,8 +83,8 @@ interface AttachmentRepositoryInterface
|
||||
public function store(array $data): Attachment;
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @param array $attachmentData
|
||||
* @param Attachment $attachment
|
||||
* @param array $attachmentData
|
||||
*
|
||||
* @return Attachment
|
||||
*/
|
||||
|
@@ -34,13 +34,13 @@ use Illuminate\Support\Collection;
|
||||
interface ALERepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param Model $model
|
||||
* @param Model $model
|
||||
* @return Collection
|
||||
*/
|
||||
public function getForObject(Model $model): Collection;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
* @return AuditLogEntry
|
||||
*/
|
||||
public function store(array $data): AuditLogEntry;
|
||||
|
@@ -104,7 +104,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
@@ -127,23 +127,11 @@ class BillRepository implements BillRepositoryInterface
|
||||
$this->user->bills()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a bill by ID.
|
||||
*
|
||||
* @param int $billId
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
public function find(int $billId): ?Bill
|
||||
{
|
||||
return $this->user->bills()->find($billId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find bill by parameters.
|
||||
*
|
||||
* @param int|null $billId
|
||||
* @param string|null $billName
|
||||
* @param int|null $billId
|
||||
* @param string|null $billName
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
@@ -170,10 +158,22 @@ class BillRepository implements BillRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a bill by ID.
|
||||
*
|
||||
* @param int $billId
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
public function find(int $billId): ?Bill
|
||||
{
|
||||
return $this->user->bills()->find($billId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a bill by name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
@@ -182,21 +182,10 @@ class BillRepository implements BillRepositoryInterface
|
||||
return $this->user->bills()->where('name', $name)->first(['bills.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveBills(): Collection
|
||||
{
|
||||
return $this->user->bills()
|
||||
->where('active', true)
|
||||
->orderBy('bills.name', 'ASC')
|
||||
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all attachments.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -230,7 +219,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -278,7 +267,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
/**
|
||||
* Get all bills with these ID's.
|
||||
*
|
||||
* @param array $billIds
|
||||
* @param array $billIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -290,7 +279,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
/**
|
||||
* Get text or return empty string.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -306,7 +295,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -341,7 +330,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
// after loop, re-loop for avg.
|
||||
/**
|
||||
* @var int $currencyId
|
||||
* @var int $currencyId
|
||||
* @var array $arr
|
||||
*/
|
||||
foreach ($result as $currencyId => $arr) {
|
||||
@@ -352,7 +341,17 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $size
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $size
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
@@ -366,9 +365,9 @@ class BillRepository implements BillRepositoryInterface
|
||||
/**
|
||||
* The "paid dates" list is a list of dates of transaction journals that are linked to this bill.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Bill $bill
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -386,45 +385,10 @@ class BillRepository implements BillRepositoryInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Between start and end, tells you on which date(s) the bill is expected to hit.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$set = new Collection();
|
||||
$currentStart = clone $start;
|
||||
//Log::debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq));
|
||||
//Log::debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d')));
|
||||
|
||||
while ($currentStart <= $end) {
|
||||
//Log::debug(sprintf('Currentstart is now %s.', $currentStart->format('Y-m-d')));
|
||||
$nextExpectedMatch = $this->nextDateMatch($bill, $currentStart);
|
||||
//Log::debug(sprintf('Next Date match after %s is %s', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
if ($nextExpectedMatch > $end) {// If nextExpectedMatch is after end, we continue
|
||||
break;
|
||||
}
|
||||
$set->push(clone $nextExpectedMatch);
|
||||
//Log::debug(sprintf('Now %d dates in set.', $set->count()));
|
||||
$nextExpectedMatch->addDay();
|
||||
|
||||
//Log::debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all rules for one bill
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -443,7 +407,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
*
|
||||
* 5 => [['id' => 1, 'title' => 'Some rule'],['id' => 2, 'title' => 'Some other rule']]
|
||||
*
|
||||
* @param Collection $collection
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -468,8 +432,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -483,8 +447,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
$result = [];
|
||||
|
||||
$journals = $bill->transactionJournals()
|
||||
->where('date', '>=', $date->year.'-01-01 00:00:00')
|
||||
->where('date', '<=', $date->year.'-12-31 23:59:59')
|
||||
->where('date', '>=', $date->year . '-01-01 00:00:00')
|
||||
->where('date', '<=', $date->year . '-12-31 23:59:59')
|
||||
->get();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
@@ -511,7 +475,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
// after loop, re-loop for avg.
|
||||
/**
|
||||
* @var int $currencyId
|
||||
* @var int $currencyId
|
||||
* @var array $arr
|
||||
*/
|
||||
foreach ($result as $currencyId => $arr) {
|
||||
@@ -524,8 +488,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
/**
|
||||
* Link a set of journals to a bill.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param array $transactions
|
||||
* @param Bill $bill
|
||||
* @param array $transactions
|
||||
*/
|
||||
public function linkCollectionToBill(Bill $bill, array $transactions): void
|
||||
{
|
||||
@@ -538,40 +502,11 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a bill and a date, this method will tell you at which moment this bill expects its next
|
||||
* transaction. Whether or not it is there already, is not relevant.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function nextDateMatch(Bill $bill, Carbon $date): Carbon
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($bill->id);
|
||||
$cache->addProperty('nextDateMatch');
|
||||
$cache->addProperty($date);
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
// find the most recent date for this bill NOT in the future. Cache this date:
|
||||
$start = clone $bill->date;
|
||||
|
||||
while ($start < $date) {
|
||||
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
}
|
||||
$cache->store($start);
|
||||
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the date in $date, this method will return a moment in the future where the bill is expected to be paid.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon
|
||||
* @throws JsonException
|
||||
@@ -587,12 +522,12 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
// find the most recent date for this bill NOT in the future. Cache this date:
|
||||
$start = clone $bill->date;
|
||||
Log::debug('nextExpectedMatch: Start is '.$start->format('Y-m-d'));
|
||||
Log::debug('nextExpectedMatch: Start is ' . $start->format('Y-m-d'));
|
||||
|
||||
while ($start < $date) {
|
||||
Log::debug(sprintf('$start (%s) < $date (%s)', $start->format('Y-m-d'), $date->format('Y-m-d')));
|
||||
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
Log::debug('Start is now '.$start->format('Y-m-d'));
|
||||
Log::debug('Start is now ' . $start->format('Y-m-d'));
|
||||
}
|
||||
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
@@ -606,14 +541,30 @@ class BillRepository implements BillRepositoryInterface
|
||||
$start = clone $end;
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
}
|
||||
Log::debug('nextExpectedMatch: Final start is '.$start->format('Y-m-d'));
|
||||
Log::debug('nextExpectedMatch: Matching end is '.$end->format('Y-m-d'));
|
||||
Log::debug('nextExpectedMatch: Final start is ' . $start->format('Y-m-d'));
|
||||
Log::debug('nextExpectedMatch: Matching end is ' . $end->format('Y-m-d'));
|
||||
|
||||
$cache->store($start);
|
||||
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Bill
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function store(array $data): Bill
|
||||
{
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user);
|
||||
|
||||
return $factory->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -625,8 +576,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -659,32 +610,6 @@ class BillRepository implements BillRepositoryInterface
|
||||
$bill->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Bill
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function store(array $data): Bill
|
||||
{
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user);
|
||||
|
||||
return $factory->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -724,6 +649,17 @@ class BillRepository implements BillRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveBills(): Collection
|
||||
{
|
||||
return $this->user->bills()
|
||||
->where('active', true)
|
||||
->orderBy('bills.name', 'ASC')
|
||||
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -756,7 +692,71 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* Between start and end, tells you on which date(s) the bill is expected to hit.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$set = new Collection();
|
||||
$currentStart = clone $start;
|
||||
//Log::debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq));
|
||||
//Log::debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d')));
|
||||
|
||||
while ($currentStart <= $end) {
|
||||
//Log::debug(sprintf('Currentstart is now %s.', $currentStart->format('Y-m-d')));
|
||||
$nextExpectedMatch = $this->nextDateMatch($bill, $currentStart);
|
||||
//Log::debug(sprintf('Next Date match after %s is %s', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
if ($nextExpectedMatch > $end) {// If nextExpectedMatch is after end, we continue
|
||||
break;
|
||||
}
|
||||
$set->push(clone $nextExpectedMatch);
|
||||
//Log::debug(sprintf('Now %d dates in set.', $set->count()));
|
||||
$nextExpectedMatch->addDay();
|
||||
|
||||
//Log::debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a bill and a date, this method will tell you at which moment this bill expects its next
|
||||
* transaction. Whether or not it is there already, is not relevant.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function nextDateMatch(Bill $bill, Carbon $date): Carbon
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($bill->id);
|
||||
$cache->addProperty('nextDateMatch');
|
||||
$cache->addProperty($date);
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
// find the most recent date for this bill NOT in the future. Cache this date:
|
||||
$start = clone $bill->date;
|
||||
|
||||
while ($start < $date) {
|
||||
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
}
|
||||
$cache->store($start);
|
||||
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*/
|
||||
public function unlinkAll(Bill $bill): void
|
||||
{
|
||||
@@ -764,8 +764,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param array $data
|
||||
* @param Bill $bill
|
||||
* @param array $data
|
||||
*
|
||||
* @return Bill
|
||||
* @throws FireflyException
|
||||
|
@@ -37,16 +37,16 @@ use Illuminate\Support\Collection;
|
||||
interface BillRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function billEndsWith(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -58,7 +58,7 @@ interface BillRepositoryInterface
|
||||
public function correctOrder(): void;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -72,7 +72,7 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Find a bill by ID.
|
||||
*
|
||||
* @param int $billId
|
||||
* @param int $billId
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
@@ -81,8 +81,8 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Find bill by parameters.
|
||||
*
|
||||
* @param int|null $billId
|
||||
* @param string|null $billName
|
||||
* @param int|null $billId
|
||||
* @param string|null $billName
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
@@ -91,7 +91,7 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Find a bill by name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*
|
||||
* @return Bill|null
|
||||
*/
|
||||
@@ -105,7 +105,7 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Get all attachments.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -119,7 +119,7 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Gets the bills which have some kind of relevance to the accounts mentioned.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -128,7 +128,7 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Get all bills with these ID's.
|
||||
*
|
||||
* @param array $billIds
|
||||
* @param array $billIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -137,30 +137,30 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Get text or return empty string.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNoteText(Bill $bill): string;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOverallAverage(Bill $bill): array;
|
||||
|
||||
/**
|
||||
* @param int $size
|
||||
* @param int $size
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getPaginator(int $size): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Bill $bill
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -169,9 +169,9 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Between start and end, tells you on which date(s) the bill is expected to hit.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Bill $bill
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -180,7 +180,7 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Return all rules for one bill
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -192,15 +192,15 @@ interface BillRepositoryInterface
|
||||
*
|
||||
* 5 => [['id' => 1, 'title' => 'Some rule'],['id' => 2, 'title' => 'Some other rule']]
|
||||
*
|
||||
* @param Collection $collection
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRulesForBills(Collection $collection): array;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -209,8 +209,8 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Link a set of journals to a bill.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param array $transactions
|
||||
* @param Bill $bill
|
||||
* @param array $transactions
|
||||
*/
|
||||
public function linkCollectionToBill(Bill $bill, array $transactions): void;
|
||||
|
||||
@@ -218,39 +218,39 @@ interface BillRepositoryInterface
|
||||
* Given a bill and a date, this method will tell you at which moment this bill expects its next
|
||||
* transaction. Whether or not it is there already, is not relevant.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function nextDateMatch(Bill $bill, Carbon $date): Carbon;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return Bill
|
||||
*/
|
||||
public function removeObjectGroup(Bill $bill): Bill;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchBill(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param string $objectGroupTitle
|
||||
* @param Bill $bill
|
||||
* @param string $objectGroupTitle
|
||||
*
|
||||
* @return Bill
|
||||
*/
|
||||
@@ -259,18 +259,18 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Set specific piggy bank to specific order.
|
||||
*
|
||||
* @param Bill $bill
|
||||
* @param int $order
|
||||
* @param Bill $bill
|
||||
* @param int $order
|
||||
*/
|
||||
public function setOrder(Bill $bill, int $order): void;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Bill
|
||||
* @throws FireflyException
|
||||
@@ -280,8 +280,8 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Collect multi-currency of sum of bills already paid.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return array
|
||||
*/
|
||||
public function sumPaidInRange(Carbon $start, Carbon $end): array;
|
||||
@@ -289,20 +289,20 @@ interface BillRepositoryInterface
|
||||
/**
|
||||
* Collect multi-currency of sum of bills yet to pay.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return array
|
||||
*/
|
||||
public function sumUnpaidInRange(Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*/
|
||||
public function unlinkAll(Bill $bill): void;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param array $data
|
||||
* @param Bill $bill
|
||||
* @param array $data
|
||||
*
|
||||
* @return Bill
|
||||
*/
|
||||
|
@@ -48,19 +48,27 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param AvailableBudget $availableBudget
|
||||
*/
|
||||
public function destroyAvailableBudget(AvailableBudget $availableBudget): void
|
||||
{
|
||||
$availableBudget->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findById(int $id): ?AvailableBudget
|
||||
{
|
||||
return $this->user->availableBudgets->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find existing AB.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return AvailableBudget|null
|
||||
*/
|
||||
@@ -74,18 +82,51 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function findById(int $id): ?AvailableBudget
|
||||
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string
|
||||
{
|
||||
return $this->user->availableBudgets->find($id);
|
||||
$amount = '0';
|
||||
$availableBudget = $this->user->availableBudgets()
|
||||
->where('transaction_currency_id', $currency->id)
|
||||
->where('start_date', $start->format('Y-m-d'))
|
||||
->where('end_date', $end->format('Y-m-d'))->first();
|
||||
if (null !== $availableBudget) {
|
||||
$amount = (string)$availableBudget->amount;
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableBudgetWithCurrency(Carbon $start, Carbon $end): array
|
||||
{
|
||||
$return = [];
|
||||
$availableBudgets = $this->user->availableBudgets()
|
||||
->where('start_date', $start->format('Y-m-d'))
|
||||
->where('end_date', $end->format('Y-m-d'))->get();
|
||||
/** @var AvailableBudget $availableBudget */
|
||||
foreach ($availableBudgets as $availableBudget) {
|
||||
$return[$availableBudget->transaction_currency_id] = $availableBudget->amount;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all available budgets (in all currencies) (for the selected period).
|
||||
*
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -104,51 +145,10 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
return $query->get(['available_budgets.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string
|
||||
{
|
||||
$amount = '0';
|
||||
$availableBudget = $this->user->availableBudgets()
|
||||
->where('transaction_currency_id', $currency->id)
|
||||
->where('start_date', $start->format('Y-m-d'))
|
||||
->where('end_date', $end->format('Y-m-d'))->first();
|
||||
if (null !== $availableBudget) {
|
||||
$amount = (string)$availableBudget->amount;
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableBudgetWithCurrency(Carbon $start, Carbon $end): array
|
||||
{
|
||||
$return = [];
|
||||
$availableBudgets = $this->user->availableBudgets()
|
||||
->where('start_date', $start->format('Y-m-d'))
|
||||
->where('end_date', $end->format('Y-m-d'))->get();
|
||||
/** @var AvailableBudget $availableBudget */
|
||||
foreach ($availableBudgets as $availableBudget) {
|
||||
$return[$availableBudget->transaction_currency_id] = $availableBudget->amount;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available budget objects.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -160,8 +160,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
/**
|
||||
* Returns all available budget objects.
|
||||
*
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*
|
||||
@@ -193,10 +193,10 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
*
|
||||
* @return AvailableBudget
|
||||
* @deprecated
|
||||
@@ -221,9 +221,9 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
@@ -231,7 +231,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return AvailableBudget|null
|
||||
*/
|
||||
@@ -259,8 +259,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
*
|
||||
* @return AvailableBudget
|
||||
*/
|
||||
@@ -275,8 +275,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
*
|
||||
* @return AvailableBudget
|
||||
*/
|
||||
|
@@ -41,23 +41,23 @@ interface AvailableBudgetRepositoryInterface
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param AvailableBudget $availableBudget
|
||||
*/
|
||||
public function destroyAvailableBudget(AvailableBudget $availableBudget): void;
|
||||
|
||||
/**
|
||||
* Find existing AB.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return AvailableBudget|null
|
||||
*/
|
||||
public function find(TransactionCurrency $currency, Carbon $start, Carbon $end): ?AvailableBudget;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
*
|
||||
* @return AvailableBudget|null
|
||||
*/
|
||||
@@ -66,17 +66,17 @@ interface AvailableBudgetRepositoryInterface
|
||||
/**
|
||||
* Return a list of all available budgets (in all currencies) (for the selected period).
|
||||
*
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(?Carbon $start = null, ?Carbon $end = null): Collection;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @deprecated
|
||||
@@ -84,8 +84,8 @@ interface AvailableBudgetRepositoryInterface
|
||||
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string;
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -94,7 +94,7 @@ interface AvailableBudgetRepositoryInterface
|
||||
/**
|
||||
* Returns all available budget objects.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -103,8 +103,8 @@ interface AvailableBudgetRepositoryInterface
|
||||
/**
|
||||
* Returns all available budget objects.
|
||||
*
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*
|
||||
@@ -114,19 +114,19 @@ interface AvailableBudgetRepositoryInterface
|
||||
/**
|
||||
* Get by transaction currency and date. Should always result in one entry or NULL.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return null|AvailableBudget
|
||||
*/
|
||||
public function getByCurrencyDate(Carbon $start, Carbon $end, TransactionCurrency $currency): ?AvailableBudget;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
*
|
||||
* @return AvailableBudget
|
||||
* @deprecated
|
||||
@@ -134,28 +134,28 @@ interface AvailableBudgetRepositoryInterface
|
||||
public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return AvailableBudget|null
|
||||
*/
|
||||
public function store(array $data): ?AvailableBudget;
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
*
|
||||
* @return AvailableBudget
|
||||
*/
|
||||
public function update(AvailableBudget $availableBudget, array $data): AvailableBudget;
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
*
|
||||
* @return AvailableBudget
|
||||
*/
|
||||
|
@@ -48,10 +48,10 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
* Tells you which amount has been budgeted (for the given budgets)
|
||||
* in the selected query. Returns a positive amount as a string.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Collection|null $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Collection|null $budgets
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -120,7 +120,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
/**
|
||||
* Destroy a budget limit.
|
||||
*
|
||||
* @param BudgetLimit $budgetLimit
|
||||
* @param BudgetLimit $budgetLimit
|
||||
*/
|
||||
public function destroyBudgetLimit(BudgetLimit $budgetLimit): void
|
||||
{
|
||||
@@ -128,24 +128,24 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return BudgetLimit|null
|
||||
* @return Collection
|
||||
*/
|
||||
public function find(Budget $budget, TransactionCurrency $currency, Carbon $start, Carbon $end): ?BudgetLimit
|
||||
public function getAllBudgetLimitsByCurrency(TransactionCurrency $currency, Carbon $start = null, Carbon $end = null): Collection
|
||||
{
|
||||
return $budget->budgetlimits()
|
||||
->where('transaction_currency_id', $currency->id)
|
||||
->where('start_date', $start->format('Y-m-d'))
|
||||
->where('end_date', $end->format('Y-m-d'))->first();
|
||||
return $this->getAllBudgetLimits($start, $end)->filter(
|
||||
static function (BudgetLimit $budgetLimit) use ($currency) {
|
||||
return $budgetLimit->transaction_currency_id === $currency->id;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -212,25 +212,9 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllBudgetLimitsByCurrency(TransactionCurrency $currency, Carbon $start = null, Carbon $end = null): Collection
|
||||
{
|
||||
return $this->getAllBudgetLimits($start, $end)->filter(
|
||||
static function (BudgetLimit $budgetLimit) use ($currency) {
|
||||
return $budgetLimit->transaction_currency_id === $currency->id;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Budget $budget
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -288,9 +272,9 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
@@ -298,7 +282,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return BudgetLimit
|
||||
* @throws FireflyException
|
||||
@@ -347,8 +331,24 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetLimit $budgetLimit
|
||||
* @param array $data
|
||||
* @param Budget $budget
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return BudgetLimit|null
|
||||
*/
|
||||
public function find(Budget $budget, TransactionCurrency $currency, Carbon $start, Carbon $end): ?BudgetLimit
|
||||
{
|
||||
return $budget->budgetlimits()
|
||||
->where('transaction_currency_id', $currency->id)
|
||||
->where('start_date', $start->format('Y-m-d'))
|
||||
->where('end_date', $end->format('Y-m-d'))->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetLimit $budgetLimit
|
||||
* @param array $data
|
||||
*
|
||||
* @return BudgetLimit
|
||||
* @throws FireflyException
|
||||
@@ -384,10 +384,10 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
*
|
||||
* @return BudgetLimit|null
|
||||
*
|
||||
|
@@ -40,10 +40,10 @@ interface BudgetLimitRepositoryInterface
|
||||
* Tells you which amount has been budgeted (for the given budgets)
|
||||
* in the selected query. Returns a positive amount as a string.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Collection|null $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Collection|null $budgets
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -57,15 +57,15 @@ interface BudgetLimitRepositoryInterface
|
||||
/**
|
||||
* Destroy a budget limit.
|
||||
*
|
||||
* @param BudgetLimit $budgetLimit
|
||||
* @param BudgetLimit $budgetLimit
|
||||
*/
|
||||
public function destroyBudgetLimit(BudgetLimit $budgetLimit): void;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Budget $budget
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return BudgetLimit|null
|
||||
*/
|
||||
@@ -74,56 +74,56 @@ interface BudgetLimitRepositoryInterface
|
||||
/**
|
||||
* TODO this method is not multi currency aware.
|
||||
*
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllBudgetLimits(Carbon $start = null, Carbon $end = null): Collection;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllBudgetLimitsByCurrency(TransactionCurrency $currency, Carbon $start = null, Carbon $end = null): Collection;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Budget $budget
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBudgetLimits(Budget $budget, Carbon $start = null, Carbon $end = null): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return BudgetLimit
|
||||
*/
|
||||
public function store(array $data): BudgetLimit;
|
||||
|
||||
/**
|
||||
* @param BudgetLimit $budgetLimit
|
||||
* @param array $data
|
||||
* @param BudgetLimit $budgetLimit
|
||||
* @param array $data
|
||||
*
|
||||
* @return BudgetLimit
|
||||
*/
|
||||
public function update(BudgetLimit $budgetLimit, array $data): BudgetLimit;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $amount
|
||||
*
|
||||
* @return BudgetLimit|null
|
||||
*/
|
||||
|
@@ -144,6 +144,65 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveBudgets(): Collection
|
||||
{
|
||||
return $this->user->budgets()->where('active', true)
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* How many days of this budget limit are between start and end?
|
||||
*
|
||||
* @param BudgetLimit $limit
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return int
|
||||
*/
|
||||
private function daysInOverlap(BudgetLimit $limit, Carbon $start, Carbon $end): int
|
||||
{
|
||||
// start1 = $start
|
||||
// start2 = $limit->start_date
|
||||
// start1 = $end
|
||||
// start2 = $limit->end_date
|
||||
|
||||
// limit is larger than start and end (inclusive)
|
||||
// |-----------|
|
||||
// |----------------|
|
||||
if ($start->gte($limit->start_date) && $end->lte($limit->end_date)) {
|
||||
return $start->diffInDays($end) + 1; // add one day
|
||||
}
|
||||
// limit starts earlier and limit ends first:
|
||||
// |-----------|
|
||||
// |-------|
|
||||
if ($limit->start_date->lte($start) && $limit->end_date->lte($end)) {
|
||||
// return days in the range $start-$limit_end
|
||||
return $start->diffInDays($limit->end_date) + 1; // add one day, the day itself
|
||||
}
|
||||
// limit starts later and limit ends earlier
|
||||
// |-----------|
|
||||
// |-------|
|
||||
if ($limit->start_date->gte($start) && $limit->end_date->gte($end)) {
|
||||
// return days in the range $limit_start - $end
|
||||
return $limit->start_date->diffInDays($end) + 1; // add one day, the day itself
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -208,7 +267,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
BudgetLimit::where('amount', 0)->delete();
|
||||
$budgets = $this->getActiveBudgets();
|
||||
/**
|
||||
* @var int $index
|
||||
* @var int $index
|
||||
* @var Budget $budget
|
||||
*/
|
||||
foreach ($budgets as $index => $budget) {
|
||||
@@ -222,7 +281,191 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
* @param array $data
|
||||
*
|
||||
* @return Budget
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function update(Budget $budget, array $data): Budget
|
||||
{
|
||||
Log::debug('Now in update()');
|
||||
|
||||
$oldName = $budget->name;
|
||||
if (array_key_exists('name', $data)) {
|
||||
$budget->name = $data['name'];
|
||||
$this->updateRuleActions($oldName, $budget->name);
|
||||
$this->updateRuleTriggers($oldName, $budget->name);
|
||||
}
|
||||
if (array_key_exists('active', $data)) {
|
||||
$budget->active = $data['active'];
|
||||
}
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->setNoteText($budget, (string)$data['notes']);
|
||||
}
|
||||
$budget->save();
|
||||
|
||||
// update or create auto-budget:
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// first things first: delete when no longer required:
|
||||
$autoBudgetType = array_key_exists('auto_budget_type', $data) ? $data['auto_budget_type'] : null;
|
||||
|
||||
if (0 === $autoBudgetType && null !== $autoBudget) {
|
||||
// delete!
|
||||
$autoBudget->delete();
|
||||
|
||||
return $budget;
|
||||
}
|
||||
if (0 === $autoBudgetType && null === $autoBudget) {
|
||||
return $budget;
|
||||
}
|
||||
if (null === $autoBudgetType && null === $autoBudget) {
|
||||
return $budget;
|
||||
}
|
||||
$this->updateAutoBudget($budget, $data);
|
||||
|
||||
return $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
private function updateRuleActions(string $oldName, string $newName): void
|
||||
{
|
||||
$types = ['set_budget',];
|
||||
$actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_actions.action_type', $types)
|
||||
->where('rule_actions.action_value', $oldName)
|
||||
->get(['rule_actions.*']);
|
||||
Log::debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||
/** @var RuleAction $action */
|
||||
foreach ($actions as $action) {
|
||||
$action->action_value = $newName;
|
||||
$action->save();
|
||||
Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
private function updateRuleTriggers(string $oldName, string $newName): void
|
||||
{
|
||||
$types = ['budget_is',];
|
||||
$triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_triggers.trigger_type', $types)
|
||||
->where('rule_triggers.trigger_value', $oldName)
|
||||
->get(['rule_triggers.*']);
|
||||
Log::debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
$trigger->trigger_value = $newName;
|
||||
$trigger->save();
|
||||
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param string $text
|
||||
* @return void
|
||||
*/
|
||||
private function setNoteText(Budget $budget, string $text): void
|
||||
{
|
||||
$dbNote = $budget->notes()->first();
|
||||
if ('' !== $text) {
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($budget);
|
||||
}
|
||||
$dbNote->text = trim($text);
|
||||
$dbNote->save();
|
||||
|
||||
return;
|
||||
}
|
||||
if (null !== $dbNote) {
|
||||
$dbNote->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAutoBudget(Budget $budget): ?AutoBudget
|
||||
{
|
||||
return $budget->autoBudgets()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param array $data
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
*/
|
||||
private function updateAutoBudget(Budget $budget, array $data): void
|
||||
{
|
||||
// update or create auto-budget:
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// grab default currency:
|
||||
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||
|
||||
if (null === $autoBudget) {
|
||||
// at this point it's a blind assumption auto_budget_type is 1 or 2.
|
||||
$autoBudget = new AutoBudget();
|
||||
$autoBudget->auto_budget_type = $data['auto_budget_type'];
|
||||
$autoBudget->budget_id = $budget->id;
|
||||
$autoBudget->transaction_currency_id = $currency->id;
|
||||
}
|
||||
|
||||
// set or update the currency.
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currencyId = (int)($data['currency_id'] ?? 0);
|
||||
$currencyCode = (string)($data['currency_code'] ?? '');
|
||||
$currency = $repos->find($currencyId);
|
||||
if (null === $currency) {
|
||||
$currency = $repos->findByCodeNull($currencyCode);
|
||||
}
|
||||
if (null !== $currency) {
|
||||
$autoBudget->transaction_currency_id = $currency->id;
|
||||
}
|
||||
}
|
||||
|
||||
// change values if submitted or presented:
|
||||
if (array_key_exists('auto_budget_type', $data)) {
|
||||
$autoBudget->auto_budget_type = $data['auto_budget_type'];
|
||||
}
|
||||
if (array_key_exists('auto_budget_amount', $data)) {
|
||||
$autoBudget->amount = $data['auto_budget_amount'];
|
||||
}
|
||||
if (array_key_exists('auto_budget_period', $data)) {
|
||||
$autoBudget->period = $data['auto_budget_period'];
|
||||
}
|
||||
|
||||
$autoBudget->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a budget or return NULL
|
||||
*
|
||||
* @param int|null $budgetId |null
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
public function find(int $budgetId = null): ?Budget
|
||||
{
|
||||
return $this->user->budgets()->find($budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -251,6 +494,15 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBudgets(): Collection
|
||||
{
|
||||
return $this->user->budgets()->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -263,20 +515,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a budget or return NULL
|
||||
*
|
||||
* @param int|null $budgetId |null
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
public function find(int $budgetId = null): ?Budget
|
||||
{
|
||||
return $this->user->budgets()->find($budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $budgetId
|
||||
* @param string|null $budgetName
|
||||
* @param int|null $budgetId
|
||||
* @param string|null $budgetName
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
@@ -300,7 +540,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
/**
|
||||
* Find budget by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param string|null $name
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
@@ -318,7 +558,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
* This method returns the oldest journal or transaction date known to this budget.
|
||||
* Will cache result.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -332,17 +572,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveBudgets(): Collection
|
||||
{
|
||||
return $this->user->budgets()->where('active', true)
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -364,27 +593,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAutoBudget(Budget $budget): ?AutoBudget
|
||||
{
|
||||
return $budget->autoBudgets()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBudgets(): Collection
|
||||
{
|
||||
return $this->user->budgets()->orderBy('order', 'ASC')
|
||||
->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all budgets with these ID's.
|
||||
*
|
||||
* @param array $budgetIds
|
||||
* @param array $budgetIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -403,11 +615,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
->orderBy('name', 'ASC')->where('active', 0)->get();
|
||||
}
|
||||
|
||||
public function getMaxOrder(): int
|
||||
{
|
||||
return (int)$this->user->budgets()->max('order');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -422,8 +629,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -440,8 +647,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param int $order
|
||||
* @param Budget $budget
|
||||
* @param int $order
|
||||
*/
|
||||
public function setBudgetOrder(Budget $budget, int $order): void
|
||||
{
|
||||
@@ -449,16 +656,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$budget->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -586,7 +783,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Budget
|
||||
* @throws FireflyException
|
||||
@@ -676,205 +873,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $newBudget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param array $data
|
||||
*
|
||||
* @return Budget
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function update(Budget $budget, array $data): Budget
|
||||
public function getMaxOrder(): int
|
||||
{
|
||||
Log::debug('Now in update()');
|
||||
|
||||
$oldName = $budget->name;
|
||||
if (array_key_exists('name', $data)) {
|
||||
$budget->name = $data['name'];
|
||||
$this->updateRuleActions($oldName, $budget->name);
|
||||
$this->updateRuleTriggers($oldName, $budget->name);
|
||||
}
|
||||
if (array_key_exists('active', $data)) {
|
||||
$budget->active = $data['active'];
|
||||
}
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->setNoteText($budget, (string)$data['notes']);
|
||||
}
|
||||
$budget->save();
|
||||
|
||||
// update or create auto-budget:
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// first things first: delete when no longer required:
|
||||
$autoBudgetType = array_key_exists('auto_budget_type', $data) ? $data['auto_budget_type'] : null;
|
||||
|
||||
if (0 === $autoBudgetType && null !== $autoBudget) {
|
||||
// delete!
|
||||
$autoBudget->delete();
|
||||
|
||||
return $budget;
|
||||
}
|
||||
if (0 === $autoBudgetType && null === $autoBudget) {
|
||||
return $budget;
|
||||
}
|
||||
if (null === $autoBudgetType && null === $autoBudget) {
|
||||
return $budget;
|
||||
}
|
||||
$this->updateAutoBudget($budget, $data);
|
||||
|
||||
return $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many days of this budget limit are between start and end?
|
||||
*
|
||||
* @param BudgetLimit $limit
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return int
|
||||
*/
|
||||
private function daysInOverlap(BudgetLimit $limit, Carbon $start, Carbon $end): int
|
||||
{
|
||||
// start1 = $start
|
||||
// start2 = $limit->start_date
|
||||
// start1 = $end
|
||||
// start2 = $limit->end_date
|
||||
|
||||
// limit is larger than start and end (inclusive)
|
||||
// |-----------|
|
||||
// |----------------|
|
||||
if ($start->gte($limit->start_date) && $end->lte($limit->end_date)) {
|
||||
return $start->diffInDays($end) + 1; // add one day
|
||||
}
|
||||
// limit starts earlier and limit ends first:
|
||||
// |-----------|
|
||||
// |-------|
|
||||
if ($limit->start_date->lte($start) && $limit->end_date->lte($end)) {
|
||||
// return days in the range $start-$limit_end
|
||||
return $start->diffInDays($limit->end_date) + 1; // add one day, the day itself
|
||||
}
|
||||
// limit starts later and limit ends earlier
|
||||
// |-----------|
|
||||
// |-------|
|
||||
if ($limit->start_date->gte($start) && $limit->end_date->gte($end)) {
|
||||
// return days in the range $limit_start - $end
|
||||
return $limit->start_date->diffInDays($end) + 1; // add one day, the day itself
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param string $text
|
||||
* @return void
|
||||
*/
|
||||
private function setNoteText(Budget $budget, string $text): void
|
||||
{
|
||||
$dbNote = $budget->notes()->first();
|
||||
if ('' !== $text) {
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($budget);
|
||||
}
|
||||
$dbNote->text = trim($text);
|
||||
$dbNote->save();
|
||||
|
||||
return;
|
||||
}
|
||||
if (null !== $dbNote) {
|
||||
$dbNote->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param array $data
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
*/
|
||||
private function updateAutoBudget(Budget $budget, array $data): void
|
||||
{
|
||||
// update or create auto-budget:
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// grab default currency:
|
||||
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||
|
||||
if (null === $autoBudget) {
|
||||
// at this point it's a blind assumption auto_budget_type is 1 or 2.
|
||||
$autoBudget = new AutoBudget();
|
||||
$autoBudget->auto_budget_type = $data['auto_budget_type'];
|
||||
$autoBudget->budget_id = $budget->id;
|
||||
$autoBudget->transaction_currency_id = $currency->id;
|
||||
}
|
||||
|
||||
// set or update the currency.
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currencyId = (int)($data['currency_id'] ?? 0);
|
||||
$currencyCode = (string)($data['currency_code'] ?? '');
|
||||
$currency = $repos->find($currencyId);
|
||||
if (null === $currency) {
|
||||
$currency = $repos->findByCodeNull($currencyCode);
|
||||
}
|
||||
if (null !== $currency) {
|
||||
$autoBudget->transaction_currency_id = $currency->id;
|
||||
}
|
||||
}
|
||||
|
||||
// change values if submitted or presented:
|
||||
if (array_key_exists('auto_budget_type', $data)) {
|
||||
$autoBudget->auto_budget_type = $data['auto_budget_type'];
|
||||
}
|
||||
if (array_key_exists('auto_budget_amount', $data)) {
|
||||
$autoBudget->amount = $data['auto_budget_amount'];
|
||||
}
|
||||
if (array_key_exists('auto_budget_period', $data)) {
|
||||
$autoBudget->period = $data['auto_budget_period'];
|
||||
}
|
||||
|
||||
$autoBudget->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
private function updateRuleActions(string $oldName, string $newName): void
|
||||
{
|
||||
$types = ['set_budget',];
|
||||
$actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_actions.action_type', $types)
|
||||
->where('rule_actions.action_value', $oldName)
|
||||
->get(['rule_actions.*']);
|
||||
Log::debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||
/** @var RuleAction $action */
|
||||
foreach ($actions as $action) {
|
||||
$action->action_value = $newName;
|
||||
$action->save();
|
||||
Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldName
|
||||
* @param string $newName
|
||||
*/
|
||||
private function updateRuleTriggers(string $oldName, string $newName): void
|
||||
{
|
||||
$types = ['budget_is',];
|
||||
$triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||
->where('rules.user_id', $this->user->id)
|
||||
->whereIn('rule_triggers.trigger_type', $types)
|
||||
->where('rule_triggers.trigger_value', $oldName)
|
||||
->get(['rule_triggers.*']);
|
||||
Log::debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
$trigger->trigger_value = $newName;
|
||||
$trigger->save();
|
||||
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||
}
|
||||
return (int)$this->user->budgets()->max('order');
|
||||
}
|
||||
}
|
||||
|
@@ -37,16 +37,16 @@ use Illuminate\Support\Collection;
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function budgetEndsWith(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -55,8 +55,8 @@ interface BudgetRepositoryInterface
|
||||
/**
|
||||
* Returns the amount that is budgeted in a period.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return array
|
||||
*/
|
||||
public function budgetedInPeriod(Carbon $start, Carbon $end): array;
|
||||
@@ -64,9 +64,9 @@ interface BudgetRepositoryInterface
|
||||
/**
|
||||
* Returns the amount that is budgeted in a period.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return array
|
||||
*/
|
||||
public function budgetedInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array;
|
||||
@@ -77,7 +77,7 @@ interface BudgetRepositoryInterface
|
||||
public function cleanupBudgets(): bool;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -89,21 +89,21 @@ interface BudgetRepositoryInterface
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*/
|
||||
public function destroyAutoBudget(Budget $budget): void;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int|null $budgetId
|
||||
* @param int|null $budgetId
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
public function find(int $budgetId = null): ?Budget;
|
||||
|
||||
/**
|
||||
* @param int|null $budgetId
|
||||
* @param string|null $budgetName
|
||||
* @param int|null $budgetId
|
||||
* @param string|null $budgetName
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
@@ -112,7 +112,7 @@ interface BudgetRepositoryInterface
|
||||
/**
|
||||
* Find budget by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param string|null $name
|
||||
*
|
||||
* @return Budget|null
|
||||
*/
|
||||
@@ -122,7 +122,7 @@ interface BudgetRepositoryInterface
|
||||
* This method returns the oldest journal or transaction date known to this budget.
|
||||
* Will cache result.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -134,14 +134,14 @@ interface BudgetRepositoryInterface
|
||||
public function getActiveBudgets(): Collection;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttachments(Budget $budget): Collection;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return AutoBudget|null
|
||||
*/
|
||||
@@ -155,7 +155,7 @@ interface BudgetRepositoryInterface
|
||||
/**
|
||||
* Get all budgets with these ID's.
|
||||
*
|
||||
* @param array $budgetIds
|
||||
* @param array $budgetIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -172,35 +172,35 @@ interface BudgetRepositoryInterface
|
||||
public function getMaxOrder(): int;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(Budget $budget): ?string;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchBudget(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param int $order
|
||||
* @param Budget $budget
|
||||
* @param int $order
|
||||
*/
|
||||
public function setBudgetOrder(Budget $budget, int $order): void;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Used in the v2 API to calculate the amount of money spent in all active budgets.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -214,7 +214,7 @@ interface BudgetRepositoryInterface
|
||||
public function spentInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Budget
|
||||
* @throws FireflyException
|
||||
@@ -222,8 +222,8 @@ interface BudgetRepositoryInterface
|
||||
public function store(array $data): Budget;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param array $data
|
||||
* @param Budget $budget
|
||||
* @param array $data
|
||||
*
|
||||
* @return Budget
|
||||
*/
|
||||
|
@@ -41,9 +41,9 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -87,19 +87,9 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
@@ -148,14 +138,24 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO this method does not include multi currency. It just counts.
|
||||
* TODO this probably also applies to the other "sumExpenses" methods.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -35,9 +35,9 @@ use Illuminate\Support\Collection;
|
||||
interface NoBudgetRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
@@ -45,14 +45,14 @@ interface NoBudgetRepositoryInterface
|
||||
public function getNoBudgetPeriodReport(Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
@@ -60,10 +60,10 @@ interface NoBudgetRepositoryInterface
|
||||
public function spentInPeriodWoBudgetMc(Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -47,7 +47,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
* A method that returns the amount of money budgeted per day for this budget,
|
||||
* on average.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -78,10 +78,10 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
* This method is being used to generate the budget overview in the year/multi-year report. Its used
|
||||
* in both the year/multi-year budget overview AND in the accompanying chart.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
@@ -129,10 +129,10 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
* which have the specified budget set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $budgets
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -201,9 +201,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
@@ -211,10 +211,21 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return Collection
|
||||
*/
|
||||
private function getBudgets(): Collection
|
||||
{
|
||||
/** @var BudgetRepositoryInterface $repos */
|
||||
$repos = app(BudgetRepositoryInterface::class);
|
||||
|
||||
return $repos->getActiveBudgets();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
@@ -272,19 +283,19 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $budgets
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $budgets
|
||||
* @param TransactionCurrency|null $currency
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public function sumExpenses(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $budgets = null,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $budgets = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array {
|
||||
//Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
@@ -379,9 +390,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
* For now, simply refer to whichever repository holds this function.
|
||||
* TODO perhaps better in the future.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Budget $budget
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -392,15 +403,4 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
return $blRepository->getBudgetLimits($budget, $start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
private function getBudgets(): Collection
|
||||
{
|
||||
/** @var BudgetRepositoryInterface $repos */
|
||||
$repos = app(BudgetRepositoryInterface::class);
|
||||
|
||||
return $repos->getActiveBudgets();
|
||||
}
|
||||
}
|
||||
|
@@ -39,17 +39,17 @@ interface OperationsRepositoryInterface
|
||||
* A method that returns the amount of money budgeted per day for this budget,
|
||||
* on average.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function budgetedPerDay(Budget $budget): string;
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
@@ -61,28 +61,28 @@ interface OperationsRepositoryInterface
|
||||
* which have the specified budget set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $budgets
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
|
||||
/**
|
||||
* Return multi-currency spent information.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
@@ -91,20 +91,21 @@ interface OperationsRepositoryInterface
|
||||
|
||||
/**
|
||||
* TODO this method was marked as deprecated but I'm not sure why.
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $budgets
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $budgets
|
||||
* @param TransactionCurrency|null $currency
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function sumExpenses(
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $budgets = null,
|
||||
Carbon $start,
|
||||
Carbon $end,
|
||||
?Collection $accounts = null,
|
||||
?Collection $budgets = null,
|
||||
?TransactionCurrency $currency = null
|
||||
): array;
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
@@ -107,32 +107,18 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category or return NULL
|
||||
* Returns a list of all the categories belonging to a user.
|
||||
*
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category|null
|
||||
* @return Collection
|
||||
*/
|
||||
public function find(int $categoryId): ?Category
|
||||
public function getCategories(): Collection
|
||||
{
|
||||
return $this->user->categories()->find($categoryId);
|
||||
return $this->user->categories()->with(['attachments'])->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function findByName(string $name): ?Category
|
||||
{
|
||||
return $this->user->categories()->where('name', $name)->first(['categories.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $categoryId
|
||||
* @param string|null $categoryName
|
||||
* @param int|null $categoryId
|
||||
* @param string|null $categoryName
|
||||
*
|
||||
* @return Category|null
|
||||
* @throws FireflyException
|
||||
@@ -159,154 +145,31 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* Find a category or return NULL
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function firstUseDate(Category $category): ?Carbon
|
||||
public function find(int $categoryId): ?Category
|
||||
{
|
||||
$firstJournalDate = $this->getFirstJournalDate($category);
|
||||
$firstTransactionDate = $this->getFirstTransactionDate($category);
|
||||
|
||||
if (null === $firstTransactionDate && null === $firstJournalDate) {
|
||||
return null;
|
||||
}
|
||||
if (null === $firstTransactionDate) {
|
||||
return $firstJournalDate;
|
||||
}
|
||||
if (null === $firstJournalDate) {
|
||||
return $firstTransactionDate;
|
||||
}
|
||||
|
||||
if ($firstTransactionDate < $firstJournalDate) {
|
||||
return $firstTransactionDate;
|
||||
}
|
||||
|
||||
return $firstJournalDate;
|
||||
return $this->user->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAttachments(Category $category): Collection
|
||||
{
|
||||
$set = $category->attachments()->get();
|
||||
|
||||
/** @var Storage $disk */
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) {
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes = $notes ? $notes->text : '';
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all categories with ID's.
|
||||
* Find a category.
|
||||
*
|
||||
* @param array $categoryIds
|
||||
* @param string $name
|
||||
*
|
||||
* @return Collection
|
||||
* @return Category|null
|
||||
*/
|
||||
public function getByIds(array $categoryIds): Collection
|
||||
public function findByName(string $name): ?Category
|
||||
{
|
||||
return $this->user->categories()->whereIn('id', $categoryIds)->get();
|
||||
return $this->user->categories()->where('name', $name)->first(['categories.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all the categories belonging to a user.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCategories(): Collection
|
||||
{
|
||||
return $this->user->categories()->with(['attachments'])->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getNoteText(Category $category): ?string
|
||||
{
|
||||
$dbNote = $category->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $dbNote->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function lastUseDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
$lastJournalDate = $this->getLastJournalDate($category, $accounts);
|
||||
$lastTransactionDate = $this->getLastTransactionDate($category, $accounts);
|
||||
|
||||
if (null === $lastTransactionDate && null === $lastJournalDate) {
|
||||
return null;
|
||||
}
|
||||
if (null === $lastTransactionDate) {
|
||||
return $lastJournalDate;
|
||||
}
|
||||
if (null === $lastJournalDate) {
|
||||
return $lastTransactionDate;
|
||||
}
|
||||
|
||||
if ($lastTransactionDate > $lastJournalDate) {
|
||||
return $lastTransactionDate;
|
||||
}
|
||||
|
||||
return $lastJournalDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*/
|
||||
public function removeNotes(Category $category): void
|
||||
{
|
||||
$category->notes()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchCategory(string $query, int $limit): Collection
|
||||
{
|
||||
$search = $this->user->categories();
|
||||
if ('' !== $query) {
|
||||
$search->where('name', 'LIKE', sprintf('%%%s%%', $query));
|
||||
}
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
* @throws FireflyException
|
||||
@@ -334,19 +197,21 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
* @throws Exception
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function update(Category $category, array $data): Category
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
/** @var CategoryUpdateService $service */
|
||||
$service = app(CategoryUpdateService::class);
|
||||
$service->setUser($this->user);
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
return $service->update($category, $data);
|
||||
/**
|
||||
* @param Category $category
|
||||
*/
|
||||
public function removeNotes(Category $category): void
|
||||
{
|
||||
$category->notes()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,7 +229,35 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
*
|
||||
*/
|
||||
public function firstUseDate(Category $category): ?Carbon
|
||||
{
|
||||
$firstJournalDate = $this->getFirstJournalDate($category);
|
||||
$firstTransactionDate = $this->getFirstTransactionDate($category);
|
||||
|
||||
if (null === $firstTransactionDate && null === $firstJournalDate) {
|
||||
return null;
|
||||
}
|
||||
if (null === $firstTransactionDate) {
|
||||
return $firstJournalDate;
|
||||
}
|
||||
if (null === $firstJournalDate) {
|
||||
return $firstTransactionDate;
|
||||
}
|
||||
|
||||
if ($firstTransactionDate < $firstJournalDate) {
|
||||
return $firstTransactionDate;
|
||||
}
|
||||
|
||||
return $firstJournalDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -381,7 +274,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -401,8 +294,83 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAttachments(Category $category): Collection
|
||||
{
|
||||
$set = $category->attachments()->get();
|
||||
|
||||
/** @var Storage $disk */
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) {
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes = $notes ? $notes->text : '';
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all categories with ID's.
|
||||
*
|
||||
* @param array $categoryIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getByIds(array $categoryIds): Collection
|
||||
{
|
||||
return $this->user->categories()->whereIn('id', $categoryIds)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getNoteText(Category $category): ?string
|
||||
{
|
||||
$dbNote = $category->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $dbNote->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function lastUseDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
$lastJournalDate = $this->getLastJournalDate($category, $accounts);
|
||||
$lastTransactionDate = $this->getLastTransactionDate($category, $accounts);
|
||||
|
||||
if (null === $lastTransactionDate && null === $lastJournalDate) {
|
||||
return null;
|
||||
}
|
||||
if (null === $lastTransactionDate) {
|
||||
return $lastJournalDate;
|
||||
}
|
||||
if (null === $lastJournalDate) {
|
||||
return $lastTransactionDate;
|
||||
}
|
||||
|
||||
if ($lastTransactionDate > $lastJournalDate) {
|
||||
return $lastTransactionDate;
|
||||
}
|
||||
|
||||
return $lastJournalDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -425,8 +393,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @throws Exception
|
||||
@@ -449,4 +417,36 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchCategory(string $query, int $limit): Collection
|
||||
{
|
||||
$search = $this->user->categories();
|
||||
if ('' !== $query) {
|
||||
$search->where('name', 'LIKE', sprintf('%%%s%%', $query));
|
||||
}
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(Category $category, array $data): Category
|
||||
{
|
||||
/** @var CategoryUpdateService $service */
|
||||
$service = app(CategoryUpdateService::class);
|
||||
$service->setUser($this->user);
|
||||
|
||||
return $service->update($category, $data);
|
||||
}
|
||||
}
|
||||
|
@@ -36,23 +36,23 @@ use Illuminate\Support\Collection;
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function categoryEndsWith(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function categoryStartsWith(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ interface CategoryRepositoryInterface
|
||||
/**
|
||||
* Find a category or return NULL
|
||||
*
|
||||
* @param int $categoryId
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
@@ -75,29 +75,29 @@ interface CategoryRepositoryInterface
|
||||
/**
|
||||
* Find a category.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function findByName(string $name): ?Category;
|
||||
|
||||
/**
|
||||
* @param int|null $categoryId
|
||||
* @param string|null $categoryName
|
||||
* @param int|null $categoryId
|
||||
* @param string|null $categoryName
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function findCategory(?int $categoryId, ?string $categoryName): ?Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function firstUseDate(Category $category): ?Carbon;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -106,7 +106,7 @@ interface CategoryRepositoryInterface
|
||||
/**
|
||||
* Get all categories with ID's.
|
||||
*
|
||||
* @param array $categoryIds
|
||||
* @param array $categoryIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -120,7 +120,7 @@ interface CategoryRepositoryInterface
|
||||
public function getCategories(): Collection;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -129,8 +129,8 @@ interface CategoryRepositoryInterface
|
||||
/**
|
||||
* Return most recent transaction(journal) date or null when never used before.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -139,25 +139,25 @@ interface CategoryRepositoryInterface
|
||||
/**
|
||||
* Remove notes.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
*/
|
||||
public function removeNotes(Category $category): void;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchCategory(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
* @throws FireflyException
|
||||
@@ -165,16 +165,16 @@ interface CategoryRepositoryInterface
|
||||
public function store(array $data): Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param array $data
|
||||
* @param Category $category
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function update(Category $category, array $data): Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param string $notes
|
||||
* @param Category $category
|
||||
* @param string $notes
|
||||
*/
|
||||
public function updateNotes(Category $category, string $notes): void;
|
||||
}
|
||||
|
@@ -43,9 +43,9 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
* which have no category set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -90,14 +90,24 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
|
||||
* which have no category set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -142,22 +152,12 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period without a category, grouped per currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -192,9 +192,9 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
/**
|
||||
* Sum of income journals in period without a category, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -39,9 +39,9 @@ interface NoCategoryRepositoryInterface
|
||||
* which have no category set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -52,25 +52,25 @@ interface NoCategoryRepositoryInterface
|
||||
* which have no category set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period without a category, grouped per currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -79,9 +79,9 @@ interface NoCategoryRepositoryInterface
|
||||
/**
|
||||
* Sum of income journals in period without a category, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -90,9 +90,9 @@ interface NoCategoryRepositoryInterface
|
||||
/**
|
||||
* Sum of transfers in period without a category, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -45,10 +45,10 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
*
|
||||
* First currency, then categories.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -116,15 +116,35 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all the categories belonging to a user.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function getCategories(): Collection
|
||||
{
|
||||
return $this->user->categories()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
|
||||
* which have the specified category set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -321,23 +341,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of categories, grouped per currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -378,10 +388,10 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/**
|
||||
* Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -421,10 +431,10 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/**
|
||||
* Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -460,14 +470,4 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all the categories belonging to a user.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function getCategories(): Collection
|
||||
{
|
||||
return $this->user->categories()->get();
|
||||
}
|
||||
}
|
||||
|
@@ -39,10 +39,10 @@ interface OperationsRepositoryInterface
|
||||
* which have the specified category set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -53,10 +53,10 @@ interface OperationsRepositoryInterface
|
||||
* which have the specified category set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -68,10 +68,10 @@ interface OperationsRepositoryInterface
|
||||
* It excludes any transfers between the listed accounts.
|
||||
* It's grouped per currency, with as few details in the array as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -83,27 +83,27 @@ interface OperationsRepositoryInterface
|
||||
* It excludes any transfers between the listed accounts.
|
||||
* It's grouped per currency, with as few details in the array as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTransferredOut(Carbon $start, Carbon $end, Collection $accounts, ?Collection $categories = null): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of categories, grouped per currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -112,10 +112,10 @@ interface OperationsRepositoryInterface
|
||||
/**
|
||||
* Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -124,10 +124,10 @@ interface OperationsRepositoryInterface
|
||||
/**
|
||||
* Sum of transfers in period for a set of categories, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -52,20 +52,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countJournals(TransactionCurrency $currency): int
|
||||
{
|
||||
$count = $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count();
|
||||
|
||||
// also count foreign:
|
||||
return $count + Transaction::where('foreign_currency_id', $currency->id)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
@@ -78,7 +65,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return string|null
|
||||
* @throws FireflyException
|
||||
@@ -166,7 +153,36 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countJournals(TransactionCurrency $currency): int
|
||||
{
|
||||
$count = $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count();
|
||||
|
||||
// also count foreign:
|
||||
return $count + Transaction::where('foreign_currency_id', $currency->id)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -186,7 +202,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
/**
|
||||
* Disables a currency
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*/
|
||||
public function disable(TransactionCurrency $currency): void
|
||||
{
|
||||
@@ -194,16 +210,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
$currency->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* Enables a currency
|
||||
*/
|
||||
public function enable(TransactionCurrency $currency): void
|
||||
{
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -224,34 +230,20 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by ID, return NULL if not found.
|
||||
*
|
||||
* @param int $currencyId
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
* @param TransactionCurrency $currency
|
||||
* Enables a currency
|
||||
*/
|
||||
public function find(int $currencyId): ?TransactionCurrency
|
||||
public function enable(TransactionCurrency $currency): void
|
||||
{
|
||||
return TransactionCurrency::find($currencyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by currency code, return NULL if unfound.
|
||||
*
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
public function findByCode(string $currencyCode): ?TransactionCurrency
|
||||
{
|
||||
return TransactionCurrency::where('code', $currencyCode)->first();
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by currency code, return NULL if unfound.
|
||||
* Used in Import Currency!
|
||||
*
|
||||
* @param string $currencyCode
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
* @deprecated
|
||||
@@ -264,7 +256,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by currency name.
|
||||
*
|
||||
* @param string $currencyName
|
||||
* @param string $currencyName
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -277,7 +269,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
* Find by currency name or return null.
|
||||
* Used in Import Currency!
|
||||
*
|
||||
* @param string $currencyName
|
||||
* @param string $currencyName
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
* @deprecated
|
||||
@@ -290,7 +282,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by currency symbol.
|
||||
*
|
||||
* @param string $currencySymbol
|
||||
* @param string $currencySymbol
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -303,7 +295,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
* Find by currency symbol or return NULL
|
||||
* Used in Import Currency!
|
||||
*
|
||||
* @param string $currencySymbol
|
||||
* @param string $currencySymbol
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
* @deprecated
|
||||
@@ -316,8 +308,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by object, ID or code. Returns user default or system default.
|
||||
*
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
* @throws FireflyException
|
||||
@@ -348,8 +340,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by object, ID or code. Returns NULL if nothing found.
|
||||
*
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -370,23 +362,31 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
* Find by ID, return NULL if not found.
|
||||
*
|
||||
* @param int $currencyId
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
public function get(): Collection
|
||||
public function find(int $currencyId): ?TransactionCurrency
|
||||
{
|
||||
return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get();
|
||||
return TransactionCurrency::find($currencyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
* Find by currency code, return NULL if unfound.
|
||||
*
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
public function getAll(): Collection
|
||||
public function findByCode(string $currencyCode): ?TransactionCurrency
|
||||
{
|
||||
return TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||
return TransactionCurrency::where('code', $currencyCode)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param array $ids
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -396,7 +396,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Preference $preference
|
||||
* @param Preference $preference
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
@@ -413,9 +413,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
/**
|
||||
* Get currency exchange rate.
|
||||
*
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return CurrencyExchangeRate|null
|
||||
*/
|
||||
@@ -451,8 +451,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -468,10 +468,11 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
|
||||
/**
|
||||
* TODO must be a factory
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
* @param float $rate
|
||||
*
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
* @param float $rate
|
||||
* @return CurrencyExchangeRate
|
||||
*/
|
||||
public function setExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date, float $rate): CurrencyExchangeRate
|
||||
@@ -488,9 +489,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
@@ -498,7 +499,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
* @throws FireflyException
|
||||
@@ -517,8 +518,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $data
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
|
@@ -38,14 +38,14 @@ use Illuminate\Support\Collection;
|
||||
interface CurrencyRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countJournals(TransactionCurrency $currency): int;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -54,14 +54,14 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Currency is in use where exactly.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function currencyInUseAt(TransactionCurrency $currency): ?string;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -70,14 +70,14 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Disables a currency
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*/
|
||||
public function disable(TransactionCurrency $currency): void;
|
||||
|
||||
/**
|
||||
* Enables a currency
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*/
|
||||
public function enable(TransactionCurrency $currency): void;
|
||||
|
||||
@@ -89,7 +89,7 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by ID, return NULL if not found.
|
||||
*
|
||||
* @param int $currencyId
|
||||
* @param int $currencyId
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -98,7 +98,7 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by currency code, return NULL if unfound.
|
||||
*
|
||||
* @param string $currencyCode
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -107,7 +107,7 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by currency code, return NULL if unfound.
|
||||
*
|
||||
* @param string $currencyCode
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -116,7 +116,7 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by currency name.
|
||||
*
|
||||
* @param string $currencyName
|
||||
* @param string $currencyName
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -125,7 +125,7 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by currency name.
|
||||
*
|
||||
* @param string $currencyName
|
||||
* @param string $currencyName
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -134,7 +134,7 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by currency symbol.
|
||||
*
|
||||
* @param string $currencySymbol
|
||||
* @param string $currencySymbol
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -143,7 +143,7 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by currency symbol.
|
||||
*
|
||||
* @param string $currencySymbol
|
||||
* @param string $currencySymbol
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -152,8 +152,8 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by object, ID or code. Returns user default or system default.
|
||||
*
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
@@ -162,8 +162,8 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Find by object, ID or code. Returns NULL if nothing found.
|
||||
*
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
* @param int|null $currencyId
|
||||
* @param string|null $currencyCode
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
@@ -180,14 +180,14 @@ interface CurrencyRepositoryInterface
|
||||
public function getAll(): Collection;
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param array $ids
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getByIds(array $ids): Collection;
|
||||
|
||||
/**
|
||||
* @param Preference $preference
|
||||
* @param Preference $preference
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
@@ -196,24 +196,24 @@ interface CurrencyRepositoryInterface
|
||||
/**
|
||||
* Get currency exchange rate.
|
||||
*
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return CurrencyExchangeRate|null
|
||||
*/
|
||||
public function getExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date): ?CurrencyExchangeRate;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFallbackCurrency(TransactionCurrency $currency): bool;
|
||||
|
||||
/**
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -221,21 +221,22 @@ interface CurrencyRepositoryInterface
|
||||
|
||||
/**
|
||||
* TODO must be a factory
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
* @param float $rate
|
||||
*
|
||||
* @param TransactionCurrency $fromCurrency
|
||||
* @param TransactionCurrency $toCurrency
|
||||
* @param Carbon $date
|
||||
* @param float $rate
|
||||
* @return CurrencyExchangeRate
|
||||
*/
|
||||
public function setExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date, float $rate): CurrencyExchangeRate;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
* @throws FireflyException
|
||||
@@ -243,8 +244,8 @@ interface CurrencyRepositoryInterface
|
||||
public function store(array $data): TransactionCurrency;
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $data
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
|
@@ -42,7 +42,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
|
||||
/**
|
||||
* Returns transaction by ID. Used to validate attachments.
|
||||
*
|
||||
* @param int $transactionId
|
||||
* @param int $transactionId
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
@@ -59,7 +59,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
|
||||
*
|
||||
* Return all attachments for journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -94,7 +94,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
|
||||
/**
|
||||
* Get all piggy bank events for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -111,9 +111,9 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
|
@@ -37,7 +37,7 @@ interface JournalAPIRepositoryInterface
|
||||
/**
|
||||
* Returns transaction by ID. Used to validate attachments.
|
||||
*
|
||||
* @param int $transactionId
|
||||
* @param int $transactionId
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ interface JournalAPIRepositoryInterface
|
||||
/**
|
||||
* Return all attachments for journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ interface JournalAPIRepositoryInterface
|
||||
/**
|
||||
* Return all journal links for journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -64,14 +64,14 @@ interface JournalAPIRepositoryInterface
|
||||
/**
|
||||
* Get all piggy bank events for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPiggyBankEvents(TransactionJournal $journal): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Get all transaction journals with a specific type, regardless of user.
|
||||
*
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return the ID of the budget linked to the journal (if any) or the transactions (if any).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -76,7 +76,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return the ID of the category linked to the journal (if any) or to the transactions (if any).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -107,8 +107,8 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return Carbon value of a meta field (or NULL).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|Carbon
|
||||
*/
|
||||
@@ -137,8 +137,8 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return value of a meta field (or NULL) as a string.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -177,7 +177,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return text of a note attached to journal, or NULL
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -218,7 +218,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return all tags as strings in an array.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -228,9 +228,9 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ interface JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Get all transaction journals with a specific type, regardless of user.
|
||||
*
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ interface JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return the ID of the budget linked to the journal (if any) or the transactions (if any).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ interface JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return the ID of the category linked to the journal (if any) or to the transactions (if any).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -71,8 +71,8 @@ interface JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return Carbon value of a meta field (or NULL).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|Carbon
|
||||
*/
|
||||
@@ -81,8 +81,8 @@ interface JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return value of a meta field (or NULL).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -91,7 +91,7 @@ interface JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return text of a note attached to journal, or NULL
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -108,14 +108,14 @@ interface JournalCLIRepositoryInterface
|
||||
/**
|
||||
* Return all tags as strings in an array.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTags(TransactionJournal $journal): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
*/
|
||||
public function destroyGroup(TransactionGroup $transactionGroup): void
|
||||
@@ -60,7 +60,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
*/
|
||||
public function destroyJournal(TransactionJournal $journal): void
|
||||
@@ -70,18 +70,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$service->destroy($journal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a specific journal.
|
||||
*
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
public function find(int $journalId): ?TransactionJournal
|
||||
{
|
||||
return $this->user->transactionJournals()->find($journalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -128,7 +116,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
/**
|
||||
* Return total amount of journal. Is always positive.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -165,7 +153,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -183,8 +171,8 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
/**
|
||||
* Return Carbon value of a meta field (or NULL).
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param string $field
|
||||
* @param int $journalId
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|Carbon
|
||||
*/
|
||||
@@ -224,7 +212,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*/
|
||||
public function reconcileById(int $journalId): void
|
||||
{
|
||||
@@ -233,11 +221,23 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$journal?->transactions()->update(['reconciled' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a specific journal.
|
||||
*
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
public function find(int $journalId): ?TransactionJournal
|
||||
{
|
||||
return $this->user->transactionJournals()->find($journalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search in journal descriptions.
|
||||
*
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -253,9 +253,9 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
@@ -265,8 +265,8 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
/**
|
||||
* Update budget for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $budgetId
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $budgetId
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
@@ -290,8 +290,8 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
/**
|
||||
* Update category for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $category
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $category
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
@@ -314,8 +314,8 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
/**
|
||||
* Update tag(s) for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $tags
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $tags
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
|
@@ -41,28 +41,28 @@ interface JournalRepositoryInterface
|
||||
/**
|
||||
* Deletes a transaction group.
|
||||
*
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*/
|
||||
public function destroyGroup(TransactionGroup $transactionGroup): void;
|
||||
|
||||
/**
|
||||
* Deletes a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
public function destroyJournal(TransactionJournal $journal): void;
|
||||
|
||||
/**
|
||||
* Find a specific journal.
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
public function find(int $journalId): ?TransactionJournal;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -78,7 +78,7 @@ interface JournalRepositoryInterface
|
||||
/**
|
||||
* Returns the destination account of the journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
@@ -88,7 +88,7 @@ interface JournalRepositoryInterface
|
||||
/**
|
||||
* Return total amount of journal. Is always positive.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -100,7 +100,7 @@ interface JournalRepositoryInterface
|
||||
public function getLast(): ?TransactionJournal;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -109,8 +109,8 @@ interface JournalRepositoryInterface
|
||||
/**
|
||||
* Return Carbon value of a meta field (or NULL).
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param string $field
|
||||
* @param int $journalId
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|Carbon
|
||||
*/
|
||||
@@ -119,7 +119,7 @@ interface JournalRepositoryInterface
|
||||
/**
|
||||
* Returns the source account of the journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
@@ -129,30 +129,30 @@ interface JournalRepositoryInterface
|
||||
/**
|
||||
* TODO Maybe to account repository? Do this wen reconcile is API only.
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*/
|
||||
public function reconcileById(int $journalId): void;
|
||||
|
||||
/**
|
||||
* Search in journal descriptions.
|
||||
*
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
* @param string $search
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchJournalDescriptions(string $search, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Update budget for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $budgetId
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $budgetId
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
@@ -161,8 +161,8 @@ interface JournalRepositoryInterface
|
||||
/**
|
||||
* Update category for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $category
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $category
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
@@ -171,8 +171,8 @@ interface JournalRepositoryInterface
|
||||
/**
|
||||
* Update tag(s) for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $tags
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $tags
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
|
@@ -43,7 +43,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* @param LinkType $linkType
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -53,8 +53,8 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LinkType $linkType
|
||||
* @param LinkType|null $moveTo
|
||||
* @param LinkType $linkType
|
||||
* @param LinkType|null $moveTo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -69,7 +69,29 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
* @param LinkType $linkType
|
||||
* @param array $data
|
||||
*
|
||||
* @return LinkType
|
||||
*/
|
||||
public function update(LinkType $linkType, array $data): LinkType
|
||||
{
|
||||
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
|
||||
$linkType->name = $data['name'];
|
||||
}
|
||||
if (array_key_exists('inward', $data) && '' !== (string)$data['inward']) {
|
||||
$linkType->inward = $data['inward'];
|
||||
}
|
||||
if (array_key_exists('outward', $data) && '' !== (string)$data['outward']) {
|
||||
$linkType->outward = $data['outward'];
|
||||
}
|
||||
$linkType->save();
|
||||
|
||||
return $linkType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
@@ -82,35 +104,11 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $linkTypeId
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
public function find(int $linkTypeId): ?LinkType
|
||||
{
|
||||
return LinkType::find($linkTypeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $name
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
public function findByName(string $name = null): ?LinkType
|
||||
{
|
||||
if (null === $name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return LinkType::where('name', $name)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if link exists between journals.
|
||||
*
|
||||
* @param TransactionJournal $one
|
||||
* @param TransactionJournal $two
|
||||
* @param TransactionJournal $one
|
||||
* @param TransactionJournal $two
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -123,34 +121,10 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
return $count + $opposingCount > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if such a link already exists (and get it).
|
||||
*
|
||||
* @param LinkType $linkType
|
||||
* @param TransactionJournal $inward
|
||||
* @param TransactionJournal $outward
|
||||
*
|
||||
* @return TransactionJournalLink|null
|
||||
*/
|
||||
public function findSpecificLink(LinkType $linkType, TransactionJournal $inward, TransactionJournal $outward): ?TransactionJournalLink
|
||||
{
|
||||
return TransactionJournalLink::where('link_type_id', $linkType->id)
|
||||
->where('source_id', $inward->id)
|
||||
->where('destination_id', $outward->id)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return LinkType::orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of all journal ID's for this type of link.
|
||||
*
|
||||
* @param LinkType $linkType
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -163,10 +137,18 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
return array_unique(array_merge($sources, $destinations));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return LinkType::orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the journal links (of a specific type).
|
||||
*
|
||||
* @param LinkType|null $linkType
|
||||
* @param LinkType|null $linkType
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -200,7 +182,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
/**
|
||||
* Return list of existing connections.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -218,9 +200,9 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
@@ -228,7 +210,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return LinkType
|
||||
*/
|
||||
@@ -247,9 +229,9 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
/**
|
||||
* Store link between two journals.
|
||||
*
|
||||
* @param array $information
|
||||
* @param TransactionJournal $inward
|
||||
* @param TransactionJournal $outward
|
||||
* @param array $information
|
||||
* @param TransactionJournal $inward
|
||||
* @param TransactionJournal $outward
|
||||
*
|
||||
* @return TransactionJournalLink|null
|
||||
* @throws Exception
|
||||
@@ -294,18 +276,65 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
* @param int $linkTypeId
|
||||
*
|
||||
* @return bool
|
||||
* @return LinkType|null
|
||||
*/
|
||||
public function switchLink(TransactionJournalLink $link): bool
|
||||
public function find(int $linkTypeId): ?LinkType
|
||||
{
|
||||
$source = $link->source_id;
|
||||
$link->source_id = $link->destination_id;
|
||||
$link->destination_id = $source;
|
||||
$link->save();
|
||||
return LinkType::find($linkTypeId);
|
||||
}
|
||||
|
||||
return true;
|
||||
/**
|
||||
* @param string|null $name
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
public function findByName(string $name = null): ?LinkType
|
||||
{
|
||||
if (null === $name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return LinkType::where('name', $name)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* See if such a link already exists (and get it).
|
||||
*
|
||||
* @param LinkType $linkType
|
||||
* @param TransactionJournal $inward
|
||||
* @param TransactionJournal $outward
|
||||
*
|
||||
* @return TransactionJournalLink|null
|
||||
*/
|
||||
public function findSpecificLink(LinkType $linkType, TransactionJournal $inward, TransactionJournal $outward): ?TransactionJournalLink
|
||||
{
|
||||
return TransactionJournalLink::where('link_type_id', $linkType->id)
|
||||
->where('source_id', $inward->id)
|
||||
->where('destination_id', $outward->id)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
* @param string $text
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setNoteText(TransactionJournalLink $link, string $text): void
|
||||
{
|
||||
$dbNote = $link->notes()->first();
|
||||
if ('' !== $text) {
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($link);
|
||||
}
|
||||
$dbNote->text = trim($text);
|
||||
$dbNote->save();
|
||||
|
||||
return;
|
||||
}
|
||||
$dbNote?->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,32 +352,25 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LinkType $linkType
|
||||
* @param array $data
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return LinkType
|
||||
* @return bool
|
||||
*/
|
||||
public function update(LinkType $linkType, array $data): LinkType
|
||||
public function switchLink(TransactionJournalLink $link): bool
|
||||
{
|
||||
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
|
||||
$linkType->name = $data['name'];
|
||||
}
|
||||
if (array_key_exists('inward', $data) && '' !== (string)$data['inward']) {
|
||||
$linkType->inward = $data['inward'];
|
||||
}
|
||||
if (array_key_exists('outward', $data) && '' !== (string)$data['outward']) {
|
||||
$linkType->outward = $data['outward'];
|
||||
}
|
||||
$linkType->save();
|
||||
$source = $link->source_id;
|
||||
$link->source_id = $link->destination_id;
|
||||
$link->destination_id = $source;
|
||||
$link->save();
|
||||
|
||||
return $linkType;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing transaction journal link.
|
||||
*
|
||||
* @param TransactionJournalLink $journalLink
|
||||
* @param array $data
|
||||
* @param TransactionJournalLink $journalLink
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionJournalLink
|
||||
* @throws Exception
|
||||
@@ -375,26 +397,4 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
|
||||
return $journalLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
* @param string $text
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setNoteText(TransactionJournalLink $link, string $text): void
|
||||
{
|
||||
$dbNote = $link->notes()->first();
|
||||
if ('' !== $text) {
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($link);
|
||||
}
|
||||
$dbNote->text = trim($text);
|
||||
$dbNote->save();
|
||||
|
||||
return;
|
||||
}
|
||||
$dbNote?->delete();
|
||||
}
|
||||
}
|
||||
|
@@ -36,29 +36,29 @@ use Illuminate\Support\Collection;
|
||||
interface LinkTypeRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param LinkType $linkType
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countJournals(LinkType $linkType): int;
|
||||
|
||||
/**
|
||||
* @param LinkType $linkType
|
||||
* @param LinkType|null $moveTo
|
||||
* @param LinkType $linkType
|
||||
* @param LinkType|null $moveTo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(LinkType $linkType, LinkType $moveTo = null): bool;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroyLink(TransactionJournalLink $link): bool;
|
||||
|
||||
/**
|
||||
* @param int $linkTypeId
|
||||
* @param int $linkTypeId
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
@@ -67,7 +67,7 @@ interface LinkTypeRepositoryInterface
|
||||
/**
|
||||
* Find link type by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param string|null $name
|
||||
*
|
||||
* @return LinkType|null
|
||||
*/
|
||||
@@ -76,8 +76,8 @@ interface LinkTypeRepositoryInterface
|
||||
/**
|
||||
* Check if link exists between journals.
|
||||
*
|
||||
* @param TransactionJournal $one
|
||||
* @param TransactionJournal $two
|
||||
* @param TransactionJournal $one
|
||||
* @param TransactionJournal $two
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -86,9 +86,9 @@ interface LinkTypeRepositoryInterface
|
||||
/**
|
||||
* See if such a link already exists (and get it).
|
||||
*
|
||||
* @param LinkType $linkType
|
||||
* @param TransactionJournal $inward
|
||||
* @param TransactionJournal $outward
|
||||
* @param LinkType $linkType
|
||||
* @param TransactionJournal $inward
|
||||
* @param TransactionJournal $outward
|
||||
*
|
||||
* @return TransactionJournalLink|null
|
||||
*/
|
||||
@@ -102,14 +102,14 @@ interface LinkTypeRepositoryInterface
|
||||
/**
|
||||
* Return array of all journal ID's for this type of link.
|
||||
*
|
||||
* @param LinkType $linkType
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJournalIds(LinkType $linkType): array;
|
||||
|
||||
/**
|
||||
* @param LinkType|null $linkType
|
||||
* @param LinkType|null $linkType
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -118,19 +118,19 @@ interface LinkTypeRepositoryInterface
|
||||
/**
|
||||
* Return list of existing connections.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getLinks(TransactionJournal $journal): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return LinkType
|
||||
*/
|
||||
@@ -139,31 +139,31 @@ interface LinkTypeRepositoryInterface
|
||||
/**
|
||||
* Store link between two journals.
|
||||
*
|
||||
* @param array $information
|
||||
* @param TransactionJournal $inward
|
||||
* @param TransactionJournal $outward
|
||||
* @param array $information
|
||||
* @param TransactionJournal $inward
|
||||
* @param TransactionJournal $outward
|
||||
*
|
||||
* @return TransactionJournalLink|null
|
||||
*/
|
||||
public function storeLink(array $information, TransactionJournal $inward, TransactionJournal $outward): ?TransactionJournalLink;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function switchLink(TransactionJournalLink $link): bool;
|
||||
|
||||
/**
|
||||
* @param int $linkId
|
||||
* @param int $linkId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function switchLinkById(int $linkId): bool;
|
||||
|
||||
/**
|
||||
* @param LinkType $linkType
|
||||
* @param array $data
|
||||
* @param LinkType $linkType
|
||||
* @param array $data
|
||||
*
|
||||
* @return LinkType
|
||||
*/
|
||||
@@ -172,8 +172,8 @@ interface LinkTypeRepositoryInterface
|
||||
/**
|
||||
* Update an existing transaction journal link.
|
||||
*
|
||||
* @param TransactionJournalLink $journalLink
|
||||
* @param array $data
|
||||
* @param TransactionJournalLink $journalLink
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionJournalLink
|
||||
*/
|
||||
|
@@ -32,17 +32,7 @@ use FireflyIII\Models\ObjectGroup;
|
||||
trait CreatesObjectGroups
|
||||
{
|
||||
/**
|
||||
* @param string $title
|
||||
*
|
||||
* @return null|ObjectGroup
|
||||
*/
|
||||
protected function findObjectGroup(string $title): ?ObjectGroup
|
||||
{
|
||||
return $this->user->objectGroups()->where('title', $title)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $groupId
|
||||
* @param int $groupId
|
||||
*
|
||||
* @return ObjectGroup|null
|
||||
*/
|
||||
@@ -52,7 +42,7 @@ trait CreatesObjectGroups
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $title
|
||||
*
|
||||
* @return ObjectGroup|null
|
||||
*/
|
||||
@@ -82,7 +72,7 @@ trait CreatesObjectGroups
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $title
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -90,4 +80,14 @@ trait CreatesObjectGroups
|
||||
{
|
||||
return 1 === $this->user->objectGroups()->where('title', $title)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*
|
||||
* @return null|ObjectGroup
|
||||
*/
|
||||
protected function findObjectGroup(string $title): ?ObjectGroup
|
||||
{
|
||||
return $this->user->objectGroups()->where('title', $title)->first();
|
||||
}
|
||||
}
|
||||
|
@@ -53,6 +53,17 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->objectGroups()
|
||||
->with(['piggyBanks', 'bills'])
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -82,17 +93,6 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
$objectGroup->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->objectGroups()
|
||||
->with(['piggyBanks', 'bills'])
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -131,8 +131,8 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -151,6 +151,34 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
return $dbQuery->take($limit)->get(['object_groups.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function update(ObjectGroup $objectGroup, array $data): ObjectGroup
|
||||
{
|
||||
if (array_key_exists('title', $data)) {
|
||||
$objectGroup->title = $data['title'];
|
||||
}
|
||||
|
||||
if (array_key_exists('order', $data)) {
|
||||
$this->setOrder($objectGroup, (int)$data['order']);
|
||||
}
|
||||
|
||||
$objectGroup->save();
|
||||
|
||||
return $objectGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -179,32 +207,4 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
|
||||
return $objectGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function update(ObjectGroup $objectGroup, array $data): ObjectGroup
|
||||
{
|
||||
if (array_key_exists('title', $data)) {
|
||||
$objectGroup->title = $data['title'];
|
||||
}
|
||||
|
||||
if (array_key_exists('order', $data)) {
|
||||
$this->setOrder($objectGroup, (int)$data['order']);
|
||||
}
|
||||
|
||||
$objectGroup->save();
|
||||
|
||||
return $objectGroup;
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ interface ObjectGroupRepositoryInterface
|
||||
public function deleteEmpty(): void;
|
||||
|
||||
/**
|
||||
* @param ObjectGroup $objectGroup
|
||||
* @param ObjectGroup $objectGroup
|
||||
*/
|
||||
public function destroy(ObjectGroup $objectGroup): void;
|
||||
|
||||
@@ -55,14 +55,14 @@ interface ObjectGroupRepositoryInterface
|
||||
public function get(): Collection;
|
||||
|
||||
/**
|
||||
* @param ObjectGroup $objectGroup
|
||||
* @param ObjectGroup $objectGroup
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBills(ObjectGroup $objectGroup): Collection;
|
||||
|
||||
/**
|
||||
* @param ObjectGroup $objectGroup
|
||||
* @param ObjectGroup $objectGroup
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -74,29 +74,29 @@ interface ObjectGroupRepositoryInterface
|
||||
public function resetOrder(): void;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function search(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param ObjectGroup $objectGroup
|
||||
* @param int $newOrder
|
||||
* @param ObjectGroup $objectGroup
|
||||
* @param int $newOrder
|
||||
*
|
||||
* @return ObjectGroup
|
||||
*/
|
||||
public function setOrder(ObjectGroup $objectGroup, int $newOrder): ObjectGroup;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param ObjectGroup $objectGroup
|
||||
* @param array $data
|
||||
* @param ObjectGroup $objectGroup
|
||||
* @param array $data
|
||||
*
|
||||
* @return ObjectGroup
|
||||
*/
|
||||
|
@@ -43,10 +43,38 @@ trait ModifiesPiggyBanks
|
||||
{
|
||||
use CreatesObjectGroups;
|
||||
|
||||
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void
|
||||
{
|
||||
Log::debug(sprintf('addAmountToRepetition: %s', $amount));
|
||||
if (-1 === bccomp($amount, '0')) {
|
||||
Log::debug('Remove amount.');
|
||||
$this->removeAmount($repetition->piggyBank, bcmul($amount, '-1'), $journal);
|
||||
}
|
||||
if (1 === bccomp($amount, '0')) {
|
||||
Log::debug('Add amount.');
|
||||
$this->addAmount($repetition->piggyBank, $amount, $journal);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool
|
||||
{
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
if (null === $repetition) {
|
||||
return false;
|
||||
}
|
||||
$repetition->currentamount = bcsub($repetition->currentamount, $amount);
|
||||
$repetition->save();
|
||||
|
||||
Log::debug('addAmount [a]: Trigger change for negative amount.');
|
||||
event(new ChangedPiggyBankAmount($piggyBank, bcmul($amount, '-1'), $journal, null));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param TransactionJournal|null $journal
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param TransactionJournal|null $journal
|
||||
* @return bool
|
||||
*/
|
||||
public function addAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool
|
||||
@@ -65,22 +93,9 @@ trait ModifiesPiggyBanks
|
||||
return true;
|
||||
}
|
||||
|
||||
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void
|
||||
{
|
||||
Log::debug(sprintf('addAmountToRepetition: %s', $amount));
|
||||
if (-1 === bccomp($amount, '0')) {
|
||||
Log::debug('Remove amount.');
|
||||
$this->removeAmount($repetition->piggyBank, bcmul($amount, '-1'), $journal);
|
||||
}
|
||||
if (1 === bccomp($amount, '0')) {
|
||||
Log::debug('Add amount.');
|
||||
$this->addAmount($repetition->piggyBank, $amount, $journal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
*
|
||||
* @return bool
|
||||
* @throws JsonException
|
||||
@@ -110,8 +125,8 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -127,7 +142,7 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
@@ -140,21 +155,6 @@ trait ModifiesPiggyBanks
|
||||
return true;
|
||||
}
|
||||
|
||||
public function removeAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool
|
||||
{
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
if (null === $repetition) {
|
||||
return false;
|
||||
}
|
||||
$repetition->currentamount = bcsub($repetition->currentamount, $amount);
|
||||
$repetition->save();
|
||||
|
||||
Log::debug('addAmount [a]: Trigger change for negative amount.');
|
||||
event(new ChangedPiggyBankAmount($piggyBank, bcmul($amount, '-1'), $journal, null));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -166,25 +166,8 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct order of piggies in case of issues.
|
||||
*/
|
||||
public function resetOrder(): void
|
||||
{
|
||||
$set = $this->user->piggyBanks()->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']);
|
||||
$current = 1;
|
||||
foreach ($set as $piggyBank) {
|
||||
if ((int)$piggyBank->order !== $current) {
|
||||
Log::debug(sprintf('Piggy bank #%d ("%s") was at place %d but should be on %d', $piggyBank->id, $piggyBank->name, $piggyBank->order, $current));
|
||||
$piggyBank->order = $current;
|
||||
$piggyBank->save();
|
||||
}
|
||||
$current++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
@@ -228,35 +211,7 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool
|
||||
{
|
||||
$oldOrder = (int)$piggyBank->order;
|
||||
Log::debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->piggyBanks()->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
|
||||
->where('piggy_banks.id', '!=', $piggyBank->id)
|
||||
->decrement('piggy_banks.order');
|
||||
$piggyBank->order = $newOrder;
|
||||
Log::debug(sprintf('Order of piggy #%d ("%s") is now %d', $piggyBank->id, $piggyBank->name, $newOrder));
|
||||
$piggyBank->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->user->piggyBanks()->where('piggy_banks.order', '>=', $newOrder)->where('piggy_banks.order', '<', $oldOrder)
|
||||
->where('piggy_banks.id', '!=', $piggyBank->id)
|
||||
->increment('piggy_banks.order');
|
||||
$piggyBank->order = $newOrder;
|
||||
Log::debug(sprintf('Order of piggy #%d ("%s") is now %d', $piggyBank->id, $piggyBank->name, $newOrder));
|
||||
$piggyBank->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
* @throws FireflyException
|
||||
@@ -320,8 +275,78 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
* Correct order of piggies in case of issues.
|
||||
*/
|
||||
public function resetOrder(): void
|
||||
{
|
||||
$set = $this->user->piggyBanks()->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']);
|
||||
$current = 1;
|
||||
foreach ($set as $piggyBank) {
|
||||
if ((int)$piggyBank->order !== $current) {
|
||||
Log::debug(sprintf('Piggy bank #%d ("%s") was at place %d but should be on %d', $piggyBank->id, $piggyBank->name, $piggyBank->order, $current));
|
||||
$piggyBank->order = $current;
|
||||
$piggyBank->save();
|
||||
}
|
||||
$current++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool
|
||||
{
|
||||
$oldOrder = (int)$piggyBank->order;
|
||||
Log::debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->piggyBanks()->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
|
||||
->where('piggy_banks.id', '!=', $piggyBank->id)
|
||||
->decrement('piggy_banks.order');
|
||||
$piggyBank->order = $newOrder;
|
||||
Log::debug(sprintf('Order of piggy #%d ("%s") is now %d', $piggyBank->id, $piggyBank->name, $newOrder));
|
||||
$piggyBank->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->user->piggyBanks()->where('piggy_banks.order', '>=', $newOrder)->where('piggy_banks.order', '<', $oldOrder)
|
||||
->where('piggy_banks.id', '!=', $piggyBank->id)
|
||||
->increment('piggy_banks.order');
|
||||
$piggyBank->order = $newOrder;
|
||||
Log::debug(sprintf('Order of piggy #%d ("%s") is now %d', $piggyBank->id, $piggyBank->name, $newOrder));
|
||||
$piggyBank->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $note
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function updateNote(PiggyBank $piggyBank, string $note): bool
|
||||
{
|
||||
if ('' === $note) {
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
$dbNote?->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($piggyBank);
|
||||
}
|
||||
$dbNote->text = trim($note);
|
||||
$dbNote->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
@@ -389,33 +414,8 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $note
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function updateNote(PiggyBank $piggyBank, string $note): bool
|
||||
{
|
||||
if ('' === $note) {
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
$dbNote?->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($piggyBank);
|
||||
}
|
||||
$dbNote->text = trim($note);
|
||||
$dbNote->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
|
@@ -59,31 +59,8 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $piggyBankId
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function find(int $piggyBankId): ?PiggyBank
|
||||
{
|
||||
// phpstan doesn't get the Model.
|
||||
return $this->user->piggyBanks()->find($piggyBankId); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by name or return NULL.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function findByName(string $name): ?PiggyBank
|
||||
{
|
||||
return $this->user->piggyBanks()->where('piggy_banks.name', $name)->first(['piggy_banks.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $piggyBankId
|
||||
* @param string|null $piggyBankName
|
||||
* @param int|null $piggyBankId
|
||||
* @param string|null $piggyBankName
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
@@ -112,6 +89,29 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $piggyBankId
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function find(int $piggyBankId): ?PiggyBank
|
||||
{
|
||||
// phpstan doesn't get the Model.
|
||||
return $this->user->piggyBanks()->find($piggyBankId); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by name or return NULL.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function findByName(string $name): ?PiggyBank
|
||||
{
|
||||
return $this->user->piggyBanks()->where('piggy_banks.name', $name)->first(['piggy_banks.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -136,7 +136,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Get current amount saved in piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -151,7 +151,17 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return PiggyBankRepetition|null
|
||||
*/
|
||||
public function getRepetition(PiggyBank $piggyBank): ?PiggyBankRepetition
|
||||
{
|
||||
return $piggyBank->piggyBankRepetitions()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -163,9 +173,9 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Used for connecting to a piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepetition $repetition
|
||||
* @param TransactionJournal $journal
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepetition $repetition
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
@@ -264,6 +274,16 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return (string)$amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -275,7 +295,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Return note for piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -290,6 +310,26 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return $note->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Also add amount in name.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPiggyBanksWithAmount(): Collection
|
||||
{
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
$set = $this->getPiggyBanks();
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($set as $piggy) {
|
||||
$currentAmount = $this->getRepetition($piggy)->currentamount ?? '0';
|
||||
$piggy->name = $piggy->name . ' (' . app('amount')->formatAnything($currency, $currentAmount, false) . ')';
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -306,40 +346,10 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
->orderBy('order', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Also add amount in name.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPiggyBanksWithAmount(): Collection
|
||||
{
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
$set = $this->getPiggyBanks();
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($set as $piggy) {
|
||||
$currentAmount = $this->getRepetition($piggy)->currentamount ?? '0';
|
||||
$piggy->name = $piggy->name.' ('.app('amount')->formatAnything($currency, $currentAmount, false).')';
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return PiggyBankRepetition|null
|
||||
*/
|
||||
public function getRepetition(PiggyBank $piggyBank): ?PiggyBankRepetition
|
||||
{
|
||||
return $piggyBank->piggyBankRepetitions()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the suggested amount the user should save per month, or "".
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
@@ -374,8 +384,8 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Get for piggy account what is left to put in piggies.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param Carbon $date
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
* @throws JsonException
|
||||
@@ -412,14 +422,4 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -38,9 +38,9 @@ use Illuminate\Support\Collection;
|
||||
interface PiggyBankRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param TransactionJournal|null $journal
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param TransactionJournal|null $journal
|
||||
* @return bool
|
||||
*/
|
||||
public function addAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool;
|
||||
@@ -48,16 +48,16 @@ interface PiggyBankRepositoryInterface
|
||||
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canAddAmount(PiggyBank $piggyBank, string $amount): bool;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Destroy piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -78,7 +78,7 @@ interface PiggyBankRepositoryInterface
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param int $piggyBankId
|
||||
* @param int $piggyBankId
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
@@ -87,22 +87,22 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Find by name or return NULL.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function findByName(string $name): ?PiggyBank;
|
||||
|
||||
/**
|
||||
* @param int|null $piggyBankId
|
||||
* @param string|null $piggyBankName
|
||||
* @param int|null $piggyBankId
|
||||
* @param string|null $piggyBankName
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function findPiggyBank(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -111,7 +111,7 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Get current amount saved in piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -120,7 +120,7 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Get all events.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -129,9 +129,9 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Used for connecting to a piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepetition $repetition
|
||||
* @param TransactionJournal $journal
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBankRepetition $repetition
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -147,7 +147,7 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Return note for piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -168,7 +168,7 @@ interface PiggyBankRepositoryInterface
|
||||
public function getPiggyBanksWithAmount(): Collection;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return PiggyBankRepetition|null
|
||||
*/
|
||||
@@ -177,7 +177,7 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Returns the suggested amount the user should save per month, or "".
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -186,23 +186,23 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Get for piggy account what is left to put in piggies.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param Carbon $date
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function leftOnAccount(PiggyBank $piggyBank, Carbon $date): string;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param TransactionJournal|null $journal
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param TransactionJournal|null $journal
|
||||
* @return bool
|
||||
*/
|
||||
public function removeAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
@@ -216,24 +216,24 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Search for piggy banks.
|
||||
*
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchPiggyBank(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
public function setCurrentAmount(PiggyBank $piggyBank, string $amount): PiggyBank;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $objectGroupTitle
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $objectGroupTitle
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
@@ -242,22 +242,22 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Set specific piggy bank to specific order.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param int $newOrder
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param int $newOrder
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Store new piggy bank.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
* @throws FireflyException
|
||||
@@ -267,8 +267,8 @@ interface PiggyBankRepositoryInterface
|
||||
/**
|
||||
* Update existing piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
|
@@ -68,8 +68,8 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
public function createdPreviously(Recurrence $recurrence, Carbon $date): bool
|
||||
{
|
||||
// if not, loop set and try to read the recurrence_date. If it matches start or end, return it as well.
|
||||
$set =
|
||||
TransactionJournalMeta::where(function (Builder $q1) use ($recurrence) {
|
||||
$set
|
||||
= TransactionJournalMeta::where(function (Builder $q1) use ($recurrence) {
|
||||
$q1->where('name', 'recurrence_id');
|
||||
$q1->where('data', json_encode((string)$recurrence->id));
|
||||
})->get(['journal_meta.transaction_journal_id']);
|
||||
@@ -92,10 +92,25 @@ 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.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*/
|
||||
public function destroy(Recurrence $recurrence): void
|
||||
{
|
||||
@@ -112,21 +127,6 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
$this->user->recurrences()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ALL recurring transactions.
|
||||
*
|
||||
@@ -160,7 +160,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the budget ID from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
@@ -180,7 +180,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the category from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
@@ -200,7 +200,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the category from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -220,9 +220,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Returns the journals created for this recurrence, possibly limited by time.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -232,7 +232,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
->where('transaction_journals.user_id', $recurrence->user_id)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('journal_meta.name', 'recurrence_id')
|
||||
->where('journal_meta.data', '"'.$recurrence->id.'"');
|
||||
->where('journal_meta.data', '"' . $recurrence->id . '"');
|
||||
if (null !== $start) {
|
||||
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'));
|
||||
}
|
||||
@@ -245,7 +245,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get journal ID's for journals created by this recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -261,7 +261,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the notes.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -277,46 +277,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate events in the date range.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getOccurrencesInRange(RecurrenceRepetition $repetition, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$occurrences = [];
|
||||
$mutator = clone $start;
|
||||
$mutator->startOfDay();
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
|
||||
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
|
||||
if ('daily' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getDailyInRange($mutator, $end, $skipMod);
|
||||
}
|
||||
if ('weekly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getWeeklyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('monthly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getMonthlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('ndom' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getNdomInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('yearly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getYearlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
|
||||
// filter out all the weekend days:
|
||||
return $this->filterWeekends($repetition, $occurrences);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurrenceTransaction $transaction
|
||||
* @param RecurrenceTransaction $transaction
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
@@ -336,7 +297,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the tags from the recurring transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $transaction
|
||||
* @param RecurrenceTransaction $transaction
|
||||
*
|
||||
* @return array
|
||||
* @throws JsonException
|
||||
@@ -355,9 +316,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param int $page
|
||||
* @param int $pageSize
|
||||
* @param Recurrence $recurrence
|
||||
* @param int $page
|
||||
* @param int $pageSize
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
@@ -385,7 +346,17 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -420,9 +391,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Calculate the next X iterations starting on the date given in $date.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param int $count
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
@@ -457,10 +428,10 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
*
|
||||
* Only returns them of they are after $afterDate
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param Carbon $afterDate
|
||||
* @param int $count
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param Carbon $afterDate
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -494,10 +465,31 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
return $this->filterMaxDate($repeatUntil, $occurrences);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon|null $max
|
||||
* @param array $occurrences
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterMaxDate(?Carbon $max, array $occurrences): array
|
||||
{
|
||||
if (null === $max) {
|
||||
return $occurrences;
|
||||
}
|
||||
$filtered = [];
|
||||
foreach ($occurrences as $date) {
|
||||
if ($date->lte($max)) {
|
||||
$filtered[] = $date;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the repetition in a string that is user readable.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param RecurrenceRepetition $repetition
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
@@ -571,17 +563,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
@@ -623,11 +605,50 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate events in the date range.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getOccurrencesInRange(RecurrenceRepetition $repetition, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$occurrences = [];
|
||||
$mutator = clone $start;
|
||||
$mutator->startOfDay();
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
Log::debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
|
||||
Log::debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
|
||||
if ('daily' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getDailyInRange($mutator, $end, $skipMod);
|
||||
}
|
||||
if ('weekly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getWeeklyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('monthly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getMonthlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('ndom' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getNdomInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
if ('yearly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getYearlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
|
||||
// filter out all the weekend days:
|
||||
return $this->filterWeekends($repetition, $occurrences);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param array $data
|
||||
* @param Recurrence $recurrence
|
||||
* @param array $data
|
||||
*
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
@@ -639,25 +660,4 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
|
||||
return $service->update($recurrence, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon|null $max
|
||||
* @param array $occurrences
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterMaxDate(?Carbon $max, array $occurrences): array
|
||||
{
|
||||
if (null === $max) {
|
||||
return $occurrences;
|
||||
}
|
||||
$filtered = [];
|
||||
foreach ($occurrences as $date) {
|
||||
if ($date->lte($max)) {
|
||||
$filtered[] = $date;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
}
|
||||
|
@@ -40,8 +40,8 @@ use Illuminate\Support\Collection;
|
||||
interface RecurringRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon $date
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon $date
|
||||
* @return bool
|
||||
*/
|
||||
public function createdPreviously(Recurrence $recurrence, Carbon $date): bool;
|
||||
@@ -49,7 +49,7 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Destroy a recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*/
|
||||
public function destroy(Recurrence $recurrence): void;
|
||||
|
||||
@@ -75,7 +75,7 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the category from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
@@ -84,7 +84,7 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the budget ID from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
@@ -93,7 +93,7 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the category from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|int
|
||||
*/
|
||||
@@ -102,7 +102,7 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the category from a recurring transaction transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
* @param RecurrenceTransaction $recTransaction
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -111,9 +111,9 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Returns the count of journals created for this recurrence, possibly limited by time.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -122,7 +122,7 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Get journal ID's for journals created by this recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -131,7 +131,7 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the notes.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -140,16 +140,16 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Generate events in the date range.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOccurrencesInRange(RecurrenceRepetition $repetition, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param RecurrenceTransaction $transaction
|
||||
* @param RecurrenceTransaction $transaction
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
@@ -158,23 +158,23 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Get the tags from the recurring transaction.
|
||||
*
|
||||
* @param RecurrenceTransaction $transaction
|
||||
* @param RecurrenceTransaction $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTags(RecurrenceTransaction $transaction): array;
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param int $page
|
||||
* @param int $pageSize
|
||||
* @param Recurrence $recurrence
|
||||
* @param int $page
|
||||
* @param int $pageSize
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getTransactionPaginator(Recurrence $recurrence, int $page, int $pageSize): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -184,9 +184,9 @@ interface RecurringRepositoryInterface
|
||||
* Calculate the next X iterations starting on the date given in $date.
|
||||
* Returns an array of Carbon objects.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param int $count
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -199,10 +199,10 @@ interface RecurringRepositoryInterface
|
||||
*
|
||||
* Only returns them of they are after $afterDate
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param Carbon $afterDate
|
||||
* @param int $count
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param Carbon $afterDate
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -212,29 +212,29 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Parse the repetition in a string that is user readable.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param RecurrenceRepetition $repetition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function repetitionDescription(RecurrenceRepetition $repetition): string;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchRecurrence(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Store a new recurring transaction.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
@@ -244,8 +244,8 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Calculate how many transactions are to be expected from this recurrence.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Recurrence $recurrence
|
||||
* @param RecurrenceRepetition $repetition
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -254,8 +254,8 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* Update a recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param array $data
|
||||
* @param Recurrence $recurrence
|
||||
* @param array $data
|
||||
*
|
||||
* @return Recurrence
|
||||
*/
|
||||
|
@@ -46,15 +46,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return $this->user->rules()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
@@ -100,16 +92,6 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
return $newRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $ruleId
|
||||
*
|
||||
* @return Rule|null
|
||||
*/
|
||||
public function find(int $ruleId): ?Rule
|
||||
{
|
||||
return $this->user->rules()->find($ruleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the users rules.
|
||||
*
|
||||
@@ -131,7 +113,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -141,7 +123,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
@@ -151,14 +133,22 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
{
|
||||
$count = $rule->ruleTriggers()->count();
|
||||
if (0 === $count) {
|
||||
throw new FireflyException('Rules should have more than zero triggers, rule #'.$rule->id.' has none!');
|
||||
throw new FireflyException('Rules should have more than zero triggers, rule #' . $rule->id . ' has none!');
|
||||
}
|
||||
|
||||
return $rule->ruleTriggers()->where('trigger_type', 'user_action')->first()->trigger_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return $this->user->rules()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -168,7 +158,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -254,43 +244,6 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function maxOrder(RuleGroup $ruleGroup): int
|
||||
{
|
||||
return (int)$ruleGroup->rules()->max('order');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule
|
||||
{
|
||||
if ($rule->rule_group_id !== $ruleGroup->id) {
|
||||
$rule->rule_group_id = $ruleGroup->id;
|
||||
}
|
||||
$rule->save();
|
||||
$rule->refresh();
|
||||
$this->setOrder($rule, $order);
|
||||
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool
|
||||
{
|
||||
$groupRepository = app(RuleGroupRepositoryInterface::class);
|
||||
$groupRepository->setUser($ruleGroup->user);
|
||||
$groupRepository->resetRuleOrder($ruleGroup);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -307,53 +260,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setOrder(Rule $rule, int $newOrder): void
|
||||
{
|
||||
$oldOrder = (int)$rule->order;
|
||||
$groupId = (int)$rule->rule_group_id;
|
||||
$maxOrder = $this->maxOrder($rule->ruleGroup);
|
||||
$newOrder = $newOrder > $maxOrder ? $maxOrder + 1 : $newOrder;
|
||||
Log::debug(sprintf('New order will be %d', $newOrder));
|
||||
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->rules()
|
||||
->where('rules.rule_group_id', $groupId)
|
||||
->where('rules.order', '<=', $newOrder)
|
||||
->where('rules.order', '>', $oldOrder)
|
||||
->where('rules.id', '!=', $rule->id)
|
||||
->decrement('rules.order');
|
||||
$rule->order = $newOrder;
|
||||
Log::debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
|
||||
$rule->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->user->rules()
|
||||
->where('rules.rule_group_id', $groupId)
|
||||
->where('rules.order', '>=', $newOrder)
|
||||
->where('rules.order', '<', $oldOrder)
|
||||
->where('rules.id', '!=', $rule->id)
|
||||
->increment('rules.order');
|
||||
$rule->order = $newOrder;
|
||||
Log::debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
|
||||
$rule->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Rule
|
||||
* @throws FireflyException
|
||||
@@ -407,28 +314,140 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $values
|
||||
* @param int $ruleId
|
||||
*
|
||||
* @return RuleAction
|
||||
* @return Rule|null
|
||||
*/
|
||||
public function storeAction(Rule $rule, array $values): RuleAction
|
||||
public function find(int $ruleId): ?Rule
|
||||
{
|
||||
$ruleAction = new RuleAction();
|
||||
$ruleAction->rule()->associate($rule);
|
||||
$ruleAction->order = $values['order'];
|
||||
$ruleAction->active = $values['active'];
|
||||
$ruleAction->stop_processing = $values['stop_processing'];
|
||||
$ruleAction->action_type = $values['action'];
|
||||
$ruleAction->action_value = $values['value'] ?? '';
|
||||
$ruleAction->save();
|
||||
|
||||
return $ruleAction;
|
||||
return $this->user->rules()->find($ruleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $values
|
||||
* @param string $moment
|
||||
* @param Rule $rule
|
||||
*/
|
||||
private function setRuleTrigger(string $moment, Rule $rule): void
|
||||
{
|
||||
/** @var RuleTrigger|null $trigger */
|
||||
$trigger = $rule->ruleTriggers()->where('trigger_type', 'user_action')->first();
|
||||
if (null !== $trigger) {
|
||||
$trigger->trigger_value = $moment;
|
||||
$trigger->save();
|
||||
|
||||
return;
|
||||
}
|
||||
$trigger = new RuleTrigger();
|
||||
$trigger->order = 0;
|
||||
$trigger->trigger_type = 'user_action';
|
||||
$trigger->trigger_value = $moment;
|
||||
$trigger->rule_id = $rule->id;
|
||||
$trigger->active = true;
|
||||
$trigger->stop_processing = false;
|
||||
$trigger->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool
|
||||
{
|
||||
$groupRepository = app(RuleGroupRepositoryInterface::class);
|
||||
$groupRepository->setUser($ruleGroup->user);
|
||||
$groupRepository->resetRuleOrder($ruleGroup);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setOrder(Rule $rule, int $newOrder): void
|
||||
{
|
||||
$oldOrder = (int)$rule->order;
|
||||
$groupId = (int)$rule->rule_group_id;
|
||||
$maxOrder = $this->maxOrder($rule->ruleGroup);
|
||||
$newOrder = $newOrder > $maxOrder ? $maxOrder + 1 : $newOrder;
|
||||
Log::debug(sprintf('New order will be %d', $newOrder));
|
||||
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->rules()
|
||||
->where('rules.rule_group_id', $groupId)
|
||||
->where('rules.order', '<=', $newOrder)
|
||||
->where('rules.order', '>', $oldOrder)
|
||||
->where('rules.id', '!=', $rule->id)
|
||||
->decrement('rules.order');
|
||||
$rule->order = $newOrder;
|
||||
Log::debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
|
||||
$rule->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->user->rules()
|
||||
->where('rules.rule_group_id', $groupId)
|
||||
->where('rules.order', '>=', $newOrder)
|
||||
->where('rules.order', '<', $oldOrder)
|
||||
->where('rules.id', '!=', $rule->id)
|
||||
->increment('rules.order');
|
||||
$rule->order = $newOrder;
|
||||
Log::debug(sprintf('Order of rule #%d ("%s") is now %d', $rule->id, $rule->title, $newOrder));
|
||||
$rule->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function maxOrder(RuleGroup $ruleGroup): int
|
||||
{
|
||||
return (int)$ruleGroup->rules()->max('order');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function storeTriggers(Rule $rule, array $data): void
|
||||
{
|
||||
$order = 1;
|
||||
foreach ($data['triggers'] as $trigger) {
|
||||
$value = $trigger['value'] ?? '';
|
||||
$stopProcessing = $trigger['stop_processing'] ?? false;
|
||||
$active = $trigger['active'] ?? true;
|
||||
$type = $trigger['type'];
|
||||
if (true === ($trigger['prohibited'] ?? false) && !str_starts_with($type, '-')) {
|
||||
$type = sprintf('-%s', $type);
|
||||
}
|
||||
|
||||
$triggerValues = [
|
||||
'action' => $type,
|
||||
'value' => $value,
|
||||
'stop_processing' => $stopProcessing,
|
||||
'order' => $order,
|
||||
'active' => $active,
|
||||
];
|
||||
$this->storeTrigger($rule, $triggerValues);
|
||||
++$order;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $values
|
||||
*
|
||||
* @return RuleTrigger
|
||||
*/
|
||||
@@ -447,8 +466,53 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $data
|
||||
* @param Rule $rule
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function storeActions(Rule $rule, array $data): void
|
||||
{
|
||||
$order = 1;
|
||||
foreach ($data['actions'] as $action) {
|
||||
$value = $action['value'] ?? '';
|
||||
$stopProcessing = $action['stop_processing'] ?? false;
|
||||
$active = $action['active'] ?? true;
|
||||
$actionValues = [
|
||||
'action' => $action['type'],
|
||||
'value' => $value,
|
||||
'stop_processing' => $stopProcessing,
|
||||
'order' => $order,
|
||||
'active' => $active,
|
||||
];
|
||||
$this->storeAction($rule, $actionValues);
|
||||
++$order;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $values
|
||||
*
|
||||
* @return RuleAction
|
||||
*/
|
||||
public function storeAction(Rule $rule, array $values): RuleAction
|
||||
{
|
||||
$ruleAction = new RuleAction();
|
||||
$ruleAction->rule()->associate($rule);
|
||||
$ruleAction->order = $values['order'];
|
||||
$ruleAction->active = $values['active'];
|
||||
$ruleAction->stop_processing = $values['stop_processing'];
|
||||
$ruleAction->action_type = $values['action'];
|
||||
$ruleAction->action_value = $values['value'] ?? '';
|
||||
$ruleAction->save();
|
||||
|
||||
return $ruleAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $data
|
||||
*
|
||||
* @return Rule
|
||||
*/
|
||||
@@ -505,81 +569,17 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $moment
|
||||
* @param Rule $rule
|
||||
* @inheritDoc
|
||||
*/
|
||||
private function setRuleTrigger(string $moment, Rule $rule): void
|
||||
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule
|
||||
{
|
||||
/** @var RuleTrigger|null $trigger */
|
||||
$trigger = $rule->ruleTriggers()->where('trigger_type', 'user_action')->first();
|
||||
if (null !== $trigger) {
|
||||
$trigger->trigger_value = $moment;
|
||||
$trigger->save();
|
||||
|
||||
return;
|
||||
if ($rule->rule_group_id !== $ruleGroup->id) {
|
||||
$rule->rule_group_id = $ruleGroup->id;
|
||||
}
|
||||
$trigger = new RuleTrigger();
|
||||
$trigger->order = 0;
|
||||
$trigger->trigger_type = 'user_action';
|
||||
$trigger->trigger_value = $moment;
|
||||
$trigger->rule_id = $rule->id;
|
||||
$trigger->active = true;
|
||||
$trigger->stop_processing = false;
|
||||
$trigger->save();
|
||||
}
|
||||
$rule->save();
|
||||
$rule->refresh();
|
||||
$this->setOrder($rule, $order);
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function storeActions(Rule $rule, array $data): void
|
||||
{
|
||||
$order = 1;
|
||||
foreach ($data['actions'] as $action) {
|
||||
$value = $action['value'] ?? '';
|
||||
$stopProcessing = $action['stop_processing'] ?? false;
|
||||
$active = $action['active'] ?? true;
|
||||
$actionValues = [
|
||||
'action' => $action['type'],
|
||||
'value' => $value,
|
||||
'stop_processing' => $stopProcessing,
|
||||
'order' => $order,
|
||||
'active' => $active,
|
||||
];
|
||||
$this->storeAction($rule, $actionValues);
|
||||
++$order;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function storeTriggers(Rule $rule, array $data): void
|
||||
{
|
||||
$order = 1;
|
||||
foreach ($data['triggers'] as $trigger) {
|
||||
$value = $trigger['value'] ?? '';
|
||||
$stopProcessing = $trigger['stop_processing'] ?? false;
|
||||
$active = $trigger['active'] ?? true;
|
||||
$type = $trigger['type'];
|
||||
if (true === ($trigger['prohibited'] ?? false) && !str_starts_with($type, '-')) {
|
||||
$type = sprintf('-%s', $type);
|
||||
}
|
||||
|
||||
$triggerValues = [
|
||||
'action' => $type,
|
||||
'value' => $value,
|
||||
'stop_processing' => $stopProcessing,
|
||||
'order' => $order,
|
||||
'active' => $active,
|
||||
];
|
||||
$this->storeTrigger($rule, $triggerValues);
|
||||
++$order;
|
||||
}
|
||||
return $rule;
|
||||
}
|
||||
}
|
||||
|
@@ -42,21 +42,21 @@ interface RuleRepositoryInterface
|
||||
public function count(): int;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(Rule $rule): bool;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return Rule
|
||||
*/
|
||||
public function duplicate(Rule $rule): Rule;
|
||||
|
||||
/**
|
||||
* @param int $ruleId
|
||||
* @param int $ruleId
|
||||
*
|
||||
* @return Rule|null
|
||||
*/
|
||||
@@ -75,28 +75,28 @@ interface RuleRepositoryInterface
|
||||
public function getFirstRuleGroup(): RuleGroup;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHighestOrderInRuleGroup(RuleGroup $ruleGroup): int;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrimaryTrigger(Rule $rule): string;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getRuleActions(Rule $rule): Collection;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -105,7 +105,7 @@ interface RuleRepositoryInterface
|
||||
/**
|
||||
* Return search query for rule.
|
||||
*
|
||||
* @param Rule $rule
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -126,73 +126,73 @@ interface RuleRepositoryInterface
|
||||
public function getUpdateRules(): Collection;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function maxOrder(RuleGroup $ruleGroup): int;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param int $order
|
||||
* @param Rule $rule
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param int $order
|
||||
*
|
||||
* @return Rule
|
||||
*/
|
||||
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchRule(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param int $newOrder
|
||||
* @param Rule $rule
|
||||
* @param int $newOrder
|
||||
*/
|
||||
public function setOrder(Rule $rule, int $newOrder): void;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Rule
|
||||
*/
|
||||
public function store(array $data): Rule;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $values
|
||||
* @param Rule $rule
|
||||
* @param array $values
|
||||
*
|
||||
* @return RuleAction
|
||||
*/
|
||||
public function storeAction(Rule $rule, array $values): RuleAction;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $values
|
||||
* @param Rule $rule
|
||||
* @param array $values
|
||||
*
|
||||
* @return RuleTrigger
|
||||
*/
|
||||
public function storeTrigger(Rule $rule, array $values): RuleTrigger;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $data
|
||||
* @param Rule $rule
|
||||
* @param array $data
|
||||
*
|
||||
* @return Rule
|
||||
*/
|
||||
|
@@ -63,6 +63,14 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->ruleGroups()->orderBy('order', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -72,8 +80,8 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup|null $moveTo
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup|null $moveTo
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
@@ -101,6 +109,108 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function resetOrder(): bool
|
||||
{
|
||||
$set = $this->user
|
||||
->ruleGroups()
|
||||
->whereNull('deleted_at')
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'DESC')
|
||||
->get();
|
||||
$count = 1;
|
||||
/** @var RuleGroup $entry */
|
||||
foreach ($set as $entry) {
|
||||
if ($entry->order !== $count) {
|
||||
$entry->order = $count;
|
||||
$entry->save();
|
||||
}
|
||||
|
||||
// also update rules in group.
|
||||
$this->resetRuleOrder($entry);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool
|
||||
{
|
||||
$set = $ruleGroup->rules()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'DESC')
|
||||
->orderBy('updated_at', 'DESC')
|
||||
->get(['rules.*']);
|
||||
$count = 1;
|
||||
/** @var Rule $entry */
|
||||
foreach ($set as $entry) {
|
||||
if ((int)$entry->order !== $count) {
|
||||
Log::debug(sprintf('Rule #%d was on spot %d but must be on spot %d', $entry->id, $entry->order, $count));
|
||||
$entry->order = $count;
|
||||
$entry->save();
|
||||
}
|
||||
$this->resetRuleActionOrder($entry);
|
||||
$this->resetRuleTriggerOrder($entry);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*/
|
||||
private function resetRuleActionOrder(Rule $rule): void
|
||||
{
|
||||
$actions = $rule->ruleActions()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('action_type', 'ASC')
|
||||
->get();
|
||||
$index = 1;
|
||||
/** @var RuleAction $action */
|
||||
foreach ($actions as $action) {
|
||||
if ((int)$action->order !== $index) {
|
||||
$action->order = $index;
|
||||
$action->save();
|
||||
Log::debug(sprintf('Rule action #%d was on spot %d but must be on spot %d', $action->id, $action->order, $index));
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*/
|
||||
private function resetRuleTriggerOrder(Rule $rule): void
|
||||
{
|
||||
$triggers = $rule->ruleTriggers()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('trigger_type', 'ASC')
|
||||
->get();
|
||||
$index = 1;
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
$order = (int)$trigger->order;
|
||||
if ($order !== $index) {
|
||||
$trigger->order = $index;
|
||||
$trigger->save();
|
||||
Log::debug(sprintf('Rule trigger #%d was on spot %d but must be on spot %d', $trigger->id, $order, $index));
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -115,7 +225,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $ruleGroupId
|
||||
* @param int $ruleGroupId
|
||||
*
|
||||
* @return RuleGroup|null
|
||||
*/
|
||||
@@ -125,7 +235,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $title
|
||||
*
|
||||
* @return RuleGroup|null
|
||||
*/
|
||||
@@ -134,14 +244,6 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
return $this->user->ruleGroups()->where('title', $title)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->ruleGroups()->orderBy('order', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -151,7 +253,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -163,7 +265,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -178,7 +280,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -193,7 +295,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $filter
|
||||
* @param string|null $filter
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -255,7 +357,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $filter
|
||||
* @param string|null $filter
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -308,7 +410,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -326,63 +428,6 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
return (int)$this->user->ruleGroups()->where('active', true)->max('order');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function resetOrder(): bool
|
||||
{
|
||||
$set = $this->user
|
||||
->ruleGroups()
|
||||
->whereNull('deleted_at')
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'DESC')
|
||||
->get();
|
||||
$count = 1;
|
||||
/** @var RuleGroup $entry */
|
||||
foreach ($set as $entry) {
|
||||
if ($entry->order !== $count) {
|
||||
$entry->order = $count;
|
||||
$entry->save();
|
||||
}
|
||||
|
||||
// also update rules in group.
|
||||
$this->resetRuleOrder($entry);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool
|
||||
{
|
||||
$set = $ruleGroup->rules()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'DESC')
|
||||
->orderBy('updated_at', 'DESC')
|
||||
->get(['rules.*']);
|
||||
$count = 1;
|
||||
/** @var Rule $entry */
|
||||
foreach ($set as $entry) {
|
||||
if ((int)$entry->order !== $count) {
|
||||
Log::debug(sprintf('Rule #%d was on spot %d but must be on spot %d', $entry->id, $entry->order, $count));
|
||||
$entry->order = $count;
|
||||
$entry->save();
|
||||
}
|
||||
$this->resetRuleActionOrder($entry);
|
||||
$this->resetRuleTriggerOrder($entry);
|
||||
|
||||
++$count;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -398,6 +443,41 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
return $search->take($limit)->get(['id', 'title', 'description']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return RuleGroup
|
||||
*/
|
||||
public function store(array $data): RuleGroup
|
||||
{
|
||||
$newRuleGroup = new RuleGroup(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'title' => $data['title'],
|
||||
'description' => $data['description'],
|
||||
'order' => 31337,
|
||||
'active' => array_key_exists('active', $data) ? $data['active'] : true,
|
||||
]
|
||||
);
|
||||
$newRuleGroup->save();
|
||||
$this->resetOrder();
|
||||
if (array_key_exists('order', $data)) {
|
||||
$this->setOrder($newRuleGroup, $data['order']);
|
||||
}
|
||||
|
||||
return $newRuleGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -425,43 +505,8 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return RuleGroup
|
||||
*/
|
||||
public function store(array $data): RuleGroup
|
||||
{
|
||||
$newRuleGroup = new RuleGroup(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'title' => $data['title'],
|
||||
'description' => $data['description'],
|
||||
'order' => 31337,
|
||||
'active' => array_key_exists('active', $data) ? $data['active'] : true,
|
||||
]
|
||||
);
|
||||
$newRuleGroup->save();
|
||||
$this->resetOrder();
|
||||
if (array_key_exists('order', $data)) {
|
||||
$this->setOrder($newRuleGroup, $data['order']);
|
||||
}
|
||||
|
||||
return $newRuleGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param array $data
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param array $data
|
||||
*
|
||||
* @return RuleGroup
|
||||
*/
|
||||
@@ -487,49 +532,4 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
|
||||
return $ruleGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*/
|
||||
private function resetRuleActionOrder(Rule $rule): void
|
||||
{
|
||||
$actions = $rule->ruleActions()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('action_type', 'ASC')
|
||||
->get();
|
||||
$index = 1;
|
||||
/** @var RuleAction $action */
|
||||
foreach ($actions as $action) {
|
||||
if ((int)$action->order !== $index) {
|
||||
$action->order = $index;
|
||||
$action->save();
|
||||
Log::debug(sprintf('Rule action #%d was on spot %d but must be on spot %d', $action->id, $action->order, $index));
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*/
|
||||
private function resetRuleTriggerOrder(Rule $rule): void
|
||||
{
|
||||
$triggers = $rule->ruleTriggers()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('trigger_type', 'ASC')
|
||||
->get();
|
||||
$index = 1;
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
$order = (int)$trigger->order;
|
||||
if ($order !== $index) {
|
||||
$trigger->order = $index;
|
||||
$trigger->save();
|
||||
Log::debug(sprintf('Rule trigger #%d was on spot %d but must be on spot %d', $trigger->id, $order, $index));
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -44,8 +44,8 @@ interface RuleGroupRepositoryInterface
|
||||
public function count(): int;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup|null $moveTo
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup|null $moveTo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -57,14 +57,14 @@ interface RuleGroupRepositoryInterface
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param int $ruleGroupId
|
||||
* @param int $ruleGroupId
|
||||
*
|
||||
* @return RuleGroup|null
|
||||
*/
|
||||
public function find(int $ruleGroupId): ?RuleGroup;
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $title
|
||||
*
|
||||
* @return RuleGroup|null
|
||||
*/
|
||||
@@ -83,21 +83,21 @@ interface RuleGroupRepositoryInterface
|
||||
public function getActiveGroups(): Collection;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveRules(RuleGroup $group): Collection;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getActiveStoreRules(RuleGroup $group): Collection;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -106,7 +106,7 @@ interface RuleGroupRepositoryInterface
|
||||
/**
|
||||
* Also inactive groups.
|
||||
*
|
||||
* @param string|null $filter
|
||||
* @param string|null $filter
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -118,14 +118,14 @@ interface RuleGroupRepositoryInterface
|
||||
public function getHighestOrderRuleGroup(): int;
|
||||
|
||||
/**
|
||||
* @param string|null $filter
|
||||
* @param string|null $filter
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getRuleGroupsWithRules(?string $filter): Collection;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $group
|
||||
* @param RuleGroup $group
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -144,41 +144,41 @@ interface RuleGroupRepositoryInterface
|
||||
public function resetOrder(): bool;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resetRuleOrder(RuleGroup $ruleGroup): bool;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchRuleGroup(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param int $newOrder
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param int $newOrder
|
||||
*/
|
||||
public function setOrder(RuleGroup $ruleGroup, int $newOrder): void;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return RuleGroup
|
||||
*/
|
||||
public function store(array $data): RuleGroup;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param array $data
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param array $data
|
||||
*
|
||||
* @return RuleGroup
|
||||
*/
|
||||
|
@@ -47,10 +47,10 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
* which have the specified tag(s) set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
*
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -119,15 +119,37 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function getTags(): Collection
|
||||
{
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
|
||||
return $repository->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
|
||||
* which have the specified tag(s) set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
*
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -197,23 +219,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of tags, grouped per currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -226,10 +238,10 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/**
|
||||
* Sum of income journals in period for a set of tags, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -238,16 +250,4 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
{
|
||||
throw new FireflyException(sprintf('%s is not yet implemented.', __METHOD__));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function getTags(): Collection
|
||||
{
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
|
||||
return $repository->get();
|
||||
}
|
||||
}
|
||||
|
@@ -40,10 +40,10 @@ interface OperationsRepositoryInterface
|
||||
* which have the specified tag(s) set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -54,27 +54,27 @@ interface OperationsRepositoryInterface
|
||||
* which have the specified tag(s) set to them. It's grouped per currency, with as few details in the array
|
||||
* as possible. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $tags = null): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Sum of withdrawal journals in period for a set of tags, grouped per currency. Amounts are always negative.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -83,10 +83,10 @@ interface OperationsRepositoryInterface
|
||||
/**
|
||||
* Sum of income journals in period for a set of tags, grouped per currency. Amounts are always positive.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection|null $accounts
|
||||
* @param Collection|null $tags
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -56,7 +56,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
@@ -84,9 +84,17 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->tags()->orderBy('tag', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -102,7 +110,17 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tagId
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tagId
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
@@ -112,7 +130,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
* @param string $tag
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
@@ -123,7 +141,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -133,14 +151,6 @@ class TagRepository implements TagRepositoryInterface
|
||||
return $tag->transactionJournals()->orderBy('date', 'ASC')->first()?->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return $this->user->tags()->orderBy('tag', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -162,16 +172,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLocation(Tag $tag): ?Location
|
||||
{
|
||||
/** @var Location|null */
|
||||
return $tag->locations()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $year
|
||||
* @param int|null $year
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -188,7 +189,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
|
||||
if (null !== $year) {
|
||||
Log::debug(sprintf('Get tags with year %s.', $year));
|
||||
$tagQuery->where('tags.date', '>=', $year.'-01-01 00:00:00')->where('tags.date', '<=', $year.'-12-31 23:59:59');
|
||||
$tagQuery->where('tags.date', '>=', $year . '-01-01 00:00:00')->where('tags.date', '<=', $year . '-12-31 23:59:59');
|
||||
}
|
||||
$collection = $tagQuery->get();
|
||||
$return = [];
|
||||
@@ -208,9 +209,9 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -226,7 +227,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -259,7 +260,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
/**
|
||||
* Find one or more tags based on the query.
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $query
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -273,8 +274,8 @@ class TagRepository implements TagRepositoryInterface
|
||||
/**
|
||||
* Search the users tags.
|
||||
*
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -291,17 +292,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
@@ -315,9 +306,9 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
@@ -385,9 +376,9 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -402,8 +393,8 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
@@ -455,4 +446,13 @@ class TagRepository implements TagRepositoryInterface
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLocation(Tag $tag): ?Location
|
||||
{
|
||||
/** @var Location|null */
|
||||
return $tag->locations()->first();
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ interface TagRepositoryInterface
|
||||
/**
|
||||
* This method destroys a tag.
|
||||
*
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -55,30 +55,30 @@ interface TagRepositoryInterface
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function expenseInPeriod(Tag $tag, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param int $tagId
|
||||
* @param int $tagId
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function find(int $tagId): ?Tag;
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
* @param string $tag
|
||||
*
|
||||
* @return Tag|null
|
||||
*/
|
||||
public function findByTag(string $tag): ?Tag;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -92,7 +92,7 @@ interface TagRepositoryInterface
|
||||
public function get(): Collection;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -101,30 +101,30 @@ interface TagRepositoryInterface
|
||||
/**
|
||||
* Return location, or NULL.
|
||||
*
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Location|null
|
||||
*/
|
||||
public function getLocation(Tag $tag): ?Location;
|
||||
|
||||
/**
|
||||
* @param int|null $year
|
||||
* @param int|null $year
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTagsInYear(?int $year): array;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function incomeInPeriod(Tag $tag, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
@@ -147,7 +147,7 @@ interface TagRepositoryInterface
|
||||
/**
|
||||
* Find one or more tags based on the query.
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $query
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -156,22 +156,22 @@ interface TagRepositoryInterface
|
||||
/**
|
||||
* Search the users tags.
|
||||
*
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchTags(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* This method stores a tag.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
@@ -180,18 +180,18 @@ interface TagRepositoryInterface
|
||||
/**
|
||||
* Calculates various amounts in tag.
|
||||
*
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sumsOfTag(Tag $tag, ?Carbon $start, ?Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -200,8 +200,8 @@ interface TagRepositoryInterface
|
||||
/**
|
||||
* Update a tag.
|
||||
*
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
|
@@ -70,7 +70,19 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
* Find a transaction group by its ID.
|
||||
*
|
||||
* @param int $groupId
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
public function find(int $groupId): ?TransactionGroup
|
||||
{
|
||||
return $this->user->transactionGroups()->find($groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
*/
|
||||
public function destroy(TransactionGroup $group): void
|
||||
{
|
||||
@@ -95,21 +107,59 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a transaction group by its ID.
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @param int $groupId
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
* @return array
|
||||
*/
|
||||
public function find(int $groupId): ?TransactionGroup
|
||||
private function expandJournal(TransactionJournal $journal): array
|
||||
{
|
||||
return $this->user->transactionGroups()->find($groupId);
|
||||
$array = $journal->toArray();
|
||||
$array['transactions'] = [];
|
||||
$array['meta'] = $journal->transactionJournalMeta->toArray();
|
||||
$array['tags'] = $journal->tags->toArray();
|
||||
$array['categories'] = $journal->categories->toArray();
|
||||
$array['budgets'] = $journal->budgets->toArray();
|
||||
$array['notes'] = $journal->notes->toArray();
|
||||
$array['locations'] = [];
|
||||
$array['attachments'] = $journal->attachments->toArray();
|
||||
$array['links'] = [];
|
||||
$array['piggy_bank_events'] = $journal->piggyBankEvents->toArray();
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
$array['transactions'][] = $this->expandTransaction($transaction);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function expandTransaction(Transaction $transaction): array
|
||||
{
|
||||
$array = $transaction->toArray();
|
||||
$array['account'] = $transaction->account->toArray();
|
||||
$array['budgets'] = [];
|
||||
$array['categories'] = [];
|
||||
|
||||
foreach ($transaction->categories as $category) {
|
||||
$array['categories'][] = $category->toArray();
|
||||
}
|
||||
|
||||
foreach ($transaction->budgets as $budget) {
|
||||
$array['budgets'][] = $budget->toArray();
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all attachments for all journals in the group.
|
||||
*
|
||||
* @param TransactionGroup $group
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -139,10 +189,40 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the note text for a journal (by ID).
|
||||
*
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(int $journalId): ?string
|
||||
{
|
||||
/** @var Note|null $note */
|
||||
$note = Note::where('noteable_id', $journalId)
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first();
|
||||
if (null === $note) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $note->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all journal links for all journals in the group.
|
||||
*
|
||||
* @param TransactionGroup $group
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -197,6 +277,58 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFormattedAmount(TransactionJournal $journal): string
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions->first();
|
||||
$currency = $transaction->transactionCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->amount);
|
||||
$return = '';
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionType::WITHDRAWAL !== $type) {
|
||||
$return = app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFormattedForeignAmount(TransactionJournal $journal): string
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions->first();
|
||||
if (null === $transaction->foreign_amount || '' === $transaction->foreign_amount) {
|
||||
return '';
|
||||
}
|
||||
if (0 === bccomp('0', $transaction->foreign_amount)) {
|
||||
return '';
|
||||
}
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
$return = '';
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionType::WITHDRAWAL !== $type) {
|
||||
$return = app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -211,8 +343,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Return object with all found meta field things as Carbon objects.
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param array $fields
|
||||
* @param int $journalId
|
||||
* @param array $fields
|
||||
*
|
||||
* @return NullArrayObject
|
||||
* @throws Exception
|
||||
@@ -236,8 +368,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Return object with all found meta field things.
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param array $fields
|
||||
* @param int $journalId
|
||||
* @param array $fields
|
||||
*
|
||||
* @return NullArrayObject
|
||||
*/
|
||||
@@ -257,30 +389,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
return new NullArrayObject($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the note text for a journal (by ID).
|
||||
*
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(int $journalId): ?string
|
||||
{
|
||||
/** @var Note|null $note */
|
||||
$note = Note::where('noteable_id', $journalId)
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first();
|
||||
if (null === $note) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $note->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all piggy bank events for all journals in the group.
|
||||
*
|
||||
* @param TransactionGroup $group
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
@@ -337,7 +449,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Get the tags for a journal (by ID).
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -353,17 +465,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionGroup
|
||||
* @throws DuplicateTransactionException
|
||||
@@ -389,8 +491,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param array $data
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionGroup
|
||||
*
|
||||
@@ -404,106 +506,4 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
|
||||
return $service->update($transactionGroup, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function expandJournal(TransactionJournal $journal): array
|
||||
{
|
||||
$array = $journal->toArray();
|
||||
$array['transactions'] = [];
|
||||
$array['meta'] = $journal->transactionJournalMeta->toArray();
|
||||
$array['tags'] = $journal->tags->toArray();
|
||||
$array['categories'] = $journal->categories->toArray();
|
||||
$array['budgets'] = $journal->budgets->toArray();
|
||||
$array['notes'] = $journal->notes->toArray();
|
||||
$array['locations'] = [];
|
||||
$array['attachments'] = $journal->attachments->toArray();
|
||||
$array['links'] = [];
|
||||
$array['piggy_bank_events'] = $journal->piggyBankEvents->toArray();
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
$array['transactions'][] = $this->expandTransaction($transaction);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function expandTransaction(Transaction $transaction): array
|
||||
{
|
||||
$array = $transaction->toArray();
|
||||
$array['account'] = $transaction->account->toArray();
|
||||
$array['budgets'] = [];
|
||||
$array['categories'] = [];
|
||||
|
||||
foreach ($transaction->categories as $category) {
|
||||
$array['categories'][] = $category->toArray();
|
||||
}
|
||||
|
||||
foreach ($transaction->budgets as $budget) {
|
||||
$array['budgets'][] = $budget->toArray();
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFormattedAmount(TransactionJournal $journal): string
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions->first();
|
||||
$currency = $transaction->transactionCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->amount);
|
||||
$return = '';
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionType::WITHDRAWAL !== $type) {
|
||||
$return = app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFormattedForeignAmount(TransactionJournal $journal): string
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions->first();
|
||||
if (null === $transaction->foreign_amount || '' === $transaction->foreign_amount) {
|
||||
return '';
|
||||
}
|
||||
if (0 === bccomp('0', $transaction->foreign_amount)) {
|
||||
return '';
|
||||
}
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
$return = '';
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionType::WITHDRAWAL !== $type) {
|
||||
$return = app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@@ -38,21 +38,21 @@ use Illuminate\Support\Collection;
|
||||
interface TransactionGroupRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countAttachments(int $journalId): int;
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
* @param TransactionGroup $group
|
||||
*/
|
||||
public function destroy(TransactionGroup $group): void;
|
||||
|
||||
/**
|
||||
* Return a group and expand all meta data etc.
|
||||
*
|
||||
* @param TransactionGroup $group
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Find a transaction group by its ID.
|
||||
*
|
||||
* @param int $groupId
|
||||
* @param int $groupId
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
*/
|
||||
@@ -70,7 +70,7 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Return all attachments for all journals in the group.
|
||||
*
|
||||
* @param TransactionGroup $group
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -79,7 +79,7 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Return all journal links for all journals in the group.
|
||||
*
|
||||
* @param TransactionGroup $group
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -88,7 +88,7 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Get the location of a journal or NULL.
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return Location|null
|
||||
*/
|
||||
@@ -97,8 +97,8 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Return object with all found meta field things as Carbon objects.
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param array $fields
|
||||
* @param int $journalId
|
||||
* @param array $fields
|
||||
*
|
||||
* @return NullArrayObject
|
||||
*/
|
||||
@@ -107,8 +107,8 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Return object with all found meta field things.
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param array $fields
|
||||
* @param int $journalId
|
||||
* @param array $fields
|
||||
*
|
||||
* @return NullArrayObject
|
||||
*/
|
||||
@@ -117,7 +117,7 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Get the note text for a journal (by ID).
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -126,7 +126,7 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Return all piggy bank events for all journals in the group.
|
||||
*
|
||||
* @param TransactionGroup $group
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -135,7 +135,7 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Get the tags for a journal (by ID) as Tag objects.
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -144,21 +144,21 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Get the tags for a journal (by ID).
|
||||
*
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTags(int $journalId): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* Create a new transaction group.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionGroup
|
||||
* @throws DuplicateTransactionException
|
||||
@@ -169,8 +169,8 @@ interface TransactionGroupRepositoryInterface
|
||||
/**
|
||||
* Update an existing transaction group.
|
||||
*
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param array $data
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionGroup
|
||||
*/
|
||||
|
@@ -33,20 +33,8 @@ use Illuminate\Support\Facades\Log;
|
||||
class TransactionTypeRepository implements TransactionTypeRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return TransactionType|null
|
||||
*/
|
||||
public function findByType(string $type): ?TransactionType
|
||||
{
|
||||
$search = ucfirst($type);
|
||||
|
||||
return TransactionType::whereType($search)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionType|null $type
|
||||
* @param string|null $typeString
|
||||
* @param TransactionType|null $type
|
||||
* @param string|null $typeString
|
||||
*
|
||||
* @return TransactionType
|
||||
*/
|
||||
@@ -69,8 +57,20 @@ class TransactionTypeRepository implements TransactionTypeRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $type
|
||||
*
|
||||
* @return TransactionType|null
|
||||
*/
|
||||
public function findByType(string $type): ?TransactionType
|
||||
{
|
||||
$search = ucfirst($type);
|
||||
|
||||
return TransactionType::whereType($search)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
|
@@ -32,23 +32,23 @@ use Illuminate\Support\Collection;
|
||||
interface TransactionTypeRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
*
|
||||
* @return TransactionType|null
|
||||
*/
|
||||
public function findByType(string $type): ?TransactionType;
|
||||
|
||||
/**
|
||||
* @param TransactionType|null $type
|
||||
* @param string|null $typeString
|
||||
* @param TransactionType|null $type
|
||||
* @param string|null $typeString
|
||||
*
|
||||
* @return TransactionType
|
||||
*/
|
||||
public function findTransactionType(?TransactionType $type, ?string $typeString): TransactionType;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
|
@@ -43,45 +43,12 @@ use Str;
|
||||
*/
|
||||
class UserRepository implements UserRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function all(): Collection
|
||||
{
|
||||
return User::orderBy('id', 'DESC')->get(['users.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $role
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function attachRole(User $user, string $role): bool
|
||||
{
|
||||
$roleObject = Role::where('name', $role)->first();
|
||||
if (null === $roleObject) {
|
||||
Log::error(sprintf('Could not find role "%s" in attachRole()', $role));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$user->roles()->attach($roleObject);
|
||||
} catch (QueryException $e) {
|
||||
// don't care
|
||||
Log::error(sprintf('Query exception when giving user a role: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This updates the users email address and records some things so it can be confirmed or undone later.
|
||||
* The user is blocked until the change is confirmed.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $newEmail
|
||||
* @param User $user
|
||||
* @param string $newEmail
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
@@ -94,7 +61,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
|
||||
// save old email as pref
|
||||
app('preferences')->setForUser($user, 'previous_email_latest', $oldEmail);
|
||||
app('preferences')->setForUser($user, 'previous_email_'.date('Y-m-d-H-i-s'), $oldEmail);
|
||||
app('preferences')->setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
|
||||
|
||||
// set undo and confirm token:
|
||||
app('preferences')->setForUser($user, 'email_change_undo_token', bin2hex(random_bytes(16)));
|
||||
@@ -110,8 +77,8 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $password
|
||||
* @param User $user
|
||||
* @param string $password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -124,9 +91,9 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param bool $isBlocked
|
||||
* @param string $code
|
||||
* @param User $user
|
||||
* @param bool $isBlocked
|
||||
* @param string $code
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -141,17 +108,9 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return $this->all()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $displayName
|
||||
* @param string $description
|
||||
* @param string $name
|
||||
* @param string $displayName
|
||||
* @param string $description
|
||||
*
|
||||
* @return Role
|
||||
*/
|
||||
@@ -160,6 +119,32 @@ class UserRepository implements UserRepositoryInterface
|
||||
return Role::create(['name' => $name, 'display_name' => $displayName, 'description' => $description]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteInvite(InvitedUser $invite): void
|
||||
{
|
||||
Log::debug(sprintf('Deleting invite #%d', $invite->id));
|
||||
$invite->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function destroy(User $user): bool
|
||||
{
|
||||
Log::debug(sprintf('Calling delete() on user %d', $user->id));
|
||||
|
||||
$user->groupMemberships()->delete();
|
||||
$user->delete();
|
||||
$this->deleteEmptyGroups();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -177,43 +162,23 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return int
|
||||
*/
|
||||
public function deleteInvite(InvitedUser $invite): void
|
||||
public function count(): int
|
||||
{
|
||||
Log::debug(sprintf('Deleting invite #%d', $invite->id));
|
||||
$invite->delete();
|
||||
return $this->all()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
* @return Collection
|
||||
*/
|
||||
public function destroy(User $user): bool
|
||||
public function all(): Collection
|
||||
{
|
||||
Log::debug(sprintf('Calling delete() on user %d', $user->id));
|
||||
|
||||
$user->groupMemberships()->delete();
|
||||
$user->delete();
|
||||
$this->deleteEmptyGroups();
|
||||
|
||||
return true;
|
||||
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
|
||||
* @param string $email
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
@@ -241,17 +206,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
*
|
||||
* @return Role|null
|
||||
*/
|
||||
public function getRole(string $role): ?Role
|
||||
{
|
||||
return Role::where('name', $role)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -287,10 +242,20 @@ class UserRepository implements UserRepositoryInterface
|
||||
return $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function find(int $userId): ?User
|
||||
{
|
||||
return User::find($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return basic user information.
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -325,12 +290,12 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param string $role
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param string $role
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRole(User|Authenticatable|null $user, string $role): bool
|
||||
public function hasRole(User | Authenticatable | null $user, string $role): bool
|
||||
{
|
||||
if (null === $user) {
|
||||
return false;
|
||||
@@ -348,7 +313,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function inviteUser(User|Authenticatable|null $user, string $email): InvitedUser
|
||||
public function inviteUser(User | Authenticatable | null $user, string $email): InvitedUser
|
||||
{
|
||||
$now = today(config('app.timezone'));
|
||||
$now->addDays(2);
|
||||
@@ -375,26 +340,11 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any role the user has.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $role
|
||||
*/
|
||||
public function removeRole(User $user, string $role): void
|
||||
{
|
||||
$roleObj = $this->getRole($role);
|
||||
if (null === $roleObj) {
|
||||
return;
|
||||
}
|
||||
$user->roles()->detach($roleObj->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set MFA code.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string|null $code
|
||||
* @param User $user
|
||||
* @param string|null $code
|
||||
*/
|
||||
public function setMFACode(User $user, ?string $code): void
|
||||
{
|
||||
@@ -403,7 +353,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
@@ -426,7 +376,32 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @param string $role
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function attachRole(User $user, string $role): bool
|
||||
{
|
||||
$roleObject = Role::where('name', $role)->first();
|
||||
if (null === $roleObject) {
|
||||
Log::error(sprintf('Could not find role "%s" in attachRole()', $role));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$user->roles()->attach($roleObject);
|
||||
} catch (QueryException $e) {
|
||||
// don't care
|
||||
Log::error(sprintf('Query exception when giving user a role: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function unblockUser(User $user): void
|
||||
{
|
||||
@@ -438,8 +413,8 @@ class UserRepository implements UserRepositoryInterface
|
||||
/**
|
||||
* Update user info.
|
||||
*
|
||||
* @param User $user
|
||||
* @param array $data
|
||||
* @param User $user
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
* @throws FireflyException
|
||||
@@ -464,11 +439,11 @@ class UserRepository implements UserRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the undo/confirm routine can't catch this one.
|
||||
* The user is NOT blocked.
|
||||
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the
|
||||
* undo/confirm routine can't catch this one. The user is NOT blocked.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $newEmail
|
||||
* @param User $user
|
||||
* @param string $newEmail
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
@@ -483,7 +458,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
|
||||
// save old email as pref
|
||||
app('preferences')->setForUser($user, 'admin_previous_email_latest', $oldEmail);
|
||||
app('preferences')->setForUser($user, 'admin_previous_email_'.date('Y-m-d-H-i-s'), $oldEmail);
|
||||
app('preferences')->setForUser($user, 'admin_previous_email_' . date('Y-m-d-H-i-s'), $oldEmail);
|
||||
|
||||
$user->email = $newEmail;
|
||||
$user->save();
|
||||
@@ -491,6 +466,31 @@ class UserRepository implements UserRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any role the user has.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $role
|
||||
*/
|
||||
public function removeRole(User $user, string $role): void
|
||||
{
|
||||
$roleObj = $this->getRole($role);
|
||||
if (null === $roleObj) {
|
||||
return;
|
||||
}
|
||||
$user->roles()->detach($roleObj->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
*
|
||||
* @return Role|null
|
||||
*/
|
||||
public function getRole(string $role): ?Role
|
||||
{
|
||||
return Role::where('name', $role)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@@ -44,8 +44,8 @@ interface UserRepositoryInterface
|
||||
/**
|
||||
* Gives a user a role.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $role
|
||||
* @param User $user
|
||||
* @param string $role
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -55,8 +55,8 @@ interface UserRepositoryInterface
|
||||
* This updates the users email address and records some things so it can be confirmed or undone later.
|
||||
* The user is blocked until the change is confirmed.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $newEmail
|
||||
* @param User $user
|
||||
* @param string $newEmail
|
||||
*
|
||||
* @return bool
|
||||
* @see updateEmail
|
||||
@@ -65,17 +65,17 @@ interface UserRepositoryInterface
|
||||
public function changeEmail(User $user, string $newEmail): bool;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $password
|
||||
* @param User $user
|
||||
* @param string $password
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function changePassword(User $user, string $password);
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param bool $isBlocked
|
||||
* @param string $code
|
||||
* @param User $user
|
||||
* @param bool $isBlocked
|
||||
* @param string $code
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -89,9 +89,9 @@ interface UserRepositoryInterface
|
||||
public function count(): int;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $displayName
|
||||
* @param string $description
|
||||
* @param string $name
|
||||
* @param string $displayName
|
||||
* @param string $description
|
||||
*
|
||||
* @return Role
|
||||
*/
|
||||
@@ -103,27 +103,27 @@ interface UserRepositoryInterface
|
||||
public function deleteEmptyGroups(): void;
|
||||
|
||||
/**
|
||||
* @param InvitedUser $invite
|
||||
* @param InvitedUser $invite
|
||||
* @return void
|
||||
*/
|
||||
public function deleteInvite(InvitedUser $invite): void;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(User $user): bool;
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @param int $userId
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function find(int $userId): ?User;
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @param string $email
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
@@ -142,22 +142,22 @@ interface UserRepositoryInterface
|
||||
public function getInvitedUsers(): Collection;
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
* @param string $role
|
||||
*
|
||||
* @return Role|null
|
||||
*/
|
||||
public function getRole(string $role): ?Role;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRoleByUser(User $user): ?string;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param int $groupId
|
||||
* @param User $user
|
||||
* @param int $groupId
|
||||
* @return array
|
||||
*/
|
||||
public function getRolesInGroup(User $user, int $groupId): array;
|
||||
@@ -165,29 +165,29 @@ interface UserRepositoryInterface
|
||||
/**
|
||||
* Return basic user information.
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserData(User $user): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param string $role
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param string $role
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRole(User|Authenticatable|null $user, string $role): bool;
|
||||
public function hasRole(User | Authenticatable | null $user, string $role): bool;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param string $email
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param string $email
|
||||
* @return InvitedUser
|
||||
*/
|
||||
public function inviteUser(User|Authenticatable|null $user, string $email): InvitedUser;
|
||||
public function inviteUser(User | Authenticatable | null $user, string $email): InvitedUser;
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $code
|
||||
* @return void
|
||||
*/
|
||||
public function redeemCode(string $code): void;
|
||||
@@ -195,47 +195,47 @@ interface UserRepositoryInterface
|
||||
/**
|
||||
* Remove any role the user has.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $role
|
||||
* @param User $user
|
||||
* @param string $role
|
||||
*/
|
||||
public function removeRole(User $user, string $role): void;
|
||||
|
||||
/**
|
||||
* Set MFA code.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string|null $code
|
||||
* @param User $user
|
||||
* @param string|null $code
|
||||
*/
|
||||
public function setMFACode(User $user, ?string $code): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function store(array $data): User;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*/
|
||||
public function unblockUser(User $user): void;
|
||||
|
||||
/**
|
||||
* Update user info.
|
||||
*
|
||||
* @param User $user
|
||||
* @param array $data
|
||||
* @param User $user
|
||||
* @param array $data
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function update(User $user, array $data): User;
|
||||
|
||||
/**
|
||||
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the undo/confirm routine can't catch this one.
|
||||
* The user is NOT blocked.
|
||||
* This updates the users email address. Same as changeEmail just without most logging. This makes sure that the
|
||||
* undo/confirm routine can't catch this one. The user is NOT blocked.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $newEmail
|
||||
* @param User $user
|
||||
* @param string $newEmail
|
||||
*
|
||||
* @return bool
|
||||
* @see changeEmail
|
||||
@@ -244,7 +244,7 @@ interface UserRepositoryInterface
|
||||
public function updateEmail(User $user, string $newEmail): bool;
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $code
|
||||
* @return bool
|
||||
*/
|
||||
public function validateInviteCode(string $code): bool;
|
||||
|
@@ -105,9 +105,9 @@ class WebhookRepository implements WebhookRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (null !== $user) {
|
||||
$this->user = $user;
|
||||
|
@@ -43,56 +43,56 @@ interface WebhookRepositoryInterface
|
||||
public function all(): Collection;
|
||||
|
||||
/**
|
||||
* @param Webhook $webhook
|
||||
* @param Webhook $webhook
|
||||
*/
|
||||
public function destroy(Webhook $webhook): void;
|
||||
|
||||
/**
|
||||
* @param WebhookAttempt $attempt
|
||||
* @param WebhookAttempt $attempt
|
||||
*/
|
||||
public function destroyAttempt(WebhookAttempt $attempt): void;
|
||||
|
||||
/**
|
||||
* @param WebhookMessage $message
|
||||
* @param WebhookMessage $message
|
||||
*/
|
||||
public function destroyMessage(WebhookMessage $message): void;
|
||||
|
||||
/**
|
||||
* @param WebhookMessage $webhookMessage
|
||||
* @param WebhookMessage $webhookMessage
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttempts(WebhookMessage $webhookMessage): Collection;
|
||||
|
||||
/**
|
||||
* @param Webhook $webhook
|
||||
* @param Webhook $webhook
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getMessages(Webhook $webhook): Collection;
|
||||
|
||||
/**
|
||||
* @param Webhook $webhook
|
||||
* @param Webhook $webhook
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getReadyMessages(Webhook $webhook): Collection;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User|Authenticatable|null $user): void;
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Webhook
|
||||
*/
|
||||
public function store(array $data): Webhook;
|
||||
|
||||
/**
|
||||
* @param Webhook $webhook
|
||||
* @param array $data
|
||||
* @param Webhook $webhook
|
||||
* @param array $data
|
||||
*
|
||||
* @return Webhook
|
||||
*/
|
||||
|
Reference in New Issue
Block a user