diff --git a/database/migrations/2023_09_21_042010_add_template_flag_to_designs_table.php b/database/migrations/2023_09_21_042010_add_template_flag_to_designs_table.php new file mode 100644 index 0000000000..cc0d75c2d0 --- /dev/null +++ b/database/migrations/2023_09_21_042010_add_template_flag_to_designs_table.php @@ -0,0 +1,25 @@ +boolean('is_template')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + } +}; diff --git a/tests/Feature/Template/TemplateTest.php b/tests/Feature/Template/TemplateTest.php new file mode 100644 index 0000000000..043d774790 --- /dev/null +++ b/tests/Feature/Template/TemplateTest.php @@ -0,0 +1,112 @@ +makeTestData(); + + $this->withoutMiddleware( + ThrottleRequests::class + ); + + } + + public function testTemplateGeneration() + { + $entity_obj = $this->invoice; + + $design = new Design(); + $design->design = json_decode(json_encode($this->invoice->company->settings->pdf_variables), true); + $design->name = 'test'; + $design->is_active = true; + $design->is_template = true; + $design->is_custom = true; + $design->user_id = $this->invoice->user_id; + $design->company_id = $this->invoice->company_id; + + $design_object = new \stdClass; + $design_object->includes = ''; + $design_object->header = ''; + $design_object->body = ''; + $design_object->product = ''; + $design_object->task = ''; + $design_object->footer = ''; + + $design->design = $design_object; + + $design->save(); + + App::forgetInstance('translator'); + $t = app('translator'); + App::setLocale($entity_obj->client->locale()); + $t->replace(Ninja::transformTranslations($entity_obj->client->getMergedSettings())); + + $html = new HtmlEngine($entity_obj->invitations()->first()); + + /** @var \App\Models\Design $design */ + $design = \App\Models\Design::withTrashed()->find($entity_obj->design_id); + + $options = [ + 'custom_partials' => json_decode(json_encode($design->design), true), + ]; + $template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options); + + $variables = $html->generateLabelsAndValues(); + + $state = [ + 'template' => $template->elements([ + 'client' => $entity_obj->client, + 'entity' => $entity_obj, + 'pdf_variables' => (array) $entity_obj->company->settings->pdf_variables, + '$product' => $design->design->product, + 'variables' => $variables, + ]), + 'variables' => $variables, + 'options' => [ + 'all_pages_header' => $entity_obj->client->getSetting('all_pages_header'), + 'all_pages_footer' => $entity_obj->client->getSetting('all_pages_footer'), + 'client' => $entity_obj->client, + 'entity' => $entity_obj, + 'variables' => $variables, + ], + 'process_markdown' => $entity_obj->client->company->markdown_enabled, + ]; + + $maker = new PdfMaker($state); + + + } +} \ No newline at end of file