invoiceninja/app/Http/Controllers/DashboardController.php

68 lines
2.2 KiB
PHP
Raw Normal View History

2015-03-17 11:30:56 +10:00
<?php namespace App\Http\Controllers;
2016-08-15 16:43:26 +03:00
use stdClass;
2015-03-26 16:24:02 +10:00
use Auth;
2015-03-17 11:30:56 +10:00
use DB;
2015-03-26 16:24:02 +10:00
use View;
use App\Models\Invoice;
2015-07-29 22:55:12 +03:00
use App\Models\Payment;
2016-08-15 06:46:47 +03:00
use App\Ninja\Repositories\DashboardRepository;
2015-03-17 07:45:25 +10:00
/**
* Class DashboardController
*/
2015-03-26 16:24:02 +10:00
class DashboardController extends BaseController
2015-03-17 07:45:25 +10:00
{
2016-08-15 06:46:47 +03:00
public function __construct(DashboardRepository $dashboardRepo)
{
$this->dashboardRepo = $dashboardRepo;
}
/**
* @return \Illuminate\Contracts\View\View
*/
2015-03-17 07:45:25 +10:00
public function index()
{
2016-08-15 06:46:47 +03:00
$user = Auth::user();
$viewAll = $user->hasPermission('view_all');
$userId = $user->id;
$accountId = $user->account->id;
$dashboardRepo = $this->dashboardRepo;
$metrics = $dashboardRepo->totals($accountId, $userId, $viewAll);
$paidToDate = $dashboardRepo->paidToDate($accountId, $userId, $viewAll);
$averageInvoice = $dashboardRepo->averages($accountId, $userId, $viewAll);
$balances = $dashboardRepo->balances($accountId, $userId, $viewAll);
$activities = $dashboardRepo->activities($accountId, $userId, $viewAll);
$pastDue = $dashboardRepo->pastDue($accountId, $userId, $viewAll);
$upcoming = $dashboardRepo->upcoming($accountId, $userId, $viewAll);
$payments = $dashboardRepo->payments($accountId, $userId, $viewAll);
2015-03-17 07:45:25 +10:00
$hasQuotes = false;
foreach ([$upcoming, $pastDue] as $data) {
foreach ($data as $invoice) {
2016-05-26 17:56:54 +03:00
if ($invoice->invoice_type_id == INVOICE_TYPE_QUOTE) {
$hasQuotes = true;
}
}
}
2015-03-17 07:45:25 +10:00
$data = [
2016-08-15 06:46:47 +03:00
'account' => $user->account,
2015-08-20 18:09:04 +03:00
'paidToDate' => $paidToDate,
'balances' => $balances,
'averageInvoice' => $averageInvoice,
'invoicesSent' => $metrics ? $metrics->invoices_sent : 0,
'activeClients' => $metrics ? $metrics->active_clients : 0,
'activities' => $activities,
'pastDue' => $pastDue,
'upcoming' => $upcoming,
'payments' => $payments,
'title' => trans('texts.dashboard'),
'hasQuotes' => $hasQuotes,
2015-08-20 18:09:04 +03:00
];
2015-03-17 07:45:25 +10:00
return View::make('dashboard', $data);
}
}