diff --git a/app/Console/Commands/BillReminder.php b/app/Console/Commands/BillReminder.php index 8c5cf2a1e..77362cf31 100644 --- a/app/Console/Commands/BillReminder.php +++ b/app/Console/Commands/BillReminder.php @@ -53,7 +53,11 @@ class BillReminder extends Command $company->setSettings(); - //$days = explode(',', setting('general.schedule_bill_days', '1,3')); + // Don't send reminders if disabled + if (!$company->send_bill_reminder) { + continue; + } + $days = explode(',', $company->schedule_bill_days); foreach ($days as $day) { diff --git a/app/Console/Commands/InvoiceReminder.php b/app/Console/Commands/InvoiceReminder.php index bb10f505e..cc459c114 100644 --- a/app/Console/Commands/InvoiceReminder.php +++ b/app/Console/Commands/InvoiceReminder.php @@ -53,7 +53,11 @@ class InvoiceReminder extends Command $company->setSettings(); - //$days = explode(',', config('general.schedule_invoice_days', '1,3')); + // Don't send reminders if disabled + if (!$company->send_invoice_reminder) { + continue; + } + $days = explode(',', $company->schedule_invoice_days); foreach ($days as $day) { diff --git a/app/Http/ViewComposers/Menu.php b/app/Http/ViewComposers/Menu.php index ea68d7d5e..7c8dd8d75 100644 --- a/app/Http/ViewComposers/Menu.php +++ b/app/Http/ViewComposers/Menu.php @@ -2,7 +2,6 @@ namespace App\Http\ViewComposers; -use Auth; use Illuminate\View\View; use anlutro\LaravelSettings\Facade as Settingg; @@ -17,17 +16,16 @@ class Menu public function compose(View $view) { $customer = null; - $company_id = session('company_id'); + $user = auth()->user(); // Get all companies - $companies = Auth::user()->companies()->limit(10)->get()->sortBy('name'); - foreach ($companies as $com) { + $companies = $user->companies()->enabled()->limit(10)->get()->each(function ($com) { $com->setSettings(); - } + })->sortBy('name'); // Get customer - if (Auth::user()->customer) { - $customer = Auth::user(); + if ($user->customer) { + $customer = $user; } $view->with(['companies' => $companies, 'customer' => $customer]); diff --git a/app/Listeners/Auth/Login.php b/app/Listeners/Auth/Login.php index 852989886..9ca023309 100644 --- a/app/Listeners/Auth/Login.php +++ b/app/Listeners/Auth/Login.php @@ -16,9 +16,19 @@ class Login */ public function handle(ILogin $event) { - // Set company id - $company = $event->user->companies()->first(); + // Get first company + $company = $event->user->companies()->enabled()->first(); + + // Logout if no company assigned + if (!$company) { + auth()->logout(); + + flash(trans('auth.error.no_company'))->error(); + + return redirect('auth/login'); + } + // Set company id session(['company_id' => $company->id]); // Save user login time diff --git a/app/Models/Company/Company.php b/app/Models/Company/Company.php index a9ecf4ff2..eb2d11247 100644 --- a/app/Models/Company/Company.php +++ b/app/Models/Company/Company.php @@ -204,6 +204,18 @@ class Company extends Eloquent return Auth::user()->companies()->filter($input)->sortable($sort)->paginate($limit); } + /** + * Scope to only include companies of a given enabled value. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param mixed $value + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeEnabled($query, $value = 1) + { + return $query->where('enabled', $value); + } + /** * Sort by company name * diff --git a/resources/lang/en-GB/auth.php b/resources/lang/en-GB/auth.php index 9d34bb4f8..70bb87394 100644 --- a/resources/lang/en-GB/auth.php +++ b/resources/lang/en-GB/auth.php @@ -13,14 +13,17 @@ return [ 'current_email' => 'Current Email', 'reset' => 'Reset', 'never' => 'never', + 'password' => [ 'current' => 'Password', 'current_confirm' => 'Password Confirmation', 'new' => 'New Password', 'new_confirm' => 'New Password Confirmation', ], + 'error' => [ - 'self_delete' => 'Error: Can not delete yourself!' + 'self_delete' => 'Error: Can not delete yourself!', + 'no_company' => 'Error: No company assigned to your account. Please, contact the system administrator.', ], 'failed' => 'These credentials do not match our records.', diff --git a/resources/views/companies/companies/index.blade.php b/resources/views/companies/companies/index.blade.php index 542832912..e18a65b10 100644 --- a/resources/views/companies/companies/index.blade.php +++ b/resources/views/companies/companies/index.blade.php @@ -62,7 +62,9 @@