diff --git a/app/Designs/Designer.php b/app/Designs/Designer.php index ea62c407ac64..5dd5bdfaafda 100644 --- a/app/Designs/Designer.php +++ b/app/Designs/Designer.php @@ -51,7 +51,7 @@ class Designer 'company4', ]; - public function __construct($entity, $design, $input_variables, $entity_string) +public function __construct($entity, $design, $input_variables, $entity_string) { $this->entity = $entity; diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 7c69b13de34c..54564ff25510 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -14,74 +14,48 @@ namespace App\Services\PdfMaker\Designs; class Plain { + public $elements; + + public function html(): ?string { return file_get_contents( - base_path('resources/views/pdf-designs//plain.html') + base_path('resources/views/pdf-designs/plain.html') ); } - public static function elements(): array + public function elements($elements): array { return [ 'company-address' => [ 'id' => 'company-address', 'elements' => [ ['element' => 'p', 'content' => '$company.address1'], - ['element' => 'p', 'content' => '$company.address2'], - ['element' => 'p', 'content' => '$company.city_state_postal'], - ['element' => 'p', 'content' => '$company.postal_city_state'], - ['element' => 'p', 'content' => '$company.country'], - ['element' => 'p', 'content' => '$company1'], - ['element' => 'p', 'content' => '$company2'], - ['element' => 'p', 'content' => '$company3'], - ['element' => 'p', 'content' => '$company4'], ], ], - 'entity-details' => [ - 'id' => 'entity-details', + 'product-table' => [ + 'id' => 'product-table', 'elements' => [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => '$entity-number-label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => '$entity-number', 'properties' => ['class' => 'text-left pr-4 font-medium']], - ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => '$entity-date-label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => '$entity-date', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => '$due-date-label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => '$due-date', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'bg-gray-200'], 'elements' => [ - ['element' => 'th', 'content' => '$balance-due-label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => '$balance-due', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ]], - ], - ], - 'client-details' => [ - 'id' => 'client-details', - 'properties' => ['hidden' => 'true'], - 'elements' => [ - ['element' => 'p', 'content' => '$client.name', 'properties' => ['class' => 'font-medium']], - ['element' => 'p', 'content' => '$client.id_number'], - ['element' => 'p', 'content' => '$client.vat_number'], - ['element' => 'p', 'content' => '$client.address1'], - ['element' => 'p', 'content' => '$client.address2'], - ['element' => 'p', 'content' => '$client.city_state_postal'], - ['element' => 'p', 'content' => '$client.postal_city_state'], - ['element' => 'p', 'content' => '$client.country'], - ['element' => 'p', 'content' => '$client.email'], - ['element' => 'p', 'content' => '$client.custom1'], - ['element' => 'p', 'content' => '$client.custom2'], - ['element' => 'p', 'content' => '$client.custom3'], - ['element' => 'p', 'content' => '$client.custom4'], - ['element' => 'p', 'content' => '$contact.custom1'], - ['element' => 'p', 'content' => '$contact.custom2'], - ['element' => 'p', 'content' => '$contact.custom3'], - ['element' => 'p', 'content' => '$contact.custom4'], + ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left bg-gray-200'], 'elements' => $this->tableHeader($elements)], + ['element' => 'tbody', 'content' => '', 'elements' => $this->tableBody()], ], ], ]; } -} \ No newline at end of file + + public function tableHeader($columns) + { + $elements = []; + + foreach ($columns as $column) { + $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'px-4 py-2']]; + } + + return $elements; + } + + public function tableBody() + { + return []; + } +} diff --git a/app/Services/PdfMaker/PdfMaker.php b/app/Services/PdfMaker/PdfMaker.php index 0aef04315cbc..7640b4d95c1b 100644 --- a/app/Services/PdfMaker/PdfMaker.php +++ b/app/Services/PdfMaker/PdfMaker.php @@ -55,7 +55,7 @@ class PdfMaker if (isset($this->data['variables'])) { $this->updateVariables($this->data['variables']); } - + return $this; } diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php index 56e57be52d0f..a696f5012fb5 100644 --- a/app/Services/PdfMaker/PdfMakerUtilities.php +++ b/app/Services/PdfMaker/PdfMakerUtilities.php @@ -117,7 +117,8 @@ trait PdfMakerUtilities public function updateVariables(array $variables) { $html = strtr($this->getCompiledHTML(), $variables['labels']); - $html = strtr($this->getCompiledHTML(), $variables['values']); + + $html = strtr($html, $variables['values']); $this->document->loadHTML($html); diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 10f6b1faad2a..013fe1df92ea 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -157,7 +157,7 @@ class RandomDataSeeder extends Seeder ]); - factory(\App\Models\Client::class, 10)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) { + factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) { factory(\App\Models\ClientContact::class, 1)->create([ 'user_id' => $user->id, 'client_id' => $c->id, @@ -173,10 +173,10 @@ class RandomDataSeeder extends Seeder }); /** Product Factory */ - factory(\App\Models\Product::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id]); + factory(\App\Models\Product::class, 2)->create(['user_id' => $user->id, 'company_id' => $company->id]); /** Invoice Factory */ - factory(\App\Models\Invoice::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); + factory(\App\Models\Invoice::class, 2)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); $invoices = Invoice::all(); $invoice_repo = new InvoiceRepository(); @@ -225,7 +225,7 @@ class RandomDataSeeder extends Seeder }); /*Credits*/ - factory(\App\Models\Credit::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); + factory(\App\Models\Credit::class, 2)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); $credits = Credit::cursor(); $credit_repo = new CreditRepository(); @@ -250,12 +250,12 @@ class RandomDataSeeder extends Seeder }); /** Recurring Invoice Factory */ - factory(\App\Models\RecurringInvoice::class, 10)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); + factory(\App\Models\RecurringInvoice::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); // factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]); /*Credits*/ - factory(\App\Models\Quote::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); + factory(\App\Models\Quote::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); $quotes = Quote::cursor(); $quote_repo = new QuoteRepository(); diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 0aa1e072ebb9..8aa201e09fcc 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\PdfMaker; +use App\Models\Design; use App\Models\Invoice; use App\Services\PdfMaker\Designs\Plain; use App\Services\PdfMaker\PdfMaker; @@ -16,9 +17,11 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine($invitation, 'invoice'); + $design = new Plain(); + $state = [ - 'template' => Plain::elements(), + 'template' => $design->elements(json_decode(json_encode($invoice->company->settings->pdf_variables), 1)['product_columns']), 'variables' => $engine->generateLabelsAndValues(), ]; @@ -28,6 +31,6 @@ class ExampleIntegrationTest extends TestCase ->design(Plain::class) ->build(); - // info($maker->getCompiledHTML()); + info($maker->getCompiledHTML()); } }