create purchase order pdf
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
@@ -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
|
||||
),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user