Support

Home Forums Event Espresso Premium Adding Company Name to Invoice

Adding Company Name to Invoice

Posted: March 13, 2014 at 9:58 am

Viewing 9 reply threads


Dan Rositano

March 13, 2014 at 9:58 am

I wanted to add the company name to my invoices using the link here: https://eventespresso.com/topic/invoice-edit-to-add-a-question-company-name/

I followed the instructions but no luck. I will add my code below. Can you tell me if I am missing anything or anything I can try to get it to work?

Thanks

————–

<?php

//Added by Imon
if (isset($_SESSION[‘espresso_session’][‘id’])) {
unset($_SESSION[‘espresso_session’][‘id’]);
}

define(‘FPDF_FONTPATH’, EVENT_ESPRESSO_PLUGINFULLPATH . ‘class/fpdf/font/’);
require_once EVENT_ESPRESSO_PLUGINFULLPATH . ‘class/fpdf/fpdf.php’;

require_once(dirname(__FILE__) . ‘/function.pdf.php’); //Added by Imon

global $espresso_premium;
if ($espresso_premium != true)
return;
global $wpdb, $org_options;

$invoice_payment_settings = get_option(‘event_espresso_invoice_payment_settings’);

//Added by Imon
$multi_reg = false;
$registration_id = espresso_return_reg_id();
$admin = isset($_REQUEST[‘admin’]) ? $_REQUEST[‘admin’] : false;
$registration_ids = array();
$c_sql = “select * from ” . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . ” where registration_id = ‘$registration_id’ “;
//echo $c_sql;
$check = $wpdb->get_row($c_sql);
if ($check !== NULL) {
$registration_id = $check->primary_registration_id;
$registration_ids = $wpdb->get_results(“select registration_id from ” . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . ” where primary_registration_id = ‘$registration_id’ “, ARRAY_A);
$multi_reg = true;
} else {
$registration_ids[] = array(“registration_id” => $registration_id);
}
$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_zip = $attendee->zip;
$attendee_email = $attendee->email;
$attendee_organization_name = $attendee->organization_name;
//$attendee_country = $attendee->country_id;
$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;
}

#$num_people = isset($num_people) && $num_people > 0 ? $num_people : espresso_count_attendees_for_registration($attendee_id);
#$event_meta = event_espresso_get_event_meta($event_id);
// $event_data[‘additional_attendee_reg_info’]
//if ($payment_status != ‘Completed’) {
// $payment_status = ‘Pending’;
// $txn_type = ‘INV’;
// $payment_date = date(‘Y-m-d-H:i:s’);

//Added by Imon
// if (count($registration_ids) > 0 && $admin == false) {
// foreach ($registration_ids as $reg_id) {
// $sql = “UPDATE ” . EVENTS_ATTENDEE_TABLE . ” SET payment_status = ‘” . $payment_status . “‘, txn_type = ‘” . $txn_type . “‘, payment_date ='” . $payment_date . “‘ WHERE registration_id ='” . $reg_id[‘registration_id’] . “‘ AND txn_type =” “;
// $wpdb->query($sql);
// }
// }
//}
//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 = ‘9’ “;
$q_sql .= ” ORDER BY eq.sequence asc “;
$wpdb->get_results($q_sql);

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

//Instanciation of inherited class
$pdf = new Espresso_PDF();
$pdf->AliasNbPages();
$pdf->SetAuthor(pdftext($org_options[‘organization’]));
if (isset($invoice_payment_settings[‘pdf_title’])) {
$pdf->SetTitle(pdftext($event_name . ‘ – ‘ . $invoice_payment_settings[‘pdf_title’]));
} else {
$pdf->SetTitle(pdftext($event_name));
}

