mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Query & loop optimizations.
This commit is contained in:
@@ -73,10 +73,8 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
// find transactions to shared asset accounts, which are without a budget by default:
|
// find transactions to shared asset accounts, which are without a budget by default:
|
||||||
// which is only relevant when shared asset accounts are hidden.
|
// which is only relevant when shared asset accounts are hidden.
|
||||||
if ($showSharedReports === false) {
|
if ($showSharedReports === false) {
|
||||||
$transfers = $query->sharedExpenses($start, $end);
|
$transfers = $query->sharedExpenses($start, $end)->sum('queryAmount');
|
||||||
foreach ($transfers as $transfer) {
|
$budgets[0]['spent'] += floatval($transfers) * -1;
|
||||||
$budgets[0]['spent'] += floatval($transfer->amount) * -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $budgets;
|
return $budgets;
|
||||||
|
@@ -111,17 +111,11 @@ class ReportQuery implements ReportQueryInterface
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end)
|
public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
$set = $this->balancedTransactionsList($account, $start, $end);
|
return floatval($this->balancedTransactionsList($account, $start, $end)->sum('queryAmount'));
|
||||||
$sum = 0;
|
|
||||||
foreach ($set as $entry) {
|
|
||||||
$sum += floatval($entry->amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -43,7 +43,7 @@ interface ReportQueryInterface
|
|||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end);
|
public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end);
|
||||||
|
|
||||||
|
@@ -80,8 +80,7 @@ class GoogleChartController extends Controller
|
|||||||
$index = 1;
|
$index = 1;
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$accountName = $account->name;
|
$chart->addColumn('Balance for ' . $account->name, 'number');
|
||||||
$chart->addColumn('Balance for ' . $accountName, 'number');
|
|
||||||
$chart->addCertainty($index);
|
$chart->addCertainty($index);
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
@@ -251,6 +250,11 @@ class GoogleChartController extends Controller
|
|||||||
$bills = $repository->getActiveBills();
|
$bills = $repository->getActiveBills();
|
||||||
$paid = new Collection; // journals.
|
$paid = new Collection; // journals.
|
||||||
$unpaid = new Collection; // bills
|
$unpaid = new Collection; // bills
|
||||||
|
// loop paid and create single entry:
|
||||||
|
$paidDescriptions = [];
|
||||||
|
$paidAmount = 0;
|
||||||
|
$unpaidDescriptions = [];
|
||||||
|
$unpaidAmount = 0;
|
||||||
|
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
@@ -287,11 +291,7 @@ class GoogleChartController extends Controller
|
|||||||
$paid = $paid->merge($journals);
|
$paid = $paid->merge($journals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// loop paid and create single entry:
|
|
||||||
$paidDescriptions = [];
|
|
||||||
$paidAmount = 0;
|
|
||||||
$unpaidDescriptions = [];
|
|
||||||
$unpaidAmount = 0;
|
|
||||||
|
|
||||||
/** @var TransactionJournal $entry */
|
/** @var TransactionJournal $entry */
|
||||||
foreach ($paid as $entry) {
|
foreach ($paid as $entry) {
|
||||||
@@ -498,19 +498,9 @@ class GoogleChartController extends Controller
|
|||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
$currentEnd = clone $start;
|
$currentEnd = clone $start;
|
||||||
$currentEnd->endOfMonth();
|
$currentEnd->endOfMonth();
|
||||||
// total income:
|
// total income && total expenses:
|
||||||
$income = $query->incomeByPeriod($start, $currentEnd, $showSharedReports);
|
$incomeSum = floatval($query->incomeByPeriod($start, $currentEnd, $showSharedReports)->sum('queryAmount'));
|
||||||
$incomeSum = 0;
|
$expenseSum = floatval($query->journalsByExpenseAccount($start, $currentEnd, $showSharedReports)->sum('queryAmount'));
|
||||||
foreach ($income as $entry) {
|
|
||||||
$incomeSum += floatval($entry->amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
// total expenses:
|
|
||||||
$expense = $query->journalsByExpenseAccount($start, $currentEnd, $showSharedReports);
|
|
||||||
$expenseSum = 0;
|
|
||||||
foreach ($expense as $entry) {
|
|
||||||
$expenseSum += floatval($entry->amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
$chart->addRow(clone $start, $incomeSum, $expenseSum);
|
$chart->addRow(clone $start, $incomeSum, $expenseSum);
|
||||||
$start->addMonth();
|
$start->addMonth();
|
||||||
@@ -549,18 +539,9 @@ class GoogleChartController extends Controller
|
|||||||
$currentEnd = clone $start;
|
$currentEnd = clone $start;
|
||||||
$currentEnd->endOfMonth();
|
$currentEnd->endOfMonth();
|
||||||
// total income:
|
// total income:
|
||||||
$incomeResult = $query->incomeByPeriod($start, $currentEnd, $showSharedReports);
|
$incomeSum = floatval($query->incomeByPeriod($start, $currentEnd, $showSharedReports)->sum('queryAmount'));
|
||||||
$incomeSum = 0;
|
|
||||||
foreach ($incomeResult as $entry) {
|
|
||||||
$incomeSum += floatval($entry->amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
// total expenses:
|
// total expenses:
|
||||||
$expenseResult = $query->journalsByExpenseAccount($start, $currentEnd, $showSharedReports);
|
$expenseSum = floatval($query->journalsByExpenseAccount($start, $currentEnd, $showSharedReports)->sum('queryAmount'));
|
||||||
$expenseSum = 0;
|
|
||||||
foreach ($expenseResult as $entry) {
|
|
||||||
$expenseSum += floatval($entry->amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
$income += $incomeSum;
|
$income += $incomeSum;
|
||||||
$expense += $expenseSum;
|
$expense += $expenseSum;
|
||||||
|
Reference in New Issue
Block a user