protected function _get_tax_rows($tktrow, $ticket)
 {
     $tax_rows = '';
     $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php';
     $template_args = array();
     $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
     foreach ($taxes as $tax) {
         $tax_added = $this->_get_tax_added($tax, $ticket);
         $template_args = array('display_tax' => !empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"', 'tax_id' => $tax->ID(), 'tkt_row' => $tktrow, 'tax_label' => $tax->get('PRC_name'), 'tax_added' => $tax_added, 'tax_added_display' => EEH_Template::format_currency($tax_added, FALSE, FALSE), 'tax_amount' => $tax->get('PRC_amount'));
         $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', $template_args, $tktrow, $ticket, $this->_is_creating_event);
         $tax_rows .= EEH_Template::display_template($template, $template_args, TRUE);
     }
     return $tax_rows;
 }
예제 #2
0
 /**
  * get all default prices that are a Tax price type (PRT_ID = 4) and return
  * @return EE_Price[] EE_Price objects that have PRT_ID == 4
  */
 public static function get_taxes_for_admin()
 {
     self::$_default_taxes = !empty(self::$_default_taxes) ? self::$_default_taxes : EE_Registry::instance()->load_model('Price')->get_all(array(array('Price_Type.PBT_ID' => 4)));
     return self::$_default_taxes;
 }
 /**
  * Returns the total taxes applied to this ticket
  * @return float
  */
 public function get_ticket_taxes_total_for_admin()
 {
     return EE_Taxes::get_total_taxes_for_admin($this);
 }
 /**
  * Calculates the registration's final price, taking into account that they
  * need to not only help pay for their OWN ticket, but also any transaction-wide surcharges and taxes,
  * and receive a portion of any transaction-wide discounts.
  * eg1, if I buy a $1 ticket and brent buys a $9 ticket, and we receive a $5 discount
  * then I'll get 1/10 of that $5 discount, which is $0.50, and brent will get
  * 9/10ths of that $5 discount, which is $4.50. So my final price should be $0.50
  * and brent's final price should be $5.50.
  *
  * In order to do this, we basically need to traverse the line item tree calculating
  * the running totals (just as if we were recalculating the total), but when we identify
  * regular line items, we need to keep track of their share of the grand total.
  * Also, we need to keep track of the TAXABLE total for each ticket purchase, so
  * we can know how to apply taxes to it. (Note: "taxable total" does not equal the "pretax total"
  * when there are non-taxable items; otherwise they would be the same)
  *
  * @param EE_Line_Item $line_item
  * @param array $billable_ticket_quantities 		array of EE_Ticket IDs and their corresponding quantity that
  *                                          									can be included in price calculations at this moment
  * @return array 		keys are line items for tickets IDs and values are their share of the running total,
  *                                          plus the key 'total', and 'taxable' which also has keys of all the ticket IDs. Eg
  *                                          array(
  *                                          12 => 4.3
  *                                          23 => 8.0
  *                                          'total' => 16.6,
  *                                          'taxable' => array(
  *                                          12 => 10,
  *                                          23 => 4
  *                                          ).
  *                                          So to find which registrations have which final price, we need to find which line item
  *                                          is theirs, which can be done with
  *                                          `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );`
  */
 public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array())
 {
     //init running grand total if not already
     if (!isset($running_totals['total'])) {
         $running_totals['total'] = 0;
     }
     if (!isset($running_totals['taxable'])) {
         $running_totals['taxable'] = array('total' => 0);
     }
     foreach ($line_item->children() as $child_line_item) {
         switch ($child_line_item->type()) {
             case EEM_Line_Item::type_sub_total:
                 $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities);
                 //combine arrays but preserve numeric keys
                 $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals);
                 $running_totals['total'] += $running_totals_from_subtotal['total'];
                 $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total'];
                 break;
             case EEM_Line_Item::type_tax_sub_total:
                 //find how much the taxes percentage is
                 if ($child_line_item->percent() != 0) {
                     $tax_percent_decimal = $child_line_item->percent() / 100;
                 } else {
                     $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100;
                 }
                 //and apply to all the taxable totals, and add to the pretax totals
                 foreach ($running_totals as $line_item_id => $this_running_total) {
                     //"total" and "taxable" array key is an exception
                     if ($line_item_id === 'taxable') {
                         continue;
                     }
                     $taxable_total = $running_totals['taxable'][$line_item_id];
                     $running_totals[$line_item_id] += $taxable_total * $tax_percent_decimal;
                 }
                 break;
             case EEM_Line_Item::type_line_item:
                 // ticket line items or ????
                 if ($child_line_item->OBJ_type() === 'Ticket') {
                     // kk it's a ticket
                     if (isset($running_totals[$child_line_item->ID()])) {
                         //huh? that shouldn't happen.
                         $running_totals['total'] += $child_line_item->total();
                     } else {
                         //its not in our running totals yet. great.
                         if ($child_line_item->is_taxable()) {
                             $taxable_amount = $child_line_item->unit_price();
                         } else {
                             $taxable_amount = 0;
                         }
                         // are we only calculating totals for some tickets?
                         if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) {
                             $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()];
                             $running_totals[$child_line_item->ID()] = $quantity ? $child_line_item->unit_price() : 0;
                             $running_totals['taxable'][$child_line_item->ID()] = $quantity ? $taxable_amount : 0;
                         } else {
                             $quantity = $child_line_item->quantity();
                             $running_totals[$child_line_item->ID()] = $child_line_item->unit_price();
                             $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount;
                         }
                         $running_totals['taxable']['total'] += $taxable_amount * $quantity;
                         $running_totals['total'] += $child_line_item->unit_price() * $quantity;
                     }
                 } else {
                     // it's some other type of item added to the cart
                     // it should affect the running totals
                     // basically we want to convert it into a PERCENT modifier. Because
                     // more clearly affect all registration's final price equally
                     $line_items_percent_of_running_total = $running_totals['total'] > 0 ? $child_line_item->total() / $running_totals['total'] + 1 : 1;
                     foreach ($running_totals as $line_item_id => $this_running_total) {
                         //the "taxable" array key is an exception
                         if ($line_item_id === 'taxable') {
                             continue;
                         }
                         // update the running totals
                         // yes this actually even works for the running grand total!
                         $running_totals[$line_item_id] = $line_items_percent_of_running_total * $this_running_total;
                         if ($child_line_item->is_taxable()) {
                             $running_totals['taxable'][$line_item_id] = $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id];
                         }
                     }
                 }
                 break;
         }
     }
     return $running_totals;
 }