Support

Home Forums Event Espresso Premium Adding a VAT breakdown to reciepts

Adding a VAT breakdown to reciepts

Posted: March 16, 2017 at 8:36 am


deckchairuk

March 16, 2017 at 8:36 am

Hello đŸ™‚

Just doing a bit of an update on receipts for our client, and they’ve asked to have a VAT breakdown.

We currently just have a total cost without any taxation modifiers on ticket costs.

I’m wondering if there’s a way to get the total cost, find 20% of it, and display it as the VAT cost.

Thanks, Harry.


Josh

  • Support Staff

March 17, 2017 at 3:34 pm

Hi Harry,

The default receipt template actually shows the VAT breakdown. You’ll see an example in this default receipt.

You can add the following to your receipt template’s template editor:

1) to the [TAX_LINE_ITEM_LIST] section:

</td>
</tr>
<tr>
	<td>[LINE_ITEM_NAME]</td>
	<td>[LINE_ITEM_DESCRIPTION]</td>
	<td class="item_c">[LINE_ITEM_AMOUNT]</td>
	<td class="item_r">[LINE_ITEM_TOTAL]</td>
</tr>
<tr>
	<td colspan="4">

2) Then add the following to the Main Content section of the receipt template:

<div class="taxes">
  <h3 class="section-title">Taxes</h3>
  <p><strong>*</strong> Taxable items. The total amount collected for taxes is reflected in the total(s) below.</p>
  <table class="invoice-amount">
    <thead>
      <tr class="header_row">
        <th class="left ticket_th">Tax Name</th>
        <th class="left">Description</th>
        <th class="event_th item_c">Rate</th>
        <th class="subtotal_th">Tax Amount</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td colspan="4">[TAX_LINE_ITEM_LIST]</td>
      </tr>
    </tbody>
  </table>
</div>


deckchairuk

March 27, 2017 at 8:24 am

Hey Josh,

Thanks for your reply, I gave it a shot but it wasn’t quite working as I was hoping.

We’ve hade the site live for about 6 months now and all the events ticket prices have been added as just flat prices, with no tax modifiers.

I’m wondering if there’s any way of spoofing the VAT by just displaying 20% of the final price in the template, is that at all possible?

Thanks, Harry.


Josh

  • Support Staff

March 27, 2017 at 4:03 pm

Hi Harry,

In order to use the code above, you’d need to break the VAT amount out as tax in the ticket editor, and the breakdown would show up for new events/registrations going forward.

Since you’re publishing a price that doesn’t include taxes as separate line items, but want to show a separate line item that doesn’t really exist in the system, that’s going to require some custom PHP work for the Receipt template where you’d build out a new template pack for the Receipt template that has some PHP code that does the 20% calculation.


deckchairuk

March 28, 2017 at 4:42 am

Hi Josh,

Excellent, thanks for that link, it explains a lot more about how the messages are generated (previously I’d be editing them in WordPress which can get messy).

I’m happy to do the custom PHP work, but I don’t want to edit the EE core files in the thought of future updates. Are there any hooks/filters I can use to edit these via my functions folder?

Thanks for your help, Harry.


deckchairuk

March 28, 2017 at 4:50 am

I’ve been looking at the core files and just a thought; would I be able to add my own shortcode called something like [VAT_TOTAL], which would get 20% of the transaction amount and display it.

That way I can just use the shortcode in my current template and it would just display 20% of whatever the final cost is.

Thanks, Harry.


Tony

  • Support Staff

March 28, 2017 at 5:22 am

To add your own template pack you mean?

We have some info within the developer documentation on how you can add your own template pack.


deckchairuk

April 10, 2017 at 9:15 am

Hi Tony,

I was meaning instead of creating my own template, is there a way I can just add a new shortcode that could be used in the template builder?

Thanks, Harry.


Josh

  • Support Staff

April 10, 2017 at 4:41 pm

Hi Harry,

If you or someone on your team has a working knowledge of the WordPress plugin API, you can use the following filter hooks to add new shortcodes:

FHEE__EE_Shortcodes__shortcodes

FHEE__EE_Shortcodes__parser_after

The above hooks are in Event Espresso 4 core here:

https://github.com/eventespresso/event-espresso-core/blob/master/core/libraries/shortcodes/EE_Shortcodes.lib.php#L199

