Support

Home Forums Event Espresso Premium Invoice for GST

Invoice for GST

Posted: April 17, 2014 at 6:22 am


Ben

April 17, 2014 at 6:22 am

Hi Guys,

Wordpress 3.6
EE V3 – all add ons
New installation
https://www.greatbunyagathering.com.au/event-registration/?ee=2

I’ve gone through this – https://eventespresso.com/wiki/using-a-custom-invoice-template-to-support-vat/
To replace VAT for GST (Australia), but it currently calculates as a %, when I’ve defined the surcharge as a flat fee, so all the amounts are round correctly and now represent a GST 10% fee.
Do you already have a GST template for EE 3? How can I have the flat surcharge fee shown instead of % calculation?

Thanks.


Ben

April 18, 2014 at 4:50 am

Hi Guys,

Any update on this post please?

Thanks.


Ben

April 22, 2014 at 3:30 am

Hi Guys,
Any update on this post please?
Thanks.


Tony

  • Support Staff

April 22, 2014 at 6:20 am

Hi Ben,

That invoice template was intended to be a base in order for developers to work from, personally I would advise against using it if possible.

To alter that template to use a flat_rate rather than percentage would basically require a full re-write of the template as it is expected within multiple places.

The invoicing system used within EE4 has had many improvements over EE3, including the ability to list taxes such as these. See https://eventespresso.com/features/tax-administration/ for more details.


Ben

April 23, 2014 at 1:48 pm

Thanks for the reply Tony.


Ben

May 1, 2014 at 3:08 pm

Hi Josh,

I’ve already tried to apply the custom invoice template to support VAT/GST for a client that has started the thread – https://eventespresso.com/topic/gst/#post-94826

Following Tony mentioning above to advise against using it, after I couldn’t get it to work myself, is there a possibility that I can put it back in place, and ask you to get it working with a purchased support token?

Thanks
Ben


Ben

May 4, 2014 at 4:57 am

Hi Guys,

I’ve finally got the custom invoice template to how it needs to look like using the – https://eventespresso.com/wiki/using-a-custom-invoice-template-to-support-vat/

However, the calculation for the ticket cost + 10% GST tax isn’t correct at the moment. Can someone highlight what code needs to be corrected in the template below please?

<code>&lt;?php
/*Custom Log Function Include*/
// require(&#039;log.php&#039;);
/*End Custom Log Function Include*/
 
