diff --git a/app/Events/InvoicePaid.php b/app/Events/InvoicePaid.php new file mode 100644 index 000000000000..42a50a8b7644 --- /dev/null +++ b/app/Events/InvoicePaid.php @@ -0,0 +1,21 @@ +invoice = $invoice; + } + +} diff --git a/app/Events/UserLoggedIn.php b/app/Events/UserLoggedIn.php new file mode 100644 index 000000000000..1f4af5e86a9a --- /dev/null +++ b/app/Events/UserLoggedIn.php @@ -0,0 +1,21 @@ +listen('user.signup', 'UserEventHandler@onSignup'); - $events->listen('user.login', 'UserEventHandler@onLogin'); - - $events->listen('user.refresh', 'UserEventHandler@onRefresh'); - } - - public function onSignup() - { - } - - public function onLogin() - { - $account = Auth::user()->account; - $account->last_login = Carbon::now()->toDateTimeString(); - $account->save(); - - Event::fire('user.refresh'); - } - - public function onRefresh() - { - Auth::user()->account->loadLocalizationSettings(); - } -} diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index d52caebe6c68..c95278c362b1 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -20,6 +20,8 @@ use App\Models\Industry; use App\Ninja\Repositories\AccountRepository; use App\Ninja\Mailers\UserMailer; use App\Ninja\Mailers\ContactMailer; +use App\Events\UserLoggedIn; +use App\Events\UserSettingsChanged; class AccountController extends BaseController { @@ -79,7 +81,7 @@ class AccountController extends BaseController } Auth::login($user, true); - Event::fire('user.login'); + Event::fire(new UserLoggedIn()); return Redirect::to('invoices/create')->with('sign_up', Input::get('sign_up')); } @@ -634,7 +636,7 @@ class AccountController extends BaseController //Image::canvas($image->width, $image->height, '#FFFFFF')->insert($image)->save($account->getLogoPath()); } - Event::fire('user.refresh'); + Event::fire(new UserSettingsChanged()); Session::flash('message', trans('texts.updated_settings')); return Redirect::to('company/details'); diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index f42f483a4701..f3e051d6f79f 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -1,5 +1,10 @@ middleware('guest', ['except' => 'getLogout']); } + public function postLoginWrapper(Request $request) + { + $response = self::postLogin($request); + + if (Auth::check()) { + Event::fire(new UserLoggedIn()); + } + + return $response; + } + } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 99af87a6f4e1..14102d7a2446 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -8,6 +8,7 @@ use Input; use Cache; use Redirect; use DB; +use Event; use App\Models\Invoice; use App\Models\Invitation; @@ -21,11 +22,14 @@ use App\Models\Size; use App\Models\Industry; use App\Models\PaymentTerm; use App\Models\InvoiceDesign; +use App\Models\AccountGateway; +use App\Models\Activity; use App\Ninja\Mailers\ContactMailer as Mailer; use App\Ninja\Repositories\InvoiceRepository; use App\Ninja\Repositories\ClientRepository; use App\Ninja\Repositories\TaxRateRepository; +use App\Events\InvoiceViewed; class InvoiceController extends BaseController { @@ -178,7 +182,8 @@ class InvoiceController extends BaseController if (!Session::has($invitationKey) && (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) { Activity::viewInvoice($invitation); - Event::fire('invoice.viewed', $invoice); + //Event::fire('invoice.viewed', $invoice); + Event::fire(new InvoiceViewed($invoice)); } Session::set($invitationKey, true); diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 32922d2f88cf..3d5b8a468437 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -7,6 +7,10 @@ use Session; use Utils; use View; +use App\Models\Invoice; +use App\Models\Client; +use App\Models\PaymentType; + use App\Ninja\Repositories\PaymentRepository; use App\Ninja\Repositories\InvoiceRepository; use App\Ninja\Repositories\AccountRepository; @@ -140,8 +144,8 @@ class PaymentController extends BaseController 'method' => 'POST', 'url' => "payments", 'title' => trans('texts.new_payment'), - //'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), - 'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), + //'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), + 'paymentTypes' => PaymentType::orderBy('id')->get(), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ); return View::make('payments.edit', $data); @@ -161,8 +165,8 @@ class PaymentController extends BaseController 'method' => 'PUT', 'url' => 'payments/'.$publicId, 'title' => trans('texts.edit_payment'), - //'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), - 'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), + //'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), + 'paymentTypes' => PaymentType::orderBy('id')->get(), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ); return View::make('payments.edit', $data); diff --git a/app/Http/Middleware/StartupCheck.php b/app/Http/Middleware/StartupCheck.php index 4a42119f634d..e32e0a3b9625 100644 --- a/app/Http/Middleware/StartupCheck.php +++ b/app/Http/Middleware/StartupCheck.php @@ -106,7 +106,7 @@ class StartupCheck { // Make sure the account/user localization settings are in the session if (Auth::check() && !Session::has(SESSION_TIMEZONE)) { - Event::fire('user.refresh'); + Event::fire('user.refresh'); } // Check if the user is claiming a license (ie, additional invoices, white label, etc.) diff --git a/app/Http/routes.php b/app/Http/routes.php index 380fcfc48550..2391cd2a0124 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -16,7 +16,6 @@ //dd(DB::getQueryLog()); //dd(Client::getPrivateId(1)); //dd(new DateTime()); -//Event::fire('user.signup'); //dd(App::environment()); //dd(gethostname()); //Log::error('test'); @@ -64,7 +63,7 @@ Route::controllers([ get('/signup', array('as' => 'signup', 'uses' => 'Auth\AuthController@getRegister')); post('/signup', array('as' => 'signup', 'uses' => 'Auth\AuthController@postRegister')); get('/login', array('as' => 'login', 'uses' => 'Auth\AuthController@getLogin')); -post('/login', array('as' => 'login', 'uses' => 'Auth\AuthController@postLogin')); +post('/login', array('as' => 'login', 'uses' => 'Auth\AuthController@postLoginWrapper')); get('/logout', array('as' => 'logout', 'uses' => 'Auth\AuthController@getLogout')); get('/forgot', array('as' => 'forgot', 'uses' => 'Auth\PasswordController@getEmail')); post('/forgot', array('as' => 'forgot', 'uses' => 'Auth\PasswordController@postEmail')); diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 7b63c9a47e15..33d799e4acb7 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -12,6 +12,7 @@ use Input; use Log; use DateTime; use stdClass; +use Carbon; use App\Models\Currency; diff --git a/app/Listeners/HandleInvoicePaid.php b/app/Listeners/HandleInvoicePaid.php new file mode 100644 index 000000000000..b1165c2e1a0a --- /dev/null +++ b/app/Listeners/HandleInvoicePaid.php @@ -0,0 +1,45 @@ +userMailer = $userMailer; + $this->contactMailer = $contactMailer; + } + + /** + * Handle the event. + * + * @param InvoicePaid $event + * @return void + */ + public function handle(InvoicePaid $event) + { + $this->contactMailer->sendPaymentConfirmation($payment); + + foreach ($invoice->account->users as $user) + { + if ($user->{'notify_paid'}) + { + $this->userMailer->sendNotification($user, $invoice, 'paid', $payment); + } + } + } + +} diff --git a/app/Listeners/HandleInvoiceSent.php b/app/Listeners/HandleInvoiceSent.php new file mode 100644 index 000000000000..0ecdf78016c6 --- /dev/null +++ b/app/Listeners/HandleInvoiceSent.php @@ -0,0 +1,40 @@ +userMailer = $userMailer; + } + + /** + * Handle the event. + * + * @param InvoiceSent $event + * @return void + */ + public function handle(InvoiceSent $event) + { + foreach ($invoice->account->users as $user) + { + if ($user->{'notify_sent'}) + { + $this->userMailer->sendNotification($user, $invoice, 'sent', $payment); + } + } + } + +} diff --git a/app/Listeners/HandleInvoiceViewed.php b/app/Listeners/HandleInvoiceViewed.php new file mode 100644 index 000000000000..3a3f6e323756 --- /dev/null +++ b/app/Listeners/HandleInvoiceViewed.php @@ -0,0 +1,42 @@ +userMailer = $userMailer; + } + + /** + * Handle the event. + * + * @param InvoiceViewed $event + * @return void + */ + public function handle(InvoiceViewed $event) + { + $invoice = $event->invoice; + + foreach ($invoice->account->users as $user) + { + if ($user->{'notify_viewed'}) + { + $this->userMailer->sendNotification($user, $invoice, 'viewed', $payment); + } + } + } + +} diff --git a/app/Listeners/HandleUserLoggedIn.php b/app/Listeners/HandleUserLoggedIn.php new file mode 100644 index 000000000000..f1f4e36eff1d --- /dev/null +++ b/app/Listeners/HandleUserLoggedIn.php @@ -0,0 +1,37 @@ +account; + $account->last_login = Carbon::now()->toDateTimeString(); + $account->save(); + + $account->loadLocalizationSettings(); + } + +} diff --git a/app/Listeners/HandleUserSettingsChanged.php b/app/Listeners/HandleUserSettingsChanged.php new file mode 100644 index 000000000000..8ebd1a9b3355 --- /dev/null +++ b/app/Listeners/HandleUserSettingsChanged.php @@ -0,0 +1,32 @@ +account; + $account->loadLocalizationSettings(); + } + +} diff --git a/app/Models/Account.php b/app/Models/Account.php index eb3444524909..1b3df82ab00b 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -2,6 +2,7 @@ use Eloquent; use Utils; +use Session; use Illuminate\Database\Eloquent\SoftDeletes; diff --git a/app/Models/Activity.php b/app/Models/Activity.php index c9c3f992696d..25c38f5d21cc 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -5,10 +5,11 @@ use Eloquent; use Utils; use Session; use Request; +use Carbon; class Activity extends Eloquent { - public $timestamps = true; + public $timestamps = true; public function scopeScope($query) { diff --git a/app/Ninja/Repositories/ClientRepository.php b/app/Ninja/Repositories/ClientRepository.php index 327b0b07996c..d4569bea4b47 100644 --- a/app/Ninja/Repositories/ClientRepository.php +++ b/app/Ninja/Repositories/ClientRepository.php @@ -172,7 +172,7 @@ class ClientRepository $client->save(); if (!$publicId || $publicId == "-1") { - \Activity::createClient($client, $notify); + Activity::createClient($client, $notify); } return $client; diff --git a/app/Providers/ConfigServiceProvider.php b/app/Providers/ConfigServiceProvider.php index 49e0df6f8fb7..739564c6eff6 100644 --- a/app/Providers/ConfigServiceProvider.php +++ b/app/Providers/ConfigServiceProvider.php @@ -15,15 +15,7 @@ class ConfigServiceProvider extends ServiceProvider { */ public function register() { - // Surely there has to be a better way than this? - app('config')->set('confide', require $this->app->basePath() . '/config/packages/zizaco/confide/config.php'); - - /* - This doesn't work: - config([ - 'config/packages/zizaco/confide/config.php' - ]);*/ } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 1cece99932c2..e5fd505a007a 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -11,9 +11,21 @@ class EventServiceProvider extends ServiceProvider { * @var array */ protected $listen = [ - 'event.name' => [ - 'EventListener', - ], + 'App\Events\UserLoggedIn' => [ + 'App\Listeners\HandleUserLoggedIn', + ], + 'App\Events\UserSettingsChanged' => [ + 'App\Listeners\HandleUserSettingsChanged', + ], + 'App\Events\InvoiceSent' => [ + 'App\Listeners\HandleInvoiceSent', + ], + 'App\Events\InvoiceViewed' => [ + 'App\Listeners\HandleInvoiceViewed', + ], + 'App\Events\InvoicePaid' => [ + 'App\Listeners\HandleInvoicePaid', + ], ]; /** diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 8df904ce8a1e..0002652750f1 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -65,7 +65,7 @@ @foreach ($activities as $activity)