https://github.com/eventespresso/event-espresso-core/blob/master/core/libraries/shortcodes/EE_Shortcodes.lib.php#L215


Tony

  • Support Staff

April 11, 2017 at 3:32 am

I have previously posted an example of adding your own shortcodes to the messages system here that might also help point you in the right direction:

https://gist.github.com/Pebblo/e87cc8e30c4848dcdfe2


deckchairuk

April 18, 2017 at 5:00 am

Perfect! I will have a go at creating one.

Thank you both, you’ve been very helpful.

Harry.


Tony

  • Support Staff

April 18, 2017 at 5:53 am

You’re most welcome, Harry.

If you run into any problems please let us know (we can’t provide support for custom code but if we can help point you in the right direction we will).


deckchairuk

April 18, 2017 at 7:13 am

Thanks Tony.

I’ve managed to get something (https://gist.github.com/deckchairuk/3edc13ff8c0c0d852a4828045e432594), I have a couple of queries when you get some time.

First is, I want to be able to use the shortcode in the main section. Is removing the ‘instanceof’ if statements the correct method to do this? Or if there and instance for the main section I can use?

Secondly, how do I access the ‘total cost’ data (the total cost of everything they purchased).

Thanks, Harry.


Tony

  • Support Staff

April 18, 2017 at 7:35 am

First is, I want to be able to use the shortcode in the main section. Is removing the ‘instanceof’ if statements the correct method to do this? Or if there and instance for the main section I can use?

Removing them isn’t really the correct method no.

One of the reasons for the instanceof checks are there is to make sure you are adding the shortcodes within a section that will have the correct data. For example, if you add a ticket specific shortcode to a transaction shortcode the data you are passed into the parser won’t match. You can actually still get the data in that case, but the point is you want to add the shortcodes to libraries which have the correct data they need.

The main section has access to multiple different shortcode libraries so you you want to add your shortcode to one of the libraries it already has access to, as this is a transaction based shortcode I’d recommend EE_Transaction_Shortcodes.

Add an instance of check into both your functions so that the shortcode is only added and parsed to the EE_Transaction_Shortcodes library (what your doing now adds the shortcode to every library, which isn’t a good idea)

That leads me onto your next question:

Secondly, how do I access the ‘total cost’ data (the total cost of everything they purchased).

Take a look at how EE parsed the current EE_Transaction_Shortcodes within:

\core\libraries\shortcodes\EE_Transaction_Shortcodes.lib.php

Notice how it pulls (and checks for) the Transaction.

Then take a look at how [TOTAL_COST] pulls the value it needs.


deckchairuk

April 18, 2017 at 8:00 am

Perfect!

Thanks for the handholding through that, should be pretty confident in future edits.

Here’s my final function file – https://gist.github.com/deckchairuk/3edc13ff8c0c0d852a4828045e432594

Thanks, Harry.


Tony

  • Support Staff

April 18, 2017 at 8:08 am

I’d add another sanity check on line 15:

if( $transaction instanceof EE_Transaction) { ... }

Use that to confirm you actually have an EE_Transaction before attempting to use it otherwise you’ll get a fatal error if for some reason you don’t have an EE_Transaction.


deckchairuk

April 18, 2017 at 8:30 am

Ah okay. I’ve added that in now, thanks!.

It’s all working as expected on my local environment, but I just pushed it up and I’m getting this when trying to add it to the live site;

An error has occurred:
The following shortcodes were found in the “Main Content” field that ARE not valid: [VAT_TOTAL]
Valid shortcodes for this field are: etc…


Tony

  • Support Staff

April 18, 2017 at 8:38 am

Use the hamburger icon on the right of the content area to confirm if the shortcode has actually been added to EE, it doesn’t appear to be.

Click the icon and look at the available shortcodes, [VAT_TOTAL] should be there, if not your code isn’t running, or is running to late.

How are you adding the code?


deckchairuk

April 21, 2017 at 9:26 am

Sorry I didn’t respond, I got excited and carried away once I’d got it working!

It was a type on my behalf causing the issue, so all’s good now.

Thank you both for your help.


Tony

  • Support Staff

April 21, 2017 at 10:23 am

Great, I’m glad you got it working đŸ™‚

The support post ‘Adding a VAT breakdown to reciepts’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso