Skip to main content

Invoice.php Broken

More
1 week 3 days ago - 1 week 3 days ago #373403 by mohairbears
-- HikaShop version -- : 6.6.0
-- Joomla version -- : 5.4.8
-- PHP version -- : 8.4.24
-- Browser(s) name and version -- : Chrome

Hi, Updated to the new version of Invoice PDF and its now completely broken!

For some time when updating I have to save a copy of invoice.php as when updating it always overwrites my own version which far more professional.

This is the php I have been using since 2022 without issue!
Code:
<?php /** * @package PDF invoice plugin for HikaShop * @version 1.1.4 * @author Adrien Baborier, Hikari Software * @copyright (C) 2010-2022 HIKARI SOFTWARE. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); ?><style type="text/css"> <!-- .invoicetitle{ text-align:left; font-size:30px; font-weight:bold; padding-top:30px;padding-bottom:30px} legend { padding:5px 20px; background-color:#5471B5;color:white;font-weight:bold;border-color:#ccc} fieldset { padding:10px; border-color:#ffffff; } div.date{color:#333;padding-left: 500px} div.width{max-width: 490px} div.date{text-align:right;color:#333;} .storeaddress{ color:#333; } .addresses{padding-top:10px;} .addresses td{padding-left:15px;} .addresses fieldset {float:left;width:320px;} table.products{margin:auto;margin-top:40px;width:580px;border-collapse:collapse} .price{text-align:center;} .products td, .products th{border:1px solid #ccc;padding:7px 4px;} .products th{background-color:#5471B5;color:white;} td.newarea{text-align:right;padding-right:20px;} tr.total{font-weight:bold;} .products tr.limitation td{background-color:#ccc;padding:1px 0px;} .hikashop_order_custom_fields_fieldset{margin-top : 20px;} .hikashop_order_custom_fields_table tr{width: 800px;} .footer{font-size:10px;color:#aaa;text-align:center;} --> </style> <page style="font-size: 14px" backtop="4mm" backbottom="8mm" backleft="10mm" backright="10mm"> <page_footer> <div class="footer"> <?php $name = $this->params->get('footer'); $trans = hikashop_translate($name); echo str_replace(array("\r\n","\n","\r"),array('<br/>','<br/>','<br/>'), $trans); ?> </div> </page_footer> <?php echo "INVOICE SUMMARY"; ?> <br> <br> <?php $image_address_path = trim($config->get('image_address_path')); $img_style_css = trim($config->get('img_style_css')); if ($image_address_path != '') { $img_style = ''; if ($img_style_css != '') { $img_style = $img_style_css; } ?> <div class="hika_invoice_img"> <img src="<?php echo $image_address_path; ?>" style="<?php echo $img_style; ?>"> </div> <?php } ?> <div class="storeaddress"> <?php $store = str_replace(array("\r\n","\n","\r"),array('<br/>','<br/>','<br/>'),$config->get('store_address','')); if(JText::_($store)!=$store){ $store = JText::_($store); } echo $store; ?> </div> <?php if(empty($order->order_invoice_number)){ $order->order_invoice_number = $order->order_number; } if(empty($order->order_invoice_created)){ $order->order_invoice_created = $order->order_created; } if($this->shipping_invoice){ $number = JText::_('SHIPPING_INVOICE').' n° '; if(JText::_('SHIPPING_INVOICE_NUMBER') != 'SHIPPING_INVOICE_NUMBER'){ $number = JText::_('SHIPPING_INVOICE_NUMBER').' '; } $item_type = 'display:back_shipping_invoice=1'; }else{ $number = JText::_('INVOICE').' n° '; if(JText::_('INVOICE_NUMBER') != 'INVOICE_NUMBER'){ $number = JText::_('INVOICE_NUMBER').' '; } $item_type = 'display:back_invoice=1'; } ?> <div class="date"><?php echo JText::_('INVOICE').': '.$order->order_invoice_number; ?></div> <div class="date"><?php echo JText::_('DATE').': '.hikashop_getDate($order->order_invoice_created,'%d %B %Y ');?></div> <table class="addresses"> <tr> <?php $addresses = array('billing_address','shipping_address'); foreach($addresses as $oneAddress){ if(empty($order->$oneAddress)) continue; if ($oneAddress=='shipping_address' && empty($pluginsShipping)) continue; ?> <td valign="top"> <fieldset> <legend><?php echo JText::_('HIKASHOP_'.strtoupper($oneAddress)); ?></legend> <?php $override = false; if(!empty($order->override_shipping_address) && $oneAddress=='shipping_address') { $override = $order->override_shipping_address; } if($override !== false ) { echo $override; } else { $addressClass = hikashop_get('class.address'); if(hikashop_isClient('administrator')){ $view = 'order'; }else{ $view = 'address'; } echo $addressClass->displayAddress($order->fields,$order->$oneAddress,$view); } ?> </fieldset> </td> <?php } ?> </tr> </table> <?php $shipping_invoice = ''; if($this->shipping_invoice){ $shipping_invoice = 'shipping_'; } $weight = bccomp((float)$order->order_weight, 0, 3); $unit_weight = false; if($weight && $config->get('show_'.$shipping_invoice.'invoice_unit_weight',0)) $unit_weight = true; $total_weight = false; if($weight && $config->get('show_'.$shipping_invoice.'invoice_total_weight',0)) $total_weight = true; $order_weight = false; if($weight && $config->get('show_'.$shipping_invoice.'invoice_weight',0)) $order_weight = true; ?> <table class="products"> <tr class="products_title"> <?php if($this->shipping_invoice){ ?> <th style="width:500px"> <?php }else{ ?> <th style="width:380px"> <?php } ?> <?php echo JText::_('PRODUCT'); ?> </th> <?php if($unit_weight) { echo '<th style="width:80px" class="price">' . JText::_('PRODUCT_WEIGHT') . '</th>'; } ?> <th style="width:50px" class="price"> <?php echo JText::_('PRODUCT_QUANTITY'); ?> </th> <?php if(!$this->shipping_invoice){ ?> <th style="width:80px" class="price"> <?php echo JText::_('UNIT_PRICE'); ?> </th> <?php } if($total_weight) { echo '<th style="width:40px" class="price">' . JText::_('TOTAL_WEIGHT') . '</th>'; } if(!$this->shipping_invoice){ ?> <th style="width:80px" class="price"> <?php echo JText::_('PRICE'); ?> </th> <?php } ?> </tr> <?php $fieldsClass = hikashop_get('class.field'); $group = $config->get('group_options',0); foreach($order->products as $product){ if($group && $product->order_product_option_parent_id) continue; ?> <tr> <td> <?php echo implode('<br/>',$this->str_split_unicode(strip_tags($product->order_product_name),80)); if($group && !$this->shipping_invoice){ $display_item_price=false; foreach($order->products as $j => $optionElement){ if($optionElement->order_product_option_parent_id != $product->order_product_id) continue; if($optionElement->order_product_price>0){ $display_item_price = true; } } if($display_item_price){ if($config->get('price_with_tax')){ echo ' '.$currencyHelper->format($product->order_product_price+$product->order_product_tax,$order->order_currency_id); }else{ echo ' '.$currencyHelper->format($product->order_product_price,$order->order_currency_id); } } } $itemFields = $fieldsClass->getFields($item_type,$product,'item'); if(!empty($itemFields)){ foreach($itemFields as $field){ $namekey = $field->field_namekey; if(!empty($product->$namekey) && strlen($product->$namekey)) { echo '<p>'.implode('<br/>',$this->str_split_unicode(strip_tags($fieldsClass->getFieldName($field).': '.$fieldsClass->show($field,$product->$namekey,'user_email')),50)).'</p>'; } } } if($group){ foreach($order->products as $j => $optionElement){ if($optionElement->order_product_option_parent_id != $product->order_product_id) continue; $product->order_product_weight += $optionElement->order_product_weight; $product->order_product_price +=$optionElement->order_product_price; $product->order_product_tax +=$optionElement->order_product_tax; $product->order_product_total_price+=$optionElement->order_product_total_price; $product->order_product_total_price_no_vat+=$optionElement->order_product_total_price_no_vat; ?><br/><?php $option_name = $optionElement->order_product_name; if($optionElement->order_product_price>0 && !$this->shipping_invoice){ if($config->get('price_with_tax')){ $option_name .= ' ( + '.$currencyHelper->format($optionElement->order_product_price+$optionElement->order_product_tax,$order->order_currency_id).' )'; }else{ $option_name .= ' ( + '.$currencyHelper->format($optionElement->order_product_price,$order->order_currency_id).' )'; } } echo '<p>'.implode('<br/>', $this->str_split_unicode(strip_tags($option_name),50)).'</p>'; } } if ($config->get('show_code')) { echo '<br/>'.$product->order_product_code; } ?> </td> <?php if($unit_weight) { echo '<td class="price">' . rtrim(rtrim($product->order_product_weight,'0'),',.').' '.JText::_($product->order_product_weight_unit) . '</td>'; } ?> <td class="price"> <?php echo $product->order_product_quantity;?> </td> <?php if(!$this->shipping_invoice){ ?> <td class="price"> <?php if($config->get('price_with_tax')){ echo $currencyHelper->format($product->order_product_price+$product->order_product_tax,$order->order_currency_id); }else{ echo $currencyHelper->format($product->order_product_price,$order->order_currency_id); } ?> </td> <?php } ?> <?php if($total_weight) { echo '<td class="price">' . rtrim(rtrim($product->order_product_weight*$product->order_product_quantity,'0'),',.').' '.JText::_($product->order_product_weight_unit) . '</td>'; } ?> <?php if(!$this->shipping_invoice){ ?> <td class="price"> <?php if($config->get('price_with_tax')){ echo $currencyHelper->format($product->order_product_total_price,$order->order_currency_id); }else{ echo $currencyHelper->format($product->order_product_total_price_no_vat,$order->order_currency_id); } ?> </td> <?php } ?> </tr> <?php } ?> <?php if(!$this->shipping_invoice){ ?> <tr class="limitation"><td colspan="4"></td></tr> <tr> <td colspan="3" class="newarea"> <?php echo JText::_( 'SUBTOTAL' ); ?> </td> <td class="price"> <?php if($config->get('price_with_tax')){ echo $currencyHelper->format($order->order_subtotal,$order->order_currency_id); }else{ echo $currencyHelper->format($order->order_subtotal_no_vat,$order->order_currency_id); } ?> </td> </tr> <?php $taxes = $currencyHelper->round($order->order_subtotal - $order->order_subtotal_no_vat - $order->order_discount_tax + $order->order_shipping_tax + $order->order_payment_tax, $currencyHelper->getRounding($order->order_currency_id,true)); if(!empty($order->order_discount_code)){ ?> <tr> <td colspan="3" class="newarea"> <?php echo JText::_( 'HIKASHOP_COUPON' ); ?> </td> <td class="price"> <?php if($config->get('price_with_tax')){ echo $currencyHelper->format($order->order_discount_price*-1,$order->order_currency_id); }else{ echo $currencyHelper->format(($order->order_discount_price-@$order->order_discount_tax)*-1,$order->order_currency_id); } ?> </td> </tr> <?php } if(!empty($order->order_shipping_method)){ ?> <tr> <td colspan="3" class="newarea"> <?php echo JText::_( 'SHIPPING' ); ?> </td> <td class="price" > <?php if($config->get('price_with_tax')){ echo $currencyHelper->format($order->order_shipping_price,$order->order_currency_id); }else{ echo $currencyHelper->format($order->order_shipping_price-@$order->order_shipping_tax,$order->order_currency_id); } ?> </td> </tr> <?php } if(!empty($order->additional)) { $exclude_additionnal = explode(',', $config->get('order_additional_hide', '')); foreach($order->additional as $additional) { if(in_array(@$additional->name, $exclude_additionnal)) continue; echo '<tr><td colspan="3" class="newarea">'. JText::_($additional->order_product_name).'</td><td class="price">'; if(!empty($additional->order_product_price) || empty($additionaltionnal->order_product_options)) { if($config->get('price_with_tax')){ echo $currencyHelper->format($additional->order_product_price+@$additional->order_product_tax, $order->order_currency_id); }else{ echo $currencyHelper->format($additional->order_product_price, $order->order_currency_id); } } else { echo $additional->order_product_options; } echo '</td></tr>'; } } if(!empty($order->order_payment_method) && $order->order_payment_price != 0){ ?> <tr> <td colspan="3" class="newarea"> <?php echo JText::_( 'HIKASHOP_PAYMENT' ); ?> </td> <td class="price"><?php if($config->get('price_with_tax')) { echo $currencyHelper->format($order->order_payment_price, $order->order_currency_id); } else { echo $currencyHelper->format($order->order_payment_price - @$order->order_payment_tax, $order->order_currency_id); } ?></td> </tr> <?php } if($taxes > 0){ if($config->get('detailed_tax_display') && !empty($order->order_tax_info)){ foreach($order->order_tax_info as $tax){ ?> <tr> <td colspan="3" class="newarea"> <?php if( function_exists('hikashop_translate')) echo hikashop_translate($tax->tax_namekey); else echo $tax->tax_namekey; ?> </td> <td class="price"> <?php echo $currencyHelper->format($tax->tax_amount,$order->order_currency_id); ?> </td> </tr> <?php } }else{ ?> <tr> <td colspan="3" class="newarea"> <?php echo JText::_( 'VAT' ); ?> </td> <td class="price"> <?php echo $currencyHelper->format($taxes,$order->order_currency_id); ?> </td> </tr> <?php } } ?> <tr class="total"> <td colspan="3" class="newarea"> <?php echo JText::_( 'HIKASHOP_TOTAL' ); ?> </td> <td class="price" > <?php echo $currencyHelper->format($order->order_full_price,$order->order_currency_id); ?> </td> </tr> <?php } ?> </table> <p> <?php if (!empty($pluginsShipping)) echo JText::_('HIKASHOP_SHIPPING_METHOD1').' : '.$pluginsShipping->getName($order->order_shipping_method, $order->order_shipping_id).'<br/>' ; if(!empty($pluginsPayment)) echo JText::_('HIKASHOP_PAYMENT_METHOD1').' : '.$pluginsPayment->getName($order->order_payment_method, $order->order_payment_id).'<br/>'; ?> </p> <br/> <?php if(hikashop_level(2) && !empty($fields['order'])){ ob_start(); foreach($fields['order'] as $fieldName => $oneExtraField) { if(!@$oneExtraField->field_frontcomp || empty($order->$fieldName)) continue; ?> <tr class="hikashop_order_custom_field_<?php echo $fieldName;?>_line"> <td class="key"> <?php echo $fieldsClass->getFieldName($oneExtraField);?> </td> <td> <?php echo $fieldsClass->show($oneExtraField,$order->$fieldName,'user_email'); ?> </td> </tr> <?php } $additionalInfo = ob_get_clean(); if(!empty($additionalInfo)){ ?> <fieldset class="hikashop_order_custom_fields_fieldset"> <legend><?php echo JText::_('ADDITIONAL_INFORMATION'); ?></legend> <table class="hikashop_order_custom_fields_table adminlist" cellpadding="1" width="100%"> <?php echo $additionalInfo; ?> </table> </fieldset> <br/> <?php } } ?> </page>
Please see what happen now! there is my version (how it should look), your version and whats happening when now when I use my version.
Last edit: 1 week 3 days ago by nicolas.

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago #373405 by nicolas
Replied by nicolas on topic Invoice.php Broken
Hi,

Thank you for the screenshots, they made it easy to find. Your invoice.php was written for the previous PDF engine and its styles are most likely wrapped between <!-- and --> inside the <style> tag, as in older versions of the default layout. The new engine of the PDF invoice plugin 5.0.x reads that as a comment, so all your styles are ignored and one CSS rule added by the plugin ends up printed at the top of the invoice.

We fixed this in version 5.0.3 of the plugin. Once you update it, your layout should display as it did before.

So that updates stop overwriting your layout, you can make your changes via the "You can edit the PDF layouts here" link in the settings of the PDF invoice plugin instead of editing the file in the plugin folder: your version is then saved as an override that the updates should leave alone.

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago #373407 by mohairbears
Replied by mohairbears on topic Invoice.php Broken
Hi, I only downloaded and installed on Thursday, the PDF is showing version 4.1.4??

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago #373409 by nicolas
Replied by nicolas on topic Invoice.php Broken
Hi,

Read carefully both blue buttons. The first one is for the latest version. The second one is for the old 4.1.4 version.

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago #373411 by mohairbears
Replied by mohairbears on topic Invoice.php Broken
Hi I did wonder?

Sort of worked but there are still changes to it that were not there before I first updated last week?
Look at my good one I send against this one?
1. Lines/box around the addresses
2. The product columns should be wider to accommodate long product titles, the width used to run the width of the page

Thanks

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago #373414 by nicolas
Replied by nicolas on topic Invoice.php Broken
Hi,

Thanks for the screenshots. I compared your invoice.php with the old PDF engine and the new one, and both differences come from the plugin, not from your file:
- your layout hides the box around the addresses with a white border (border-color:#ffffff on fieldset), but the new engine always drew that box with a grey border
- the old engine added the padding of each cell around the column widths, which made the products table wider than the widths written in the layout. The new engine didn't, so the table came out narrower

Version 5.0.5 of the plugin handles both. With your invoice.php, I get the addresses without the box and the products table across the page like on your good invoice. So once you update the plugin, it should look like before, again without any change to your invoice.php.

As before, if your invoice.php is in the plugin folder, the update will replace it, so keep a copy to put it back, or better, paste it in the PDF layout editor available from the plugin settings so that it is kept on updates.

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago #373418 by mohairbears
Replied by mohairbears on topic Invoice.php Broken
that worked:) thank you
The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.218 seconds
Powered by Kunena Forum