complete invoice pdf template

This commit is contained in:
Manuel Raynaud
2013-10-02 18:03:25 +02:00
parent df08809a48
commit 9fcbeab69c
6 changed files with 367 additions and 70 deletions

View File

@@ -39,7 +39,7 @@
"symfony/icu": "1.0", "symfony/icu": "1.0",
"swiftmailer/swiftmailer": "5.0.*", "swiftmailer/swiftmailer": "5.0.*",
"symfony/serializer": "2.3.*", "symfony/serializer": "2.3.*",
"dompdf/dompdf": "dev-master" "ensepar/html2pdf": "1.0.1"
}, },
"require-dev" : { "require-dev" : {
"phpunit/phpunit": "3.7.*", "phpunit/phpunit": "3.7.*",

168
composer.lock generated
View File

@@ -3,30 +3,31 @@
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
], ],
"hash": "39e5fa13bfa3de21f03854c90a076713", "hash": "852879ecc2e39e5cf283a3b1c5051a8e",
"packages": [ "packages": [
{ {
"name": "dompdf/dompdf", "name": "ensepar/html2pdf",
"version": "dev-master", "version": "1.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/dompdf/dompdf.git", "url": "https://github.com/OwlyCode/html2pdf.git",
"reference": "3a8a09240159ac084f0c4b607eb12ca83ddbe318" "reference": "b53a27430cc35b29bbe2faaa55ed4a7d5c156cd3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/3a8a09240159ac084f0c4b607eb12ca83ddbe318", "url": "https://api.github.com/repos/OwlyCode/html2pdf/zipball/b53a27430cc35b29bbe2faaa55ed4a7d5c156cd3",
"reference": "3a8a09240159ac084f0c4b607eb12ca83ddbe318", "reference": "b53a27430cc35b29bbe2faaa55ed4a7d5c156cd3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"phenx/php-font-lib": "0.2.*" "ensepar/tcpdf": "5.0.003",
"php": ">=5.2"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
"classmap": [ "psr-0": {
"include/" "HTML2PDF": "."
] }
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
"license": [ "license": [
@@ -34,17 +35,79 @@
], ],
"authors": [ "authors": [
{ {
"name": "Fabien Ménager", "name": "Spipu",
"email": "fabien.menager@gmail.com" "homepage": "http://sourceforge.net/users/spipu",
"role": "Developer"
}, },
{ {
"name": "Brian Sweeney", "name": "OwlyCode",
"email": "eclecticgeek@gmail.com" "homepage": "http://www.github.com/OwlyCode",
"role": "Developer"
} }
], ],
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", "description": "Unofficial fork of 'html2pdf' with Composer support. (Fixed composer dependency problem)",
"homepage": "https://github.com/dompdf/dompdf", "homepage": "https://github.com/jwronsky/html2pdf",
"time": "2013-09-04 20:59:58" "keywords": [
"html",
"html2pdf",
"pdf"
],
"time": "2013-09-13 12:23:43"
},
{
"name": "ensepar/tcpdf",
"version": "5.0.003",
"source": {
"type": "git",
"url": "https://github.com/OwlyCode/tcpdf.git",
"reference": "ae578409e9454fdf6c794cce6f063b0c95bfa518"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/OwlyCode/tcpdf/zipball/ae578409e9454fdf6c794cce6f063b0c95bfa518",
"reference": "ae578409e9454fdf6c794cce6f063b0c95bfa518",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"classmap": [
"fonts",
"config/lang",
"config",
"2dbarcodes.php",
"barcodes.php",
"htmlcolors.php",
"qrcode.php",
"tcpdf.php",
"unicode_data.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPLv3"
],
"authors": [
{
"name": "Nicola Asuni",
"email": "info@tecnick.com",
"homepage": "http://nicolaasuni.tecnick.com"
},
{
"name": "Tristan Maindron",
"email": "tmaindron@gmail.com",
"homepage": "http://www.github.com/OwlyCode"
}
],
"description": "TCPDF is a PHP class for generating PDF documents.",
"homepage": "http://www.tcpdf.org/",
"keywords": [
"TCPDF",
"pdf"
],
"time": "2013-09-12 17:00:40"
}, },
{ {
"name": "imagine/imagine", "name": "imagine/imagine",
@@ -249,40 +312,6 @@
"homepage": "http://leafo.net/lessphp/", "homepage": "http://leafo.net/lessphp/",
"time": "2013-08-09 17:09:19" "time": "2013-08-09 17:09:19"
}, },
{
"name": "phenx/php-font-lib",
"version": "0.2.1",
"source": {
"type": "git",
"url": "https://github.com/PhenX/php-font-lib.git",
"reference": "42a1ca6d19f14076911a118705b771c3a5a8b179"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/42a1ca6d19f14076911a118705b771c3a5a8b179",
"reference": "42a1ca6d19f14076911a118705b771c3a5a8b179",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"classes/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
}
],
"description": "A library to read, parse, export and make subsets of different types of font files.",
"homepage": "https://github.com/PhenX/php-font-lib",
"time": "2013-02-22 23:30:49"
},
{ {
"name": "propel/propel", "name": "propel/propel",
"version": "dev-master", "version": "dev-master",
@@ -1838,6 +1867,40 @@
], ],
"time": "2013-09-11 13:01:19" "time": "2013-09-11 13:01:19"
}, },
{
"name": "phenx/php-font-lib",
"version": "0.2.1",
"source": {
"type": "git",
"url": "https://github.com/PhenX/php-font-lib.git",
"reference": "42a1ca6d19f14076911a118705b771c3a5a8b179"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/42a1ca6d19f14076911a118705b771c3a5a8b179",
"reference": "42a1ca6d19f14076911a118705b771c3a5a8b179",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"classes/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL"
],
"authors": [
{
"name": "Fabien Ménager",
"email": "fabien.menager@gmail.com"
}
],
"description": "A library to read, parse, export and make subsets of different types of font files.",
"homepage": "https://github.com/PhenX/php-font-lib",
"time": "2013-02-22 23:30:49"
},
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "1.2.12", "version": "1.2.12",
@@ -2218,7 +2281,6 @@
"ptachoire/cssembed": 20, "ptachoire/cssembed": 20,
"simplepie/simplepie": 20, "simplepie/simplepie": 20,
"imagine/imagine": 20, "imagine/imagine": 20,
"dompdf/dompdf": 20,
"fzaninotto/faker": 20, "fzaninotto/faker": 20,
"maximebf/debugbar": 20 "maximebf/debugbar": 20
}, },

