mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Expand search with negated search options
This commit is contained in:
@@ -62,6 +62,16 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function dayIsNot(string $day): GroupCollectorInterface
|
||||
{
|
||||
$this->query->whereDay('transaction_journals.date', '!=', $day);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
@@ -142,6 +152,28 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $day
|
||||
* @param string $field
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaDayIsNot(string $day, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
$filter = function (int $index, array $object) use ($field, $day): bool {
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon
|
||||
) {
|
||||
return (int) $day !== $transaction[$field]->day;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
@@ -210,6 +242,28 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @param string $field
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaMonthIsNot(string $month, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
$filter = function (int $index, array $object) use ($field, $month): bool {
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon
|
||||
) {
|
||||
return (int) $month !== $transaction[$field]->month;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
@@ -279,6 +333,28 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $field
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function metaYearIsNot(string $year, string $field): GroupCollectorInterface
|
||||
{
|
||||
$this->withMetaDate($field);
|
||||
$filter = function (int $index, array $object) use ($field, $year): bool {
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon
|
||||
) {
|
||||
return $year !== (string) $transaction[$field]->year;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $month
|
||||
* @return GroupCollectorInterface
|
||||
@@ -311,6 +387,16 @@ trait TimeCollection
|
||||
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
|
||||
@@ -344,6 +430,17 @@ trait TimeCollection
|
||||
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
|
||||
@@ -377,6 +474,17 @@ trait TimeCollection
|
||||
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
|
||||
@@ -410,6 +518,17 @@ trait TimeCollection
|
||||
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.
|
||||
*
|
||||
@@ -535,6 +654,37 @@ trait TimeCollection
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param string $field
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeMetaDateRange(Carbon $start, Carbon $end, string $field): GroupCollectorInterface
|
||||
{
|
||||
if ($end < $start) {
|
||||
[$start, $end] = [$end, $start];
|
||||
}
|
||||
$end = clone $end; // this is so weird, but it works if $end and $start secretly point to the same object.
|
||||
$end->endOfDay();
|
||||
$start->startOfDay();
|
||||
$this->withMetaDate($field);
|
||||
|
||||
$filter = function (int $index, array $object) use ($field, $start, $end): bool {
|
||||
foreach ($object['transactions'] as $transaction) {
|
||||
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
|
||||
return $transaction[$field]->lt($start) || $transaction[$field]->gt($end);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
$this->postFilters[] = $filter;
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param string $field
|
||||
@@ -576,6 +726,23 @@ 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');
|
||||
$before = $end->format('Y-m-d 23:59:59');
|
||||
|
||||
$this->query->where(sprintf('transaction_journals.%s', $field), '<', $after);
|
||||
$this->query->orWhere(sprintf('transaction_journals.%s', $field), '>', $before);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the start and end time of the results to return.
|
||||
*
|
||||
@@ -599,6 +766,27 @@ trait TimeCollection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function excludeRange(Carbon $start, Carbon $end): GroupCollectorInterface
|
||||
{
|
||||
if ($end < $start) {
|
||||
[$start, $end] = [$end, $start];
|
||||
}
|
||||
$startStr = $start->format('Y-m-d 00:00:00');
|
||||
$endStr = $end->format('Y-m-d 23:59:59');
|
||||
|
||||
$this->query->where('transaction_journals.date', '<', $startStr);
|
||||
$this->query->orWhere('transaction_journals.date', '>', $endStr);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Collect transactions updated on a specific date.
|
||||
*
|
||||
@@ -616,22 +804,44 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user