VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: uschmi on March 31, 2012, 21:24:22 PM

Title: Overide pdf invoice
Post by: uschmi on March 31, 2012, 21:24:22 PM
Could someone give me a hint where to override the header and footer of the pdf invoice?
I could easily do this for the body in invoice_items.php and invoice_order.php, but I didn´t found the place where to change to output of the header and footer.
Thanks in advance
Title: Re: Overide pdf invoice
Post by: uschmi on April 01, 2012, 20:56:22 PM
anyone, please?
Title: Re: Overide pdf invoice
Post by: jjk on April 01, 2012, 22:30:35 PM
I don't know for shure, but probably you will find the info you need in one of the following threads:
http://forum.virtuemart.net/index.php?topic=98841.msg326136#msg326136 (http://forum.virtuemart.net/index.php?topic=98841.msg326136#msg326136)
http://forum.virtuemart.net/index.php?topic=99503.0 (http://forum.virtuemart.net/index.php?topic=99503.0)
Title: Re: Overide pdf invoice
Post by: uschmi on April 01, 2012, 23:36:32 PM
Unfortunately there is no hint how to override header/footer in these threads.
Any other ideas?
Title: Re: Overide pdf invoice
Post by: jjk on April 02, 2012, 08:33:32 AM
What exactly do you want to change? The layout or just the information in header and footer?
Title: Re: Overide pdf invoice
Post by: uschmi on April 02, 2012, 08:48:10 AM
Information & layout have to be changed in header+footer.
In germany,  you have to insert informations as f.ex. your adress, tax ident number aso. by law!
In addition, it´s usual to have the banking account informations and logo in the header or footer.
Title: Re: Overide pdf invoice
Post by: jjk on April 02, 2012, 14:43:13 PM
I think primarily you just have to enter your vendor information into 'Shop' - 'Vendor' view in the backend. Header logo must be a jpg image currently. (tcpdf has a problem with png image files). You can place your bank account information into the 'Description' filed for example.

Personally, I would label the outgoing e-mail to "Auftrags-  oder Bestellbestätigung" instead of "Rechnung", because as far as I know the information required in invoices by the 'Umsatzsteuergesetz" doesn't have to be provided in a "Auftragsbestätigung". Also if you email "invoices" right away, the invoice date might not match the date when you actually mail the ordered items.

If you need to alter the code, the relevant files which get rendered by tcpdf are in ...\components\com_virtuemart\views\invoice\tmpl\***.php
Title: Re: Overide pdf invoice
Post by: uschmi on April 02, 2012, 14:55:06 PM
I know that I can change the BODY-code in ...\components\com_virtuemart\views\invoice\tmpl\***.php.
But there is no possibility to change code for header/footer!!!
Title: Re: Overide pdf invoice
Post by: jjk on April 02, 2012, 15:47:46 PM
I currently can't play with tcpdf output because my VM2 SVN version has an issue with that.
Your last post sounds like you are looking for these files  ;) :
...\libraries\tcpdf\tcpdf.php
...\libraries\tcpdf\config\tcpdf_config.php
Title: Re: Overide pdf invoice
Post by: uschmi on April 07, 2012, 20:10:41 PM
I tried with $pdf->setPrintHeader(false); and even tried to manipulate tcpdf.php with no success.
$pdf->setPrintHeader(false); had no effect at all.
By manipulating tcpdf.php I could get a blank header, but I could remove the header-area.

This is essential for german users, because in Germany, you are forced to have several information about your company (as f.ex. tax id...) on your invoice.

Anyone with a solution/idea?
Title: Re: Overide pdf invoice
Post by: alf1234 on June 10, 2012, 03:11:22 AM
i think you should be able to modify the pdf file in:
/components/com_virtuemart/views/invoice/tmpl/invoice.php
it also grabs info from variables set in:
/components/com_virtuemart/views/invoice/view.html.php
such as vendorAddress which is what gets put into your header (the bit you are trying to change).

The problem i have, is you can't override the pdf template. don't know why. if anyone has a solution i would love to know. all the other files in the invoice folder work with override (ie the mail_html_xxxxxxxxx.php files all override perfectly, but the invoice_xxxxxxx.php files dont work with overrride)
Title: Re: Overide pdf invoice
Post by: malaclypse on June 25, 2012, 16:49:31 PM
I can confirm that it is possible to override the mail_html_*.php files in the invoice folder as alf1234 described.

