firefly-iii/app/lib/FireflyIII/Collection/PiggybankPart.php

179 lines
3.4 KiB
PHP
Raw Normal View History

2014-11-24 03:12:34 -06:00
<?php
namespace FireflyIII\Collection;
use Carbon\Carbon;
2014-12-13 14:59:02 -06:00
/**
* Class PiggyBankPart
2014-12-13 14:59:02 -06:00
*
* @package FireflyIII\Collection
*/
class PiggyBankPart
2014-11-24 03:12:34 -06:00
{
2014-11-24 11:06:21 -06:00
/** @var float */
2014-11-24 03:12:34 -06:00
public $amountPerBar;
2014-11-24 11:06:21 -06:00
/** @var float */
public $cumulativeAmount;
/** @var float */
public $currentamount;
2014-11-24 10:01:37 -06:00
/** @var \Reminder */
public $reminder;
2014-11-24 11:06:21 -06:00
/** @var \PiggyBankRepetition */
2014-11-24 03:12:34 -06:00
public $repetition;
2014-11-24 11:06:21 -06:00
2014-11-24 03:12:34 -06:00
/** @var Carbon */
public $startdate;
2014-11-24 11:06:21 -06:00
2014-11-24 03:12:34 -06:00
/** @var Carbon */
public $targetdate;
2014-11-24 10:01:37 -06:00
/**
* @return \Reminder
*/
public function getReminder()
{
if (is_null($this->reminder)) {
$this->reminder = $this->repetition->piggyBank->reminders()->where('startdate', $this->getStartdate()->format('Y-m-d'))->where(
2014-12-20 08:00:53 -06:00
'enddate', $this->getTargetdate()->format('Y-m-d')
2014-12-14 13:40:02 -06:00
)->first();
}
2014-11-24 10:01:37 -06:00
return $this->reminder;
}
/**
* @param \Reminder $reminder
*/
public function setReminder($reminder)
{
$this->reminder = $reminder;
}
2014-11-24 03:12:34 -06:00
/**
* @return Carbon
*/
public function getStartdate()
{
return $this->startdate;
}
/**
* @param Carbon $startdate
*/
public function setStartdate($startdate)
{
$this->startdate = $startdate;
}
/**
* @return Carbon
*/
public function getTargetdate()
{
return $this->targetdate;
}
/**
* @param Carbon $targetdate
*/
public function setTargetdate($targetdate)
{
$this->targetdate = $targetdate;
}
2014-12-20 08:00:53 -06:00
/**
* @return \PiggyBankRepetition
2014-12-20 08:00:53 -06:00
*/
public function getRepetition()
{
return $this->repetition;
}
/**
* @param \PiggyBankRepetition $repetition
2014-12-20 08:00:53 -06:00
*/
public function setRepetition($repetition)
{
$this->repetition = $repetition;
}
2014-12-13 14:59:02 -06:00
/**
* @return bool
*/
2014-11-24 10:01:37 -06:00
public function hasReminder()
{
return !is_null($this->reminder);
}
2014-12-13 14:59:02 -06:00
/**
* @return float|int
*/
2014-11-24 03:12:34 -06:00
public function percentage()
{
2014-11-24 11:06:21 -06:00
if ($this->getCurrentamount() < $this->getCumulativeAmount()) {
2014-11-24 03:12:34 -06:00
$pct = 0;
2014-12-31 09:17:43 -06:00
// calculate halfway point?
2014-11-24 11:06:21 -06:00
if ($this->getCumulativeAmount() - $this->getCurrentamount() < $this->getAmountPerBar()) {
2014-11-24 03:12:34 -06:00
$left = $this->getCurrentamount() % $this->getAmountPerBar();
$pct = round($left / $this->getAmountPerBar() * 100);
}
return $pct;
} else {
return 100;
}
}
/**
2014-11-24 11:06:21 -06:00
* @return float
2014-11-24 03:12:34 -06:00
*/
public function getCurrentamount()
{
return $this->currentamount;
}
/**
2014-11-24 11:06:21 -06:00
* @param float $currentamount
2014-11-24 03:12:34 -06:00
*/
public function setCurrentamount($currentamount)
{
$this->currentamount = $currentamount;
}
/**
2014-11-24 11:06:21 -06:00
* @return float
2014-11-24 03:12:34 -06:00
*/
public function getCumulativeAmount()
2014-11-24 03:12:34 -06:00
{
return $this->cumulativeAmount;
2014-11-24 03:12:34 -06:00
}
/**
* @param float $cumulativeAmount
2014-11-24 03:12:34 -06:00
*/
public function setCumulativeAmount($cumulativeAmount)
2014-11-24 03:12:34 -06:00
{
$this->cumulativeAmount = $cumulativeAmount;
2014-11-24 03:12:34 -06:00
}
/**
2014-11-24 11:06:21 -06:00
* @return float
2014-11-24 03:12:34 -06:00
*/
public function getAmountPerBar()
2014-11-24 03:12:34 -06:00
{
return $this->amountPerBar;
2014-11-24 03:12:34 -06:00
}
/**
* @param float $amountPerBar
2014-11-24 03:12:34 -06:00
*/
public function setAmountPerBar($amountPerBar)
2014-11-24 03:12:34 -06:00
{
$this->amountPerBar = $amountPerBar;
2014-11-24 03:12:34 -06:00
}
2014-11-24 11:06:21 -06:00
2014-11-24 03:12:34 -06:00
}