News:

Support the VirtueMart project and become a member

Main Menu

Overide pdf invoice

Started by uschmi, March 31, 2012, 21:24:22 PM

Previous topic - Next topic

gastonfl

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
?

reinhold

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...

WebStuff

#17
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.


Milbo

#18
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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

neo314

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.

reinhold

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]

phobophil

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

reinhold

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.

baqpad

#23
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?

lindapowers

#24
No idea, they just released 2.018C


Eireann75

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.