From 75b1350808c004694864a0d48bb6cd4487ba75c2 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 8 Jan 2014 20:09:47 +0000 Subject: [PATCH] bug fixes --- README.md | 2 +- app/config/packages/zizaco/confide/config.php | 4 +- app/controllers/ActivityController.php | 2 +- app/controllers/ClientController.php | 2 + app/controllers/HomeController.php | 5 ++ app/controllers/UserController.php | 4 +- app/libraries/utils.php | 27 ++++++++ app/models/Activity.php | 31 +++++---- app/models/Client.php | 5 +- app/models/Country.php | 3 + app/models/Credit.php | 2 +- app/models/EntityModel.php | 14 ++++ app/models/Frequency.php | 1 + app/models/Gateway.php | 3 +- app/models/Industry.php | 2 + app/models/InvoiceStatus.php | 1 + app/models/Payment.php | 1 - app/models/Size.php | 1 + app/models/Timezone.php | 1 + app/models/User.php | 12 ++++ app/ninja/repositories/ClientRepository.php | 2 + app/ninja/repositories/InvoiceRepository.php | 7 ++ app/routes.php | 10 +-- app/views/coming_soon.blade.php | 35 ++++++++++ app/views/datatable.blade.php | 2 +- app/views/header.blade.php | 3 +- app/views/invoices/edit.blade.php | 69 +++++++++++++++---- app/views/master.blade.php | 2 +- public/css/style.css | 6 +- 29 files changed, 212 insertions(+), 47 deletions(-) create mode 100755 app/views/coming_soon.blade.php diff --git a/README.md b/README.md index 3e58e69292d3..58d501e02ead 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Invoice Ninja ## Simple, Intuitive Invoicing -### Live demo: [http://invoiceninja.eu1.frbit.net](http://invoiceninja.eu1.frbit.net) +### Live demo: [http://www.invoiceninja.com](http://www.invoiceninja.com) ### Introduction Most online invoicing sites are expensive. They shouldn't be. The aim of this project is to provide a free, open-source alternative. Additionally, the hope is this codebase will serve as a sample site for Laravel as well as other JavaScript technologies. diff --git a/app/config/packages/zizaco/confide/config.php b/app/config/packages/zizaco/confide/config.php index fc965a952af9..21cc78fec664 100755 --- a/app/config/packages/zizaco/confide/config.php +++ b/app/config/packages/zizaco/confide/config.php @@ -111,7 +111,7 @@ return array( | table, otherwise they will not be able to login after the payment. | */ - 'signup_email' => false, - 'signup_confirm' => false, + 'signup_email' => true, + 'signup_confirm' => true, ); diff --git a/app/controllers/ActivityController.php b/app/controllers/ActivityController.php index cd341d273d01..11377ff5c181 100755 --- a/app/controllers/ActivityController.php +++ b/app/controllers/ActivityController.php @@ -12,7 +12,7 @@ class ActivityController extends \BaseController { return Datatable::query($query) ->addColumn('created_at', function($model) { return Utils::timestampToDateTimeString(strtotime($model->created_at)); }) - ->addColumn('message', function($model) { return $model->message; }) + ->addColumn('message', function($model) { return Utils::decodeActivity($model->message); }) ->addColumn('balance', function($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) ->addColumn('adjustment', function($model) { return $model->adjustment != 0 ? Utils::formatMoney($model->adjustment, $model->currency_id) : ''; }) ->make(); diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index 7fc7bf94c930..4020bc9e7432 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -213,6 +213,8 @@ class ClientController extends \BaseController { $contact->delete(); } } + + Activity::createClient($client); if ($publicId) { Session::flash('message', 'Successfully updated client'); diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index 36f47935e8f4..75bed4ee107d 100755 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -9,6 +9,11 @@ class HomeController extends BaseController { return View::make('splash'); } + public function showComingSoon() + { + return View::make('coming_soon'); + } + public function logError() { $count = Session::get('error_count', 0); diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 978a99273476..1d431209695e 100755 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -74,8 +74,8 @@ class UserController extends BaseController { { if( Confide::user() ) { - Event::fire('user.login'); - return Redirect::to('/clients'); + Event::fire('user.login'); + return Redirect::to('/invoices/create'); } else { diff --git a/app/libraries/utils.php b/app/libraries/utils.php index 1d924f6413c1..b13f22a72061 100755 --- a/app/libraries/utils.php +++ b/app/libraries/utils.php @@ -283,4 +283,31 @@ class Utils } } + public static function encodeActivity($person = null, $action, $entity = null, $otherPerson = null) + { + $person = $person ? $person->getFullName() : 'System'; + $entity = $entity ? '[' . $entity->getKey() . ']' : ''; + $otherPerson = $otherPerson ? 'to ' . $otherPerson->getFullName() : ''; + + return trim("$person $action $entity $otherPerson"); + } + + public static function decodeActivity($message) + { + $pattern = '/\[([\w]*):([\d]*):(.*)\]/i'; + preg_match($pattern, $message, $matches); + + if (count($matches) > 0) + { + $match = $matches[0]; + $type = $matches[1]; + $publicId = $matches[2]; + $name = $matches[3]; + + $link = link_to($type . 's/' . $publicId, $name); + $message = str_replace($match, "$type $link", $message); + } + + return $message; + } } \ No newline at end of file diff --git a/app/models/Activity.php b/app/models/Activity.php index 28d895d9f9b4..f7688cce5a56 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -20,6 +20,9 @@ define("ACTIVITY_TYPE_DELETE_CREDIT", 15); class Activity extends Eloquent { + public $timestamps = true; + protected $softDelete = false; + public function scopeScope($query) { return $query->whereAccountId(Auth::user()->account_id); @@ -53,7 +56,7 @@ class Activity extends Eloquent $activity = Activity::getBlank(); $activity->client_id = $client->id; $activity->activity_type_id = ACTIVITY_TYPE_CREATE_CLIENT; - $activity->message = Auth::user()->getFullName() . ' created client ' . link_to('clients/'.$client->public_id, $client->name); + $activity->message = Utils::encodeActivity(Auth::user(), 'created', $client); $activity->save(); } @@ -64,7 +67,7 @@ class Activity extends Eloquent $activity = Activity::getBlank(); $activity->client_id = $client->id; $activity->activity_type_id = ACTIVITY_TYPE_DELETE_CLIENT; - $activity->message = Auth::user()->getFullName() . ' deleted client ' . link_to('clients/'.$client->public_id, $client->name); + $activity->message = Utils::encodeActivity(Auth::user(), 'deleted', $client); $activity->save(); } } @@ -76,7 +79,7 @@ class Activity extends Eloquent $activity = Activity::getBlank(); $activity->client_id = $client->id; $activity->activity_type_id = ACTIVITY_TYPE_ARCHIVE_CLIENT; - $activity->message = Auth::user()->getFullName() . ' archived client ' . link_to('clients/'.$client->public_id, $client->name); + $activity->message = Utils::encodeActivity(Auth::user(), 'archived', $client); $activity->balance = $client->balance; $activity->save(); } @@ -84,15 +87,13 @@ class Activity extends Eloquent public static function createInvoice($invoice) { - $userName = Auth::check() ? Auth::user()->getFullName() : 'System'; - if ($invoice->is_recurring) { - $message = $userName . ' created ' . link_to('invoices/'.$invoice->public_id, 'recuring invoice'); + $message = Utils::encodeActivity(null, 'created recurring', $invoice); } else { - $message = $userName . ' created invoice ' . link_to('invoices/'.$invoice->public_id, $invoice->invoice_number); + $message = Utils::encodeActivity(Auth::user(), 'created', $invoice); } $activity = Activity::getBlank($invoice); @@ -125,7 +126,7 @@ class Activity extends Eloquent $activity->invoice_id = $invoice->id; $activity->client_id = $invoice->client_id; $activity->activity_type_id = ACTIVITY_TYPE_ARCHIVE_INVOICE; - $activity->message = Auth::user()->getFullName() . ' archived invoice ' . $invoice->invoice_number; + $activity->message = Utils::encodeActivity(Auth::user(), 'archived', $invoice); $activity->balance = $client->balance; $activity->adjustment = $invoice->balance; @@ -151,7 +152,7 @@ class Activity extends Eloquent $activity->invoice_id = $invitation->invoice_id; $activity->contact_id = $invitation->contact_id; $activity->activity_type_id = ACTIVITY_TYPE_EMAIL_INVOICE; - $activity->message = $userName . ' emailed invoice ' . link_to('invoices/'.$invitation->invoice->public_id, $invitation->invoice->invoice_number) . ' to ' . $invitation->contact->getDisplayName(); + $activity->message = Utils::encodeActivity(Auth::check() ? Auth::user() : null, 'emailed', $invoice, $invitation->contact); $activity->balance = $client->balance; $activity->adjustment = $adjustment; $activity->save(); @@ -177,7 +178,7 @@ class Activity extends Eloquent $activity->client_id = $invoice->client_id; $activity->invoice_id = $invoice->id; $activity->activity_type_id = ACTIVITY_TYPE_DELETE_INVOICE; - $activity->message = Auth::user()->getFullName() . ' deleted invoice ' . link_to('invoices/'.$invoice->public_id, $invoice->invoice_number); + $activity->message = Utils::encodeActivity(Auth::user(), 'deleted', $invoice); $activity->balance = $client->balance; $activity->adjustment = $invoice->balance * -1; $activity->save(); @@ -201,7 +202,7 @@ class Activity extends Eloquent $activity->client_id = $invoice->client_id; $activity->invoice_id = $invoice->id; $activity->activity_type_id = ACTIVITY_TYPE_UPDATE_INVOICE; - $activity->message = Auth::user()->getFullName() . ' updated invoice ' . link_to('invoices/'.$invoice->public_id, $invoice->invoice_number); + $activity->message = Utils::encodeActivity(Auth::user(), 'updated', $invoice); $activity->balance = $client->balance; $activity->adjustment = $diff; $activity->json_backup = $backupInvoice->hidePrivateFields()->toJSON(); @@ -219,7 +220,7 @@ class Activity extends Eloquent if (Auth::check()) { $activity = Activity::getBlank(); - $activity->message = Auth::user()->getFullName() . ' created payment ' . $payment->transaction_reference; + $activity->message = Utils::encodeActivity(Auth::user(), 'created payment'); } else { @@ -254,7 +255,7 @@ class Activity extends Eloquent $client->save(); $activity = Activity::getBlank(); - $activity->message = Auth::user()->getFullName() . ' created credit'; + $activity->message = Utils::encodeActivity(Auth::user(), 'created credit'); $activity->credit_id = $credit->id; $activity->client_id = $credit->client_id; @@ -280,7 +281,7 @@ class Activity extends Eloquent $activity->invoice_id = $invoice->id; $activity->client_id = $invoice->client_id; $activity->activity_type_id = ACTIVITY_TYPE_ARCHIVE_PAYMENT; - $activity->message = Auth::user()->getFullName() . ' archived payment'; + $activity->message = Utils::encodeActivity(Auth::user(), 'archived payment'); $activity->balance = $payment->client->balance; $activity->save(); } @@ -312,7 +313,7 @@ class Activity extends Eloquent $activity->contact_id = $invitation->contact_id; $activity->invoice_id = $invitation->invoice_id; $activity->activity_type_id = ACTIVITY_TYPE_VIEW_INVOICE; - $activity->message = $invitation->contact->getFullName() . ' viewed invoice ' . link_to('invoices/'.$invitation->invoice->public_id, $invitation->invoice->invoice_number); + $activity->message = Utils::encodeActivity($invitation->contact, 'viewed', $invitation->invoice); $activity->balance = $invitation->invoice->client->balance; $activity->save(); } diff --git a/app/models/Client.php b/app/models/Client.php index 021768048a60..54d2f3fe5cf3 100755 --- a/app/models/Client.php +++ b/app/models/Client.php @@ -49,7 +49,7 @@ class Client extends EntityModel public function getName() { - return $this->name; + return $this->getDisplayName(); } public function getDisplayName() @@ -59,6 +59,7 @@ class Client extends EntityModel return $this->name; } + $this->load('contacts'); $contact = $this->contacts()->first(); return $contact->getDisplayName(); @@ -164,10 +165,12 @@ class Client extends EntityModel } } +/* Client::created(function($client) { Activity::createClient($client); }); +*/ Client::updating(function($client) { diff --git a/app/models/Country.php b/app/models/Country.php index 0c273c4ad513..01c300e56796 100755 --- a/app/models/Country.php +++ b/app/models/Country.php @@ -2,5 +2,8 @@ class Country extends Eloquent { + public $timestamps = false; + protected $softDelete = false; + protected $visible = ['id', 'name']; } \ No newline at end of file diff --git a/app/models/Credit.php b/app/models/Credit.php index c96d29fb2bc2..05be6923c0c1 100755 --- a/app/models/Credit.php +++ b/app/models/Credit.php @@ -14,7 +14,7 @@ class Credit extends EntityModel public function getName() { - return $this->credit_number; + return ''; } public function getEntityType() diff --git a/app/models/EntityModel.php b/app/models/EntityModel.php index ae9ea81a487c..cd67685d3419 100755 --- a/app/models/EntityModel.php +++ b/app/models/EntityModel.php @@ -3,6 +3,8 @@ class EntityModel extends Eloquent { protected $softDelete = true; + public $timestamps = false; + protected $hidden = ['id', 'created_at', 'deleted_at', 'updated_at']; public static function createNew($parent = false) @@ -40,10 +42,22 @@ class EntityModel extends Eloquent return $className::scope($publicId)->pluck('id'); } + public function getKey() + { + return $this->getEntityType() . ':' . $this->public_id . ':' . $this->getName(); + } + + /* + public function getEntityType() + { + return ''; + } + public function getNmae() { return ''; } + */ public function scopeScope($query, $publicId = false, $accountId = false) { diff --git a/app/models/Frequency.php b/app/models/Frequency.php index deac8c7a88ae..89d7f9196e13 100755 --- a/app/models/Frequency.php +++ b/app/models/Frequency.php @@ -3,4 +3,5 @@ class Frequency extends Eloquent { public $timestamps = false; + protected $softDelete = false; } diff --git a/app/models/Gateway.php b/app/models/Gateway.php index 805abf03f8c2..2b072d1f290f 100755 --- a/app/models/Gateway.php +++ b/app/models/Gateway.php @@ -2,5 +2,6 @@ class Gateway extends Eloquent { - + public $timestamps = false; + protected $softDelete = false; } \ No newline at end of file diff --git a/app/models/Industry.php b/app/models/Industry.php index 66c1a1cbadaf..b52cc3e90826 100755 --- a/app/models/Industry.php +++ b/app/models/Industry.php @@ -3,4 +3,6 @@ class Industry extends Eloquent { public $timestamps = false; + protected $softDelete = false; + } diff --git a/app/models/InvoiceStatus.php b/app/models/InvoiceStatus.php index 45f123aeee9d..03d0b11ad7fd 100755 --- a/app/models/InvoiceStatus.php +++ b/app/models/InvoiceStatus.php @@ -3,4 +3,5 @@ class InvoiceStatus extends Eloquent { public $timestamps = false; + protected $softDelete = false; } diff --git a/app/models/Payment.php b/app/models/Payment.php index 964bcd911ace..b9544af3ede9 100755 --- a/app/models/Payment.php +++ b/app/models/Payment.php @@ -20,7 +20,6 @@ class Payment extends EntityModel public function getName() { return ''; - //return $this->invoice_number; } public function getEntityType() diff --git a/app/models/Size.php b/app/models/Size.php index d4f9f2cac3ab..e0f3464435f8 100755 --- a/app/models/Size.php +++ b/app/models/Size.php @@ -3,4 +3,5 @@ class Size extends Eloquent { public $timestamps = false; + protected $softDelete = false; } diff --git a/app/models/Timezone.php b/app/models/Timezone.php index e3790b5ff27e..97dc0125f984 100755 --- a/app/models/Timezone.php +++ b/app/models/Timezone.php @@ -3,4 +3,5 @@ class Timezone extends Eloquent { public $timestamps = false; + protected $softDelete = false; } \ No newline at end of file diff --git a/app/models/User.php b/app/models/User.php index 94da1b98ef52..a8d32599e43e 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -87,4 +87,16 @@ class User extends ConfideUser implements UserInterface, RemindableInterface { return !$this->theme_id || in_array($this->theme_id, [2, 3, 5, 6, 7, 8, 10, 11, 12]); } + + public function afterSave($success=true, $forced = false) + { + if ($this->email) + { + return parent::afterSave($success=true, $forced = false); + } + else + { + return true; + } + } } \ No newline at end of file diff --git a/app/ninja/repositories/ClientRepository.php b/app/ninja/repositories/ClientRepository.php index 12b86e1bc07f..4103e3b512e8 100755 --- a/app/ninja/repositories/ClientRepository.php +++ b/app/ninja/repositories/ClientRepository.php @@ -95,6 +95,8 @@ class ClientRepository } $client->save(); + + \Activity::createClient($client); return $client; } diff --git a/app/ninja/repositories/InvoiceRepository.php b/app/ninja/repositories/InvoiceRepository.php index 24cec92e7784..e44642aec2be 100755 --- a/app/ninja/repositories/InvoiceRepository.php +++ b/app/ninja/repositories/InvoiceRepository.php @@ -191,6 +191,13 @@ class InvoiceRepository $invoice->balance = $total; $invoice->save(); + if ($data['set_default_terms']) + { + $account = \Auth::user()->account; + $account->invoice_terms = $invoice->terms; + $account->save(); + } + return $invoice; } } diff --git a/app/routes.php b/app/routes.php index a1f2f1393a87..49ebbb4151f7 100755 --- a/app/routes.php +++ b/app/routes.php @@ -26,14 +26,16 @@ DB::listen(function($sql)) { } */ - // TODO_FIX replace with cron Route::get('/send_emails', function() { Artisan::call('ninja:send-invoices'); }); -Route::get('/', 'HomeController@showWelcome'); +Route::get('/', 'HomeController@showComingSoon'); +Route::get('/rocksteady', 'HomeController@showWelcome'); + + Route::get('log_error', 'HomeController@logError'); Route::post('get_started', 'AccountController@getStarted'); @@ -47,7 +49,7 @@ Route::post('signup/submit', 'AccountController@submitSignup'); // Confide routes Route::get('login', 'UserController@login'); Route::post('login', 'UserController@do_login'); -//Route::get( 'user/confirm/{code}', 'UserController@confirm'); +Route::get( 'user/confirm/{code}', 'UserController@confirm'); Route::get('forgot_password', 'UserController@forgot_password'); Route::post('forgot_password', 'UserController@do_forgot_password'); //Route::get('user/reset_password/{token}', 'UserController@reset_password'); @@ -135,7 +137,7 @@ define('CONTACT_EMAIL', 'contact@invoiceninja.com'); define('ENV_DEVELOPMENT', 'local'); define('ENV_STAGING', 'staging'); -define('ENV_PRODUCTION', 'production'); +define('ENV_PRODUCTION', 'fortrabbit'); define('RECENTLY_VIEWED', 'RECENTLY_VIEWED'); define('ENTITY_CLIENT', 'client'); diff --git a/app/views/coming_soon.blade.php b/app/views/coming_soon.blade.php new file mode 100755 index 000000000000..4aa8221d2574 --- /dev/null +++ b/app/views/coming_soon.blade.php @@ -0,0 +1,35 @@ +@extends('master') + +@section('body') + + + +
+ coming soon +
+ +@stop \ No newline at end of file diff --git a/app/views/datatable.blade.php b/app/views/datatable.blade.php index 7d07fd8eeb9b..c01a4dedc43d 100755 --- a/app/views/datatable.blade.php +++ b/app/views/datatable.blade.php @@ -41,7 +41,7 @@ @if (isset($hasCheckboxes) && $hasCheckboxes) "aoColumnDefs" : [ { 'bSortable' : false, - 'aTargets' : [ 0 ] + 'aTargets' : [ 0, {{ count($columns) - 1 }} ] } ], @endif @foreach ($options as $k => $o) diff --git a/app/views/header.blade.php b/app/views/header.blade.php index 271b256758e9..a470def00bbd 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -35,7 +35,8 @@ @if (!Auth::check() || Auth::user()->showGreyBackground()) body { - background-color: #F6F6F6; + /* background-color: #F6F6F6; */ + background-color: #EEEEEE; } @endif diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index 56bc622f456c..bd614b8b52ad 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -147,7 +147,11 @@ {{ Former::textarea('public_notes')->data_bind("value: wrapped_notes, valueUpdate: 'afterkeydown'") ->label(false)->placeholder('Note to client')->style('width: 520px; resize: none') }} {{ Former::textarea('terms')->data_bind("value: wrapped_terms, valueUpdate: 'afterkeydown'") - ->label(false)->placeholder('Invoice terms')->style('width: 520px; resize: none') }} + ->label(false)->placeholder('Invoice terms')->style('width: 520px; resize: none') + ->addGroupClass('less-space-bottom') }} + Subtotal @@ -250,7 +254,7 @@ {{ Button::primary_submit('Save Invoice', array('data-bind'=>'css: $root.enable.save')) }} @endif - {{ Button::primary('Send Email', array('id' => 'email_button', 'onclick' => 'onEmailClick()', 'data-bind' => 'css: $root.enable.email')) }} + {{ Button::primary('Email Invoice', array('id' => 'email_button', 'onclick' => 'onEmailClick()', 'data-bind' => 'css: $root.enable.email')) }}

 

@@ -269,7 +273,7 @@
-
+
{{ Former::legend('Organization') }} @@ -347,7 +351,7 @@
-
+
@@ -376,7 +380,7 @@ {{ Former::checkbox('invoice_taxes')->text('Enable specifying an invoice tax') ->label('Settings')->data_bind('checked: $root.invoice_taxes, enable: $root.tax_rates().length > 1') }} - {{ Former::checkbox('invoice_item_taxes')->text('Enable specifying line item taxes')->addOnGroupClass('no-space-bottom') + {{ Former::checkbox('invoice_item_taxes')->text('Enable specifying line item taxes') ->label(' ')->data_bind('checked: $root.invoice_item_taxes, enable: $root.tax_rates().length > 1') }}
@@ -393,11 +397,43 @@ + + + {{ Former::close() }}