Support

Home Forums Event Espresso Premium Bill to in the pdf invoice. Adding a new field not working

Bill to in the pdf invoice. Adding a new field not working

Posted: March 2, 2017 at 10:13 am

Viewing 17 reply threads


avstrati

March 2, 2017 at 10:13 am

Hello

I tried to follow the instructions from this post https://eventespresso.com/topic/invoice-edit-to-add-a-question-company-name/#post-58301 but it didn’t work for me.

The “Bill to” part in my pdf invoice currently gives:
First Name Last name
email
Street Address
City State
Zip Code

I would like to add the company name before the email, and the country at the bottom (and if possible the Street Adress 2).
My question ID for name of organization is 13, country is 24 and street address 2 is 5.

Here is what I have in my template invoice: (in wp-content/plugin/event-espresso.3.1.36.6.P/gateways/invoice/template

//Query Database for event and get variable
/* $events = $wpdb->get_results(“SELECT * FROM ” . EVENTS_DETAIL_TABLE . ” WHERE id='” . $event_id . “‘”);
foreach ($events as $event){
//$event_id = $event->id;
$event_name = html_entity_decode(stripslashes($event->event_name),ENT_QUOTES,”UTF-8″);
$event_desc = $event->event_desc;
$event_description = $event->event_desc;
$event_identifier = $event->event_identifier;
$start_date = $event->start_date;
} */
//This is an example of how to get custom questions for an attendee
//Get the questions for the attendee
$q_sql = “SELECT ea.answer, eq.question
FROM ” . EVENTS_ANSWER_TABLE . ” ea
LEFT JOIN ” . EVENTS_QUESTION_TABLE . ” eq ON eq.id = ea.question_id
WHERE ea.registration_id = ‘”.$registration_id.”‘”;
$q_sql .= ” AND ea.question_id = ’13’ “;
$q_sql .= ” ORDER BY eq.sequence asc “;
$wpdb->get_results($q_sql);

$organization_name = $wpdb->last_result[0]->answer;//question_id = ’13’

And a bit further:
//Set the billing information
$pdf->SetFont(‘Times’, ‘B’, 12);
$pdf->Cell(50, 5, __(‘Bill To: ‘, ‘event_espresso’), 0, 1, ‘L’); //Set bill to
$pdf->SetFont(‘Times’, ”, 12);
$pdf->Cell(50, 5, pdftext($attendee_first . ‘ ‘ . $attendee_last), 0, 1, ‘L’); //Set attendee name
$pdf->Cell(50, 5, $attendee_organization_name, 0, 1, ‘L’); //Set attendee organization name
$pdf->Cell(50, 5, $attendee_email, 0, 1, ‘L’); //Set attendee email
//Set attendee address
$attendee_address != ” ? $pdf->Cell(100, 5, $attendee_address, 0, 1, ‘L’) : ”;
$pdf->Cell(100, 5, (pdftext($attendee_city != ” ? $attendee_city : ”) . ($attendee_state != ” ? ‘ ‘ . $attendee_state : ”)), 0, 1, ‘L’);
$attendee_zip != ” ? $pdf->Cell(50, 5, $attendee_zip, 0, 1, ‘L’) : ”;
$attendee_country != ” ? $pdf->Cell(50, 5, $attendee_country, 0, 1, ‘L’) : ”;

$pdf->Ln(10);

I hope you can help! Thanks!


Josh

  • Support Staff

March 2, 2017 at 1:02 pm

Hi there,

I can see at least one mistake in your code that should be fixed. The line of code that his this:
$pdf->Cell(50, 5, $attendee_organization_name, 0, 1, 'L');

needs to be changed to:
$pdf->Cell(50, 5, $organization_name, 0, 1, 'L');


avstrati

March 2, 2017 at 1:10 pm

Thank you Josh!
I just made the change, but it doesn’t change the result.

I am adding another part of my code that I think might be part of the problem.

$attendees = $wpdb->get_results(“SELECT a.*, e.event_name FROM ” . EVENTS_ATTENDEE_TABLE . ” a JOIN ” . EVENTS_DETAIL_TABLE . ” e ON e.id=a.event_id WHERE a.registration_id ='” . $registration_id . “‘ order by a.id LIMIT 0,1 “);

foreach ($attendees as $attendee) {
$attendee_id = $attendee->id;
$attendee_last = html_entity_decode(stripslashes($attendee->lname), ENT_QUOTES, “UTF-8”);
$attendee_first = html_entity_decode(stripslashes($attendee->fname), ENT_QUOTES, “UTF-8”);
$attendee_address = html_entity_decode(stripslashes($attendee->address), ENT_QUOTES, “UTF-8”);
$attendee_address .= isset($attendee->address2) ? “\n” . html_entity_decode(stripslashes($attendee->address2), ENT_QUOTES, “UTF-8”);
$attendee_city = html_entity_decode(stripslashes($attendee->city), ENT_QUOTES, “UTF-8”);
$attendee_state = html_entity_decode(stripslashes($attendee->state), ENT_QUOTES, “UTF-8”);
$attendee_organization_name = html_entity_decode(stripslashes($attendee->organization_name), ENT_QUOTES, “UTF-8”);
$attendee_country = html_entity_decode(stripslashes($attendee->country_id), ENT_QUOTES, “UTF-8”);
$attendee_zip = $attendee->zip;
$attendee_email = $attendee->email;
$phone = $attendee->phone;
$date = $attendee->date;
$num_people = $attendee->quantity;
$payment_status = $attendee->payment_status;
$txn_type = $attendee->txn_type;
$amount_pd = $attendee->amount_pd;
$payment_date = $attendee->payment_date;
$event_id = $attendee->event_id;
$event_name = html_entity_decode(stripslashes($attendee->event_name), ENT_QUOTES, “UTF-8”);
//$attendee_session = $attendee->attendee_session;
//$registration_id=$attendee->registration_id;
}


Josh

  • Support Staff

March 2, 2017 at 1:20 pm

I’m afraid I’m having a difficult time reading your code since it’s not formatted as code. Can you post the entire contents of the code file you’re working with into a pastebin or github gist, then link here?


avstrati

March 2, 2017 at 1:26 pm

Yes, here it is: http://pastebin.com/fGSu5ZXB


Josh

  • Support Staff

March 2, 2017 at 1:49 pm

Is there a reason why you removed the calls to the pdftext() function in many places?


avstrati

March 2, 2017 at 1:52 pm

I did not create the code myself, I am not sure if there was a reason to do so in the first place. Should I add them back?


Josh

  • Support Staff

March 2, 2017 at 1:56 pm

Yes that may help. If you compare your modified file to the original you’ll see where the calls to pdftext() were removed:

https://github.com/eventespresso/event-espresso-legacy/blob/master/gateways/invoice/template.php#L134


avstrati

March 2, 2017 at 2:30 pm

Hello Josh,
I added the missing pdftext() so it should be clean now.

I made another try and the company name still doesn’t appear. Here is the code: http://pastebin.com/JEuEiP7n


Josh

  • Support Staff

March 2, 2017 at 4:29 pm

You’re missing a left bracket on line 190:
$pdf->InvoiceTotals(pdftext__('Total:', 'event_espresso')), $total_cost, $left, $right);

That should be fixed so it’s:
$pdf->InvoiceTotals(pdftext(__('Total:', 'event_espresso')), $total_cost, $left, $right);


Josh

  • Support Staff

March 2, 2017 at 4:40 pm

I tested the code in this copy of the file and it works on my test site:

https://gist.github.com/joshfeck/7efc568cf75a831d7909cf735de7aaa0


avstrati

March 3, 2017 at 7:58 am

Hello Josh, Thank you!
However My invoice is still the same, it only shows:
Bill to:
First Name Last name
email
Street Address
City State
Zip Code

Could it have anything to do with the way my questions are made?
Here is the event I am testing on my webpage: https://www.iap.aero/index.php/event-registration/?regevent_action=register&event_id=164

Thank you!


Josh

  • Support Staff

March 3, 2017 at 9:17 am

The way your questions are made should be fine. It’s more likely that your custom code isn’t actually loading. May I ask where are your custom invoice templates located on the server? i.e. which directory are they in?


avstrati

March 3, 2017 at 9:45 am

I think the problem is there,
I just found out I have been using the template invoice in this path:
/www/www.iap.aero/wp-content/plugins/event-espresso.3.1.36.6.P/gateways/invoice

But I found out I have another event espresso folder here:
/www/www.iap.aero/wp-content/plugins/event-espresso.3.1.21.P/gateways/invoice

I tried to change the new code in the new folder but now when I click on pdf invoice a blank page opens.


Josh

  • Support Staff

March 3, 2017 at 9:47 am

The blank page is a fatal error. You’ll need to make sure you have the newer version of Event Espresso 3 activated and you can find what’s causing the fatal error by turning on WP_DEBUG. You can also check the /wp-content/uploads/espresso/gateways directory and look for an invoice folder there.


avstrati

March 3, 2017 at 12:25 pm

I managed to get back so it wouldn’t get a fatal error; I noticed the code in the folder is slightly different (especially between 159-176) but I’ll leave it as is unless there is important mistakes.

I ended up with white space between the email and the address but the company name still doesn’t appear. I also tried to add the Attendee_country after the city and state but it doesn’t appear either.

http://pastebin.com/jYcTDrZx

I’ll keep trying to see if something can solve this; I would need the approval from the external developer to do change the version and he is not very available now so I would rather live it as is if I cannot find a solution with this version.


Josh

  • Support Staff

March 3, 2017 at 2:04 pm

You should try to get approval to update the site to have the current version of Event Espresso 3, which is currently 3.1.37.11. The version you have right now is missing more than a few security and WordPress compatibility fixes. Basically your version was compatible with the version of WordPress that was available in 2012, which was around WordPress 3.4.


avstrati

March 3, 2017 at 2:07 pm

I guess I’ll have to, thank you!

Viewing 17 reply threads

The support post ‘Bill to in the pdf invoice. Adding a new field not working’ 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