mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Some more moved to traits.
This commit is contained in:
87
app/Helpers/Collector/Extensions/AmountCollection.php
Normal file
87
app/Helpers/Collector/Extensions/AmountCollection.php
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* AmountCollection.php
|
||||||
|
* Copyright (c) 2020 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FireflyIII\Helpers\Collector\Extensions;
|
||||||
|
|
||||||
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait AmountCollection
|
||||||
|
*/
|
||||||
|
trait AmountCollection
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get transactions with a specific amount.
|
||||||
|
*
|
||||||
|
* @param string $amount
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function amountIs(string $amount): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
$this->query->where(
|
||||||
|
static function (EloquentBuilder $q) use ($amount) {
|
||||||
|
$q->where('source.amount', app('steam')->negative($amount));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get transactions where the amount is less than.
|
||||||
|
*
|
||||||
|
* @param string $amount
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function amountLess(string $amount): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
$this->query->where(
|
||||||
|
function (EloquentBuilder $q) use ($amount) {
|
||||||
|
$q->where('destination.amount', '<', app('steam')->positive($amount));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get transactions where the amount is more than.
|
||||||
|
*
|
||||||
|
* @param string $amount
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function amountMore(string $amount): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
$this->query->where(
|
||||||
|
function (EloquentBuilder $q) use ($amount) {
|
||||||
|
$q->where('destination.amount', '>', app('steam')->positive($amount));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
120
app/Helpers/Collector/Extensions/TimeCollection.php
Normal file
120
app/Helpers/Collector/Extensions/TimeCollection.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* TimeCollection.php
|
||||||
|
* Copyright (c) 2020 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FireflyIII\Helpers\Collector\Extensions;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait TimeCollection
|
||||||
|
*/
|
||||||
|
trait TimeCollection
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect transactions after a specific date.
|
||||||
|
*
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function setAfter(Carbon $date): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
$afterStr = $date->format('Y-m-d 00:00:00');
|
||||||
|
$this->query->where('transaction_journals.date', '>=', $afterStr);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect transactions before a specific date.
|
||||||
|
*
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function setBefore(Carbon $date): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
$beforeStr = $date->format('Y-m-d 00:00:00');
|
||||||
|
$this->query->where('transaction_journals.date', '<=', $beforeStr);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect transactions created on a specific date.
|
||||||
|
*
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function setCreatedAt(Carbon $date): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
$after = $date->format('Y-m-d 00:00:00');
|
||||||
|
$before = $date->format('Y-m-d 23:59:59');
|
||||||
|
$this->query->where('transaction_journals.created_at', '>=', $after);
|
||||||
|
$this->query->where('transaction_journals.created_at', '<=', $before);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the start and end time of the results to return.
|
||||||
|
*
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function setRange(Carbon $start, Carbon $end): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
if ($end < $start) {
|
||||||
|
[$start, $end] = [$end, $start];
|
||||||
|
}
|
||||||
|
$startStr = $start->format('Y-m-d H:i:s');
|
||||||
|
$endStr = $end->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
$this->query->where('transaction_journals.date', '>=', $startStr);
|
||||||
|
$this->query->where('transaction_journals.date', '<=', $endStr);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect transactions updated on a specific date.
|
||||||
|
*
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function setUpdatedAt(Carbon $date): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
$after = $date->format('Y-m-d 00:00:00');
|
||||||
|
$before = $date->format('Y-m-d 23:59:59');
|
||||||
|
$this->query->where('transaction_journals.updated_at', '>=', $after);
|
||||||
|
$this->query->where('transaction_journals.updated_at', '<=', $before);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@@ -27,7 +27,9 @@ use Carbon\Carbon;
|
|||||||
use Carbon\Exceptions\InvalidDateException;
|
use Carbon\Exceptions\InvalidDateException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Helpers\Collector\Extensions\AccountCollection;
|
use FireflyIII\Helpers\Collector\Extensions\AccountCollection;
|
||||||
|
use FireflyIII\Helpers\Collector\Extensions\AmountCollection;
|
||||||
use FireflyIII\Helpers\Collector\Extensions\CollectorProperties;
|
use FireflyIII\Helpers\Collector\Extensions\CollectorProperties;
|
||||||
|
use FireflyIII\Helpers\Collector\Extensions\TimeCollection;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
@@ -50,7 +52,7 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class GroupCollector implements GroupCollectorInterface
|
class GroupCollector implements GroupCollectorInterface
|
||||||
{
|
{
|
||||||
use CollectorProperties, AccountCollection;
|
use CollectorProperties, AccountCollection, AmountCollection, TimeCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Group collector constructor.
|
* Group collector constructor.
|
||||||
@@ -128,60 +130,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get transactions with a specific amount.
|
|
||||||
*
|
|
||||||
* @param string $amount
|
|
||||||
*
|
|
||||||
* @return GroupCollectorInterface
|
|
||||||
*/
|
|
||||||
public function amountIs(string $amount): GroupCollectorInterface
|
|
||||||
{
|
|
||||||
$this->query->where(
|
|
||||||
function (EloquentBuilder $q) use ($amount) {
|
|
||||||
$q->where('source.amount', app('steam')->negative($amount));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get transactions where the amount is less than.
|
|
||||||
*
|
|
||||||
* @param string $amount
|
|
||||||
*
|
|
||||||
* @return GroupCollectorInterface
|
|
||||||
*/
|
|
||||||
public function amountLess(string $amount): GroupCollectorInterface
|
|
||||||
{
|
|
||||||
$this->query->where(
|
|
||||||
function (EloquentBuilder $q) use ($amount) {
|
|
||||||
$q->where('destination.amount', '<', app('steam')->positive($amount));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get transactions where the amount is more than.
|
|
||||||
*
|
|
||||||
* @param string $amount
|
|
||||||
*
|
|
||||||
* @return GroupCollectorInterface
|
|
||||||
*/
|
|
||||||
public function amountMore(string $amount): GroupCollectorInterface
|
|
||||||
{
|
|
||||||
$this->query->where(
|
|
||||||
function (EloquentBuilder $q) use ($amount) {
|
|
||||||
$q->where('destination.amount', '>', app('steam')->positive($amount));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -275,38 +223,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Collect transactions after a specific date.
|
|
||||||
*
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return GroupCollectorInterface
|
|
||||||
*/
|
|
||||||
public function setAfter(Carbon $date): GroupCollectorInterface
|
|
||||||
{
|
|
||||||
$afterStr = $date->format('Y-m-d 00:00:00');
|
|
||||||
$this->query->where('transaction_journals.date', '>=', $afterStr);
|
|
||||||
Log::debug(sprintf('GroupCollector range is now after %s (inclusive)', $afterStr));
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collect transactions before a specific date.
|
|
||||||
*
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return GroupCollectorInterface
|
|
||||||
*/
|
|
||||||
public function setBefore(Carbon $date): GroupCollectorInterface
|
|
||||||
{
|
|
||||||
$beforeStr = $date->format('Y-m-d 00:00:00');
|
|
||||||
$this->query->where('transaction_journals.date', '<=', $beforeStr);
|
|
||||||
Log::debug(sprintf('GroupCollector range is now before %s (inclusive)', $beforeStr));
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Limit the search to a specific bill.
|
* Limit the search to a specific bill.
|
||||||
*
|
*
|
||||||
@@ -401,24 +317,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Collect transactions created on a specific date.
|
|
||||||
*
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return GroupCollectorInterface
|
|
||||||
*/
|
|
||||||
public function setCreatedAt(Carbon $date): GroupCollectorInterface
|
|
||||||
{
|
|
||||||
$after = $date->format('Y-m-d 00:00:00');
|
|
||||||
$before = $date->format('Y-m-d 23:59:59');
|
|
||||||
$this->query->where('transaction_journals.created_at', '>=', $after);
|
|
||||||
$this->query->where('transaction_journals.created_at', '<=', $before);
|
|
||||||
Log::debug(sprintf('GroupCollector created_at is now after %s (inclusive)', $after));
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Limit results to a specific currency, either foreign or normal one.
|
* Limit results to a specific currency, either foreign or normal one.
|
||||||
*
|
*
|
||||||
@@ -429,7 +327,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
public function setCurrency(TransactionCurrency $currency): GroupCollectorInterface
|
public function setCurrency(TransactionCurrency $currency): GroupCollectorInterface
|
||||||
{
|
{
|
||||||
$this->query->where(
|
$this->query->where(
|
||||||
function (EloquentBuilder $q) use ($currency) {
|
static function (EloquentBuilder $q) use ($currency) {
|
||||||
$q->where('source.transaction_currency_id', $currency->id);
|
$q->where('source.transaction_currency_id', $currency->id);
|
||||||
$q->orWhere('source.foreign_currency_id', $currency->id);
|
$q->orWhere('source.foreign_currency_id', $currency->id);
|
||||||
}
|
}
|
||||||
@@ -499,29 +397,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the start and end time of the results to return.
|
|
||||||
*
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return GroupCollectorInterface
|
|
||||||
*/
|
|
||||||
public function setRange(Carbon $start, Carbon $end): GroupCollectorInterface
|
|
||||||
{
|
|
||||||
if ($end < $start) {
|
|
||||||
[$start, $end] = [$end, $start];
|
|
||||||
}
|
|
||||||
$startStr = $start->format('Y-m-d H:i:s');
|
|
||||||
$endStr = $end->format('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
$this->query->where('transaction_journals.date', '>=', $startStr);
|
|
||||||
$this->query->where('transaction_journals.date', '<=', $endStr);
|
|
||||||
app('log')->debug(sprintf('GroupCollector range is now %s - %s (inclusive)', $startStr, $endStr));
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for words in descriptions.
|
* Search for words in descriptions.
|
||||||
*
|
*
|
||||||
@@ -613,24 +488,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Collect transactions updated on a specific date.
|
|
||||||
*
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return GroupCollectorInterface
|
|
||||||
*/
|
|
||||||
public function setUpdatedAt(Carbon $date): GroupCollectorInterface
|
|
||||||
{
|
|
||||||
$after = $date->format('Y-m-d 00:00:00');
|
|
||||||
$before = $date->format('Y-m-d 23:59:59');
|
|
||||||
$this->query->where('transaction_journals.updated_at', '>=', $after);
|
|
||||||
$this->query->where('transaction_journals.updated_at', '<=', $before);
|
|
||||||
Log::debug(sprintf('GroupCollector created_at is now after %s (inclusive)', $after));
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the user object and start the query.
|
* Set the user object and start the query.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user