mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-29 02:11:12 -06:00
Removed dead code.
This commit is contained in:
parent
4c2938c5cd
commit
cddc123539
@ -31,72 +31,6 @@ class BudgetLimit extends Eloquent
|
||||
return $this->belongsTo('Budget');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO see if this method is still used.
|
||||
* Create a new repetition for this limit, starting on
|
||||
* the given date.
|
||||
*
|
||||
* @param Carbon $start
|
||||
*/
|
||||
public function createRepetition(Carbon $start)
|
||||
{
|
||||
|
||||
$end = clone $start;
|
||||
// go to end:
|
||||
switch ($this->repeat_freq) {
|
||||
case 'daily':
|
||||
$end->addDay();
|
||||
break;
|
||||
case 'weekly':
|
||||
$end->addWeek();
|
||||
break;
|
||||
case 'monthly':
|
||||
$end->addMonth();
|
||||
break;
|
||||
case 'quarterly':
|
||||
$end->addMonths(3);
|
||||
break;
|
||||
case 'half-year':
|
||||
$end->addMonths(6);
|
||||
break;
|
||||
case 'yearly':
|
||||
$end->addYear();
|
||||
break;
|
||||
}
|
||||
$end->subDay();
|
||||
$count = $this->limitrepetitions()->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->count();
|
||||
|
||||
if ($count == 0) {
|
||||
|
||||
$repetition = new \LimitRepetition();
|
||||
$repetition->startdate = $start;
|
||||
$repetition->enddate = $end;
|
||||
$repetition->amount = $this->amount;
|
||||
$repetition->budgetLimit()->associate($this);
|
||||
|
||||
try {
|
||||
$repetition->save();
|
||||
\Log::debug('Created new repetition with id #' . $repetition->id);
|
||||
} catch (QueryException $e) {
|
||||
// do nothing
|
||||
|
||||
\Log::error('Trying to save new Limitrepetition failed!');
|
||||
\Log::error($e->getMessage());
|
||||
}
|
||||
if (isset($repetition->id)) {
|
||||
\Event::fire('limits.repetition', [$repetition]); // not used, I guess?
|
||||
}
|
||||
} else {
|
||||
if ($count == 1) {
|
||||
// update this one:
|
||||
$repetition = $this->limitrepetitions()->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->first();
|
||||
$repetition->amount = $this->amount;
|
||||
$repetition->save();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
@ -33,17 +33,6 @@ class LimitRepetition extends Eloquent
|
||||
return ['created_at', 'updated_at', 'startdate', 'enddate'];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO see if this scope is still used.
|
||||
*
|
||||
* How much money is left in this?
|
||||
*/
|
||||
public function leftInRepetition()
|
||||
{
|
||||
return floatval($this->amount - $this->spentInRepetition());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO remove this method in favour of something in the FireflyIII libraries.
|
||||
*
|
||||
@ -64,43 +53,4 @@ class LimitRepetition extends Eloquent
|
||||
|
||||
return floatval($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO remove this method in favour of something in the FireflyIII libraries.
|
||||
*
|
||||
* Returns a string used to sort this particular repetition
|
||||
* based on the date and period it falls into. Ie. the limit
|
||||
* repeats monthly and the start date is 12 dec 2012, this will
|
||||
* return 2012-12.
|
||||
*/
|
||||
public function periodOrder()
|
||||
{
|
||||
if (is_null($this->repeat_freq)) {
|
||||
$this->repeat_freq = $this->limit->repeat_freq;
|
||||
}
|
||||
switch ($this->repeat_freq) {
|
||||
default:
|
||||
throw new FireflyException('No date formats for frequency "' . $this->repeat_freq . '"!');
|
||||
break;
|
||||
case 'daily':
|
||||
return $this->startdate->format('Ymd') . '-5';
|
||||
break;
|
||||
case 'weekly':
|
||||
return $this->startdate->format('Ymd') . '-4';
|
||||
break;
|
||||
case 'monthly':
|
||||
return $this->startdate->format('Ymd') . '-3';
|
||||
break;
|
||||
case 'quarterly':
|
||||
return $this->startdate->format('Ymd') . '-2';
|
||||
break;
|
||||
case 'half-year':
|
||||
return $this->startdate->format('Ymd') . '-1';
|
||||
break;
|
||||
case 'yearly':
|
||||
return $this->startdate->format('Ymd') . '-0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -56,26 +56,6 @@ class PiggyBank extends Eloquent
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO remove this method in favour of something in the FireflyIII libraries.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $target
|
||||
*
|
||||
* @return PiggyBankRepetition
|
||||
*/
|
||||
public function createRepetition(Carbon $start = null, Carbon $target = null)
|
||||
{
|
||||
$rep = new \PiggyBankRepetition;
|
||||
$rep->piggyBank()->associate($this);
|
||||
$rep->startdate = $start;
|
||||
$rep->targetdate = $target;
|
||||
$rep->currentamount = 0;
|
||||
$rep->save();
|
||||
|
||||
return $rep;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO remove this method in favour of something in the FireflyIII libraries.
|
||||
*
|
||||
@ -168,42 +148,6 @@ class PiggyBank extends Eloquent
|
||||
return $this->morphMany('Reminder', 'remindersable');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO remove this method in favour of something in the FireflyIII libraries.
|
||||
*
|
||||
* Same but for specific date.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @returns \PiggyBankRepetition
|
||||
*/
|
||||
public function repetitionForDate(Carbon $date)
|
||||
{
|
||||
$query = $this->piggyBankRepetitions()->where(
|
||||
function ($q) use ($date) {
|
||||
|
||||
$q->where(
|
||||
function ($q) use ($date) {
|
||||
$q->whereNull('startdate');
|
||||
$q->orWhere('startdate', '<=', $date->format('Y-m-d'));
|
||||
}
|
||||
)->where(
|
||||
function ($q) use ($date) {
|
||||
$q->whereNull('targetdate');
|
||||
$q->orWhere('targetdate', '>=', $date->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
}
|
||||
)->orWhere(
|
||||
function ($q) use ($date) {
|
||||
$q->where('startdate', '>=', $date->format('Y-m-d'));
|
||||
$q->where('targetdate', '>=', $date->format('Y-m-d'));
|
||||
}
|
||||
)->orderBy('startdate', 'ASC');
|
||||
$result = $query->first();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
|
@ -24,23 +24,6 @@ class PiggyBankRepetition extends Eloquent
|
||||
return ['created_at', 'updated_at', 'targetdate', 'startdate'];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO remove this method in favour of something in the FireflyIII libraries.
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function pct()
|
||||
{
|
||||
$total = $this->piggyBank->targetamount;
|
||||
$saved = $this->currentamount;
|
||||
if ($total == 0) {
|
||||
return 0;
|
||||
}
|
||||
$pct = round(($saved / $total) * 100, 1);
|
||||
|
||||
return $pct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user