How to customize layout for %invoice_text%?

Discussion in 'Templates customization' started by orish, May 20, 2014.

  1. orish

    orish aMember Pro Customer

    Joined:
    Mar 15, 2011
    Messages:
    45
    Hi, I noticed there was another thread related to this question, but it seemed to involve recoding a core PHP file.

    I need to send a confirmation email to my customers for their payments, but at the moment it's a real mess and looks very unprofessional.

    This is what my customers get:

    Invoice #DC6EB / 20/05/2014 ------------------------------------------------------------------- 1. Read Thai Video Workshop Package MP4 1x10000.00 7500.00 THB ------------------------------------------------------------------- Subtotal 10000.00 THB Discount 2500.00 THB Total 7500.00 THB -------------------------------------------------------------------

    I'd like to define a layout and format the purchase items.
    • There's only one item that gets purchased at a time in my case, although there may be some free add-ons.
    • Because I'm using the Thai Baht as the currency, it's messy to add the .00 at the end of each amount and I need to add in the thousands comma.
    • Also the currency symbol should be on the left hand side, not the right of the amount
    • The currency symbol should only appear on the total amount.
    • If there is no discount then there is no need for a total amount - just the price of the item (in which case it will have the currency symbol).
    • I also don't need the date (the date of payment is the date of the email) or invoice number because it's completely irrelevant.
    • Finally, the dashed lines makes the layout look amateur, especially when the email confirmation is in HTML. Either use an HTML table or leave out the lines completely.
    So the above invoice (actually it's not an invoice, it's a receipt) should look like this:

    Purchase Details
    Read Thai Video Workshop Package MP4 10,000
    Discount Coupon (student) 2,500
    Total paid THB 7,500

    How do I do this, preferably without writing a mini program to do it?
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,993
    First of all in case you use %invoice_text% placeholder in context of HTML you need to wrap it with <pre> tags eg.
    HTML:
    <pre>
    %invoice_text%
    </pre>
    It is not possible to customize output of this placeholder without changes in core files. Definition of this placeholder can be found in file /application/default/models/Invoice.php method render

    It is possible to define custom placeholder eg. %receipt% and format it as necessary based on invoice object.
    You can do it in site.php file (http://www.amember.com/docs/Site.php_file) so these changes will not be overwritten with upgrade in future.

    Please have a look how to define custom placeholder
    http://www.amember.com/docs/How_to_add_custom_placeholders_to_email_templates

    You need to know PHP in order to implement it.
  3. russell_stutely

    russell_stutely aMember Pro Customer

    Joined:
    Jul 25, 2007
    Messages:
    30
    I want to do exactly the same.. but do not understand one word of the answer or documentation.

    Would it not be real simple for amember just to tidy up the standard invoice / receipt layout in the next update?
  4. orish

    orish aMember Pro Customer

    Joined:
    Mar 15, 2011
    Messages:
    45
    Hello, me again! :)

    I've just updated to version 6 beta.

    The invoice.php core file that I modified to design a nice, friendly layout for %invoice_text% has disappeared.

    It's been a pain to continuously have to re-edit this file each time I updated amember, but at least it only took half an hour and I was up and running again.

    It would be useful to have this matter fixed once and for all. The standard layout for the payment receipt is really ugly and slapdash. It doesn't look professional at all.

    (I never understood Ceasar's reply about creating a custom placeholder, but I imagine that this is what needs to be done to resolve this problem. But I don't know how to go about it at all.)

    The design I created shows a nice table with the item(s) purchased, payment amounts and total. I send this to the customer whenever there is a sign-up (even for a free trial).

    Alex & co, if you haven't already implemented this as a feature for V6, please consider doing so in the next update. We should be able to design a template (and, no, I don't want to send a PDF invoice at this stage: just a receipt in the confirmation email itself).

    I'd be happy to buy a plugin that does this, with a selection of nice templates.

    In the meantime, does anyone have any suggestions how one can do this in V6 - either by modifying a core file (to avoid if possible) or by creating a custom design file somewhere?

    Thanks in advance,
    Gary

    Attached Files:

  5. orish

    orish aMember Pro Customer

    Joined:
    Mar 15, 2011
    Messages:
    45
    OK, I've revisited this issue and I'd like to follow Caesar's suggestion of creating the %receipt% custom placeholder in site.php. The instructions are very unclear, though. For instance, how does the code

    $tmpl->setPlaceholder("TEST");

    set the placeholder %placeholder% to TEST? What code do I use to create a placeholder called %receipt%? Do I use the code

    $tmpl->setReceipt (render(someparameter1, someparameter2));

    These are the changes I made to the function render() in Invoice.php. How do I call this function to assign the text string to %receipt%?

    I need very basic instructions, I'm afraid because I'm not a PHP/Zend developer, but I can tweak some existing code if I have a template to follow...

    ..............

    $out = $indent . "<b>Purchase Details</b>"."$newline"."$newline";
    $out .= '<table cellspacing="0" style="border:1px solid #000;border-collapse:collapse;">';
    $tdLeft = '<td style="border:1px solid #000;border-collapse:collapse;text-align:left;padding-left:10px;width:350px;">';
    $tfRight = '<td style="border:1px solid #000;border-collapse:collapse;text-align:right;padding-right:10px;width:150px;">';
    $num = 1;
    $tempCount = '';
    foreach ($this->getItems() as $item) {
    $tempCount = $tempCount + 1;
    }

    foreach ($this->getItems() as $item) {
    $title = explode("\n", $this->wordWrap($item->item_title, $column_title, "\n", true));
    $out .= '<tr>'.$tdLeft.$indent.' '.$title[0].'</td>'.$tfRight.number_format($item->{$prefix . '_price'}).'</td></tr>';
    for ($i=1; $i<count($title); $i++){
    if(!empty($title[$i])){
    $out .= '<tr>'.$tdLeft.$indent.' '.$title[$i].'</td>'.$tfRight.'</td></tr>';
    }
    }
    $num++;
    }
    if ($this->{$prefix . '_discount'} > 0){
    $out .= '<tr>'.$tdLeft.$indent.' '.'Shipping'.'</td>'.$tfRight.number_format($this->{$prefix . '_shipping'}).'</td></tr>';
    }
    if ($this->{$prefix . '_tax'} > 0){
    $out .= '<tr>'.$tdLeft.$indent.' '.'Tax'.'</td>'.$tfRight.number_format($this->{$prefix . '_tax'}).'</td></tr>';
    }

    $out .= '<tr>'.$tdLeft.$indent.' '.'<b>Total paid</b>'.'</td>'.$tfRight.'<b>'.$this->currency.' '.number_format($this->{$prefix . '_total'}).'</b></td></tr>';

    if ($this->rebill_times) {
    $terms = explode("\n", $this->wordWrap($this->getTerms(), $row_width, "\n", true));
    foreach ($terms as $term_part){
    $out .= '<tr>'.$tdLeft.$indent . $term_part.'</td>'.$tfRight.'</td></tr>';
    }
    }

    $out .= '</table>';
    return $out;
    }


    THANKS,
    Gary
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,993
    Gary, I suggest to use placeholder %invoice_html% and then modify template:
    application/default/views/mail/_invoice.phtml
    the way you need.

Share This Page