Jump to content

[Guide] Modifying Prestashop 1.5/1.6 Invoice Template.


Supremacy2k
 Share

Recommended Posts

Hello, I have a large invoices in 2 pages and I really need to do this; Header show only in first page and footer show only in last page. Now In every page I have header and footer.

 

Hi cikcak,

 

Remove the content from pdf/header.tpl and pdf/footer.tpl and place it at the top and at the bottom of invoice.tpl (and other pdf templates you use). Some variables used in header or footer might not be available for use in invoice.tpl, if this is the case, perhaps you could simply write the values directly in the code instead (if that is an option for your project).

 

header.tpl and footer.tpl is included at the top/bottom of every page. So the only way to change it is to not use those files.

 

Good luck

Share this post


Link to post
Share on other sites

Hi cikcak,

 

Remove the content from pdf/header.tpl and pdf/footer.tpl and place it at the top and at the bottom of invoice.tpl (and other pdf templates you use). Some variables used in header or footer might not be available for use in invoice.tpl, if this is the case, perhaps you could simply write the values directly in the code instead (if that is an option for your project).

 

header.tpl and footer.tpl is included at the top/bottom of every page. So the only way to change it is to not use those files.

 

Good luck

But how to do that footer would be at the bottom of page? Now its after all content and I see it in middle of page.

Share this post


Link to post
Share on other sites

But how to do that footer would be at the bottom of page? Now its after all content and I see it in middle of page.

 

I don't think there is a simple solution to that problem. I believe that you will have to hack it yourself or hire someone to do it.

Edited by patrikar (see edit history)

Share this post


Link to post
Share on other sites

I don't think there is a simple solution to that problem. I believe that you will have to hack it yourself or hire someone to do it.

 

Exactly! ;)  However, you've been on the right track. The best way is to study this whole topic carefully, in this special case my post here from May 2013.

 

You got to modify the assemby of the pdf invoice in /classes/pdf/pdf.php by disabling the rendering of the header and the footer, which btw for the header is a bit tricky, for you need to do some changes in /classes/pdf/PDFgenerator.php too (so you guys better read my post).

Share this post


Link to post
Share on other sites

Hi to everyone,

 

I'm using PS 1.6.0.9, default bootsrap template and I'm trying to customize the invoice in order to get it more similar to the one I've been using till now.

I would like to put the shop address into the header, instead of order nr. and date. I tried to follow tuk66's instructions (previous page of this topic) and copying the smarty variables from footer to header in HTMLtemplateinvoice.php but I really can't get it work. Can someone help me?

 

Thanks a lot!

Edited by toncika (see edit history)

Share this post


Link to post
Share on other sites

Hi toncika,

 

the easiest way in this case is to modify or override function getHeader() in classes/pdf/HTMLTemplate.php. Move line 75 to 78 from function getFooter()

'shop_address' => $shop_address,
'shop_fax' => Configuration::get('PS_SHOP_FAX', null, null, (int)$this->order->id_shop),
'shop_phone' => Configuration::get('PS_SHOP_PHONE', null, null, (int)$this->order->id_shop),
'shop_details' => Configuration::get('PS_SHOP_DETAILS', null, null, (int)$this->order->id_shop),

to function getHeader() by adding it after e.g. line 58, so that the function will look like this:

public function getHeader()
{
	$shop_name = Configuration::get('PS_SHOP_NAME', null, null, (int)$this->order->id_shop);
	$path_logo = $this->getLogo();

	$width = 0;
	$height = 0;
	if (!empty($path_logo))
		list($width, $height) = getimagesize($path_logo);

   $shop_address = $this->getShopAddress(); 
   this->smarty->assign(array(
	'logo_path' => $path_logo,
 	'img_ps_dir' => 'http://'.Tools::getMediaServer(_PS_IMG_)._PS_IMG_,
 	'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
 	'title' => $this->title,
 	'date' => $this->date,
 	'shop_name' => $shop_name,
        'shop_address' => $shop_address,
        'shop_fax' => Configuration::get('PS_SHOP_FAX', null, null, (int)$this->order->id_shop),
        'shop_phone' => Configuration::get('PS_SHOP_PHONE', null, null, (int)$this->order->id_shop),
        'shop_details' => Configuration::get('PS_SHOP_DETAILS', null, null, (int)$this->order->id_shop),
	'width_logo' => $width,
	'height_logo' => $height
	));

	return $this->smarty->fetch($this->getTemplate('header'));
}

If you want to make this an override, which will not be affected by further update, save the following as HTMLTemplate.php and upload it to /override/classes/pdf/

