diff --git a/.env.example b/.env.example index 54e388c4fee7..f08acd05bc0f 100644 --- a/.env.example +++ b/.env.example @@ -52,8 +52,9 @@ TRUSTED_PROXIES= NINJA_ENVIRONMENT=selfhost +PHANTOMJS_PDF_GENERATION=true PHANTOMJS_KEY='a-demo-key-with-low-quota-per-ip-address' -PHANTOMJS_SECRET= +PHANTOMJS_SECRET=secret COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}' SENTRY_LARAVEL_DSN=https://cc7e8e2c678041689e53e409b7dba236@sentry.invoicing.co/5 \ No newline at end of file diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 6f115f3d78c9..5612705a5bac 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -65,6 +65,7 @@ class BaseController extends Controller 'company.task_statuses', 'company.expense_categories', 'company.documents', + 'company.users', //'company.users.company_user', 'company.clients.contacts.company', 'company.clients.gateway_tokens', diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index 1e552e1ff7d9..9b9027fef718 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -87,7 +87,7 @@ class CreateEntityPdf implements ShouldQueue public function handle() { - if (config('ninja.phantomjs_key')) { + if (config('ninja.phantomjs_pdf_generation')) { return (new Phantom)->generate($this->invitation); } diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index fd0c799adc70..1bd1a7373869 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -11,6 +11,7 @@ namespace App\Models; +use App\Models\TaxRate; use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\SoftDeletes; @@ -55,6 +56,11 @@ class CompanyUser extends Pivot return self::class; } + public function tax_rates() + { + return $this->hasMany(TaxRate::class,'company_id', 'company_id'); + } + public function account() { return $this->belongsTo(Account::class); diff --git a/app/Utils/PhantomJS/Phantom.php b/app/Utils/PhantomJS/Phantom.php index fee98d2d50e1..c69511751323 100644 --- a/app/Utils/PhantomJS/Phantom.php +++ b/app/Utils/PhantomJS/Phantom.php @@ -88,8 +88,7 @@ class Phantom { $key = $entity.'_id'; - $invitation_instance = 'App\Models\\'.Str::camel(ucfirst($entity)).'Invitation'; - + $invitation_instance = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation'; $invitation = $invitation_instance::whereRaw('BINARY `key`= ?', [$invitation_key])->first(); $entity_obj = $invitation->{$entity}; @@ -115,9 +114,9 @@ class Phantom $state = [ 'template' => $template->elements([ - 'client' => $this->entity->client, - 'entity' => $this->entity, - 'pdf_variables' => (array) $this->entity->company->settings->pdf_variables, + 'client' => $entity_obj->client, + 'entity' => $entity_obj, + 'pdf_variables' => (array) $entity_obj->company->settings->pdf_variables, '$product' => $design->design->product, ]), 'variables' => $html->generateLabelsAndValues(), diff --git a/app/Utils/SystemHealth.php b/app/Utils/SystemHealth.php index 4931fdd2fc3f..3abb9182d4b9 100644 --- a/app/Utils/SystemHealth.php +++ b/app/Utils/SystemHealth.php @@ -78,9 +78,19 @@ class SystemHealth 'simple_db_check' => (bool) self::simpleDbCheck(), 'npm_status' => self::checkNpm(), 'node_status' => self::checkNode(), + 'cache_enabled' => self::checkConfigCache(), + 'phantom_enabled' => (bool) config('ninja.phantomjs_pdf_generation'), ]; } + public static function checkConfigCache() + { + if(env('APP_URL')) + return false; + + return true; + } + public static function checkNode() { try { diff --git a/config/ninja.php b/config/ninja.php index 6edfe78c9e16..b07123bea9bf 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -29,6 +29,7 @@ return [ 'enabled_modules' => 32767, 'phantomjs_key' => env('PHANTOMJS_KEY', false), 'phantomjs_secret' => env('PHANTOMJS_SECRET', false), + 'phantomjs_pdf_generation' => env('PHANTOMJS_PDF_GENERATION', true), 'trusted_proxies' => env('TRUSTED_PROXIES', false), 'sentry_dsn' => env('SENTRY_LARAVEL_DSN', 'https://9b4e15e575214354a7d666489783904a@sentry.invoicing.co/6'),