Lots of cleaning up.

This commit is contained in:
James Cole
2015-01-02 12:38:13 +01:00
parent 3be1cdb249
commit 5707dc7579
20 changed files with 201 additions and 121 deletions

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -16,7 +16,6 @@ class Steam
{
/**
* TODO find a way to reliably remove cache entries for accounts.
*
* @param \Account $account
* @param Carbon $date