This commit is contained in:
Benjamin Beganović 2020-07-30 16:43:57 +02:00
parent cb4efc8c61
commit 70ee476193
6 changed files with 41 additions and 63 deletions

View File

@ -51,7 +51,7 @@ class Designer
'company4', 'company4',
]; ];
public function __construct($entity, $design, $input_variables, $entity_string) public function __construct($entity, $design, $input_variables, $entity_string)
{ {
$this->entity = $entity; $this->entity = $entity;

View File

@ -14,74 +14,48 @@ namespace App\Services\PdfMaker\Designs;
class Plain class Plain
{ {
public $elements;
public function html(): ?string public function html(): ?string
{ {
return file_get_contents( 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 [ return [
'company-address' => [ 'company-address' => [
'id' => 'company-address', 'id' => 'company-address',
'elements' => [ 'elements' => [
['element' => 'p', 'content' => '$company.address1'], ['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' => [ 'product-table' => [
'id' => 'entity-details', 'id' => 'product-table',
'elements' => [ 'elements' => [
['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left bg-gray-200'], 'elements' => $this->tableHeader($elements)],
['element' => 'th', 'content' => '$entity-number-label', 'properties' => ['class' => 'text-left pr-4 font-normal']], ['element' => 'tbody', 'content' => '', 'elements' => $this->tableBody()],
['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'],
], ],
], ],
]; ];
} }
}
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 [];
}
}

View File

@ -55,7 +55,7 @@ class PdfMaker
if (isset($this->data['variables'])) { if (isset($this->data['variables'])) {
$this->updateVariables($this->data['variables']); $this->updateVariables($this->data['variables']);
} }
return $this; return $this;
} }

View File

@ -117,7 +117,8 @@ trait PdfMakerUtilities
public function updateVariables(array $variables) public function updateVariables(array $variables)
{ {
$html = strtr($this->getCompiledHTML(), $variables['labels']); $html = strtr($this->getCompiledHTML(), $variables['labels']);
$html = strtr($this->getCompiledHTML(), $variables['values']);
$html = strtr($html, $variables['values']);
$this->document->loadHTML($html); $this->document->loadHTML($html);

View File

@ -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([ factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $user->id, 'user_id' => $user->id,
'client_id' => $c->id, 'client_id' => $c->id,
@ -173,10 +173,10 @@ class RandomDataSeeder extends Seeder
}); });
/** Product Factory */ /** 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 */ /** 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(); $invoices = Invoice::all();
$invoice_repo = new InvoiceRepository(); $invoice_repo = new InvoiceRepository();
@ -225,7 +225,7 @@ class RandomDataSeeder extends Seeder
}); });
/*Credits*/ /*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(); $credits = Credit::cursor();
$credit_repo = new CreditRepository(); $credit_repo = new CreditRepository();
@ -250,12 +250,12 @@ class RandomDataSeeder extends Seeder
}); });
/** Recurring Invoice Factory */ /** 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)]); // 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*/ /*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(); $quotes = Quote::cursor();
$quote_repo = new QuoteRepository(); $quote_repo = new QuoteRepository();

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\PdfMaker; namespace Tests\Feature\PdfMaker;
use App\Models\Design;
use App\Models\Invoice; use App\Models\Invoice;
use App\Services\PdfMaker\Designs\Plain; use App\Services\PdfMaker\Designs\Plain;
use App\Services\PdfMaker\PdfMaker; use App\Services\PdfMaker\PdfMaker;
@ -16,9 +17,11 @@ class ExampleIntegrationTest extends TestCase
$invitation = $invoice->invitations()->first(); $invitation = $invoice->invitations()->first();
$engine = new HtmlEngine($invitation, 'invoice'); $engine = new HtmlEngine($invitation, 'invoice');
$design = new Plain();
$state = [ $state = [
'template' => Plain::elements(), 'template' => $design->elements(json_decode(json_encode($invoice->company->settings->pdf_variables), 1)['product_columns']),
'variables' => $engine->generateLabelsAndValues(), 'variables' => $engine->generateLabelsAndValues(),
]; ];
@ -28,6 +31,6 @@ class ExampleIntegrationTest extends TestCase
->design(Plain::class) ->design(Plain::class)
->build(); ->build();
// info($maker->getCompiledHTML()); info($maker->getCompiledHTML());
} }
} }