Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 73 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DefaultPdf | |
0.00% |
0 / 73 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| Header | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
72 | |||
| Footer | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package Modules\Media |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | /** |
| 16 | * Default PDF class. |
| 17 | * |
| 18 | * The TCPDF class must be included previously in the parent code. |
| 19 | * |
| 20 | * @package Modules\Media |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | * |
| 25 | * @link ../../../../../../Resources/tcpdf/TCPDF.php |
| 26 | */ |
| 27 | class DefaultPdf extends TCPDF |
| 28 | { |
| 29 | /** |
| 30 | * Font |
| 31 | * |
| 32 | * @var string |
| 33 | * @since 1.0.0 |
| 34 | */ |
| 35 | public string $fontName = ''; |
| 36 | |
| 37 | /** |
| 38 | * Font size |
| 39 | * |
| 40 | * @var int |
| 41 | * @since 1.0.0 |
| 42 | */ |
| 43 | public int $fontSize = 8; |
| 44 | |
| 45 | /** |
| 46 | * Side margins |
| 47 | * |
| 48 | * @var int |
| 49 | * @since 1.0.0 |
| 50 | */ |
| 51 | public int $sideMargin = 15; |
| 52 | |
| 53 | /** |
| 54 | * Template language |
| 55 | * |
| 56 | * @var string |
| 57 | * @since 1.0.0 |
| 58 | */ |
| 59 | public string $language = 'en'; |
| 60 | |
| 61 | /** |
| 62 | * Language components |
| 63 | * |
| 64 | * @var array<string, array<string, string>> |
| 65 | * @since 1.0.0 |
| 66 | */ |
| 67 | public array $lang = [ |
| 68 | 'en' => [ |
| 69 | 'Page' => 'Page', |
| 70 | 'CEO' => 'CEO', |
| 71 | 'TaxOffice' => 'Tax office', |
| 72 | 'TaxNumber' => 'Tax number', |
| 73 | 'Swift' => 'BIC', |
| 74 | 'BankAccount' => 'IBAN', |
| 75 | ], |
| 76 | 'de' => [ |
| 77 | 'Page' => 'Seite', |
| 78 | 'CEO' => 'Geschäftsführer', |
| 79 | 'TaxOffice' => 'Finanzamt', |
| 80 | 'TaxNumber' => 'Steuernummer', |
| 81 | 'Swift' => 'BIC', |
| 82 | 'BankAccount' => 'IBAN', |
| 83 | ], |
| 84 | ]; |
| 85 | |
| 86 | /** |
| 87 | * Bill attributes |
| 88 | * |
| 89 | * @var array<string, string> |
| 90 | * @since 1.0.0 |
| 91 | */ |
| 92 | public array $attributes = [ |
| 93 | 'logo' => __DIR__ . '/../Web/Backend/img/logo.png', |
| 94 | 'title_name' => 'Jingga', |
| 95 | 'slogan' => 'Business solutions made simple.', |
| 96 | 'legal_name' => '', |
| 97 | 'address' => '', |
| 98 | 'city' => '', |
| 99 | 'country' => '', |
| 100 | 'ceo' => '', |
| 101 | 'tax_office' => '', |
| 102 | 'tax_number' => '', |
| 103 | 'bank_name' => '', |
| 104 | 'swift' => '', |
| 105 | 'bank_account' => '', |
| 106 | 'website' => '', |
| 107 | 'email' => '', |
| 108 | 'phone' => '', |
| 109 | ]; |
| 110 | |
| 111 | /** |
| 112 | * Constructor. |
| 113 | * |
| 114 | * @since 1.0.0 |
| 115 | */ |
| 116 | public function __construct() |
| 117 | { |
| 118 | parent::__construct('P', 'mm', 'A4', true, 'UTF-8', false); |
| 119 | |
| 120 | // set default header data |
| 121 | $this->setHeaderData('', 15, $this->attributes['title_name'], $this->attributes['slogan']); |
| 122 | |
| 123 | // set header and footer fonts |
| 124 | $this->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); |
| 125 | $this->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
| 126 | |
| 127 | // set default monospaced font |
| 128 | $this->setDefaultMonospacedFont(PDF_FONT_MONOSPACED); |
| 129 | |
| 130 | // set margins |
| 131 | $this->setMargins(15, 30, 15); |
| 132 | |
| 133 | // set auto page breaks |
| 134 | $this->setAutoPageBreak(true, 25); |
| 135 | |
| 136 | // set image scale factor |
| 137 | $this->setImageScale(PDF_IMAGE_SCALE_RATIO); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Create header |
| 142 | * |
| 143 | * @return void |
| 144 | * |
| 145 | * @since 1.0.0 |
| 146 | */ |
| 147 | public function Header() : void |
| 148 | { |
| 149 | if ($this->header_xobjid === false) { |
| 150 | $this->header_xobjid = $this->startTemplate($this->w, 0); |
| 151 | |
| 152 | // Set Logo |
| 153 | if (!empty($this->header_logo)) { |
| 154 | $this->Image( |
| 155 | $this->header_logo, |
| 156 | 15, 15, |
| 157 | $this->header_logo_width, 0, |
| 158 | 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | // Set Title |
| 163 | $this->setFont('helvetica', 'B', 20); |
| 164 | $this->setX(15 + 15 + 3); |
| 165 | $this->Cell(0, 14, $this->header_title, 0, 0, 'L', false, '', 0, false, 'T', 'M'); |
| 166 | |
| 167 | $this->setFont('helvetica', '', 10); |
| 168 | $this->setX(15 + 15 + 3); |
| 169 | $this->Cell(0, 26, $this->header_string, 0, 0, 'L', false, '', 0, false, 'T', 'M'); |
| 170 | |
| 171 | $this->endTemplate(); |
| 172 | } |
| 173 | |
| 174 | $x = 0; |
| 175 | $dx = 0; |
| 176 | |
| 177 | if (!$this->header_xobj_autoreset && $this->booklet && (($this->page % 2) == 0)) { |
| 178 | // adjust margins for booklet mode |
| 179 | $dx = ($this->original_lMargin - $this->original_rMargin); |
| 180 | } |
| 181 | |
| 182 | $x = $this->rtl ? $this->w + $dx : 0 + $dx; |
| 183 | |
| 184 | $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false); |
| 185 | if ($this->header_xobj_autoreset) { |
| 186 | // reset header xobject template at each page |
| 187 | $this->header_xobjid = false; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Create footer |
| 193 | * |
| 194 | * @return void |
| 195 | * |
| 196 | * @since 1.0.0 |
| 197 | */ |
| 198 | public function Footer() : void |
| 199 | { |
| 200 | $this->setY(-25); |
| 201 | |
| 202 | $this->setFont('helvetica', 'I', 7); |
| 203 | $this->Cell($this->getPageWidth() - 22, 0, $this->lang[$this->language]['Page'] . ' '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, 0, 'R', false, '', 0, false, 'T', 'M'); |
| 204 | $this->Ln(); |
| 205 | $this->Ln(); |
| 206 | |
| 207 | $this->SetFillColor(245, 245, 245); |
| 208 | $this->setX(0); |
| 209 | $this->Cell($this->getPageWidth(), 25, '', 0, 0, 'L', true, '', 0, false, 'T', 'T'); |
| 210 | |
| 211 | $this->setFont('helvetica', '', 7); |
| 212 | $this->setXY(15 + 10, -15, true); |
| 213 | $this->MultiCell( |
| 214 | 30, 0, |
| 215 | $this->attributes['legal_name'] . "\n" |
| 216 | . $this->attributes['address'] . "\n" |
| 217 | . $this->attributes['city'], |
| 218 | 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B' |
| 219 | ); |
| 220 | |
| 221 | $this->setXY(25 + 15 + 20, -15, true); |
| 222 | $this->MultiCell( |
| 223 | 40, 0, |
| 224 | $this->lang[$this->language]['CEO']. ': ' . $this->attributes['ceo'] . "\n" |
| 225 | . $this->lang[$this->language]['TaxOffice']. ': ' . $this->attributes['tax_office'] . "\n" |
| 226 | . $this->lang[$this->language]['TaxNumber']. ': ' . $this->attributes['tax_number'], |
| 227 | 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B' |
| 228 | ); |
| 229 | |
| 230 | $this->setXY(25 + 45 + 15 + 30, -15, true); |
| 231 | $this->MultiCell( |
| 232 | 35, 0, |
| 233 | $this->attributes['bank_name'] . "\n" |
| 234 | . $this->lang[$this->language]['Swift']. ': ' . $this->attributes['swift'] . "\n" |
| 235 | . $this->lang[$this->language]['BankAccount']. ': ' . $this->attributes['bank_account'], |
| 236 | 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B' |
| 237 | ); |
| 238 | |
| 239 | $this->setXY(25 + 45 + 35 + 15 + 40, -15, true); |
| 240 | $this->MultiCell( |
| 241 | 35, 0, |
| 242 | $this->attributes['website'] . "\n" |
| 243 | . $this->attributes['email'] . "\n" |
| 244 | . $this->attributes['phone'], |
| 245 | 0, 'L', false, 1, null, null, true, 0, false, true, 0, 'B' |
| 246 | ); |
| 247 | } |
| 248 | } |