mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-30 20:43:52 -04:00 
			
		
		
		
	Clean design & filters
This commit is contained in:
		
							parent
							
								
									b7bdf3b341
								
							
						
					
					
						commit
						1f8ddc0642
					
				
							
								
								
									
										13
									
								
								tests/Feature/PdfMaker/Clean.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								tests/Feature/PdfMaker/Clean.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Tests\Feature\PdfMaker; | ||||
| 
 | ||||
| class Clean | ||||
| { | ||||
|     public function html() | ||||
|     { | ||||
|         return file_get_contents( | ||||
|             base_path('tests/Feature/PdfMaker/designs/clean.html') | ||||
|         ); | ||||
|     } | ||||
| } | ||||
| @ -16,6 +16,12 @@ class PdfMaker | ||||
| 
 | ||||
|     private $xpath; | ||||
| 
 | ||||
|     private $filters = [ | ||||
|         '<![CDATA[' => '', | ||||
|         ']]>' => '', | ||||
|         '<?xml version="1.0" encoding="utf-8" standalone="yes"??>' => '', | ||||
|     ]; | ||||
| 
 | ||||
|     public function __construct(array $data) | ||||
|     { | ||||
|         $this->data = $data; | ||||
| @ -43,8 +49,16 @@ class PdfMaker | ||||
|         return $this; | ||||
|     } | ||||
| 
 | ||||
|     public function getCompiledHTML() | ||||
|     public function getCompiledHTML($final = false) | ||||
|     { | ||||
|         if ($final) { | ||||
|             $html = $this->document->saveXML(); | ||||
| 
 | ||||
|             $filtered = strtr($html, $this->filters); | ||||
| 
 | ||||
|             return $filtered; | ||||
|         } | ||||
| 
 | ||||
|         return $this->document->saveXML(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -33,6 +33,8 @@ class PdfMakerDesignsTest extends TestCase | ||||
|                 '$terms' => 'Trend and SEO report has been sent via email. This is really long text just to test the width of the elements.', | ||||
| 
 | ||||
|                 '$invoice-issued-to' => 'Invoice issued to:', | ||||
| 
 | ||||
|                 '$entity' => 'Invoice', | ||||
|             ], | ||||
|         ]; | ||||
|     } | ||||
| @ -135,16 +137,110 @@ class PdfMakerDesignsTest extends TestCase | ||||
| 
 | ||||
