Modify search for #963

This commit is contained in:
James Cole
2017-10-30 17:28:43 +01:00
parent 0bb46dd184
commit 5722622251
5 changed files with 188 additions and 40 deletions

View File

@@ -133,7 +133,7 @@ class JournalCollector implements JournalCollectorInterface
public function addFilter(string $filter): JournalCollectorInterface
{
$interfaces = class_implements($filter);
if (in_array(FilterInterface::class, $interfaces) && !in_array($filter, $this->filters) ) {
if (in_array(FilterInterface::class, $interfaces) && !in_array($filter, $this->filters)) {
Log::debug(sprintf('Enabled filter %s', $filter));
$this->filters[] = $filter;
}
@@ -141,6 +141,78 @@ class JournalCollector implements JournalCollectorInterface
return $this;
}
/**
* @param string $amount
*
* @return JournalCollectorInterface
*/
public function amountIs(string $amount): JournalCollectorInterface
{
$this->query->where(
function (EloquentBuilder $q) use ($amount) {
$q->where('transactions.amount', $amount);
$q->orWhere('transactions.amount', bcmul($amount, '-1'));
}
);
return $this;
}
/**
* @param string $amount
*
* @return JournalCollectorInterface
*/
public function amountLess(string $amount): JournalCollectorInterface
{
$this->query->where(
function (EloquentBuilder $q1) use ($amount) {
$q1->where(
function (EloquentBuilder $q2) use ($amount) {
// amount < 0 and .amount > -$amount
$amount = bcmul($amount,'-1');
$q2->where('transactions.amount', '<', 0)->where('transactions.amount', '>', $amount);
}
)
->orWhere(
function (EloquentBuilder $q3) use ($amount) {
// amount > 0 and .amount < $amount
$q3->where('transactions.amount', '>', 0)->where('transactions.amount', '<', $amount);
}
);
}
);
return $this;
}
/**
* @param string $amount
*
* @return JournalCollectorInterface
*/
public function amountMore(string $amount): JournalCollectorInterface
{
$this->query->where(
function (EloquentBuilder $q1) use ($amount) {
$q1->where(
function (EloquentBuilder $q2) use ($amount) {
// amount < 0 and .amount < -$amount
$amount = bcmul($amount,'-1');
$q2->where('transactions.amount', '<', 0)->where('transactions.amount', '<', $amount);
}
)
->orWhere(
function (EloquentBuilder $q3) use ($amount) {
// amount > 0 and .amount > $amount
$q3->where('transactions.amount', '>', 0)->where('transactions.amount', '>', $amount);
}
);
}
);
return $this;
}
/**
* @return int
* @throws FireflyException
@@ -251,6 +323,20 @@ class JournalCollector implements JournalCollectorInterface
return $this;
}
/**
* @param Carbon $after
*
* @return JournalCollectorInterface
*/
public function setAfter(Carbon $after): JournalCollectorInterface
{
$afterStr = $after->format('Y-m-d');
$this->query->where('transaction_journals.date', '>=', $afterStr);
Log::debug(sprintf('JournalCollector range is now after %s (inclusive)', $afterStr));
return $this;
}
/**
* @return JournalCollectorInterface
*/
@@ -273,6 +359,20 @@ class JournalCollector implements JournalCollectorInterface
return $this;
}
/**
* @param Carbon $before
*
* @return JournalCollectorInterface
*/
public function setBefore(Carbon $before): JournalCollectorInterface
{
$beforeStr = $before->format('Y-m-d');
$this->query->where('transaction_journals.date', '<=', $beforeStr);
Log::debug(sprintf('JournalCollector range is now before %s (inclusive)', $beforeStr));
return $this;
}
/**
* @param Collection $bills
*
@@ -523,7 +623,7 @@ class JournalCollector implements JournalCollectorInterface
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->orderBy('transaction_journals.description', 'DESC')
->orderBy('transactions.amount','DESC');
->orderBy('transactions.amount', 'DESC');
$this->query = $query;

View File

@@ -45,6 +45,27 @@ interface JournalCollectorInterface
*/
public function addFilter(string $filter): JournalCollectorInterface;
/**
* @param string $amount
*
* @return JournalCollectorInterface
*/
public function amountMore(string $amount): JournalCollectorInterface;
/**
* @param string $amount
*
* @return JournalCollectorInterface
*/
public function amountLess(string $amount): JournalCollectorInterface;
/**
* @param string $amount
*
* @return JournalCollectorInterface
*/
public function amountIs(string $amount): JournalCollectorInterface;
/**
* @return int
*/
@@ -74,11 +95,25 @@ interface JournalCollectorInterface
*/
public function setAccounts(Collection $accounts): JournalCollectorInterface;
/**
* @param Carbon $after
*
* @return JournalCollectorInterface
*/
public function setAfter(Carbon $after): JournalCollectorInterface;
/**
* @return JournalCollectorInterface
*/
public function setAllAssetAccounts(): JournalCollectorInterface;
/**
* @param Carbon $before
*
* @return JournalCollectorInterface
*/
public function setBefore(Carbon $before): JournalCollectorInterface;
/**
* @param Collection $bills
*