if (isset($_SESSION[&#039;espresso_session&#039;][&#039;id&#039;])) {
unset($_SESSION[&#039;espresso_session&#039;][&#039;id&#039;]);
}
define(&#039;FPDF_FONTPATH&#039;, EVENT_ESPRESSO_PLUGINFULLPATH . &#039;class/fpdf/font/&#039;);
require_once EVENT_ESPRESSO_PLUGINFULLPATH . &#039;class/fpdf/fpdf.php&#039;;
global $espresso_premium; if ($espresso_premium != true) return;
global $wpdb, $org_options, $dqty;
$invoice_payment_settings = get_option(&#039;event_espresso_invoice_payment_settings&#039;);
/*Initial query
* We are using your initial query to pull the &#039;attendee_session&#039; from the database. This will be used in the main query.
* It might be an idea to use the &#039;attendee_session&#039;in the generated invoice url as you could then eliminate this query alltogether.
* Ideally we would use a stored procedure to eliminate the need to lines 19-65
*/
//add a check to make sure it pulls the right registration id variable as admina nd front end differ.
if($_REQUEST[&#039;r_id&#039;] == &#039;&#039;) { $theregid = $_REQUEST[&#039;registration_id&#039;]; }
else { $theregid = $_REQUEST[&#039;r_id&#039;]; }
 
$xyz = $wpdb-&gt;get_results(&quot;SELECT attendee_session FROM &quot;. EVENTS_ATTENDEE_TABLE .&quot; WHERE registration_id =&#039;&quot; . $theregid . &quot;&#039; LIMIT 0,1&quot;);
 
$attendees = $wpdb-&gt;get_results(&quot;SELECT * FROM &quot;. EVENTS_ATTENDEE_TABLE .&quot; WHERE attendee_session =&#039;&quot; . $xyz[0]-&gt;attendee_session . &quot;&#039; &quot;);
 
foreach ($attendees as $attendee){
$attendee_id = $attendee-&gt;id;
$attendee_last = $attendee-&gt;lname;
$attendee_first = $attendee-&gt;fname;
$attendee_address = $attendee-&gt;address;
$attendee_address2 = $attendee-&gt;address2;
$attendee_city = $attendee-&gt;city;
$attendee_state = $attendee-&gt;state;
$attendee_zip = $attendee-&gt;zip;
$attendee_email = $attendee-&gt;email;
//$attendee_organization_name = $attendee-&gt;organization_name;
$attendee_country = $attendee-&gt;country_id;
$phone = $attendee-&gt;phone;
$date = $attendee-&gt;date;
//$num_people = $attendee-&gt;quantity;
$payment_status = $attendee-&gt;payment_status;
$txn_type = $attendee-&gt;txn_type;
$attendee_session = $attendee-&gt;attendee_session;
$event_price_type = $attendee-&gt;price_option;
$amount_pd = $attendee-&gt;amount_pd;
$payment_date = $attendee-&gt;payment_date;
$event_id = $attendee-&gt;event_id;
$registration_id=$attendee-&gt;registration_id;
$quantity = $attendee-&gt;quantity;
$final_cost = $attendee-&gt;final_price;
$orig_cost = $attendee-&gt;orig_price;
 
$discount_amt = $orig_cost - $final_cost;
}
 
 
 
/*
* Calculate the total cost for each event in the basket (without surcharge, in our case VAT)
* @param integer $event_cost
* @param integer $quantity //value calculated by the query
* @return double $total_cost
*/
function lh_calc_event_cost($event_cost, $quantity, $final_cost, $orig_cost){
/*
if($final_cost != $orig_cost) {
return doubleval($final_cost * $quantity);
}
else {
return doubleval($event_cost * $quantity);
}
*/
return doubleval($event_cost * $quantity);
}
/*
* Calculate the surcharge on an event (in our case VAT)
* @param integer $surcharge
* @param integer $quantity
* @param integer $event_cost
* @return integer $event_surcharge
*/
function lh_calc_event_tax($surcharge, $quantity, $event_cost){
$surcharge_rate = &#039;0.&#039; . $surcharge;
return ($event_cost * $surcharge_rate) * $quantity;
}
/*
* Query to pull all the information we need for our invoice from the database.
* $multi_events formatted as a numerically indexed array.
* Using $attendee_session we can evaluate all of the events in a single order using a single query.
* Structure of $multi_events:
* array (
* 0 =&gt;
* array (
* 0 =&gt; &lt;QUANTITY&gt;,
* 1 =&gt; &lt;EVENT NAME&gt;,
* 2 =&gt; &lt;EVENT DATE&gt;,
* 3 =&gt; &lt;EVENT COST&gt;,
* 4 =&gt; &lt;EVENT SURCHARGE&gt;,
* )
*/
$multi_events = $wpdb-&gt;get_results(&quot;SELECT COUNT(*), &quot; . EVENTS_DETAIL_TABLE . &quot;.event_name, &quot; . EVENTS_DETAIL_TABLE . &quot;.start_date, &quot; . EVENTS_PRICES_TABLE . &quot;.event_cost, &quot; . EVENTS_PRICES_TABLE . &quot;.surcharge
FROM &quot;. EVENTS_ATTENDEE_TABLE .&quot;
LEFT JOIN &quot; . EVENTS_DETAIL_TABLE . &quot; ON &quot; . EVENTS_ATTENDEE_TABLE . &quot;.event_id = &quot; . EVENTS_DETAIL_TABLE . &quot;.id
LEFT JOIN &quot; . EVENTS_PRICES_TABLE . &quot; ON &quot; . EVENTS_ATTENDEE_TABLE . &quot;.event_id = &quot; . EVENTS_PRICES_TABLE . &quot;.event_id
WHERE &quot; . EVENTS_ATTENDEE_TABLE . &quot;.attendee_session = &#039;&quot; . $attendee_session . &quot;&#039;
GROUP BY &quot; . EVENTS_DETAIL_TABLE . &quot;.event_name;&quot;, ARRAY_N );
//invoice_log::singleton()-&gt;log( array ( &#039;file&#039; =&gt; __FILE__, &#039;function&#039; =&gt; __FUNCTION__, &#039;status&#039; =&gt; &quot;sqldump = &quot; . var_export($multi_events, true) ) );
 
//Build the PDF
class PDF extends Espresso_FPDF
{
//Page header
function Header()
{
global $wpdb, $org_options;
$invoice_payment_settings = get_option(&#039;event_espresso_invoice_payment_settings&#039;);
//Logo
if (trim($invoice_payment_settings[&#039;image_url&#039;]) !=&#039;&#039;){
$this-&gt;Image($invoice_payment_settings[&#039;image_url&#039;],10,8,90,0);//Set the logo if it is available
}else{
$this-&gt;SetFont(&#039;Arial&#039;,&#039;B&#039;,15);
$this-&gt;Cell(10,10,iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$org_options[&#039;organization&#039;]),0,0,&#039;L&#039;);//If no logo, then display the organizatin name
}
//Arial bold 15
$this-&gt;SetFont(&#039;Arial&#039;,&#039;B&#039;,15);
//Move to the right
$this-&gt;Cell(80);
//Title
$this-&gt;MultiCell(100,20,iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$invoice_payment_settings[&#039;pdf_title&#039;]),0,&#039;R&#039;);//Set the right header
//Line break
$this-&gt;Ln(20);
}
function LoadData($file)
{
$lines=$file;
$data=array();
foreach($lines as $line)
$data[]=explode(&#039;;&#039;,chop($line));
return $data;
}
//Better table
function ImprovedTable($header,$event_data)
{
$options = get_option(&#039;events_organization_settings&#039;);
$currency = $options[&#039;currency_symbol&#039;];
//Column widths
/*
* Extra columns added to the table layout
*/
$w=array(115,15,25,35);
//Header
for($i=0;$i&lt;count($header);$i++)
$this-&gt;Cell($w[$i],7,$header[$i],1,0,&#039;C&#039;);
$this-&gt;Ln();
$x = $this-&gt;GetX();
$y = $this-&gt;GetY();
/*
* The only modification needed to the function in order to display the extra data is
* an extra foreach loop. We also modified the positioning of the cells to account for the
* extra information we are displaying
*/
foreach($event_data as $data){
//invoice_log::singleton()-&gt;log( array ( &#039;file&#039; =&gt; __FILE__, &#039;function&#039; =&gt; __FUNCTION__, &#039;status&#039; =&gt; &quot;sqldump = &quot; . var_export($event_data, true) ) );
foreach($data as $row)
{
 
$row[3] = $row[1] * $row[3];
 
//invoice_log::singleton()-&gt;log( array ( &#039;file&#039; =&gt; __FILE__, &#039;function&#039; =&gt; __FUNCTION__, &#039;status&#039; =&gt; &quot;sqldump = &quot; . var_export($row, true) ) );
$y1 = $this-&gt;GetY();
$this-&gt;MultiCell($w[0],6,$row[0],&#039;LBR&#039;);
$y2 = $this-&gt;GetY();
$yH = $y2 - $y1;
$this-&gt;SetXY($x + $w[0], $this-&gt;GetY() - $yH);
$this-&gt;Cell($w[1],$yH,$row[1],&#039;LBR&#039;,0,&#039;C&#039;);
$this-&gt;Cell($w[2],$yH,$row[2],&#039;LBR&#039;,0,&#039;C&#039;);
//$this-&gt;Cell($w[3],$yH,number_format($row[3],2, &#039;.&#039;, &#039;&#039;),&#039;LBR&#039;,0,&#039;C&#039;);
$this-&gt;Cell($w[3],$yH,html_entity_decode($currency, ENT_QUOTES, &#039;ISO-8859-15&#039;) . number_format($row[3],2,&#039;.&#039;,&#039;&#039;),&#039;LBR&#039;,0,&#039;C&#039;);
$this-&gt;Ln();
}
 
}
//Closure line
$this-&gt;Cell(array_sum($w),0,&#039;&#039;,&#039;T&#039;);
}
/*
* Function to display the totals that we have calculated. Mainly cosmetic.
* @param integer $sub_total (this is the total cost of the events without surcharge added)
* @param integer $vat (the total surcharge on the order)
*/
function InvoiceTotals($sub_total, $vat, $surcharge, $attendees){
$options = get_option(&#039;events_organization_settings&#039;);
$currency = $options[&#039;currency_symbol&#039;];
$this-&gt;SetFillColor(225,225,225);
$discount_amt = 0;
$single_cost = 0;
 
//pull the default ticket price
global $wpdb, $org_options;
foreach( $attendees as $atts ) {
$single_disc_amt = $atts-&gt;orig_price - $atts-&gt;final_price;
$discount_amt = $discount_amt + $single_disc_amt;
 
$SQL = &quot;SELECT event_cost FROM &quot; . EVENTS_PRICES_TABLE . &quot; WHERE event_id=%d AND price_type=%s ORDER BY id ASC LIMIT 1&quot;;
$single_cost = $wpdb-&gt;get_var( $wpdb-&gt;prepare( $SQL, absint( $atts-&gt;event_id ), $atts-&gt;price_option ));
 
$correct_price = $correct_price + $single_cost;
}
 
$sub_total = $sub_total - $discount_amt;
 
 
$total_cost = ($correct_price + $vat) - $discount_amt;
 
 
//Print sub total
//$this-&gt;Cell(155, 10, &#039;Subtotal excluding VAT:&#039;, 0, 0, &#039;R&#039;, true);
//$this-&gt;Cell(35, 10, html_entity_decode($currency, ENT_QUOTES, &#039;ISO-8859-15&#039;) . number_format($sub_total,2, &#039;.&#039;, &#039;&#039;), 0, 1, &#039;C&#039;, true);
//Print total VAT
$this-&gt;Cell(155, 10, &#039;GST @ 10&#039; . $surcharge . &#039;%:&#039;, 0, 0, &#039;R&#039;, true);
$this-&gt;Cell(35, 10, html_entity_decode($currency, ENT_QUOTES, &#039;ISO-8859-15&#039;) . number_format($vat,2, &#039;.&#039;, &#039;&#039;), 0, 1, &#039;C&#039;, true);
 
 
 
//$this-&gt;Cell(155, 10, &#039;Discount:&#039;, 0, 0, &#039;R&#039;, true);
//$this-&gt;Cell(35, 10, html_entity_decode($currency, ENT_QUOTES, &#039;ISO-8859-15&#039;) . number_format($discount_amt,2, &#039;.&#039;, &#039;&#039;), 0, 1, &#039;C&#039;, true);
 
//Print total cost
$this-&gt;Cell(155, 10, &#039;Total:&#039;, 0, 0, &#039;R&#039;);
$this-&gt;Cell(35, 10, html_entity_decode($currency, ENT_QUOTES, &#039;ISO-8859-15&#039;) . number_format($total_cost,2, &#039;.&#039;, &#039;&#039;), 0, 1, &#039;C&#039;);
$this-&gt;Ln(20);
//$this-&gt;Cell(190, 10, &#039;VAT registration number: XXX XXXX XX.&#039;, 0, 0, &#039;R&#039;); // replace with your VAT ID or comment this line out
}
//Page footer
function Footer()
{
//Position at 1.5 cm from bottom
$this-&gt;SetY(-15);
//Arial italic 8
$this-&gt;SetFont(&#039;Arial&#039;,&#039;&#039;,8);
//Page number
$this-&gt;Cell(0,10, __(&#039;Page&#039;,&#039;event_espresso&#039;).$this-&gt;PageNo().&#039;/{nb}&#039;,0,0,&#039;C&#039;);
}
}
//Create a payment link
$payment_link = home_url() . &quot;/?page_id=&quot; . $org_options[&#039;return_url&#039;] . &quot;&amp;id=&quot; . $attendee_id;
//Instanciation of inherited class
$pdf=new PDF();
$pdf-&gt;AliasNbPages();
$pdf-&gt;SetAuthor(iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$org_options[&#039;organization&#039;]));
$pdf-&gt;SetTitle(iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;, $attendee_id . $attendee_last . &#039; - &#039; . $invoice_payment_settings[&#039;pdf_title&#039;]));
//$pdf-&gt;SetAutoPageBreak(&#039;auto&#039;);
$pdf-&gt;AddPage();
//Create the top right of invoice below header
$pdf-&gt;SetFont(&#039;Helvetica&#039;,&#039;&#039;,12);
$pdf-&gt;Cell(180,0, __(&#039;Date: &#039;,&#039;event_espresso&#039;). date(&#039;d-m-Y&#039;),0,1, &#039;R&#039;);//Set invoice date
$pdf-&gt;Cell(180,10,__(&#039;Primary Attendee ID: &#039;,&#039;event_espresso&#039;). $attendee_id,0,0, &#039;R&#039;);//Set Invoice number
$pdf-&gt;Ln(0);
//Set the top left of invoice below header
$pdf-&gt;SetFont(&#039;Helvetica&#039;,&#039;B&#039;,12);
$pdf-&gt;MultiCell(0,5,iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$invoice_payment_settings[&#039;payable_to&#039;]),0,&#039;L&#039;);//Set payable to
$pdf-&gt;SetFont(&#039;Helvetica&#039;,&#039;&#039;,12);
$pdf-&gt;MultiCell(80,5,iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$invoice_payment_settings[&#039;payment_address&#039;]),0, &#039;L&#039;);//Set address
$pdf-&gt;Ln(5);
//Set the biiling information
$pdf-&gt;SetFont(&#039;Helvetica&#039;,&#039;B&#039;,12);
$pdf-&gt;Cell(50,5,__(&#039;Bill To: &#039;,&#039;event_espresso&#039;),0,1,&#039;L&#039;);//Set biil to
$pdf-&gt;SetFont(&#039;Helvetica&#039;,&#039;&#039;,12);
$pdf-&gt;Cell(50,5,iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$attendee_first . &#039; &#039; . $attendee_last),0,1, &#039;L&#039;);//Set attendee name
$pdf-&gt;Cell(50,5,$attendee_email,0,1,&#039;L&#039;);//Set attendee email
//Set attendee address
$attendee_address != &#039;&#039; ? $pdf-&gt;Cell(100,5,$attendee_address,0,1,&#039;L&#039;) :&#039;&#039;;
$attendee_address2 != &#039;&#039; ? $pdf-&gt;Cell(100,5,$attendee_address2,0,1,&#039;L&#039;) :&#039;&#039;;
$pdf-&gt;Cell(100,5,(iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$attendee_city != &#039;&#039; ? $attendee_city :&#039;&#039;). ($attendee_state != &#039;&#039; ? &#039; &#039; . $attendee_state :&#039;&#039;) . ($attendee_zip != &#039;&#039; ? &#039; &#039; . $attendee_zip : &#039;&#039;)), 0, 1, &#039;L&#039;);
$attendee_country != &#039;&#039; ? $pdf-&gt;Cell(50, 5, $attendee_country, 0, 1, &#039;L&#039;) : &#039;&#039;;
$pdf-&gt;Ln(10);
//Build the table for the event details
//Column titles
$header=array(__(&#039;Event Name&#039;,&#039;event_espresso&#039;),__(&#039;Qty.&#039;,&#039;event_espresso&#039;),__(&#039;Event Date&#039;,&#039;event_espresso&#039;),__(&#039;Price&#039;,&#039;event_espresso&#039;));
//Event Data
/*
* Here we have make multiple calls to the &#039;LoadData&#039; function in order to format the data we pulled from the database.
* As we are simply patching your code, this was the simplest solution.
*
*/
$tax_total = 0;
$cost_total = 0;
if($multi_events){
 
global $dqty;
 
$discount_amt = $attendees[0]-&gt;orig_price - $attendees[0]-&gt;final_price;
$discount_amt = $discount_amt * $dqty;
 
 
foreach($multi_events as $s_event){
$cost = lh_calc_event_cost($s_event[3], $s_event[0], $final_cost, $orig_cost );
$event_data[] = $pdf-&gt;LoadData (array(iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$s_event[1]) . &#039;;&#039; . iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;, $s_event[0]) . &#039;;&#039; . date(&#039;m-d-Y&#039;,strtotime($s_event[2])) . &#039;;&#039; . doubleval($s_event[3]) . &#039;;&#039; ) );
//$cost = lh_calc_event_cost($s_event[3], $quantity );
//$event_data[] = $pdf-&gt;LoadData (array(iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$s_event[1]) . &#039;;&#039; . $quantity . &#039;;&#039; . date(&#039;m-d-Y&#039;,strtotime($s_event[2])) . &#039;;&#039; . doubleval($s_event[3]) . &#039;;&#039; ) );
$tax_total += lh_calc_event_tax($s_event[4], $s_event[0], $s_event[3]);
//$tax_total += lh_calc_event_tax($s_event[4], $quantity, $s_event[3]);
//$surcharge = $s_event[4];
$cost_total += $cost;
}
$pdf-&gt;ImprovedTable($header, $event_data);
}
$pdf-&gt;Ln();
/*
* Using the totals calculated above, add in the totals section of the pdf.
*/
$pdf-&gt;InvoiceTotals($cost_total, $tax_total, $surcharge, $attendees);
$pdf-&gt;Ln(0);
//Build the payment link and instructions
$pdf-&gt;SetFont(&#039;Helvetica&#039;,&#039;BU&#039;,18);
$pdf-&gt;Cell(200,10,&#039;Pay Online&#039;,0,1,&#039;C&#039;,0,$payment_link);//Set payment link
$pdf-&gt;SetFont(&#039;Helvetica&#039;,&#039;B&#039;,12);
$pdf-&gt;MultiCell(185,5,iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1&quot;,$invoice_payment_settings[&#039;pdf_instructions&#039;]),0,&#039;L&#039;);//Set instructions
$pdf-&gt;Ln(6);
$pdf-&gt;Output($attendee_id . &#039;-&#039; . $attendee_last.&#039;.pdf&#039;,&#039;D&#039;);</code>


Ben

May 4, 2014 at 4:58 am

Also, How do I remove the ‘QTY’ ‘4’ column? what is it’s relevance?


Ben

May 5, 2014 at 8:08 am

Hi Dean/Josh,

Any ideas about this please?

Thanks.


Ben

May 5, 2014 at 3:40 pm

Hi Guys,

Any ideas about this please?

Thanks.


Lorenzo Orlando Caum

  • Support Staff

May 5, 2014 at 4:08 pm

Hi Ben,

Please complete this form and a team member will get back to you with some information:

https://eventespresso.com/contact/customization-request-form/


Lorenzo


Ben

May 5, 2014 at 4:22 pm

Thanks Lorenzo.

Customisation form has been completed and sent.

Thanks.


dave segal

May 9, 2014 at 4:26 am

I have been using event espresso for a few years now and still waiting to be able to use GST on my invoices. I note that ee4 may possibly do this but currently ee4 does not support any of the event espresso plugins which I just bought. I have the old event espresso (2) on my first site MHIST.com and the next version (3) on burtongarran50th.org and even after three years there is still no sight of having GST included in the invoicing system. Come on guys, event espresso is good. We have paid you money for it and I’m sure this is not a difficult thing to fix up.


Josh

  • Support Staff

May 13, 2014 at 8:02 am

Hi Dave,

Thanks for the feedback. We’re recommending anyone that needs GST in the invoice to update to Event Espresso 4 because it has the ability to line itemize price modifiers like GST. I invite you to fill out this survey to let us know which add-ons you need for Event Espresso 4:

https://eventespresso.com/ee4-add-ons-feature-requests/

The support post ‘Invoice for GST’ 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