<?php

class HTMLTemplate extends HTMLTemplateCore

public function getHeader()
  {
    $shop_name = Configuration::get('PS_SHOP_NAME', null, null, (int)$this->order->id_shop);
    $path_logo = $this->getLogo();

    $width = 0;
    $height = 0;
    if (!empty($path_logo))
        list($width, $height) = getimagesize($path_logo);

$shop_address = $this->getShopAddress(); 
this->smarty->assign(array(
    'logo_path' => $path_logo,
    'img_ps_dir' => 'http://'.Tools::getMediaServer(_PS_IMG_)._PS_IMG_,
    'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
    'title' => $this->title,
    'date' => $this->date,
    'shop_name' => $shop_name,
    'shop_address' => $shop_address,
    'shop_fax' => Configuration::get('PS_SHOP_FAX', null, null, (int)$this->order->id_shop),
    'shop_phone' => Configuration::get('PS_SHOP_PHONE', null, null, (int)$this->order->id_shop),
    'shop_details' => Configuration::get('PS_SHOP_DETAILS', null, null, (int)$this->order->id_shop),
    'width_logo' => $width,
    'height_logo' => $height
    ));

    return $this->smarty->fetch($this->getTemplate('header'));
  }
}

And if you modify a tpl-file for PDFs, you should duplicate the pdf directory before to your themes directory and change the files just in this place. Those modifications won't be affected by upgrades as well.

Edited by eleazar (see edit history)

Share this post


Link to post
Share on other sites

Thank you very much eleazar. Tried it now but doesn't work :( After coppying the strings as you written and saved the file, added a string in header tpl (the same that appear in footer.tpl) for getting shop address and details but I only managed to get the details and not the address :( :(

 

Any idea?

Share this post


Link to post
Share on other sites

Thank you very much eleazar, it works perfectly now!

I would only like to change the format of the address, now it is

name of shop - address - country

 

I'd like to put it

name of shop

address

country

 

Tried to use the string tuk66 suggested on previuos page,

$shop_address = str_replace("|", "<br>", AddressFormat::generateAddress($shop_address_obj, array(), '|', ' '));

 

inserting it in HTMLtemplate but it doesn't work.

 

Would you please help me with this too?

Thanks again :)

Share this post


Link to post
Share on other sites

So complicated because ... I'm not a CSS/PHP/HTML expert so I only read and try to use the information that I find. :)

 

Thank you a lot, it works perfectly.

I'd like to make two changes more: add shop url and shop email (the one inserted in Preferences > Store contacts) under the shop address. Have searched in HTMLtemplate but there is no string that refers to it... is it possible to do or would it mean too much work?

 

The second thing is that I would like to insert the text written in Preferences > Store contacts > Registration under the order (product details). This text is - I think - what shop_details tab refers to, but don't how to insert it.

 

Thanks again and again :)

Share this post


Link to post
Share on other sites

Okay, in this case we should make it be as less complicated as possible for you. ;)
To cut it short, no more modifying the Prestashop core. Let's just create 3 new translation items for fixed text.
Wherever you want in header.tpl or invoice.tpl place a new item like e.g. the shop url:
 

 {l s='shop url' pdf='true'}

Something like this in a table form in header.tpl:

<td style="font-size: 12pt";>{l s='shop url' pdf='true'}</td>

Something like this as a div-tag in invoice.tpl:

<div>{l s='store contacts' pdf='true'}</div>

The result will be three new translation items in
localisation -> translations -> pdf
In your back office. Fill in here, whatever you want.

Edited by eleazar (see edit history)

Share this post


Link to post
Share on other sites

Thanks eleazar, I used this method and it works great!

 

I'm almost done with this invoice. I need just one more thing to set up... When a customer pays by COD, I'd like to have "COD payment: amount" on the right side of the delivery address.

 

I already moved and changed the positions of the addresses but don't know how to write an "if" string to make it look like this:

 

 

delivery address                                                                                COD payment: xxx euro

 

billing adress

 

invoice etc

 

