/**
  * is_applicable_item
  * control which events have promotions applied to them
  *
  * @param bool          $is_applicable_item
  * @param \EE_Line_Item $object_type_line_item
  * @return bool
  */
 public function is_applicable_item($is_applicable_item = true, EE_Line_Item $object_type_line_item)
 {
     $is_applicable_item = $object_type_line_item->total() > 0 ? $is_applicable_item : false;
     return $is_applicable_item;
 }
 /**
  * get_redeemable_scope_promos
  * searches the cart for any items that this promotion applies to
  *
  * @since   1.0.0
  *
  * @param EE_Line_Item $parent_line_item the line item to create the new promotion line item under
  * @param EE_Promotion $promotion        the promotion object that the line item is being created for
  * @param string       $promo_name
  * @param bool         $affects_tax
  * @return \EE_Line_Item
  * @throws \EE_Error
  */
 public function generate_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion, $promo_name = '', $affects_tax = false)
 {
     // verify EE_Line_Item
     if (!$parent_line_item instanceof EE_Line_Item) {
         throw new EE_Error(__('A valid EE_Line_Item object is required to generate a promotion line item.', 'event_espresso'));
     }
     // verify EE_Promotion
     if (!$promotion instanceof EE_Promotion) {
         throw new EE_Error(__('A valid EE_Promotion object is required to generate a promotion line item.', 'event_espresso'));
     }
     $promo_name = !empty($promo_name) ? $promo_name : $promotion->name();
     $promo_desc = $promotion->price()->desc();
     $promo_desc .= $promotion->code() != '' ? ' ( ' . $promotion->code() . ' )' : '';
     // generate promotion line_item
     $line_item = EE_Line_Item::new_instance(array('LIN_code' => 'promotion-' . $promotion->ID(), 'TXN_ID' => $parent_line_item->TXN_ID(), 'LIN_name' => apply_filters('FHEE__EE_Promotion_Scope__generate_promotion_line_item__LIN_name', $promo_name, $promotion), 'LIN_desc' => $promo_desc, 'LIN_unit_price' => $promotion->is_percent() ? 0 : $promotion->amount(), 'LIN_percent' => $promotion->is_percent() ? $promotion->amount() : 0, 'LIN_is_taxable' => $affects_tax, 'LIN_order' => $promotion->price()->order() + EE_Promotion_Scope::$_counter, 'LIN_total' => $promotion->calculated_amount_on_value($parent_line_item->total()), 'LIN_quantity' => 1, 'LIN_parent' => $parent_line_item->ID(), 'LIN_type' => $this->get_promotion_line_item_type(), 'OBJ_ID' => $promotion->ID(), 'OBJ_type' => 'Promotion'));
     EE_Promotion_Scope::$_counter++;
     return $line_item;
 }
 /**
  *    _payments_and_amount_owing_rows
  *
  * @param EE_Line_Item $line_item
  * @param array        $options
  * @return mixed
  */
 private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
 {
     $html = '';
     $owing = $line_item->total();
     $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
     if ($transaction instanceof EE_Transaction) {
         $registration_payments = array();
         $registrations = !empty($options['registrations']) ? $options['registrations'] : $transaction->registrations();
         foreach ($registrations as $registration) {
             if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
                 $registration_payments = $registration_payments + $registration->registration_payments();
             }
         }
         if (!empty($registration_payments)) {
             foreach ($registration_payments as $registration_payment) {
                 if ($registration_payment instanceof EE_Registration_Payment) {
                     $owing = $owing - $registration_payment->amount();
                     $payment = $registration_payment->payment();
                     if ($payment instanceof EE_Payment) {
                         $payment_desc = sprintf(__('Payment%1$s Received: %2$s', 'event_espresso'), $payment->txn_id_chq_nmbr() != '' ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' : '', $payment->timestamp());
                     } else {
                         $payment_desc = '';
                     }
                     // start of row
                     $html .= EEH_HTML::tr('', '', 'total_tr odd');
                     // payment desc
                     $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
                     // total td
                     $html .= EEH_HTML::td(EEH_Template::format_currency($registration_payment->amount(), false, false), '', 'total jst-rght');
                     // end of row
                     $html .= EEH_HTML::trx();
                 }
             }
             if ($line_item->total()) {
                 // start of row
                 $html .= EEH_HTML::tr('', '', 'total_tr odd');
                 // total td
                 $html .= EEH_HTML::td(__('Amount Owing', 'event_espresso'), '', 'total_currency total jst-rght', '', ' colspan="3"');
                 // total td
                 $html .= EEH_HTML::td(EEH_Template::format_currency($owing, false, false), '', 'total jst-rght');
                 // end of row
                 $html .= EEH_HTML::trx();
             }
         }
     }
     $this->_grand_total = $owing;
     return $html;
 }
 /**
  * 	_total_row
  *
  * @param EE_Line_Item $line_item
  * @param string       $text
  * @return mixed
  */
 private function _sub_total_row(EE_Line_Item $line_item, $text = '')
 {
     $html = '';
     if ($line_item->total()) {
         // start of row
         $html = EEH_HTML::tr('', '', 'total_tr odd');
         $text = $line_item->code() == 'pre-tax-subtotal' ? EED_Multi_Event_Registration::$event_cart_name . ' ' . $text : $text;
         // total td
         $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
         // total td
         $total = $line_item->total();
         $html .= EEH_HTML::td(EEH_Template::format_currency($total, false, false), '', 'total jst-rght');
         // end of row
         $html .= EEH_HTML::trx();
     }
     return $html;
 }
 /**
  * 	_sub_item_row
  *
  * @param EE_Line_Item $line_item
  * @param array        $options
  * @return mixed
  */
 private function _sub_item_row(EE_Line_Item $line_item, $options = array())
 {
     // start of row
     $html = EEH_HTML::tr('', 'item sub-item-row');
     // name && desc
     $name_and_desc = $line_item->name();
     $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
     // name td
     $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
     // discount/surcharge td
     if ($line_item->is_percent()) {
         $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
     } else {
         $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
     }
     // total td
     $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
     // end of row
     $html .= EEH_HTML::trx();
     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 "\n<br />";
     for ($i = 0; $i < $indentation; $i++) {
         echo " - ";
     }
     if ($line_item->is_percent()) {
         $breakdown = $line_item->percent() . '%';
     } else {
         $breakdown = '$' . $line_item->unit_price() . "x" . $line_item->quantity();
     }
     echo $line_item->name() . "( " . $line_item->ID() . " ) : " . $line_item->type() . " \$" . $line_item->total() . "(" . $breakdown . ")";
     if ($line_item->is_taxable()) {
         echo "  * taxable";
     }
     if ($line_item->children()) {
         foreach ($line_item->children() as $child) {
             self::visualize($child, $indentation + 1);
         }
     }
 }
 /**
  *    _total_row
  *
  * @param EE_Line_Item $line_item
  * @param string $text
  * @return mixed
  */
 private function _total_tax_row(EE_Line_Item $line_item, $text = '')
 {
     $html = '';
     if ($line_item->total()) {
         // start of row
         $html = EEH_HTML::tr('', 'event-cart-total-tax-row-' . $line_item->ID(), 'event-cart-total-tax-row total_tr');
         // total td
         $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght');
         $html .= EEH_HTML::td('', '', 'total jst-cntr');
         // empty td (price)
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
         // total td
         $html .= EEH_HTML::td($line_item->total_no_code(), '', 'total jst-rght');
         // end of row
         $html .= EEH_HTML::trx();
     }
     return $html;
 }
 /**
  * 	_total_row
  *
  * @param EE_Line_Item $line_item
  * @param string       $text
  * @param array        $options
  * @return mixed
  */
 private function _total_row(EE_Line_Item $line_item, $text = '', $options = array())
 {
     $html = '';
     if ($line_item->total()) {
         // start of row
         $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
         // total td
         $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
         // total td
         $this->_grand_total = $this->_billable_total + $this->_total_tax;
         $html .= EEH_HTML::td(EEH_Template::format_currency($this->_grand_total, false, false), '', 'total jst-rght');
         // end of row
         $html .= EEH_HTML::trx();
     }
     return $html;
 }
 /**
  * 		Processes the final step of SPCO in order to process payments
  * 		@access public
  * 		@param EE_Line_Item $total_line_item the line item whose total takes all other line items on this transaction into account
  *		@param EE_Transaction $transaction
  * 		@return 	mixed	void or FALSE on fail
  */
 public function process_payment_start(EE_Line_Item $line_item, EE_Transaction $transaction = NULL, $total_to_charge = NULL)
 {
     do_action('AHEE_log', __FILE__, __FUNCTION__, '');
     if (empty($transaction)) {
         $transaction = $line_item->transaction();
     }
     EE_Registry::instance()->load_helper('Template');
     // free event?
     if ($line_item->total() == EEH_Template::format_currency(0, TRUE)) {
         $transaction->set_status(EEM_Transaction::complete_status_code);
         $transaction->save();
         $transaction->finalize();
         $response = array('msg' => array('success' => TRUE));
     } else {
         try {
             $response = array('msg' => $this->selected_gateway_obj()->process_payment_start($line_item, $transaction, $total_to_charge));
         } catch (EE_Error $e) {
             $response = array('msg' => array('error' => $e->getMessage()));
         }
         //make sure we remove the credit card and other sensitive data, as we dont want to store that in the db
         $this->_clean_billing_info_in_session($transaction);
     }
     // add return URL
     $response['forward_url'] = $this->_get_return_page_url($transaction);
     return $response;
 }
 /**
  * 	_total_row
  *
  * @param EE_Line_Item $line_item
  * @param array        $options
  * @return mixed
  */
 protected function _total_row(EE_Line_Item $line_item, $options = array())
 {
     $registration = isset($options['EE_Registration']) ? $options['EE_Registration'] : null;
     $registration_total = $registration instanceof EE_Registration ? $registration->pretty_final_price() : 0;
     //if no valid registration object then we're not going to show the approximate text.
     $total_match = $registration instanceof EE_Registration ? $registration->final_price() == $line_item->total() : true;
     // start of row
     $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
     // Total th label
     if ($total_match) {
         $total_label = sprintf(__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
     } else {
         $total_label = sprintf(__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
         $total_label .= '<br>';
         $total_label .= '<p class="ee-footnote-text">' . sprintf(__('The registrations\' share of the transaction total is approximate because it might not be possible to evenly divide the transaction total among each registration, and so some registrations may need to pay a penny more than others.  This registration\'s final share is actually %1$s%2$s%3$s.', 'event_espresso'), '<strong>', $registration_total, '</strong>') . '</p>';
     }
     $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="3"');
     // total th
     $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
     // end of row
     $html .= EEH_HTML::trx();
     return $html;
 }
 /**
  * 	_total_row
  *
  * @param EE_Line_Item $line_item
  * @param string       $text
  * @return mixed
  */
 private function _sub_total_row(EE_Line_Item $line_item, $text = '')
 {
     if ($line_item->total() && count($this->_events) > 1) {
         return $this->_total_row($line_item, $text);
     }
     return '';
 }
 /**
  * 	_total_row
  *
  * @param EE_Line_Item $line_item
  * @param array        $options
  * @return mixed
  */
 protected function _total_row(EE_Line_Item $line_item, $options = array())
 {
     // start of row
     $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
     // Total th label
     $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
     $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"');
     // total th
     $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
     // end of row
     $html .= EEH_HTML::trx();
     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);
         }
     }
 }
 /**
  * 	_total_row
  *
  * @param EE_Line_Item $line_item
  * @param string       $text
  * @return mixed
  */
 private function _total_row(EE_Line_Item $line_item, $text = '')
 {
     // start of row
     $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
     // total td
     $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
     // total td
     $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'total jst-rght');
     // end of row
     $html .= EEH_HTML::trx();
     return $html;
 }