From 6e29325d19d5603f731b513e89072a3069d0ca0d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 3 Oct 2013 10:45:21 +0200 Subject: [PATCH] create purchase order pdf --- core/lib/Thelia/Action/Pdf.php | 2 +- .../Thelia/Config/Resources/routing/admin.xml | 5 + .../Controller/Admin/OrderController.php | 12 +- core/lib/Thelia/Core/Event/PdfEvent.php | 122 ++++++++++- .../Smarty/Plugins/DataAccessFunctions.php | 13 ++ install/insert.sql | 3 +- templates/admin/default/order-edit.html | 2 +- templates/pdf/delivery.html | 193 ++++++++++++++++++ templates/pdf/invoice.html | 24 +-- 9 files changed, 353 insertions(+), 23 deletions(-) create mode 100644 templates/pdf/delivery.html diff --git a/core/lib/Thelia/Action/Pdf.php b/core/lib/Thelia/Action/Pdf.php index 385f948fb..52ce0b92d 100644 --- a/core/lib/Thelia/Action/Pdf.php +++ b/core/lib/Thelia/Action/Pdf.php @@ -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'); diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index f83874631..6051a3783 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -155,6 +155,11 @@ \d+ + + Thelia\Controller\Admin\OrderController::generateDeliveryPdf + \d+ + + diff --git a/core/lib/Thelia/Controller/Admin/OrderController.php b/core/lib/Thelia/Controller/Admin/OrderController.php index ececff6e8..1df0679f0 100644 --- a/core/lib/Thelia/Controller/Admin/OrderController.php +++ b/core/lib/Thelia/Controller/Admin/OrderController.php @@ -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 ), diff --git a/core/lib/Thelia/Core/Event/PdfEvent.php b/core/lib/Thelia/Core/Event/PdfEvent.php index b65ba39a2..e0f873e04 100644 --- a/core/lib/Thelia/Core/Event/PdfEvent.php +++ b/core/lib/Thelia/Core/Event/PdfEvent.php @@ -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; + } + + } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index 315adf37e..17d9e37a3 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -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'), ); } diff --git a/install/insert.sql b/install/insert.sql index ec4e1b02b..d91c511dc 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -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()) ; diff --git a/templates/admin/default/order-edit.html b/templates/admin/default/order-edit.html index 59c3d9cce..f05bc2a05 100644 --- a/templates/admin/default/order-edit.html +++ b/templates/admin/default/order-edit.html @@ -268,7 +268,7 @@ {intl l='Delivery address'}
- + {intl l='PDF | Purchase order'} diff --git a/templates/pdf/delivery.html b/templates/pdf/delivery.html new file mode 100644 index 000000000..9aec97a7b --- /dev/null +++ b/templates/pdf/delivery.html @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + +
{intl l="page"} [[page_cu]]/[[page_nb]]
+
+ +{loop name="order.invoice" type="order" id=$order_id customer="*"} + {loop name="currency.order" type="currency" id=$CURRENCY} + {assign "orderCurrency" $SYMBOL} + {/loop} + + + + + + + + + + + + + + + + +
+ +
+

+ {config key="company_name"} + +

+ + + +

{intl l='Delivery module'}
{$DELIVERY_REF}

+
+ + + + + + + + + + + + + + +
{intl l="invoice ref"}{intl l="invoice date"}
{$REF}{format_date date=$INVOICE_DATE}
+ + + + + + + + + + + + + +
{intl l="invoice"} {intl l="customer number"}
{$INVOICE_REF}{loop type="customer" name="customer.invoice" id=$CUSTOMER current="0"}{$REF}{/loop}
+
+ + + + + + + + + +
{intl l="delivery address"}
+ {loop type="order_address" name="delivery_address" id=$DELIVERY_ADDRESS} + {loop type="title" name="order-invoice-address-title" id=$TITLE}{$LONG}{/loop}{$FIRSTNAME} {$LASTNAME}
+ {$ADDRESS1} {$ADDRESS2} {$ADDRESS3}
+ {$ZIPCODE} {$COUNTRY}
+ {loop type="country" name="country_delivery" id=$COUNTRY}{$TITLE}{/loop} + {/loop} +
+ + + + + + + + + +
{intl l="invoice address"}
+ {loop type="order_address" name="delivery_address" id=$INVOICE_ADDRESS} + {loop type="title" name="order-invoice-address-title" id=$TITLE}{$LONG}{/loop}{$FIRSTNAME} {$LASTNAME}
+ {$ADDRESS1} {$ADDRESS2} {$ADDRESS3}
+ {$ZIPCODE} {$COUNTRY}
+ {loop type="country" name="country_delivery" id=$COUNTRY}{$TITLE}{/loop} + {/loop} +
+
+ + + + + + + + + + + + + + + + + + {loop type="order_product" name="order-products" order=$ID} + + + + + + {/loop} + +
{intl l="Ref"}{intl l="product"}{intl l="Quantity"}
{$REF}{$TITLE}{$QUANTITY}
+ + + + + + + + + + + + +
{intl l="delivery module"}{loop name="delivery-module" type="module" id=$DELIVERY_MODULE}{$TITLE}{/loop}
+ +{/loop} +
diff --git a/templates/pdf/invoice.html b/templates/pdf/invoice.html index 3ad552d9a..22e6d2760 100644 --- a/templates/pdf/invoice.html +++ b/templates/pdf/invoice.html @@ -59,7 +59,7 @@
-

#VARIABLE(nomsite)

+

{config key="company_name"}

{intl l="invoice"} {$INVOICE_REF}

@@ -73,7 +73,7 @@ {$REF} - {loop type="customer" name="customer.invoice" id=$CUSTOMER}$REF{/loop} + {loop type="customer" name="customer.invoice" id=$CUSTOMER current="0"}{$REF}{/loop} {format_date date=$INVOICE_DATE} @@ -185,24 +185,12 @@ - ::Mode de règlement:: - #PAIEMENTTITRE + {intl l="Payment module"} + {loop name="payment-module" type="module" id=$PAYMENT_MODULE}{$TITLE}{/loop} - ::Mode de livraison:: - #TRANSPORTTITRE - - - - - - - - - - - - + +
::Zone de correspondance::
{intl l="delivery module"}{loop name="delivery-module" type="module" id=$DELIVERY_MODULE}{$TITLE}{/loop}