Some comment cleanup in the libraries.

This commit is contained in:
James Cole
2014-09-09 20:01:13 +02:00
parent f6586be5e7
commit fdf03cd8e2
7 changed files with 100 additions and 36 deletions

View File

@@ -73,7 +73,7 @@ abstract class SingleTableInheritanceEntity extends Ardent
// newEloquentBuilder() was added in 4.1 // newEloquentBuilder() was added in 4.1
$builder = $this->newEloquentBuilder($this->newBaseQueryBuilder()); $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder());
// Once we have the query builders, we will set the model instances so the // Once Firefly has the query builders, it will set the model instances so the
// builder can easily access any information it may need from the model // builder can easily access any information it may need from the model
// while it is constructing and executing various queries against it. // while it is constructing and executing various queries against it.
$builder->setModel($this)->with($this->with); $builder->setModel($this)->with($this->with);

View File

@@ -28,13 +28,16 @@ class Account implements AccountInterface
* Since it is entirely possible the database is messed up somehow it might be that a transaction * Since it is entirely possible the database is messed up somehow it might be that a transaction
* journal has only one transaction. This is mainly caused by wrong deletions and other artefacts from the past. * journal has only one transaction. This is mainly caused by wrong deletions and other artefacts from the past.
* *
* If it is the case, we remove $item and continue like nothing ever happened. This will however, * If it is the case, Firefly removes $item and continues like nothing ever happened. This will however,
* mess up some statisics but we can live with that. We might be needing some cleanup routine in the future. * mess up some statisics but it's decided everybody should learn to live with that.
* *
* For now, we simply warn the user of this. * Firefly might be needing some cleanup routine in the future.
*
* For now, Firefly simply warns the user of this.
* *
* @param \Account $account * @param \Account $account
* @param $perPage * @param $perPage
*
* @return array|mixed * @return array|mixed
* @throws \Firefly\Exception\FireflyException * @throws \Firefly\Exception\FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)

View File

@@ -550,9 +550,10 @@ class Chart implements ChartInterface
} }
/** /**
* We check how much money has been spend on the limitrepetition (aka: the current envelope) in the period denoted. * Firefly checks how much money has been spend on the limitrepetition (aka: the current envelope) in
* Aka, we have a certain amount of money in an envelope and we wish to know how much we've spent between the dates * the period denoted. Aka, the user has a certain amount of money in an envelope and wishes to know how
* entered. This can be a partial match with the date range of the envelope or no match at all. * much he has spent between the dates entered. This date range can be a partial match with the date range
* of the envelope or no match at all.
* *
* @param \LimitRepetition $repetition * @param \LimitRepetition $repetition
* @param Carbon $start * @param Carbon $start

View File

@@ -98,9 +98,10 @@ interface ChartInterface
/** /**
* We check how much money has been spend on the limitrepetition (aka: the current envelope) in the period denoted. * Firefly checks how much money has been spend on the limitrepetition (aka: the current envelope) in
* Aka, we have a certain amount of money in an envelope and we wish to know how much we've spent between the dates * the period denoted. Aka, the user has a certain amount of money in an envelope and wishes to know how
* entered. This can be a partial match with the date range of the envelope or no match at all. * much he has spent between the dates entered. This date range can be a partial match with the date range
* of the envelope or no match at all.
* *
* @param \LimitRepetition $repetition * @param \LimitRepetition $repetition
* @param Carbon $start * @param Carbon $start

View File

@@ -133,7 +133,7 @@ class Import
return; return;
} }
// if we try to import a beneficiary, Firefly will "merge" already, // if Firefly tries to import a beneficiary, Firefly will "merge" already existing ones,
// so we don't care: // so we don't care:
if (isset($payload['data']['account_type']) && $payload['data']['account_type'] == 'Beneficiary account') { if (isset($payload['data']['account_type']) && $payload['data']['account_type'] == 'Beneficiary account') {
// store beneficiary // store beneficiary

View File

@@ -65,6 +65,16 @@ class EloquentReminderRepository implements ReminderRepositoryInterface
return $this->_user->reminders()->validOn($today)->get(); return $this->_user->reminders()->validOn($today)->get();
} }
/**
* @return mixed
*/
public function getPiggybankReminders()
{
$today = new Carbon;
return $this->_user->reminders()->where('class','PiggybankReminder')->validOn($today)->get();
}
/** /**
* *
*/ */

