mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-09 23:15:45 -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();
|
||||
getAvailableBox();
|
||||
getNetWorthBox();
|
||||
getPiggyBanks();
|
||||
|
||||
//getBoxAmounts();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getPiggyBanks() {
|
||||
$.getJSON(piggyInfoUri).done(function (data) {
|
||||
if (data.html.length > 0) {
|
||||
$('#piggy_bank_overview').html(data.html);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getNetWorthBox() {
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
@ -60,7 +72,7 @@ function getNetWorthBox() {
|
||||
function getAvailableBox() {
|
||||
// box-left-to-spend
|
||||
// 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-per-day').html(data.perDay);
|
||||
});
|
||||
@ -72,7 +84,7 @@ function getAvailableBox() {
|
||||
function getBillsBox() {
|
||||
// box-bills-unpaid
|
||||
// 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-unpaid').html(data.unpaid);
|
||||
});
|
||||
@ -85,7 +97,7 @@ function getBalanceBox() {
|
||||
// box-balance-total
|
||||
// box-balance-out
|
||||
// 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-in').html(data.income);
|
||||
$('#box-balance-out').html(data.expense);
|
||||
@ -93,7 +105,6 @@ function getBalanceBox() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getBoxAmounts() {
|
||||
"use strict";
|
||||
var boxes = ['in', 'out', 'bills-unpaid', 'bills-paid'];
|
||||
|
@ -21,7 +21,7 @@
|
||||
{# BUDGETS #}
|
||||
<div class="box">
|
||||
<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 class="box-body">
|
||||
<canvas id="budgets-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
|
||||
@ -30,7 +30,7 @@
|
||||
{# CATEGORIES #}
|
||||
<div class="box">
|
||||
<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 class="box-body">
|
||||
@ -39,22 +39,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<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 #}
|
||||
<div id="all_transactions">
|
||||
{% for data in transactions %}
|
||||
@ -100,6 +84,27 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
</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 class="row">
|
||||
@ -107,7 +112,7 @@
|
||||
{# EXPENSE ACCOUNTS #}
|
||||
<div class="box">
|
||||
<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 class="box-body">
|
||||
@ -118,7 +123,7 @@
|
||||
{% if showDeps %}
|
||||
<div class="box">
|
||||
<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 class="box-body">
|
||||
@ -136,6 +141,7 @@
|
||||
var accountFrontpageUri = '{{ route('chart.account.frontpage') }}';
|
||||
var accountRevenueUri = '{{ route('chart.account.revenue') }}';
|
||||
var accountExpenseUri = '{{ route('chart.account.expense') }}';
|
||||
var piggyInfoUri = '{{ route('json.fp.piggy-banks') }}';
|
||||
</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