|     public function testClean() | ||||
|     { | ||||
|         $state = []; | ||||
|         $state = [ | ||||
|             'template' => [ | ||||
|                 'company-details' => [ | ||||
|                     'id' => 'company-details', | ||||
|                     'elements' => [ | ||||
|                         ['element' => 'p', 'content' => 'Ninja Sample', 'properties' => ['class' => 'text-blue-500']], | ||||
|                         ['element' => 'p', 'content' => 'contact@invoiceninja.com'], | ||||
|                         ['element' => 'p', 'content' => '1-800-555-Ninja'], | ||||
|                     ], | ||||
|                 ], | ||||
|                 'company-address' => [ | ||||
|                     'id' => 'company-address', | ||||
|                     'elements' => [ | ||||
|                         ['element' => 'p', 'content' => '123 Ninja Blvd.'], | ||||
|                         ['element' => 'p', 'content' => 'NinjaLand, 97315'], | ||||
|                         ['element' => 'p', 'content' => 'United States'], | ||||
|                     ], | ||||
|                 ], | ||||
|                 'entity-details' => [ | ||||
|                     'id' => 'entity-details', | ||||
|                     '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' => '', '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', | ||||
|                     'elements' => [ | ||||
|                         ['element' => 'p', 'content' => 'Winterfield Medical Supply', 'properties' => ['class' => 'font-medium']], | ||||
|                         ['element' => 'p', 'content' => '65 Medical Complex Rd., D98'], | ||||
|                         ['element' => 'p', 'content' => 'Atlanta, GA 22546'], | ||||
|                         ['element' => 'p', 'content' => 'United States'], | ||||
|                         ['element' => 'p', 'content' => 'demo@invoiceninja.com'], | ||||
|                     ], | ||||
|                 ], | ||||
|                 'product-table' => [ | ||||
|                     'id' => 'product-table', | ||||
|                     'elements' => [ | ||||
|                         ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], 'elements' => [ | ||||
|                             ['element' => 'th', 'content' => 'Item', 'properties' => ['class' => 'font-semibold px-4 py-5']], | ||||
|                             ['element' => 'th', 'content' => 'Description', 'properties' => ['class' => 'font-semibold px-4 py-5']], | ||||
|                             ['element' => 'th', 'content' => 'Unit cost', 'properties' => ['class' => 'font-semibold px-4 py-5']], | ||||
|                             ['element' => 'th', 'content' => 'Quantity', 'properties' => ['class' => 'font-semibold px-4 py-5']], | ||||
|                             ['element' => 'th', 'content' => 'Line total', 'properties' => ['class' => 'font-semibold px-4 py-5']], | ||||
|                         ]], | ||||
|                         ['element' => 'tbody', 'content' => '', 'elements' => [ | ||||
|                             ['element' => 'tr', 'content' => '', 'elements' => [ | ||||
|                                 ['element' => 'td', 'content' => 'Painting service', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                                 ['element' => 'td', 'content' => '25 hours of painting', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                                 ['element' => 'td', 'content' => '885.00', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                                 ['element' => 'td', 'content' => '1', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                                 ['element' => 'td', 'content' => '$885.00', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                             ]], | ||||
|                             ['element' => 'tr', 'content' => '', 'elements' => [ | ||||
|                                 ['element' => 'td', 'content' => 'Painting service', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                                 ['element' => 'td', 'content' => '25 hours of painting', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                                 ['element' => 'td', 'content' => '885.00', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                                 ['element' => 'td', 'content' => '1', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                                 ['element' => 'td', 'content' => '$885.00', 'properties' => ['class' => 'border-t border-b px-4 py-4']], | ||||
|                             ]], | ||||
|                         ]], | ||||
|                         ['element' => 'tfoot', 'content' => '', 'elements' => [ | ||||
|                             ['element' => 'tr', 'content' => '', 'elements' => [ | ||||
|                                 ['element' => 'td', 'content' => 'Trend and SEO report has been sent via email. This is really long text just to test the width of the elements.', 'properties' => ['class' => 'border-l-4 border-white px-4 py-4', 'colspan' => '2']], | ||||
|                                 ['element' => 'td', 'content' => 'Subtotal', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']], | ||||
|                                 ['element' => 'td', 'content' => '$0', 'properties' => ['class' => 'px-4 py-4 text-right']], | ||||
|                             ]], | ||||
|                             ['element' => 'tr', 'content' => '', 'elements' => [ | ||||
|                                 ['element' => 'td', 'content' => 'Paid to date', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], | ||||
|                                 ['element' => 'td', 'content' => '$0.00', 'properties' => ['class' => 'px-4 py-4 text-right']], | ||||
|                             ]], | ||||
|                             ['element' => 'tr', 'content' => '', 'elements' => [ | ||||
|                                 ['element' => 'td', 'content' => 'Discount %20', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], | ||||
|                                 ['element' => 'td', 'content' => '$2.00', 'properties' => ['class' => 'px-4 py-4 text-right']], | ||||
|                             ]], | ||||
|                         ]], | ||||
|                     ], | ||||
|                 ], | ||||
|             ], | ||||
|             'variables' => array_merge([], $this->state['variables']), | ||||
|         ]; | ||||
| 
 | ||||
|         $maker = new PdfMaker($state); | ||||
| 
 | ||||
|         $maker | ||||
|             ->design(Business::class) | ||||
|             ->design(Clean::class) | ||||
|             ->build(); | ||||
| 
 | ||||
|         exec('echo "" > storage/logs/laravel.log'); | ||||
| 
 | ||||
|         info($maker->getCompiledHTML()); | ||||
|         info($maker->getCompiledHTML(true)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -6,7 +6,7 @@ | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||||
|     <meta http-equiv="x-ua-compatible" content="ie=edge"> | ||||
| 
 | ||||
|     <link rel="stylesheet" href="#css"> | ||||
|     <link rel="stylesheet" href="$css"> | ||||
| </head> | ||||
| 
 | ||||
| <style> | ||||
| @ -21,20 +21,20 @@ | ||||
|     } | ||||
| </style> | ||||
| 
 | ||||
| <body class="#global-margin bg-white break-words antialiased"> | ||||
| <body class="$global-margin bg-white break-words antialiased"> | ||||
|     <!-- Logo, company details & company address --> | ||||
|     <div class="flex grid items-start grid-cols-12 gap-4"> | ||||
|         <img src="#company-logo" alt="#company-name" class="grid w-24 col-span-4 sm:w-32"> | ||||
|         <img src="$company-logo" alt="$company-name" class="grid w-24 col-span-4 sm:w-32"> | ||||
|         <div class="grid grid-cols-2 col-span-8 space-x-10 text-gray-700 lg:col-start-8"> | ||||
|             <div id="company-details" class="col-span-1"></div> | ||||
|             <div id="company-address" class="col-span-1"></div> | ||||
|             <div id="company-details" class="col-span-1 text-gray-500"></div> | ||||
|             <div id="company-address" class="col-span-1 text-gray-500"></div> | ||||
|         </div> | ||||
|     </div> | ||||
| 
 | ||||
|     <!-- Client details, entity details --> | ||||
|     <div class="grid grid-cols-12 gap-4 my-12"> | ||||
|         <div class="col-span-6"> | ||||
|             <p>#invoice-issued-to</p> | ||||
|             <p>$invoice-issued-to</p> | ||||
|             <div id="client-details" class="mt-4 text-orange-600"></div> | ||||
|         </div> | ||||
|         <div class="col-span-6"> | ||||
| @ -50,14 +50,14 @@ | ||||
|     <!-- Balance due card --> | ||||
|     <div class="grid grid-cols-12 my-12"> | ||||
|         <div class="col-span-6"> | ||||
|             <p class="font-semibold">#terms-label</p> | ||||
|             <p>#terms</p> | ||||
|             <p class="font-semibold">$terms-label</p> | ||||
|             <p>$terms</p> | ||||
|         </div> | ||||
|         <div class="col-span-5 col-start-8 lg:col-start-9 lg:col-span-4"> | ||||
|             <div class="h-auto px-4 py-4 bg-orange-600 rounded-lg"> | ||||
|                 <div class="flex justify-between text-white"> | ||||
|                     <p>#balance-due-label</p> | ||||
|                     <p>#balance-due</p> | ||||
|                     <p>$balance-due-label</p> | ||||
|                     <p>$balance-due</p> | ||||
|                 </div> | ||||
|             </div> | ||||
|         </div> | ||||
|  | ||||
							
								
								
									
										37
									
								
								tests/Feature/PdfMaker/designs/clean.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								tests/Feature/PdfMaker/designs/clean.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| <!DOCTYPE html> | ||||
| <html> | ||||
| 
 | ||||
| <head> | ||||
|     <meta charset="utf-8"> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||||
|     <meta http-equiv="x-ua-compatible" content="ie=edge"> | ||||
| 
 | ||||
|     <link rel="stylesheet" href="$css"> | ||||
| </head> | ||||
| 
 | ||||
| <style> | ||||
|     #product-table tr:nth-child(even) { | ||||
|         background-color: #f7fafc; | ||||
|     } | ||||
| </style> | ||||
| 
 | ||||
| <body class="$global-margin bg-white break-words antialiased"> | ||||
|     <!-- Company logo, company details --> | ||||
|     <div class="grid grid-cols-12 px-2"> | ||||
|         <img src="$company-logo" alt="$company-name logo" class="grid w-24 col-span-4 sm:w-32"> | ||||
|         <div class="grid grid-cols-2 col-span-8 text-gray-700 lg:col-span-6"> | ||||
|             <div id="company-details" class="col-span-1"></div> | ||||
|             <div id="company-address" class="col-span-1"></div> | ||||
|         </div> | ||||
|     </div> | ||||
| 
 | ||||
|     <!-- Entity labels, client details --> | ||||
|     <p class="mt-10 text-xl text-blue-500 uppercase">$entity</p> | ||||
|     <div class="grid grid-cols-12 px-2 py-3 mt-4 border-t border-b"> | ||||
|         <table class="col-span-6 lg:col-span-5" id="entity-details"></table> | ||||
|         <div id="client-details" class="col-span-6"></div> | ||||
|     </div> | ||||
| 
 | ||||
|     <!-- Product table --> | ||||
|     <table id="product-table" class="table-auto"></table> | ||||
| </body> | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user