mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for #937
This commit is contained in:
parent
fb0cd056b9
commit
93bcc8f63d
74
app/Http/Controllers/Json/FrontpageController.php
Normal file
74
app/Http/Controllers/Json/FrontpageController.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FrontpageController.php
|
||||||
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Http\Controllers\Json;
|
||||||
|
|
||||||
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
|
use FireflyIII\Models\PiggyBank;
|
||||||
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
|
use Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FrontpageController
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Http\Controllers\Json
|
||||||
|
*/
|
||||||
|
class FrontpageController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function piggyBanks(PiggyBankRepositoryInterface $repository)
|
||||||
|
{
|
||||||
|
$set = $repository->getPiggyBanks();
|
||||||
|
$info = [];
|
||||||
|
/** @var PiggyBank $piggyBank */
|
||||||
|
foreach ($set as $piggyBank) {
|
||||||
|
$rep = $piggyBank->currentRelevantRep();
|
||||||
|
$amount = strval($rep->currentamount);
|
||||||
|
if (!is_null($rep->id) && bccomp($amount, '0') === 1) {
|
||||||
|
|
||||||
|
// percentage!
|
||||||
|
$pct = round(($amount / $piggyBank->targetamount) * 100);
|
||||||
|
|
||||||
|
$entry = [
|
||||||
|
'id' => $piggyBank->id,
|
||||||
|
'name' => $piggyBank->name,
|
||||||
|
'amount' => $amount,
|
||||||
|
'target' => $piggyBank->targetamount,
|
||||||
|
'percentage' => $pct,
|
||||||
|
];
|
||||||
|
|
||||||
|
$info[] = $entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
$html = '';
|
||||||
|
if (count($info) > 0) {
|
||||||
|
$html = view('json.piggy-banks', compact('info'))->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response::json(['html' => $html]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
public/js/ff/index.js
vendored
21
public/js/ff/index.js
vendored
@ -43,13 +43,25 @@ function drawChart() {
|
|||||||
getBillsBox();
|
getBillsBox();
|
||||||
getAvailableBox();
|
getAvailableBox();
|
||||||
getNetWorthBox();
|
getNetWorthBox();
|
||||||
|
getPiggyBanks();
|
||||||
|
|
||||||
//getBoxAmounts();
|
//getBoxAmounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function getPiggyBanks() {
|
||||||
|
$.getJSON(piggyInfoUri).done(function (data) {
|
||||||
|
if (data.html.length > 0) {
|
||||||
|
$('#piggy_bank_overview').html(data.html);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getNetWorthBox() {
|
function getNetWorthBox() {
|
||||||
// box-net-worth
|
// box-net-worth
|
||||||
$.getJSON('json/box/net-worth').done(function(data) {
|
$.getJSON('json/box/net-worth').done(function (data) {
|
||||||
$('#box-net-worth').html(data.net_worth);
|
$('#box-net-worth').html(data.net_worth);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -60,7 +72,7 @@ function getNetWorthBox() {
|
|||||||
function getAvailableBox() {
|
function getAvailableBox() {
|
||||||
// box-left-to-spend
|
// box-left-to-spend
|
||||||
// box-left-per-day
|
// box-left-per-day
|
||||||
$.getJSON('json/box/available').done(function(data) {
|
$.getJSON('json/box/available').done(function (data) {
|
||||||
$('#box-left-to-spend').html(data.left);
|
$('#box-left-to-spend').html(data.left);
|
||||||
$('#box-left-per-day').html(data.perDay);
|
$('#box-left-per-day').html(data.perDay);
|
||||||
});
|
});
|
||||||
@ -72,7 +84,7 @@ function getAvailableBox() {
|
|||||||
function getBillsBox() {
|
function getBillsBox() {
|
||||||
// box-bills-unpaid
|
// box-bills-unpaid
|
||||||
// box-bills-paid
|
// box-bills-paid
|
||||||
$.getJSON('json/box/bills').done(function(data) {
|
$.getJSON('json/box/bills').done(function (data) {
|
||||||
$('#box-bills-paid').html(data.paid);
|
$('#box-bills-paid').html(data.paid);
|
||||||
$('#box-bills-unpaid').html(data.unpaid);
|
$('#box-bills-unpaid').html(data.unpaid);
|
||||||
});
|
});
|
||||||
@ -85,7 +97,7 @@ function getBalanceBox() {
|
|||||||
// box-balance-total
|
// box-balance-total
|
||||||
// box-balance-out
|
// box-balance-out
|
||||||
// box-balance-in
|
// box-balance-in
|
||||||
$.getJSON('json/box/balance').done(function(data) {
|
$.getJSON('json/box/balance').done(function (data) {
|
||||||
$('#box-balance-total').html(data.combined);
|
$('#box-balance-total').html(data.combined);
|
||||||
$('#box-balance-in').html(data.income);
|
$('#box-balance-in').html(data.income);
|
||||||
$('#box-balance-out').html(data.expense);
|
$('#box-balance-out').html(data.expense);
|
||||||
@ -93,7 +105,6 @@ function getBalanceBox() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getBoxAmounts() {
|
function getBoxAmounts() {
|
||||||
"use strict";
|
"use strict";
|
||||||
var boxes = ['in', 'out', 'bills-unpaid', 'bills-paid'];
|
var boxes = ['in', 'out', 'bills-unpaid', 'bills-paid'];
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
{# BUDGETS #}
|
{# BUDGETS #}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'budgetsAndSpending'|_ }}</h3>
|
<h3 class="box-title"><a href="{{ route('budgets.index') }}" title="{{ 'budgetsAndSpending'|_ }}">{{ 'budgetsAndSpending'|_ }}</a></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<canvas id="budgets-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
|
<canvas id="budgets-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
|
||||||
@ -30,7 +30,7 @@
|
|||||||
{# CATEGORIES #}
|
{# CATEGORIES #}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'categories'|_ }}</h3>
|
<h3 class="box-title"><a href="{{ route('categories.index') }}" title="{{ 'categories'|_ }}">{{ 'categories'|_ }}</a></h3>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
@ -39,22 +39,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-4 col-md-6 col-sm-12">
|
<div class="col-lg-4 col-md-6 col-sm-12">
|
||||||
{% if billCount > 0 %}
|
|
||||||
{# BILLS #}
|
|
||||||
<div class="box">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<h3 class="box-title">{{ 'bills'|_ }}</h3>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="box-body">
|
|
||||||
<div style="width:100%;margin:0 auto;">
|
|
||||||
<canvas id="bills-chart" style="width:100%;height:200px;" height="200"></canvas>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{# TRANSACTIONS #}
|
{# TRANSACTIONS #}
|
||||||
<div id="all_transactions">
|
<div id="all_transactions">
|
||||||
{% for data in transactions %}
|
{% for data in transactions %}
|
||||||
@ -100,6 +84,27 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if billCount > 0 %}
|
||||||
|
{# BILLS #}
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title"><a href="{{ route('bills.index') }}" title="{{ 'bills'|_ }}">{{ 'bills'|_ }}</a></h3>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<div style="width:100%;margin:0 auto;">
|
||||||
|
<canvas id="bills-chart" style="width:100%;height:200px;" height="200"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# box for piggy bank data (JSON) #}
|
||||||
|
<div id="piggy_bank_overview">
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -107,7 +112,7 @@
|
|||||||
{# EXPENSE ACCOUNTS #}
|
{# EXPENSE ACCOUNTS #}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'expense_accounts'|_ }}</h3>
|
<h3 class="box-title"><a href="{{ route('accounts.index',['expense']) }}" title="{{ 'expense_accounts'|_ }}">{{ 'expense_accounts'|_ }}</a></h3>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
@ -118,7 +123,7 @@
|
|||||||
{% if showDeps %}
|
{% if showDeps %}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'revenue_accounts'|_ }}</h3>
|
<h3 class="box-title"><a href="{{ route('accounts.index',['revenue']) }}" title="{{ 'revenue_accounts'|_ }}">{{ 'revenue_accounts'|_ }}</a></h3>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
@ -136,6 +141,7 @@
|
|||||||
var accountFrontpageUri = '{{ route('chart.account.frontpage') }}';
|
var accountFrontpageUri = '{{ route('chart.account.frontpage') }}';
|
||||||
var accountRevenueUri = '{{ route('chart.account.revenue') }}';
|
var accountRevenueUri = '{{ route('chart.account.revenue') }}';
|
||||||
var accountExpenseUri = '{{ route('chart.account.expense') }}';
|
var accountExpenseUri = '{{ route('chart.account.expense') }}';
|
||||||
|
var piggyInfoUri = '{{ route('json.fp.piggy-banks') }}';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}"></script>
|
||||||
|
16
resources/views/json/piggy-banks.twig
Normal file
16
resources/views/json/piggy-banks.twig
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title"><a href="{{ route('piggy-banks.index') }}" title="{{ 'piggyBanks'|_ }}">{{ 'piggyBanks'|_ }}</a></h3>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
{% for entry in info %}
|
||||||
|
<strong>{{ entry.name }}</strong><br />
|
||||||
|
<div class="progress">
|
||||||
|
<div class="progress-bar" role="progressbar" aria-valuenow="{{ entry.percentage }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ entry.percentage }}%;">
|
||||||
|
{{ entry.amount|formatAmountPlain }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user