diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php new file mode 100644 index 000000000000..315079f795db --- /dev/null +++ b/app/controllers/DashboardController.php @@ -0,0 +1,50 @@ += '.INVOICE_STATUS_SENT.' THEN 1 ELSE 0 END) invoices_sent, + COUNT(DISTINCT clients.id) active_clients'); + + $metrics = DB::table('clients') + ->select($select) + ->leftJoin('invoices', 'clients.id', '=', 'invoices.client_id') + ->where('clients.account_id', '=', Auth::user()->account_id) + ->where('clients.deleted_at', '=', null) + ->groupBy('clients.account_id') + ->first(); + + $invoiceAvg = DB::table('invoices') + ->where('invoices.account_id', '=', Auth::user()->account_id) + ->where('invoices.deleted_at', '=', null) + ->avg('amount'); + + + $activities = Activity::where('activities.account_id', '=', Auth::user()->account_id) + ->orderBy('created_at', 'desc')->take(6)->get(); + + $pastDue = Invoice::scope()->where('due_date', '<', date('Y-m-d')) + ->orderBy('due_date', 'asc')->take(6)->get(); + + $upcoming = Invoice::scope()->where('due_date', '>', date('Y-m-d')) + ->orderBy('due_date', 'asc')->take(6)->get(); + + $data = [ + 'totalIncome' => Utils::formatMoney($metrics->total_income, Session::get(SESSION_CURRENCY)), + 'billedClients' => $metrics->billed_clients, + 'invoicesSent' => $metrics->invoices_sent, + 'activeClients' => $metrics->active_clients, + 'invoiceAvg' => Utils::formatMoney($invoiceAvg, Session::get(SESSION_CURRENCY)), + 'activities' => $activities, + 'pastDue' => $pastDue, + 'upcoming' => $upcoming + ]; + + return View::make('dashboard', $data); + } + +} \ No newline at end of file diff --git a/app/database/migrations/2014_02_13_151500_add_cascase_drops.php b/app/database/migrations/2014_02_13_151500_add_cascase_drops.php new file mode 100644 index 000000000000..66d362317dfd --- /dev/null +++ b/app/database/migrations/2014_02_13_151500_add_cascase_drops.php @@ -0,0 +1,32 @@ +dropForeign('invoices_account_id_foreign'); + $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } + +} diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 98756ee1f7cb..51d49e756144 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -32,6 +32,11 @@ class Invoice extends EntityModel return $this->invoice_number; } + public function getLink() + { + return link_to('invoices/' . $this->public_id, $this->invoice_number); + } + public function getEntityType() { return ENTITY_INVOICE; diff --git a/app/ninja/repositories/InvoiceRepository.php b/app/ninja/repositories/InvoiceRepository.php index 443dfbfe2336..4f686fef2a0d 100755 --- a/app/ninja/repositories/InvoiceRepository.php +++ b/app/ninja/repositories/InvoiceRepository.php @@ -12,14 +12,14 @@ class InvoiceRepository { $query = \DB::table('invoices') ->join('clients', 'clients.id', '=','invoices.client_id') - ->join('invoice_statuses', 'invoice_statuses.id', '=', 'invoices.invoice_status_id') - ->join('contacts', 'contacts.client_id', '=', 'clients.id') - ->where('invoices.account_id', '=', $accountId) + ->join('invoice_statuses', 'invoice_statuses.id', '=', 'invoices.invoice_status_id') + ->join('contacts', 'contacts.client_id', '=', 'clients.id') + ->where('invoices.account_id', '=', $accountId) ->where('invoices.deleted_at', '=', null) ->where('clients.deleted_at', '=', null) ->where('invoices.is_recurring', '=', false) ->where('contacts.is_primary', '=', true) - ->select('clients.public_id as client_public_id', 'invoice_number', 'clients.name as client_name', 'invoices.public_id', 'amount', 'invoices.balance', 'invoice_date', 'due_date', 'invoice_statuses.name as invoice_status_name', 'clients.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email'); + ->select('clients.public_id as client_public_id', 'invoice_number', 'clients.name as client_name', 'invoices.public_id', 'amount', 'invoices.balance', 'invoice_date', 'due_date', 'invoice_statuses.name as invoice_status_name', 'clients.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email'); if ($clientPublicId) { diff --git a/app/routes.php b/app/routes.php index 7f5aeb0bf86d..f1c1b8a1de27 100755 --- a/app/routes.php +++ b/app/routes.php @@ -85,7 +85,7 @@ Route::get('logout', 'UserController@logout'); Route::group(array('before' => 'auth'), function() { - Route::get('home', function() { return View::make('header'); }); + Route::get('dashboard', 'DashboardController@index'); Route::get('account/getSearchData', array('as' => 'getSearchData', 'uses' => 'AccountController@getSearchData')); Route::get('account/{section?}', 'AccountController@showSection'); Route::post('account/{section?}', 'AccountController@doSection'); diff --git a/app/views/dashboard.blade.php b/app/views/dashboard.blade.php new file mode 100644 index 000000000000..56d68e8a1b31 --- /dev/null +++ b/app/views/dashboard.blade.php @@ -0,0 +1,141 @@ +@extends('header') + +@section('content') + +
+
+
+
+ +
+ {{ $totalIncome }} +
+
+ in total income +
+
+
+
+
+
+
+ +
+ {{ $billedClients }} +
+
+ {{ Utils::pluralize('billed client', $billedClients) }} +
+
+
+
+
+
+
+ +
+ {{ $invoicesSent }} +
+
+ {{ Utils::pluralize('invoice', $invoicesSent) }} sent +
+
+
+
+
+ + +

 

+ +
+
+
+
+

+ Notifications +

+
+
    + @foreach ($activities as $activity) +
  • + {{ Utils::timestampToDateTimeString(strtotime($activity->created_at)) }}: + {{ Utils::decodeActivity($activity->message) }} +
  • + @endforeach +
+
+
+
+
+
+

+ Invoices Past Due +

+
+
+ + + + + + + + + @foreach ($pastDue as $invoice) + + + + + + + @endforeach + +
Invoice #ClientDue dateBalance due
{{ $invoice->getLink() }}{{ $invoice->client->getDisplayName() }}{{ Utils::fromSqlDate($invoice->due_date) }}{{ Utils::formatMoney($invoice->balance, $invoice->client->currency_id) }}
+
+
+
+
+ +
+
+
+
+

+ Upcoming invoices +

+
+
+ + + + + + + + + @foreach ($upcoming as $invoice) + + + + + + + @endforeach + +
Invoice #ClientDue dateBalance due
{{ $invoice->getLink() }}{{ $invoice->client->getDisplayName() }}{{ Utils::fromSqlDate($invoice->due_date) }}{{ Utils::formatMoney($invoice->balance, $invoice->client->currency_id) }}
+
+
+
+
+
+
{{ $activeClients }}
+
{{ Utils::pluralize('active client', $activeClients) }}
+
+
+
average invoice
+
{{ $invoiceAvg }}
+
+
+
+ +@stop \ No newline at end of file diff --git a/app/views/header.blade.php b/app/views/header.blade.php index 330692d01f43..856bf022fbc8 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -77,12 +77,14 @@ - Invoice Ninja + + +