akaunting/app/Widgets/TotalIncome.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2019-12-29 03:01:19 +03:00
<?php
namespace App\Widgets;
use App\Abstracts\Widget;
use App\Models\Banking\Transaction;
use App\Models\Income\Invoice;
class TotalIncome extends Widget
{
public function show()
{
$current = $open = $overdue = 0;
$this->applyFilters(Transaction::type('income')->isNotTransfer())->each(function ($transaction) use (&$current) {
2019-12-29 03:01:19 +03:00
$current += $transaction->getAmountConvertedToDefault();
});
$this->applyFilters(Invoice::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($invoice) use (&$open, &$overdue) {
2019-12-29 03:01:19 +03:00
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($invoice);
$open += $open_tmp;
$overdue += $overdue_tmp;
});
$progress = 100;
if (!empty($open) && !empty($overdue)) {
$progress = (int) ($open * 100) / ($open + $overdue);
}
$totals = [
'current' => $current,
'open' => money($open, setting('default.currency'), true),
'overdue' => money($overdue, setting('default.currency'), true),
'progress' => $progress,
];
return view('widgets.total_income', [
'config' => (object) $this->config,
'totals' => $totals,
]);
}
}