mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 10:53:31 +00:00
Show bill average.
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types = 1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers;
|
namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Http\Requests\BillFormRequest;
|
use FireflyIII\Http\Requests\BillFormRequest;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
@@ -190,15 +191,20 @@ class BillController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function show(BillRepositoryInterface $repository, Bill $bill)
|
public function show(BillRepositoryInterface $repository, Bill $bill)
|
||||||
{
|
{
|
||||||
|
/** @var Carbon $date */
|
||||||
|
$date = session('start');
|
||||||
|
$year = $date->year;
|
||||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||||
$journals = $repository->getJournals($bill, $page, $pageSize);
|
$journals = $repository->getJournals($bill, $page, $pageSize);
|
||||||
|
$yearAverage = $repository->getYearAverage($bill, $date);
|
||||||
|
$overallAverage = $repository->getOverallAverage($bill);
|
||||||
$journals->setPath('/bills/show/' . $bill->id);
|
$journals->setPath('/bills/show/' . $bill->id);
|
||||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
|
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
|
||||||
$hideBill = true;
|
$hideBill = true;
|
||||||
$subTitle = e($bill->name);
|
$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;
|
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;
|
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.
|
* Find a bill by ID.
|
||||||
*
|
*
|
||||||
|
@@ -415,6 +415,8 @@ return [
|
|||||||
'cannot_scan_inactive_bill' => 'Inactive bills cannot be scanned.',
|
'cannot_scan_inactive_bill' => 'Inactive bills cannot be scanned.',
|
||||||
'rescanned_bill' => 'Rescanned everything.',
|
'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.',
|
'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:
|
// accounts:
|
||||||
'details_for_asset' => 'Details for asset account ":name"',
|
'details_for_asset' => 'Details for asset account ":name"',
|
||||||
|
@@ -60,6 +60,14 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</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>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user