diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 052a477c2d..951767d0ec 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -52,6 +52,7 @@ class Handler extends ExceptionHandler MaxAttemptsExceededException::class, CommandNotFoundException::class, ValidationException::class, + ModelNotFoundException::class, ]; /** diff --git a/app/Http/Controllers/Auth/ContactLoginController.php b/app/Http/Controllers/Auth/ContactLoginController.php index 795707d88d..3f9d0503f0 100644 --- a/app/Http/Controllers/Auth/ContactLoginController.php +++ b/app/Http/Controllers/Auth/ContactLoginController.php @@ -81,8 +81,8 @@ class ContactLoginController extends Controller { Auth::shouldUse('contact'); - if(Ninja::isHosted() && $request->has('db')) - MultiDB::setDb($request->input('db')); + if(Ninja::isHosted() && $request->has('company_key')) + MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); $this->validateLogin($request); // If the class is using the ThrottlesLogins trait, we can automatically throttle diff --git a/app/Http/Controllers/ClientPortal/SwitchCompanyController.php b/app/Http/Controllers/ClientPortal/SwitchCompanyController.php index 2867541476..160c2246ad 100644 --- a/app/Http/Controllers/ClientPortal/SwitchCompanyController.php +++ b/app/Http/Controllers/ClientPortal/SwitchCompanyController.php @@ -27,7 +27,7 @@ class SwitchCompanyController extends Controller ->where('id', $this->transformKeys($contact)) ->first(); - auth()->guard('contact')->user()->login($client_contact, true); + auth()->guard('contact')->login($client_contact, true); return redirect('/client/dashboard'); } diff --git a/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php b/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php index 675827b6ca..60abdf57cb 100644 --- a/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php +++ b/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php @@ -42,6 +42,9 @@ class StoreRecurringExpenseRequest extends Request $rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.auth()->user()->company()->id; $rules['frequency_id'] = 'required|integer|digits_between:1,12'; + $rules['tax_amount1'] = 'numeric'; + $rules['tax_amount2'] = 'numeric'; + $rules['tax_amount3'] = 'numeric'; return $this->globalRules($rules); } diff --git a/app/Http/Requests/RecurringExpense/UpdateRecurringExpenseRequest.php b/app/Http/Requests/RecurringExpense/UpdateRecurringExpenseRequest.php index c1be81d105..4f03269bf7 100644 --- a/app/Http/Requests/RecurringExpense/UpdateRecurringExpenseRequest.php +++ b/app/Http/Requests/RecurringExpense/UpdateRecurringExpenseRequest.php @@ -43,6 +43,10 @@ class UpdateRecurringExpenseRequest extends Request $rules['number'] = Rule::unique('recurring_expenses')->where('company_id', auth()->user()->company()->id)->ignore($this->recurring_expense->id); } + $rules['tax_amount1'] = 'numeric'; + $rules['tax_amount2'] = 'numeric'; + $rules['tax_amount3'] = 'numeric'; + return $this->globalRules($rules); } diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 05f1c7392b..9607bb2436 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -92,7 +92,7 @@ class ClientContact extends Authenticatable implements HasLocalePreference 'custom_value4', 'email', 'is_primary', - // 'client_id', + 'send_email', ]; /** diff --git a/app/Models/GatewayType.php b/app/Models/GatewayType.php index e7b5160b81..d6c51bc4e7 100644 --- a/app/Models/GatewayType.php +++ b/app/Models/GatewayType.php @@ -84,7 +84,7 @@ class GatewayType extends StaticModel case self::EPS: return ctrans('texts.eps'); case self::BECS: - return ctrans('tets.becs'); + return ctrans('texts.becs'); case self::ACSS: return ctrans('texts.acss'); case self::DIRECT_DEBIT: diff --git a/app/PaymentDrivers/WePayPaymentDriver.php b/app/PaymentDrivers/WePayPaymentDriver.php index 27c60e570b..9624a329cf 100644 --- a/app/PaymentDrivers/WePayPaymentDriver.php +++ b/app/PaymentDrivers/WePayPaymentDriver.php @@ -185,7 +185,7 @@ class WePayPaymentDriver extends BaseDriver } if (! isset($objectType)) { - throw new Exception('Could not find object id parameter'); + throw new \Exception('Could not find object id parameter'); } if ($objectType == 'credit_card') { diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 2f62dbc6cc..cf37b1d3f1 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -113,25 +113,26 @@ class BaseRepository * @param $action * * @return int + * @deprecated - this doesn't appear to be used anywhere? */ - public function bulk($ids, $action) - { - if (! $ids) { - return 0; - } + // public function bulk($ids, $action) + // { + // if (! $ids) { + // return 0; + // } - $ids = $this->transformKeys($ids); + // $ids = $this->transformKeys($ids); - $entities = $this->findByPublicIdsWithTrashed($ids); + // $entities = $this->findByPublicIdsWithTrashed($ids); - foreach ($entities as $entity) { - if (auth()->user()->can('edit', $entity)) { - $this->$action($entity); - } - } + // foreach ($entities as $entity) { + // if (auth()->user()->can('edit', $entity)) { + // $this->$action($entity); + // } + // } - return count($entities); - } + // return count($entities); + // } /* Returns an invoice if defined as a key in the $resource array*/ public function getInvitation($invitation, $resource) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 162923cee0..45d0ab893a 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -134,9 +134,9 @@ class InvoiceService * * @return InvoiceService Parent class object */ - public function updateBalance($balance_adjustment) + public function updateBalance($balance_adjustment, bool $is_draft = false) { - $this->invoice = (new UpdateBalance($this->invoice, $balance_adjustment))->run(); + $this->invoice = (new UpdateBalance($this->invoice, $balance_adjustment, $is_draft))->run(); if ((int)$this->invoice->balance == 0) { $this->invoice->next_send_date = null; @@ -339,6 +339,10 @@ class InvoiceService public function removeUnpaidGatewayFees() { + //return early if type three does not exist. + if(!collect($this->invoice->line_items)->contains('type_id', 3)) + return $this; + $this->invoice->line_items = collect($this->invoice->line_items) ->reject(function ($item) { return $item->type_id == '3'; diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index fbf874f955..a205b83dd0 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -47,7 +47,7 @@ class MarkSent extends AbstractService ->service() ->applyNumber() ->setDueDate() - ->updateBalance($this->invoice->amount) + ->updateBalance($this->invoice->amount, true) ->deletePdf() ->setReminder() ->save(); diff --git a/app/Services/Invoice/UpdateBalance.php b/app/Services/Invoice/UpdateBalance.php index 9a95391abb..0aab1c2e8c 100644 --- a/app/Services/Invoice/UpdateBalance.php +++ b/app/Services/Invoice/UpdateBalance.php @@ -20,10 +20,13 @@ class UpdateBalance extends AbstractService public $balance_adjustment; - public function __construct($invoice, $balance_adjustment) + private $is_draft; + + public function __construct($invoice, $balance_adjustment, bool $is_draft) { $this->invoice = $invoice; $this->balance_adjustment = $balance_adjustment; + $this->is_draft = $is_draft; } public function run() @@ -34,7 +37,7 @@ class UpdateBalance extends AbstractService $this->invoice->balance += floatval($this->balance_adjustment); - if ($this->invoice->balance == 0) { + if ($this->invoice->balance == 0 && !$this->is_draft) { $this->invoice->status_id = Invoice::STATUS_PAID; } diff --git a/resources/views/portal/ninja2020/gateways/stripe/becs/becs_debit.blade.php b/resources/views/portal/ninja2020/gateways/stripe/becs/becs_debit.blade.php index cd41c59d29..cf52d7a8b5 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/becs/becs_debit.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/becs/becs_debit.blade.php @@ -22,7 +22,7 @@