Thank you again (imagine there's a flower-giving-smiley) :)

Share this post


Link to post
Share on other sites

Brat! :rolleyes::D

 

Try something like this:

<table style="width: 92%; font-size: 10pt; color: #000;">
<div style="font-size: 8pt; color: #444">

	<tr>
		<td style="width: 4%"> </td> 
		<td style="height: 105px;width: 40%"><br />{$invoice_address}</td>
		<td> </td>
		<td style="height: 105px;width: 40%;">{if !empty($delivery_address)}{l s='Delivery Address' pdf='true'}<br />{$delivery_address}{/if}</td>
		<td> </td>
		<td style="height: 105px;width: 16%;">{if $payment->payment_method == 'COD'}COD Payment: {displayPrice currency=$order->id_currency price=$order_invoice->total_paid_tax_incl}{/if}</td>
	</tr>
</table>

Share this post


Link to post
Share on other sites

:rolleyes:

 

Hmm.. tried it but does not work... 

I think that the reason is that I use CODfee module.

 

I searched where payment methods are generated but didn't found, so I looked in CODfee module php and tried changing the above string in 

{if $payment->payment_method == 'codfee'}COD Payment: {displayPrice currency=$order->id_currency price=$order_invoice->total_paid_tax_incl}{/if}

 

but nothing.

 

Any idea?

 

Thank you again!!

Share this post


Link to post
Share on other sites

Sorry, toncika, my fault. Should have tested this first. I applied the wrong variable. :unsure:

Try this instead;

{if $order->payment == 'codfee'}COD Payment: {displayPrice currency=$order->id_currency price=$order_invoice->total_paid_tax_incl}{/if}

I don't know if it's 'codfee' or 'COD' or whatevs. In any case you have to choose the payment displayed in your Back Office orders' list.

Share this post


Link to post
Share on other sites

It doesn't work :( :(

I the BO the payment method displayed is COD with fee, I tried all possible combinations - CODfee, Codfee, CodFee, codfee.... but doesn't work :(

Hi, can you add some image with the final result after applying all changes above?
 
Thank you.

Share this post


Link to post
Share on other sites

It doesn't work :( :(

I the BO the payment method displayed is COD with fee, I tried all possible combinations - CODfee, Codfee, CodFee, codfee.... but doesn't work :(

 

Why?? Just do what I told you: you have to choose the payment name for COD displayed in your Back Office orders' list.

Share this post


Link to post
Share on other sites

Why?? Just do what I told you: you have to choose the payment name for COD displayed in your Back Office orders' list.

 

Hi eleazar,

 

sorry for this late reply.

 

In my BO orders list there is written Cash on delivery with fee but as I told you I can't get it work.

Even if I put "Bank wire" instead of COD with fee and try to generate an invoice for a customer that choose Bank wire payment, there is no new line on the right side of the invoice.

 

Maybe there is something wrong in my invoice template :( :( :(

Share this post


Link to post
Share on other sites

  • 3 weeks later...

Hello,

 

I need to edit invoice_addess , I need to add some labels before some text like Phone, dni, vat etc.

 

On example:

Company Name

Name Surname

...

PHONE nr.:   123456789

DNI:     987654321

VAT:    XX147258369

 

 

Is there any solution how to achieve that (not in Countries at backoffice... that is not what I mean), like using varriables etc ?

 

 

 

If it is not posible to solve this only for invoice, I haven't got problem, if the solution affects addresses in emails etc.

 

Thank you in advance

Share this post


Link to post
Share on other sites

Hello,

 

I need to edit invoice_addess , I need to add some labels before some text like Phone, dni, vat etc.

 

On example:

Company Name

Name Surname

...

PHONE nr.:   123456789

DNI:     987654321

VAT:    XX147258369

 

I use 1.6 presta, so maybe some arrays will be a litle bit different :)

 

in classes/pdf/HtmlTemplateInvoice.php  find function getContent()

	public function getContent()
	{
		$country = new Country((int)$this->order->id_address_invoice);
		$invoice_address = new Address((int)$this->order->id_address_invoice);
		$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
		$formatted_delivery_address = '';
		if ($this->order->id_address_delivery != $this->order->id_address_invoice)
		{
			$delivery_address = new Address((int)$this->order->id_address_delivery);
			$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
		}

		$customer = new Customer((int)$this->order->id_customer);

		$data = array(
			'order' => $this->order,
			'order_details' => $this->order_invoice->getProducts(),
			'cart_rules' => $this->order->getCartRules($this->order_invoice->id),
			'delivery_address' => $formatted_delivery_address,
			'invoice_address' => $formatted_invoice_address,
			'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
			'tax_tab' => $this->getTaxTabContent(),
			'customer' => $customer
		);

to $data = array you add line for each variable, as you can see in Country > adress, so you can add for example

  'incompany_value' => $invoice_address->company,
  'indni_value' => $invoice_address->dni,
  'invat_value' => $invoice_address->vat_number,
  'incountry_value' => $invoice_address->country,
  'inmail_value' => $customer->email

For creating variables for Company name, DNI and VAT, country and email  (you can use all variables as  firstname lastname etc)

 

and in your invoice template you simply use

VAT: {$invat_value}

and you see f.e. VAT:    XX147258369

Edited by lorDoom (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

You just need to create these 3 new variables:
 

  'indni' => $invoice_address->dni,
  'inphone' => $invoice_address->phone,
  'invat' => $invoice_address->vat_number,

The customer's country (if choosed for address), email address and company is already provided for the invoice, so you don't have to modify the core. Just get the information you need by using the following syntax directly in the invoice.tpl without any further changes:

<strong>{l s='Mail'}: </strong>{$customer->mail}
<strong>{l s='Company'}: </strong>{$customer->company}

Or, if you don't use other languages than English and therefor don't need translation items:
 

<strong>Mail: </strong>{$customer->mail}
<strong>Company: </strong>{$customer->company}
Edited by eleazar (see edit history)

Share this post


Link to post
Share on other sites

Hi to everyone,

 

I would like to delete the customer's phone number from the invoice, I've searched but can't found where the address is generated in order to delete this string. Can anyone help me?

 

Thank you a lot!

Share this post


Link to post
Share on other sites

The address is created according to the Address format set under Localization > Country (every).

Thank you very much tuk66. I've searched in all php file but forgot to look in BO. No comment :huh:

 

Why?? Just do what I told you: you have to choose the payment name for COD displayed in your Back Office orders' list.

Eleazar, I've tried again and again, trying to modify also the string you wrote. I finally fixed it, the string that works is:

 

{if !$order->payment->payment_method == 'CODfee'}COD payment: {displayPrice currency=$order->id_currency price=$order_invoice->total_paid_tax_incl}{/if}

 

:) :)

Share this post


Link to post
Share on other sites

 

Eleazar, I've tried again and again, trying to modify also the string you wrote. I finally fixed it, the string that works is:

 

{if !$order->payment->payment_method == 'CODfee'}COD payment: {displayPrice currency=$order->id_currency price=$order_invoice->total_paid_tax_incl}{/if}

 

:) :)

 

Toncika, a wise man once said: 'For every complex problem there is an answer that is clear, simple, and wrong.' :)

