コード例 #1
0
 /**
  * simply take an incoming ticket and calculate the subtotal for the ticket
  * @param  EE_Ticket $ticket
  * @return float     subtotal calculated from all EE_Price[] on Ticket.
  */
 private static function _get_subtotal_for_admin(EE_Ticket $ticket)
 {
     $subtotal = 0;
     //get all prices
     $prices = $ticket->get_many_related('Price', array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')));
     //let's loop through them (base price is always the first item)
     foreach ($prices as $price) {
         if ($price instanceof EE_Price) {
             $price_type = $price->type_obj();
             if ($price_type instanceof EE_Price_Type) {
                 switch ($price->type_obj()->base_type()) {
                     case 1:
                         // base price
                     // base price
                     case 3:
                         // surcharges
                         $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 : $price->get('PRC_amount');
                         break;
                     case 2:
                         // discounts
                         $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 : $price->get('PRC_amount');
                         break;
                 }
             }
         }
     }
     $TKT_ID = $ticket->ID();
     self::$_subtotal = array($TKT_ID => $subtotal);
     return $subtotal;
 }
コード例 #2
0
 /**
  *    _set_initial_ticket_datetime_availability
  *
  * @access 	private
  * @param 	EE_Ticket $ticket
  * @return 	int
  */
 private static function _set_initial_ticket_datetime_availability(EE_Ticket $ticket)
 {
     // first, get all of the datetimes that are available to this ticket
     $datetimes = $ticket->get_many_related('Datetime', array(array('DTT_EVT_end' => array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'))), 'order_by' => array('DTT_EVT_start' => 'ASC')));
     if (!empty($datetimes)) {
         // now loop thru all of the datetimes
         foreach ($datetimes as $datetime) {
             if ($datetime instanceof EE_Datetime) {
                 // the number of spaces available for the datetime without considering individual ticket quantities
                 $spaces_remaining = $datetime->spaces_remaining();
                 // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold or the datetime spaces remaining) to this ticket using the datetime ID as the key
                 self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min($ticket->qty() - $ticket->sold(), $spaces_remaining);
                 // if the remaining spaces for this datetime is already set, then compare that against the datetime spaces remaining, and take the lowest number,
                 // else just take the datetime spaces remaining, and assign to the datetimes array
                 self::$_available_spaces['datetimes'][$datetime->ID()] = isset(self::$_available_spaces['datetimes'][$datetime->ID()]) ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) : $spaces_remaining;
             }
         }
     }
 }
 /**
  *
  * @access  protected
  * @param \EE_Ticket $ticket
  * @param array $price_rows
  * @param int $ticket_price
  * @param int $base_price
  * @param int $base_price_id
  * @return \EE_Ticket
  * @throws \EE_Error
  */
 protected function _duplicate_ticket(EE_Ticket $ticket, $price_rows = array(), $ticket_price = 0, $base_price = 0, $base_price_id = 0)
 {
     // create new ticket that's a copy of the existing
     // except a new id of course (and not archived)
     // AND has the new TKT_price associated with it.
     $new_ticket = clone $ticket;
     $new_ticket->set('TKT_ID', 0);
     $new_ticket->set('TKT_deleted', 0);
     $new_ticket->set('TKT_price', $ticket_price);
     $new_ticket->set('TKT_sold', 0);
     // let's get a new ID for this ticket
     $new_ticket->save();
     // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
     $datetimes_on_existing = $ticket->get_many_related('Datetime');
     $new_ticket = $this->_update_ticket_datetimes($new_ticket, $datetimes_on_existing, array_keys($datetimes_on_existing));
     // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
     // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
     // available.
     if ($ticket->sold() > 0) {
         $new_qty = $ticket->qty() - $ticket->sold();
         $new_ticket->set_qty($new_qty);
     }
     //now we update the prices just for this ticket
     $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
     //and we update the base price
     $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id);
     return $new_ticket;
 }