View File

@@ -14,7 +14,9 @@ use Illuminate\Events\Dispatcher;
class EloquentPiggybankTrigger class EloquentPiggybankTrigger
{ {
/** /**
* * This method checks every repeating piggy bank the user has (these are called repeated expenses) and makes
* sure each repeated expense has a "repetition" for the current time period. For example, if the user has
* a weekly repeated expense of E 40,- this method will fire every week and create a new repetition.
*/ */
public function checkRepeatingPiggies() public function checkRepeatingPiggies()
{ {
@@ -25,26 +27,29 @@ class EloquentPiggybankTrigger
$piggies = []; $piggies = [];
} }
\Log::debug('Now in checkRepeatingPiggies with ' . count($piggies) . ' piggies'); \Log::debug('Now in checkRepeatingPiggies with ' . count($piggies) . ' piggies found.');
/** @var \Piggybank $piggyBank */ /** @var \Piggybank $piggyBank */
foreach ($piggies as $piggyBank) { foreach ($piggies as $piggyBank) {
\Log::debug('Now working on ' . $piggyBank->name); \Log::debug('Now working on ' . $piggyBank->name);
// get the latest repetition, see if we need to "append" more: /*
* Get the latest repetition, see if Firefly needs to create more.
*/
/** @var \PiggybankRepetition $primer */ /** @var \PiggybankRepetition $primer */
$primer = $piggyBank->piggybankrepetitions()->orderBy('targetdate', 'DESC')->first(); $primer = $piggyBank->piggybankrepetitions()->orderBy('targetdate', 'DESC')->first();
\Log::debug('Last target date is: ' . $primer->targetdate); \Log::debug('Last target date is: ' . $primer->targetdate);
// for repeating piggy banks, the target date is mandatory:
$today = new Carbon; $today = new Carbon;
$end = clone $primer->targetdate;
// the next repetition must be created starting at the day after the target date: // the next repetition must be created starting at the day after the target date of the previous one.
/*
* A repeated expense runs from day 1 to day X. Since it repeats, the next repetition starts at day X+1
* until however often the repeated expense is set to repeat: a month, a week, a year.
*/
$start = clone $primer->targetdate; $start = clone $primer->targetdate;
$start->addDay(); $start->addDay();
while ($start <= $today) { while ($start <= $today) {
\Log::debug('Looping! Start is: ' . $start); \Log::debug('Looping! Start is: ' . $start);
@@ -104,15 +109,26 @@ class EloquentPiggybankTrigger
/** /**
* Whenever a repetition is made, the decision is there to make reminders for it. Or not. * Whenever a repetition is made, the decision is there to make reminders for it. Or not.
*
* Some combinations are "invalid" or impossible and will never trigger reminders. Others do. * Some combinations are "invalid" or impossible and will never trigger reminders. Others do.
* *
* @param \PiggybankRepetition $rep * The numbers below refer to a small list I made in a text-file (it no longer exists) which contained the eight
* binary combinations that can be made of three properties each piggy bank has (among others):
*
* - Whether or not it has a start date.
* - Whether or not it has an end date.
* - Whether or not the piggy bank repeats itself.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @param \PiggybankRepetition $repetition
* *
* @return null * @return null
*/ */
public function createdRepetition(\PiggybankRepetition $repetition) public function createdRepetition(\PiggybankRepetition $repetition)
{ {
\Log::debug('TRIGGER on createdRepetition() for repetition #' . $repetition->id);
$piggyBank = $repetition->piggybank; $piggyBank = $repetition->piggybank;
@@ -120,49 +136,70 @@ class EloquentPiggybankTrigger
// no reminders needed (duh) // no reminders needed (duh)
if (is_null(($piggyBank->reminder))) { if (is_null(($piggyBank->reminder))) {
\Log::debug('No reminders because no reminder needed.');
return null; return null;
} }
// no start, no target, no repeat (#1): // no start, no target, no repeat (#1):
if (is_null($piggyBank->startdate) && is_null($piggyBank->targetdate) && $piggyBank->repeats == 0) { if (is_null($piggyBank->startdate) && is_null($piggyBank->targetdate) && $piggyBank->repeats == 0) {
\Log::debug('No reminders because no start, no target, no repeat (#1)');
return null; return null;
} }
// no start, but repeats (#5): // no start, but repeats (#5):
if (is_null($piggyBank->startdate) && $piggyBank->repeats == 1) { if (is_null($piggyBank->startdate) && $piggyBank->repeats == 1) {
\Log::debug('No reminders because no start, but repeats (#5)');
return null; return null;
} }
// no start, no end, but repeats (#6) // no start, no end, but repeats (#6)
if (is_null($piggyBank->startdate) && is_null($piggyBank->targetdate) && $piggyBank->repeats == 1) { if (is_null($piggyBank->startdate) && is_null($piggyBank->targetdate) && $piggyBank->repeats == 1) {
\Log::debug('No reminders because no start, no end, but repeats (#6)');
return null; return null;
} }
// no end, but repeats (#7) // no end, but repeats (#7)
if (is_null($piggyBank->targetdate) && $piggyBank->repeats == 1) { if (is_null($piggyBank->targetdate) && $piggyBank->repeats == 1) {
\Log::debug('No reminders because no end, but repeats (#7)');
return null; return null;
} }
// #2, #3, #4 and #8 are valid combo's. \Log::debug('Will continue...');
/*
* #2, #3, #4 and #8 are valid combo's.
*
* We add two years to the end when the repetition has no target date; we "pretend" there is a target date.
*
*/
if (is_null($repetition->targetdate)) { if (is_null($repetition->targetdate)) {
$end = new Carbon; $end = new Carbon;
$end->addYears(2); $end->addYears(2);
} else { } else {
$end = $repetition->targetdate; $end = $repetition->targetdate;
} }
/*
* If there is no start date, the start dat becomes right now.
*/
if (is_null($repetition->startdate)) { if (is_null($repetition->startdate)) {
$start = new Carbon; $start = new Carbon;
} else { } else {
$start = $repetition->startdate; $start = $repetition->startdate;
} }
/*
* Firefly checks every period X between $start and $end and if necessary creates a reminder. Firefly
* only creates reminders if the $current date is after today. Piggy banks may have their start in the past.
*
* This loop will jump a month when the reminder is set monthly, a week when it's set weekly, etcetera.
*/
$current = $start; $current = $start;
$today = new Carbon; $today = new Carbon;
$today->startOfDay();
while ($current <= $end) { while ($current <= $end) {
\Log::debug('Looping reminder dates; now at ' . $current);
// when do we start reminding? /*
// X days before $current: * Piggy bank reminders start X days before the actual date of the event.
*/
$reminderStart = clone $current; $reminderStart = clone $current;
switch ($piggyBank->reminder) { switch ($piggyBank->reminder) {
case 'day': case 'day':
@@ -179,20 +216,32 @@ class EloquentPiggybankTrigger
break; break;
} }
/*
* If the date is past today we create a reminder, otherwise we don't. The end date is the date
* the reminder is due; after that it is invalid.
*/
if ($current >= $today) { if ($current >= $today) {
$reminder = new \PiggybankReminder; $reminder = new \PiggybankReminder;
$reminder->piggybank()->associate($piggyBank); $reminder->piggybank()->associate($piggyBank);
$reminder->user()->associate(\Auth::user()); $reminder->user()->associate(\Auth::user());
$reminder->startdate = $reminderStart; $reminder->startdate = $reminderStart;
$reminder->enddate = $current; $reminder->enddate = $current;
$reminder->active = 1;
\Log::debug('Will create a reminder. Is it valid?');
\Log::debug($reminder->validate());
try { try {
$reminder->save(); $reminder->save();
} catch (QueryException $e) { } catch (QueryException $e) {
\Log::error('Could not save reminder: ' . $e->getMessage());
} }
} else {
\Log::debug('Current is before today, will not make a reminder.');
} }
/*
* Here Firefly jumps ahead to the next reminder period.
*/
switch ($piggyBank->reminder) { switch ($piggyBank->reminder) {
case 'day': case 'day':
$current->addDays($piggyBank->reminder_skip); $current->addDays($piggyBank->reminder_skip);