Some fixes to amounts.

This commit is contained in:
James Cole
2015-12-06 13:17:00 +01:00
parent 77262f52a4
commit 8f57c7dcb3
3 changed files with 31 additions and 28 deletions

View File

@@ -20,6 +20,7 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget as BudgetModel; use FireflyIII\Models\Budget as BudgetModel;
use FireflyIII\Models\LimitRepetition; use FireflyIII\Models\LimitRepetition;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Steam;
/** /**
* Class ReportHelper * Class ReportHelper
@@ -70,6 +71,7 @@ class ReportHelper implements ReportHelperInterface
return null; return null;
} }
); );
return $this->getAccountReportForList($date, $end, $accounts); return $this->getAccountReportForList($date, $end, $accounts);
} }
@@ -405,29 +407,46 @@ class ReportHelper implements ReportHelperInterface
* This method generates a full report for the given period on all * This method generates a full report for the given period on all
* given accounts * given accounts
* *
* @param Carbon $date * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts * @param Collection $accounts
* *
* @return AccountCollection * @return AccountCollection
*/ */
public function getAccountReportForList(Carbon $date, Carbon $end, Collection $accounts) public function getAccountReportForList(Carbon $start, Carbon $end, Collection $accounts)
{ {
$start = '0'; $startAmount = '0';
$end = '0'; $endAmount = '0';
$diff = '0'; $diff = '0';
bcscale(2); bcscale(2);
$accounts->each(
function (Account $account) use ($start, $end) {
/**
* The balance for today always incorporates transactions
* made on today. So to get todays "start" balance, we sub one
* day.
*/
$yesterday = clone $start;
$yesterday->subDay();
/** @noinspection PhpParamsInspection */
$account->startBalance = Steam::balance($account, $yesterday);
$account->endBalance = Steam::balance($account, $end);
}
);
// summarize: // summarize:
foreach ($accounts as $account) { foreach ($accounts as $account) {
$start = bcadd($start, $account->startBalance); $startAmount = bcadd($startAmount, $account->startBalance);
$end = bcadd($end, $account->endBalance); $endAmount = bcadd($endAmount, $account->endBalance);
$diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance)); $diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
} }
$object = new AccountCollection; $object = new AccountCollection;
$object->setStart($start); $object->setStart($startAmount);
$object->setEnd($end); $object->setEnd($endAmount);
$object->setDifference($diff); $object->setDifference($diff);
$object->setAccounts($accounts); $object->setAccounts($accounts);

View File

@@ -36,13 +36,13 @@ interface ReportHelperInterface
* This method generates a full report for the given period on all * This method generates a full report for the given period on all
* given accounts * given accounts
* *
* @param Carbon $date * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts * @param Collection $accounts
* *
* @return AccountCollection * @return AccountCollection
*/ */
public function getAccountReportForList(Carbon $date, Carbon $end, Collection $accounts); public function getAccountReportForList(Carbon $start, Carbon $end, Collection $accounts);
/** /**
* This method generates a full report for the given period on all * This method generates a full report for the given period on all

View File

@@ -103,22 +103,6 @@ class ReportQuery implements ReportQueryInterface
); );
} }
$set = $query->get(['accounts.*']); $set = $query->get(['accounts.*']);
$set->each(
function (Account $account) use ($start, $end) {
/**
* The balance for today always incorporates transactions
* made on today. So to get todays "start" balance, we sub one
* day.
*/
$yesterday = clone $start;
$yesterday->subDay();
/** @noinspection PhpParamsInspection */
$account->startBalance = Steam::balance($account, $yesterday);
$account->endBalance = Steam::balance($account, $end);
}
);
return $set; return $set;
} }