alfredopacino Posted July 15, 2014 Share Posted July 15, 2014 (edited) i need a little help with the invoice template: this is my invoice.tpl, in attachment the pdf screenshot <div style="font-size: 8pt; color: #444"> <!-- shop info --> <div style="text-align:right"> <table style=""> <tr> <td style="text-align: right; font-size: 11pt; color: #444"> <!-- {$shop_address|escape:'htmlall':'UTF-8'}--> <br /> {if isset($shop_details)} {$shop_details|escape:'htmlall':'UTF-8'}<br /> {/if} {if !empty($shop_phone) OR !empty($shop_fax)} {if !empty($shop_phone)} Tel: {$shop_phone|escape:'htmlall':'UTF-8'}<br /> {/if} {if !empty($shop_fax)} Fax: {$shop_fax|escape:'htmlall':'UTF-8'} {/if} <br /> {/if} </td> </tr> </table> </div> <!-- /shop info --> <!-- ADDRESSES --> <table style="width: 100%; font-size: 11pt; color: #000;"> <tr> <td style="width: 5%"> </td> <td style="width: 45%; height: 110px;"> <span style="font-weight: bold;">{l s='Billing Address' pdf='true'}</span> <br /><br /> {$invoice_address} </td> <td style="width: 45%; height: 110px;"> <span style="font-weight: bold;">{l s='Delivery Address' pdf='true'}</span> <br /><br /> {if empty($delivery_address)} {$invoice_address} {else} {$delivery_address} {/if} </td> <td style="width: 5%"> </td> </tr> </table> <!-- / ADDRESSES --> <br /><br /> <table style="width: 100%; text-align: center; border: 1px solid #CCC; font-size: 9pt;"> <tr> <td style="width: 33%; background-color: #CCC; color: #000;"> <b>{l s='Order Number:' pdf='true'}</b> </td> <td style="width: 33%; background-color: #CCC; color: #000;"> <b>{l s='Order Date:' pdf='true'}</b> </td> <td style="width: 34%; background-color: #CCC; color: #000;"> <b>{l s='Payment Method:' pdf='true'}</b> </td> </tr> <tr> <td style="width: 33%;"> {$order->getUniqReference()} </td> <td style="width: 33%;"> {$order->date_add|date_format:"%d-%m-%Y %H:%M"} </td> <td style="width: 34%;"> {foreach from=$order_invoice->getOrderPaymentCollection() item=payment} <b>{$payment->payment_method}</b> : {displayPrice price=$payment->amount currency=$order->id_currency} {foreachelse} {l s='No payment' pdf='true'} {/foreach} </td> </tr> </table> <br /> {foreach from=$order->getShipping() item=shipping name=shippingsLoop} <table style="width: 100%; text-align: center; border: 1px solid #CCC; font-size: 9pt;"> <tr> <td colspan = "3" style="background-color: #CCC; color: #000;"> <b>{l s='Shipping #' pdf='true'}{$smarty.foreach.shippingsLoop.iteration}</b> </td> </tr> <tr> <td style="width: 33%; background-color: #EEE; color: #000;"> <b>{l s='Peso:' pdf='true'}</b> </td> <td style="width: 33%; background-color: #EEE; color: #000;"> <b>{l s='Corriere:' pdf='true'}</b> </td> <td style="width: 34%; background-color: #EEE; color: #000;"> <b>{l s='Track Spedizione:' pdf='true'}</b> </td> </tr> <tr> <td style="width: 33%;"> {$shipping.weight|string_format:"%.2f"} Kg </td> <td style="width: 33%;"> {$shipping.state_name} </td> <td style="width: 34%;"> {$shipping.tracking_number} </td> </tr> </table> {/foreach} <br /><br /> <!-- PRODUCTS TAB --> <table style="width: 100%; font-size: 8pt;"> <tr style="line-height:4px;"> <td style="text-align: left; background-color: #CCC; color: #000; padding-left: 10px; font-weight: bold; width: 12%">{l s='Reference' pdf='true'}</td> <td style="text-align: left; background-color: #CCC; color: #000; padding-left: 10px; font-weight: bold; width: 42%">{l s='Articolo' pdf='true'}</td> <!-- unit price tax excluded is mandatory --> {if !$tax_excluded_display} <td style="background-color: #CCC; color: #000; text-align: right; font-weight: bold; width: 10%">{l s='Unit Price' pdf='true'} <br />{l s='(Tax Excl.)' pdf='true'}</td> {/if} <td style="background-color: #CCC; color: #000; text-align: right; font-weight: bold; width: 10%"> {l s='Unit Price' pdf='true'} {if $tax_excluded_display} {l s='(Tax Excl.)' pdf='true'} {else} {l s='(Tax Incl.)' pdf='true'} {/if} </td> <td style="background-color: #CCC; color: #000; text-align: right; font-weight: bold; width: 9%">{l s='Discount' pdf='true'}</td> <td style="background-color: #CCC; color: #000; text-align: center; font-weight: bold; width: 5%">{l s='Qty' pdf='true'}</td> <td style="background-color: #CCC; color: #000; text-align: right; font-weight: bold; width: 12%"> {l s='Total' pdf='true'} {if $tax_excluded_display} {l s='(Tax Excl.)' pdf='true'} {else} {l s='(Tax Incl.)' pdf='true'} {/if} </td> </tr> <!-- PRODUCTS --> {foreach $order_details as $order_detail} {cycle values='#FFF,#EEE' assign=bgcolor} <tr style="line-height:6px;background-color:{$bgcolor};"> <td style="text-align: center;"> {if !empty($order_detail.product_reference)} {$order_detail.product_reference} {else} -- {/if} </td> <td style="text-align: left;">{$order_detail.product_name}</td> <!-- unit price tax excluded is mandatory --> {if !$tax_excluded_display} <td style="text-align: right; width: 10%"> {displayPrice currency=$order->id_currency price=$order_detail.unit_price_tax_excl} </td> {/if} <td style="text-align: right;"> {if $tax_excluded_display} {displayPrice currency=$order->id_currency price=$order_detail.unit_price_tax_excl} {else} {displayPrice currency=$order->id_currency price=$order_detail.unit_price_tax_incl} {/if} </td> <td style="text-align: right;"> {if (isset($order_detail.reduction_amount) && $order_detail.reduction_amount > 0)} -{displayPrice currency=$order->id_currency price=$order_detail.reduction_amount} {else if (isset($order_detail.reduction_percent) && $order_detail.reduction_percent > 0)} -{$order_detail.reduction_percent}% {else} -- {/if} </td> <td style="text-align: center;">{$order_detail.product_quantity}</td> <td style="text-align: right;"> {if $tax_excluded_display} {displayPrice currency=$order->id_currency price=$order_detail.total_price_tax_excl} {else} {displayPrice currency=$order->id_currency price=$order_detail.total_price_tax_incl} {/if} </td> </tr> {foreach $order_detail.customizedDatas as $customizationPerAddress} {foreach $customizationPerAddress as $customizationId => $customization} <tr style="line-height:6px;background-color:{$bgcolor}; "> <td style="line-height:3px; text-align: left; width: 60%; vertical-align: top"> <blockquote> {if isset($customization.datas[$smarty.const._CUSTOMIZE_TEXTFIELD_]) && count($customization.datas[$smarty.const._CUSTOMIZE_TEXTFIELD_]) > 0} {foreach $customization.datas[$smarty.const._CUSTOMIZE_TEXTFIELD_] as $customization_infos} {$customization_infos.name}: {$customization_infos.value} {if !$smarty.foreach.custo_foreach.last}<br /> {else} <div style="line-height:0.4pt"> </div> {/if} {/foreach} {/if} {if isset($customization.datas[$smarty.const._CUSTOMIZE_FILE_]) && count($customization.datas[$smarty.const._CUSTOMIZE_FILE_]) > 0} {count($customization.datas[$smarty.const._CUSTOMIZE_FILE_])} {l s='image(s)' pdf='true'} {/if} </blockquote> </td> <td style="text-align: right; width: 15%"></td> <td style="text-align: center; width: 10%; vertical-align: top">({$customization.quantity})</td> <td style="width: 15%; text-align: right;"></td> </tr> {/foreach} {/foreach} {/foreach} <!-- END PRODUCTS --> <!-- CART RULES --> {assign var="shipping_discount_tax_incl" value="0"} {foreach $cart_rules as $cart_rule} {cycle values='#FFF,#DDD' assign=bgcolor} <tr style="line-height:6px;background-color:{$bgcolor}; text-align:right;"> <td colspan="{if !$tax_excluded_display}6{else}5{/if}">{$cart_rule.name}</td> <td> {if $cart_rule.free_shipping} {assign var="shipping_discount_tax_incl" value=$order_invoice->total_shipping_tax_incl} {/if} {if $tax_excluded_display} - {displayPrice currency=$order->id_currency price=$cart_rule.value_tax_excl} {else} - {displayPrice currency=$order->id_currency price=$cart_rule.value} {/if} </td> </tr> {/foreach} <!-- END CART RULES --> </table> <table style="width: 100%;"> {if (($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl) > 0)} <tr style="line-height:5px;"> <td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Excl.)' pdf='true'}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products}</td> </tr> <tr style="line-height:5px;"> <td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Incl.)' pdf='true'}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products_wt}</td> </tr> {else} <tr style="line-height:5px;"> <td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total' pdf='true'}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products}</td> </tr> {/if} {if $order_invoice->total_discount_tax_incl > 0} <tr style="line-height:5px;"> <td style="text-align: right; font-weight: bold">{l s='Total Vouchers' pdf='true'}</td> <td style="width: 15%; text-align: right;">-{displayPrice currency=$order->id_currency price=($order_invoice->total_discount_tax_incl + $shipping_discount_tax_incl)}</td> </tr> {/if} {if $order_invoice->total_wrapping_tax_incl > 0} <tr style="line-height:5px;"> <td style="text-align: right; font-weight: bold">{l s='Wrapping Cost' pdf='true'}</td> <td style="width: 15%; text-align: right;"> {if $tax_excluded_display} {displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_excl} {else} {displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_incl} {/if} </td> </tr> {/if} {if $order_invoice->total_shipping_tax_incl > 0} <tr style="line-height:5px;"> <td style="text-align: right; font-weight: bold">{l s='Shipping Cost' pdf='true'}</td> <td style="width: 15%; text-align: right;"> {if $tax_excluded_display} {displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_excl} {else} {displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_incl} {/if} </td> </tr> {/if} {if ($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl) > 0} <tr style="line-height:5px;"> <td style="text-align: right; font-weight: bold">{l s='Total Tax' pdf='true'}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl)}</td> </tr> {/if} <tr style="line-height:5px;"> <td style="text-align: right; font-weight: bold">{l s='Total' pdf='true'}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_paid_tax_incl}</td> </tr> </table> <!-- / PRODUCTS TAB --> <div style="line-height: 1pt"> </div> {$tax_tab} {if isset($order_invoice->note) && $order_invoice->note} <div style="line-height: 1pt"> </div> <table style="width: 100%"> <tr> <td style="width: 15%"></td> <td style="width: 85%">{$order_invoice->note|nl2br}</td> </tr> </table> {/if} {if isset($HOOK_DISPLAY_PDF)} <div style="line-height: 1pt"> </div> <table style="width: 100%"> <tr> <td style="width: 15%"></td> <td style="width: 85%">{$HOOK_DISPLAY_PDF}</td> </tr> </table> {/if} </div> As you can see it could be improved: 1. the red code in invoice.tpl should be placed in header.tpl, before date and invoice number, but if I paste this code in header it doesn't show anything. I think the var $shop_details, $shop_phone, $shop_fax aren't visible in header.tpl. 2. in the product table, as you can see the prices and tax columns have a too small width, but in the tpl. have width:15% 3. I need to change the Shop name in the footer, not the PS shop name, just in the invoices. Edited July 15, 2014 by alfredopacino (see edit history) 1 Link to comment Share on other sites More sharing options...
wjbeckett Posted September 8, 2014 Share Posted September 8, 2014 Did you ever get this figured out? I'm running into the same issues with my invoice. If I try to put certain variables in the header it just breaks. Link to comment Share on other sites More sharing options...
alfredopacino Posted September 8, 2014 Author Share Posted September 8, 2014 nop sorry the client preferred to disable completely the invoice PS function, he prefer manages the invoices manually Link to comment Share on other sites More sharing options...
wjbeckett Posted September 8, 2014 Share Posted September 8, 2014 ahh that's okay! I've been playing around with the invoice on my end. Ended up giving up on trying to get the Order number into the header. Obviously it doesn't know anything about those variables.I just worked it into the body of the invoice. Wish there was an easier way to 'prettify' invoices without having to spend a great deal of money on modules.Oh well, all part of the learning curve I guess! Thanks for getting back to me anyway! Link to comment Share on other sites More sharing options...
tuk66 Posted September 10, 2014 Share Posted September 10, 2014 The invoice is divided to three parts - header.tpl, invoice.tpl and footer.tpl. You must follow this approach. Link to comment Share on other sites More sharing options...
wjbeckett Posted September 10, 2014 Share Posted September 10, 2014 The invoice is divided to three parts - header.tpl, invoice.tpl and footer.tpl. You must follow this approach. I have been following this approach. It seems I can't get certain code to work in the header though. For example, I can't get the Order number to show in the header. it just fails to load the invoice after I create it. If I remove the code, it's fine. I also am having issues where the <td syle="font-weight: bold;"> blah blah </td> doesn't actually bold anything. Not sure if it's the particular font I'm using or not though. Link to comment Share on other sites More sharing options...
tuk66 Posted September 10, 2014 Share Posted September 10, 2014 You need appropriate variables in templates. See getHeader, getContent and getFooter functions in /classes/pdf/HTML* files. 2 Link to comment Share on other sites More sharing options...
wjbeckett Posted September 10, 2014 Share Posted September 10, 2014 So the variables that work in the invoice.tpl won't necessarily work in the header or footer? Link to comment Share on other sites More sharing options...
tuk66 Posted September 10, 2014 Share Posted September 10, 2014 You have come to this. Link to comment Share on other sites More sharing options...
wjbeckett Posted September 10, 2014 Share Posted September 10, 2014 You have come to this. I'm not sure I follow? Link to comment Share on other sites More sharing options...
epidote Posted November 11, 2014 Share Posted November 11, 2014 Thanks to tuk66 for the tip to add variables to header. For anyone interested, in PS 1.6 at least, you just modify HTMLTemplate.php 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); //////// I ADDED THIS TO BRING IN CUSTOMER INFO FROM HTMLTemplateInvoice.php $customer = new Customer((int)$this->order->id_customer); $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, //////////YOUR CUSTOM VARIABLE IN MY CASE I WANTED THE CUSTOMER GROUP 'custgroup' => $customer->id_default_group, ////////////////// 'shop_name' => $shop_name, 'width_logo' => $width, 'height_logo' => $height )); return $this->smarty->fetch($this->getTemplate('header')); } then add the variable to header.tpl {if $custgroup != 4} Additional text for other customers here {/if} // OR JUST USE THE VARIABLE {$custgroup} seems like a hack for the classes, I've copied the pdf/ into my theme dir so it won't be overwritten but can you do the same for the classes? Link to comment Share on other sites More sharing options...
Mickeel Posted January 8, 2015 Share Posted January 8, 2015 Thanks to tuk66 for the tip to add variables to header. For anyone interested, in PS 1.6 at least, you just modify HTMLTemplate.php 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); //////// I ADDED THIS TO BRING IN CUSTOMER INFO FROM HTMLTemplateInvoice.php $customer = new Customer((int)$this->order->id_customer); $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, //////////YOUR CUSTOM VARIABLE IN MY CASE I WANTED THE CUSTOMER GROUP 'custgroup' => $customer->id_default_group, ////////////////// 'shop_name' => $shop_name, 'width_logo' => $width, 'height_logo' => $height )); return $this->smarty->fetch($this->getTemplate('header')); } then add the variable to header.tpl {if $custgroup != 4} Additional text for other customers here {/if} // OR JUST USE THE VARIABLE {$custgroup} seems like a hack for the classes, I've copied the pdf/ into my theme dir so it won't be overwritten but can you do the same for the classes? AFAIK, we need to put it inside overrides folder to override the classes, because it wont work in theme dir. CMIIW Link to comment Share on other sites More sharing options...
Recommended Posts