//$pdf->SetAutoPageBreak(‘auto’);
$pdf->AddPage();
//Create the top right of invoice below header
$pdf->SetFont(‘Times’, ”, 12);
$pdf->Cell(180, 0, __(‘Date: ‘, ‘event_espresso’) . date(get_option(‘date_format’)), 0, 1, ‘R’); //Set invoice date
$pdf->Cell(180, 10, __(‘Primary Attendee ID: ‘, ‘event_espresso’) . $attendee_id, 0, 0, ‘R’); //Set Invoice number
$pdf->Ln(0);

//Set the top left of invoice below header
$pdf->SetFont(‘Times’, ‘BI’, 14);
if (isset($invoice_payment_settings[‘payable_to’])) {
$pdf->MultiCell(0, 10, pdftext($invoice_payment_settings[‘payable_to’]), 0, ‘L’); //Set payable to
} else {
$pdf->MultiCell(0, 10, pdftext(”), 0, ‘L’); //Set payable to
}
$pdf->SetFont(‘Times’, ”, 12);
if (isset($invoice_payment_settings[‘payment_address’])) {
$pdf->MultiCell(50, 5, pdftext($invoice_payment_settings[‘payment_address’]), 0, ‘L’); //Set address
} else {
$pdf->MultiCell(50, 5, pdftext(”), 0, ‘L’); //Set address
}
$pdf->Ln(5);

//Set the biiling information
$pdf->SetFont(‘Times’, ‘B’, 12);
$pdf->Cell(50, 5, __(‘Bill To: ‘, ‘event_espresso’), 0, 1, ‘L’); //Set biil 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_email, 0, 1, ‘L’); //Set attendee email
$pdf->Cell(50, 5, $organization_name, 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’) : ”;

$pdf->Ln(10);

//Added by Imon
$attendees = array();
$total_cost = 0.00;
$total_orig_cost = 0.00;
$total_amount_pd = 0.00;
foreach ($registration_ids as $reg_id) {
$sql = “select ea.registration_id, ed.event_name, ed.start_date, ed.event_identifier, ea.fname, ea.lname, ea.quantity, ea.orig_price, ea.final_price, ea.amount_pd from ” . EVENTS_ATTENDEE_TABLE . ” ea “;
//$sql .= ” inner join ” . EVENTS_ATTENDEE_COST_TABLE . ” eac on ea.id = eac.attendee_id “;
$sql .= ” inner join ” . EVENTS_DETAIL_TABLE . ” ed on ea.event_id = ed.id “;
$sql .= ” where ea.registration_id = ‘” . $reg_id[‘registration_id’] . “‘ order by ed.event_name “;

$tmp_attendees = $wpdb->get_results($sql, ARRAY_A);

foreach ($tmp_attendees as $tmp_attendee) {
$sub_total = $tmp_attendee[“final_price”] * $tmp_attendee[“quantity”];
$orig_total = $tmp_attendee[“orig_price”] * $tmp_attendee[“quantity”];
$attendees[] = $pdf->LoadData(array(
pdftext($tmp_attendee[“event_name”] . “[” . date(‘m-d-Y’, strtotime($tmp_attendee[‘start_date’])) . “]”) . ‘ >> ‘
. pdftext(html_entity_decode($tmp_attendee[“fname”], ENT_QUOTES, “UTF-8″) . ” ” . html_entity_decode($tmp_attendee[“lname”], ENT_QUOTES, “UTF-8”)) . ‘;’
. pdftext($tmp_attendee[“quantity”]) . ‘;’
. doubleval($tmp_attendee[“final_price”]) . ‘;’
. doubleval($sub_total)
)
);
$total_cost += $sub_total;
$total_orig_cost += $orig_total;
$total_amount_pd += $tmp_attendee[“amount_pd”];
$event_identifier = $tmp_attendee[“event_identifier”];
}
}
$header = array(__(‘Event & Attendee’, ‘event_espresso’), __(‘Quantity’, ‘event_espresso’), __(‘Per Unit’, ‘event_espresso’), __(‘Sub total’, ‘event_espresso’));
$w = array(100, 25, 30, 30);
$alling = array(‘L’, ‘L’, ‘C’, ‘C’, ‘C’);
$left = 100 + 25 + 30;
$right = 30;

