From 470e0bf06e838af84b5646fbb293c548152e8d52 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 29 Nov 2013 14:09:21 +0200 Subject: [PATCH] Implemented the view client screen --- app/controllers/ActivityController.php | 21 +++++ app/controllers/ClientController.php | 6 +- app/controllers/InvoiceController.php | 37 ++++++--- app/controllers/PaymentController.php | 20 +++-- ...11_05_180133_confide_setup_users_table.php | 1 + app/libraries/entity.php | 8 ++ app/models/Client.php | 52 ++++++++++++ app/models/Contact.php | 29 ++++++- app/routes.php | 56 ++++++++++++- app/start/global.php | 1 + app/views/accounts/details.blade.php | 50 ++++++----- app/views/clients/edit.blade.php | 74 +++++++++-------- app/views/clients/show.blade.php | 82 ++++++++++++++++++- app/views/header.blade.php | 30 +++++-- app/views/invoices/index.blade.php | 2 +- 15 files changed, 382 insertions(+), 87 deletions(-) create mode 100755 app/controllers/ActivityController.php create mode 100644 app/libraries/entity.php diff --git a/app/controllers/ActivityController.php b/app/controllers/ActivityController.php new file mode 100755 index 000000000000..cf1bc4fe97cb --- /dev/null +++ b/app/controllers/ActivityController.php @@ -0,0 +1,21 @@ +account_id) + ->where('client_id','=',$clientId)->get()) + ->addColumn('date', function($model) + { + return $model->created_at->format('m/d/y h:i a'); + }) + ->addColumn('message', function($model) + { + return $model->message; + }) + ->orderColumns('date') + ->make(); + } + +} \ No newline at end of file diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index 655b9223cef7..e9ad390df2f9 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -79,7 +79,10 @@ class ClientController extends \BaseController { */ public function show($id) { - $client = Client::find($id); + $client = Client::with('contacts')->find($id); + trackViewed(Request::url(), $client->name); + + return View::make('clients.show')->with('client', $client); } @@ -128,6 +131,7 @@ class ClientController extends \BaseController { $client = Client::find($id); } else { $client = new Client; + $client->account_id = Auth::user()->account_id; } $client->name = Input::get('name'); diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index f0edded2ee80..c22efbd09d0e 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -13,18 +13,28 @@ class InvoiceController extends \BaseController { return View::make('invoices.index'); } - public function getDatatable() + public function getDatatable($clientId = null) { - return Datatable::collection(Invoice::with('client','invoice_items')->where('account_id','=',Auth::user()->account_id)->get()) - ->addColumn('number', function($model) - { - return link_to('invoices/' . $model->id . '/edit', $model->invoice_number); - }) - ->addColumn('client', function($model) - { - return link_to('clients/' . $model->client->id, $model->client->name); - }) - ->addColumn('amount', function($model) + $collection = Invoice::with('client','invoice_items')->where('account_id','=',Auth::user()->account_id); + + if ($clientId) { + $collection->where('client_id','=',$clientId); + } + + $table = Datatable::collection($collection->get())->addColumn('number', function($model) + { + return link_to('invoices/' . $model->id . '/edit', $model->invoice_number); + }); + + if (!$clientId) + { + $table->addColumn('client', function($model) { + return link_to('clients/' . $model->client->id, $model->client->name); + }); + + } + + return $table->addColumn('amount', function($model) { return '$' . money_format('%i', $model->getTotal()); }) @@ -33,7 +43,7 @@ class InvoiceController extends \BaseController { return $model->created_at->format('m/d/y h:i a'); }) ->orderColumns('number') - ->make(); + ->make(); } @@ -176,7 +186,8 @@ class InvoiceController extends \BaseController { public function edit($id) { $invoice = Invoice::with('client', 'invoice_items')->find($id); - + trackViewed(Request::url(), $invoice->invoice_number . ' - ' . $invoice->client->name); + $data = array( 'invoice' => $invoice, 'method' => 'PUT', diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index 8188731dc8d0..bff7f8a0c151 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -7,14 +7,24 @@ class PaymentController extends \BaseController return View::make('payments.index'); } - public function getDatatable() + public function getDatatable($clientId = null) { - return Datatable::collection(Payment::with('invoice.client')->where('account_id', '=', Auth::user()->account_id)->get()) - ->addColumn('client', function($model) + $collection = Payment::with('invoice.client')->where('account_id', '=', Auth::user()->account_id); + + if ($clientId) { + $collection->where('client_id','=',$clientId); + } + + $table = Datatable::collection($collection->get()); + + if (!$clientId) { + $table->addColumn('client', function($model) { return link_to('clients/' . $model->invoice->client->id, $model->invoice->client->name); - }) - ->addColumn('invoice', function($model) + }); + } + + return $table->addColumn('invoice', function($model) { return link_to('invoices/' . $model->invoice->id . '/edit', $model->invoice->number); }) diff --git a/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php b/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php index 2151a838eaec..2604ee9500de 100755 --- a/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php +++ b/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php @@ -195,6 +195,7 @@ class ConfideSetupUsersTable extends Migration { $t->increments('id'); $t->integer('invoice_id'); $t->integer('account_id'); + $t->integer('client_id'); $t->integer('contact_id'); $t->integer('user_id'); $t->timestamps(); diff --git a/app/libraries/entity.php b/app/libraries/entity.php new file mode 100644 index 000000000000..57e447e2e271 --- /dev/null +++ b/app/libraries/entity.php @@ -0,0 +1,8 @@ +hasMany('Contact'); } + + public function getAddress() + { + $str = ''; + + if ($this->address1) { + $str .= $this->address1 . '
'; + } + if ($this->address2) { + $str .= $this->address2 . '
'; + } + if ($this->city) { + $str .= $this->city . ', '; + } + if ($this->state) { + $str .= $this->state . ' '; + } + if ($this->postal_code) { + $str .= $this->postal_code; + } + + if ($str) + { + $str = '

' . $str . '

'; + } + + return $str; + } + + public function getPhone() + { + $str = ''; + + if ($this->work_phone) + { + $str .= '' . $this->work_phone; + } + + return $str; + } + + public function getNotes() + { + $str = ''; + + if ($this->notes) + { + $str .= '' . $this->notes . ''; + } + + return $str; + } } Client::created(function($client) diff --git a/app/models/Contact.php b/app/models/Contact.php index a3424d23a53b..4d37619afb38 100755 --- a/app/models/Contact.php +++ b/app/models/Contact.php @@ -32,11 +32,38 @@ class Contact extends Eloquent if ($fullName == ' ') { - return "Unknown"; + return 'Guest'; } else { return $fullName; } } + + public function getDetails() + { + $str = ''; + + if ($this->first_name || $this->last_name) + { + $str .= '' . $this->first_name . ' ' . $this->last_name . '
'; + } + + if ($this->email) + { + $str .= '' . HTML::mailto($this->email, $this->email) . '
'; + } + + if ($this->phone) + { + $str .= '' . $this->phone; + } + + if ($str) + { + $str = '

' . $str . '

'; + } + + return $str; + } } \ No newline at end of file diff --git a/app/routes.php b/app/routes.php index 54f9ef9efbf3..e256e699d091 100755 --- a/app/routes.php +++ b/app/routes.php @@ -39,15 +39,17 @@ Route::group(array('before' => array('auth', 'csrf')), function() Route::get('api/clients', array('as'=>'api.clients', 'uses'=>'ClientController@getDatatable')); Route::resource('invoices', 'InvoiceController'); - Route::get('api/invoices', array('as'=>'api.invoices', 'uses'=>'InvoiceController@getDatatable')); + Route::get('api/invoices/{client_id?}', array('as'=>'api.invoices', 'uses'=>'InvoiceController@getDatatable')); Route::get('invoices/create/{client_id}', 'InvoiceController@create'); Route::get('payments', 'PaymentController@index'); - Route::get('api/payments', array('as'=>'api.payments', 'uses'=>'PaymentController@getDatatable')); + Route::get('api/payments/{client_id?}', array('as'=>'api.payments', 'uses'=>'PaymentController@getDatatable')); Route::get('home', function() { return View::make('header'); }); Route::get('reports', function() { return View::make('header'); }); Route::get('payments/create', function() { return View::make('header'); }); + + Route::get('api/activities/{client_id?}', array('as'=>'api.activities', 'uses'=>'ActivityController@getDatatable')); }); // Confide routes @@ -65,9 +67,14 @@ Route::get('logout', 'UserController@logout'); -HTML::macro('nav_link', function($url, $text, $url2 = '') { +HTML::macro('nav_link', function($url, $text, $url2 = '', $extra = '') { $class = ( Request::is($url) || Request::is($url.'/*') || Request::is($url2) ) ? ' class="active"' : ''; - return ''.$text.''; + return ''.$text.''; +}); + +HTML::macro('tab_link', function($url, $text, $active = false) { + $class = $active ? ' class="active"' : ''; + return ''.$text.''; }); HTML::macro('menu_link', function($type) { @@ -131,10 +138,51 @@ function processedRequest($url) Session::put('_token', md5(microtime())); } + + +function trackViewed($url, $name) +{ + $viewed = Session::get(RECENTLY_VIEWED); + + if (!$viewed) + { + $viewed = []; + } + + $object = new stdClass; + $object->url = $url; + $object->name = $name; + + for ($i=0; $iurl == $item->url) + { + array_splice($viewed, $i, 1); + } + } + + array_unshift($viewed, $object); + + if (count($viewed) > 5) + { + array_pop($viewed); + } + + Session::put(RECENTLY_VIEWED, $viewed); +} + + define("ENV_DEVELOPMENT", "local"); define("ENV_STAGING", "staging"); define("ENV_PRODUCTION", "production"); +define("RECENTLY_VIEWED", "RECENTLY_VIEWED"); +define("ENTITY_CLIENT", "Client"); +define("ENTITY_INVOICE", "Invoice"); +define("ENTITY_PAYMENT", "Payment"); + define("ACCOUNT_DETAILS", "details"); define("ACCOUNT_SETTINGS", "settings"); define("ACCOUNT_IMPORT", "import"); diff --git a/app/start/global.php b/app/start/global.php index 7697a6be4989..05f422745ba4 100755 --- a/app/start/global.php +++ b/app/start/global.php @@ -17,6 +17,7 @@ ClassLoader::addDirectories(array( app_path().'/controllers', app_path().'/models', app_path().'/database/seeds', + app_path().'/libraries', )); diff --git a/app/views/accounts/details.blade.php b/app/views/accounts/details.blade.php index 11c073358a5d..ad43e3835cdc 100755 --- a/app/views/accounts/details.blade.php +++ b/app/views/accounts/details.blade.php @@ -24,33 +24,41 @@ @endif {{ Former::populateField('phone', $account->users()->first()->phone) }} - {{ Former::legend('Account') }} - {{ Former::text('name') }} +
+
- {{ Former::file('logo')->max(2, 'MB')->accept('image')->wrap('test') }} + {{ Former::legend('Account') }} + {{ Former::text('name') }} - @if (file_exists($account->getLogoPath())) -
- {{ HTML::image($account->getLogoPath(), "Logo") }} -
- @endif + {{ Former::file('logo')->max(2, 'MB')->accept('image')->wrap('test') }} - {{ Former::legend('Users') }} - {{ Former::text('first_name') }} - {{ Former::text('last_name') }} - {{ Former::text('email')->label('Email/Username') }} - {{ Former::text('phone') }} + @if (file_exists($account->getLogoPath())) +
+ {{ HTML::image($account->getLogoPath(), "Logo") }} +
+ @endif + {{ Former::legend('Address') }} + {{ Former::text('address1')->label('Street') }} + {{ Former::text('address2')->label('Apt/Floor') }} + {{ Former::text('city') }} + {{ Former::text('state') }} + {{ Former::text('postal_code') }} + {{ Former::select('country_id')->addOption('','')->label('Country') + ->fromQuery($countries, 'name', 'id')->select($account ? $account->country_id : '') }} + +
- {{ Former::legend('Address') }} - {{ Former::text('address1')->label('Street') }} - {{ Former::text('address2')->label('Apt/Floor') }} - {{ Former::text('city') }} - {{ Former::text('state') }} - {{ Former::text('postal_code') }} - {{ Former::select('country_id')->addOption('','')->label('Country') - ->fromQuery($countries, 'name', 'id')->select($account ? $account->country_id : '') }} +
+ {{ Former::legend('Users') }} + {{ Former::text('first_name') }} + {{ Former::text('last_name') }} + {{ Former::text('email')->label('Email/Username') }} + {{ Former::text('phone') }} +
+
+ {{ Former::actions( Button::lg_primary_submit('Save') ) }} {{ Former::close() }} diff --git a/app/views/clients/edit.blade.php b/app/views/clients/edit.blade.php index 71f862a9de21..7a4aadf8db4a 100755 --- a/app/views/clients/edit.blade.php +++ b/app/views/clients/edit.blade.php @@ -20,43 +20,53 @@ @endif - {{ Former::legend('Organization') }} - {{ Former::text('name') }} - {{ Former::text('work_phone')->label('Phone') }} - {{ Former::textarea('notes') }} +
+
+ + {{ Former::legend('Organization') }} + {{ Former::text('name') }} + {{ Former::text('work_phone')->label('Phone') }} + {{ Former::textarea('notes') }} + + + {{ Former::legend('Address') }} + {{ Former::text('address1')->label('Street') }} + {{ Former::text('address2')->label('Apt/Floor') }} + {{ Former::text('city') }} + {{ Former::text('state') }} + {{ Former::text('postal_code') }} + {{ Former::select('country_id')->addOption('','')->label('Country') + ->fromQuery($countries, 'name', 'id')->select($client ? $client->country_id : '') }} - {{ Former::legend('Contacts') }} -
- {{ Former::hidden('id')->data_bind("value: id, valueUpdate: 'afterkeydown'") }} - {{ Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown'") }} - {{ Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown'") }} - {{ Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown'") }} - {{ Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown'") }} -
-
- - {{ link_to('#', 'Remove contact', array('data-bind'=>'click: $parent.removeContact')) }} - - - {{ link_to('#', 'Add contact', array('onclick'=>'return addContact()')) }} - -
-
+
+ {{ Former::legend('Contacts') }} +
+ {{ Former::hidden('id')->data_bind("value: id, valueUpdate: 'afterkeydown'") }} + {{ Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown'") }} + {{ Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown'") }} + {{ Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown'") }} + {{ Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown'") }} + +
+
+ + {{ link_to('#', 'Remove contact', array('data-bind'=>'click: $parent.removeContact')) }} + + + {{ link_to('#', 'Add contact', array('onclick'=>'return addContact()')) }} + +
+
+ +
+ +
- - {{ Former::legend('Address') }} - {{ Former::text('address1')->label('Street') }} - {{ Former::text('address2')->label('Apt/Floor') }} - {{ Former::text('city') }} - {{ Former::text('state') }} - {{ Former::text('postal_code') }} - {{ Former::select('country_id')->addOption('','')->label('Country') - ->fromQuery($countries, 'name', 'id')->select($client ? $client->country_id : '') }} {{ Former::hidden('data')->data_bind("value: ko.toJSON(model)") }} diff --git a/app/views/clients/show.blade.php b/app/views/clients/show.blade.php index ccf4fbaba62e..dbb2137125c9 100755 --- a/app/views/clients/show.blade.php +++ b/app/views/clients/show.blade.php @@ -1,14 +1,88 @@ @extends('header') @section('content') - -

View Client

- - {{ $client->name }} +
{{ Button::link(URL::to('clients/' . $client->id . '/edit'), 'Edit Client') }} {{ Button::primary_link(URL::to('invoices/create/' . $client->id), 'Create Invoice') }}
+

{{ $client->name }}

+ +
+ +
+

Details

+

{{ $client->getAddress() }}

+

{{ $client->getPhone() }}

+

{{ $client->getNotes() }}

+
+ +
+

Contacts

+ @foreach ($client->contacts as $contact) + {{ $contact->getDetails() }} + @endforeach +
+ +
+

Balance

+

$0.00 Paid to Date USD

+

$0.00 Outstanding USD

+
+
+ +

 

+ + + +
+ +
+ + {{ Datatable::table() + ->addColumn('Date', 'Message') + ->setUrl(url('api/activities/'. $client->id)) + ->setOptions('sPaginationType', 'bootstrap') + ->setOptions('bFilter', false) + ->render() }} + +
+ +
+ + {{ Datatable::table() + ->addColumn('Invoice Number', 'Amount', 'Date') + ->setUrl(url('api/invoices/' . $client->id)) + ->setOptions('sPaginationType', 'bootstrap') + ->setOptions('bFilter', false) + ->render() }} + +
+
+ + + {{ Datatable::table() + ->addColumn('Invoice Number', 'Amount', 'Date') + ->setUrl(url('api/payments/' . $client->id)) + ->setOptions('sPaginationType', 'bootstrap') + ->setOptions('bFilter', false) + ->render() }} + +
+
+ + + @stop \ No newline at end of file diff --git a/app/views/header.blade.php b/app/views/header.blade.php index 6c9bb45b1345..cd19d1e89248 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -23,12 +23,13 @@ --> - + + {{-- Basset::show('bootstrapper.css') --}} - {{ Basset::show('bootstrapper.js') }} + {{-- Basset::show('bootstrapper.js') --}} @@ -61,7 +62,7 @@ body > div.container { - max-width: 850px; + /*max-width: 850px;*/ } label.control-label { @@ -69,6 +70,11 @@ } + div.panel { + padding-left: 0px !important; + padding-right: 0px !important; + } + .form-actions { margin: 0; background-color: transparent; @@ -233,7 +239,7 @@

- LOGO + Invoice Ninja
Logged in as Guest (Sign up) | {{ link_to('account/details', 'My Account') }}

This is a sample site, the data is erased

@@ -261,11 +267,25 @@ {{ HTML::menu_link('payment') }} {{-- HTML::nav_link('reports', 'Reports') --}} -
diff --git a/app/views/invoices/index.blade.php b/app/views/invoices/index.blade.php index 302b373ac715..11b469c94f1d 100755 --- a/app/views/invoices/index.blade.php +++ b/app/views/invoices/index.blade.php @@ -5,7 +5,7 @@ {{ Button::primary_link(URL::to('invoices/create'), 'New Invoice', array('class' => 'pull-right')) }} {{ Datatable::table() - ->addColumn('Number', 'Client', 'Amount', 'Date') + ->addColumn('Invoice Number', 'Client', 'Amount', 'Date') ->setUrl(route('api.invoices')) ->setOptions('sPaginationType', 'bootstrap') ->setOptions('bFilter', false)