mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-26 02:40:43 -06:00
Show bill average.
This commit is contained in:
parent
e8e7ab01d2
commit
f1e8d1cf1e
@ -11,6 +11,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Requests\BillFormRequest;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -190,15 +191,20 @@ class BillController extends Controller
|
||||
*/
|
||||
public function show(BillRepositoryInterface $repository, Bill $bill)
|
||||
{
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$journals = $repository->getJournals($bill, $page, $pageSize);
|
||||
/** @var Carbon $date */
|
||||
$date = session('start');
|
||||
$year = $date->year;
|
||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$journals = $repository->getJournals($bill, $page, $pageSize);
|
||||
$yearAverage = $repository->getYearAverage($bill, $date);
|
||||
$overallAverage = $repository->getOverallAverage($bill);
|
||||
$journals->setPath('/bills/show/' . $bill->id);
|
||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
|
||||
$hideBill = true;
|
||||
$subTitle = e($bill->name);
|
||||
|
||||
return view('bills.show', compact('journals', 'hideBill', 'bill', 'subTitle'));
|
||||
return view('bills.show', compact('journals', 'yearAverage', 'overallAverage', 'year', 'hideBill', 'bill', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -557,4 +557,52 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
return $wordMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getYearAverage(Bill $bill, Carbon $date): string
|
||||
{
|
||||
$journals = $bill->transactionjournals()
|
||||
->where('date', '>=', $date->year . '-01-01')
|
||||
->where('date', '<=', $date->year . '-12-31')
|
||||
->get();
|
||||
$sum = '0';
|
||||
$count = strval($journals->count());
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$sum = bcadd($sum, TransactionJournal::amountPositive($journal));
|
||||
}
|
||||
$avg = '0';
|
||||
if ($journals->count() > 0) {
|
||||
$avg = bcdiv($sum, $count);
|
||||
}
|
||||
|
||||
return $avg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bill
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOverallAverage($bill): string
|
||||
{
|
||||
$journals = $bill->transactionjournals()->get();
|
||||
$sum = '0';
|
||||
$count = strval($journals->count());
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$sum = bcadd($sum, TransactionJournal::amountPositive($journal));
|
||||
}
|
||||
$avg = '0';
|
||||
if ($journals->count() > 0) {
|
||||
$avg = bcdiv($sum, $count);
|
||||
}
|
||||
|
||||
return $avg;
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,21 @@ interface BillRepositoryInterface
|
||||
*/
|
||||
public function destroy(Bill $bill): bool;
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getYearAverage(Bill $bill, Carbon $date): string;
|
||||
|
||||
/**
|
||||
* @param $bill
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOverallAverage($bill): string;
|
||||
|
||||
/**
|
||||
* Find a bill by ID.
|
||||
*
|
||||
|
@ -415,6 +415,8 @@ return [
|
||||
'cannot_scan_inactive_bill' => 'Inactive bills cannot be scanned.',
|
||||
'rescanned_bill' => 'Rescanned everything.',
|
||||
'bill_date_little_relevance' => 'The only part of this date used by Firefly is the day. It is only useful when your bill arrives at exactly the same date every month. If the payment date of your bills varies, simply use the first of the month.',
|
||||
'average_bill_amount_year' => 'Average bill amount (:year)',
|
||||
'average_bill_amount_overall' => 'Average bill amount (overall)',
|
||||
|
||||
// accounts:
|
||||
'details_for_asset' => 'Details for asset account ":name"',
|
||||
|
@ -60,6 +60,14 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ trans('firefly.average_bill_amount_year', {year: year}) }}</td>
|
||||
<td>{{ '0'|formatAmount }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ 'average_bill_amount_overall'|_ }}</td>
|
||||
<td>{{ '0'|formatAmount }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user