$pdf->ImprovedTable($header, $attendees, $w, $alling);

$pdf->Ln();
//if ( $total_amount_pd != $total_cost ) {
$pdf->InvoiceTotals(__(‘Total:’, ‘event_espresso’), $total_cost, $left, $right);
$text = __(‘Amount Paid:’, ‘event_espresso’);
$pdf->InvoiceTotals($text, $total_amount_pd, $left, $right);
// $discount = $total_orig_cost – $total_cost;
// if ($discount > 0) {
// $text = __(‘Discount:’, ‘event_espresso’);
// } else {
// $text = __(‘Discount:’, ‘event_espresso’);
// $pdf->InvoiceTotals($text, $discount, $left, $right);
// }
//}
$total_owing = $total_cost – $total_amount_pd;
$text = __(“Total due:”, ‘event_espresso’);
$pdf->InvoiceTotals($text, $total_owing, $left, $right);
$pdf->Ln(10);

//Build the payment link and instructions
if (isset($invoice_payment_settings[‘pdf_instructions’])) {
$pdf->MultiCell(100, 5, pdftext($invoice_payment_settings[‘pdf_instructions’]), 0, ‘L’); //Set instructions
} else {
$pdf->MultiCell(100, 5, pdftext(”), 0, ‘L’); //Set instructions
}

//Create a payment link
$payment_link = home_url() . “/?page_id=” . $org_options[‘return_url’] . “&r_id=” . $registration_id;

$pdf->SetFont(‘Arial’, ‘BU’, 20);
$pdf->Cell(200, 20, ‘Pay Online’, 0, 1, ‘C’, 0, $payment_link); //Set payment link

$pdf->Output(‘Invoice_’ . $attendee_id . ‘_’ . $event_identifier . ‘.pdf’, ‘D’);
exit;


Tony

  • Support Staff

March 13, 2014 at 10:24 am

Hi Dan,

Rather than writing your own query, we have a shortcode you can use to pull in specific answers. So within the template you can use:

do_shortcode('[EE_ANSWER q="XX" a="'.$attendee_id.'"]');

Where XX is the ID of the specific question (in your case its appears to be 9?)

Place the answer into a variable and use that.

Does that help?


Dan Rositano

March 13, 2014 at 12:49 pm

Gave this a try but no luck. I replaced this code:

$pdf->Cell(50, 5, $organization_name, 0, 1, ‘L’); //Set attendee email

with the code you gave me and substituted the ID and when I viewed the invoice the Company name still did not come up.


Tony

  • Support Staff

March 14, 2014 at 8:37 am

Hi Dan,

You’ll need that code to actually output the $organisation_name within the PDF.

Where you can use the code I provided is in place of this:

$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 = ’9? “;
$q_sql .= ” ORDER BY eq.sequence asc “;
$wpdb->get_results($q_sql);
$organization_name = $wpdb->last_result[0]->answer;//question_id = ’9?

You can simply do:

$organization_name = do_shortcode('[EE_ANSWER q="XX" a="'.$attendee_id.'"]');

You’ll then need:

$pdf->Cell(50, 5, $organization_name, 0, 1, ‘L’);

To output that variable to within the PDF.

Where is it you are trying to output the company name?


Dan Rositano

March 14, 2014 at 2:00 pm

Tom,

I am trying to output the company name on the invoice one downloads when using the invoice payment option. Per your directions I made the changes but still not Company name. I am including the code for you to see what I did.

———–

<?php

//Added by Imon
if (isset($_SESSION[‘espresso_session’][‘id’])) {
unset($_SESSION[‘espresso_session’][‘id’]);
}

define(‘FPDF_FONTPATH’, EVENT_ESPRESSO_PLUGINFULLPATH . ‘class/fpdf/font/’);
require_once EVENT_ESPRESSO_PLUGINFULLPATH . ‘class/fpdf/fpdf.php’;