However I'm having a similar issue with invoice_*.php files. The override only works for the pdfs generated in the backend (Orders&Shoppers->Orders->Invoice Button). It does not work for the automatically generated invoice pdfs (attached to the mails) which are sent if an order is set to confirmed.

Joomla 2.5.6 VM 2.0.6
Title: Re: Overide pdf invoice
Post by: c.media on September 26, 2012, 10:02:25 AM
in www\components\com_virtuemart\controllers\invoice.php

search :
$view->addTemplatePath( JPATH_VM_SITE.DS.'views'.DS.'invoice'.DS.'tmpl' );

and replace it by :

$application = JFactory::getApplication();
$templateName = $application->getTemplate();
               
$TempateViewsFolder = JPATH_SITE.DS."templates".DS.$templateName.DS."html".DS."com_virtuemart".DS."invoice";
if(file_exists($TempateViewsFolder)){
$view->addTemplatePath( $TempateViewsFolder);
} else{
$view->addTemplatePath( JPATH_VM_SITE.DS.'views'.DS.'invoice'.DS.'tmpl' );
}
Title: Re: Overide pdf invoice
Post by: c.media on September 26, 2012, 10:46:13 AM
sorry

does not work with template name variable but just if it's name is directly gived, i'll post later a better solution
Title: Re: Overide pdf invoice
Post by: c.media on September 26, 2012, 11:49:31 AM
for the moment, only by hacking :

$templateName = "Put your template name";
$view->addTemplatePath( JPATH_SITE.DS."templates".DS.$templateName.DS."html".DS."com_virtuemart".DS."invoice");

and copy all the invoice views files in the correct template overwrite directory to make it works

Title: Re: Overide pdf invoice
Post by: gastonfl on September 27, 2012, 20:37:40 PM
Quote from: uschmi on March 31, 2012, 21:24:22 PM
Could someone give me a hint where to override the header and footer of the pdf invoice?
I could easily do this for the body in invoice_items.php and invoice_order.php, but I didn´t found the place where to change to output of the header and footer.
Thanks in advance
Did you try editing mail_html_header.php mail_html_footer.php
in invoice/tmpl
?
Title: Re: Overide pdf invoice
Post by: reinhold on November 21, 2012, 18:54:21 PM
Here is the solution to enable template overrides for the invoices:

In components/com_virtuemart/controllers/invoice.php, after the addTemplatePath for the view's default tmpl folder, you need to add the template override path:

$view->addTemplatePath( JPATH_VM_SITE.DS.'views'.DS.$viewName.DS.'tmpl' );
$vmtemplate = VmConfig::get('vmtemplate','default');
if($vmtemplate=='default'){
if(JVM_VERSION == 2){
$q = 'SELECT `template` FROM `#__template_styles` WHERE `client_id`="0" AND `home`="1"';
} else {
$q = 'SELECT `template` FROM `#__templates_menu` WHERE `client_id`="0" AND `menuid`="0"';
}
$db = JFactory::getDbo();
$db->setQuery($q);
$templateName = $db->loadResult();
} else {
$templateName = $vmtemplate;
}

$TemplateOverrideFolder = JPATH_SITE.DS."templates".DS.$templateName.DS."html".DS."com_virtuemart".DS."invoice";
if(file_exists($TemplateOverrideFolder)){
$view->addTemplatePath( $TemplateOverrideFolder);
}


I simply took the code that I found in the function shopFunctionsF::renderMail (file components/com_virtuemart/helpers/shopfunctionsf.php) and adjusted it.

Notice, however, that language overrides also don't work in the invoices!
It seems like the whole virtuemart environment is NOT properly setup when the invoices are generated...
Title: Re: Overide pdf invoice
Post by: WebStuff on December 04, 2012, 12:52:28 PM
I think the problem and some of the confusion with pdf's seems to be that the pdf invoices are generated by two different processes.
There is the one that is generated by the button in the admin view of orders and then there is the one generated when an order is generated, confirmed or whatever you have set as the trigger.
The one generated by the button is not the same as the one stored in your external invoices folder which is generated at the "order generation" stage. You can check this by deleting one of the invoices in that folder and then click the button and the resultant pdf is not regenerated in the folder. This means that there is the possibility of having two different versions of the pdf invoice which seems ludicrous to me.

IMHO the button should first check if the invoice is in the folder, if so then just show that one, if not then generate it.
If when an order is meant to have a pdf attached, i.e. at the confirmed stage then again the email should check if the pdf is already generated in the BE and use that one.

