mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Code cleanup.
This commit is contained in:
@@ -35,10 +35,6 @@ trait AccountCollection
|
||||
{
|
||||
/**
|
||||
* These accounts must not be included.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -55,10 +51,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* These accounts must not be destination accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeDestinationAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -74,10 +66,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* These accounts must not be source accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeSourceAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -93,10 +81,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* Define which accounts can be part of the source and destination transactions.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -108,7 +92,7 @@ trait AccountCollection
|
||||
$query->orWhereIn('destination.account_id', $accountIds);
|
||||
}
|
||||
);
|
||||
//app('log')->debug(sprintf('GroupCollector: setAccounts: %s', implode(', ', $accountIds)));
|
||||
// app('log')->debug(sprintf('GroupCollector: setAccounts: %s', implode(', ', $accountIds)));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -116,10 +100,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* Both source AND destination must be in this list of accounts.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setBothAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -139,10 +119,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* Define which accounts can be part of the source and destination transactions.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setDestinationAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -158,10 +134,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* Define which accounts can NOT be part of the source and destination transactions.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setNotAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -173,7 +145,7 @@ trait AccountCollection
|
||||
$query->whereNotIn('destination.account_id', $accountIds);
|
||||
}
|
||||
);
|
||||
//app('log')->debug(sprintf('GroupCollector: setAccounts: %s', implode(', ', $accountIds)));
|
||||
// app('log')->debug(sprintf('GroupCollector: setAccounts: %s', implode(', ', $accountIds)));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -181,10 +153,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* Define which accounts can be part of the source and destination transactions.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setSourceAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -200,10 +168,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* Either account can be set, but NOT both. This effectively excludes internal transfers.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setXorAccounts(Collection $accounts): GroupCollectorInterface
|
||||
{
|
||||
@@ -237,8 +201,6 @@ trait AccountCollection
|
||||
|
||||
/**
|
||||
* Will include the source and destination account names and types.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withAccountInformation(): GroupCollectorInterface
|
||||
{
|
||||
|
||||
@@ -34,10 +34,6 @@ trait AmountCollection
|
||||
{
|
||||
/**
|
||||
* Get transactions with a specific amount.
|
||||
*
|
||||
* @param string $amount
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function amountIs(string $amount): GroupCollectorInterface
|
||||
{
|
||||
@@ -50,9 +46,6 @@ trait AmountCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function amountIsNot(string $amount): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
@@ -66,10 +59,6 @@ trait AmountCollection
|
||||
|
||||
/**
|
||||
* Get transactions where the amount is less than.
|
||||
*
|
||||
* @param string $amount
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function amountLess(string $amount): GroupCollectorInterface
|
||||
{
|
||||
@@ -84,10 +73,6 @@ trait AmountCollection
|
||||
|
||||
/**
|
||||
* Get transactions where the amount is more than.
|
||||
*
|
||||
* @param string $amount
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function amountMore(string $amount): GroupCollectorInterface
|
||||
{
|
||||
@@ -102,10 +87,6 @@ trait AmountCollection
|
||||
|
||||
/**
|
||||
* Get transactions with a specific foreign amount.
|
||||
*
|
||||
* @param string $amount
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function foreignAmountIs(string $amount): GroupCollectorInterface
|
||||
{
|
||||
@@ -121,10 +102,6 @@ trait AmountCollection
|
||||
|
||||
/**
|
||||
* Get transactions with a specific foreign amount.
|
||||
*
|
||||
* @param string $amount
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function foreignAmountIsNot(string $amount): GroupCollectorInterface
|
||||
{
|
||||
@@ -140,10 +117,6 @@ trait AmountCollection
|
||||
|
||||
/**
|
||||
* Get transactions where the amount is less than.
|
||||
*
|
||||
* @param string $amount
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function foreignAmountLess(string $amount): GroupCollectorInterface
|
||||
{
|
||||
@@ -159,10 +132,6 @@ trait AmountCollection
|
||||
|
||||
/**
|
||||
* Get transactions where the amount is more than.
|
||||
*
|
||||
* @param string $amount
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function foreignAmountMore(string $amount): GroupCollectorInterface
|
||||
{
|
||||
|
||||
@@ -35,15 +35,11 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
*/
|
||||
trait AttachmentCollection
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNameContains(string $name): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
$this->withAttachmentInformation();
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $object
|
||||
@@ -64,6 +60,7 @@ trait AttachmentCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -73,8 +70,6 @@ trait AttachmentCollection
|
||||
|
||||
/**
|
||||
* Has attachments
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function hasAttachments(): GroupCollectorInterface
|
||||
{
|
||||
@@ -86,29 +81,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join table to get attachment information.
|
||||
*/
|
||||
private function joinAttachmentTables(): void
|
||||
{
|
||||
if (false === $this->hasJoinedAttTables) {
|
||||
// join some extra tables:
|
||||
$this->hasJoinedAttTables = true;
|
||||
$this->query->leftJoin('attachments', 'attachments.attachable_id', '=', 'transaction_journals.id')
|
||||
->where(
|
||||
static function (EloquentBuilder $q1) { // @phpstan-ignore-line
|
||||
$q1->where('attachments.attachable_type', TransactionJournal::class);
|
||||
$q1->where('attachments.uploaded', true);
|
||||
$q1->whereNull('attachments.deleted_at');
|
||||
$q1->orWhereNull('attachments.attachable_type');
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withAttachmentInformation(): GroupCollectorInterface
|
||||
{
|
||||
$this->fields[] = 'attachments.id as attachment_id';
|
||||
@@ -120,20 +92,17 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNameDoesNotContain(string $name): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
$this->withAttachmentInformation();
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $object
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
$filter = static function (array $object) use ($name): bool {
|
||||
@@ -150,6 +119,7 @@ trait AttachmentCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -157,20 +127,17 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNameDoesNotEnd(string $name): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
$this->withAttachmentInformation();
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $object
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
$filter = static function (array $object) use ($name): bool {
|
||||
@@ -187,6 +154,7 @@ trait AttachmentCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -194,20 +162,17 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNameDoesNotStart(string $name): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
$this->withAttachmentInformation();
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param array $object
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
$filter = static function (array $object) use ($name): bool {
|
||||
@@ -224,6 +189,7 @@ trait AttachmentCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -231,11 +197,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNameEnds(string $name): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -254,6 +215,7 @@ trait AttachmentCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -261,11 +223,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNameIs(string $name): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -281,6 +238,7 @@ trait AttachmentCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -288,11 +246,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNameIsNot(string $name): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -308,6 +261,7 @@ trait AttachmentCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -315,11 +269,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNameStarts(string $name): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -338,6 +287,7 @@ trait AttachmentCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -345,11 +295,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNotesAre(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -359,12 +304,14 @@ trait AttachmentCollection
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
/** @var array $attachment */
|
||||
foreach ($transaction['attachments'] as $attachment) {
|
||||
/** @var Attachment|null $object */
|
||||
/** @var null|Attachment $object */
|
||||
$object = auth()->user()->attachments()->find($attachment['id']);
|
||||
$notes = (string)$object?->notes()->first()?->text;
|
||||
return $notes !== '' && $notes === $value;
|
||||
|
||||
return '' !== $notes && $notes === $value;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -372,11 +319,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNotesAreNot(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -386,12 +328,14 @@ trait AttachmentCollection
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
/** @var array $attachment */
|
||||
foreach ($transaction['attachments'] as $attachment) {
|
||||
/** @var Attachment|null $object */
|
||||
/** @var null|Attachment $object */
|
||||
$object = auth()->user()->attachments()->find($attachment['id']);
|
||||
$notes = (string)$object?->notes()->first()?->text;
|
||||
return $notes !== '' && $notes !== $value;
|
||||
|
||||
return '' !== $notes && $notes !== $value;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -399,11 +343,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNotesContains(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -413,12 +352,14 @@ trait AttachmentCollection
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
/** @var array $attachment */
|
||||
foreach ($transaction['attachments'] as $attachment) {
|
||||
/** @var Attachment|null $object */
|
||||
/** @var null|Attachment $object */
|
||||
$object = auth()->user()->attachments()->find($attachment['id']);
|
||||
$notes = (string)$object?->notes()->first()?->text;
|
||||
return $notes !== '' && str_contains(strtolower($notes), strtolower($value));
|
||||
|
||||
return '' !== $notes && str_contains(strtolower($notes), strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -426,11 +367,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNotesDoNotContain(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -440,12 +376,14 @@ trait AttachmentCollection
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
/** @var array $attachment */
|
||||
foreach ($transaction['attachments'] as $attachment) {
|
||||
/** @var Attachment|null $object */
|
||||
/** @var null|Attachment $object */
|
||||
$object = auth()->user()->attachments()->find($attachment['id']);
|
||||
$notes = (string)$object?->notes()->first()?->text;
|
||||
return $notes !== '' && !str_contains(strtolower($notes), strtolower($value));
|
||||
|
||||
return '' !== $notes && !str_contains(strtolower($notes), strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -453,11 +391,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNotesDoNotEnd(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -467,12 +400,14 @@ trait AttachmentCollection
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
/** @var array $attachment */
|
||||
foreach ($transaction['attachments'] as $attachment) {
|
||||
/** @var Attachment|null $object */
|
||||
/** @var null|Attachment $object */
|
||||
$object = auth()->user()->attachments()->find($attachment['id']);
|
||||
$notes = (string)$object?->notes()->first()?->text;
|
||||
return $notes !== '' && !str_ends_with(strtolower($notes), strtolower($value));
|
||||
|
||||
return '' !== $notes && !str_ends_with(strtolower($notes), strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -480,11 +415,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNotesDoNotStart(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -494,12 +424,14 @@ trait AttachmentCollection
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
/** @var array $attachment */
|
||||
foreach ($transaction['attachments'] as $attachment) {
|
||||
/** @var Attachment|null $object */
|
||||
/** @var null|Attachment $object */
|
||||
$object = auth()->user()->attachments()->find($attachment['id']);
|
||||
$notes = (string)$object?->notes()->first()?->text;
|
||||
return $notes !== '' && !str_starts_with(strtolower($notes), strtolower($value));
|
||||
|
||||
return '' !== $notes && !str_starts_with(strtolower($notes), strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -507,11 +439,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNotesEnds(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -521,12 +448,14 @@ trait AttachmentCollection
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
/** @var array $attachment */
|
||||
foreach ($transaction['attachments'] as $attachment) {
|
||||
/** @var Attachment|null $object */
|
||||
/** @var null|Attachment $object */
|
||||
$object = auth()->user()->attachments()->find($attachment['id']);
|
||||
$notes = (string)$object?->notes()->first()?->text;
|
||||
return $notes !== '' && str_ends_with(strtolower($notes), strtolower($value));
|
||||
|
||||
return '' !== $notes && str_ends_with(strtolower($notes), strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -534,11 +463,6 @@ trait AttachmentCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function attachmentNotesStarts(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->hasAttachments();
|
||||
@@ -548,12 +472,14 @@ trait AttachmentCollection
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
/** @var array $attachment */
|
||||
foreach ($transaction['attachments'] as $attachment) {
|
||||
/** @var Attachment|null $object */
|
||||
/** @var null|Attachment $object */
|
||||
$object = auth()->user()->attachments()->find($attachment['id']);
|
||||
$notes = (string)$object?->notes()->first()?->text;
|
||||
return $notes !== '' && str_starts_with(strtolower($notes), strtolower($value));
|
||||
|
||||
return '' !== $notes && str_starts_with(strtolower($notes), strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -563,8 +489,6 @@ trait AttachmentCollection
|
||||
|
||||
/**
|
||||
* Has attachments
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function hasNoAttachments(): GroupCollectorInterface
|
||||
{
|
||||
@@ -577,13 +501,35 @@ trait AttachmentCollection
|
||||
->orWhere(static function (Builder $q2) {
|
||||
$q2
|
||||
->whereNotNull('attachments.attachable_id')
|
||||
->whereNotNull('attachments.deleted_at');
|
||||
->whereNotNull('attachments.deleted_at')
|
||||
;
|
||||
// id is not null
|
||||
// deleted at is not null.
|
||||
});
|
||||
})
|
||||
;
|
||||
});
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join table to get attachment information.
|
||||
*/
|
||||
private function joinAttachmentTables(): void
|
||||
{
|
||||
if (false === $this->hasJoinedAttTables) {
|
||||
// join some extra tables:
|
||||
$this->hasJoinedAttTables = true;
|
||||
$this->query->leftJoin('attachments', 'attachments.attachable_id', '=', 'transaction_journals.id')
|
||||
->where(
|
||||
static function (EloquentBuilder $q1) { // @phpstan-ignore-line
|
||||
$q1->where('attachments.attachable_type', TransactionJournal::class);
|
||||
$q1->where('attachments.uploaded', true);
|
||||
$q1->whereNull('attachments.deleted_at');
|
||||
$q1->orWhereNull('attachments.attachable_type');
|
||||
}
|
||||
)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,6 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
trait MetaCollection
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeBills(Collection $bills): GroupCollectorInterface
|
||||
{
|
||||
$this->withBillInformation();
|
||||
@@ -55,8 +52,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Will include bill name + ID, if any.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withBillInformation(): GroupCollectorInterface
|
||||
{
|
||||
@@ -74,10 +69,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Exclude a specific budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeBudget(Budget $budget): GroupCollectorInterface
|
||||
{
|
||||
@@ -93,8 +84,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Will include budget ID + name, if any.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withBudgetInformation(): GroupCollectorInterface
|
||||
{
|
||||
@@ -112,9 +101,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeBudgets(Collection $budgets): GroupCollectorInterface
|
||||
{
|
||||
if ($budgets->count() > 0) {
|
||||
@@ -128,9 +114,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeCategories(Collection $categories): GroupCollectorInterface
|
||||
{
|
||||
if ($categories->count() > 0) {
|
||||
@@ -146,8 +129,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Will include category ID + name, if any.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withCategoryInformation(): GroupCollectorInterface
|
||||
{
|
||||
@@ -167,10 +148,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Exclude a specific category.
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeCategory(Category $category): GroupCollectorInterface
|
||||
{
|
||||
@@ -184,9 +161,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeExternalId(string $externalId): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -196,22 +170,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join table to get tag information.
|
||||
*/
|
||||
protected function joinMetaDataTables(): void
|
||||
{
|
||||
if (false === $this->hasJoinedMetaTables) {
|
||||
$this->hasJoinedMetaTables = true;
|
||||
$this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id');
|
||||
$this->fields[] = 'journal_meta.name as meta_name';
|
||||
$this->fields[] = 'journal_meta.data as meta_data';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeExternalUrl(string $url): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -221,9 +179,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeInternalReference(string $internalReference): GroupCollectorInterface
|
||||
{
|
||||
$internalReference = (string)json_encode($internalReference);
|
||||
@@ -236,9 +191,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeRecurrenceId(string $recurringId): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -248,9 +200,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function externalIdContains(string $externalId): GroupCollectorInterface
|
||||
{
|
||||
$externalId = (string)json_encode($externalId);
|
||||
@@ -263,9 +212,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function externalIdDoesNotContain(string $externalId): GroupCollectorInterface
|
||||
{
|
||||
$externalId = (string)json_encode($externalId);
|
||||
@@ -278,9 +224,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function externalIdDoesNotEnd(string $externalId): GroupCollectorInterface
|
||||
{
|
||||
$externalId = (string)json_encode($externalId);
|
||||
@@ -293,9 +236,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function externalIdDoesNotStart(string $externalId): GroupCollectorInterface
|
||||
{
|
||||
$externalId = (string)json_encode($externalId);
|
||||
@@ -308,9 +248,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function externalIdEnds(string $externalId): GroupCollectorInterface
|
||||
{
|
||||
$externalId = (string)json_encode($externalId);
|
||||
@@ -323,9 +260,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function externalIdStarts(string $externalId): GroupCollectorInterface
|
||||
{
|
||||
$externalId = (string)json_encode($externalId);
|
||||
@@ -338,11 +272,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function externalUrlContains(string $url): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -354,11 +283,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function externalUrlDoesNotContain(string $url): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -370,11 +294,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function externalUrlDoesNotEnd(string $url): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -386,17 +305,12 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function externalUrlDoesNotStart(string $url): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
$url = (string)json_encode($url);
|
||||
$url = str_replace('\\', '\\\\', rtrim($url, '"'));
|
||||
//var_dump($url);
|
||||
// var_dump($url);
|
||||
|
||||
$this->query->where('journal_meta.name', '=', 'external_url');
|
||||
$this->query->where('journal_meta.data', 'NOT LIKE', sprintf('%s%%', $url));
|
||||
@@ -404,11 +318,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function externalUrlEnds(string $url): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -420,17 +329,12 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function externalUrlStarts(string $url): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
$url = (string)json_encode($url);
|
||||
$url = str_replace('\\', '\\\\', rtrim($url, '"'));
|
||||
//var_dump($url);
|
||||
// var_dump($url);
|
||||
|
||||
$this->query->where('journal_meta.name', '=', 'external_url');
|
||||
$this->query->where('journal_meta.data', 'LIKE', sprintf('%s%%', $url));
|
||||
@@ -440,8 +344,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Where has no tags.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function hasAnyTag(): GroupCollectorInterface
|
||||
{
|
||||
@@ -451,9 +353,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withTagInformation(): GroupCollectorInterface
|
||||
{
|
||||
$this->fields[] = 'tags.id as tag_id';
|
||||
@@ -469,28 +368,12 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join table to get tag information.
|
||||
*/
|
||||
protected function joinTagTables(): void
|
||||
{
|
||||
if (false === $this->hasJoinedTagTables) {
|
||||
// join some extra tables:
|
||||
$this->hasJoinedTagTables = true;
|
||||
$this->query->leftJoin('tag_transaction_journal', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
$this->query->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function internalReferenceContains(string $internalReference): GroupCollectorInterface
|
||||
{
|
||||
$internalReference = (string)json_encode($internalReference);
|
||||
$internalReference = str_replace('\\', '\\\\', trim($internalReference, '"'));
|
||||
//var_dump($internalReference);
|
||||
//exit;
|
||||
// var_dump($internalReference);
|
||||
// exit;
|
||||
|
||||
$this->joinMetaDataTables();
|
||||
$this->query->where('journal_meta.name', '=', 'internal_reference');
|
||||
@@ -499,9 +382,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function internalReferenceDoesNotContain(string $internalReference): GroupCollectorInterface
|
||||
{
|
||||
$internalReference = (string)json_encode($internalReference);
|
||||
@@ -514,9 +394,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function internalReferenceDoesNotEnd(string $internalReference): GroupCollectorInterface
|
||||
{
|
||||
$internalReference = (string)json_encode($internalReference);
|
||||
@@ -529,9 +406,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function internalReferenceDoesNotStart(string $internalReference): GroupCollectorInterface
|
||||
{
|
||||
$internalReference = (string)json_encode($internalReference);
|
||||
@@ -544,9 +418,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function internalReferenceEnds(string $internalReference): GroupCollectorInterface
|
||||
{
|
||||
$internalReference = (string)json_encode($internalReference);
|
||||
@@ -559,9 +430,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function internalReferenceStarts(string $internalReference): GroupCollectorInterface
|
||||
{
|
||||
$internalReference = (string)json_encode($internalReference);
|
||||
@@ -574,11 +442,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesContain(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -587,9 +450,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withNotes(): GroupCollectorInterface
|
||||
{
|
||||
if (false === $this->hasNotesInformation) {
|
||||
@@ -610,11 +470,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesDoNotContain(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -626,11 +481,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesDontEndWith(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -642,11 +492,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesDontStartWith(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -658,11 +503,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesEndWith(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -671,11 +511,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesExactly(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -684,11 +519,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesExactlyNot(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -700,11 +530,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function notesStartWith(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -715,10 +540,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit the search to a specific bill.
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setBill(Bill $bill): GroupCollectorInterface
|
||||
{
|
||||
@@ -730,10 +551,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit the search to a specific set of bills.
|
||||
*
|
||||
* @param Collection $bills
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setBills(Collection $bills): GroupCollectorInterface
|
||||
{
|
||||
@@ -745,10 +562,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit the search to a specific budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setBudget(Budget $budget): GroupCollectorInterface
|
||||
{
|
||||
@@ -760,10 +573,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit the search to a specific set of budgets.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): GroupCollectorInterface
|
||||
{
|
||||
@@ -777,10 +586,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit the search to a specific bunch of categories.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): GroupCollectorInterface
|
||||
{
|
||||
@@ -794,10 +599,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit the search to a specific category.
|
||||
*
|
||||
* @param Category $category
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setCategory(Category $category): GroupCollectorInterface
|
||||
{
|
||||
@@ -807,9 +608,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setExternalId(string $externalId): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -819,9 +617,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setExternalUrl(string $url): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -831,9 +626,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setInternalReference(string $internalReference): GroupCollectorInterface
|
||||
{
|
||||
$internalReference = (string)json_encode($internalReference);
|
||||
@@ -846,9 +638,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setRecurrenceId(string $recurringId): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -858,9 +647,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSepaCT(string $sepaCT): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -873,10 +659,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit results to a specific tag.
|
||||
*
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setTag(Tag $tag): GroupCollectorInterface
|
||||
{
|
||||
@@ -888,10 +670,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit results to a specific set of tags.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): GroupCollectorInterface
|
||||
{
|
||||
@@ -904,10 +682,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Without tags
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setWithoutSpecificTags(Collection $tags): GroupCollectorInterface
|
||||
{
|
||||
@@ -924,17 +698,14 @@ trait MetaCollection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withAnyNotes(): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -945,8 +716,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit results to transactions without a bill.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withBill(): GroupCollectorInterface
|
||||
{
|
||||
@@ -958,8 +727,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a budget..
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withBudget(): GroupCollectorInterface
|
||||
{
|
||||
@@ -971,8 +738,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a category.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withCategory(): GroupCollectorInterface
|
||||
{
|
||||
@@ -982,9 +747,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withExternalId(): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -994,9 +756,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withExternalUrl(): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -1008,8 +767,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a bill.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutBill(): GroupCollectorInterface
|
||||
{
|
||||
@@ -1020,8 +777,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a budget..
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutBudget(): GroupCollectorInterface
|
||||
{
|
||||
@@ -1033,8 +788,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a category.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutCategory(): GroupCollectorInterface
|
||||
{
|
||||
@@ -1044,9 +797,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withoutExternalId(): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -1065,9 +815,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withoutExternalUrl(): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -1086,9 +833,6 @@ trait MetaCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutNotes(): GroupCollectorInterface
|
||||
{
|
||||
$this->withNotes();
|
||||
@@ -1102,8 +846,6 @@ trait MetaCollection
|
||||
|
||||
/**
|
||||
* Where has no tags.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutTags(): GroupCollectorInterface
|
||||
{
|
||||
@@ -1112,4 +854,30 @@ trait MetaCollection
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join table to get tag information.
|
||||
*/
|
||||
protected function joinMetaDataTables(): void
|
||||
{
|
||||
if (false === $this->hasJoinedMetaTables) {
|
||||
$this->hasJoinedMetaTables = true;
|
||||
$this->query->leftJoin('journal_meta', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id');
|
||||
$this->fields[] = 'journal_meta.name as meta_name';
|
||||
$this->fields[] = 'journal_meta.data as meta_data';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Join table to get tag information.
|
||||
*/
|
||||
protected function joinTagTables(): void
|
||||
{
|
||||
if (false === $this->hasJoinedTagTables) {
|
||||
// join some extra tables:
|
||||
$this->hasJoinedTagTables = true;
|
||||
$this->query->leftJoin('tag_transaction_journal', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
$this->query->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,57 +32,34 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
*/
|
||||
trait TimeCollection
|
||||
{
|
||||
/**
|
||||
* @param string $day
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function dayAfter(string $day): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay('transaction_journals.date', '>=', $day);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function dayBefore(string $day): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay('transaction_journals.date', '<=', $day);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function dayIs(string $day): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay('transaction_journals.date', '=', $day);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function dayIsNot(string $day): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay('transaction_journals.date', '!=', $day);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeMetaDateRange(Carbon $start, Carbon $end, string $field): GroupCollectorInterface
|
||||
{
|
||||
if ($end < $start) {
|
||||
@@ -107,9 +84,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function withMetaDate(string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->joinMetaDataTables();
|
||||
@@ -119,13 +93,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeObjectRange(Carbon $start, Carbon $end, string $field): GroupCollectorInterface
|
||||
{
|
||||
$after = $start->format('Y-m-d 00:00:00');
|
||||
@@ -137,12 +104,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeRange(Carbon $start, Carbon $end): GroupCollectorInterface
|
||||
{
|
||||
if ($end < $start) {
|
||||
@@ -157,12 +118,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaDayAfter(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -181,12 +136,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaDayBefore(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -205,12 +154,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaDayIs(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -225,15 +168,10 @@ trait TimeCollection
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaDayIsNot(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -248,15 +186,10 @@ trait TimeCollection
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaMonthAfter(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -275,12 +208,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaMonthBefore(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -299,12 +226,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaMonthIs(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -319,15 +240,10 @@ trait TimeCollection
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaMonthIsNot(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -342,15 +258,10 @@ trait TimeCollection
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaYearAfter(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -369,12 +280,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaYearBefore(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -393,12 +298,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaYearIs(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -417,12 +316,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaYearIsNot(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -433,6 +326,7 @@ trait TimeCollection
|
||||
return $year !== (string)$transaction[$field]->year;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
@@ -440,200 +334,120 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function monthAfter(string $month): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereMonth('transaction_journals.date', '>=', $month);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function monthBefore(string $month): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereMonth('transaction_journals.date', '<=', $month);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function monthIs(string $month): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereMonth('transaction_journals.date', '=', $month);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function monthIsNot(string $month): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereMonth('transaction_journals.date', '!=', $month);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectDayAfter(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay(sprintf('transaction_journals.%s', $field), '>=', $day);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectDayBefore(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay(sprintf('transaction_journals.%s', $field), '<=', $day);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectDayIs(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay(sprintf('transaction_journals.%s', $field), '=', $day);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectDayIsNot(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay(sprintf('transaction_journals.%s', $field), '!=', $day);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectMonthAfter(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereMonth(sprintf('transaction_journals.%s', $field), '>=', $month);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectMonthBefore(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereMonth(sprintf('transaction_journals.%s', $field), '<=', $month);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectMonthIs(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereMonth(sprintf('transaction_journals.%s', $field), '=', $month);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectMonthIsNot(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereMonth(sprintf('transaction_journals.%s', $field), '!=', $month);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectYearAfter(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereYear(sprintf('transaction_journals.%s', $field), '>=', $year);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectYearBefore(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereYear(sprintf('transaction_journals.%s', $field), '<=', $year);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectYearIs(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereYear(sprintf('transaction_journals.%s', $field), '=', $year);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function objectYearIsNot(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereYear(sprintf('transaction_journals.%s', $field), '!=', $year);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect transactions after a specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setAfter(Carbon $date): GroupCollectorInterface
|
||||
{
|
||||
@@ -645,10 +459,6 @@ trait TimeCollection
|
||||
|
||||
/**
|
||||
* Collect transactions before a specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setBefore(Carbon $date): GroupCollectorInterface
|
||||
{
|
||||
@@ -660,10 +470,6 @@ trait TimeCollection
|
||||
|
||||
/**
|
||||
* Collect transactions created on a specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setCreatedAt(Carbon $date): GroupCollectorInterface
|
||||
{
|
||||
@@ -677,10 +483,6 @@ trait TimeCollection
|
||||
|
||||
/**
|
||||
* Set the end time of the results to return.
|
||||
*
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setEnd(Carbon $end): GroupCollectorInterface
|
||||
{
|
||||
@@ -692,12 +494,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setMetaAfter(Carbon $date, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -717,12 +513,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setMetaBefore(Carbon $date, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
@@ -741,13 +531,6 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setMetaDateRange(Carbon $start, Carbon $end, string $field): GroupCollectorInterface
|
||||
{
|
||||
if ($end < $start) {
|
||||
@@ -769,15 +552,10 @@ trait TimeCollection
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setObjectAfter(Carbon $date, string $field): GroupCollectorInterface
|
||||
{
|
||||
$afterStr = $date->format('Y-m-d 00:00:00');
|
||||
@@ -786,26 +564,14 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setObjectBefore(Carbon $date, string $field): GroupCollectorInterface
|
||||
{
|
||||
$afterStr = $date->format('Y-m-d 00:00:00');
|
||||
$this->query->where(sprintf('transaction_journals.%s', $field), '<=', $afterStr);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $field
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setObjectRange(Carbon $start, Carbon $end, string $field): GroupCollectorInterface
|
||||
{
|
||||
$after = $start->format('Y-m-d 00:00:00');
|
||||
@@ -820,11 +586,6 @@ trait TimeCollection
|
||||
* Set the start and end time of the results to return.
|
||||
*
|
||||
* Can either or both be NULL
|
||||
*
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setRange(?Carbon $start, ?Carbon $end): GroupCollectorInterface
|
||||
{
|
||||
@@ -847,10 +608,6 @@ trait TimeCollection
|
||||
|
||||
/**
|
||||
* Set the start time of the results to return.
|
||||
*
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setStart(Carbon $start): GroupCollectorInterface
|
||||
{
|
||||
@@ -863,10 +620,6 @@ trait TimeCollection
|
||||
|
||||
/**
|
||||
* Collect transactions updated on a specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setUpdatedAt(Carbon $date): GroupCollectorInterface
|
||||
{
|
||||
@@ -878,47 +631,31 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function yearAfter(string $year): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereYear('transaction_journals.date', '>=', $year);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function yearBefore(string $year): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereYear('transaction_journals.date', '<=', $year);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function yearIs(string $year): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereYear('transaction_journals.date', '=', $year);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function yearIsNot(string $year): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereYear('transaction_journals.date', '!=', $year);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace FireflyIII\Helpers\Collector;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Carbon\Exceptions\InvalidFormatException;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\Extensions\AccountCollection;
|
||||
@@ -47,8 +46,6 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class GroupCollector
|
||||
*
|
||||
|
||||
*/
|
||||
class GroupCollector implements GroupCollectorInterface
|
||||
{
|
||||
@@ -101,7 +98,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$this->stringFields = ['amount', 'foreign_amount'];
|
||||
$this->total = 0;
|
||||
$this->fields = [
|
||||
# group
|
||||
// group
|
||||
'transaction_groups.id as transaction_group_id',
|
||||
'transaction_groups.user_id as user_id',
|
||||
'transaction_groups.user_group_id as user_group_id',
|
||||
@@ -109,22 +106,22 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transaction_groups.updated_at as updated_at',
|
||||
'transaction_groups.title as transaction_group_title',
|
||||
|
||||
# journal
|
||||
// journal
|
||||
'transaction_journals.id as transaction_journal_id',
|
||||
'transaction_journals.transaction_type_id',
|
||||
'transaction_journals.description',
|
||||
'transaction_journals.date',
|
||||
'transaction_journals.order',
|
||||
|
||||
# types
|
||||
// types
|
||||
'transaction_types.type as transaction_type_type',
|
||||
|
||||
# source info (always present)
|
||||
// source info (always present)
|
||||
'source.id as source_transaction_id',
|
||||
'source.account_id as source_account_id',
|
||||
'source.reconciled',
|
||||
|
||||
# currency info:
|
||||
// currency info:
|
||||
'source.amount as amount',
|
||||
'source.transaction_currency_id as currency_id',
|
||||
'currency.code as currency_code',
|
||||
@@ -132,7 +129,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'currency.symbol as currency_symbol',
|
||||
'currency.decimal_places as currency_decimal_places',
|
||||
|
||||
# foreign currency info
|
||||
// foreign currency info
|
||||
'source.foreign_amount as foreign_amount',
|
||||
'source.foreign_currency_id as foreign_currency_id',
|
||||
'foreign_currency.code as foreign_currency_code',
|
||||
@@ -140,14 +137,11 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'foreign_currency.symbol as foreign_currency_symbol',
|
||||
'foreign_currency.decimal_places as foreign_currency_decimal_places',
|
||||
|
||||
# destination account info (always present)
|
||||
// destination account info (always present)
|
||||
'destination.account_id as destination_account_id',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function descriptionDoesNotEnd(array $array): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
@@ -175,9 +169,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function descriptionDoesNotStart(array $array): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
@@ -205,9 +196,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function descriptionEnds(array $array): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
@@ -234,9 +222,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function descriptionIs(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
@@ -249,9 +234,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function descriptionIsNot(string $value): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
@@ -269,9 +251,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function descriptionStarts(array $array): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
@@ -298,9 +277,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function dumpQuery(): void
|
||||
{
|
||||
$query = $this->query->select($this->fields)->toSql();
|
||||
@@ -311,7 +287,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$replace = (string)$param;
|
||||
}
|
||||
$pos = strpos($query, '?');
|
||||
if ($pos !== false) {
|
||||
if (false !== $pos) {
|
||||
$query = substr_replace($query, $replace, $pos, 1);
|
||||
}
|
||||
}
|
||||
@@ -322,9 +298,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function dumpQueryInLogs(): void
|
||||
{
|
||||
app('log')->debug($this->query->select($this->fields)->toSql());
|
||||
@@ -333,10 +306,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/**
|
||||
* Limit results to NOT a specific currency, either foreign or normal one.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeCurrency(TransactionCurrency $currency): GroupCollectorInterface
|
||||
{
|
||||
@@ -355,9 +324,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeForeignCurrency(TransactionCurrency $currency): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(static function (EloquentBuilder $q2) use ($currency) { // @phpstan-ignore-line
|
||||
@@ -370,10 +336,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/**
|
||||
* Limit the result to NOT a set of specific transaction groups.
|
||||
*
|
||||
* @param array $groupIds
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeIds(array $groupIds): GroupCollectorInterface
|
||||
{
|
||||
@@ -384,10 +346,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/**
|
||||
* Limit the result to NOT a set of specific journals.
|
||||
*
|
||||
* @param array $journalIds
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeJournalIds(array $journalIds): GroupCollectorInterface
|
||||
{
|
||||
@@ -395,7 +353,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
// make all integers.
|
||||
$integerIDs = array_map('intval', $journalIds);
|
||||
|
||||
|
||||
$this->query->whereNotIn('transaction_journals.id', $integerIDs);
|
||||
}
|
||||
|
||||
@@ -404,10 +361,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/**
|
||||
* Search for words in descriptions.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeSearchWords(array $array): GroupCollectorInterface
|
||||
{
|
||||
@@ -439,9 +392,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function excludeTypes(array $types): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereNotIn('transaction_types.type', $types);
|
||||
@@ -449,9 +399,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function exists(): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereNull('transaction_groups.deleted_at');
|
||||
@@ -459,12 +406,10 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transaction_types.type',
|
||||
[TransactionType::LIABILITY_CREDIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION]
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findNothing(): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('transaction_groups.id', -1);
|
||||
@@ -472,9 +417,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getExpandGroupSearch(): bool
|
||||
{
|
||||
return $this->expandGroupSearch;
|
||||
@@ -482,13 +424,12 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/**
|
||||
* Return the transaction journals without group information. Is useful in some instances.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtractedJournals(): array
|
||||
{
|
||||
$selection = $this->getGroups();
|
||||
$return = [];
|
||||
|
||||
/** @var array $group */
|
||||
foreach ($selection as $group) {
|
||||
$count = count($group['transactions']);
|
||||
@@ -504,8 +445,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/**
|
||||
* Return the groups.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getGroups(): Collection
|
||||
{
|
||||
@@ -537,22 +476,217 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* Same as getGroups but everything is in a paginator.
|
||||
*/
|
||||
public function getPaginatedGroups(): LengthAwarePaginator
|
||||
{
|
||||
$set = $this->getGroups();
|
||||
if (0 === $this->limit) {
|
||||
$this->setLimit(50);
|
||||
}
|
||||
|
||||
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the number of returned entries.
|
||||
*/
|
||||
public function setLimit(int $limit): GroupCollectorInterface
|
||||
{
|
||||
$this->limit = $limit;
|
||||
// app('log')->debug(sprintf('GroupCollector: The limit is now %d', $limit));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isNotReconciled(): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('source.reconciled', 0)->where('destination.reconciled', 0);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isReconciled(): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('source.reconciled', 1)->where('destination.reconciled', 1);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit results to a specific currency, either foreign or normal one.
|
||||
*/
|
||||
public function setCurrency(TransactionCurrency $currency): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
static function (EloquentBuilder $q) use ($currency) { // @phpstan-ignore-line
|
||||
$q->where('source.transaction_currency_id', $currency->id);
|
||||
$q->orWhere('source.foreign_currency_id', $currency->id);
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setExpandGroupSearch(bool $expandGroupSearch): GroupCollectorInterface
|
||||
{
|
||||
$this->expandGroupSearch = $expandGroupSearch;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setForeignCurrency(TransactionCurrency $currency): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('source.foreign_currency_id', $currency->id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the result to a set of specific transaction groups.
|
||||
*/
|
||||
public function setIds(array $groupIds): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereIn('transaction_groups.id', $groupIds);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the result to a set of specific journals.
|
||||
*/
|
||||
public function setJournalIds(array $journalIds): GroupCollectorInterface
|
||||
{
|
||||
if (0 !== count($journalIds)) {
|
||||
// make all integers.
|
||||
$integerIDs = array_map('intval', $journalIds);
|
||||
|
||||
$this->query->whereIn('transaction_journals.id', $integerIDs);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the page to get.
|
||||
*/
|
||||
public function setPage(int $page): GroupCollectorInterface
|
||||
{
|
||||
$page = 0 === $page ? 1 : $page;
|
||||
$this->page = $page;
|
||||
// app('log')->debug(sprintf('GroupCollector: page is now %d', $page));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for words in descriptions.
|
||||
*/
|
||||
public function setSearchWords(array $array): GroupCollectorInterface
|
||||
{
|
||||
if (0 === count($array)) {
|
||||
return $this;
|
||||
}
|
||||
$this->query->where(
|
||||
static function (EloquentBuilder $q) use ($array) { // @phpstan-ignore-line
|
||||
$q->where(
|
||||
static function (EloquentBuilder $q1) use ($array) {
|
||||
foreach ($array as $word) {
|
||||
$keyword = sprintf('%%%s%%', $word);
|
||||
$q1->where('transaction_journals.description', 'LIKE', $keyword);
|
||||
}
|
||||
}
|
||||
);
|
||||
$q->orWhere(
|
||||
static function (EloquentBuilder $q2) use ($array) {
|
||||
foreach ($array as $word) {
|
||||
$keyword = sprintf('%%%s%%', $word);
|
||||
$q2->where('transaction_groups.title', 'LIKE', $keyword);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the search to one specific transaction group.
|
||||
*/
|
||||
public function setTransactionGroup(TransactionGroup $transactionGroup): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('transaction_groups.id', $transactionGroup->id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the included transaction types.
|
||||
*/
|
||||
public function setTypes(array $types): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereIn('transaction_types.type', $types);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user object and start the query.
|
||||
*/
|
||||
public function setUser(User $user): GroupCollectorInterface
|
||||
{
|
||||
if (null === $this->user) {
|
||||
$this->user = $user;
|
||||
$this->startQuery();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user object and start the query.
|
||||
*/
|
||||
public function setUserGroup(UserGroup $userGroup): GroupCollectorInterface
|
||||
{
|
||||
if (null === $this->userGroup) {
|
||||
$this->userGroup = $userGroup;
|
||||
$this->startQueryForGroup();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically include all stuff required to make API calls work.
|
||||
*/
|
||||
public function withAPIInformation(): GroupCollectorInterface
|
||||
{
|
||||
// include source + destination account name and type.
|
||||
$this->withAccountInformation()
|
||||
// include category ID + name (if any)
|
||||
->withCategoryInformation()
|
||||
// include budget ID + name (if any)
|
||||
->withBudgetInformation()
|
||||
// include bill ID + name (if any)
|
||||
->withBillInformation()
|
||||
;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function getCollectedGroupIds(): array
|
||||
{
|
||||
return $this->query->get(['transaction_journals.transaction_group_id'])->pluck('transaction_group_id')->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return Collection
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function parseArray(Collection $collection): Collection
|
||||
{
|
||||
$groups = [];
|
||||
|
||||
/** @var TransactionJournal $augumentedJournal */
|
||||
foreach ($collection as $augumentedJournal) {
|
||||
$groupId = (int)$augumentedJournal->transaction_group_id;
|
||||
@@ -575,6 +709,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$journalId = (int)$augumentedJournal->transaction_journal_id; // @phpstan-ignore-line
|
||||
$groupArray['transactions'][$journalId] = $parsedGroup;
|
||||
$groups[$groupId] = $groupArray;
|
||||
|
||||
continue;
|
||||
}
|
||||
// or parse the rest.
|
||||
@@ -588,7 +723,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
if (!array_key_exists($journalId, $groups[$groupId]['transactions'])) {
|
||||
// create second, third, fourth split:
|
||||
$groups[$groupId]['count']++;
|
||||
++$groups[$groupId]['count'];
|
||||
$groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedJournal($augumentedJournal);
|
||||
}
|
||||
}
|
||||
@@ -599,9 +734,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $augumentedJournal
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function parseAugmentedJournal(TransactionJournal $augumentedJournal): array
|
||||
@@ -615,6 +747,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$result['book_date'] = null;
|
||||
$result['due_date'] = null;
|
||||
$result['process_date'] = null;
|
||||
|
||||
try {
|
||||
$result['date'] = new Carbon($result['date'], 'UTC');
|
||||
$result['created_at'] = new Carbon($result['created_at'], 'UTC');
|
||||
@@ -624,8 +757,9 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$result['date']->setTimezone(config('app.timezone'));
|
||||
$result['created_at']->setTimezone(config('app.timezone'));
|
||||
$result['updated_at']->setTimezone(config('app.timezone'));
|
||||
} catch (Exception $e) { // intentional generic exception
|
||||
} catch (\Exception $e) { // intentional generic exception
|
||||
app('log')->error($e->getMessage());
|
||||
|
||||
throw new FireflyException($e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
@@ -648,6 +782,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
if (array_key_exists('tag_id', $result) && null !== $result['tag_id']) { // assume the other fields are present as well.
|
||||
$tagId = (int)$augumentedJournal['tag_id'];
|
||||
$tagDate = null;
|
||||
|
||||
try {
|
||||
$tagDate = Carbon::parse($augumentedJournal['tag_date']);
|
||||
} catch (InvalidFormatException $e) {
|
||||
@@ -680,7 +815,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$result['tag_name'], $result['tag_date'], $result['tag_description'],
|
||||
$result['tag_latitude'], $result['tag_longitude'], $result['tag_zoom_level'],
|
||||
$result['attachment_filename'], $result['attachment_id']
|
||||
|
||||
);
|
||||
|
||||
return $result;
|
||||
@@ -688,10 +822,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/**
|
||||
* Convert a selected set of fields to arrays.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function convertToInteger(array $array): array
|
||||
{
|
||||
@@ -702,11 +832,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function convertToStrings(array $array): array
|
||||
{
|
||||
foreach ($this->stringFields as $field) {
|
||||
@@ -716,12 +841,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $existingJournal
|
||||
* @param TransactionJournal $newJournal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function mergeTags(array $existingJournal, TransactionJournal $newJournal): array
|
||||
{
|
||||
$newArray = $newJournal->toArray();
|
||||
@@ -729,6 +848,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$tagId = (int)$newJournal['tag_id'];
|
||||
|
||||
$tagDate = null;
|
||||
|
||||
try {
|
||||
$tagDate = Carbon::parse($newArray['tag_date']);
|
||||
} catch (InvalidFormatException $e) {
|
||||
@@ -746,12 +866,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $existingJournal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $existingJournal
|
||||
* @param TransactionJournal $newJournal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function mergeAttachments(array $existingJournal, TransactionJournal $newJournal): array
|
||||
{
|
||||
$newArray = $newJournal->toArray();
|
||||
@@ -766,11 +880,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $existingJournal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $groups
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function parseSums(array $groups): array
|
||||
{
|
||||
/**
|
||||
@@ -814,24 +923,19 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function postFilterCollection(Collection $collection): Collection
|
||||
{
|
||||
$currentCollection = $collection;
|
||||
|
||||
app('log')->debug(sprintf('GroupCollector: postFilterCollection has %d filter(s) and %d transaction(s).', count($this->postFilters), count($currentCollection)));
|
||||
|
||||
|
||||
/**
|
||||
* @var Closure $function
|
||||
* @var \Closure $function
|
||||
*/
|
||||
foreach ($this->postFilters as $function) {
|
||||
app('log')->debug('Applying filter...');
|
||||
$nextCollection = new Collection();
|
||||
|
||||
// loop everything in the current collection
|
||||
// and save it (or not) in the new collection.
|
||||
// that new collection is the next current collection
|
||||
@@ -849,235 +953,19 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$currentCollection = $nextCollection;
|
||||
app('log')->debug(sprintf('GroupCollector: postFilterCollection has %d transaction(s) left.', count($currentCollection)));
|
||||
}
|
||||
|
||||
return $currentCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as getGroups but everything is in a paginator.
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getPaginatedGroups(): LengthAwarePaginator
|
||||
{
|
||||
$set = $this->getGroups();
|
||||
if (0 === $this->limit) {
|
||||
$this->setLimit(50);
|
||||
}
|
||||
|
||||
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the number of returned entries.
|
||||
*
|
||||
* @param int $limit
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setLimit(int $limit): GroupCollectorInterface
|
||||
{
|
||||
$this->limit = $limit;
|
||||
//app('log')->debug(sprintf('GroupCollector: The limit is now %d', $limit));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isNotReconciled(): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('source.reconciled', 0)->where('destination.reconciled', 0);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isReconciled(): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('source.reconciled', 1)->where('destination.reconciled', 1);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit results to a specific currency, either foreign or normal one.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setCurrency(TransactionCurrency $currency): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where(
|
||||
static function (EloquentBuilder $q) use ($currency) { // @phpstan-ignore-line
|
||||
$q->where('source.transaction_currency_id', $currency->id);
|
||||
$q->orWhere('source.foreign_currency_id', $currency->id);
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $expandGroupSearch
|
||||
*/
|
||||
public function setExpandGroupSearch(bool $expandGroupSearch): GroupCollectorInterface
|
||||
{
|
||||
$this->expandGroupSearch = $expandGroupSearch;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setForeignCurrency(TransactionCurrency $currency): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('source.foreign_currency_id', $currency->id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the result to a set of specific transaction groups.
|
||||
*
|
||||
* @param array $groupIds
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setIds(array $groupIds): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereIn('transaction_groups.id', $groupIds);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the result to a set of specific journals.
|
||||
*
|
||||
* @param array $journalIds
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setJournalIds(array $journalIds): GroupCollectorInterface
|
||||
{
|
||||
if (0 !== count($journalIds)) {
|
||||
// make all integers.
|
||||
$integerIDs = array_map('intval', $journalIds);
|
||||
|
||||
|
||||
$this->query->whereIn('transaction_journals.id', $integerIDs);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the page to get.
|
||||
*
|
||||
* @param int $page
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setPage(int $page): GroupCollectorInterface
|
||||
{
|
||||
$page = 0 === $page ? 1 : $page;
|
||||
$this->page = $page;
|
||||
//app('log')->debug(sprintf('GroupCollector: page is now %d', $page));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for words in descriptions.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setSearchWords(array $array): GroupCollectorInterface
|
||||
{
|
||||
if (0 === count($array)) {
|
||||
return $this;
|
||||
}
|
||||
$this->query->where(
|
||||
static function (EloquentBuilder $q) use ($array) { // @phpstan-ignore-line
|
||||
$q->where(
|
||||
static function (EloquentBuilder $q1) use ($array) {
|
||||
foreach ($array as $word) {
|
||||
$keyword = sprintf('%%%s%%', $word);
|
||||
$q1->where('transaction_journals.description', 'LIKE', $keyword);
|
||||
}
|
||||
}
|
||||
);
|
||||
$q->orWhere(
|
||||
static function (EloquentBuilder $q2) use ($array) {
|
||||
foreach ($array as $word) {
|
||||
$keyword = sprintf('%%%s%%', $word);
|
||||
$q2->where('transaction_groups.title', 'LIKE', $keyword);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the search to one specific transaction group.
|
||||
*
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setTransactionGroup(TransactionGroup $transactionGroup): GroupCollectorInterface
|
||||
{
|
||||
$this->query->where('transaction_groups.id', $transactionGroup->id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the included transaction types.
|
||||
*
|
||||
* @param array $types
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setTypes(array $types): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereIn('transaction_types.type', $types);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user object and start the query.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setUser(User $user): GroupCollectorInterface
|
||||
{
|
||||
if (null === $this->user) {
|
||||
$this->user = $user;
|
||||
$this->startQuery();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the query.
|
||||
*/
|
||||
private function startQuery(): void
|
||||
{
|
||||
//app('log')->debug('GroupCollector::startQuery');
|
||||
// app('log')->debug('GroupCollector::startQuery');
|
||||
$this->query = $this->user
|
||||
//->transactionGroups()
|
||||
//->leftJoin('transaction_journals', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
||||
// ->transactionGroups()
|
||||
// ->leftJoin('transaction_journals', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
||||
->transactionJournals()
|
||||
->leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
||||
|
||||
@@ -1086,7 +974,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as source',
|
||||
static function (JoinClause $join) {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('source.amount', '<', 0);
|
||||
->where('source.amount', '<', 0)
|
||||
;
|
||||
}
|
||||
)
|
||||
// join destination transaction
|
||||
@@ -1094,7 +983,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as destination',
|
||||
static function (JoinClause $join) {
|
||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('destination.amount', '>', 0);
|
||||
->where('destination.amount', '>', 0)
|
||||
;
|
||||
}
|
||||
)
|
||||
// left join transaction type.
|
||||
@@ -1109,24 +999,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->orderBy('transaction_journals.description', 'DESC')
|
||||
->orderBy('source.amount', 'DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user object and start the query.
|
||||
*
|
||||
* @param UserGroup $userGroup
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function setUserGroup(UserGroup $userGroup): GroupCollectorInterface
|
||||
{
|
||||
if (null === $this->userGroup) {
|
||||
$this->userGroup = $userGroup;
|
||||
$this->startQueryForGroup();
|
||||
}
|
||||
|
||||
return $this;
|
||||
->orderBy('source.amount', 'DESC')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1134,7 +1008,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
private function startQueryForGroup(): void
|
||||
{
|
||||
//app('log')->debug('GroupCollector::startQuery');
|
||||
// app('log')->debug('GroupCollector::startQuery');
|
||||
$this->query = $this->userGroup
|
||||
->transactionJournals()
|
||||
->leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
||||
@@ -1144,7 +1018,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as source',
|
||||
static function (JoinClause $join) {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('source.amount', '<', 0);
|
||||
->where('source.amount', '<', 0)
|
||||
;
|
||||
}
|
||||
)
|
||||
// join destination transaction
|
||||
@@ -1152,7 +1027,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as destination',
|
||||
static function (JoinClause $join) {
|
||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('destination.amount', '>', 0);
|
||||
->where('destination.amount', '>', 0)
|
||||
;
|
||||
}
|
||||
)
|
||||
// left join transaction type.
|
||||
@@ -1169,23 +1045,4 @@ class GroupCollector implements GroupCollectorInterface
|
||||
->orderBy('transaction_journals.description', 'DESC')
|
||||
->orderBy('source.amount', 'DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically include all stuff required to make API calls work.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withAPIInformation(): GroupCollectorInterface
|
||||
{
|
||||
// include source + destination account name and type.
|
||||
$this->withAccountInformation()
|
||||
// include category ID + name (if any)
|
||||
->withCategoryInformation()
|
||||
// include budget ID + name (if any)
|
||||
->withBudgetInformation()
|
||||
// include bill ID + name (if any)
|
||||
->withBillInformation();
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user