require_once(dirname(__FILE__) . ‘/function.pdf.php’); //Added by Imon

global $espresso_premium;
if ($espresso_premium != true)
return;
global $wpdb, $org_options;

$invoice_payment_settings = get_option(‘event_espresso_invoice_payment_settings’);

//Added by Imon
$multi_reg = false;
$registration_id = espresso_return_reg_id();
$admin = isset($_REQUEST[‘admin’]) ? $_REQUEST[‘admin’] : false;
$registration_ids = array();
$c_sql = “select * from ” . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . ” where registration_id = ‘$registration_id’ “;
//echo $c_sql;
$check = $wpdb->get_row($c_sql);
if ($check !== NULL) {
$registration_id = $check->primary_registration_id;
$registration_ids = $wpdb->get_results(“select registration_id from ” . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . ” where primary_registration_id = ‘$registration_id’ “, ARRAY_A);
$multi_reg = true;
} else {
$registration_ids[] = array(“registration_id” => $registration_id);
}
$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_zip = $attendee->zip;
$attendee_email = $attendee->email;
$attendee_organization_name = $attendee->organization_name;
//$attendee_country = $attendee->country_id;
$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;
}

#$num_people = isset($num_people) && $num_people > 0 ? $num_people : espresso_count_attendees_for_registration($attendee_id);
#$event_meta = event_espresso_get_event_meta($event_id);
// $event_data[‘additional_attendee_reg_info’]
//if ($payment_status != ‘Completed’) {
// $payment_status = ‘Pending’;
// $txn_type = ‘INV’;
// $payment_date = date(‘Y-m-d-H:i:s’);

//Added by Imon
// if (count($registration_ids) > 0 && $admin == false) {
// foreach ($registration_ids as $reg_id) {
// $sql = “UPDATE ” . EVENTS_ATTENDEE_TABLE . ” SET payment_status = ‘” . $payment_status . “‘, txn_type = ‘” . $txn_type . “‘, payment_date ='” . $payment_date . “‘ WHERE registration_id ='” . $reg_id[‘registration_id’] . “‘ AND txn_type =” “;
// $wpdb->query($sql);
// }
// }
//}
//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 = ‘9’ “;
$q_sql .= ” ORDER BY eq.sequence asc “;
$wpdb->get_results($q_sql);*/

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

