diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 5d40fb8b87..2049d9c59c 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -15,15 +15,16 @@ use Exception; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException; +use Illuminate\Database\Eloquent\RelationNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Http\Exceptions\ThrottleRequestsException; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Schema; use Illuminate\Validation\ValidationException; +use Sentry\State\Scope; use Symfony\Component\Debug\Exception\FatalThrowableError; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Illuminate\Database\Eloquent\RelationNotFoundException; -use Sentry\State\Scope; use function Sentry\configureScope; class Handler extends ExceptionHandler @@ -55,9 +56,12 @@ class Handler extends ExceptionHandler */ public function report(Exception $exception) { + if(!Schema::hasTable('accounts')) + return; + if (app()->bound('sentry') && $this->shouldReport($exception)) { app('sentry')->configureScope(function (Scope $scope): void { - if (auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) { + if (auth()->guard('contact') && auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) { $scope->setUser([ 'id' => auth()->guard('contact')->user()->company->account->key, 'email' => "anonymous@example.com", diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 0b2293328e..3444d6983e 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -23,6 +23,7 @@ use App\Utils\Traits\AppSetup; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Request as Input; +use Illuminate\Support\Facades\Schema; use League\Fractal\Manager; use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Resource\Collection; @@ -319,10 +320,10 @@ class BaseController extends Controller // return redirect()->secure(request()->path()); // } - if ((bool)$this->checkAppSetup() !== false) { + if ((bool)$this->checkAppSetup() !== false && Schema::hasTable('accounts') && $account = Account::all()->first()) { $data = []; - if (Ninja::isSelfHost() && $account = Account::all()->first()) { + if (Ninja::isSelfHost()) { $data['report_errors'] = $account->report_errors; } else { $data['report_errors'] = true; diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index 9177e7ebd7..dda5d1fcce 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -62,6 +62,8 @@ class ApplyPayment extends AbstractService $this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($this->payment_amount*-1); } + $this->invoice->service()->applyNumber()->save(); + return $this->invoice; } } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index ad5567fc0a..589f6a3e24 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -139,8 +139,13 @@ class InvoiceService /* One liners */ public function setDueDate() { - $this->invoice->due_date = Carbon::now()->addDays($this->invoice->client->getSetting('payment_terms')); + if($this->invoice->due_date != '') + return $this; + //$this->invoice->due_date = Carbon::now()->addDays($this->invoice->client->getSetting('payment_terms')); + + $this->invoice->due_date = Carbon::parse($this->invoice->date)->addDays($this->invoice->client->getSetting('payment_terms')); + return $this; } diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 6660c1a7df..8778a4ebd3 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -61,6 +61,7 @@ class MarkPaid extends AbstractService $this->invoice->service() ->updateBalance($payment->amount*-1) ->setStatus(Invoice::STATUS_PAID) + ->applyNumber() ->save(); /* Update Invoice balance */ diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 994344bcb4..f31175598b 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -45,6 +45,7 @@ class MarkSent extends AbstractService ->service() ->setStatus(Invoice::STATUS_SENT) ->applyNumber() + ->setDueDate() ->save(); $this->client->service()->updateBalance($this->invoice->balance)->save(); diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php index e00726d139..62b30fe154 100644 --- a/database/factories/ClientFactory.php +++ b/database/factories/ClientFactory.php @@ -13,7 +13,7 @@ $factory->define(App\Models\Client::class, function (Faker $faker) { 'paid_to_date' => 0, 'vat_number' => $faker->text(25), 'id_number' => '', - 'custom_value1' => 'date|'.$faker->date('Y-m-d'), + 'custom_value1' => $faker->date('Y-m-d'), 'custom_value2' => '', 'custom_value3' => '', 'custom_value4' => '', diff --git a/resources/views/setup/_database.blade.php b/resources/views/setup/_database.blade.php index 159bd92957..52c2e1f487 100644 --- a/resources/views/setup/_database.blade.php +++ b/resources/views/setup/_database.blade.php @@ -17,7 +17,7 @@ Show code
 -- Commands to create a MySQL database and user
-CREATE SCHEMA `ninja` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
+CREATE SCHEMA `db-ninja-01` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
 CREATE USER 'ninja'@'localhost' IDENTIFIED BY 'ninja';
 GRANT ALL PRIVILEGES ON `ninja`.* TO 'ninja'@'localhost';
 FLUSH PRIVILEGES;
@@ -38,7 +38,7 @@ FLUSH PRIVILEGES;
                     {{ ctrans('texts.host') }}*
                 
                 
- +
@@ -46,7 +46,7 @@ FLUSH PRIVILEGES; {{ ctrans('texts.database') }}*
- +
@@ -54,7 +54,7 @@ FLUSH PRIVILEGES; {{ ctrans('texts.username') }}*
- +
@@ -62,7 +62,7 @@ FLUSH PRIVILEGES; {{ ctrans('texts.password') }}
- +