mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Lots of cleaning up.
This commit is contained in:
@@ -239,7 +239,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
$q->orWhere(
|
||||
function (QueryBuilder $q) use ($model) {
|
||||
$q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
|
||||
// TODO magic number!
|
||||
$q->where('accounts.account_type_id', 3);
|
||||
$q->where('accounts.active', 0);
|
||||
}
|
||||
@@ -280,7 +279,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
$q->orWhere(
|
||||
function (EloquentBuilder $q) use ($model) {
|
||||
$q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
|
||||
// TODO magic number!
|
||||
$q->where('accounts.account_type_id', 3);
|
||||
$q->where('accounts.active', 0);
|
||||
}
|
||||
@@ -324,7 +322,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
$this->storeInitialBalance($account, $data);
|
||||
}
|
||||
|
||||
// TODO this needs cleaning up and thinking over.
|
||||
switch ($account->accountType->type) {
|
||||
case 'Asset account':
|
||||
case 'Default account':
|
||||
@@ -352,7 +349,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
$model->name = $data['name'];
|
||||
$model->active = isset($data['active']) ? intval($data['active']) : 0;
|
||||
|
||||
// TODO this needs cleaning up and thinking over.
|
||||
switch ($model->accountType->type) {
|
||||
case 'Asset account':
|
||||
case 'Default account':
|
||||
@@ -365,7 +361,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
if (isset($data['openingbalance']) && isset($data['openingbalancedate']) && strlen($data['openingbalancedate']) > 0) {
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$openingBalance = $this->openingBalanceTransaction($model);
|
||||
// TODO this needs cleaning up and thinking over.
|
||||
if (is_null($openingBalance)) {
|
||||
$this->storeInitialBalance($model, $data);
|
||||
} else {
|
||||
@@ -483,7 +478,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
*/
|
||||
public function findByWhat($what)
|
||||
{
|
||||
// TODO: Implement findByWhat() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
@@ -495,7 +489,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
// TODO: Implement get() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
|
||||
@@ -202,6 +202,73 @@ class Bill implements CUDInterface, CommonDatabaseCallsInterface, BillInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Bill $bill
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function lastFoundMatch(\Bill $bill)
|
||||
{
|
||||
$last = $bill->transactionjournals()->orderBy('date', 'DESC')->first();
|
||||
if ($last) {
|
||||
return $last->date;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Bill $bill
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function nextExpectedMatch(\Bill $bill)
|
||||
{
|
||||
/*
|
||||
* The date Firefly tries to find. If this stays null, it's "unknown".
|
||||
*/
|
||||
$finalDate = null;
|
||||
if ($bill->active == 0) {
|
||||
return $finalDate;
|
||||
}
|
||||
|
||||
/*
|
||||
* $today is the start of the next period, to make sure FF3 won't miss anything
|
||||
* when the current period has a transaction journal.
|
||||
*/
|
||||
$today = \DateKit::addPeriod(new Carbon, $bill->repeat_freq, 0);
|
||||
|
||||
/*
|
||||
* FF3 loops from the $start of the bill, and to make sure
|
||||
* $skip works, it adds one (for modulo).
|
||||
*/
|
||||
$skip = $bill->skip + 1;
|
||||
$start = \DateKit::startOfPeriod(new Carbon, $bill->repeat_freq);
|
||||
/*
|
||||
* go back exactly one month/week/etc because FF3 does not care about 'next'
|
||||
* bills if they're too far into the past.
|
||||
*/
|
||||
|
||||
$counter = 0;
|
||||
while ($start <= $today) {
|
||||
if (($counter % $skip) == 0) {
|
||||
// do something.
|
||||
$end = \DateKit::endOfPeriod(clone $start, $bill->repeat_freq);
|
||||
$journalCount = $bill->transactionjournals()->before($end)->after($start)->count();
|
||||
if ($journalCount == 0) {
|
||||
$finalDate = clone $start;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// add period for next round!
|
||||
$start = \DateKit::addPeriod($start, $bill->repeat_freq, 0);
|
||||
$counter++;
|
||||
}
|
||||
|
||||
return $finalDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Bill $bill
|
||||
* @param \TransactionJournal $journal
|
||||
|
||||
@@ -23,6 +23,20 @@ interface BillInterface
|
||||
*/
|
||||
public function getJournalForBillInRange(\Bill $bill, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param \Bill $bill
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function lastFoundMatch(\Bill $bill);
|
||||
|
||||
/**
|
||||
* @param \Bill $bill
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function nextExpectedMatch(\Bill $bill);
|
||||
|
||||
/**
|
||||
* @param \Bill $bill
|
||||
* @param \TransactionJournal $journal
|
||||
|
||||
@@ -16,7 +16,6 @@ class Steam
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO find a way to reliably remove cache entries for accounts.
|
||||
*
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
|
||||
Reference in New Issue
Block a user