View File

@@ -12,7 +12,6 @@ define('THELIA_MODULE_DIR' , THELIA_LOCAL_DIR . 'modules/');
define('THELIA_WEB_DIR' , THELIA_ROOT . 'web/'); define('THELIA_WEB_DIR' , THELIA_ROOT . 'web/');
define('THELIA_TEMPLATE_DIR' , THELIA_ROOT . 'templates/'); define('THELIA_TEMPLATE_DIR' , THELIA_ROOT . 'templates/');
define('DS', DIRECTORY_SEPARATOR); define('DS', DIRECTORY_SEPARATOR);
define('DOMPDF_ENABLE_AUTOLOAD', false);
$loader = require __DIR__ . "/vendor/autoload.php"; $loader = require __DIR__ . "/vendor/autoload.php";

View File

@@ -37,13 +37,13 @@ class Pdf extends BaseAction implements EventSubscriberInterface
public function generatePdf(PdfEvent $event) public function generatePdf(PdfEvent $event)
{ {
require_once THELIA_ROOT . '/core/vendor/dompdf/dompdf/dompdf_config.inc.php';
$domPdf = new \DOMPDF(); $html2pdf = new \HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', array(0,0,0,0));
$domPdf->load_html($event->getContent());
$domPdf->render();
$event->setPdf($domPdf->output()); $html2pdf->pdf->SetDisplayMode('real');
$html2pdf->writeHTML($event->getContent());
$event->setPdf($html2pdf->output(null, 'S'));
} }
/** /**

View File

@@ -226,7 +226,7 @@ class OrderController extends BaseAdminController
} }
} catch (\Exception $e) { } catch (\Exception $e) {
\Thelia\Log\Tlog::getInstance()->error(sprintf('error during generating invoice pdf for order id : %d', $order_id)); \Thelia\Log\Tlog::getInstance()->error(sprintf('error during generating invoice pdf for order id : %d with message "%s"', $order_id, $e->getMessage()));
} }

View File

@@ -1,9 +1,245 @@
<!DOCTYPE html> <!--
<html> THELIA - Modèle de facture
<head>
<title>REF</title> Pour plus d'information sur les possibilités de mise en page, merci de consulter
</head> la documentation de html2pdf: http://html2pdf.fr/
<body> -->
generate invoice
</body> <style type="text/css">
</html> <!--
table {
border-collapse: collapse;
width: 100%;
}
td,th {
padding: 1.5mm;
border: 0.2mm solid #333;
}
th {
background-color: #D83C46;
color: #fff;
text-align: center;
font-weight: normal;
}
td.total {
background-color: #ccc;
font-weight: bold;
}
-->
</style>
<page backtop="10mm" backleft="10mm" backright="10mm" backbottom="10mm">
<page_header>
</page_header>
<page_footer>
<table>
<col style="width: 80%; padding: 3mm; border: none; text-align: center;" />
<col style="width: 20%; padding: 3mm; border: none; text-align: right;" />
<tbody>
<tr>
<td><!-- Insérer ici les mentions légales --></td>
<td>{intl l="Page"} [[page_cu]]/[[page_nb]]</td>
</tr>
</tbody>
</table>
</page_footer>
{loop name="order.invoice" type="order" id=$order_id customer="*"}
{loop name="currency.order" type="currency" id=$CURRENCY}
{assign "orderCurrency" $SYMBOL}
{/loop}
<table style="padding-bottom: 5mm;">
<tr>
<td style="width:50%; padding: 0; border: none;" valign="bottom">
<div style="text-align: center; padding-bottom: 10mm;">
<h1>#VARIABLE(nomsite)<!-- Vous pouvez remplacer #VARIABLE(nomsite) par le nom de votre entreprise --></h1>
<p><!-- Insérer ici l'adresse de votre entreprise --></p>
<h2>{intl l="invoice"} {$INVOICE_REF}</h2>
</div>
<table style="width: 100%">
<tr>
<th>{intl l="invoice ref"}</th>
<th>{intl l="customer number"}</th>
<th>{intl l="invoice date"}</th>
</tr>
<tr>
<td>{$REF}</td>
<td>{loop type="customer" name="customer.invoice" id=$CUSTOMER}$REF{/loop}</td>
<td>{format_date date=$INVOICE_DATE}</td>
</tr>
</table>
</td>
<td style="width:50%; padding: 0; border: none;" valign="bottom">
<table style="padding-bottom: 5mm;">
<tr>
<th style="width: 100%; text-align: left;">{intl l="delivery address"}</th>
</tr>
<tr>
<td>
{loop type="order_address" name="delivery_address" id=$DELIVERY_ADDRESS}
{loop type="title" name="order-invoice-address-title" id=$TITLE}{$LONG}{/loop}{$FIRSTNAME} {$LASTNAME}<br />
{$ADDRESS1} {$ADDRESS2} {$ADDRESS3}<br />
{$ZIPCODE} {$COUNTRY}<br/>
{loop type="country" name="country_delivery" id=$COUNTRY}{$TITLE}{/loop}
{/loop}
</td>
</tr>
</table>
<table>
<tr>
<th style="width: 100%; text-align: left;">{intl l="invoice address"}</th>
</tr>
<tr>
<td>
{loop type="order_address" name="delivery_address" id=$INVOICE_ADDRESS}
{loop type="title" name="order-invoice-address-title" id=$TITLE}{$LONG}{/loop}{$FIRSTNAME} {$LASTNAME}<br />
{$ADDRESS1} {$ADDRESS2} {$ADDRESS3}<br />
{$ZIPCODE} {$COUNTRY}<br/>
{loop type="country" name="country_delivery" id=$COUNTRY}{$TITLE}{/loop}
{/loop}
</td>
</tr>
</table>
</td>
</tr>
</table>
<table>
<col style="width: 38%;" />
<col style="width: 15%;" />
<col style="width: 15%; text-align: right" />
<col style="width: 12%; text-align: right" />
<col style="width: 5%; text-align: right" />
<col style="width: 15%; text-align: right" />
<thead>
<tr>
<th style="text-align: center;">{intl l="Product"}</th>
<th style="text-align: center;">{intl l="Unit. price"}</th>
<th style="text-align: center;">{intl l="Tax"}</th>
<th style="text-align: center;">{intl l="Unit taxed price"}</th>
<th style="text-align: center;">{intl l="Quantity"}</th>
<th style="text-align: center;">{intl l="Taxed total"}</th>
</tr>
</thead>
<tbody>
{loop type="order_product" name="order-products" order=$ID}
{if $WAS_IN_PROMO == 1}
{assign "realPrice" $PROMO_PRICE}
{assign "realTax" $PROMO_PRICE_TAX}
{assign "realTaxedPrice" $TAXED_PROMO_PRICE}
{else}
{assign "realPrice" $PRICE}
{assign "realTax" $PRICE_TAX}
{assign "realTaxedPrice" $TAXED_PRICE}
{/if}
<tr>
<td>
{$TITLE}
{ifloop rel="combinations"}
{loop type="order_product_attribute_combination" name="combinations" order_product=$ID}
{$ATTRIBUTE_TITLE} - {$ATTRIBUTE_AVAILABILITY_TITLE}<br>
{/loop}
{/ifloop}
</td>
<td>{$orderCurrency} {$realPrice}</td>
<td>{$orderCurrency} {$realTax}</td>
<td>{$orderCurrency} {$realTaxedPrice}</td>
<td>{$QUANTITY}</td>
<td>{$orderCurrency} {$realTaxedPrice * $QUANTITY}</td>
</tr>
{/loop}
</tbody>
</table>
<!-- Pied du tableau -->
<table>
<col style="width: 65%;" />
<col style="width: 35%;" />
<tr>
<td style="padding: 0; padding-top: 5mm; border: none;">
<table style="width: 90%; padding-bottom: 5mm;">
<col style="width: 35%; text-align: right;" />
<col style="width: 65%;" />
<tbody>
<tr>
<th>::Mode de règlement::</th>
<td>#PAIEMENTTITRE</td>
</tr>
<tr>
<th>::Mode de livraison::</th>
<td>#TRANSPORTTITRE</td>
</tr>
</tbody>
</table>
<table style="width: 90%;">
<col style="width: 100%; text-align: left;" />
<tbody>
<tr>
<th>::Zone de correspondance::</th>
</tr>
<tr>
<td style="height: 20mm;"></td>
</tr>
</tbody>
</table>
</td>
<td valign="top" style="padding: 0;padding-top: 5mm; border: none;">
<table style="padding-bottom: 5mm;">
<col style="width: 58%; text-align: right;" />
<col style="width: 42%; text-align: right;" />
<tbody>
<tr>
<td>{intl l="Total without tax"}</td>
<td>{$orderCurrency} {$TOTAL_AMOUNT}</td>
</tr>
<tr>
<td>{intl l="Total with tax"}</td>
<td>{$orderCurrency} {$TOTAL_TAXED_AMOUNT - $POSTAGE}</td>
</tr>
<tr>
<td>{intl l="Postage"}</td>
<td>{$orderCurrency} {$POSTAGE}</td>
</tr>
<tr>
<td class="total">{intl l="Total"}</td>
<td class="total">{$orderCurrency} {$TOTAL_TAXED_AMOUNT}</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
{/loop}
</page>