PHP code example of darkling / invoice

1. Go to this page and download the library: Download darkling/invoice library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

darkling / invoice example snippets


// inside Presenter class

/** 
 * @var  IExporterFactory 
 * @inject 
 */
public $exporterFactory;



public function renderDefault() {

	$supplier = new Participant('Dodavatel Dodavatelovič', 'Ulička', 15, 'Městečko', '555 33');
	$supplier->setIn('562656959')->setTin('CZ562656959')->setAccountNumber('015160/15114');

	$customer = new Participant('Zákazník Zákazníkovič', 'Ulice', 51, 'Město', '333 55');

	$items[] = new Item('Item 1', 2, 100, Tax::fromPercent(21), TRUE);
	$items[] = new Item('Item 2', 1, 50, Tax::fromPercent(21), TRUE, 'kg');

	$data = new Data(1, 'Faktura', $supplier, $customer, new \DateTime('2016-01-01'), new \DateTime('2000-02-01'), $items);
	$data->setVariableSymbol('0101010')->setConstantSymbol('21212121')->setSpecificSymbol('313131313');

	$exporter = $this->exporterFactory->create($data);
	//$exporter->setTemplatePath(__DIR__ . '/path/to/your/template.latte');

	$name = __DIR__ . '/path/where/to/save/file.pdf';
	$pdf = $exporter->exportToPdf($name, Exporter::DEST_SAVE);
}