I have struggled trying to get the code changed to not show a link for the product in the emailed pdf.
I have found where to change the code for the button generated pdf and changed this successfully so just the plain item name is shown however none of these changes have any effect on the pdf attached to the emails. These still have a url anchor for the item name.


EDIT:
Solved my own problem with a regex:
Added $html = preg_replace('/<\/?a[^>]*>/','',$html); at around line 188 just before the $pdf->writeHTMLCell call in ./components/com_virtuemart/controllers/invoice.php.
This removes the <a> tags from the $html text before it is written.

Title: Re: Overide pdf invoice
Post by: Milbo on December 18, 2012, 01:53:55 AM
I think you both pdfs freaks should with me in skype and then I can correctly explain the problem.

yes it should first check if there is an invoice already.

Added your fix reinhold
Title: Re: Overide pdf invoice
Post by: neo314 on December 19, 2012, 22:34:05 PM
Quote from: Milbo on December 18, 2012, 01:53:55 AM
I think you both pdfs freaks should with me in skype and then I can correctly explain the problem.

yes it should first check if there is an invoice already.

Added your fix reinhold

As another "PDF Freak" I would like to know what the problem is, and I think it is a pretty important issue. A lot of end users are very focused on how their invoices look. I added reinhold's code to 2.0.14 and it has not made a difference. I'm not surprised because the BE pdf and the email pdf never looked the same anyway.

There needs to be clear (and ideally easy) instructions for altering/overriding all copies of the invoice, and preferably one template from which all the invoice views are derived for consistency. Nobody wants to say here is my invoice... oh that is also my invoice... oh that one is mine to. They want their invoices to look the same.

Right now, I can change the email format and the BE pdf view, but I really NEED to be able to alter the PDF that is attached to the email and I can't seem to do it or find the information on how to do it.
Title: Re: Overide pdf invoice
Post by: reinhold on January 17, 2013, 11:29:46 AM
This is just to let everyone know that I have made a huge patch to virtuemart that properly implements vendor-styled letters in the shop configuration (where you can edit the header/footer of the invoice), unifies the invoice PDF generation to one method, adds delivery notes (or are they better called dispatch notes or packing slips?) and finally really creates the PDF invoices on disk in all cases (so far, the backend link always re-generated the PDF on the fly).

I've sent the huge patches to Milbo, let's see when they get included. It will probably be not in the 2.0.x series of VM, though.

Cheers,
Reinhold

I'm attaching a screenshot of the configuration page, as well as a sample page of the vendor-letter PDF creation.

[attachment cleanup by admin]
Title: Re: Overide pdf invoice
Post by: phobophil on January 17, 2013, 18:35:23 PM
The whole day I was looking for solutions styling my invoice and got a little bit frustrated. And then, very good news. Thank you reinhold! Please dont let me wait too long... I will try to be patient. It would be nice to know when your update will be implemented,  approximately tomorrow or some month later?  8)

phobophil
Title: Re: Overide pdf invoice
Post by: reinhold on January 17, 2013, 22:17:41 PM
Quote from: phobophil on January 17, 2013, 18:35:23 PM
It would be nice to know when your update will be implemented,  approximately tomorrow or some month later?  8)

The code changes for VirtueMart are already finished (here on my harddisk). I have sent those changes to Milbo (the VirtueMart maintainer), so he can include it in future releases. AFAIK, the next release will be Virtuemart 2.1, which might take a little while due to some new larger features that need some ironing out... So, you better ask milbo about an estimate.
Title: Re: Overide pdf invoice
Post by: baqpad on March 02, 2013, 18:24:19 PM
Quote from: reinhold on January 17, 2013, 22:17:41 PM
...the next release will be Virtuemart 2.1, which might take a little while due to some new larger features that need some ironing out... So, you better ask milbo about an estimate.

Any news yet about VM 2.1?
Title: Re: Overide pdf invoice
Post by: lindapowers on March 03, 2013, 04:40:47 AM
No idea, they just released 2.018C

Title: Re: Overide pdf invoice
Post by: Eireann75 on March 12, 2013, 15:59:06 PM
reinhold, your changes to the invoice creation and logic look very promising! Just what I have been looking for. Me and my client hope to see those changes implemented very soon. we would even gladly pay for it if it was an extension sans code hacks of any kind.