create purchase order pdf

This commit is contained in:
Manuel Raynaud
2013-10-03 10:45:21 +02:00
parent 9fcbeab69c
commit 6e29325d19
9 changed files with 353 additions and 23 deletions

View File

@@ -38,7 +38,7 @@ class Pdf extends BaseAction implements EventSubscriberInterface
public function generatePdf(PdfEvent $event)
{
$html2pdf = new \HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', array(0,0,0,0));
$html2pdf = new \HTML2PDF($event->getOrientation(), $event->getFormat(), $event->getLang(), $event->getUnicode(), $event->getEncoding(), $event->getMarges());
$html2pdf->pdf->SetDisplayMode('real');

View File

@@ -155,6 +155,11 @@
<requirement key="order_id">\d+</requirement>
</route>
<route id="admin.order.pdf.invoice" path="/admin/order/pdf/delivery/{order_id}">
<default key="_controller">Thelia\Controller\Admin\OrderController::generateDeliveryPdf</default>
<requirement key="order_id">\d+</requirement>
</route>
<!-- end order management -->
<!-- Categories management -->

View File

@@ -198,12 +198,22 @@ class OrderController extends BaseAdminController
}
public function generateInvoicePdf($order_id)
{
return $this->generatePdf($order_id, ConfigQuery::read('pdf_invoice_file', 'invoice'));
}
public function generateDeliveryPdf($order_id)
{
return $this->generatePdf($order_id, ConfigQuery::read('pdf_delivery_file', 'delivery'));
}
protected function generatePdf($order_id, $fileName)
{
if (null !== $response = $this->checkAuth("admin.order.update")) return $response;
$html = $this->renderRaw(
ConfigQuery::read('pdf_invoice_file', 'invoice'),
$fileName,
array(
'order_id' => $order_id
),

View File

@@ -35,9 +35,31 @@ class PdfEvent extends ActionEvent
protected $pdf;
public function __construct($content)
protected $orientation;
protected $format;
protected $lang;
protected $unicode;
protected $encoding;
protected $marges;
/**
* @param $content html content to transform into pdf
* @param string $orientation page orientation, same as TCPDF
* @param string $format The format used for pages, same as TCPDF
* @param string $lang Lang : fr, en, it...
* @param bool $unicode TRUE means that the input text is unicode (default = true)
* @param string $encoding charset encoding; default is UTF-8
* @param array $marges Default marges (left, top, right, bottom)
*/
public function __construct($content, $orientation = 'P', $format = 'A4', $lang='fr', $unicode=true, $encoding='UTF-8',array $marges = array(0, 0, 0, 0))
{
$this->content = $content;
$this->orientation = $orientation;
$this->format = $format;
$this->lang = $lang;
$this->unicode = $unicode;
$this->encoding = $encoding;
$this->marges = $marges;
}
/**
@@ -70,4 +92,102 @@ class PdfEvent extends ActionEvent
{
return null !== $this->pdf;
}
/**
* @param mixed $encoding
*/
public function setEncoding($encoding)
{
$this->encoding = $encoding;
}
/**
* @return mixed
*/
public function getEncoding()
{
return $this->encoding;
}
/**
* @param mixed $format
*/
public function setFormat($format)
{
$this->format = $format;
}
/**
* @return mixed
*/
public function getFormat()
{
return $this->format;
}
/**
* @param mixed $lang
*/
public function setLang($lang)
{
$this->lang = $lang;
}
/**
* @return mixed
*/
public function getLang()
{
return $this->lang;
}
/**
* @param mixed $marges
*/
public function setMarges($marges)
{
$this->marges = $marges;
}
/**
* @return mixed
*/
public function getMarges()
{
return $this->marges;
}
/**
* @param mixed $orientation
*/
public function setOrientation($orientation)
{
$this->orientation = $orientation;
}
/**
* @return mixed
*/
public function getOrientation()
{
return $this->orientation;
}
/**
* @param mixed $unicode
*/
public function setUnicode($unicode)
{
$this->unicode = $unicode;
}
/**
* @return mixed
*/
public function getUnicode()
{
return $this->unicode;
}
}

View File

@@ -30,6 +30,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Security\SecurityContext;
use Thelia\Core\Template\ParserContext;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CategoryQuery;
use Thelia\Model\ContentQuery;
use Thelia\Model\CountryQuery;
@@ -234,6 +235,17 @@ class DataAccessFunctions extends AbstractSmartyPlugin
return $this->dataAccess("Lang", $params, $this->request->getSession()->getLang());
}
public function ConfigDataAccess($params, $smarty)
{
if(false === array_key_exists("key", $params)) {
return null;
}
$key = $params['key'];
return ConfigQuery::read($key);
}
/**
* @param $objectLabel
* @param $params
@@ -344,6 +356,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'),
new SmartyPluginDescriptor('function', 'cart', $this, 'cartDataAccess'),
new SmartyPluginDescriptor('function', 'order', $this, 'orderDataAccess'),
new SmartyPluginDescriptor('function', 'config', $this, 'ConfigDataAccess'),
);
}

View File

@@ -27,7 +27,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
('thelia_admin_remember_me_cookie_expiration', 2592000, 0, 0, NOW(), NOW()),
('thelia_customer_remember_me_cookie_name', 'tcrmcn', 0, 0, NOW(), NOW()),
('thelia_customer_remember_me_cookie_expiration', 31536000, 0, 0, NOW(), NOW()),
('session_config.handlers', 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeFileSessionHandler', 0, 0, NOW(), NOW())
('session_config.handlers', 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeFileSessionHandler', 0, 0, NOW(), NOW()),
('company_name','', 0, 0, NOW(), NOW())
;

View File

@@ -268,7 +268,7 @@
<caption class="clearfix">
{intl l='Delivery address'}
<div class="pull-right">
<a class="btn btn-default btn-primary" title="{intl l='Download purchase order as PDF'}" href="#">
<a class="btn btn-default btn-primary" title="{intl l='Download purchase order as PDF'}" href="{url path="/admin/order/pdf/delivery/$ID"}">
<span class="glyphicon glyphicon-cloud-download"></span> {intl l='PDF | Purchase order'}
</a>
<a class="btn btn-default btn-primary js-update-order-address" data-address-id="{$DELIVERY_ADDRESS}" title="{intl l='Edit delivery address'}" href="#edit_order_address_dialog" data-toggle="modal">

193
templates/pdf/delivery.html Normal file
View File

@@ -0,0 +1,193 @@
<!--
THELIA - Modèle de bon de livraison
Pour plus d'information sur les possibilités de mise en page, merci de consulter
la documentation de html2pdf: http://html2pdf.fr/
-->
<style type="text/css">
<!--
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}
<!-- En-tete du document -->
<table style="padding-bottom: 5mm;">
<col style="width:50%; padding: 0; border: none;" />
<col style="width:50%; padding: 0; border: none;" />
<tr>
<!-- A gauche: informations sur le BL -->
<td valign="bottom">
<div style="text-align: center; padding-bottom: 5mm;">
<h1 style="font-size: 5mm;">
{config key="company_name"}
<!-- Vous pouvez remplacer #VARIABLE(nomsite) par le nom de votre entreprise -->
</h1>
<!--
<p> Vous pouvez insérer ici l'adresse de votre entreprise</p>
-->
<h2 style="font-size: 5mm;">{intl l='Delivery module'}<br />{$DELIVERY_REF}</h2>
</div>
<table style="width: 80%">
<col style="width:50%;text-align: center;" />
<col style="width:50%;text-align: center;" />
<tr>
<th>{intl l="invoice ref"}</th>
<th>{intl l="invoice date"}</th>
</tr>
<tr>
<td>{$REF}</td>
<td>{format_date date=$INVOICE_DATE}</td>
</tr>
</table>
<table style="width: 80%; margin-top: 3mm;">
<col style="width:50%;text-align: center;" />
<col style="width:50%;text-align: center;" />
<tr>
<th>{intl l="invoice"} </th>
<th>{intl l="customer number"}</th>
</tr>
<tr>
<td>{$INVOICE_REF}</td>
<td>{loop type="customer" name="customer.invoice" id=$CUSTOMER current="0"}{$REF}{/loop}</td>
</tr>
</table>
</td>
<!-- A droite: adresses de livraison et de facturation -->
<td 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>
<!-- Liste des articles -->
<table>
<col style="width: 20%;" />
<col style="width: 65%;" />
<col style="width: 15%; text-align: right" />
<thead>
<tr>
<th style="text-align: center;">{intl l="Ref"}</th>
<th style="text-align: center;">{intl l="product"}</th>
<th style="text-align: center;">{intl l="Quantity"}</th>
</tr>
</thead>
<tbody>
{loop type="order_product" name="order-products" order=$ID}
<tr>
<td>{$REF}</td>
<td>{$TITLE}</td>
<td>{$QUANTITY}</td>
</tr>
{/loop}
</tbody>
</table>
<!-- Mode de livraison -->
<table style="width: 100%; margin-top: 5mm;">
<col style="width: 20%;" />
<col style="width: 80%;" />
<tbody>
<tr>
<th>{intl l="delivery module"}</th>
<td>{loop name="delivery-module" type="module" id=$DELIVERY_MODULE}{$TITLE}{/loop}</td>
</tr>
</tbody>
</table>
{/loop}
</page>

View File

@@ -59,7 +59,7 @@
<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>
<h1>{config key="company_name"}</h1>
<p><!-- Insérer ici l'adresse de votre entreprise --></p>
<h2>{intl l="invoice"} {$INVOICE_REF}</h2>
</div>
@@ -73,7 +73,7 @@
<tr>
<td>{$REF}</td>
<td>{loop type="customer" name="customer.invoice" id=$CUSTOMER}$REF{/loop}</td>
<td>{loop type="customer" name="customer.invoice" id=$CUSTOMER current="0"}{$REF}{/loop}</td>
<td>{format_date date=$INVOICE_DATE}</td>
</tr>
</table>
@@ -185,24 +185,12 @@
<tbody>
<tr>
<th>::Mode de règlement::</th>
<td>#PAIEMENTTITRE</td>
<th>{intl l="Payment module"}</th>
<td>{loop name="payment-module" type="module" id=$PAYMENT_MODULE}{$TITLE}{/loop}</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>
<th>{intl l="delivery module"}</th>
<td>{loop name="delivery-module" type="module" id=$DELIVERY_MODULE}{$TITLE}{/loop}</td>
</tr>
</tbody>
</table>