mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-04 05:06:37 +00:00
Updated some tests, fixed some bugs.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use Grumpydictator\Gchart\GChart as GChart;
|
||||
|
||||
/**
|
||||
* Class GoogleChartController
|
||||
@@ -7,6 +8,18 @@ use Carbon\Carbon;
|
||||
class GoogleChartController extends BaseController
|
||||
{
|
||||
|
||||
/** @var GChart */
|
||||
protected $_chart;
|
||||
|
||||
/**
|
||||
* @param GChart $chart
|
||||
*/
|
||||
public function __construct(GChart $chart)
|
||||
{
|
||||
$this->_chart = $chart;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $view
|
||||
@@ -15,55 +28,35 @@ class GoogleChartController extends BaseController
|
||||
*/
|
||||
public function accountBalanceChart(Account $account, $view = 'session')
|
||||
{
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$this->_chart->addColumn('Day of month', 'date');
|
||||
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
|
||||
$chart->addColumn('Day of month', 'date');
|
||||
$chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
$start = Session::get('start');
|
||||
$end = Session::get('end');
|
||||
$count = $account->transactions()->count();
|
||||
|
||||
/*
|
||||
* Loop the date, then loop the accounts, then add balance.
|
||||
*/
|
||||
switch ($view) {
|
||||
default:
|
||||
case 'session':
|
||||
$start = Session::get('start');
|
||||
$end = Session::get('end');
|
||||
break;
|
||||
case 'all':
|
||||
$first = $account->transactionjournals()->orderBy('date', 'DESC')->first();
|
||||
$last = $account->transactionjournals()->orderBy('date', 'ASC')->first();
|
||||
if (is_null($first)) {
|
||||
$start = Session::get('start');
|
||||
} else {
|
||||
$start = clone $first->date;
|
||||
}
|
||||
if (is_null($last)) {
|
||||
$end = Session::get('end');
|
||||
} else {
|
||||
$end = clone $last->date;
|
||||
}
|
||||
break;
|
||||
if ($view == 'all' && $count > 0) {
|
||||
$first = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy(
|
||||
'date', 'ASC'
|
||||
)->first(['transaction_journals.date']);
|
||||
$last = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->orderBy(
|
||||
'date', 'DESC'
|
||||
)->first(['transaction_journals.date']);
|
||||
$start = new Carbon($first->date);
|
||||
$end = new Carbon($last->date);
|
||||
}
|
||||
|
||||
$current = clone $start;
|
||||
|
||||
while ($end >= $current) {
|
||||
$row = [clone $current];
|
||||
if ($current > Carbon::now()) {
|
||||
$row[] = null;
|
||||
} else {
|
||||
$row[] = Steam::balance($account, $current);
|
||||
}
|
||||
|
||||
$chart->addRowArray($row);
|
||||
$this->_chart->addRow(clone $current, $current > Carbon::now() ? null : Steam::balance($account, $current));
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
|
||||
$chart->generate();
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($chart->getData());
|
||||
return Response::json($this->_chart->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class TestContentSeeder
|
||||
*/
|
||||
class TestContentSeeder extends Seeder
|
||||
{
|
||||
|
||||
@@ -27,6 +30,7 @@ class TestContentSeeder extends Seeder
|
||||
// create two asset accounts.
|
||||
$checking = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);
|
||||
$savings = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);
|
||||
$deleteMe = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);
|
||||
|
||||
// create two budgets:
|
||||
$groceriesBudget = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $account) }}
|
||||
{{Form::open(['class' => 'form-horizontal','url' => route('accounts.destroy',$account->id)])}}
|
||||
{{Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('accounts.destroy',$account->id)])}}
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||
<div class="panel panel-red">
|
||||
@@ -29,16 +29,5 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{{Form::close()}}
|
||||
@stop
|
||||
Reference in New Issue
Block a user