mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Cleaning up
This commit is contained in:
@@ -19,57 +19,6 @@ use Navigation;
|
||||
class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Based on the piggy bank, the reminder-setting and
|
||||
* other variables this method tries to divide the piggy bank into equal parts. Each is
|
||||
* accommodated by a reminder (if everything goes to plan).
|
||||
*
|
||||
* @param PiggyBankRepetition $repetition
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function calculateParts(PiggyBankRepetition $repetition)
|
||||
{
|
||||
/** @var PiggyBank $piggyBank */
|
||||
$piggyBank = $repetition->piggyBank()->first();
|
||||
$bars = new Collection;
|
||||
$currentStart = clone $repetition->startdate;
|
||||
|
||||
if (is_null($piggyBank->reminder)) {
|
||||
$entry = ['repetition' => $repetition, 'amountPerBar' => floatval($piggyBank->targetamount),
|
||||
'currentAmount' => floatval($repetition->currentamount), 'cumulativeAmount' => floatval($piggyBank->targetamount),
|
||||
'startDate' => clone $repetition->startdate, 'targetDate' => clone $repetition->targetdate];
|
||||
$bars->push($this->createPiggyBankPart($entry));
|
||||
|
||||
return $bars;
|
||||
}
|
||||
|
||||
while ($currentStart < $repetition->targetdate) {
|
||||
$currentTarget = Navigation::endOfX($currentStart, $piggyBank->reminder, $repetition->targetdate);
|
||||
$entry = ['repetition' => $repetition, 'amountPerBar' => null, 'currentAmount' => floatval($repetition->currentamount),
|
||||
'cumulativeAmount' => null, 'startDate' => $currentStart, 'targetDate' => $currentTarget];
|
||||
$bars->push($this->createPiggyBankPart($entry));
|
||||
$currentStart = clone $currentTarget;
|
||||
$currentStart->addDay();
|
||||
|
||||
}
|
||||
$amountPerBar = floatval($piggyBank->targetamount) / $bars->count();
|
||||
$cumulative = $amountPerBar;
|
||||
/** @var PiggyBankPart $bar */
|
||||
foreach ($bars as $index => $bar) {
|
||||
$bar->setAmountPerBar($amountPerBar);
|
||||
$bar->setCumulativeAmount($cumulative);
|
||||
if ($bars->count() - 1 == $index) {
|
||||
$bar->setCumulativeAmount($piggyBank->targetamount);
|
||||
}
|
||||
$cumulative += $amountPerBar;
|
||||
}
|
||||
|
||||
return $bars;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param $amount
|
||||
@@ -83,24 +32,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBankPart
|
||||
*/
|
||||
public function createPiggyBankPart(array $data)
|
||||
{
|
||||
$part = new PiggyBankPart;
|
||||
$part->setRepetition($data['repetition']);
|
||||
$part->setAmountPerBar($data['amountPerBar']);
|
||||
$part->setCurrentamount($data['currentAmount']);
|
||||
$part->setCumulativeAmount($data['cumulativeAmount']);
|
||||
$part->setStartdate($data['startDate']);
|
||||
$part->setTargetdate($data['targetDate']);
|
||||
|
||||
return $part;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
|
Reference in New Issue
Block a user