1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 17:31:35 +02:00
invoiceninja/app/Http/Controllers/DashboardController.php

67 lines
2.2 KiB
PHP
Raw Normal View History

2015-03-17 02:30:56 +01:00
<?php namespace App\Http\Controllers;
2015-03-26 07:24:02 +01:00
use Auth;
2015-03-17 02:30:56 +01:00
use DB;
2015-03-26 07:24:02 +01:00
use View;
use App\Models\Invoice;
2015-07-29 21:55:12 +02:00
use App\Models\Payment;
2016-08-15 05:46:47 +02:00
use App\Ninja\Repositories\DashboardRepository;
2015-03-16 22:45:25 +01:00
/**
* Class DashboardController
*/
2015-03-26 07:24:02 +01:00
class DashboardController extends BaseController
2015-03-16 22:45:25 +01:00
{
2016-08-15 05:46:47 +02:00
public function __construct(DashboardRepository $dashboardRepo)
{
$this->dashboardRepo = $dashboardRepo;
}
/**
* @return \Illuminate\Contracts\View\View
*/
2015-03-16 22:45:25 +01:00
public function index()
{
2016-08-15 05:46:47 +02: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-16 22:45:25 +01:00
$hasQuotes = false;
foreach ([$upcoming, $pastDue] as $data) {
foreach ($data as $invoice) {
2016-05-26 16:56:54 +02:00
if ($invoice->invoice_type_id == INVOICE_TYPE_QUOTE) {
$hasQuotes = true;
}
}
}
2015-03-16 22:45:25 +01:00
$data = [
2016-08-15 05:46:47 +02:00
'account' => $user->account,
2015-08-20 17:09:04 +02: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 17:09:04 +02:00
];
2015-03-16 22:45:25 +01:00
return View::make('dashboard', $data);
}
}