mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-04 05:06:37 +00:00
Code fixes.
This commit is contained in:
@@ -233,25 +233,35 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
* @param array|null $sort
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsByType(array $types): 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);
|
||||
}
|
||||
$res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types);
|
||||
if (0 !== count($res)) {
|
||||
$query->orderBy('accounts.order', 'ASC');
|
||||
|
||||
// add sort parameters. At this point they're filtered to allowed fields to sort by:
|
||||
if (count($sort) > 0) {
|
||||
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');
|
||||
}
|
||||
$query->orderBy('accounts.active', 'DESC');
|
||||
$query->orderBy('accounts.name', 'ASC');
|
||||
|
||||
return $query->get(['accounts.*']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,11 +121,12 @@ interface AccountRepositoryInterface
|
||||
public function getAccountsById(array $accountIds): Collection;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
* @param array|null $sort
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsByType(array $types): Collection;
|
||||
public function getAccountsByType(array $types, ?array $sort = []): Collection;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
|
||||
@@ -88,7 +88,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
*/
|
||||
public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum($start, $end, $accounts, $expense, $currency, TransactionType::WITHDRAWAL);
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByCurrency($journals, 'negative');
|
||||
|
||||
@@ -100,7 +100,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
public function sumExpensesByDestination(
|
||||
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum($start, $end, $accounts, $expense, $currency, TransactionType::WITHDRAWAL);
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'destination', 'negative');
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
public function sumExpensesBySource(
|
||||
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $expense = null, ?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum($start, $end, $accounts, $expense, $currency, TransactionType::WITHDRAWAL);
|
||||
$journals = $this->getTransactionsForSum(TransactionType::WITHDRAWAL, $start, $end, $accounts, $expense, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'source', 'negative');
|
||||
}
|
||||
@@ -121,7 +121,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
*/
|
||||
public function sumIncome(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum($start, $end, $accounts, $revenue, $currency, TransactionType::DEPOSIT);
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByCurrency($journals, 'positive');
|
||||
}
|
||||
@@ -132,7 +132,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
public function sumIncomeByDestination(
|
||||
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum($start, $end, $accounts, $revenue, $currency, TransactionType::DEPOSIT);
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'destination', 'positive');
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
public function sumIncomeBySource(
|
||||
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, ?TransactionCurrency $currency = null
|
||||
): array {
|
||||
$journals = $this->getTransactionsForSum($start, $end, $accounts, $revenue, $currency, TransactionType::DEPOSIT);
|
||||
$journals = $this->getTransactionsForSum(TransactionType::DEPOSIT, $start, $end, $accounts, $revenue, $currency);
|
||||
|
||||
return $this->groupByDirection($journals, 'source', 'positive');
|
||||
}
|
||||
@@ -153,7 +153,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
*/
|
||||
public function sumTransfers(Carbon $start, Carbon $end, ?Collection $accounts = null, ?TransactionCurrency $currency = null): array
|
||||
{
|
||||
$journals = $this->getTransactionsForSum($start, $end, $accounts, null, $currency, TransactionType::TRANSFER);
|
||||
$journals = $this->getTransactionsForSum(TransactionType::TRANSFER, $start, $end, $accounts, null, $currency);
|
||||
|
||||
return $this->groupByEither($journals);
|
||||
}
|
||||
@@ -234,8 +234,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
* @return array
|
||||
*/
|
||||
private function getTransactionsForSum(
|
||||
Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $opposing = null, ?TransactionCurrency $currency = null,
|
||||
string $type
|
||||
string $type, Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $opposing = null, ?TransactionCurrency $currency = null
|
||||
|
||||
): array {
|
||||
$start->startOfDay();
|
||||
$end->endOfDay();
|
||||
@@ -261,11 +261,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setSourceAccounts($opposing);
|
||||
}
|
||||
}
|
||||
if(TransactionType::TRANSFER === $type) {
|
||||
// supports only accounts, not opposing.
|
||||
if(null !== $accounts) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
// supports only accounts, not opposing.
|
||||
if (TransactionType::TRANSFER === $type && null !== $accounts) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
|
||||
if (null !== $currency) {
|
||||
|
||||
@@ -174,10 +174,8 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
$attachment->title = $data['title'];
|
||||
}
|
||||
|
||||
if (array_key_exists('filename', $data)) {
|
||||
if ('' !== (string)$data['filename'] && $data['filename'] !== $attachment->filename) {
|
||||
$attachment->filename = $data['filename'];
|
||||
}
|
||||
if (array_key_exists('filename', $data) && '' !== (string)$data['filename'] && $data['filename'] !== $attachment->filename) {
|
||||
$attachment->filename = $data['filename'];
|
||||
}
|
||||
// update model (move attachment)
|
||||
// should be validated already:
|
||||
|
||||
@@ -505,14 +505,6 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
}
|
||||
$simple = $set->each(
|
||||
static function (Carbon $date) {
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
);
|
||||
|
||||
//Log::debug(sprintf('Found dates between %s and %s:', $start->format('Y-m-d'), $end->format('Y-m-d')), $simple->toArray());
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
@@ -657,12 +649,6 @@ class BillRepository implements BillRepositoryInterface
|
||||
while ($start < $date) {
|
||||
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
}
|
||||
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
|
||||
//Log::debug('nextDateMatch: Final start is ' . $start->format('Y-m-d'));
|
||||
//Log::debug('nextDateMatch: Matching end is ' . $end->format('Y-m-d'));
|
||||
|
||||
$cache->store($start);
|
||||
|
||||
return $start;
|
||||
|
||||
@@ -151,7 +151,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment, int $index) use ($disk) {
|
||||
static function (Attachment $attachment) use ($disk) {
|
||||
/** @var Note $note */
|
||||
$note = $attachment->notes()->first();
|
||||
// only used in v1 view of tags
|
||||
|
||||
@@ -116,7 +116,7 @@ class WebhookRepository implements WebhookRepositoryInterface
|
||||
*/
|
||||
public function store(array $data): Webhook
|
||||
{
|
||||
$secret = $random = Str::random(24);
|
||||
$secret = Str::random(24);
|
||||
$fullData = [
|
||||
'user_id' => $this->user->id,
|
||||
'active' => $data['active'] ?? false,
|
||||
@@ -144,7 +144,7 @@ class WebhookRepository implements WebhookRepositoryInterface
|
||||
$webhook->url = $data['url'] ?? $webhook->url;
|
||||
|
||||
if (true === $data['secret']) {
|
||||
$secret = $random = Str::random(24);
|
||||
$secret = Str::random(24);
|
||||
$webhook->secret = $secret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user