Though this prob is of minor complexity, I'm afraid this statement fits.

 

Just for the record: The "!" you added to the php statement is an abbreviation for 'NOT'. Which means, the if-clause has the following meaning:

 

If the array defined by the database table order contains a field payment, that in turn points to an array field named payment method, is NOT named 'CODfee', then display COD payment: total price tax incl.

 

The statement I proposed contained the following condition:

{if $order->payment == 'CODfee'}

As your (wrong) condition

{if !$order->payment->payment_method == 'CODfee'}

will never be the case, this works fine with COD payment in fact - but not only with COD payment! It will be displayed in any case, regardless of which payment the customer chose,  because this condition will never be true.

 

I'm sorry, but you've counted your chickens before they're hatched. ;)

 

Once again, you have to ask for the exact payment name in the language displayed in your BO. If you are not sure, maybe because the BO is run in a different language than your shop, use PHPMyAdmin and have a look into the field payment in your database table ps_orders. This field payment contains the name of the payment method you have to ask for in in the if-clause.

Edited by eleazar (see edit history)

Share this post


Link to post
Share on other sites

:( :( :(

 

You're right eleazar. I just checked with other payments and obviously there is always the line on the invoice :(

 

I'm giving up-

 

The name of the module/payment method that I see in BO does not work, really. So if the string with ! says "write this if there is NO xy" can I use it to say "write COD payment=xx eur if there is no bank wire payment, no paypal payment, no cash payment"?

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Solved: How can customer messages be displayed in the pdf invoice?

Jump to the bottom of this post for the solution - thanks to pointers from Bellini13!

 

I'm looking for the method to display messages on the pdf invoice that are displayed in the order history and the BO order display. In the front office when a customer selects order history in the "My Account" block, the messages are displayed when they click on "details" in the order history table. This lead me to look at the code in order-details.tpl that displays the data on the screen. Below is that code that I tried to paste in the invoice.tpl file, but it didn't work. Any ideas how to make the messages display in the pdf invoice?

{if count($messages)}
<h3>{l s='Messages'}</h3>
<div class="table_block">
  <table class="detail_step_by_step std">
   <thead>
	<tr>
	 <th class="first_item" style="width:150px;">{l s='From'}</th>
	 <th class="last_item">{l s='Message'}</th>
	</tr>
   </thead>
   <tbody>
   {foreach from=$messages item=message name="messageList"}
	<tr class="{if $smarty.foreach.messageList.first}first_item{elseif $smarty.foreach.messageList.last}last_item{/if} {if $smarty.foreach.messageList.index % 2}alternate_item{else}item{/if}">
	 <td>
	  {if isset($message.elastname) && $message.elastname}
	   {$message.efirstname|escape:'htmlall':'UTF-8'} {$message.elastname|escape:'htmlall':'UTF-8'}
	  {elseif $message.clastname}
	   {$message.cfirstname|escape:'htmlall':'UTF-8'} {$message.clastname|escape:'htmlall':'UTF-8'}
	  {else}
	   <b>{$shop_name|escape:'htmlall':'UTF-8'}</b>
	  {/if}
	  <br />
	  {dateFormat date=$message.date_add full=1}
	 </td>
	 <td>{$message.message|escape:'htmlall':'UTF-8'|nl2br}</td>
	</tr>
   {/foreach}
   </tbody>
  </table>
</div>
{/if}

The solution:

1. Override the HTMLTemplateInvoice.php using the code below to place the customer messages in Smarty. This will lookup the messages, place assign them into smarty, and then return the standard invoice getContent. The file should be placed in the override/classes/pdf directory.

<?php
/*
* Override for 1.5.4.1 HTMLTemplateInvoice.php to get order messages so they can be displayed in pdf invoice
*/

class HTMLTemplateInvoice extends HTMLTemplateInvoiceCore
{
public function getContent()
    {
		 $this->smarty->assign(array(
		 'order' => $this->order,
				    'messages' => CustomerMessage::getMessagesByOrderId((int)($this->order->id), false),
		 ));
		    return parent::getContent();
   }
}
2. Insert the following code in the theme/pdf/invoice.tpl file. The location depends where you want the comments to display. For my invoice the code was inserted just before

</table>
<!-- / PRODUCTS TAB -->
so the comments were displayed as the last item after the other sections of the invoice.

<!-- / CUSTOMER MESSAGES -->
   <tbody>
   {if $messages} <b>Order Messages</b>
   {foreach from=$messages item=message name="messageList"}
    <tr class="{if $smarty.foreach.messageList.first}first_item{elseif $smarty.foreach.messageList.last}last_item{/if} {if $smarty.foreach.messageList.index % 2}alternate_item{else}item{/if}">
	  <hr><td>
	  {if isset($message.elastname) && $message.elastname}
	   {$message.efirstname|escape:'htmlall':'UTF-8'} {$message.elastname|escape:'htmlall':'UTF-8'}
	  {elseif $message.clastname}
	   {$message.cfirstname|escape:'htmlall':'UTF-8'} {$message.clastname|escape:'htmlall':'UTF-8'}
	  {else}
	   <b>{$shop_name|escape:'htmlall':'UTF-8'}</b>
	  {/if}
	  <br />
	  {dateFormat date=$message.date_add full=1}
	 </td>
	 <td>{$message.message|escape:'htmlall':'UTF-8'|nl2br}</td>
    </tr>
   {/foreach}
   {/if}
   </tbody>
<!-- / CUSTOMER MESSAGES -->

 

Hi, just a question is it also adaptable for PS 1.6?

Edited by domorodecmezilidmi (see edit history)

Share this post


Link to post
Share on other sites

  • 5 weeks later...
  • 1 month later...

Okey I'm blind.

I totally missed the "tools" folder, hehe.

 

Anyways.

 

On line 23.203 i have the following:

} else {
on 23.205 i have this:

}
On 24.618 this:

$this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
and on 24.650 this

if (isset($this->theadMargins['top'])) {
m3442a .. can you post your lines from 24203 to 24205 and from 24618 to 24650 ?

 

 

 

Hi,

 

Thank you for this guide, great tutorial and invoice template.

 

Can you please help me with these error, in back office --> orders --> when I want do view invoice for a client (attached printscreen). For the client in email invoice it's ok.

 

PS 1.5.6.2 (no upgrade from 1.4)

 

 

Thank you.

 

 

 

invoice_error.jpg

Warning: Division by zero in /home/site-name/public_html/tools/tcpdf/tcpdf.php on line 22982

Warning: array_fill() [function.array-fill]: Number of elements must be positive in /home/site-name/public_html/tools/tcpdf/tcpdf.php on line 22984

Warning: Invalid argument supplied for foreach() in /home/site-name/public_html/tools/tcpdf/tcpdf.php on line 24393

Warning: Invalid argument supplied for foreach() in /home/site-name/public_html/tools/tcpdf/tcpdf.php on line 24425

Warning: Cannot modify header information - headers already sent by (output started at /home/site-name/public_html/tools/tcpdf/tcpdf.php:22982) in /home/site-name/public_html/tools/tcpdf/tcpdf.php on line 8966
TCPDF ERROR: Some data has already been output to browser, can't send PDF file
Edited by eduard02 (see edit history)

Share this post


Link to post
Share on other sites

  • 2 weeks later...

What do you mean "pagination?" The invoice is automatically divided to more pages in case of large number of order items.

Pagiation - if only 1 page it writes: 1 of 1 for example in footer. If 2 pages: on first page footer: 1 of 2 page , second page 2  - page.

Share this post


Link to post
Share on other sites

No, you can't. The PS 1.3 and 1.6 invoices are completely different. Of course, PS 1.6 has some new things and improvements, so this is another reason.

 

There are some 3rd party invoice templates and modules. For example, the M4 PDF Extensions module uses one invoice look in all PrestaShop versions.

Share this post


Link to post
Share on other sites

No, you can't. The PS 1.3 and 1.6 invoices are completely different. Of course, PS 1.6 has some new things and improvements, so this is another reason.

 

There are some 3rd party invoice templates and modules. For example, the M4 PDF Extensions module uses one invoice look in all PrestaShop versions.

Thank you. Does the guide on the first page work for PS 1.6.09? 

I've already checked out your module. ;)

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hi,
I actually posted this question before, but the thread never got any attention, so forgive me for re-posting it here. When I first posted I was on presto 1.5.4 but now I'm on 1.6.0.14.
I've been trying to use the delivery slip to print out a packing list and an address label on one piece of paper. The paper I'm using has a dedicated peel-off section, where I place the delivery address, so it's ready to stick on the package right after packing.
In order to place the address in a fixed position on the paper, I have put it in the footer of the delivery slip(by overriding) and adjusted it so it fits.
This works very well if I print one delivery slip at the time, but since the idea was to save time and work, I would like to print all delivery slips once a day and bring them to the packing room to do all shipments in one round. When I try to do this, the addresses gets mixed up. The address in the footer is not the same as the address in the top of the delivery slip, -it's the same as the one on top of the following delivery slip! The last page of the deliveries.pdf is the only one that has the right address in the footer, -probably as there is no following slip to pull the address from.
Seems to me that somehow the next footer is created before the active pdf is closed in the tcpdf workflow...that would be very illogical, but is there another explanation?
What I've done is to override HTMLTemplateDeliverySlip.php by adding a function, getFooter(), that overrides the original getFooter() from HTMLTemplate.php. The new getFooter() simply fetches the delivery_address and uses a different template than footer.tpl to format it properly. 

 

Here's the override that I have in HTMLTemplateDeiverySlip.php:
 

public function getFooter()
{
 $delivery_address = new Address((int)$this->order->id_address_delivery);
 $formatted_delivery_address = AddressFormat::generateAddress($this->delivery_address, array(), '<br />', ' ');
 
 $this->smarty->assign(array('delivery_address' => $formatted_delivery_address));
 
       return $this->smarty->fetch($this->getTemplate('JSfooter_delivery'));
}

 

Seems simple enough, and it works, but unfortunately not for bulk printing.

 

Any help is very welcome!

Share this post


Link to post
Share on other sites

Thanks, guys. I've played with the HTML code and was able to achieve more or less desired look. Still need to figure out how to move the cells with order date, courier and payment method above the product summary table.

 

If anybody is concerned about wasting your printer ink on background color while printing invoices and delivery slips, I've finally figured out how to add lines between table cells/rows. You will need to add CSS by inserting the following code above <table>

<style type="text/css">

and then close it

</table>
</style>

In every row where you want lines between rows (<td style=), add this:

border:1px solid black;

And then remove any background color.

Share this post


Link to post
Share on other sites

  • 5 weeks later...
  • 1 month later...

Hi Supremacy2k, very nice tutorial. Is it possible to only display the header and footer on the first page and last page of invoice?

 

Ok, I'm not Supremaczyk, but I can answer your question.

  • Open /pdf/header.tpl
  • Insert a <thead>-Tag right after the <table>-Tag and before closing it. Like this:

     

    <table style="width: 100%">
    <thead>
    <tr>
    (...)
    </tr>
    </thead>
    </table>
  • Repeat this for /pdf/footer.tpl

That's all.

Share this post


Link to post
Share on other sites

  • 3 weeks later...

First, let me say, I’m sorry for my poor English. I hope you understand my questions.  I’m just about to open a small shop for dog supplies in Germany and I’m having problems with the look of the invoice.

 

I read the modifications from Supremacy2k. I downloaded the header and invoice.tpl and already got stuck, because on the invoice.tpl I do not have 307 lines. I’m using Prestashop 1.6.1 .

 

I really like the invoice Woutermesker uploaded here, but unfortunately he didn’t post his codes. For me it’s very important to have my company details on the invoice, such as company address and bank details, just like Woutermesker has. And I’d prefer the tax not to be mentioned again in the second table below the actual invoice table. Do you know what I mean?

 

Anyone here who can help me?

Share this post


Link to post
Share on other sites

  • 1 month later...

Hello,

 

That was a good guide. Recently I tried changing the invoice template. In the original template, the product price that is displayed is excl tax. I want it to show incl tax. So, I changed the product_tab.tpl and the invoice .tpl accordingly and renamed it to product_tab2.tpl and invoice2.tpl. I uploaded it into the /PDF folder but when I went to the BO, i don't have the drop down list for the invoice2.

 

FYI, I'm using custom Leo theme and it does have /PDF folder of its own but the only file is index.php and lang folder. I'm not to sure how to upload the new invoice template without removing the original template. I'd appreciate if you can help me on this matter.

 

Thanks.

Share this post


Link to post
Share on other sites

Hello,

 

FYI, I'm using custom Leo theme and it does have /PDF folder of its own but the only file is index.php and lang folder. I'm not to sure how to upload the new invoice template without removing the original template. I'd appreciate if you can help me on this matter.

Thanks.

You don't have to remove anything. Just upload your invoice2.tpl to the Leo theme's pdf folder. And if you use header and footer you have to add both tpl-files to this folder too. When done, the drop down will show your invoice.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hello,

 

That was a good guide. Recently I tried changing the invoice template. In the original template, the product price that is displayed is excl tax. I want it to show incl tax. So, I changed the product_tab.tpl and the invoice .tpl accordingly and renamed it to product_tab2.tpl and invoice2.tpl. I uploaded it into the /PDF folder but when I went to the BO, i don't have the drop down list for the invoice2.

 

FYI, I'm using custom Leo theme and it does have /PDF folder of its own but the only file is index.php and lang folder. I'm not to sure how to upload the new invoice template without removing the original template. I'd appreciate if you can help me on this matter.

 

Thanks.

you can find at PRESTASHOP_ROOT/pdf, all invoice template file are in there.

Share this post


Link to post
Share on other sites

  • 3 weeks later...

Hello

 

I tried delete margin of header.tpl in /classes/pdf/PDFGenerator.php changing code around line 200 but not work:

    public function writePage()
    {
        $this->SetHeaderMargin(5);

to: 

    public function writePage()
    {
        $this->SetHeaderMargin(0);

How can delete header margin o delete header in invoice?

 

Thank you very much

best regards

Share this post


Link to post
Share on other sites

 

Hello, thank you very much for info. I tried this changes but header margin still persists:

 

PDF.php line 92= /**$this->pdf_renderer->createHeader($template->getHeader());*/

 

PDFGenerator.php line 200 = /**$this->SetHeaderMargin(0, 0, 0);*/

 

Some other changes to make?

 

best regards

PS 1.6.1.1

Share this post


Link to post
Share on other sites

ok, now works. I thought deleting header code could work  :)

 

Do you know asign min-height for global table?

 

I tried also in tr and td with min-height and display:block but didnt work

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hello guys  :) 

Why am i not able to override PDFGenerator.php file?

 

Under "Override/classes/pdf/" i have created the same file, which is PDFGenerator.php. Within that file i have put code below, because i want to define different header and footer height. The problem is, that override doesn't work at all, even if i disable cache and delete class_index.php file within cache directory. What am i doing wrong? Is there maybe a bug or something?

<?php

class PDFGeneratorCoreOverride extends PDFGeneratorCore {

    /* Header and Footer HEIGHT change */
    public function writePage() {
        
        $this->SetHeaderMargin(10);
        $this->SetFooterMargin(30);
        $this->setMargins(10, 40, 10);

        $this->AddPage();

        $this->writeHTML($this->content, true, false, true, false, '');
    }
    
}

I am using Prestashop version 1.6.0.14.

 

If i change code directly, it affects PDF, when it is exported. It works as it should but no results, when overriding PDFGenerator.php file.

Could you guys take a look and help me here please?

Thank you and best regards,
Housy

Share this post


Link to post
Share on other sites

  • 3 weeks later...
  • 3 weeks later...
  • 4 months later...

It is possible modify the address of invoice? I'd like change the order of name and company. The order is the following

 

Company

Name

Address complete

 

I think must change php file. But I don't know which file.

 

Thank you very much

Share this post


Link to post
Share on other sites

  • 2 months later...
  • 3 weeks later...

PS 1.6.1.1

 

Hi

 

This post has almost got me there. If I modify the core file it works ok, but to do this correctly I need it to be in an override. However in the override in 1.6 the code is different from 1.5. See below:

        $data = array(
            'order' => $this->order,
            'order_invoice' => $this->order_invoice,
            'order_details' => $order_details,
            'cart_rules' => $cart_rules,
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address),
            'tax_excluded_display' => $tax_excluded_display,
            'display_product_images' => $display_product_images,
            'layout' => $layout,
            'tax_tab' => $this->getTaxTabContent(),
            'customer' => $customer,
            'footer' => $footer,
            'ps_price_compute_precision' => _PS_PRICE_COMPUTE_PRECISION_,
            'round_type' => $round_type,
            'legal_free_text' => $legal_free_text,
            'messages' => CustomerMessage::getMessagesByOrderId((int)($this->order->id), false),
        );

        if (Tools::getValue('debug')) {
            die(json_encode($data));
        }

        $this->smarty->assign($data);

        $tpls = array(
            'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
            'addresses_tab' => $this->smarty->fetch($this->getTemplate('invoice.addresses-tab')),
            'summary_tab' => $this->smarty->fetch($this->getTemplate('invoice.summary-tab')),
            'product_tab' => $this->smarty->fetch($this->getTemplate('invoice.product-tab')),
            'tax_tab' => $this->getTaxTabContent(),
            'payment_tab' => $this->smarty->fetch($this->getTemplate('invoice.payment-tab')),
            'total_tab' => $this->smarty->fetch($this->getTemplate('invoice.total-tab')),
        );
        $this->smarty->assign($tpls);
      
        return $this->smarty->fetch($this->getTemplateByCountry($country->iso_code));
        return parent::getContent();

I know the bottom line:

 

return parent::getContent();

 

is in the wrong place.

 

Where should it go?

 

Thanks for any and all help.

Share this post


Link to post
Share on other sites

Got it. Should have tried this first. For anyone who's interested:

class HTMLTemplateInvoice extends HTMLTemplateInvoiceCore
{
    /**
     * Returns the template's HTML content
     *
     * @return string HTML content
     */
    public function getContent()
    {
        $msgdata = array(
            'messages' => CustomerMessage::getMessagesByOrderId((int)($this->order->id), false),
        );

        $this->smarty->assign($msgdata);

        return parent::getContent();
    }

    /**
     * Returns the tax tab content
     *
     * @return String Tax tab html content
     */
}

Share this post


Link to post
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
  • 2 weeks later...
  • 1 year later...

hello guys

can someone help me with dates problem, in my country invoice must have some formailities, with are not included in basic invoice, many of them are easily achiveable, but I have problem with due date.

 

I need to achieve, that I have on my invoice creation date (included in basic invoice), "date of payment" (this could be same as creation date) and due date, with should be for example date of creation + additional 7 days and I don't know, how in smarty I can create it.

 

I need something like

{dateFormat date=$order->date_add"+ 7 days" full=0}

but I don't know, how should this code look like to working

 

Someone knows ? thx

Share this post


Link to post
Share on other sites

Hello @stoner666,

the PHP code you are looking for is:

{"+1 week"|strtotime|date_format:"d.m.Y"}

A short synopsis of the php date format I posted here (in German): https://www.prestashop.com/forums/topic/241513-tipp-datumsformat-richtig-erfassen/. 

Or you might prefer this longer tutorial in English: https://secure.php.net/manual/de/datetime.formats.date.php

If the pdf creation date is ok for you, use this Smarty code:

{$smarty.now|date_format:"%d.%m.%Y"}

Depending on your country maybe you need to change the date format. If you don't know how, folow this Link: https://www.smarty.net/docsv2/de/language.modifier.date.format.tpl

Things like this and more you'll find in this pdf template I posted in my own thread to change the invoice (in the German forum):  https://www.prestashop.com/forums/topic/244719-tutorial-rechnungsformular-ändern-für-version-15x-und-16x/

Share this post


Link to post
Share on other sites