$organization_name = do_shortcode(‘[EE_ANSWER q=”9″ a=”‘.$attendee_id.'”]’);

//Instanciation of inherited class
$pdf = new Espresso_PDF();
$pdf->AliasNbPages();
$pdf->SetAuthor(pdftext($org_options[‘organization’]));
if (isset($invoice_payment_settings[‘pdf_title’])) {
$pdf->SetTitle(pdftext($event_name . ‘ – ‘ . $invoice_payment_settings[‘pdf_title’]));
} else {
$pdf->SetTitle(pdftext($event_name));
}

//$pdf->SetAutoPageBreak(‘auto’);
$pdf->AddPage();
//Create the top right of invoice below header
$pdf->SetFont(‘Times’, ”, 12);
$pdf->Cell(180, 0, __(‘Date: ‘, ‘event_espresso’) . date(get_option(‘date_format’)), 0, 1, ‘R’); //Set invoice date
$pdf->Cell(180, 10, __(‘Primary Attendee ID: ‘, ‘event_espresso’) . $attendee_id, 0, 0, ‘R’); //Set Invoice number
$pdf->Ln(0);

//Set the top left of invoice below header
$pdf->SetFont(‘Times’, ‘BI’, 14);
if (isset($invoice_payment_settings[‘payable_to’])) {
$pdf->MultiCell(0, 10, pdftext($invoice_payment_settings[‘payable_to’]), 0, ‘L’); //Set payable to
} else {
$pdf->MultiCell(0, 10, pdftext(”), 0, ‘L’); //Set payable to
}
$pdf->SetFont(‘Times’, ”, 12);
if (isset($invoice_payment_settings[‘payment_address’])) {
$pdf->MultiCell(50, 5, pdftext($invoice_payment_settings[‘payment_address’]), 0, ‘L’); //Set address
} else {
$pdf->MultiCell(50, 5, pdftext(”), 0, ‘L’); //Set address
}
$pdf->Ln(5);

//Set the biiling information
$pdf->SetFont(‘Times’, ‘B’, 12);
$pdf->Cell(50, 5, __(‘Bill To: ‘, ‘event_espresso’), 0, 1, ‘L’); //Set biil 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_email, 0, 1, ‘L’); //Set attendee email
$pdf->Cell(50, 5, $organization_name, 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’) : ”;

$pdf->Ln(10);

//Added by Imon
$attendees = array();
$total_cost = 0.00;
$total_orig_cost = 0.00;
$total_amount_pd = 0.00;
foreach ($registration_ids as $reg_id) {
$sql = “select ea.registration_id, ed.event_name, ed.start_date, ed.event_identifier, ea.fname, ea.lname, ea.quantity, ea.orig_price, ea.final_price, ea.amount_pd from ” . EVENTS_ATTENDEE_TABLE . ” ea “;
//$sql .= ” inner join ” . EVENTS_ATTENDEE_COST_TABLE . ” eac on ea.id = eac.attendee_id “;
$sql .= ” inner join ” . EVENTS_DETAIL_TABLE . ” ed on ea.event_id = ed.id “;
$sql .= ” where ea.registration_id = ‘” . $reg_id[‘registration_id’] . “‘ order by ed.event_name “;

$tmp_attendees = $wpdb->get_results($sql, ARRAY_A);

foreach ($tmp_attendees as $tmp_attendee) {
$sub_total = $tmp_attendee[“final_price”] * $tmp_attendee[“quantity”];
$orig_total = $tmp_attendee[“orig_price”] * $tmp_attendee[“quantity”];
$attendees[] = $pdf->LoadData(array(
pdftext($tmp_attendee[“event_name”] . “[” . date(‘m-d-Y’, strtotime($tmp_attendee[‘start_date’])) . “]”) . ‘ >> ‘
. pdftext(html_entity_decode($tmp_attendee[“fname”], ENT_QUOTES, “UTF-8″) . ” ” . html_entity_decode($tmp_attendee[“lname”], ENT_QUOTES, “UTF-8”)) . ‘;’
. pdftext($tmp_attendee[“quantity”]) . ‘;’
. doubleval($tmp_attendee[“final_price”]) . ‘;’
. doubleval($sub_total)
)
);
$total_cost += $sub_total;
$total_orig_cost += $orig_total;
$total_amount_pd += $tmp_attendee[“amount_pd”];
$event_identifier = $tmp_attendee[“event_identifier”];
}
}
$header = array(__(‘Event & Attendee’, ‘event_espresso’), __(‘Quantity’, ‘event_espresso’), __(‘Per Unit’, ‘event_espresso’), __(‘Sub total’, ‘event_espresso’));
$w = array(100, 25, 30, 30);
$alling = array(‘L’, ‘L’, ‘C’, ‘C’, ‘C’);
$left = 100 + 25 + 30;
$right = 30;

$pdf->ImprovedTable($header, $attendees, $w, $alling);

$pdf->Ln();
//if ( $total_amount_pd != $total_cost ) {
$pdf->InvoiceTotals(__(‘Total:’, ‘event_espresso’), $total_cost, $left, $right);
$text = __(‘Amount Paid:’, ‘event_espresso’);
$pdf->InvoiceTotals($text, $total_amount_pd, $left, $right);
// $discount = $total_orig_cost – $total_cost;
// if ($discount > 0) {
// $text = __(‘Discount:’, ‘event_espresso’);
// } else {
// $text = __(‘Discount:’, ‘event_espresso’);
// $pdf->InvoiceTotals($text, $discount, $left, $right);
// }
//}
$total_owing = $total_cost – $total_amount_pd;
$text = __(“Total due:”, ‘event_espresso’);
$pdf->InvoiceTotals($text, $total_owing, $left, $right);
$pdf->Ln(10);

//Build the payment link and instructions
if (isset($invoice_payment_settings[‘pdf_instructions’])) {
$pdf->MultiCell(100, 5, pdftext($invoice_payment_settings[‘pdf_instructions’]), 0, ‘L’); //Set instructions
} else {
$pdf->MultiCell(100, 5, pdftext(”), 0, ‘L’); //Set instructions
}

//Create a payment link
$payment_link = home_url() . “/?page_id=” . $org_options[‘return_url’] . “&r_id=” . $registration_id;

$pdf->SetFont(‘Arial’, ‘BU’, 20);
$pdf->Cell(200, 20, ‘Pay Online’, 0, 1, ‘C’, 0, $payment_link); //Set payment link

$pdf->Output(‘Invoice_’ . $attendee_id . ‘_’ . $event_identifier . ‘.pdf’, ‘D’);
exit;


Tony

  • Support Staff

March 14, 2014 at 5:50 pm

Hi Dan,

Could you post your code to something like http://pastebin.com/ and then post the link here please?

The forum adjusts the code preventing me from testing it.


Dan Rositano

March 17, 2014 at 12:12 pm

Tony,

Try seeing if this works for you to review the code:

<pre class=”brush: html; gutter: true; first-line: 1; highlight: []; html-script: false”><?php

//Added by Imon
if (isset($_SESSION['espresso_session']['id'])) {
unset($_SESSION['espresso_session']['id']);
}

define('FPDF_FONTPATH', EVENT_ESPRESSO_PLUGINFULLPATH . 'class/fpdf/font/');
require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'class/fpdf/fpdf.php';

require_once(dirname(__FILE__) . '/function.pdf.php'); //Added by Imon

global $espresso_premium;
if ($espresso_premium != true)
return;
global $wpdb, $org_options;

$invoice_payment_settings = get_option('event_espresso_invoice_payment_settings');

//Added by Imon
$multi_reg = false;
$registration_id = espresso_return_reg_id();
$admin = isset($_REQUEST['admin']) ? $_REQUEST['admin'] : false;
$registration_ids = array();
$c_sql = "select * from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where registration_id = '$registration_id' ";
//echo $c_sql;
$check = $wpdb->get_row($c_sql);
if ($check !== NULL) {
$registration_id = $check->primary_registration_id;
$registration_ids = $wpdb->get_results("select registration_id from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where primary_registration_id = '$registration_id' ", ARRAY_A);
$multi_reg = true;
} else {
$registration_ids[] = array("registration_id" => $registration_id);
}
$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_zip = $attendee->zip;
$attendee_email = $attendee->email;
$attendee_organization_name = $attendee->organization_name;
//$attendee_country = $attendee->country_id;
$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;
}

#$num_people = isset($num_people) && $num_people > 0 ? $num_people : espresso_count_attendees_for_registration($attendee_id);
#$event_meta = event_espresso_get_event_meta($event_id);
// $event_data['additional_attendee_reg_info']
//if ($payment_status != 'Completed') {
// $payment_status = 'Pending';
// $txn_type = 'INV';
// $payment_date = date('Y-m-d-H:i:s');

//Added by Imon
// if (count($registration_ids) > 0 && $admin == false) {
// foreach ($registration_ids as $reg_id) {
// $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '" . $payment_status . "', txn_type = '" . $txn_type . "', payment_date ='" . $payment_date . "' WHERE registration_id ='" . $reg_id['registration_id'] . "' AND txn_type ='' ";
// $wpdb->query($sql);
// }
// }
//}
//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 = '9' ";
$q_sql .= " ORDER BY eq.sequence asc ";
$wpdb->get_results($q_sql);*/

$organization_name = $wpdb->last_result[0]->answer;//question_id = '9'

$organization_name = do_shortcode('[EE_ANSWER q="9" a="'.$attendee_id.'"]');

//Instanciation of inherited class
$pdf = new Espresso_PDF();
$pdf->AliasNbPages();
$pdf->SetAuthor(pdftext($org_options['organization']));
if (isset($invoice_payment_settings['pdf_title'])) {
$pdf->SetTitle(pdftext($event_name . ' – ' . $invoice_payment_settings['pdf_title']));
} else {
$pdf->SetTitle(pdftext($event_name));
}

//$pdf->SetAutoPageBreak('auto');
$pdf->AddPage();
//Create the top right of invoice below header
$pdf->SetFont('Times', '', 12);
$pdf->Cell(180, 0, __('Date: ', 'event_espresso') . date(get_option('date_format')), 0, 1, 'R'); //Set invoice date
$pdf->Cell(180, 10, __('Primary Attendee ID: ', 'event_espresso') . $attendee_id, 0, 0, 'R'); //Set Invoice number
$pdf->Ln(0);

//Set the top left of invoice below header
$pdf->SetFont('Times', 'BI', 14);
if (isset($invoice_payment_settings['payable_to'])) {
$pdf->MultiCell(0, 10, pdftext($invoice_payment_settings['payable_to']), 0, 'L'); //Set payable to
} else {
$pdf->MultiCell(0, 10, pdftext(''), 0, 'L'); //Set payable to
}
$pdf->SetFont('Times', '', 12);
if (isset($invoice_payment_settings['payment_address'])) {
$pdf->MultiCell(50, 5, pdftext($invoice_payment_settings['payment_address']), 0, 'L'); //Set address
} else {
$pdf->MultiCell(50, 5, pdftext(''), 0, 'L'); //Set address
}
$pdf->Ln(5);

//Set the biiling information
$pdf->SetFont('Times', 'B', 12);
$pdf->Cell(50, 5, __('Bill To: ', 'event_espresso'), 0, 1, 'L'); //Set biil 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_email, 0, 1, 'L'); //Set attendee email
$pdf->Cell(50, 5, $organization_name, 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') : '';

$pdf->Ln(10);

//Added by Imon
$attendees = array();
$total_cost = 0.00;
$total_orig_cost = 0.00;
$total_amount_pd = 0.00;
foreach ($registration_ids as $reg_id) {
$sql = "select ea.registration_id, ed.event_name, ed.start_date, ed.event_identifier, ea.fname, ea.lname, ea.quantity, ea.orig_price, ea.final_price, ea.amount_pd from " . EVENTS_ATTENDEE_TABLE . " ea ";
//$sql .= " inner join " . EVENTS_ATTENDEE_COST_TABLE . " eac on ea.id = eac.attendee_id ";
$sql .= " inner join " . EVENTS_DETAIL_TABLE . " ed on ea.event_id = ed.id ";
$sql .= " where ea.registration_id = '" . $reg_id['registration_id'] . "' order by ed.event_name ";

$tmp_attendees = $wpdb->get_results($sql, ARRAY_A);

foreach ($tmp_attendees as $tmp_attendee) {
$sub_total = $tmp_attendee["final_price"] * $tmp_attendee["quantity"];
$orig_total = $tmp_attendee["orig_price"] * $tmp_attendee["quantity"];
$attendees[] = $pdf->LoadData(array(
pdftext($tmp_attendee["event_name"] . "[" . date('m-d-Y', strtotime($tmp_attendee['start_date'])) . "]") . ' >> '
. pdftext(html_entity_decode($tmp_attendee["fname"], ENT_QUOTES, "UTF-8") . " " . html_entity_decode($tmp_attendee["lname"], ENT_QUOTES, "UTF-8")) . ';'
. pdftext($tmp_attendee["quantity"]) . ';'
. doubleval($tmp_attendee["final_price"]) . ';'
. doubleval($sub_total)
)
);
$total_cost += $sub_total;
$total_orig_cost += $orig_total;
$total_amount_pd += $tmp_attendee["amount_pd"];
$event_identifier = $tmp_attendee["event_identifier"];
}
}
$header = array(__('Event & Attendee', 'event_espresso'), __('Quantity', 'event_espresso'), __('Per Unit', 'event_espresso'), __('Sub total', 'event_espresso'));
$w = array(100, 25, 30, 30);
$alling = array('L', 'L', 'C', 'C', 'C');
$left = 100 + 25 + 30;
$right = 30;

$pdf->ImprovedTable($header, $attendees, $w, $alling);

$pdf->Ln();
//if ( $total_amount_pd != $total_cost ) {
$pdf->InvoiceTotals(__('Total:', 'event_espresso'), $total_cost, $left, $right);
$text = __('Amount Paid:', 'event_espresso');
$pdf->InvoiceTotals($text, $total_amount_pd, $left, $right);
// $discount = $total_orig_cost – $total_cost;
// if ($discount > 0) {
// $text = __('Discount:', 'event_espresso');
// } else {
// $text = __('Discount:', 'event_espresso');
// $pdf->InvoiceTotals($text, $discount, $left, $right);
// }
//}
$total_owing = $total_cost – $total_amount_pd;
$text = __("Total due:", 'event_espresso');
$pdf->InvoiceTotals($text, $total_owing, $left, $right);
$pdf->Ln(10);

//Build the payment link and instructions
if (isset($invoice_payment_settings['pdf_instructions'])) {
$pdf->MultiCell(100, 5, pdftext($invoice_payment_settings['pdf_instructions']), 0, 'L'); //Set instructions
} else {
$pdf->MultiCell(100, 5, pdftext(''), 0, 'L'); //Set instructions
}

//Create a payment link
$payment_link = home_url() . "/?page_id=" . $org_options['return_url'] . "&r_id=" . $registration_id;

$pdf->SetFont('Arial', 'BU', 20);
$pdf->Cell(200, 20, 'Pay Online', 0, 1, 'C', 0, $payment_link); //Set payment link

$pdf->Output('Invoice_' . $attendee_id . '_' . $event_identifier . '.pdf', 'D');
exit;


Dan Rositano

March 17, 2014 at 12:13 pm

Tony,

Here is my attempt with the pastebin link: http://pastebin.com/9bwhSpVQ


Tony

  • Support Staff

March 18, 2014 at 4:16 am

Hi Dan,

The code you provided works fine. However there is a couple of thing to note.

Remove or comment out line 98:

$organization_name = $wpdb->last_result[0]->answer;//question_id = '9'

It is not needed.

On my install the question with ID number 9 is ‘ZIP’, which is a system question and is therefor likely the same question ID on your install.

How are you gathering the attendee organisation name?

I’m assuming via a custom question, can you go to Event Espresso -> Questions. Then Click on your custom question from within the list. In the address bar at the top you will see question_id=XX on the end of the URL. http://take.ms/KdUwi

Use that question ID within your invoice template within the EE_ANSWER shortcode.

In my example the question ID was 20. So i use:

$organization_name = do_shortcode('[EE_ANSWER q="20" a="'.$attendee_id.'"]');

Be sure the attendee has already answered this question or it will not be displayed within the Invoice.

The EE_ANSWER shortcode pulls in the answer to whichever question ID you set in q=XX so if you create custom question you must input the custom question ID into that field.

Hope that helps.


Dan Rositano

March 18, 2014 at 7:34 am

There is a Company name field under the “personal information” section when you sign up to an event espresso event. I am assuming that I am pulling from that field. If it would help I can send a screen shot. Is there a way to attach a file?


Tony

  • Support Staff

March 18, 2014 at 8:05 am

For images you would need to host the image and then include the link here.

Can you find the Company Name question within Event Espresso -> Questions?

Viewing 9 reply threads

The support post ‘Adding Company Name to Invoice’ 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