/**
 * 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;
            ?>
">&nbsp;</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;
            ?>
">&nbsp;</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;
            ?>
">&nbsp;</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;
    }
}
 /**
  *    _adjust_line_item_quantity
  *
  * @access    protected
  * @param EE_Line_Item $line_item
  * @param int $quantity
  * @param string $action
  * @return EE_Line_Item|null
  */
 protected function adjust_line_item_quantity($line_item, $quantity = 1, $action = 'add')
 {
     if ($line_item instanceof EE_Line_Item) {
         //EEH_Debug_Tools::printr( $line_item->code(), '$line_item->code()', __FILE__, __LINE__ );
         //EEH_Debug_Tools::printr( $line_item->type(), '$line_item->type()', __FILE__, __LINE__ );
         //EEH_Debug_Tools::printr( $line_item->OBJ_type(), '$line_item->OBJ_type()', __FILE__, __LINE__ );
         //EEH_Debug_Tools::printr( $line_item->OBJ_ID(), '$line_item->OBJ_ID()', __FILE__, __LINE__ );
         //EEH_Debug_Tools::printr( $quantity, '$quantity', __FILE__, __LINE__ );
         //EEH_Debug_Tools::printr( $action, '$action', __FILE__, __LINE__ );
         $quantity = (int) $quantity;
         if ($quantity === 0 && $action == 'update') {
             $_REQUEST['ticket'] = $line_item->OBJ_ID();
             $_REQUEST['line_item'] = $line_item->code();
             $this->delete_ticket(false);
             return $line_item;
         } else {
             if ($quantity > 0) {
                 $additional = 'An additional';
                 $added_or_removed = 'added';
             } else {
                 $additional = 'A ';
                 $added_or_removed = 'removed';
             }
         }
         $quantity = $action == 'update' ? $quantity : $line_item->quantity() + $quantity;
         // update quantity
         $line_item->set_quantity($quantity);
         //it's "proper" to update the sub-line items quantities too, but core can actually fix it if we don't anyways
         if (method_exists('EEH_Line_Item', 'update_quantity')) {
             EEH_Line_Item::update_quantity($line_item, $quantity);
         } else {
             $line_item->set_quantity($quantity);
         }
         //EEH_Debug_Tools::printr( $line_item, '$line_item', __FILE__, __LINE__ );
         $saved = $line_item->ID() ? $line_item->save() : $line_item->quantity() == $quantity;
         if ($saved) {
             if ($action != 'update') {
                 $msg = sprintf(__('%1$s item was successfully %2$s for this event.', 'event_espresso'), $additional, $added_or_removed);
             } else {
                 $msg = __('The quantities were successfully updated for this event.', 'event_espresso');
             }
             // something got added
             if (apply_filters('FHEE__EED_Multi_Event_Registration__display_success_messages', false)) {
                 EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
             }
         } else {
             if ($line_item->quantity() != $quantity) {
                 // nothing added
                 EE_Error::add_error(sprintf(__('%1$s item was not %2$s for this event. Please refresh the page and try it again.', 'event_espresso'), $additional, $added_or_removed), __FILE__, __FUNCTION__, __LINE__);
                 return null;
             }
         }
     }
     return $line_item;
 }
 /**
  * 	_total_row
  *
  * @param EE_Line_Item $line_item
  * @param array        $options
  * @return mixed
  */
 private function _item_row(EE_Line_Item $line_item, $options = array())
 {
     // start of row
     $row_class = $options['odd'] ? 'item odd' : 'item';
     $html = EEH_HTML::tr('', $row_class);
     // name td
     $html .= EEH_HTML::td($line_item->name(), '', 'item_l');
     // desc td
     $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
     // quantity td
     $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l');
     // price td
     $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
     // total td
     $total = $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
     $html .= EEH_HTML::td($total, '', 'item_r');
     // end of row
     $html .= EEH_HTML::trx();
     return $html;
 }
 /**
  *    _item_row
  *
  * @param EE_Line_Item $line_item
  * @return mixed
  */
 private function _item_row(EE_Line_Item $line_item)
 {
     // start of row
     $html = EEH_HTML::tr('', 'event-cart-item-row-' . $line_item->code());
     $name_and_desc = $line_item->name();
     $name_and_desc .= $line_item->desc() != '' ? '<span class="line-item-desc-spn smaller-text"> : ' . $line_item->desc() . '</span>' : '';
     $name_and_desc = $line_item->is_taxable() ? $name_and_desc . ' * ' : $name_and_desc;
     // name td
     $html .= EEH_HTML::td($name_and_desc);
     // amount
     if ($line_item->percent()) {
         // percent td
         $html .= EEH_HTML::td($line_item->percent() . ' %', '', 'jst-rght');
     } else {
         // price td
         $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
     }
     // quantity td
     $html .= EEH_HTML::td($line_item->quantity(), '', 'mini-cart-tbl-qty-td jst-cntr');
     // total td
     $total = $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
     $this->_show_taxes = $line_item->is_taxable() ? TRUE : $this->_show_taxes;
     $html .= EEH_HTML::td($total, '', 'jst-rght');
     // end of row
     $html .= EEH_HTML::trx();
     return $html;
 }
 /**
  *    _item_row
  *
  * @param EE_Line_Item $line_item
  * @param array        $options
  * @return mixed
  */
 private function _item_row(EE_Line_Item $line_item, $options = array())
 {
     // start of row
     $html = EEH_HTML::tr('', 'event-cart-item-row-' . $line_item->ID(), 'event-cart-item-row item');
     // name && desc
     $name_and_desc = $line_item->name();
     $name_and_desc .= $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text"> : ' . $line_item->desc() . '</span>' : '';
     $name_and_desc = $line_item->is_taxable() ? $name_and_desc . ' * ' : $name_and_desc;
     // name td
     $html .= EEH_HTML::td($name_and_desc);
     // amount
     if ($line_item->percent()) {
         // percent td
         $html .= EEH_HTML::td($line_item->percent() . ' %', '', 'jst-rght');
     } else {
         // price td
         $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
     }
     // quantity td
     $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-cntr');
     // total td
     $html .= EEH_HTML::td($line_item->total_no_code(), '', '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);
 }
 /**
  *    _item_row
  *
  * @param EE_Line_Item $line_item
  * @return mixed
  */
 private function _item_row(EE_Line_Item $line_item)
 {
     // start of row
     $content = $line_item->name();
     if ($line_item->percent()) {
         $content .= ' ' . $line_item->percent() . ' %';
     } else {
         $content .= ' ' . $line_item->unit_price_no_code();
     }
     $content .= ' ' . $line_item->quantity() . ' = ';
     $content .= $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
     // track taxes
     $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
     return EEH_HTML::li($content, 'event-cart-item-list-' . $line_item->code());
 }
 /**
  *    _item_row
  *
  * @param EE_Line_Item $line_item
  * @param array        $options
  * @return mixed
  */
 protected function _item_row(EE_Line_Item $line_item, $options = array())
 {
     $line_item_related_object = $line_item->get_object();
     $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null;
     // start of row
     $row_class = $options['odd'] ? 'item odd' : 'item';
     $html = EEH_HTML::tr('', '', $row_class);
     //Name Column
     $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : '';
     //related object scope.
     $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : '';
     $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name;
     $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : '';
     $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name();
     $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html;
     $name_html .= $line_item->is_taxable() ? ' *' : '';
     //maybe preface with icon?
     $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html;
     $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
     $name_html .= sprintf(_x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'), '<span class="ee-line-item-related-parent-object">', $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type() : __('Item:', 'event_espresso'), $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name, '</span>');
     $html .= EEH_HTML::td($name_html, '', 'jst-left');
     //Type Column
     $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type() . '<br />' : '';
     $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
     $type_html .= !empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
     $html .= EEH_HTML::td($type_html, '', 'jst-left');
     //Amount Column
     if ($line_item->is_percent()) {
         $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
     } else {
         $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
     }
     //QTY column
     $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght');
     //total column
     $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
     //finish things off and return
     $html .= EEH_HTML::trx();
     return $html;
 }