/** * @param EE_Line_Item $line_item * @param array $options * @return mixed */ public function display_line_item(EE_Line_Item $line_item, $options = array()) { EE_Registry::instance()->load_helper('Template'); EE_Registry::instance()->load_helper('HTML'); $html = ''; // set some default options and merge with incoming $default_options = array('show_desc' => TRUE, 'odd' => FALSE); $options = array_merge($default_options, (array) $options); switch ($line_item->type()) { case EEM_Line_Item::type_line_item: // item row $html .= $this->_item_row($line_item, $options); // got any kids? foreach ($line_item->children() as $child_line_item) { $this->display_line_item($child_line_item, $options); } break; case EEM_Line_Item::type_sub_line_item: $html .= $this->_sub_item_row($line_item, $options); break; case EEM_Line_Item::type_sub_total: break; case EEM_Line_Item::type_tax: $this->_tax_rate += $line_item->percent(); break; case EEM_Line_Item::type_tax_sub_total: foreach ($line_item->children() as $child_line_item) { if ($child_line_item->type() == EEM_Line_Item::type_tax) { // recursively feed children back into this method $this->display_line_item($child_line_item, $options); } } break; case EEM_Line_Item::type_total: // get all child line items $children = $line_item->children(); if ($options['set_tax_rate'] === true) { // loop thru tax child line items just to determine tax rate foreach ($children as $child_line_item) { if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) { // recursively feed children back into this method $this->display_line_item($child_line_item, $options); } } } else { // now loop thru all non-tax child line items foreach ($children as $child_line_item) { if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } } } break; } return $html; }
/** * This is used to output a single * @param EE_Line_Item $line_item * @param array $options * @return mixed */ public function display_line_item(EE_Line_Item $line_item, $options = array()) { EE_Registry::instance()->load_helper('Template'); EE_Registry::instance()->load_helper('HTML'); $html = ''; // set some default options and merge with incoming $default_options = array('odd' => true, 'use_table_wrapper' => true, 'table_css_class' => 'admin-primary-mbox-tbl', 'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr', 'total_tr_css_class' => 'admin-primary-mbox-total-tr'); $options = array_merge($default_options, (array) $options); switch ($line_item->type()) { case EEM_Line_Item::type_line_item: // item row $html .= $this->_item_row($line_item, $options); break; case EEM_Line_Item::type_sub_line_item: $html .= $this->_sub_item_row($line_item, $options); break; case EEM_Line_Item::type_sub_total: //loop through children $child_line_items = $line_item->children(); //loop through children foreach ($child_line_items as $child_line_item) { //recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } $html .= $this->_sub_total_row($line_item, $options); break; case EEM_Line_Item::type_tax: if ($this->_show_taxes) { $this->_taxes_html .= $this->_tax_row($line_item, $options); } break; case EEM_Line_Item::type_tax_sub_total: foreach ($line_item->children() as $child_line_item) { if ($child_line_item->type() == EEM_Line_Item::type_tax) { $this->display_line_item($child_line_item, $options); } } break; case EEM_Line_Item::type_total: // determine whether to display taxes or not $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false; // get all child line items $children = $line_item->children(); // loop thru all non-tax child line items foreach ($children as $child_line_item) { $html .= $this->display_line_item($child_line_item, $options); } $html .= $this->_taxes_html; $html .= $this->_total_row($line_item, $options); if ($options['use_table_wrapper']) { $html = $this->_table_header($options) . $html . $this->_table_footer($options); } break; } return $html; }
/** * @param EE_Line_Item $line_item * @param array $options * @return mixed */ public function display_line_item(EE_Line_Item $line_item, $options = array()) { EE_Registry::instance()->load_helper('HTML'); $html = ''; // set some default options and merge with incoming $default_options = array('show_desc' => TRUE, 'odd' => FALSE); $options = array_merge($default_options, (array) $options); switch ($line_item->type()) { case EEM_Line_Item::type_total: // loop thru children foreach ($line_item->children() as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } $html .= $this->_separator_row($options); $html .= $this->_total_row($line_item, __('Total', 'event_espresso'), $options); break; case EEM_Line_Item::type_sub_total: // loop thru children foreach ($line_item->children() as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } $html .= $this->_total_row($line_item, __('Sub-Total', 'event_espresso'), $options); break; case EEM_Line_Item::type_tax_sub_total: // loop thru children foreach ($line_item->children() as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } $html .= $this->_total_row($line_item, __('Tax Total', 'event_espresso'), $options); break; case EEM_Line_Item::type_line_item: // item row $html .= $this->_item_row($line_item, $options); // got any kids? foreach ($line_item->children() as $child_line_item) { $this->display_line_item($child_line_item, $options); } break; case EEM_Line_Item::type_sub_line_item: $html .= $this->_sub_item_row($line_item, $options); break; case EEM_Line_Item::type_tax: $html .= $this->_tax_row($line_item, $options); break; } return $html; }
/** * Recursive function for traversing all the sub-items of each line item * and displaying them in the table * @param EE_Line_Item $line_item * @param boolean $odd for indicating whether to style this line item as an 'odd' or 'even' */ function ee_invoice_display_line_item(EE_Line_Item $line_item, $show_line_item_description, $odd = false) { switch ($line_item->type()) { case EEM_Line_Item::type_total: foreach ($line_item->children() as $child_line_item) { ee_invoice_display_line_item($child_line_item, $show_line_item_description); } ?> <tr><td colspan="<?php echo $show_line_item_description ? 5 : 4; ?> "><hr></td></tr> <tr class="total_tr odd"> <td colspan="<?php echo $show_line_item_description ? 2 : 1; ?> "> </td> <td colspan="2" class="total" id="total_currency"><?php _e('Total', 'event_espresso'); ?> </td> <td class="total"><?php echo $line_item->total_no_code(); ?> </td> </tr> <?php break; case EEM_Line_Item::type_sub_total: foreach ($line_item->children() as $child_line_item) { //$odd = !$odd; ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd); } ?> <tr class="total_tr odd"> <td colspan="<?php echo $show_line_item_description ? 2 : 1; ?> "> </td> <td colspan="2" class="total" id="total_currency"><?php _e('Sub-Total', 'event_espresso'); ?> </td> <td class="total"><?php echo $line_item->total_no_code(); ?> </td> </tr> <?php break; case EEM_Line_Item::type_tax_sub_total: foreach ($line_item->children() as $child_line_item) { $odd = !$odd; ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd); } ?> <tr class="total_tr odd"> <td colspan="<?php echo $show_line_item_description ? 2 : 1; ?> "> </td> <td colspan="2" class="total" id="total_currency"><?php _e('Tax Total', 'event_espresso'); ?> </td> <td class="total"><?php echo $line_item->total_no_code(); ?> </td> </tr> <?php break; case EEM_Line_Item::type_line_item: $subitems = $line_item->children(); $has_subitems = count($subitems) > 1; if ($has_subitems) { ?> <tr class="item <?php echo $odd ? 'odd' : ''; ?> "> <td class="item_l"><?php echo $line_item->name(); ?> </td> <?php if ($show_line_item_description) { ?> <td class="item_l"><?php echo $line_item->desc(); ?> </td><?php } ?> <td class="item_l"><?php echo $line_item->quantity(); ?> </td> <td class="item_c"><?php echo $line_item->unit_price_no_code(); ?> </td> <td class="item_r"> <?php echo $line_item->total_no_code(); echo $line_item->is_taxable() ? '*' : ''; ?> </td> <?php //<td class="item_l"><?php $datetimes_strings = array(); foreach($datetimes as $datetime){ $datetimes_strings[]= $datetime->start_date_and_time();} echo implode(", ",$datetimes_strings); ?> </tr> <?php if ($has_subitems) { foreach ($line_item->children() as $child_line_item) { ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd); } } } else { //no subitems - just show this line item ?> <tr class="item <?php echo $odd ? 'odd' : ''; ?> "> <td class="item_l"><?php echo $line_item->name(); ?> </td> <?php if ($show_line_item_description) { ?> <td class="item_l"><?php echo $line_item->desc(); ?> </td><?php } ?> <td class="item_l"><?php echo $line_item->quantity(); ?> </td> <td class="item_c"><?php echo $line_item->unit_price_no_code(); ?> </td> <td class="item_r"> <?php echo $line_item->total_no_code(); echo $line_item->is_taxable() ? '*' : ''; ?> </td> <?php //<td class="item_l"><?php $datetimes_strings = array(); foreach($datetimes as $datetime){ $datetimes_strings[]= $datetime->start_date_and_time();} echo implode(", ",$datetimes_strings); ?> </tr> <?php } break; case EEM_Line_Item::type_sub_line_item: ?> <tr class="item subitem-row"> <td class="item_l subitem"><?php echo $line_item->name(); ?> </td> <?php if ($show_line_item_description) { ?> <td class="item_l"><?php echo $line_item->desc(); ?> </td><?php } ?> <?php if ($line_item->is_percent()) { ?> <td></td> <td class="item_c"><?php echo $line_item->percent(); ?> %</td> <?php } else { //flat discount/surcharge ?> <td></td> <td class="item_c"><?php echo $line_item->unit_price_no_code(); ?> </td> <?php } ?> <td class="item_r"><?php echo $line_item->total_no_code(); ?> </td> </tr> <?php break; case EEM_Line_Item::type_tax: ?> <tr class="item sub-item tax-total"> <td class="item_l"><?php echo $line_item->name(); ?> </td> <?php if ($show_line_item_description) { ?> <td class="item_l"><?php echo $line_item->desc(); ?> </td><?php } ?> <td colspan="2" class="item_c"><?php echo $line_item->percent(); ?> %</td> <td class="item_r"><?php echo $line_item->total_no_code(); ?> </td> </tr><?php break; } }
/** * @param EE_Line_Item $line_item * @param array $options * @return mixed */ public function display_line_item(EE_Line_Item $line_item, $options = array()) { EE_Registry::instance()->load_helper('Template'); EE_Registry::instance()->load_helper('HTML'); $html = ''; // set some default options and merge with incoming $default_options = array('show_desc' => true, 'odd' => false); $options = array_merge($default_options, (array) $options); switch ($line_item->type()) { case EEM_Line_Item::type_line_item: $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; if ($line_item->OBJ_type() == 'Ticket') { // item row $html .= $this->_ticket_row($line_item, $options); // got any kids? foreach ($line_item->children() as $child_line_item) { $this->display_line_item($child_line_item, $options); } } else { // item row $html .= $this->_item_row($line_item, $options); // got any kids? foreach ($line_item->children() as $child_line_item) { $this->display_line_item($child_line_item, $options); } } break; case EEM_Line_Item::type_sub_line_item: $html .= $this->_sub_item_row($line_item, $options); break; case EEM_Line_Item::type_sub_total: static $sub_total = 0; $event_sub_total = 0; $text = __('Sub-Total', 'event_espresso'); if ($line_item->OBJ_type() == 'Event') { $options['event_id'] = $event_id = $line_item->OBJ_ID(); if (!isset($this->_events[$options['event_id']])) { $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); if ($event instanceof EE_Event) { if ($event->default_registration_status() == EEM_Registration::status_id_not_approved) { return ''; } } $this->_events[$options['event_id']] = 0; $html .= $this->_event_row($line_item); $text = __('Event Sub-Total', 'event_espresso'); } } $child_line_items = $line_item->children(); // loop thru children foreach ($child_line_items as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; $sub_total += $event_sub_total; if ($line_item->code() != 'pre-tax-subtotal' && count($child_line_items) > 1 || $line_item->code() == 'pre-tax-subtotal' && count($this->_events) > 1) { $options['sub_total'] = $line_item->OBJ_type() == 'Event' ? $event_sub_total : $sub_total; $html .= $this->_sub_total_row($line_item, $text, $options); } break; case EEM_Line_Item::type_tax: if ($this->_show_taxes) { $this->_taxes_html .= $this->_tax_row($line_item, $options); } break; case EEM_Line_Item::type_tax_sub_total: if ($this->_show_taxes) { $child_line_items = $line_item->children(); // loop thru children foreach ($child_line_items as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } if (count($child_line_items) > 1) { $this->_taxes_html .= $this->_total_tax_row($line_item, __('Tax Total', 'event_espresso')); } } break; case EEM_Line_Item::type_total: // get all child line items $children = $line_item->children(); // loop thru all non-tax child line items foreach ($children as $child_line_item) { if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } } // now loop thru tax child line items foreach ($children as $child_line_item) { if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } } $html .= $this->_taxes_html; $html .= $this->_total_row($line_item, __('Total', 'event_espresso')); $html .= $this->_payments_and_amount_owing_rows($line_item, $options); break; } return $html; }
/** * @param EE_Line_Item $line_item * @param array $options * @return mixed */ public function display_line_item(EE_Line_Item $line_item, $options = array()) { EE_Registry::instance()->load_helper('HTML'); $html = ''; // set some default options and merge with incoming $default_options = array('show_desc' => TRUE, 'odd' => FALSE); $options = array_merge($default_options, (array) $options); switch ($line_item->type()) { case EEM_Line_Item::type_line_item: // item row if ($line_item->OBJ_type() == 'Ticket') { $html .= $this->_ticket_row($line_item); } else { $html .= $this->_item_row($line_item); } // got any kids? foreach ($line_item->children() as $child_line_item) { $this->display_line_item($child_line_item); } break; case EEM_Line_Item::type_sub_line_item: $html .= $this->_sub_item_row($line_item); break; case EEM_Line_Item::type_sub_total: $text = __('Sub-Total', 'event_espresso'); if ($line_item->OBJ_type() == 'Event') { if (!isset($this->_events[$line_item->OBJ_ID()])) { $html .= $this->_event_row($line_item); $text = __('Event Sub-Total', 'event_espresso'); } } $count = 0; // loop thru children foreach ($line_item->children() as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item); $count++; } // only display subtotal if there are multiple child line items $html .= $count > 1 ? $this->_sub_total_row($line_item, $text) : ''; break; case EEM_Line_Item::type_tax: if ($this->_show_taxes) { $html .= $this->_tax_row($line_item); } break; case EEM_Line_Item::type_tax_sub_total: if ($this->_show_taxes) { // loop thru children foreach ($line_item->children() as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item); } $html .= $this->_total_row($line_item, __('Tax Total', 'event_espresso'), true); } break; case EEM_Line_Item::type_total: if (count($line_item->get_items())) { // loop thru children foreach ($line_item->children() as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item); } } else { $html .= $this->_empty_msg_row(); } $html .= $this->_total_row($line_item, __('Total', 'event_espresso')); break; } return $html; }
/** * _total_row * * @param EE_Line_Item $line_item * @param string $text * @param int $total_items * @return mixed */ private function _total_row(EE_Line_Item $line_item, $text = '', $total_items = 0) { //EE_Registry::instance()->load_helper('Money'); // start of row $html = EEH_HTML::tr('', 'event-cart-total-row-' . $line_item->ID(), 'event-cart-total-row-' . $line_item->type() . ' event-cart-total-row total_tr'); // total td $html .= EEH_HTML::td(EEH_HTML::strong($text), '', 'total_currency total jst-rght', '', ' colspan="2"'); // total qty $total_items = $total_items ? $total_items : ''; $html .= EEH_HTML::td(EEH_HTML::strong('<span class="total">' . $total_items . '</span>'), '', 'total jst-cntr'); // total td $html .= EEH_HTML::td(EEH_HTML::strong($line_item->total_no_code()), '', 'total jst-rght'); // end of row $html .= EEH_HTML::trx(); return $html; }
/** * Creates a new, unsaved line item, but if it's a ticket line item * with a total of 0, or a subtotal of 0, returns null instead * @param EE_Line_Item $line_item * @return EE_Line_Item */ public static function non_empty_line_item(EE_Line_Item $line_item) { if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket' && $line_item->quantity() == 0) { return null; } $new_li_fields = $line_item->model_field_array(); //don't set the total. We'll leave that up to the code that calculates it unset($new_li_fields['LIN_ID']); unset($new_li_fields['LIN_parent']); return EE_Line_Item::new_instance($new_li_fields); }
/** * @param EE_Line_Item $line_item * @param array $options * @return mixed */ public function display_line_item(EE_Line_Item $line_item, $options = array()) { EE_Registry::instance()->load_helper('Template'); EE_Registry::instance()->load_helper('HTML'); $html = ''; // set some default options and merge with incoming $default_options = array('show_desc' => TRUE, 'odd' => FALSE); $options = array_merge($default_options, (array) $options); if (isset($options['registrations'])) { $this->_process_billable_registrations($options['registrations']); } switch ($line_item->type()) { case EEM_Line_Item::type_line_item: $options['billable_qty'] = $this->_is_billable($line_item); if ($options['billable_qty']) { // item row $html .= $this->_item_row($line_item, $options); // got any kids? foreach ($line_item->children() as $child_line_item) { $this->display_line_item($child_line_item, $options); } } break; case EEM_Line_Item::type_sub_line_item: $html .= $this->_sub_item_row($line_item, $options); break; case EEM_Line_Item::type_sub_total: static $sub_total = 0; $sub_total += $line_item->total(); $child_line_items = $line_item->children(); // loop thru children foreach ($child_line_items as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } //EEH_Debug_Tools::printr( $line_item->total(), '$line_item->total()', __FILE__, __LINE__ ); //EEH_Debug_Tools::printr( $sub_total, '$sub_total', __FILE__, __LINE__ ); if ($line_item->total() != $sub_total && count($child_line_items) > 1) { $html .= $this->_sub_total_row($line_item, __('Sub-Total', 'event_espresso'), $options); } break; case EEM_Line_Item::type_tax: if ($this->_show_taxes) { $this->_taxes_html .= $this->_tax_row($line_item, $options); } break; case EEM_Line_Item::type_tax_sub_total: if ($this->_show_taxes) { $child_line_items = $line_item->children(); // loop thru children foreach ($child_line_items as $child_line_item) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } $this->_total_tax = $line_item->total() * $this->_tax_rate(); if (count($child_line_items) > 1) { $this->_taxes_html .= $this->_total_tax_row($line_item, __('Tax Total', 'event_espresso'), $options); } } break; case EEM_Line_Item::type_total: // determine whether to display taxes or not $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false; // get all child line items $children = $line_item->children(); // loop thru all non-tax child line items foreach ($children as $child_line_item) { if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } } // now loop thru tax child line items foreach ($children as $child_line_item) { if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) { // recursively feed children back into this method $html .= $this->display_line_item($child_line_item, $options); } } $html .= $this->_taxes_html; $html .= $this->_total_row($line_item, __('Total', 'event_espresso'), $options); //$html .= $this->_payments_and_amount_owing_rows( $line_item ); //echo '<br/><br/><h5 style="color:#2EA2CC;">$this->_billable_total : <span style="color:#E76700">' . $this->_billable_total . '</span><br/><span style="font-size:9px;font-weight:normal;color:#666">' . __FILE__ . '</span> <b style="font-size:10px;color:#333"> ' . __LINE__ . ' </b></h5>'; //echo '<h5 style="color:#2EA2CC;">$this->_non_billable_total : <span style="color:#E76700">' . $this->_non_billable_total . '</span><br/><span style="font-size:9px;font-weight:normal;color:#666">' . __FILE__ . '</span> <b style="font-size:10px;color:#333"> ' . __LINE__ . ' </b></h5>'; //echo '<h5 style="color:#2EA2CC;">$this->_billable_tax_total : <span style="color:#E76700">' . $this->_billable_tax_total . '</span><br/><span style="font-size:9px;font-weight:normal;color:#666">' . __FILE__ . '</span> <b style="font-size:10px;color:#333"> ' . __LINE__ . ' </b></h5>'; //echo '<h5 style="color:#2EA2CC;">$this->_non_billable_tax_total : <span style="color:#E76700">' . $this->_non_billable_tax_total . '</span><br/><span style="font-size:9px;font-weight:normal;color:#666">' . __FILE__ . '</span> <b style="font-size:10px;color:#333"> ' . __LINE__ . ' </b></h5>'; //echo '<h5 style="color:#2EA2CC;">$this->_total_items : <span style="color:#E76700">' . $this->_total_items . '</span><br/><span style="font-size:9px;font-weight:normal;color:#666">' . __FILE__ . '</span> <b style="font-size:10px;color:#333"> ' . __LINE__ . ' </b></h5>'; break; } return $html; }
/** * Prints out a representation of the line item tree * @param EE_Line_Item $line_item * @param int $indentation * @return void */ public static function visualize(EE_Line_Item $line_item, $indentation = 0) { echo "\r\n"; for ($i = 0; $i < $indentation; $i++) { echo "-"; } echo $line_item->name() . ": " . $line_item->type() . " \$" . $line_item->total(); if ($line_item->is_taxable()) { echo " taxable"; } if ($line_item->children()) { foreach ($line_item->children() as $child) { self::visualize($child, $indentation + 1); } } }