From 2fadadf5d40024f49226cd1bd89c5cc96b16dc6f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 22 Jun 2020 15:52:20 +1000 Subject: [PATCH 1/3] Change document->path to ->url --- app/Http/Controllers/BaseController.php | 2 ++ app/Jobs/Util/UploadFile.php | 2 +- app/Models/Credit.php | 6 ++++++ app/Models/Document.php | 2 +- app/Transformers/CreditTransformer.php | 3 ++- app/Transformers/DocumentTransformer.php | 2 +- app/Transformers/QuoteTransformer.php | 5 +++-- .../migrations/2014_10_13_000000_create_users_table.php | 2 +- tests/Unit/CompanyDocumentsTest.php | 4 ++-- 9 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index f1b2af101f..0a046e4f81 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -265,7 +265,9 @@ class BaseController extends Controller 'company.payments.paymentables', 'company.quotes.invitations.contact', 'company.quotes.invitations.company', + 'company.quotes.documents', 'company.credits.invitations.company', + 'company.credits.documents', 'company.payment_terms.company', //'company.credits.invitations.contact', //'company.credits.invitations.company', diff --git a/app/Jobs/Util/UploadFile.php b/app/Jobs/Util/UploadFile.php index 6fe1fe728a..ac9168e21b 100644 --- a/app/Jobs/Util/UploadFile.php +++ b/app/Jobs/Util/UploadFile.php @@ -88,7 +88,7 @@ class UploadFile implements ShouldQueue $document = new Document(); $document->user_id = $this->user->id; $document->company_id = $this->company->id; - $document->path = $instance; + $document->url = $instance; $document->name = $this->file->getClientOriginalName(); $document->type = $this->file->extension(); $document->disk = $this->disk; diff --git a/app/Models/Credit.php b/app/Models/Credit.php index c82292a24b..e817c7aa75 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -170,6 +170,12 @@ class Credit extends BaseModel return $this->morphToMany(Payment::class, 'paymentable'); } + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } + + /** * Access the invoice calculator object * diff --git a/app/Models/Document.php b/app/Models/Document.php index a16bdaaeb2..f46e8276e1 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -100,7 +100,7 @@ class Document extends BaseModel public function generateUrl($absolute = false) { - $url = Storage::disk($this->disk)->url($this->path); + $url = Storage::disk($this->disk)->url($this->url); if ($url && $absolute) { return url($url); diff --git a/app/Transformers/CreditTransformer.php b/app/Transformers/CreditTransformer.php index a1e432f25b..1d18564364 100644 --- a/app/Transformers/CreditTransformer.php +++ b/app/Transformers/CreditTransformer.php @@ -24,13 +24,14 @@ class CreditTransformer extends EntityTransformer protected $defaultIncludes = [ 'invitations', + 'documents', ]; protected $availableIncludes = [ 'invitations', // 'payments', // 'client', - // 'documents', + 'documents', ]; public function includeInvitations(Credit $credit) diff --git a/app/Transformers/DocumentTransformer.php b/app/Transformers/DocumentTransformer.php index 9f76163c07..ca3435c58f 100644 --- a/app/Transformers/DocumentTransformer.php +++ b/app/Transformers/DocumentTransformer.php @@ -37,7 +37,7 @@ class DocumentTransformer extends EntityTransformer 'assigned_user_id' => $this->encodePrimaryKey($document->assigned_user_id), 'project_id' => $this->encodePrimaryKey($document->project_id), 'vendor_id' => $this->encodePrimaryKey($document->vendor_id), - 'path' => (string) $document->path ?: '', + 'url' => (string) $document->url ?: '', 'preview' => (string) $document->preview ?: '', 'name' => (string) $document->name, 'type' => (string) $document->type, diff --git a/app/Transformers/QuoteTransformer.php b/app/Transformers/QuoteTransformer.php index c01af6fed6..abf4d6c1fd 100644 --- a/app/Transformers/QuoteTransformer.php +++ b/app/Transformers/QuoteTransformer.php @@ -22,13 +22,14 @@ class QuoteTransformer extends EntityTransformer protected $defaultIncludes = [ 'invitations', + 'documents', ]; protected $availableIncludes = [ 'invitations', - // 'payments', + 'documents', + // 'payments', // 'client', - // 'documents', ]; public function includeInvitations(Quote $quote) diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 2f80117792..f4a0462f04 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -222,7 +222,7 @@ class CreateUsersTable extends Migration $table->unsignedInteger('company_id')->index(); $table->unsignedInteger('project_id')->nullable(); $table->unsignedInteger('vendor_id')->nullable(); - $table->string('path')->nullable(); + $table->string('url')->nullable(); $table->string('preview')->nullable(); $table->string('name')->nullable(); $table->string('type')->nullable(); diff --git a/tests/Unit/CompanyDocumentsTest.php b/tests/Unit/CompanyDocumentsTest.php index bcfc354902..e669dbc708 100644 --- a/tests/Unit/CompanyDocumentsTest.php +++ b/tests/Unit/CompanyDocumentsTest.php @@ -47,7 +47,7 @@ class CompanyDocumentsTest extends TestCase $this->assertNotNull($document); - $this->assertTrue(Storage::exists($document->path)); + $this->assertTrue(Storage::exists($document->url)); $this->assertGreaterThan($original_count, Document::whereCompanyId($this->company->id)->count()); @@ -55,6 +55,6 @@ class CompanyDocumentsTest extends TestCase $this->assertEquals(0, Document::whereCompanyId($this->company->id)->count()); - $this->assertFalse(Storage::exists($document->path)); + $this->assertFalse(Storage::exists($document->url)); } } From fa02cc1abeeab81d25cfa392de3304725dab3a4f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 22 Jun 2020 20:28:08 +1000 Subject: [PATCH 2/3] Add variables --- app/DataMapper/CompanySettings.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 7df5648621..a5009b4a76 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -232,8 +232,12 @@ class CompanySettings extends BaseSettings public $portal_custom_js = ''; public $client_can_register = false; + public $client_signup_terms = ''; + public $client_signup_privacy_policy = ''; public static $casts = [ + 'client_signup_terms' => 'string', + 'client_signup_privacy_policy' => 'string', 'client_can_register' => 'bool', 'portal_design_id' => 'string', 'late_fee_endless_percent' => 'float', From 5bd17ba6d121e16ad7f9235fc338ece14dc36a2c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 22 Jun 2020 20:56:31 +1000 Subject: [PATCH 3/3] Fixes for tests --- app/Transformers/QuoteTransformer.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/Transformers/QuoteTransformer.php b/app/Transformers/QuoteTransformer.php index abf4d6c1fd..9720df1119 100644 --- a/app/Transformers/QuoteTransformer.php +++ b/app/Transformers/QuoteTransformer.php @@ -11,8 +11,10 @@ namespace App\Transformers; +use App\Models\Document; use App\Models\Quote; use App\Models\QuoteInvitation; +use App\Transformers\DocumentTransformer; use App\Transformers\QuoteInvitationTransformer; use App\Utils\Traits\MakesHash; @@ -59,18 +61,14 @@ class QuoteTransformer extends EntityTransformer return $this->includeCollection($quote->expenses, $transformer, ENTITY_EXPENSE); } - - public function includeDocuments(quote $quote) - { - $transformer = new DocumentTransformer($this->account, $this->serializer); - - $quote->documents->each(function ($document) use ($quote) { - $document->setRelation('quote', $quote); - }); - - return $this->includeCollection($quote->documents, $transformer, ENTITY_DOCUMENT); - } */ + + public function includeDocuments(Quote $quote) + { + $transformer = new DocumentTransformer($this->serializer); + return $this->includeCollection($quote->documents, $transformer, Document::class); + } + public function transform(Quote $quote) { return [