/ generate_document.md
generate_document.md
1 # 1. Contents 2 3 - [1. Contents](#1--contents) 4 - [2. Features](#2--features) 5 - [2.1. Generate Document](#21-generate-document) 6 - [2.2. Settings](#22-settings) 7 - [3. Getting started](#3-getting-started) 8 - [4. Additional Notes](#4-additional-notes) 9 - [4.1. Adding New Types of Documents and Templates](#41-adding-new-types-of-documents-and-templates) 10 - [4.2. Helpers](#42-helpers) 11 - [5. Bibliography](#5-bibliography) 12 13 # 2. Features 14 15 ## 2.1. Generate Document 16 17 SGOC is equipped to generate documents with a PDF extension by using templates in the docx format. These templates utilize tokens as keys to achieve dynamic document generation. 18 19 SGOC allows the integration of new types of documents and templates, which will be explained in the [Additional Notes Section](#41-adding-new-types-of-documents-and-templates). 20 21 ## 2.2. Settings 22 23 SGOC has a section of options where you can configure the head, email, colors, and logo that should appear in the generated document. 24 25 | Token | Description | 26 | ------------- | ---------------------------------- | 27 | ${sgoc_email} | The value that the email will have | 28 | ${sgoc_head} | The value that the head will have | 29 30 # 3. Getting started 31 32 - Make sure the docker image has been built . 33 - You should have a template prepared with a .docx extension containing the information you want to print. Remember that the token should be presented as follows: ${token} (token can be another name). 34 - In the documents section of the project or dossier, you should click on internal documentation, select the document type, language, and template. 35 - Once generated, the document can be approved, reviewed, and downloaded with the signature already included in PDF format. 36 37 # 4. Additional Notes 38 39 # 4.1. Adding New Types of Documents and Templates 40 41 - If you need to extend the types of documents you want to generate, you should add it to the data insertion seeder in the following way: 42 43 ```php 44 DocumentType::create([ 45 'code' => 'XXX', 46 'description' => 'Internal', 47 'internal' => true, 48 'validate' => false|true, 49 'approve' => false|true, 50 ]); 51 ``` 52 53 - If you need to add other templates, these templates should be added to the data insertion seeder in the following way: 54 55 ```php 56 Template::create([ 57 'name' => 'filename-EN-v1', 58 'path' => 'path/filename-EN-v1.docx', 59 'filename' => 'filename-EN-v1.docx', 60 'document_type_id' => document_type_id, 61 ]); 62 ``` 63 64 - In case you want to display more than one language different from the default one, you should add it to the `AvailableLanguagesTrait` trait so that SGOC adjusts to the configuration. 65 66 - Once everything is configured, you should run a new migration. If the application has not been put into production yet, execute the command 67 `sail php artisan migrate:fresh --seed` to generate new PDF documents based on the template. If the application is in production, you only need to add the document type and the template to the database. 68 69 # 4.2. Helpers 70 71 - The helper will be necessary in case you need to create a new type of document for a template: 72 73 - BaseDocGen is the parent class from which each of the other helpers originates. It will contain common functions. 74 - XXXTemplateDocGen will be the name given to the specific helper for that template, which will contain functions to process the specific tokens of that template. 75 76 # 5. Bibliography 77 78 - [PhpWord](https://phpword.readthedocs.io/en/latest/)