diff --git a/app/config/app.php b/app/config/app.php index 494293a5cf6b..90d2aeec0f81 100755 --- a/app/config/app.php +++ b/app/config/app.php @@ -216,5 +216,6 @@ return array( 'CreditCard' => 'Omnipay\Common\CreditCard', 'Image' => 'Intervention\Image\Facades\Image', 'Countries' => 'Webpatser\Countries\CountriesFacade', + 'Carbon' => 'Carbon\Carbon', ), ); \ No newline at end of file diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index e9ad390df2f9..21f2d28a4a3f 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -12,12 +12,19 @@ class ClientController extends \BaseController { //$clients = Client::orderBy('name')->get(); //return View::make('clients.index')->with('clients', $clients); - return View::make('clients.index'); + return View::make('list', array( + 'entityType'=>ENTITY_CLIENT, + 'columns'=>['checkbox', 'Client', 'Contact', 'Balance', 'Last Login', 'Date Created', 'Email', 'Phone'] + )); } public function getDatatable() { return Datatable::collection(Client::with('contacts')->where('account_id','=',Auth::user()->account_id)->get()) + ->addColumn('checkbox', function($model) + { + return ''; + }) ->addColumn('name', function($model) { //return $model->name; @@ -27,9 +34,17 @@ class ClientController extends \BaseController { { return $model->contacts[0]->getFullName(); }) + ->addColumn('balance', function($model) + { + return '$' . $model->balance; + }) ->addColumn('last_login', function($model) { - return $model->contacts[0]->lastLogin(); + return $model->contacts[0]->getLastLogin(); + }) + ->addColumn('date_created', function($model) + { + return $model->getDateCreated(); }) ->addColumn('email', function($model) { @@ -183,18 +198,27 @@ class ClientController extends \BaseController { } /** - * Remove the specified resource from storage. + * Bulk update the records * - * @param int $id * @return Response */ - public function destroy($id) + public function bulk() { - $client = Client::find($id); - $client->delete(); + $action = Input::get('action'); + $ids = Input::get('ids'); + $clients = Client::find($ids); + + foreach ($clients as $client) { + if ($action == 'archive') { + $client->delete(); + } else if ($action == 'delete') { + $client->forceDelete(); + } + } + + $message = pluralize('Successfully '.$action.'d ? client', count($ids)); + Session::flash('message', $message); - // redirect - Session::flash('message', 'Successfully deleted the client'); return Redirect::to('clients'); } } \ No newline at end of file diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index c22efbd09d0e..d5680fbb8fea 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -10,21 +10,29 @@ class InvoiceController extends \BaseController { public function index() { //$invoices = Invoice::with('client')->orderBy('created_at', 'DESC')->get(); - return View::make('invoices.index'); + //return View::make('invoices.index'); + return View::make('list', array( + 'entityType'=>ENTITY_INVOICE, + 'columns'=>['checkbox', 'Invoice Number', 'Client', 'Total', 'Amount Due', 'Invoice Date', 'Due Date', 'Status'] + )); } public function getDatatable($clientId = null) { - $collection = Invoice::with('client','invoice_items')->where('account_id','=',Auth::user()->account_id); + $collection = Invoice::with('client','invoice_items','invoice_status')->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); - }); + $table = Datatable::collection($collection->get())->addColumn('checkbox', function($model) + { + return ''; + }) + ->addColumn('invoice_number', function($model) + { + return link_to('invoices/' . $model->id . '/edit', $model->invoice_number); + }); if (!$clientId) { @@ -34,13 +42,25 @@ class InvoiceController extends \BaseController { } - return $table->addColumn('amount', function($model) + return $table->addColumn('total', function($model) { return '$' . money_format('%i', $model->getTotal()); }) - ->addColumn('date', function($model) + ->addColumn('amount_due', function($model) { - return $model->created_at->format('m/d/y h:i a'); + return '$' . money_format('%i', $model->getTotal()); + }) + ->addColumn('invoice_date', function($model) + { + return (new Carbon($model->invoice_date))->toFormattedDateString(); + }) + ->addColumn('due_date', function($model) + { + return $model->due_date == '0000-00-00' ? '' : (new Carbon($model->due_date))->toFormattedDateString(); + }) + ->addColumn('status', function($model) + { + return $model->invoice_status->name; }) ->orderColumns('number') ->make(); @@ -375,13 +395,23 @@ class InvoiceController extends \BaseController { * @param int $id * @return Response */ - public function destroy($id) + public function bulk() { - $invoice = Invoice::find($id); - $invoice->delete(); + $action = Input::get('action'); + $ids = Input::get('ids'); + $invoices = Invoice::find($ids); + + foreach ($invoices as $invoice) { + if ($action == 'archive') { + $invoice->delete(); + } else if ($action == 'delete') { + $invoice->forceDelete(); + } + } + + $message = pluralize('Successfully '.$action.'d ? invoice', count($ids)); + Session::flash('message', $message); - // redirect - Session::flash('message', 'Successfully deleted the invoice'); return Redirect::to('invoices'); } } \ No newline at end of file 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 2604ee9500de..031b78a6e189 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 @@ -10,6 +10,7 @@ class ConfideSetupUsersTable extends Migration { */ public function up() { + Schema::dropIfExists('invoice_statuses'); Schema::dropIfExists('invitations'); Schema::dropIfExists('activities'); Schema::dropIfExists('account_gateways'); @@ -110,7 +111,7 @@ class ConfideSetupUsersTable extends Migration { $t->integer('country_id'); $t->string('work_phone'); $t->text('notes'); - + $t->decimal('balance', 10, 2); //$t->foreign('account_id')->references('id')->on('accounts'); }); @@ -136,6 +137,7 @@ class ConfideSetupUsersTable extends Migration { $t->increments('id'); $t->integer('client_id'); $t->integer('account_id'); + $t->integer('invoice_status_id')->default(1); $t->timestamps(); $t->softDeletes(); @@ -147,6 +149,12 @@ class ConfideSetupUsersTable extends Migration { //$t->foreign('account_id')->references('id')->on('accounts'); }); + Schema::create('invoice_statuses', function($t) + { + $t->increments('id'); + $t->string('name'); + }); + Schema::create('invitations', function($t) { @@ -232,6 +240,7 @@ class ConfideSetupUsersTable extends Migration { */ public function down() { + Schema::dropIfExists('invoice_statuses'); Schema::dropIfExists('invitations'); Schema::dropIfExists('activities'); Schema::dropIfExists('account_gateways'); diff --git a/app/database/seeds/ConstantsSeeder.php b/app/database/seeds/ConstantsSeeder.php index 0651c122f887..9dbcbc6de2de 100755 --- a/app/database/seeds/ConstantsSeeder.php +++ b/app/database/seeds/ConstantsSeeder.php @@ -5,8 +5,39 @@ class ConstantsSeeder extends Seeder public function run() { - DB::table('gateways')->delete(); + // TEST DATA + /* + $contact = new Contact; + $contact->first_name = 'Hillel'; + $contact->last_name = 'Hillel'; + $contact->email = 'hillelcoren@gmail.com'; + $contact->last_name = '2125551234'; + $client->contacts()->save($contact); + $invoice = new Invoice; + $invoice->invoice_number = '0001'; + $client->invoices()->save($invoice); + + $invoice = new Invoice; + $invoice->invoice_number = '0002'; + $client->invoices()->save($invoice); + + $invoice = new Invoice; + $invoice->invoice_number = '0003'; + $client->invoices()->save($invoice); + + $invoice = new Invoice; + $invoice->invoice_number = '0004'; + $client->invoices()->save($invoice); + */ + + + InvoiceStatus::create(array('name' => 'Draft')); + InvoiceStatus::create(array('name' => 'Sent')); + InvoiceStatus::create(array('name' => 'Viewed')); + InvoiceStatus::create(array('name' => 'Partial')); + InvoiceStatus::create(array('name' => 'Paid')); + $gateways = [ array('name'=>'Authorize.Net AIM', 'provider'=>'AuthorizeNet_AIM'), array('name'=>'Authorize.Net SIM', 'provider'=>'AuthorizeNet_SIM'), diff --git a/app/filters.php b/app/filters.php index efb311bd434a..e6e99d3d6b7e 100755 --- a/app/filters.php +++ b/app/filters.php @@ -81,11 +81,14 @@ Route::filter('csrf', function() $tokenInput = Input::get('_token'); $tokenSession = Session::token(); + /* if ($url = Session::get($tokenInput)) { return Redirect::to($url); } - else if ($tokenSession != $tokenInput) + */ + + if ($tokenSession != $tokenInput) { throw new Illuminate\Session\TokenMismatchException; } diff --git a/app/models/Activity.php b/app/models/Activity.php index adc9310de8c6..1ca78a9afcd2 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -22,12 +22,12 @@ class Activity extends Eloquent } public static function createClient($client) - { + { $activity = Activity::getBlank(); $activity->client_id = $client->id; $activity->activity_type_id = ACTIVITY_TYPE_CREATE_CLIENT; $activity->message = Auth::user()->getFullName() . ' created client ' . $client->name; - $activity->save(); + $activity->save(); } public static function archiveClient($client) diff --git a/app/models/Client.php b/app/models/Client.php index 0db799cd0cae..37c5d3927de4 100755 --- a/app/models/Client.php +++ b/app/models/Client.php @@ -79,6 +79,19 @@ class Client extends Eloquent return $str; } + + public function getDateCreated() + { + if ($this->created_at == '0000-00-00 00:00:00') + { + return '---'; + } + else + { + return $this->created_at->format('m/d/y h:i a'); + } + } + } Client::created(function($client) diff --git a/app/models/Contact.php b/app/models/Contact.php index 4d37619afb38..ddcaafa9dfda 100755 --- a/app/models/Contact.php +++ b/app/models/Contact.php @@ -14,7 +14,7 @@ class Contact extends Eloquent return $this->belongsTo('Client'); } - public function lastLogin() + public function getLastLogin() { if ($this->last_login == '0000-00-00 00:00:00') { @@ -22,7 +22,7 @@ class Contact extends Eloquent } else { - return $this->last_login; + return $this->last_login->format('m/d/y h:i a'); } } diff --git a/app/models/Invoice.php b/app/models/Invoice.php index f7e302772123..af3919dc656f 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -14,6 +14,11 @@ class Invoice extends Eloquent return $this->hasMany('InvoiceItem'); } + public function invoice_status() + { + return $this->belongsTo('InvoiceStatus'); + } + public function getTotal() { $total = 0; diff --git a/app/models/InvoiceStatus.php b/app/models/InvoiceStatus.php new file mode 100755 index 000000000000..45f123aeee9d --- /dev/null +++ b/app/models/InvoiceStatus.php @@ -0,0 +1,6 @@ + array('auth', 'csrf')), function() Route::resource('clients', 'ClientController'); Route::get('api/clients', array('as'=>'api.clients', 'uses'=>'ClientController@getDatatable')); + Route::post('clients/bulk', 'ClientController@bulk'); Route::resource('invoices', 'InvoiceController'); Route::get('api/invoices/{client_id?}', array('as'=>'api.invoices', 'uses'=>'InvoiceController@getDatatable')); Route::get('invoices/create/{client_id}', 'InvoiceController@create'); + Route::post('invoices/bulk', 'InvoiceController@bulk'); Route::get('payments', 'PaymentController@index'); Route::get('api/payments/{client_id?}', array('as'=>'api.payments', 'uses'=>'PaymentController@getDatatable')); + Route::post('payments/bulk', 'PaymentController@bulk'); Route::get('home', function() { return View::make('header'); }); Route::get('reports', function() { return View::make('header'); }); @@ -179,9 +182,9 @@ 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("ENTITY_CLIENT", "client"); +define("ENTITY_INVOICE", "invoice"); +define("ENTITY_PAYMENT", "payment"); define("ACCOUNT_DETAILS", "details"); define("ACCOUNT_SETTINGS", "settings"); diff --git a/app/views/clients/index.blade.php b/app/views/clients/index.blade.php index 23b88a8c1ff9..899fde962209 100755 --- a/app/views/clients/index.blade.php +++ b/app/views/clients/index.blade.php @@ -5,7 +5,7 @@ {{ Button::primary_link(URL::to('clients/create'), 'New Client', array('class' => 'pull-right')) }} {{ Datatable::table() - ->addColumn('Client', 'Contact', 'Last Login', 'Email', 'Phone') + ->addColumn('Client', 'Contact', 'Balance', 'Last Login', 'Date Created', 'Email', 'Phone') ->setUrl(route('api.clients')) ->setOptions('sPaginationType', 'bootstrap') ->setOptions('bFilter', false) diff --git a/app/views/datatable.blade.php b/app/views/datatable.blade.php new file mode 100755 index 000000000000..0dfcdfe0702d --- /dev/null +++ b/app/views/datatable.blade.php @@ -0,0 +1,55 @@ + + + @for ($i = 0; $i < count($columns); $i++) + + @endfor + + + + @foreach($columns as $i => $c) + + @endforeach + + + + @foreach($data as $d) + + @foreach($d as $dd) + + @endforeach + + @endforeach + +
+ @if ($c == 'checkbox' && $haeCheckboxes = true) + + @else + {{ $c }} + @endif +
{{ $dd }}
+ \ No newline at end of file diff --git a/app/views/header.blade.php b/app/views/header.blade.php index cd19d1e89248..a936aef855f7 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -37,7 +37,6 @@ - @@ -51,13 +50,6 @@ - - -