diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 57bfd3d6e4..1f4403b733 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -1,10 +1,4 @@ startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); + if ($frontPage->data == []) { $accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->get(['accounts.*']); } else { @@ -74,8 +75,8 @@ class HomeController extends Controller ->with(['transactions', 'transactioncurrency', 'transactiontype']) ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id) - ->where('date', '>=', $start->format('Y-m-d')) - ->where('date', '<=', $end->format('Y-m-d')) + ->before($end) + ->after($start) ->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.id', 'DESC') ->take(10) diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index f4583a826f..62e0dcd69b 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -1,20 +1,112 @@ transactionjournals() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->before($end) + ->after($start) + ->transactionTypes(['Deposit']) + ->where('transactions.amount', '>', 0) + ->first([DB::Raw('SUM(transactions.amount) as `amount`')]); + if (!is_null($in)) { + $amount = floatval($in->amount); + } + + break; + case 'out': + $box = Input::get('box'); + $in = Auth::user()->transactionjournals() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->before($end) + ->after($start) + ->transactionTypes(['Withdrawal']) + ->where('transactions.amount', '>', 0) + ->first([DB::Raw('SUM(transactions.amount) as `amount`')]); + if (!is_null($in)) { + $amount = floatval($in->amount); + } + + break; + case 'bills-unpaid': + $box = 'bills-unpaid'; + $bills = Auth::user()->bills()->where('active', 1)->get(); + + /** @var Bill $bill */ + foreach ($bills as $bill) { + $ranges = $repository->getRanges($bill, $start, $end); + + foreach ($ranges as $range) { + // paid a bill in this range? + $count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count(); + if ($count == 0) { + $amount += ($bill->amount_max + $bill->amount_min / 2); + + } + + } + } + break; + case 'bills-paid': + $box = 'bills-paid'; + // these two functions are the same as the chart TODO + $bills = Auth::user()->bills()->where('active', 1)->get(); + + /** @var Bill $bill */ + foreach ($bills as $bill) { + $ranges = $repository->getRanges($bill, $start, $end); + + foreach ($ranges as $range) { + // paid a bill in this range? + $count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count(); + if ($count != 0) { + $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); + $paid['items'][] = $journal->description; + $currentAmount = 0; + foreach ($journal->transactions as $t) { + if (floatval($t->amount) > 0) { + $currentAmount = floatval($t->amount); + } + } + $amount += $currentAmount; + } + + } + } + } + + return Response::json(['box' => $box, 'amount' => Amount::format($amount, false)]); + } + /** * Returns a list of categories. * @@ -22,8 +114,8 @@ class JsonController extends Controller { */ public function categories() { - $list = Auth::user()->categories()->orderBy('name','ASC')->get(); - $return = []; + $list = Auth::user()->categories()->orderBy('name', 'ASC')->get(); + $return = []; foreach ($list as $entry) { $return[] = $entry->name; } @@ -40,8 +132,8 @@ class JsonController extends Controller { */ public function expenseAccounts() { - $list = Auth::user()->accounts()->accountTypeIn(['Expense account', 'Beneficiary account'])->get(); - $return = []; + $list = Auth::user()->accounts()->accountTypeIn(['Expense account', 'Beneficiary account'])->get(); + $return = []; foreach ($list as $entry) { $return[] = $entry->name; } @@ -55,8 +147,8 @@ class JsonController extends Controller { */ public function revenueAccounts() { - $list = Auth::user()->accounts()->accountTypeIn(['Revenue account'])->get(); - $return = []; + $list = Auth::user()->accounts()->accountTypeIn(['Revenue account'])->get(); + $return = []; foreach ($list as $entry) { $return[] = $entry->name; } diff --git a/app/Http/Requests/BillFormRequest.php b/app/Http/Requests/BillFormRequest.php index f66c5db1b1..9782d6ba6f 100644 --- a/app/Http/Requests/BillFormRequest.php +++ b/app/Http/Requests/BillFormRequest.php @@ -1,10 +1,4 @@ 'JsonController@expenseAccounts', 'as' => 'json.expense-accounts']); Route::get('/json/revenue-accounts', ['uses' => 'JsonController@revenueAccounts', 'as' => 'json.revenue-accounts']); Route::get('/json/categories', ['uses' => 'JsonController@categories', 'as' => 'json.categories']); + Route::get('/json/box', ['uses' => 'JsonController@box', 'as' => 'json.box']); /** diff --git a/public/js/index.js b/public/js/index.js index 3328f23d6f..8b829c290c 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -3,7 +3,21 @@ google.setOnLoadCallback(drawChart); function drawChart() { googleLineChart('chart/home/account', 'accounts-chart'); - googleBarChart('chart/home/budgets','budgets-chart'); - googleColumnChart('chart/home/categories','categories-chart'); - googlePieChart('chart/home/bills','bills-chart') + googleBarChart('chart/home/budgets', 'budgets-chart'); + googleColumnChart('chart/home/categories', 'categories-chart'); + googlePieChart('chart/home/bills', 'bills-chart'); + getBoxAmounts(); +} + +function getBoxAmounts() { + var boxes = ['in', 'out','bills-unpaid','bills-paid']; + for (x in boxes) { + var box = boxes[x]; + $.getJSON('/json/box', {box: box}).success(function (data) { + "use strict"; + $('#box-' + data.box).html(data.amount); + }).fail(function () { + console.log('Failed to get box!') + }); + } } diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php deleted file mode 100644 index b0b406e2a7..0000000000 --- a/resources/views/app.blade.php +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - Laravel - - - - - - - - - - - - - - @yield('content') - - - - - - diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index 7ec53cefe4..dc7ac7fb86 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -17,6 +17,10 @@ @else + + @include('partials.boxes') + +
diff --git a/resources/views/partials/boxes.blade.php b/resources/views/partials/boxes.blade.php new file mode 100644 index 0000000000..58a9da0a77 --- /dev/null +++ b/resources/views/partials/boxes.blade.php @@ -0,0 +1,92 @@ + +
+
+
+
+
+
+ +
+
+
{{Amount::format(0,false)}}
+
Money out
+
+
+
+ + + +
+
+
+
+
+
+
+ +
+
+
{{Amount::format(0,false)}}
+
Money in
+
+
+
+ + + +
+
+
+
+
+
+
+ +
+
+
{{Amount::format(0,false)}}
+
Bills to pay
+
+
+
+ + + +
+
+
+
+
+
+
+ +
+
+
{{Amount::format(0,false)}}
+
Bills paid
+
+
+
+ + + +
+
+
+ \ No newline at end of file