@@ -1,91 +1,91 @@ |
||
1 | 1 | <div id="ee-single-page-checkout-dv" class=""> |
2 | 2 | <?php |
3 | - if (! $empty_cart) { |
|
4 | - if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
3 | + if (! $empty_cart) { |
|
4 | + if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
5 | 5 | <p id="spco-registration-time-limit-pg" class="spco-steps-pg ee-attention important-notice" |
6 | 6 | style="display: none;"> |
7 | 7 | <?php echo sprintf( |
8 | - apply_filters( |
|
9 | - 'FHEE__registration_page_wrapper_template___time_limit', |
|
10 | - __('You have %1$s to complete your registration.', 'event_espresso') |
|
11 | - ), |
|
12 | - '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' . $registration_time_limit . '</span>' |
|
13 | - ); |
|
14 | - ?> |
|
8 | + apply_filters( |
|
9 | + 'FHEE__registration_page_wrapper_template___time_limit', |
|
10 | + __('You have %1$s to complete your registration.', 'event_espresso') |
|
11 | + ), |
|
12 | + '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' . $registration_time_limit . '</span>' |
|
13 | + ); |
|
14 | + ?> |
|
15 | 15 | <span id="spco-registration-expiration-spn" class="" style="display:none;"></span> |
16 | 16 | </p> |
17 | 17 | <?php } |
18 | - if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
19 | - ?> |
|
18 | + if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
19 | + ?> |
|
20 | 20 | <h2 id="spco-steps-big-hdr" class="spco-steps-big-hdr"><?php _e(' Steps', 'event_espresso'); ?></h2> |
21 | 21 | |
22 | 22 | <div id="spco-steps-display-dv"> |
23 | 23 | <?php |
24 | - $step_nmbr = 1; |
|
25 | - $total_steps = count($reg_steps) - 1; |
|
26 | - foreach ($reg_steps as $reg_step) { |
|
27 | - if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
28 | - $slug = $reg_step->slug(); |
|
29 | - $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
|
30 | - ?> |
|
24 | + $step_nmbr = 1; |
|
25 | + $total_steps = count($reg_steps) - 1; |
|
26 | + foreach ($reg_steps as $reg_step) { |
|
27 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
28 | + $slug = $reg_step->slug(); |
|
29 | + $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
|
30 | + ?> |
|
31 | 31 | <div id="spco-step-<?php echo $slug; ?>-display-dv" |
32 | 32 | class="spco-step-display-dv <?php echo $step_display_dv_class; ?> steps-<?php echo $total_steps; ?>"> |
33 | 33 | <h4 id="spco-step-<?php echo $slug; ?>-display-hdr" class="spco-steps-display-hdr"> |
34 | 34 | <span class="spco-step-big-nmbr"><?php echo $step_nmbr; ?></span> |
35 | 35 | <span class="spco-step-name"> |
36 | 36 | <?php echo str_replace( |
37 | - ' ', |
|
38 | - '<br/> ', |
|
39 | - $reg_step->name() |
|
40 | - ); ?> |
|
37 | + ' ', |
|
38 | + '<br/> ', |
|
39 | + $reg_step->name() |
|
40 | + ); ?> |
|
41 | 41 | </span> |
42 | 42 | </h4> |
43 | 43 | </div> |
44 | 44 | |
45 | 45 | <?php |
46 | - if ($step_nmbr < $total_steps) { ?> |
|
46 | + if ($step_nmbr < $total_steps) { ?> |
|
47 | 47 | <div class="spco-step-arrow-dv">»</div> |
48 | 48 | <?php |
49 | - } |
|
50 | - $step_nmbr++; |
|
51 | - } |
|
52 | - } |
|
53 | - ?> |
|
49 | + } |
|
50 | + $step_nmbr++; |
|
51 | + } |
|
52 | + } |
|
53 | + ?> |
|
54 | 54 | <div class="clear-float"></div> |
55 | 55 | </div> |
56 | 56 | |
57 | 57 | <?php |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - do_action('AHEE__SPCO__before_registration_steps'); |
|
61 | - $step_nmbr = 1; |
|
62 | - foreach ($reg_steps as $reg_step) { |
|
63 | - if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
64 | - $slug = $reg_step->slug(); |
|
65 | - do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
66 | - // todo: deprecate hook AHEE__registration_page_attendee_information__start |
|
67 | - ?> |
|
60 | + do_action('AHEE__SPCO__before_registration_steps'); |
|
61 | + $step_nmbr = 1; |
|
62 | + foreach ($reg_steps as $reg_step) { |
|
63 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
64 | + $slug = $reg_step->slug(); |
|
65 | + do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
66 | + // todo: deprecate hook AHEE__registration_page_attendee_information__start |
|
67 | + ?> |
|
68 | 68 | <div id="spco-<?php echo $slug; ?>-dv" class="spco-step-dv <?php echo $reg_step->div_class(); ?>"> |
69 | 69 | <?php echo $reg_step->display_reg_form(); ?> |
70 | 70 | <?php do_action('AHEE__SPCO_after_reg_step_form', $slug, $next_step); ?> |
71 | 71 | </div> |
72 | 72 | <?php $step_nmbr++; |
73 | - } |
|
74 | - } |
|
75 | - do_action('AHEE__SPCO__after_registration_steps'); |
|
76 | - } else { |
|
77 | - ?> |
|
73 | + } |
|
74 | + } |
|
75 | + do_action('AHEE__SPCO__after_registration_steps'); |
|
76 | + } else { |
|
77 | + ?> |
|
78 | 78 | <h3 id="spco-empty-cart-hdr" class="spco-step-title-hdr"> |
79 | 79 | <?php esc_html_e( |
80 | - 'Nothing in your Event Queue', |
|
81 | - 'event_espresso' |
|
82 | - ); ?></h3> |
|
80 | + 'Nothing in your Event Queue', |
|
81 | + 'event_espresso' |
|
82 | + ); ?></h3> |
|
83 | 83 | <p><?php echo $empty_msg; ?></p> |
84 | 84 | <?php echo $cookies_not_set_msg; ?> |
85 | 85 | <?php |
86 | - } |
|
87 | - do_action('AHEE__SPCO__reg_form_footer'); |
|
88 | - ?> |
|
86 | + } |
|
87 | + do_action('AHEE__SPCO__reg_form_footer'); |
|
88 | + ?> |
|
89 | 89 | |
90 | 90 | </div> |
91 | 91 |
@@ -18,360 +18,360 @@ |
||
18 | 18 | class TicketSelectorRowStandard extends TicketSelectorRow |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var TicketDetails $ticket_details |
|
23 | - */ |
|
24 | - protected $ticket_details; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var \EE_Ticket_Selector_Config $template_settings |
|
28 | - */ |
|
29 | - protected $template_settings; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EE_Tax_Config $tax_settings |
|
33 | - */ |
|
34 | - protected $tax_settings; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var boolean $prices_displayed_including_taxes |
|
38 | - */ |
|
39 | - protected $prices_displayed_including_taxes; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int $row |
|
43 | - */ |
|
44 | - protected $row; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var int $cols |
|
48 | - */ |
|
49 | - protected $cols; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var boolean $hidden_input_qty |
|
53 | - */ |
|
54 | - protected $hidden_input_qty; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string $ticket_datetime_classes |
|
58 | - */ |
|
59 | - protected $ticket_datetime_classes; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * TicketDetails constructor. |
|
64 | - * |
|
65 | - * @param TicketDetails $ticket_details |
|
66 | - * @param EE_Tax_Config $tax_settings |
|
67 | - * @param int $total_tickets |
|
68 | - * @param int $max_attendees |
|
69 | - * @param int $row |
|
70 | - * @param int $cols |
|
71 | - * @param boolean $required_ticket_sold_out |
|
72 | - * @param string $event_status |
|
73 | - * @param string $ticket_datetime_classes |
|
74 | - * @throws EE_Error |
|
75 | - * @throws UnexpectedEntityException |
|
76 | - */ |
|
77 | - public function __construct( |
|
78 | - TicketDetails $ticket_details, |
|
79 | - EE_Tax_Config $tax_settings, |
|
80 | - $total_tickets, |
|
81 | - $max_attendees, |
|
82 | - $row, |
|
83 | - $cols, |
|
84 | - $required_ticket_sold_out, |
|
85 | - $event_status, |
|
86 | - $ticket_datetime_classes |
|
87 | - ) { |
|
88 | - $this->ticket_details = $ticket_details; |
|
89 | - $this->template_settings = $ticket_details->getTemplateSettings(); |
|
90 | - $this->tax_settings = $tax_settings; |
|
91 | - $this->row = $row; |
|
92 | - $this->cols = $cols; |
|
93 | - $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
94 | - parent::__construct( |
|
95 | - $ticket_details->getTicket(), |
|
96 | - $max_attendees, |
|
97 | - $ticket_details->getDateFormat(), |
|
98 | - $event_status, |
|
99 | - $required_ticket_sold_out, |
|
100 | - $total_tickets |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * other ticket rows will need to know if a required ticket is sold out, |
|
107 | - * so that they are not offered for sale |
|
108 | - * |
|
109 | - * @return boolean |
|
110 | - */ |
|
111 | - public function getRequiredTicketSoldOut() |
|
112 | - { |
|
113 | - return $this->required_ticket_sold_out; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function getCols() |
|
121 | - { |
|
122 | - return $this->cols; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * getHtml |
|
128 | - * |
|
129 | - * @return string |
|
130 | - * @throws EE_Error |
|
131 | - */ |
|
132 | - public function getHtml() |
|
133 | - { |
|
134 | - $this->min = 0; |
|
135 | - $this->max = $this->ticket->max(); |
|
136 | - $remaining = $this->ticket->remaining(); |
|
137 | - $this->setTicketMinAndMax($remaining); |
|
138 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
139 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
140 | - ? $this->ticket->start_date() |
|
141 | - : $this->required_ticket_sold_out; |
|
142 | - $this->setTicketPriceDetails(); |
|
143 | - $this->setTicketStatusClasses($remaining); |
|
144 | - $filtered_row_html = $this->getFilteredRowHtml(); |
|
145 | - if ($filtered_row_html !== false) { |
|
146 | - return $filtered_row_html; |
|
147 | - } |
|
148 | - $ticket_selector_row_html = EEH_HTML::tr( |
|
149 | - '', |
|
150 | - '', |
|
151 | - "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
152 | - . espresso_get_object_css_class($this->ticket) |
|
153 | - ); |
|
154 | - $filtered_row_content = $this->getFilteredRowContents(); |
|
155 | - if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
156 | - return $ticket_selector_row_html |
|
157 | - . $filtered_row_content |
|
158 | - . $this->ticketQtyAndIdHiddenInputs() |
|
159 | - . EEH_HTML::trx(); |
|
160 | - } |
|
161 | - if ($filtered_row_content !== false) { |
|
162 | - return $ticket_selector_row_html |
|
163 | - . $filtered_row_content |
|
164 | - . EEH_HTML::trx(); |
|
165 | - } |
|
166 | - $this->hidden_input_qty = $this->max_attendees > 1; |
|
167 | - |
|
168 | - $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
169 | - $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
170 | - $ticket_selector_row_html .= EEH_HTML::td( |
|
171 | - '', |
|
172 | - '', |
|
173 | - 'tckt-slctr-tbl-td-qty cntr', |
|
174 | - '', |
|
175 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
176 | - ); |
|
177 | - $this->setTicketStatusDisplay($remaining); |
|
178 | - if (empty($this->ticket_status_display)) { |
|
179 | - if ($this->max_attendees === 1) { |
|
180 | - // only ONE attendee is allowed to register at a time |
|
181 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
182 | - } elseif ($this->max > 0) { |
|
183 | - $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
184 | - } |
|
185 | - } |
|
186 | - $ticket_selector_row_html .= $this->ticket_status_display; |
|
187 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
188 | - $ticket_selector_row_html .= $this->ticket_details->display( |
|
189 | - $this->ticket_price, |
|
190 | - $remaining, |
|
191 | - $this->cols |
|
192 | - ); |
|
193 | - $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
194 | - $ticket_selector_row_html .= EEH_HTML::trx(); |
|
195 | - |
|
196 | - |
|
197 | - $this->row++; |
|
198 | - return $ticket_selector_row_html; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * getTicketPriceDetails |
|
204 | - * |
|
205 | - * @return void |
|
206 | - * @throws EE_Error |
|
207 | - */ |
|
208 | - protected function setTicketPriceDetails() |
|
209 | - { |
|
210 | - $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
211 | - ? $this->ticket->get_ticket_total_with_taxes() |
|
212 | - : $this->ticket->get_ticket_subtotal(); |
|
213 | - $this->ticket_bundle = false; |
|
214 | - $ticket_min = $this->ticket->min(); |
|
215 | - // for ticket bundles, set min and max qty the same |
|
216 | - if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
217 | - $this->ticket_price *= $ticket_min; |
|
218 | - $this->ticket_bundle = true; |
|
219 | - } |
|
220 | - $this->ticket_price = apply_filters( |
|
221 | - 'FHEE__ticket_selector_chart_template__ticket_price', |
|
222 | - $this->ticket_price, |
|
223 | - $this->ticket |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * ticketNameTableCell |
|
230 | - * |
|
231 | - * @return string |
|
232 | - * @throws EE_Error |
|
233 | - */ |
|
234 | - protected function ticketNameTableCell() |
|
235 | - { |
|
236 | - $html = EEH_HTML::td( |
|
237 | - '', |
|
238 | - '', |
|
239 | - 'tckt-slctr-tbl-td-name', |
|
240 | - '', |
|
241 | - 'headers="details-' . $this->EVT_ID . '"' |
|
242 | - ); |
|
243 | - $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
244 | - $html .= $this->ticket_details->getShowHideLinks(); |
|
245 | - if ($this->ticket->required()) { |
|
246 | - $html .= EEH_HTML::p( |
|
247 | - apply_filters( |
|
248 | - 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
249 | - esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
250 | - ), |
|
251 | - '', |
|
252 | - 'ticket-required-pg' |
|
253 | - ); |
|
254 | - } |
|
255 | - $html .= EEH_HTML::tdx(); |
|
256 | - return $html; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * ticketPriceTableCell |
|
262 | - * |
|
263 | - * @return string |
|
264 | - * @throws EE_Error |
|
265 | - */ |
|
266 | - protected function ticketPriceTableCell() |
|
267 | - { |
|
268 | - $html = ''; |
|
269 | - if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
270 | - $html .= EEH_HTML::td( |
|
271 | - '', |
|
272 | - '', |
|
273 | - 'tckt-slctr-tbl-td-price jst-rght', |
|
274 | - '', |
|
275 | - 'headers="price-' . $this->EVT_ID . '"' |
|
276 | - ); |
|
277 | - $html .= EEH_HTML::span( |
|
278 | - EEH_Template::format_currency($this->ticket_price), |
|
279 | - '', |
|
280 | - 'tckt-price--nowrap' |
|
281 | - ); |
|
282 | - $html .= $this->ticket->taxable() |
|
283 | - ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
284 | - : ''; |
|
285 | - $html .= ' '; |
|
286 | - // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
287 | - $html .= EEH_HTML::span( |
|
288 | - $this->ticket_bundle |
|
289 | - ? apply_filters( |
|
290 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
291 | - __(' / bundle', 'event_espresso') |
|
292 | - ) |
|
293 | - : apply_filters( |
|
294 | - 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
295 | - __('', 'event_espresso') |
|
296 | - ), |
|
297 | - '', |
|
298 | - 'smaller-text no-bold' |
|
299 | - ); |
|
300 | - $html .= ' '; |
|
301 | - $html .= EEH_HTML::tdx(); |
|
302 | - $this->cols++; |
|
303 | - } |
|
304 | - return $html; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * onlyOneAttendeeCanRegister |
|
310 | - * |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - protected function onlyOneAttendeeCanRegister() |
|
314 | - { |
|
315 | - // display submit button since we have tickets available |
|
316 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
317 | - $this->hidden_input_qty = false; |
|
318 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
319 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
320 | - $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
321 | - $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
322 | - $html .= ' id="' . $id . '"'; |
|
323 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
324 | - $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
325 | - $html .= ' title=""/>'; |
|
326 | - return $html; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * ticketQuantitySelector |
|
332 | - * |
|
333 | - * @return string |
|
334 | - * @throws EE_Error |
|
335 | - */ |
|
336 | - protected function ticketQuantitySelector() |
|
337 | - { |
|
338 | - // display submit button since we have tickets available |
|
339 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
340 | - $this->hidden_input_qty = false; |
|
341 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
342 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
343 | - $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
344 | - $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
345 | - $html .= ' id="' . $id . '"'; |
|
346 | - $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
347 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
348 | - if ($this->min !== 0 && ! $this->ticket->required()) { |
|
349 | - $html .= '<option value="0"> 0 </option>'; |
|
350 | - } |
|
351 | - // offer ticket quantities from the min to the max |
|
352 | - for ($i = $this->min; $i <= $this->max; $i++) { |
|
353 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
354 | - } |
|
355 | - $html .= '</select>'; |
|
356 | - return $html; |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * getHiddenInputs |
|
362 | - * |
|
363 | - * @return string |
|
364 | - * @throws EE_Error |
|
365 | - */ |
|
366 | - protected function ticketQtyAndIdHiddenInputs() |
|
367 | - { |
|
368 | - $html = ''; |
|
369 | - // depending on group reg we need to change the format for qty |
|
370 | - if ($this->hidden_input_qty) { |
|
371 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
372 | - } |
|
373 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
374 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
375 | - return $html; |
|
376 | - } |
|
21 | + /** |
|
22 | + * @var TicketDetails $ticket_details |
|
23 | + */ |
|
24 | + protected $ticket_details; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var \EE_Ticket_Selector_Config $template_settings |
|
28 | + */ |
|
29 | + protected $template_settings; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EE_Tax_Config $tax_settings |
|
33 | + */ |
|
34 | + protected $tax_settings; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var boolean $prices_displayed_including_taxes |
|
38 | + */ |
|
39 | + protected $prices_displayed_including_taxes; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int $row |
|
43 | + */ |
|
44 | + protected $row; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var int $cols |
|
48 | + */ |
|
49 | + protected $cols; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var boolean $hidden_input_qty |
|
53 | + */ |
|
54 | + protected $hidden_input_qty; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string $ticket_datetime_classes |
|
58 | + */ |
|
59 | + protected $ticket_datetime_classes; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * TicketDetails constructor. |
|
64 | + * |
|
65 | + * @param TicketDetails $ticket_details |
|
66 | + * @param EE_Tax_Config $tax_settings |
|
67 | + * @param int $total_tickets |
|
68 | + * @param int $max_attendees |
|
69 | + * @param int $row |
|
70 | + * @param int $cols |
|
71 | + * @param boolean $required_ticket_sold_out |
|
72 | + * @param string $event_status |
|
73 | + * @param string $ticket_datetime_classes |
|
74 | + * @throws EE_Error |
|
75 | + * @throws UnexpectedEntityException |
|
76 | + */ |
|
77 | + public function __construct( |
|
78 | + TicketDetails $ticket_details, |
|
79 | + EE_Tax_Config $tax_settings, |
|
80 | + $total_tickets, |
|
81 | + $max_attendees, |
|
82 | + $row, |
|
83 | + $cols, |
|
84 | + $required_ticket_sold_out, |
|
85 | + $event_status, |
|
86 | + $ticket_datetime_classes |
|
87 | + ) { |
|
88 | + $this->ticket_details = $ticket_details; |
|
89 | + $this->template_settings = $ticket_details->getTemplateSettings(); |
|
90 | + $this->tax_settings = $tax_settings; |
|
91 | + $this->row = $row; |
|
92 | + $this->cols = $cols; |
|
93 | + $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
94 | + parent::__construct( |
|
95 | + $ticket_details->getTicket(), |
|
96 | + $max_attendees, |
|
97 | + $ticket_details->getDateFormat(), |
|
98 | + $event_status, |
|
99 | + $required_ticket_sold_out, |
|
100 | + $total_tickets |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * other ticket rows will need to know if a required ticket is sold out, |
|
107 | + * so that they are not offered for sale |
|
108 | + * |
|
109 | + * @return boolean |
|
110 | + */ |
|
111 | + public function getRequiredTicketSoldOut() |
|
112 | + { |
|
113 | + return $this->required_ticket_sold_out; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function getCols() |
|
121 | + { |
|
122 | + return $this->cols; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * getHtml |
|
128 | + * |
|
129 | + * @return string |
|
130 | + * @throws EE_Error |
|
131 | + */ |
|
132 | + public function getHtml() |
|
133 | + { |
|
134 | + $this->min = 0; |
|
135 | + $this->max = $this->ticket->max(); |
|
136 | + $remaining = $this->ticket->remaining(); |
|
137 | + $this->setTicketMinAndMax($remaining); |
|
138 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
139 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
140 | + ? $this->ticket->start_date() |
|
141 | + : $this->required_ticket_sold_out; |
|
142 | + $this->setTicketPriceDetails(); |
|
143 | + $this->setTicketStatusClasses($remaining); |
|
144 | + $filtered_row_html = $this->getFilteredRowHtml(); |
|
145 | + if ($filtered_row_html !== false) { |
|
146 | + return $filtered_row_html; |
|
147 | + } |
|
148 | + $ticket_selector_row_html = EEH_HTML::tr( |
|
149 | + '', |
|
150 | + '', |
|
151 | + "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
152 | + . espresso_get_object_css_class($this->ticket) |
|
153 | + ); |
|
154 | + $filtered_row_content = $this->getFilteredRowContents(); |
|
155 | + if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
156 | + return $ticket_selector_row_html |
|
157 | + . $filtered_row_content |
|
158 | + . $this->ticketQtyAndIdHiddenInputs() |
|
159 | + . EEH_HTML::trx(); |
|
160 | + } |
|
161 | + if ($filtered_row_content !== false) { |
|
162 | + return $ticket_selector_row_html |
|
163 | + . $filtered_row_content |
|
164 | + . EEH_HTML::trx(); |
|
165 | + } |
|
166 | + $this->hidden_input_qty = $this->max_attendees > 1; |
|
167 | + |
|
168 | + $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
169 | + $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
170 | + $ticket_selector_row_html .= EEH_HTML::td( |
|
171 | + '', |
|
172 | + '', |
|
173 | + 'tckt-slctr-tbl-td-qty cntr', |
|
174 | + '', |
|
175 | + 'headers="quantity-' . $this->EVT_ID . '"' |
|
176 | + ); |
|
177 | + $this->setTicketStatusDisplay($remaining); |
|
178 | + if (empty($this->ticket_status_display)) { |
|
179 | + if ($this->max_attendees === 1) { |
|
180 | + // only ONE attendee is allowed to register at a time |
|
181 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
182 | + } elseif ($this->max > 0) { |
|
183 | + $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
184 | + } |
|
185 | + } |
|
186 | + $ticket_selector_row_html .= $this->ticket_status_display; |
|
187 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
188 | + $ticket_selector_row_html .= $this->ticket_details->display( |
|
189 | + $this->ticket_price, |
|
190 | + $remaining, |
|
191 | + $this->cols |
|
192 | + ); |
|
193 | + $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
194 | + $ticket_selector_row_html .= EEH_HTML::trx(); |
|
195 | + |
|
196 | + |
|
197 | + $this->row++; |
|
198 | + return $ticket_selector_row_html; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * getTicketPriceDetails |
|
204 | + * |
|
205 | + * @return void |
|
206 | + * @throws EE_Error |
|
207 | + */ |
|
208 | + protected function setTicketPriceDetails() |
|
209 | + { |
|
210 | + $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
211 | + ? $this->ticket->get_ticket_total_with_taxes() |
|
212 | + : $this->ticket->get_ticket_subtotal(); |
|
213 | + $this->ticket_bundle = false; |
|
214 | + $ticket_min = $this->ticket->min(); |
|
215 | + // for ticket bundles, set min and max qty the same |
|
216 | + if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
217 | + $this->ticket_price *= $ticket_min; |
|
218 | + $this->ticket_bundle = true; |
|
219 | + } |
|
220 | + $this->ticket_price = apply_filters( |
|
221 | + 'FHEE__ticket_selector_chart_template__ticket_price', |
|
222 | + $this->ticket_price, |
|
223 | + $this->ticket |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * ticketNameTableCell |
|
230 | + * |
|
231 | + * @return string |
|
232 | + * @throws EE_Error |
|
233 | + */ |
|
234 | + protected function ticketNameTableCell() |
|
235 | + { |
|
236 | + $html = EEH_HTML::td( |
|
237 | + '', |
|
238 | + '', |
|
239 | + 'tckt-slctr-tbl-td-name', |
|
240 | + '', |
|
241 | + 'headers="details-' . $this->EVT_ID . '"' |
|
242 | + ); |
|
243 | + $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
244 | + $html .= $this->ticket_details->getShowHideLinks(); |
|
245 | + if ($this->ticket->required()) { |
|
246 | + $html .= EEH_HTML::p( |
|
247 | + apply_filters( |
|
248 | + 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
249 | + esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
250 | + ), |
|
251 | + '', |
|
252 | + 'ticket-required-pg' |
|
253 | + ); |
|
254 | + } |
|
255 | + $html .= EEH_HTML::tdx(); |
|
256 | + return $html; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * ticketPriceTableCell |
|
262 | + * |
|
263 | + * @return string |
|
264 | + * @throws EE_Error |
|
265 | + */ |
|
266 | + protected function ticketPriceTableCell() |
|
267 | + { |
|
268 | + $html = ''; |
|
269 | + if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
270 | + $html .= EEH_HTML::td( |
|
271 | + '', |
|
272 | + '', |
|
273 | + 'tckt-slctr-tbl-td-price jst-rght', |
|
274 | + '', |
|
275 | + 'headers="price-' . $this->EVT_ID . '"' |
|
276 | + ); |
|
277 | + $html .= EEH_HTML::span( |
|
278 | + EEH_Template::format_currency($this->ticket_price), |
|
279 | + '', |
|
280 | + 'tckt-price--nowrap' |
|
281 | + ); |
|
282 | + $html .= $this->ticket->taxable() |
|
283 | + ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
284 | + : ''; |
|
285 | + $html .= ' '; |
|
286 | + // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
287 | + $html .= EEH_HTML::span( |
|
288 | + $this->ticket_bundle |
|
289 | + ? apply_filters( |
|
290 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
291 | + __(' / bundle', 'event_espresso') |
|
292 | + ) |
|
293 | + : apply_filters( |
|
294 | + 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
295 | + __('', 'event_espresso') |
|
296 | + ), |
|
297 | + '', |
|
298 | + 'smaller-text no-bold' |
|
299 | + ); |
|
300 | + $html .= ' '; |
|
301 | + $html .= EEH_HTML::tdx(); |
|
302 | + $this->cols++; |
|
303 | + } |
|
304 | + return $html; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * onlyOneAttendeeCanRegister |
|
310 | + * |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + protected function onlyOneAttendeeCanRegister() |
|
314 | + { |
|
315 | + // display submit button since we have tickets available |
|
316 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
317 | + $this->hidden_input_qty = false; |
|
318 | + $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
319 | + $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
320 | + $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
321 | + $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
322 | + $html .= ' id="' . $id . '"'; |
|
323 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
324 | + $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
325 | + $html .= ' title=""/>'; |
|
326 | + return $html; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * ticketQuantitySelector |
|
332 | + * |
|
333 | + * @return string |
|
334 | + * @throws EE_Error |
|
335 | + */ |
|
336 | + protected function ticketQuantitySelector() |
|
337 | + { |
|
338 | + // display submit button since we have tickets available |
|
339 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
340 | + $this->hidden_input_qty = false; |
|
341 | + $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
342 | + $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
343 | + $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
344 | + $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
345 | + $html .= ' id="' . $id . '"'; |
|
346 | + $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
347 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
348 | + if ($this->min !== 0 && ! $this->ticket->required()) { |
|
349 | + $html .= '<option value="0"> 0 </option>'; |
|
350 | + } |
|
351 | + // offer ticket quantities from the min to the max |
|
352 | + for ($i = $this->min; $i <= $this->max; $i++) { |
|
353 | + $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
354 | + } |
|
355 | + $html .= '</select>'; |
|
356 | + return $html; |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * getHiddenInputs |
|
362 | + * |
|
363 | + * @return string |
|
364 | + * @throws EE_Error |
|
365 | + */ |
|
366 | + protected function ticketQtyAndIdHiddenInputs() |
|
367 | + { |
|
368 | + $html = ''; |
|
369 | + // depending on group reg we need to change the format for qty |
|
370 | + if ($this->hidden_input_qty) { |
|
371 | + $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
372 | + } |
|
373 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
374 | + $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
375 | + return $html; |
|
376 | + } |
|
377 | 377 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | '', |
173 | 173 | 'tckt-slctr-tbl-td-qty cntr', |
174 | 174 | '', |
175 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
175 | + 'headers="quantity-'.$this->EVT_ID.'"' |
|
176 | 176 | ); |
177 | 177 | $this->setTicketStatusDisplay($remaining); |
178 | 178 | if (empty($this->ticket_status_display)) { |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | '', |
239 | 239 | 'tckt-slctr-tbl-td-name', |
240 | 240 | '', |
241 | - 'headers="details-' . $this->EVT_ID . '"' |
|
241 | + 'headers="details-'.$this->EVT_ID.'"' |
|
242 | 242 | ); |
243 | 243 | $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
244 | 244 | $html .= $this->ticket_details->getShowHideLinks(); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | '', |
273 | 273 | 'tckt-slctr-tbl-td-price jst-rght', |
274 | 274 | '', |
275 | - 'headers="price-' . $this->EVT_ID . '"' |
|
275 | + 'headers="price-'.$this->EVT_ID.'"' |
|
276 | 276 | ); |
277 | 277 | $html .= EEH_HTML::span( |
278 | 278 | EEH_Template::format_currency($this->ticket_price), |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | // display submit button since we have tickets available |
316 | 316 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
317 | 317 | $this->hidden_input_qty = false; |
318 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
319 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
320 | - $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
321 | - $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
322 | - $html .= ' id="' . $id . '"'; |
|
323 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
318 | + $id = 'ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row; |
|
319 | + $html = '<label class="ee-a11y-screen-reader-text" for="'.$id.'">'; |
|
320 | + $html .= esc_html__('Select this ticket', 'event_espresso').'</label>'; |
|
321 | + $html .= '<input type="radio" name="tkt-slctr-qty-'.$this->EVT_ID.'"'; |
|
322 | + $html .= ' id="'.$id.'"'; |
|
323 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="'.$this->row.'-1"'; |
|
324 | 324 | $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
325 | 325 | $html .= ' title=""/>'; |
326 | 326 | return $html; |
@@ -338,11 +338,11 @@ discard block |
||
338 | 338 | // display submit button since we have tickets available |
339 | 339 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
340 | 340 | $this->hidden_input_qty = false; |
341 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
342 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
343 | - $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
344 | - $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
345 | - $html .= ' id="' . $id . '"'; |
|
341 | + $id = 'ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row; |
|
342 | + $html = '<label class="ee-a11y-screen-reader-text" for="'.$id.'">'; |
|
343 | + $html .= esc_html__('Quantity', 'event_espresso').'</label>'; |
|
344 | + $html .= '<select name="tkt-slctr-qty-'.$this->EVT_ID.'[]"'; |
|
345 | + $html .= ' id="'.$id.'"'; |
|
346 | 346 | $html .= ' class="ticket-selector-tbl-qty-slct">'; |
347 | 347 | // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
348 | 348 | if ($this->min !== 0 && ! $this->ticket->required()) { |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | } |
351 | 351 | // offer ticket quantities from the min to the max |
352 | 352 | for ($i = $this->min; $i <= $this->max; $i++) { |
353 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
353 | + $html .= '<option value="'.$i.'"> '.$i.' </option>'; |
|
354 | 354 | } |
355 | 355 | $html .= '</select>'; |
356 | 356 | return $html; |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | $html = ''; |
369 | 369 | // depending on group reg we need to change the format for qty |
370 | 370 | if ($this->hidden_input_qty) { |
371 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
371 | + $html .= '<input type="hidden" name="tkt-slctr-qty-'.$this->EVT_ID.'[]" value="0"/>'; |
|
372 | 372 | } |
373 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
374 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
373 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-'.$this->EVT_ID.'[]"'; |
|
374 | + $html .= ' value="'.$this->ticket->ID().'"/>'; |
|
375 | 375 | return $html; |
376 | 376 | } |
377 | 377 | } |
@@ -12,149 +12,149 @@ |
||
12 | 12 | class EE_Taxes extends EE_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * This is used for when EE_Taxes is used statically by the admin |
|
17 | - * |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - private static $_subtotal = []; |
|
15 | + /** |
|
16 | + * This is used for when EE_Taxes is used statically by the admin |
|
17 | + * |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + private static $_subtotal = []; |
|
21 | 21 | |
22 | - /** |
|
23 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
24 | - * |
|
25 | - * @var EE_Price[] |
|
26 | - */ |
|
27 | - private static $_default_taxes = []; |
|
22 | + /** |
|
23 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
24 | + * |
|
25 | + * @var EE_Price[] |
|
26 | + */ |
|
27 | + private static $_default_taxes = []; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
32 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
33 | - * calc of taxes for tickets listed in the event editor. |
|
34 | - * |
|
35 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
36 | - * @return float total taxes to apply to ticket. |
|
37 | - * @throws EE_Error |
|
38 | - * @throws ReflectionException |
|
39 | - */ |
|
40 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
41 | - { |
|
42 | - $tax = 0; |
|
43 | - $total_tax = 0; |
|
44 | - // This first checks to see if the given ticket is taxable. |
|
45 | - if (! $ticket->taxable()) { |
|
46 | - return $tax; |
|
47 | - } |
|
48 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
49 | - $subtotal = EE_Taxes::get_subtotal_for_admin($ticket); |
|
50 | - // get taxes |
|
51 | - $taxes = EE_Taxes::get_taxes_for_admin(); |
|
52 | - // apply taxes to subtotal |
|
53 | - foreach ($taxes as $tax) { |
|
54 | - // assuming taxes are not cumulative |
|
55 | - $total_tax += $subtotal * $tax->amount() / 100; |
|
56 | - } |
|
57 | - return $total_tax; |
|
58 | - } |
|
30 | + /** |
|
31 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
32 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
33 | + * calc of taxes for tickets listed in the event editor. |
|
34 | + * |
|
35 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
36 | + * @return float total taxes to apply to ticket. |
|
37 | + * @throws EE_Error |
|
38 | + * @throws ReflectionException |
|
39 | + */ |
|
40 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
41 | + { |
|
42 | + $tax = 0; |
|
43 | + $total_tax = 0; |
|
44 | + // This first checks to see if the given ticket is taxable. |
|
45 | + if (! $ticket->taxable()) { |
|
46 | + return $tax; |
|
47 | + } |
|
48 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
49 | + $subtotal = EE_Taxes::get_subtotal_for_admin($ticket); |
|
50 | + // get taxes |
|
51 | + $taxes = EE_Taxes::get_taxes_for_admin(); |
|
52 | + // apply taxes to subtotal |
|
53 | + foreach ($taxes as $tax) { |
|
54 | + // assuming taxes are not cumulative |
|
55 | + $total_tax += $subtotal * $tax->amount() / 100; |
|
56 | + } |
|
57 | + return $total_tax; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
63 | - * |
|
64 | - * @return float the percentage of tax that should be added to taxable items |
|
65 | - * @throws EE_Error |
|
66 | - * @throws ReflectionException |
|
67 | - * eg 20 for %20 tax (NOT 0.20, which |
|
68 | - */ |
|
69 | - public static function get_total_taxes_percentage() |
|
70 | - { |
|
71 | - $total_tax_percent = 0; |
|
72 | - foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) { |
|
73 | - $total_tax_percent += $tax_price->get('PRC_amount'); |
|
74 | - } |
|
75 | - return $total_tax_percent; |
|
76 | - } |
|
61 | + /** |
|
62 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
63 | + * |
|
64 | + * @return float the percentage of tax that should be added to taxable items |
|
65 | + * @throws EE_Error |
|
66 | + * @throws ReflectionException |
|
67 | + * eg 20 for %20 tax (NOT 0.20, which |
|
68 | + */ |
|
69 | + public static function get_total_taxes_percentage() |
|
70 | + { |
|
71 | + $total_tax_percent = 0; |
|
72 | + foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) { |
|
73 | + $total_tax_percent += $tax_price->get('PRC_amount'); |
|
74 | + } |
|
75 | + return $total_tax_percent; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param EE_Ticket $ticket |
|
81 | - * @return float |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
86 | - { |
|
87 | - $TKT_ID = $ticket->ID(); |
|
88 | - return isset(EE_Taxes::$_subtotal[ $TKT_ID ]) |
|
89 | - ? EE_Taxes::$_subtotal[ $TKT_ID ] |
|
90 | - : EE_Taxes::_get_subtotal_for_admin($ticket); |
|
91 | - } |
|
79 | + /** |
|
80 | + * @param EE_Ticket $ticket |
|
81 | + * @return float |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
86 | + { |
|
87 | + $TKT_ID = $ticket->ID(); |
|
88 | + return isset(EE_Taxes::$_subtotal[ $TKT_ID ]) |
|
89 | + ? EE_Taxes::$_subtotal[ $TKT_ID ] |
|
90 | + : EE_Taxes::_get_subtotal_for_admin($ticket); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
96 | - * |
|
97 | - * @param EE_Ticket $ticket |
|
98 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
99 | - * @throws EE_Error |
|
100 | - * @throws ReflectionException |
|
101 | - */ |
|
102 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
103 | - { |
|
104 | - $subtotal = 0; |
|
105 | - // get all prices |
|
106 | - $prices = $ticket->get_many_related( |
|
107 | - 'Price', |
|
108 | - [ |
|
109 | - 0 => [ |
|
110 | - 'Price_Type.PBT_ID' => ['NOT', EEM_Price_Type::base_type_tax], |
|
111 | - ], |
|
112 | - 'default_where_conditions' => 'none', |
|
113 | - 'order_by' => ['PRC_order' => 'ASC'], |
|
114 | - ] |
|
115 | - ); |
|
116 | - // let's loop through them (base price is always the first item) |
|
117 | - foreach ($prices as $price) { |
|
118 | - if ($price instanceof EE_Price) { |
|
119 | - $price_type = $price->type_obj(); |
|
120 | - if ($price_type instanceof EE_Price_Type) { |
|
121 | - switch ($price->type_obj()->base_type()) { |
|
122 | - case 1: // base price |
|
123 | - case 3: // surcharges |
|
124 | - $subtotal += $price->is_percent() |
|
125 | - ? $subtotal * $price->get('PRC_amount') / 100 |
|
126 | - : $price->get('PRC_amount'); |
|
127 | - break; |
|
128 | - case 2: // discounts |
|
129 | - $subtotal -= $price->is_percent() |
|
130 | - ? $subtotal * $price->get('PRC_amount') / 100 |
|
131 | - : $price->get('PRC_amount'); |
|
132 | - break; |
|
133 | - } |
|
134 | - } |
|
135 | - } |
|
136 | - } |
|
137 | - $TKT_ID = $ticket->ID(); |
|
138 | - EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal; |
|
139 | - return $subtotal; |
|
140 | - } |
|
94 | + /** |
|
95 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
96 | + * |
|
97 | + * @param EE_Ticket $ticket |
|
98 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
99 | + * @throws EE_Error |
|
100 | + * @throws ReflectionException |
|
101 | + */ |
|
102 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
103 | + { |
|
104 | + $subtotal = 0; |
|
105 | + // get all prices |
|
106 | + $prices = $ticket->get_many_related( |
|
107 | + 'Price', |
|
108 | + [ |
|
109 | + 0 => [ |
|
110 | + 'Price_Type.PBT_ID' => ['NOT', EEM_Price_Type::base_type_tax], |
|
111 | + ], |
|
112 | + 'default_where_conditions' => 'none', |
|
113 | + 'order_by' => ['PRC_order' => 'ASC'], |
|
114 | + ] |
|
115 | + ); |
|
116 | + // let's loop through them (base price is always the first item) |
|
117 | + foreach ($prices as $price) { |
|
118 | + if ($price instanceof EE_Price) { |
|
119 | + $price_type = $price->type_obj(); |
|
120 | + if ($price_type instanceof EE_Price_Type) { |
|
121 | + switch ($price->type_obj()->base_type()) { |
|
122 | + case 1: // base price |
|
123 | + case 3: // surcharges |
|
124 | + $subtotal += $price->is_percent() |
|
125 | + ? $subtotal * $price->get('PRC_amount') / 100 |
|
126 | + : $price->get('PRC_amount'); |
|
127 | + break; |
|
128 | + case 2: // discounts |
|
129 | + $subtotal -= $price->is_percent() |
|
130 | + ? $subtotal * $price->get('PRC_amount') / 100 |
|
131 | + : $price->get('PRC_amount'); |
|
132 | + break; |
|
133 | + } |
|
134 | + } |
|
135 | + } |
|
136 | + } |
|
137 | + $TKT_ID = $ticket->ID(); |
|
138 | + EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal; |
|
139 | + return $subtotal; |
|
140 | + } |
|
141 | 141 | |
142 | 142 | |
143 | - /** |
|
144 | - * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
145 | - * |
|
146 | - * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
147 | - * @throws EE_Error |
|
148 | - */ |
|
149 | - public static function get_taxes_for_admin() |
|
150 | - { |
|
151 | - if (empty(EE_Taxes::$_default_taxes)) { |
|
152 | - /** @var EEM_Price $price_model */ |
|
153 | - $price_model = LoaderFactory::getLoader()->getShared('EEM_Price'); |
|
154 | - EE_Taxes::$_default_taxes = $price_model->get_all( |
|
155 | - [['Price_Type.PBT_ID' => 4]] |
|
156 | - ); |
|
157 | - } |
|
158 | - return EE_Taxes::$_default_taxes; |
|
159 | - } |
|
143 | + /** |
|
144 | + * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
145 | + * |
|
146 | + * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
147 | + * @throws EE_Error |
|
148 | + */ |
|
149 | + public static function get_taxes_for_admin() |
|
150 | + { |
|
151 | + if (empty(EE_Taxes::$_default_taxes)) { |
|
152 | + /** @var EEM_Price $price_model */ |
|
153 | + $price_model = LoaderFactory::getLoader()->getShared('EEM_Price'); |
|
154 | + EE_Taxes::$_default_taxes = $price_model->get_all( |
|
155 | + [['Price_Type.PBT_ID' => 4]] |
|
156 | + ); |
|
157 | + } |
|
158 | + return EE_Taxes::$_default_taxes; |
|
159 | + } |
|
160 | 160 | } |
@@ -15,2013 +15,2013 @@ |
||
15 | 15 | class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * TicKet Sold out: |
|
20 | - * constant used by ticket_status() to indicate that a ticket is sold out |
|
21 | - * and no longer available for purchases |
|
22 | - */ |
|
23 | - const sold_out = 'TKS'; |
|
24 | - |
|
25 | - /** |
|
26 | - * TicKet Expired: |
|
27 | - * constant used by ticket_status() to indicate that a ticket is expired |
|
28 | - * and no longer available for purchase |
|
29 | - */ |
|
30 | - const expired = 'TKE'; |
|
31 | - |
|
32 | - /** |
|
33 | - * TicKet Archived: |
|
34 | - * constant used by ticket_status() to indicate that a ticket is archived |
|
35 | - * and no longer available for purchase |
|
36 | - */ |
|
37 | - const archived = 'TKA'; |
|
38 | - |
|
39 | - /** |
|
40 | - * TicKet Pending: |
|
41 | - * constant used by ticket_status() to indicate that a ticket is pending |
|
42 | - * and is NOT YET available for purchase |
|
43 | - */ |
|
44 | - const pending = 'TKP'; |
|
45 | - |
|
46 | - /** |
|
47 | - * TicKet On sale: |
|
48 | - * constant used by ticket_status() to indicate that a ticket is On Sale |
|
49 | - * and IS available for purchase |
|
50 | - */ |
|
51 | - const onsale = 'TKO'; |
|
52 | - |
|
53 | - /** |
|
54 | - * extra meta key for tracking ticket reservations |
|
55 | - * |
|
56 | - * @type string |
|
57 | - */ |
|
58 | - const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
59 | - |
|
60 | - /** |
|
61 | - * override of parent property |
|
62 | - * |
|
63 | - * @var EEM_Ticket |
|
64 | - */ |
|
65 | - protected $_model; |
|
66 | - |
|
67 | - /** |
|
68 | - * cached result from method of the same name |
|
69 | - * |
|
70 | - * @var float $_ticket_total_with_taxes |
|
71 | - */ |
|
72 | - private $_ticket_total_with_taxes; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @param array $props_n_values incoming values |
|
77 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
78 | - * used.) |
|
79 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
80 | - * date_format and the second value is the time format |
|
81 | - * @return EE_Ticket |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
86 | - { |
|
87 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
88 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param array $props_n_values incoming values from the database |
|
94 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
95 | - * the website will be used. |
|
96 | - * @return EE_Ticket |
|
97 | - * @throws EE_Error |
|
98 | - * @throws ReflectionException |
|
99 | - */ |
|
100 | - public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
101 | - { |
|
102 | - return new self($props_n_values, true, $timezone); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return bool |
|
108 | - * @throws EE_Error |
|
109 | - * @throws ReflectionException |
|
110 | - */ |
|
111 | - public function parent() |
|
112 | - { |
|
113 | - return $this->get('TKT_parent'); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * return if a ticket has quantities available for purchase |
|
119 | - * |
|
120 | - * @param int $DTT_ID the primary key for a particular datetime |
|
121 | - * @return boolean |
|
122 | - * @throws EE_Error |
|
123 | - * @throws ReflectionException |
|
124 | - */ |
|
125 | - public function available($DTT_ID = 0) |
|
126 | - { |
|
127 | - // are we checking availability for a particular datetime ? |
|
128 | - if ($DTT_ID) { |
|
129 | - // get that datetime object |
|
130 | - $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]); |
|
131 | - // if ticket sales for this datetime have exceeded the reg limit... |
|
132 | - if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
133 | - return false; |
|
134 | - } |
|
135 | - } |
|
136 | - // datetime is still open for registration, but is this ticket sold out ? |
|
137 | - return $this->qty() < 1 || $this->qty() > $this->sold(); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
143 | - * |
|
144 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
145 | - * relevant status const |
|
146 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
147 | - * further processing |
|
148 | - * @return mixed status int if the display string isn't requested |
|
149 | - * @throws EE_Error |
|
150 | - * @throws ReflectionException |
|
151 | - */ |
|
152 | - public function ticket_status($display = false, $remaining = null) |
|
153 | - { |
|
154 | - $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
155 | - if (! $remaining) { |
|
156 | - return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
157 | - } |
|
158 | - if ($this->get('TKT_deleted')) { |
|
159 | - return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
160 | - } |
|
161 | - if ($this->is_expired()) { |
|
162 | - return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
163 | - } |
|
164 | - if ($this->is_pending()) { |
|
165 | - return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
166 | - } |
|
167 | - if ($this->is_on_sale()) { |
|
168 | - return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
169 | - } |
|
170 | - return ''; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
176 | - * considering ALL the factors used for figuring that out. |
|
177 | - * |
|
178 | - * @access public |
|
179 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
180 | - * @return boolean true = tickets remaining, false not. |
|
181 | - * @throws EE_Error |
|
182 | - * @throws ReflectionException |
|
183 | - */ |
|
184 | - public function is_remaining($DTT_ID = 0) |
|
185 | - { |
|
186 | - $num_remaining = $this->remaining($DTT_ID); |
|
187 | - if ($num_remaining === 0) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
191 | - return false; |
|
192 | - } |
|
193 | - return true; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * return the total number of tickets available for purchase |
|
199 | - * |
|
200 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
201 | - * set to 0 for all related datetimes |
|
202 | - * @return int |
|
203 | - * @throws EE_Error |
|
204 | - * @throws ReflectionException |
|
205 | - */ |
|
206 | - public function remaining($DTT_ID = 0) |
|
207 | - { |
|
208 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Gets min |
|
214 | - * |
|
215 | - * @return int |
|
216 | - * @throws EE_Error |
|
217 | - * @throws ReflectionException |
|
218 | - */ |
|
219 | - public function min() |
|
220 | - { |
|
221 | - return $this->get('TKT_min'); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * return if a ticket is no longer available cause its available dates have expired. |
|
227 | - * |
|
228 | - * @return boolean |
|
229 | - * @throws EE_Error |
|
230 | - * @throws ReflectionException |
|
231 | - */ |
|
232 | - public function is_expired() |
|
233 | - { |
|
234 | - return ($this->get_raw('TKT_end_date') < time()); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Return if a ticket is yet to go on sale or not |
|
240 | - * |
|
241 | - * @return boolean |
|
242 | - * @throws EE_Error |
|
243 | - * @throws ReflectionException |
|
244 | - */ |
|
245 | - public function is_pending() |
|
246 | - { |
|
247 | - return ($this->get_raw('TKT_start_date') >= time()); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Return if a ticket is on sale or not |
|
253 | - * |
|
254 | - * @return boolean |
|
255 | - * @throws EE_Error |
|
256 | - * @throws ReflectionException |
|
257 | - */ |
|
258 | - public function is_on_sale() |
|
259 | - { |
|
260 | - return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time()); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * This returns the chronologically last datetime that this ticket is associated with |
|
266 | - * |
|
267 | - * @param string $date_format |
|
268 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
269 | - * the end date ie: Jan 01 "to" Dec 31 |
|
270 | - * @return string |
|
271 | - * @throws EE_Error |
|
272 | - * @throws ReflectionException |
|
273 | - */ |
|
274 | - public function date_range($date_format = '', $conjunction = ' - ') |
|
275 | - { |
|
276 | - $date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt; |
|
277 | - $first_date = $this->first_datetime() instanceof EE_Datetime |
|
278 | - ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format) |
|
279 | - : ''; |
|
280 | - $last_date = $this->last_datetime() instanceof EE_Datetime |
|
281 | - ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format) |
|
282 | - : ''; |
|
283 | - |
|
284 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * This returns the chronologically first datetime that this ticket is associated with |
|
290 | - * |
|
291 | - * @return EE_Datetime |
|
292 | - * @throws EE_Error |
|
293 | - * @throws ReflectionException |
|
294 | - */ |
|
295 | - public function first_datetime() |
|
296 | - { |
|
297 | - $datetimes = $this->datetimes(['limit' => 1]); |
|
298 | - return reset($datetimes); |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * Gets all the datetimes this ticket can be used for attending. |
|
304 | - * Unless otherwise specified, orders datetimes by start date. |
|
305 | - * |
|
306 | - * @param array $query_params @see |
|
307 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
308 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
309 | - * @throws EE_Error |
|
310 | - * @throws ReflectionException |
|
311 | - */ |
|
312 | - public function datetimes($query_params = []) |
|
313 | - { |
|
314 | - if (! isset($query_params['order_by'])) { |
|
315 | - $query_params['order_by']['DTT_order'] = 'ASC'; |
|
316 | - } |
|
317 | - return $this->get_many_related('Datetime', $query_params); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * This returns the chronologically last datetime that this ticket is associated with |
|
323 | - * |
|
324 | - * @return EE_Datetime |
|
325 | - * @throws EE_Error |
|
326 | - * @throws ReflectionException |
|
327 | - */ |
|
328 | - public function last_datetime() |
|
329 | - { |
|
330 | - $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]); |
|
331 | - return end($datetimes); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * This returns the total tickets sold depending on the given parameters. |
|
337 | - * |
|
338 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
339 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
340 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
341 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
342 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
343 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
344 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
345 | - * @return mixed (array|int) how many tickets have sold |
|
346 | - * @throws EE_Error |
|
347 | - * @throws ReflectionException |
|
348 | - */ |
|
349 | - public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
350 | - { |
|
351 | - $total = 0; |
|
352 | - $tickets_sold = $this->_all_tickets_sold(); |
|
353 | - switch ($what) { |
|
354 | - case 'ticket': |
|
355 | - return $tickets_sold['ticket']; |
|
356 | - break; |
|
357 | - case 'datetime': |
|
358 | - if (empty($tickets_sold['datetime'])) { |
|
359 | - return $total; |
|
360 | - } |
|
361 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
362 | - EE_Error::add_error( |
|
363 | - __( |
|
364 | - 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
365 | - 'event_espresso' |
|
366 | - ), |
|
367 | - __FILE__, |
|
368 | - __FUNCTION__, |
|
369 | - __LINE__ |
|
370 | - ); |
|
371 | - return $total; |
|
372 | - } |
|
373 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
374 | - break; |
|
375 | - default: |
|
376 | - return $total; |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
383 | - * |
|
384 | - * @return EE_Ticket[] |
|
385 | - * @throws EE_Error |
|
386 | - * @throws ReflectionException |
|
387 | - */ |
|
388 | - protected function _all_tickets_sold() |
|
389 | - { |
|
390 | - $datetimes = $this->get_many_related('Datetime'); |
|
391 | - $tickets_sold = []; |
|
392 | - if (! empty($datetimes)) { |
|
393 | - foreach ($datetimes as $datetime) { |
|
394 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
395 | - } |
|
396 | - } |
|
397 | - // Tickets sold |
|
398 | - $tickets_sold['ticket'] = $this->sold(); |
|
399 | - return $tickets_sold; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * This returns the base price object for the ticket. |
|
405 | - * |
|
406 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
407 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
408 | - * @throws EE_Error |
|
409 | - * @throws ReflectionException |
|
410 | - */ |
|
411 | - public function base_price($return_array = false) |
|
412 | - { |
|
413 | - $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price]; |
|
414 | - return $return_array |
|
415 | - ? $this->get_many_related('Price', [$_where]) |
|
416 | - : $this->get_first_related('Price', [$_where]); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
422 | - * |
|
423 | - * @access public |
|
424 | - * @return EE_Price[] |
|
425 | - * @throws EE_Error |
|
426 | - * @throws ReflectionException |
|
427 | - */ |
|
428 | - public function price_modifiers() |
|
429 | - { |
|
430 | - $query_params = [ |
|
431 | - 0 => [ |
|
432 | - 'Price_Type.PBT_ID' => [ |
|
433 | - 'NOT IN', |
|
434 | - [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax], |
|
435 | - ], |
|
436 | - ], |
|
437 | - ]; |
|
438 | - return $this->prices($query_params); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
444 | - * |
|
445 | - * @access public |
|
446 | - * @return EE_Price[] |
|
447 | - * @throws EE_Error |
|
448 | - * @throws ReflectionException |
|
449 | - */ |
|
450 | - public function tax_price_modifiers() |
|
451 | - { |
|
452 | - $query_params = [ |
|
453 | - 0 => [ |
|
454 | - 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, |
|
455 | - ], |
|
456 | - ]; |
|
457 | - return $this->prices($query_params); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * Gets all the prices that combine to form the final price of this ticket |
|
463 | - * |
|
464 | - * @param array $query_params @see |
|
465 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
466 | - * @return EE_Price[]|EE_Base_Class[] |
|
467 | - * @throws EE_Error |
|
468 | - * @throws ReflectionException |
|
469 | - */ |
|
470 | - public function prices($query_params = []) |
|
471 | - { |
|
472 | - return $this->get_many_related('Price', $query_params); |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Gets all the ticket datetimes (ie, relations between datetimes and tickets) |
|
478 | - * |
|
479 | - * @param array $query_params @see |
|
480 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
481 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
482 | - * @throws EE_Error |
|
483 | - * @throws ReflectionException |
|
484 | - */ |
|
485 | - public function datetime_tickets($query_params = []) |
|
486 | - { |
|
487 | - return $this->get_many_related('Datetime_Ticket', $query_params); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Gets all the datetimes from the db ordered by DTT_order |
|
493 | - * |
|
494 | - * @param boolean $show_expired |
|
495 | - * @param boolean $show_deleted |
|
496 | - * @return EE_Datetime[] |
|
497 | - * @throws EE_Error |
|
498 | - * @throws ReflectionException |
|
499 | - */ |
|
500 | - public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
501 | - { |
|
502 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
503 | - $this->ID(), |
|
504 | - $show_expired, |
|
505 | - $show_deleted |
|
506 | - ); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * Gets ID |
|
512 | - * |
|
513 | - * @return int |
|
514 | - * @throws EE_Error |
|
515 | - * @throws ReflectionException |
|
516 | - */ |
|
517 | - public function ID() |
|
518 | - { |
|
519 | - return $this->get('TKT_ID'); |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * get the author of the ticket. |
|
525 | - * |
|
526 | - * @return int |
|
527 | - * @throws EE_Error |
|
528 | - * @throws ReflectionException |
|
529 | - * @since 4.5.0 |
|
530 | - */ |
|
531 | - public function wp_user() |
|
532 | - { |
|
533 | - return $this->get('TKT_wp_user'); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Gets the template for the ticket |
|
539 | - * |
|
540 | - * @return EE_Ticket_Template|EE_Base_Class |
|
541 | - * @throws EE_Error |
|
542 | - * @throws ReflectionException |
|
543 | - */ |
|
544 | - public function template() |
|
545 | - { |
|
546 | - return $this->get_first_related('Ticket_Template'); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * Simply returns an array of EE_Price objects that are taxes. |
|
552 | - * |
|
553 | - * @return EE_Price[] |
|
554 | - * @throws EE_Error |
|
555 | - * @throws ReflectionException |
|
556 | - */ |
|
557 | - public function get_ticket_taxes_for_admin(): array |
|
558 | - { |
|
559 | - /** @var EE_Admin_Config $admin_config */ |
|
560 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
561 | - return $admin_config->useAdvancedEditor() ? $this->tax_price_modifiers() : EE_Taxes::get_taxes_for_admin(); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * @return float |
|
567 | - * @throws EE_Error |
|
568 | - * @throws ReflectionException |
|
569 | - */ |
|
570 | - public function ticket_price() |
|
571 | - { |
|
572 | - return $this->get('TKT_price'); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * @return mixed |
|
578 | - * @throws EE_Error |
|
579 | - * @throws ReflectionException |
|
580 | - */ |
|
581 | - public function pretty_price() |
|
582 | - { |
|
583 | - return $this->get_pretty('TKT_price'); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * @return bool |
|
589 | - * @throws EE_Error |
|
590 | - * @throws ReflectionException |
|
591 | - */ |
|
592 | - public function is_free() |
|
593 | - { |
|
594 | - return $this->get_ticket_total_with_taxes() === (float) 0; |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * get_ticket_total_with_taxes |
|
600 | - * |
|
601 | - * @param bool $no_cache |
|
602 | - * @return float |
|
603 | - * @throws EE_Error |
|
604 | - * @throws ReflectionException |
|
605 | - */ |
|
606 | - public function get_ticket_total_with_taxes($no_cache = false) |
|
607 | - { |
|
608 | - if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
609 | - /** @var EE_Admin_Config $admin_config */ |
|
610 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
611 | - $this->_ticket_total_with_taxes = $admin_config->useAdvancedEditor() |
|
612 | - ? $this->ticket_price() |
|
613 | - : $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
614 | - } |
|
615 | - return (float) $this->_ticket_total_with_taxes; |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * @throws EE_Error |
|
621 | - * @throws ReflectionException |
|
622 | - */ |
|
623 | - public function ensure_TKT_Price_correct() |
|
624 | - { |
|
625 | - $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
626 | - $this->save(); |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - /** |
|
631 | - * @return float |
|
632 | - * @throws EE_Error |
|
633 | - * @throws ReflectionException |
|
634 | - */ |
|
635 | - public function get_ticket_subtotal() |
|
636 | - { |
|
637 | - return EE_Taxes::get_subtotal_for_admin($this); |
|
638 | - } |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * Returns the total taxes applied to this ticket |
|
643 | - * |
|
644 | - * @return float |
|
645 | - * @throws EE_Error |
|
646 | - * @throws ReflectionException |
|
647 | - */ |
|
648 | - public function get_ticket_taxes_total_for_admin() |
|
649 | - { |
|
650 | - return EE_Taxes::get_total_taxes_for_admin($this); |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - /** |
|
655 | - * Sets name |
|
656 | - * |
|
657 | - * @param string $name |
|
658 | - * @throws EE_Error |
|
659 | - * @throws ReflectionException |
|
660 | - */ |
|
661 | - public function set_name($name) |
|
662 | - { |
|
663 | - $this->set('TKT_name', $name); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * Gets description |
|
669 | - * |
|
670 | - * @return string |
|
671 | - * @throws EE_Error |
|
672 | - * @throws ReflectionException |
|
673 | - */ |
|
674 | - public function description() |
|
675 | - { |
|
676 | - return $this->get('TKT_description'); |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * Sets description |
|
682 | - * |
|
683 | - * @param string $description |
|
684 | - * @throws EE_Error |
|
685 | - * @throws ReflectionException |
|
686 | - */ |
|
687 | - public function set_description($description) |
|
688 | - { |
|
689 | - $this->set('TKT_description', $description); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Gets start_date |
|
695 | - * |
|
696 | - * @param string $date_format |
|
697 | - * @param string $time_format |
|
698 | - * @return string |
|
699 | - * @throws EE_Error |
|
700 | - * @throws ReflectionException |
|
701 | - */ |
|
702 | - public function start_date($date_format = '', $time_format = '') |
|
703 | - { |
|
704 | - return $this->_get_datetime('TKT_start_date', $date_format, $time_format); |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * Sets start_date |
|
710 | - * |
|
711 | - * @param string $start_date |
|
712 | - * @return void |
|
713 | - * @throws EE_Error |
|
714 | - * @throws ReflectionException |
|
715 | - */ |
|
716 | - public function set_start_date($start_date) |
|
717 | - { |
|
718 | - $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * Gets end_date |
|
724 | - * |
|
725 | - * @param string $date_format |
|
726 | - * @param string $time_format |
|
727 | - * @return string |
|
728 | - * @throws EE_Error |
|
729 | - * @throws ReflectionException |
|
730 | - */ |
|
731 | - public function end_date($date_format = '', $time_format = '') |
|
732 | - { |
|
733 | - return $this->_get_datetime('TKT_end_date', $date_format, $time_format); |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * Sets end_date |
|
739 | - * |
|
740 | - * @param string $end_date |
|
741 | - * @return void |
|
742 | - * @throws EE_Error |
|
743 | - * @throws ReflectionException |
|
744 | - */ |
|
745 | - public function set_end_date($end_date) |
|
746 | - { |
|
747 | - $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
748 | - } |
|
749 | - |
|
750 | - |
|
751 | - /** |
|
752 | - * Sets sell until time |
|
753 | - * |
|
754 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
755 | - * @throws EE_Error |
|
756 | - * @throws ReflectionException |
|
757 | - * @since 4.5.0 |
|
758 | - */ |
|
759 | - public function set_end_time($time) |
|
760 | - { |
|
761 | - $this->_set_time_for($time, 'TKT_end_date'); |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - /** |
|
766 | - * Sets min |
|
767 | - * |
|
768 | - * @param int $min |
|
769 | - * @return void |
|
770 | - * @throws EE_Error |
|
771 | - * @throws ReflectionException |
|
772 | - */ |
|
773 | - public function set_min($min) |
|
774 | - { |
|
775 | - $this->set('TKT_min', $min); |
|
776 | - } |
|
777 | - |
|
778 | - |
|
779 | - /** |
|
780 | - * Gets max |
|
781 | - * |
|
782 | - * @return int |
|
783 | - * @throws EE_Error |
|
784 | - * @throws ReflectionException |
|
785 | - */ |
|
786 | - public function max() |
|
787 | - { |
|
788 | - return $this->get('TKT_max'); |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - /** |
|
793 | - * Sets max |
|
794 | - * |
|
795 | - * @param int $max |
|
796 | - * @return void |
|
797 | - * @throws EE_Error |
|
798 | - * @throws ReflectionException |
|
799 | - */ |
|
800 | - public function set_max($max) |
|
801 | - { |
|
802 | - $this->set('TKT_max', $max); |
|
803 | - } |
|
804 | - |
|
805 | - |
|
806 | - /** |
|
807 | - * Sets price |
|
808 | - * |
|
809 | - * @param float $price |
|
810 | - * @return void |
|
811 | - * @throws EE_Error |
|
812 | - * @throws ReflectionException |
|
813 | - */ |
|
814 | - public function set_price($price) |
|
815 | - { |
|
816 | - $this->set('TKT_price', $price); |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * Gets sold |
|
822 | - * |
|
823 | - * @return int |
|
824 | - * @throws EE_Error |
|
825 | - * @throws ReflectionException |
|
826 | - */ |
|
827 | - public function sold() |
|
828 | - { |
|
829 | - return $this->get_raw('TKT_sold'); |
|
830 | - } |
|
831 | - |
|
832 | - |
|
833 | - /** |
|
834 | - * Sets sold |
|
835 | - * |
|
836 | - * @param int $sold |
|
837 | - * @return void |
|
838 | - * @throws EE_Error |
|
839 | - * @throws ReflectionException |
|
840 | - */ |
|
841 | - public function set_sold($sold) |
|
842 | - { |
|
843 | - // sold can not go below zero |
|
844 | - $sold = max(0, $sold); |
|
845 | - $this->set('TKT_sold', $sold); |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - /** |
|
850 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
851 | - * associated datetimes. |
|
852 | - * |
|
853 | - * @param int $qty |
|
854 | - * @return boolean |
|
855 | - * @throws EE_Error |
|
856 | - * @throws InvalidArgumentException |
|
857 | - * @throws InvalidDataTypeException |
|
858 | - * @throws InvalidInterfaceException |
|
859 | - * @throws ReflectionException |
|
860 | - * @since 4.9.80.p |
|
861 | - */ |
|
862 | - public function increaseSold($qty = 1) |
|
863 | - { |
|
864 | - $qty = absint($qty); |
|
865 | - // increment sold and decrement reserved datetime quantities simultaneously |
|
866 | - // don't worry about failures, because they must have already had a spot reserved |
|
867 | - $this->increaseSoldForDatetimes($qty); |
|
868 | - // Increment and decrement ticket quantities simultaneously |
|
869 | - $success = $this->adjustNumericFieldsInDb( |
|
870 | - [ |
|
871 | - 'TKT_reserved' => $qty * -1, |
|
872 | - 'TKT_sold' => $qty, |
|
873 | - ] |
|
874 | - ); |
|
875 | - do_action( |
|
876 | - 'AHEE__EE_Ticket__increase_sold', |
|
877 | - $this, |
|
878 | - $qty, |
|
879 | - $this->sold(), |
|
880 | - $success |
|
881 | - ); |
|
882 | - return $success; |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - /** |
|
887 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
888 | - * |
|
889 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
|
890 | - * counts), Negative means to decreases old counts (and increase reserved counts). |
|
891 | - * @param EE_Datetime[] $datetimes |
|
892 | - * @throws EE_Error |
|
893 | - * @throws InvalidArgumentException |
|
894 | - * @throws InvalidDataTypeException |
|
895 | - * @throws InvalidInterfaceException |
|
896 | - * @throws ReflectionException |
|
897 | - * @since 4.9.80.p |
|
898 | - */ |
|
899 | - protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
900 | - { |
|
901 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
902 | - foreach ($datetimes as $datetime) { |
|
903 | - $datetime->increaseSold($qty); |
|
904 | - } |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - /** |
|
909 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
910 | - * DB and then updates the model objects. |
|
911 | - * Does not affect the reserved counts. |
|
912 | - * |
|
913 | - * @param int $qty |
|
914 | - * @return boolean |
|
915 | - * @throws EE_Error |
|
916 | - * @throws InvalidArgumentException |
|
917 | - * @throws InvalidDataTypeException |
|
918 | - * @throws InvalidInterfaceException |
|
919 | - * @throws ReflectionException |
|
920 | - * @since 4.9.80.p |
|
921 | - */ |
|
922 | - public function decreaseSold($qty = 1) |
|
923 | - { |
|
924 | - $qty = absint($qty); |
|
925 | - $this->decreaseSoldForDatetimes($qty); |
|
926 | - $success = $this->adjustNumericFieldsInDb( |
|
927 | - [ |
|
928 | - 'TKT_sold' => $qty * -1, |
|
929 | - ] |
|
930 | - ); |
|
931 | - do_action( |
|
932 | - 'AHEE__EE_Ticket__decrease_sold', |
|
933 | - $this, |
|
934 | - $qty, |
|
935 | - $this->sold(), |
|
936 | - $success |
|
937 | - ); |
|
938 | - return $success; |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * Decreases sold on related datetimes |
|
944 | - * |
|
945 | - * @param int $qty |
|
946 | - * @param EE_Datetime[] $datetimes |
|
947 | - * @return void |
|
948 | - * @throws EE_Error |
|
949 | - * @throws InvalidArgumentException |
|
950 | - * @throws InvalidDataTypeException |
|
951 | - * @throws InvalidInterfaceException |
|
952 | - * @throws ReflectionException |
|
953 | - * @since 4.9.80.p |
|
954 | - */ |
|
955 | - protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
956 | - { |
|
957 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
958 | - if (is_array($datetimes)) { |
|
959 | - foreach ($datetimes as $datetime) { |
|
960 | - if ($datetime instanceof EE_Datetime) { |
|
961 | - $datetime->decreaseSold($qty); |
|
962 | - } |
|
963 | - } |
|
964 | - } |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - /** |
|
969 | - * Gets qty of reserved tickets |
|
970 | - * |
|
971 | - * @return int |
|
972 | - * @throws EE_Error |
|
973 | - * @throws ReflectionException |
|
974 | - */ |
|
975 | - public function reserved() |
|
976 | - { |
|
977 | - return $this->get_raw('TKT_reserved'); |
|
978 | - } |
|
979 | - |
|
980 | - |
|
981 | - /** |
|
982 | - * Sets reserved |
|
983 | - * |
|
984 | - * @param int $reserved |
|
985 | - * @return void |
|
986 | - * @throws EE_Error |
|
987 | - * @throws ReflectionException |
|
988 | - */ |
|
989 | - public function set_reserved($reserved) |
|
990 | - { |
|
991 | - // reserved can not go below zero |
|
992 | - $reserved = max(0, (int) $reserved); |
|
993 | - $this->set('TKT_reserved', $reserved); |
|
994 | - } |
|
995 | - |
|
996 | - |
|
997 | - /** |
|
998 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
999 | - * |
|
1000 | - * @param int $qty |
|
1001 | - * @param string $source |
|
1002 | - * @return bool whether we successfully reserved the ticket or not. |
|
1003 | - * @throws EE_Error |
|
1004 | - * @throws InvalidArgumentException |
|
1005 | - * @throws ReflectionException |
|
1006 | - * @throws InvalidDataTypeException |
|
1007 | - * @throws InvalidInterfaceException |
|
1008 | - * @since 4.9.80.p |
|
1009 | - */ |
|
1010 | - public function increaseReserved($qty = 1, $source = 'unknown') |
|
1011 | - { |
|
1012 | - $qty = absint($qty); |
|
1013 | - do_action( |
|
1014 | - 'AHEE__EE_Ticket__increase_reserved__begin', |
|
1015 | - $this, |
|
1016 | - $qty, |
|
1017 | - $source |
|
1018 | - ); |
|
1019 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
1020 | - $success = false; |
|
1021 | - $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
1022 | - if ($datetimes_adjusted_successfully) { |
|
1023 | - $success = $this->incrementFieldConditionallyInDb( |
|
1024 | - 'TKT_reserved', |
|
1025 | - 'TKT_sold', |
|
1026 | - 'TKT_qty', |
|
1027 | - $qty |
|
1028 | - ); |
|
1029 | - if (! $success) { |
|
1030 | - // The datetimes were successfully bumped, but not the |
|
1031 | - // ticket. So we need to manually rollback the datetimes. |
|
1032 | - $this->decreaseReservedForDatetimes($qty); |
|
1033 | - } |
|
1034 | - } |
|
1035 | - do_action( |
|
1036 | - 'AHEE__EE_Ticket__increase_reserved', |
|
1037 | - $this, |
|
1038 | - $qty, |
|
1039 | - $this->reserved(), |
|
1040 | - $success |
|
1041 | - ); |
|
1042 | - return $success; |
|
1043 | - } |
|
1044 | - |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * Increases reserved counts on related datetimes |
|
1048 | - * |
|
1049 | - * @param int $qty |
|
1050 | - * @param EE_Datetime[] $datetimes |
|
1051 | - * @return boolean indicating success |
|
1052 | - * @throws EE_Error |
|
1053 | - * @throws InvalidArgumentException |
|
1054 | - * @throws InvalidDataTypeException |
|
1055 | - * @throws InvalidInterfaceException |
|
1056 | - * @throws ReflectionException |
|
1057 | - * @since 4.9.80.p |
|
1058 | - */ |
|
1059 | - protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
1060 | - { |
|
1061 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
1062 | - $datetimes_updated = []; |
|
1063 | - $limit_exceeded = false; |
|
1064 | - if (is_array($datetimes)) { |
|
1065 | - foreach ($datetimes as $datetime) { |
|
1066 | - if ($datetime instanceof EE_Datetime) { |
|
1067 | - if ($datetime->increaseReserved($qty)) { |
|
1068 | - $datetimes_updated[] = $datetime; |
|
1069 | - } else { |
|
1070 | - $limit_exceeded = true; |
|
1071 | - break; |
|
1072 | - } |
|
1073 | - } |
|
1074 | - } |
|
1075 | - // If somewhere along the way we detected a datetime whose |
|
1076 | - // limit was exceeded, do a manual rollback. |
|
1077 | - if ($limit_exceeded) { |
|
1078 | - $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
1079 | - return false; |
|
1080 | - } |
|
1081 | - } |
|
1082 | - return true; |
|
1083 | - } |
|
1084 | - |
|
1085 | - |
|
1086 | - /** |
|
1087 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
1088 | - * |
|
1089 | - * @param int $qty |
|
1090 | - * @param bool $adjust_datetimes |
|
1091 | - * @param string $source |
|
1092 | - * @return boolean |
|
1093 | - * @throws EE_Error |
|
1094 | - * @throws InvalidArgumentException |
|
1095 | - * @throws ReflectionException |
|
1096 | - * @throws InvalidDataTypeException |
|
1097 | - * @throws InvalidInterfaceException |
|
1098 | - * @since 4.9.80.p |
|
1099 | - */ |
|
1100 | - public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
1101 | - { |
|
1102 | - $qty = absint($qty); |
|
1103 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
1104 | - if ($adjust_datetimes) { |
|
1105 | - $this->decreaseReservedForDatetimes($qty); |
|
1106 | - } |
|
1107 | - $success = $this->adjustNumericFieldsInDb( |
|
1108 | - [ |
|
1109 | - 'TKT_reserved' => $qty * -1, |
|
1110 | - ] |
|
1111 | - ); |
|
1112 | - do_action( |
|
1113 | - 'AHEE__EE_Ticket__decrease_reserved', |
|
1114 | - $this, |
|
1115 | - $qty, |
|
1116 | - $this->reserved(), |
|
1117 | - $success |
|
1118 | - ); |
|
1119 | - return $success; |
|
1120 | - } |
|
1121 | - |
|
1122 | - |
|
1123 | - /** |
|
1124 | - * Decreases the reserved count on the specified datetimes. |
|
1125 | - * |
|
1126 | - * @param int $qty |
|
1127 | - * @param EE_Datetime[] $datetimes |
|
1128 | - * @throws EE_Error |
|
1129 | - * @throws InvalidArgumentException |
|
1130 | - * @throws ReflectionException |
|
1131 | - * @throws InvalidDataTypeException |
|
1132 | - * @throws InvalidInterfaceException |
|
1133 | - * @since 4.9.80.p |
|
1134 | - */ |
|
1135 | - protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
1136 | - { |
|
1137 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
1138 | - foreach ($datetimes as $datetime) { |
|
1139 | - if ($datetime instanceof EE_Datetime) { |
|
1140 | - $datetime->decreaseReserved($qty); |
|
1141 | - } |
|
1142 | - } |
|
1143 | - } |
|
1144 | - |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * Gets ticket quantity |
|
1148 | - * |
|
1149 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
1150 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
1151 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
1152 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
1153 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
1154 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
1155 | - * @return int |
|
1156 | - * @throws EE_Error |
|
1157 | - * @throws ReflectionException |
|
1158 | - */ |
|
1159 | - public function qty($context = '') |
|
1160 | - { |
|
1161 | - switch ($context) { |
|
1162 | - case 'reg_limit': |
|
1163 | - return $this->real_quantity_on_ticket(); |
|
1164 | - case 'saleable': |
|
1165 | - return $this->real_quantity_on_ticket('saleable'); |
|
1166 | - default: |
|
1167 | - return $this->get_raw('TKT_qty'); |
|
1168 | - } |
|
1169 | - } |
|
1170 | - |
|
1171 | - |
|
1172 | - /** |
|
1173 | - * Gets ticket quantity |
|
1174 | - * |
|
1175 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
1176 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
1177 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
1178 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
1179 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
1180 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
1181 | - * set to 0 for all related datetimes |
|
1182 | - * @return int |
|
1183 | - * @throws EE_Error |
|
1184 | - * @throws ReflectionException |
|
1185 | - */ |
|
1186 | - public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
1187 | - { |
|
1188 | - $raw = $this->get_raw('TKT_qty'); |
|
1189 | - // return immediately if it's zero |
|
1190 | - if ($raw === 0) { |
|
1191 | - return $raw; |
|
1192 | - } |
|
1193 | - // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
1194 | - // ensure qty doesn't exceed raw value for THIS ticket |
|
1195 | - $qty = min(EE_INF, $raw); |
|
1196 | - // echo "\n . qty: " . $qty . '<br />'; |
|
1197 | - // calculate this ticket's total sales and reservations |
|
1198 | - $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
1199 | - // echo "\n . sold: " . $this->sold() . '<br />'; |
|
1200 | - // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
1201 | - // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
1202 | - // first we need to calculate the maximum number of tickets available for the datetime |
|
1203 | - // do we want data for one datetime or all of them ? |
|
1204 | - $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : []; |
|
1205 | - $datetimes = $this->datetimes($query_params); |
|
1206 | - if (is_array($datetimes) && ! empty($datetimes)) { |
|
1207 | - foreach ($datetimes as $datetime) { |
|
1208 | - if ($datetime instanceof EE_Datetime) { |
|
1209 | - $datetime->refresh_from_db(); |
|
1210 | - // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
1211 | - // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
1212 | - // initialize with no restrictions for each datetime |
|
1213 | - // but adjust datetime qty based on datetime reg limit |
|
1214 | - $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
1215 | - // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
1216 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1217 | - // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
1218 | - // and reservations for this datetime, that do NOT include sales and reservations |
|
1219 | - // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
1220 | - if ($context === 'saleable') { |
|
1221 | - $datetime_qty = max( |
|
1222 | - $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
1223 | - 0 |
|
1224 | - ); |
|
1225 | - // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
1226 | - // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
1227 | - // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
1228 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1229 | - $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
1230 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1231 | - } |
|
1232 | - $qty = min($datetime_qty, $qty); |
|
1233 | - // echo "\n . . qty: " . $qty . '<br />'; |
|
1234 | - } |
|
1235 | - } |
|
1236 | - } |
|
1237 | - // NOW that we know the maximum number of tickets available for the datetime |
|
1238 | - // we can finally factor in the details for this specific ticket |
|
1239 | - if ($qty > 0 && $context === 'saleable') { |
|
1240 | - // and subtract the sales for THIS ticket |
|
1241 | - $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
1242 | - // echo "\n . qty: " . $qty . '<br />'; |
|
1243 | - } |
|
1244 | - // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
1245 | - return $qty; |
|
1246 | - } |
|
1247 | - |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
1251 | - * |
|
1252 | - * @param int $qty |
|
1253 | - * @return void |
|
1254 | - * @throws EE_Error |
|
1255 | - * @throws ReflectionException |
|
1256 | - */ |
|
1257 | - public function set_qty($qty) |
|
1258 | - { |
|
1259 | - $datetimes = $this->datetimes(); |
|
1260 | - foreach ($datetimes as $datetime) { |
|
1261 | - if ($datetime instanceof EE_Datetime) { |
|
1262 | - $qty = min($qty, $datetime->reg_limit()); |
|
1263 | - } |
|
1264 | - } |
|
1265 | - $this->set('TKT_qty', $qty); |
|
1266 | - } |
|
1267 | - |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Gets uses |
|
1271 | - * |
|
1272 | - * @return int |
|
1273 | - * @throws EE_Error |
|
1274 | - * @throws ReflectionException |
|
1275 | - */ |
|
1276 | - public function uses() |
|
1277 | - { |
|
1278 | - return $this->get('TKT_uses'); |
|
1279 | - } |
|
1280 | - |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * Sets uses |
|
1284 | - * |
|
1285 | - * @param int $uses |
|
1286 | - * @return void |
|
1287 | - * @throws EE_Error |
|
1288 | - * @throws ReflectionException |
|
1289 | - */ |
|
1290 | - public function set_uses($uses) |
|
1291 | - { |
|
1292 | - $this->set('TKT_uses', $uses); |
|
1293 | - } |
|
1294 | - |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * returns whether ticket is required or not. |
|
1298 | - * |
|
1299 | - * @return boolean |
|
1300 | - * @throws EE_Error |
|
1301 | - * @throws ReflectionException |
|
1302 | - */ |
|
1303 | - public function required() |
|
1304 | - { |
|
1305 | - return $this->get('TKT_required'); |
|
1306 | - } |
|
1307 | - |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * sets the TKT_required property |
|
1311 | - * |
|
1312 | - * @param boolean $required |
|
1313 | - * @return void |
|
1314 | - * @throws EE_Error |
|
1315 | - * @throws ReflectionException |
|
1316 | - */ |
|
1317 | - public function set_required($required) |
|
1318 | - { |
|
1319 | - $this->set('TKT_required', $required); |
|
1320 | - } |
|
1321 | - |
|
1322 | - |
|
1323 | - /** |
|
1324 | - * Gets taxable |
|
1325 | - * |
|
1326 | - * @return boolean |
|
1327 | - * @throws EE_Error |
|
1328 | - * @throws ReflectionException |
|
1329 | - */ |
|
1330 | - public function taxable() |
|
1331 | - { |
|
1332 | - return $this->get('TKT_taxable'); |
|
1333 | - } |
|
1334 | - |
|
1335 | - |
|
1336 | - /** |
|
1337 | - * Sets taxable |
|
1338 | - * |
|
1339 | - * @param boolean $taxable |
|
1340 | - * @return void |
|
1341 | - * @throws EE_Error |
|
1342 | - * @throws ReflectionException |
|
1343 | - */ |
|
1344 | - public function set_taxable($taxable) |
|
1345 | - { |
|
1346 | - $this->set('TKT_taxable', $taxable); |
|
1347 | - } |
|
1348 | - |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * Gets is_default |
|
1352 | - * |
|
1353 | - * @return boolean |
|
1354 | - * @throws EE_Error |
|
1355 | - * @throws ReflectionException |
|
1356 | - */ |
|
1357 | - public function is_default() |
|
1358 | - { |
|
1359 | - return $this->get('TKT_is_default'); |
|
1360 | - } |
|
1361 | - |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * Sets is_default |
|
1365 | - * |
|
1366 | - * @param boolean $is_default |
|
1367 | - * @return void |
|
1368 | - * @throws EE_Error |
|
1369 | - * @throws ReflectionException |
|
1370 | - */ |
|
1371 | - public function set_is_default($is_default) |
|
1372 | - { |
|
1373 | - $this->set('TKT_is_default', $is_default); |
|
1374 | - } |
|
1375 | - |
|
1376 | - |
|
1377 | - /** |
|
1378 | - * Gets order |
|
1379 | - * |
|
1380 | - * @return int |
|
1381 | - * @throws EE_Error |
|
1382 | - * @throws ReflectionException |
|
1383 | - */ |
|
1384 | - public function order() |
|
1385 | - { |
|
1386 | - return $this->get('TKT_order'); |
|
1387 | - } |
|
1388 | - |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * Sets order |
|
1392 | - * |
|
1393 | - * @param int $order |
|
1394 | - * @return void |
|
1395 | - * @throws EE_Error |
|
1396 | - * @throws ReflectionException |
|
1397 | - */ |
|
1398 | - public function set_order($order) |
|
1399 | - { |
|
1400 | - $this->set('TKT_order', $order); |
|
1401 | - } |
|
1402 | - |
|
1403 | - |
|
1404 | - /** |
|
1405 | - * Gets row |
|
1406 | - * |
|
1407 | - * @return int |
|
1408 | - * @throws EE_Error |
|
1409 | - * @throws ReflectionException |
|
1410 | - */ |
|
1411 | - public function row() |
|
1412 | - { |
|
1413 | - return $this->get('TKT_row'); |
|
1414 | - } |
|
1415 | - |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * Sets row |
|
1419 | - * |
|
1420 | - * @param int $row |
|
1421 | - * @return void |
|
1422 | - * @throws EE_Error |
|
1423 | - * @throws ReflectionException |
|
1424 | - */ |
|
1425 | - public function set_row($row) |
|
1426 | - { |
|
1427 | - $this->set('TKT_row', $row); |
|
1428 | - } |
|
1429 | - |
|
1430 | - |
|
1431 | - /** |
|
1432 | - * Gets deleted |
|
1433 | - * |
|
1434 | - * @return boolean |
|
1435 | - * @throws EE_Error |
|
1436 | - * @throws ReflectionException |
|
1437 | - */ |
|
1438 | - public function deleted() |
|
1439 | - { |
|
1440 | - return $this->get('TKT_deleted'); |
|
1441 | - } |
|
1442 | - |
|
1443 | - |
|
1444 | - /** |
|
1445 | - * Sets deleted |
|
1446 | - * |
|
1447 | - * @param boolean $deleted |
|
1448 | - * @return void |
|
1449 | - * @throws EE_Error |
|
1450 | - * @throws ReflectionException |
|
1451 | - */ |
|
1452 | - public function set_deleted($deleted) |
|
1453 | - { |
|
1454 | - $this->set('TKT_deleted', $deleted); |
|
1455 | - } |
|
1456 | - |
|
1457 | - |
|
1458 | - /** |
|
1459 | - * Gets parent |
|
1460 | - * |
|
1461 | - * @return int |
|
1462 | - * @throws EE_Error |
|
1463 | - * @throws ReflectionException |
|
1464 | - */ |
|
1465 | - public function parent_ID() |
|
1466 | - { |
|
1467 | - return $this->get('TKT_parent'); |
|
1468 | - } |
|
1469 | - |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Sets parent |
|
1473 | - * |
|
1474 | - * @param int $parent |
|
1475 | - * @return void |
|
1476 | - * @throws EE_Error |
|
1477 | - * @throws ReflectionException |
|
1478 | - */ |
|
1479 | - public function set_parent_ID($parent) |
|
1480 | - { |
|
1481 | - $this->set('TKT_parent', $parent); |
|
1482 | - } |
|
1483 | - |
|
1484 | - |
|
1485 | - /** |
|
1486 | - * @return boolean |
|
1487 | - * @throws EE_Error |
|
1488 | - * @throws InvalidArgumentException |
|
1489 | - * @throws InvalidDataTypeException |
|
1490 | - * @throws InvalidInterfaceException |
|
1491 | - * @throws ReflectionException |
|
1492 | - */ |
|
1493 | - public function reverse_calculate() |
|
1494 | - { |
|
1495 | - return $this->get('TKT_reverse_calculate'); |
|
1496 | - } |
|
1497 | - |
|
1498 | - |
|
1499 | - /** |
|
1500 | - * @param boolean $reverse_calculate |
|
1501 | - * @throws EE_Error |
|
1502 | - * @throws InvalidArgumentException |
|
1503 | - * @throws InvalidDataTypeException |
|
1504 | - * @throws InvalidInterfaceException |
|
1505 | - * @throws ReflectionException |
|
1506 | - */ |
|
1507 | - public function set_reverse_calculate($reverse_calculate) |
|
1508 | - { |
|
1509 | - $this->set('TKT_reverse_calculate', $reverse_calculate); |
|
1510 | - } |
|
1511 | - |
|
1512 | - |
|
1513 | - /** |
|
1514 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
1515 | - * |
|
1516 | - * @return string |
|
1517 | - * @throws EE_Error |
|
1518 | - * @throws ReflectionException |
|
1519 | - */ |
|
1520 | - public function name_and_info() |
|
1521 | - { |
|
1522 | - $times = []; |
|
1523 | - foreach ($this->datetimes() as $datetime) { |
|
1524 | - $times[] = $datetime->start_date_and_time(); |
|
1525 | - } |
|
1526 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
1527 | - } |
|
1528 | - |
|
1529 | - |
|
1530 | - /** |
|
1531 | - * Gets name |
|
1532 | - * |
|
1533 | - * @return string |
|
1534 | - * @throws EE_Error |
|
1535 | - * @throws ReflectionException |
|
1536 | - */ |
|
1537 | - public function name() |
|
1538 | - { |
|
1539 | - return $this->get('TKT_name'); |
|
1540 | - } |
|
1541 | - |
|
1542 | - |
|
1543 | - /** |
|
1544 | - * Gets price |
|
1545 | - * |
|
1546 | - * @return float |
|
1547 | - * @throws EE_Error |
|
1548 | - * @throws ReflectionException |
|
1549 | - */ |
|
1550 | - public function price() |
|
1551 | - { |
|
1552 | - return $this->get('TKT_price'); |
|
1553 | - } |
|
1554 | - |
|
1555 | - |
|
1556 | - /** |
|
1557 | - * Gets all the registrations for this ticket |
|
1558 | - * |
|
1559 | - * @param array $query_params @see |
|
1560 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1561 | - * @return EE_Registration[]|EE_Base_Class[] |
|
1562 | - * @throws EE_Error |
|
1563 | - * @throws ReflectionException |
|
1564 | - */ |
|
1565 | - public function registrations($query_params = []) |
|
1566 | - { |
|
1567 | - return $this->get_many_related('Registration', $query_params); |
|
1568 | - } |
|
1569 | - |
|
1570 | - |
|
1571 | - /** |
|
1572 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
1573 | - * |
|
1574 | - * @return int |
|
1575 | - * @throws EE_Error |
|
1576 | - * @throws ReflectionException |
|
1577 | - */ |
|
1578 | - public function update_tickets_sold() |
|
1579 | - { |
|
1580 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
1581 | - [ |
|
1582 | - [ |
|
1583 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
1584 | - 'REG_deleted' => 0, |
|
1585 | - ], |
|
1586 | - ] |
|
1587 | - ); |
|
1588 | - $this->set_sold($count_regs_for_this_ticket); |
|
1589 | - $this->save(); |
|
1590 | - return $count_regs_for_this_ticket; |
|
1591 | - } |
|
1592 | - |
|
1593 | - |
|
1594 | - /** |
|
1595 | - * Counts the registrations for this ticket |
|
1596 | - * |
|
1597 | - * @param array $query_params @see |
|
1598 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1599 | - * @return int |
|
1600 | - * @throws EE_Error |
|
1601 | - * @throws ReflectionException |
|
1602 | - */ |
|
1603 | - public function count_registrations($query_params = []) |
|
1604 | - { |
|
1605 | - return $this->count_related('Registration', $query_params); |
|
1606 | - } |
|
1607 | - |
|
1608 | - |
|
1609 | - /** |
|
1610 | - * Implementation for EEI_Has_Icon interface method. |
|
1611 | - * |
|
1612 | - * @return string |
|
1613 | - * @see EEI_Visual_Representation for comments |
|
1614 | - */ |
|
1615 | - public function get_icon() |
|
1616 | - { |
|
1617 | - return '<span class="dashicons dashicons-tickets-alt"/>'; |
|
1618 | - } |
|
1619 | - |
|
1620 | - |
|
1621 | - /** |
|
1622 | - * Implementation of the EEI_Event_Relation interface method |
|
1623 | - * |
|
1624 | - * @return EE_Event |
|
1625 | - * @throws EE_Error |
|
1626 | - * @throws UnexpectedEntityException |
|
1627 | - * @throws ReflectionException |
|
1628 | - * @see EEI_Event_Relation for comments |
|
1629 | - */ |
|
1630 | - public function get_related_event() |
|
1631 | - { |
|
1632 | - // get one datetime to use for getting the event |
|
1633 | - $datetime = $this->first_datetime(); |
|
1634 | - if (! $datetime instanceof EE_Datetime) { |
|
1635 | - throw new UnexpectedEntityException( |
|
1636 | - $datetime, |
|
1637 | - 'EE_Datetime', |
|
1638 | - sprintf( |
|
1639 | - __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
1640 | - $this->name() |
|
1641 | - ) |
|
1642 | - ); |
|
1643 | - } |
|
1644 | - $event = $datetime->event(); |
|
1645 | - if (! $event instanceof EE_Event) { |
|
1646 | - throw new UnexpectedEntityException( |
|
1647 | - $event, |
|
1648 | - 'EE_Event', |
|
1649 | - sprintf( |
|
1650 | - __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
1651 | - $this->name() |
|
1652 | - ) |
|
1653 | - ); |
|
1654 | - } |
|
1655 | - return $event; |
|
1656 | - } |
|
1657 | - |
|
1658 | - |
|
1659 | - /** |
|
1660 | - * Implementation of the EEI_Event_Relation interface method |
|
1661 | - * |
|
1662 | - * @return string |
|
1663 | - * @throws UnexpectedEntityException |
|
1664 | - * @throws EE_Error |
|
1665 | - * @throws ReflectionException |
|
1666 | - * @see EEI_Event_Relation for comments |
|
1667 | - */ |
|
1668 | - public function get_event_name() |
|
1669 | - { |
|
1670 | - $event = $this->get_related_event(); |
|
1671 | - return $event instanceof EE_Event ? $event->name() : ''; |
|
1672 | - } |
|
1673 | - |
|
1674 | - |
|
1675 | - /** |
|
1676 | - * Implementation of the EEI_Event_Relation interface method |
|
1677 | - * |
|
1678 | - * @return int |
|
1679 | - * @throws UnexpectedEntityException |
|
1680 | - * @throws EE_Error |
|
1681 | - * @throws ReflectionException |
|
1682 | - * @see EEI_Event_Relation for comments |
|
1683 | - */ |
|
1684 | - public function get_event_ID() |
|
1685 | - { |
|
1686 | - $event = $this->get_related_event(); |
|
1687 | - return $event instanceof EE_Event ? $event->ID() : 0; |
|
1688 | - } |
|
1689 | - |
|
1690 | - |
|
1691 | - /** |
|
1692 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
1693 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
1694 | - * If there are none then it can be permanently deleted. |
|
1695 | - * |
|
1696 | - * @return bool |
|
1697 | - * @throws EE_Error |
|
1698 | - * @throws ReflectionException |
|
1699 | - */ |
|
1700 | - public function is_permanently_deleteable() |
|
1701 | - { |
|
1702 | - return $this->count_registrations() === 0; |
|
1703 | - } |
|
1704 | - |
|
1705 | - |
|
1706 | - /** |
|
1707 | - * @return int |
|
1708 | - * @throws EE_Error |
|
1709 | - * @throws ReflectionException |
|
1710 | - * @since $VID:$ |
|
1711 | - */ |
|
1712 | - public function visibility(): int |
|
1713 | - { |
|
1714 | - return $this->get('TKT_visibility'); |
|
1715 | - } |
|
1716 | - |
|
1717 | - |
|
1718 | - /** |
|
1719 | - * @return int |
|
1720 | - * @throws EE_Error |
|
1721 | - * @throws ReflectionException |
|
1722 | - * @since $VID:$ |
|
1723 | - */ |
|
1724 | - public function isHidden(): int |
|
1725 | - { |
|
1726 | - return $this->visibility() === EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE; |
|
1727 | - } |
|
1728 | - |
|
1729 | - |
|
1730 | - /** |
|
1731 | - * @return int |
|
1732 | - * @throws EE_Error |
|
1733 | - * @throws ReflectionException |
|
1734 | - * @since $VID:$ |
|
1735 | - */ |
|
1736 | - public function isNotHidden(): int |
|
1737 | - { |
|
1738 | - return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE; |
|
1739 | - } |
|
1740 | - |
|
1741 | - |
|
1742 | - /** |
|
1743 | - * @return int |
|
1744 | - * @throws EE_Error |
|
1745 | - * @throws ReflectionException |
|
1746 | - * @since $VID:$ |
|
1747 | - */ |
|
1748 | - public function isPublicOnly(): int |
|
1749 | - { |
|
1750 | - return $this->isNotHidden() && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE; |
|
1751 | - } |
|
1752 | - |
|
1753 | - |
|
1754 | - /** |
|
1755 | - * @return int |
|
1756 | - * @throws EE_Error |
|
1757 | - * @throws ReflectionException |
|
1758 | - * @since $VID:$ |
|
1759 | - */ |
|
1760 | - public function isMembersOnly(): int |
|
1761 | - { |
|
1762 | - return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE |
|
1763 | - && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE; |
|
1764 | - } |
|
1765 | - |
|
1766 | - |
|
1767 | - /** |
|
1768 | - * @return int |
|
1769 | - * @throws EE_Error |
|
1770 | - * @throws ReflectionException |
|
1771 | - * @since $VID:$ |
|
1772 | - */ |
|
1773 | - public function isAdminsOnly(): int |
|
1774 | - { |
|
1775 | - return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE |
|
1776 | - && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE; |
|
1777 | - } |
|
1778 | - |
|
1779 | - |
|
1780 | - /** |
|
1781 | - * @return int |
|
1782 | - * @throws EE_Error |
|
1783 | - * @throws ReflectionException |
|
1784 | - * @since $VID:$ |
|
1785 | - */ |
|
1786 | - public function isAdminUiOnly(): int |
|
1787 | - { |
|
1788 | - return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE |
|
1789 | - && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE; |
|
1790 | - } |
|
1791 | - |
|
1792 | - |
|
1793 | - /** |
|
1794 | - * @param int $visibility |
|
1795 | - * @throws EE_Error |
|
1796 | - * @throws ReflectionException |
|
1797 | - * @since $VID:$ |
|
1798 | - */ |
|
1799 | - public function set_visibility(int $visibility) |
|
1800 | - { |
|
1801 | - |
|
1802 | - $ticket_visibility_options = $this->_model->ticketVisibilityOptions(); |
|
1803 | - $ticket_visibility = -1; |
|
1804 | - foreach ($ticket_visibility_options as $ticket_visibility_option) { |
|
1805 | - if ($visibility === $ticket_visibility_option) { |
|
1806 | - $ticket_visibility = $visibility; |
|
1807 | - } |
|
1808 | - } |
|
1809 | - if ($ticket_visibility === -1) { |
|
1810 | - throw new DomainException( |
|
1811 | - sprintf( |
|
1812 | - esc_html__( |
|
1813 | - 'The supplied ticket visibility setting of "%1$s" is not valid. It needs to match one of the keys in the following array:%2$s %3$s ', |
|
1814 | - 'event_espresso' |
|
1815 | - ), |
|
1816 | - $visibility, |
|
1817 | - '<br />', |
|
1818 | - var_export($ticket_visibility_options, true) |
|
1819 | - ) |
|
1820 | - ); |
|
1821 | - } |
|
1822 | - $this->set('TKT_visibility', $ticket_visibility); |
|
1823 | - } |
|
1824 | - |
|
1825 | - |
|
1826 | - /******************************************************************* |
|
18 | + /** |
|
19 | + * TicKet Sold out: |
|
20 | + * constant used by ticket_status() to indicate that a ticket is sold out |
|
21 | + * and no longer available for purchases |
|
22 | + */ |
|
23 | + const sold_out = 'TKS'; |
|
24 | + |
|
25 | + /** |
|
26 | + * TicKet Expired: |
|
27 | + * constant used by ticket_status() to indicate that a ticket is expired |
|
28 | + * and no longer available for purchase |
|
29 | + */ |
|
30 | + const expired = 'TKE'; |
|
31 | + |
|
32 | + /** |
|
33 | + * TicKet Archived: |
|
34 | + * constant used by ticket_status() to indicate that a ticket is archived |
|
35 | + * and no longer available for purchase |
|
36 | + */ |
|
37 | + const archived = 'TKA'; |
|
38 | + |
|
39 | + /** |
|
40 | + * TicKet Pending: |
|
41 | + * constant used by ticket_status() to indicate that a ticket is pending |
|
42 | + * and is NOT YET available for purchase |
|
43 | + */ |
|
44 | + const pending = 'TKP'; |
|
45 | + |
|
46 | + /** |
|
47 | + * TicKet On sale: |
|
48 | + * constant used by ticket_status() to indicate that a ticket is On Sale |
|
49 | + * and IS available for purchase |
|
50 | + */ |
|
51 | + const onsale = 'TKO'; |
|
52 | + |
|
53 | + /** |
|
54 | + * extra meta key for tracking ticket reservations |
|
55 | + * |
|
56 | + * @type string |
|
57 | + */ |
|
58 | + const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
59 | + |
|
60 | + /** |
|
61 | + * override of parent property |
|
62 | + * |
|
63 | + * @var EEM_Ticket |
|
64 | + */ |
|
65 | + protected $_model; |
|
66 | + |
|
67 | + /** |
|
68 | + * cached result from method of the same name |
|
69 | + * |
|
70 | + * @var float $_ticket_total_with_taxes |
|
71 | + */ |
|
72 | + private $_ticket_total_with_taxes; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @param array $props_n_values incoming values |
|
77 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
78 | + * used.) |
|
79 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
80 | + * date_format and the second value is the time format |
|
81 | + * @return EE_Ticket |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
86 | + { |
|
87 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
88 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param array $props_n_values incoming values from the database |
|
94 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
95 | + * the website will be used. |
|
96 | + * @return EE_Ticket |
|
97 | + * @throws EE_Error |
|
98 | + * @throws ReflectionException |
|
99 | + */ |
|
100 | + public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
101 | + { |
|
102 | + return new self($props_n_values, true, $timezone); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return bool |
|
108 | + * @throws EE_Error |
|
109 | + * @throws ReflectionException |
|
110 | + */ |
|
111 | + public function parent() |
|
112 | + { |
|
113 | + return $this->get('TKT_parent'); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * return if a ticket has quantities available for purchase |
|
119 | + * |
|
120 | + * @param int $DTT_ID the primary key for a particular datetime |
|
121 | + * @return boolean |
|
122 | + * @throws EE_Error |
|
123 | + * @throws ReflectionException |
|
124 | + */ |
|
125 | + public function available($DTT_ID = 0) |
|
126 | + { |
|
127 | + // are we checking availability for a particular datetime ? |
|
128 | + if ($DTT_ID) { |
|
129 | + // get that datetime object |
|
130 | + $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]); |
|
131 | + // if ticket sales for this datetime have exceeded the reg limit... |
|
132 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
133 | + return false; |
|
134 | + } |
|
135 | + } |
|
136 | + // datetime is still open for registration, but is this ticket sold out ? |
|
137 | + return $this->qty() < 1 || $this->qty() > $this->sold(); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
143 | + * |
|
144 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
145 | + * relevant status const |
|
146 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
147 | + * further processing |
|
148 | + * @return mixed status int if the display string isn't requested |
|
149 | + * @throws EE_Error |
|
150 | + * @throws ReflectionException |
|
151 | + */ |
|
152 | + public function ticket_status($display = false, $remaining = null) |
|
153 | + { |
|
154 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
155 | + if (! $remaining) { |
|
156 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
157 | + } |
|
158 | + if ($this->get('TKT_deleted')) { |
|
159 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
160 | + } |
|
161 | + if ($this->is_expired()) { |
|
162 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
163 | + } |
|
164 | + if ($this->is_pending()) { |
|
165 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
166 | + } |
|
167 | + if ($this->is_on_sale()) { |
|
168 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
169 | + } |
|
170 | + return ''; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
176 | + * considering ALL the factors used for figuring that out. |
|
177 | + * |
|
178 | + * @access public |
|
179 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
180 | + * @return boolean true = tickets remaining, false not. |
|
181 | + * @throws EE_Error |
|
182 | + * @throws ReflectionException |
|
183 | + */ |
|
184 | + public function is_remaining($DTT_ID = 0) |
|
185 | + { |
|
186 | + $num_remaining = $this->remaining($DTT_ID); |
|
187 | + if ($num_remaining === 0) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
191 | + return false; |
|
192 | + } |
|
193 | + return true; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * return the total number of tickets available for purchase |
|
199 | + * |
|
200 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
201 | + * set to 0 for all related datetimes |
|
202 | + * @return int |
|
203 | + * @throws EE_Error |
|
204 | + * @throws ReflectionException |
|
205 | + */ |
|
206 | + public function remaining($DTT_ID = 0) |
|
207 | + { |
|
208 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Gets min |
|
214 | + * |
|
215 | + * @return int |
|
216 | + * @throws EE_Error |
|
217 | + * @throws ReflectionException |
|
218 | + */ |
|
219 | + public function min() |
|
220 | + { |
|
221 | + return $this->get('TKT_min'); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * return if a ticket is no longer available cause its available dates have expired. |
|
227 | + * |
|
228 | + * @return boolean |
|
229 | + * @throws EE_Error |
|
230 | + * @throws ReflectionException |
|
231 | + */ |
|
232 | + public function is_expired() |
|
233 | + { |
|
234 | + return ($this->get_raw('TKT_end_date') < time()); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Return if a ticket is yet to go on sale or not |
|
240 | + * |
|
241 | + * @return boolean |
|
242 | + * @throws EE_Error |
|
243 | + * @throws ReflectionException |
|
244 | + */ |
|
245 | + public function is_pending() |
|
246 | + { |
|
247 | + return ($this->get_raw('TKT_start_date') >= time()); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Return if a ticket is on sale or not |
|
253 | + * |
|
254 | + * @return boolean |
|
255 | + * @throws EE_Error |
|
256 | + * @throws ReflectionException |
|
257 | + */ |
|
258 | + public function is_on_sale() |
|
259 | + { |
|
260 | + return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time()); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * This returns the chronologically last datetime that this ticket is associated with |
|
266 | + * |
|
267 | + * @param string $date_format |
|
268 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
269 | + * the end date ie: Jan 01 "to" Dec 31 |
|
270 | + * @return string |
|
271 | + * @throws EE_Error |
|
272 | + * @throws ReflectionException |
|
273 | + */ |
|
274 | + public function date_range($date_format = '', $conjunction = ' - ') |
|
275 | + { |
|
276 | + $date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt; |
|
277 | + $first_date = $this->first_datetime() instanceof EE_Datetime |
|
278 | + ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format) |
|
279 | + : ''; |
|
280 | + $last_date = $this->last_datetime() instanceof EE_Datetime |
|
281 | + ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format) |
|
282 | + : ''; |
|
283 | + |
|
284 | + return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * This returns the chronologically first datetime that this ticket is associated with |
|
290 | + * |
|
291 | + * @return EE_Datetime |
|
292 | + * @throws EE_Error |
|
293 | + * @throws ReflectionException |
|
294 | + */ |
|
295 | + public function first_datetime() |
|
296 | + { |
|
297 | + $datetimes = $this->datetimes(['limit' => 1]); |
|
298 | + return reset($datetimes); |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * Gets all the datetimes this ticket can be used for attending. |
|
304 | + * Unless otherwise specified, orders datetimes by start date. |
|
305 | + * |
|
306 | + * @param array $query_params @see |
|
307 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
308 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
309 | + * @throws EE_Error |
|
310 | + * @throws ReflectionException |
|
311 | + */ |
|
312 | + public function datetimes($query_params = []) |
|
313 | + { |
|
314 | + if (! isset($query_params['order_by'])) { |
|
315 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
316 | + } |
|
317 | + return $this->get_many_related('Datetime', $query_params); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * This returns the chronologically last datetime that this ticket is associated with |
|
323 | + * |
|
324 | + * @return EE_Datetime |
|
325 | + * @throws EE_Error |
|
326 | + * @throws ReflectionException |
|
327 | + */ |
|
328 | + public function last_datetime() |
|
329 | + { |
|
330 | + $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]); |
|
331 | + return end($datetimes); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * This returns the total tickets sold depending on the given parameters. |
|
337 | + * |
|
338 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
339 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
340 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
341 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
342 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
343 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
344 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
345 | + * @return mixed (array|int) how many tickets have sold |
|
346 | + * @throws EE_Error |
|
347 | + * @throws ReflectionException |
|
348 | + */ |
|
349 | + public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
350 | + { |
|
351 | + $total = 0; |
|
352 | + $tickets_sold = $this->_all_tickets_sold(); |
|
353 | + switch ($what) { |
|
354 | + case 'ticket': |
|
355 | + return $tickets_sold['ticket']; |
|
356 | + break; |
|
357 | + case 'datetime': |
|
358 | + if (empty($tickets_sold['datetime'])) { |
|
359 | + return $total; |
|
360 | + } |
|
361 | + if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
362 | + EE_Error::add_error( |
|
363 | + __( |
|
364 | + 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
365 | + 'event_espresso' |
|
366 | + ), |
|
367 | + __FILE__, |
|
368 | + __FUNCTION__, |
|
369 | + __LINE__ |
|
370 | + ); |
|
371 | + return $total; |
|
372 | + } |
|
373 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
374 | + break; |
|
375 | + default: |
|
376 | + return $total; |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
383 | + * |
|
384 | + * @return EE_Ticket[] |
|
385 | + * @throws EE_Error |
|
386 | + * @throws ReflectionException |
|
387 | + */ |
|
388 | + protected function _all_tickets_sold() |
|
389 | + { |
|
390 | + $datetimes = $this->get_many_related('Datetime'); |
|
391 | + $tickets_sold = []; |
|
392 | + if (! empty($datetimes)) { |
|
393 | + foreach ($datetimes as $datetime) { |
|
394 | + $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
395 | + } |
|
396 | + } |
|
397 | + // Tickets sold |
|
398 | + $tickets_sold['ticket'] = $this->sold(); |
|
399 | + return $tickets_sold; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * This returns the base price object for the ticket. |
|
405 | + * |
|
406 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
407 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
408 | + * @throws EE_Error |
|
409 | + * @throws ReflectionException |
|
410 | + */ |
|
411 | + public function base_price($return_array = false) |
|
412 | + { |
|
413 | + $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price]; |
|
414 | + return $return_array |
|
415 | + ? $this->get_many_related('Price', [$_where]) |
|
416 | + : $this->get_first_related('Price', [$_where]); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
422 | + * |
|
423 | + * @access public |
|
424 | + * @return EE_Price[] |
|
425 | + * @throws EE_Error |
|
426 | + * @throws ReflectionException |
|
427 | + */ |
|
428 | + public function price_modifiers() |
|
429 | + { |
|
430 | + $query_params = [ |
|
431 | + 0 => [ |
|
432 | + 'Price_Type.PBT_ID' => [ |
|
433 | + 'NOT IN', |
|
434 | + [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax], |
|
435 | + ], |
|
436 | + ], |
|
437 | + ]; |
|
438 | + return $this->prices($query_params); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
444 | + * |
|
445 | + * @access public |
|
446 | + * @return EE_Price[] |
|
447 | + * @throws EE_Error |
|
448 | + * @throws ReflectionException |
|
449 | + */ |
|
450 | + public function tax_price_modifiers() |
|
451 | + { |
|
452 | + $query_params = [ |
|
453 | + 0 => [ |
|
454 | + 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, |
|
455 | + ], |
|
456 | + ]; |
|
457 | + return $this->prices($query_params); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * Gets all the prices that combine to form the final price of this ticket |
|
463 | + * |
|
464 | + * @param array $query_params @see |
|
465 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
466 | + * @return EE_Price[]|EE_Base_Class[] |
|
467 | + * @throws EE_Error |
|
468 | + * @throws ReflectionException |
|
469 | + */ |
|
470 | + public function prices($query_params = []) |
|
471 | + { |
|
472 | + return $this->get_many_related('Price', $query_params); |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Gets all the ticket datetimes (ie, relations between datetimes and tickets) |
|
478 | + * |
|
479 | + * @param array $query_params @see |
|
480 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
481 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
482 | + * @throws EE_Error |
|
483 | + * @throws ReflectionException |
|
484 | + */ |
|
485 | + public function datetime_tickets($query_params = []) |
|
486 | + { |
|
487 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Gets all the datetimes from the db ordered by DTT_order |
|
493 | + * |
|
494 | + * @param boolean $show_expired |
|
495 | + * @param boolean $show_deleted |
|
496 | + * @return EE_Datetime[] |
|
497 | + * @throws EE_Error |
|
498 | + * @throws ReflectionException |
|
499 | + */ |
|
500 | + public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
501 | + { |
|
502 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
503 | + $this->ID(), |
|
504 | + $show_expired, |
|
505 | + $show_deleted |
|
506 | + ); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * Gets ID |
|
512 | + * |
|
513 | + * @return int |
|
514 | + * @throws EE_Error |
|
515 | + * @throws ReflectionException |
|
516 | + */ |
|
517 | + public function ID() |
|
518 | + { |
|
519 | + return $this->get('TKT_ID'); |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * get the author of the ticket. |
|
525 | + * |
|
526 | + * @return int |
|
527 | + * @throws EE_Error |
|
528 | + * @throws ReflectionException |
|
529 | + * @since 4.5.0 |
|
530 | + */ |
|
531 | + public function wp_user() |
|
532 | + { |
|
533 | + return $this->get('TKT_wp_user'); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Gets the template for the ticket |
|
539 | + * |
|
540 | + * @return EE_Ticket_Template|EE_Base_Class |
|
541 | + * @throws EE_Error |
|
542 | + * @throws ReflectionException |
|
543 | + */ |
|
544 | + public function template() |
|
545 | + { |
|
546 | + return $this->get_first_related('Ticket_Template'); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * Simply returns an array of EE_Price objects that are taxes. |
|
552 | + * |
|
553 | + * @return EE_Price[] |
|
554 | + * @throws EE_Error |
|
555 | + * @throws ReflectionException |
|
556 | + */ |
|
557 | + public function get_ticket_taxes_for_admin(): array |
|
558 | + { |
|
559 | + /** @var EE_Admin_Config $admin_config */ |
|
560 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
561 | + return $admin_config->useAdvancedEditor() ? $this->tax_price_modifiers() : EE_Taxes::get_taxes_for_admin(); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * @return float |
|
567 | + * @throws EE_Error |
|
568 | + * @throws ReflectionException |
|
569 | + */ |
|
570 | + public function ticket_price() |
|
571 | + { |
|
572 | + return $this->get('TKT_price'); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * @return mixed |
|
578 | + * @throws EE_Error |
|
579 | + * @throws ReflectionException |
|
580 | + */ |
|
581 | + public function pretty_price() |
|
582 | + { |
|
583 | + return $this->get_pretty('TKT_price'); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * @return bool |
|
589 | + * @throws EE_Error |
|
590 | + * @throws ReflectionException |
|
591 | + */ |
|
592 | + public function is_free() |
|
593 | + { |
|
594 | + return $this->get_ticket_total_with_taxes() === (float) 0; |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * get_ticket_total_with_taxes |
|
600 | + * |
|
601 | + * @param bool $no_cache |
|
602 | + * @return float |
|
603 | + * @throws EE_Error |
|
604 | + * @throws ReflectionException |
|
605 | + */ |
|
606 | + public function get_ticket_total_with_taxes($no_cache = false) |
|
607 | + { |
|
608 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
609 | + /** @var EE_Admin_Config $admin_config */ |
|
610 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
611 | + $this->_ticket_total_with_taxes = $admin_config->useAdvancedEditor() |
|
612 | + ? $this->ticket_price() |
|
613 | + : $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
614 | + } |
|
615 | + return (float) $this->_ticket_total_with_taxes; |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * @throws EE_Error |
|
621 | + * @throws ReflectionException |
|
622 | + */ |
|
623 | + public function ensure_TKT_Price_correct() |
|
624 | + { |
|
625 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
626 | + $this->save(); |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + /** |
|
631 | + * @return float |
|
632 | + * @throws EE_Error |
|
633 | + * @throws ReflectionException |
|
634 | + */ |
|
635 | + public function get_ticket_subtotal() |
|
636 | + { |
|
637 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
638 | + } |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * Returns the total taxes applied to this ticket |
|
643 | + * |
|
644 | + * @return float |
|
645 | + * @throws EE_Error |
|
646 | + * @throws ReflectionException |
|
647 | + */ |
|
648 | + public function get_ticket_taxes_total_for_admin() |
|
649 | + { |
|
650 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + /** |
|
655 | + * Sets name |
|
656 | + * |
|
657 | + * @param string $name |
|
658 | + * @throws EE_Error |
|
659 | + * @throws ReflectionException |
|
660 | + */ |
|
661 | + public function set_name($name) |
|
662 | + { |
|
663 | + $this->set('TKT_name', $name); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * Gets description |
|
669 | + * |
|
670 | + * @return string |
|
671 | + * @throws EE_Error |
|
672 | + * @throws ReflectionException |
|
673 | + */ |
|
674 | + public function description() |
|
675 | + { |
|
676 | + return $this->get('TKT_description'); |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * Sets description |
|
682 | + * |
|
683 | + * @param string $description |
|
684 | + * @throws EE_Error |
|
685 | + * @throws ReflectionException |
|
686 | + */ |
|
687 | + public function set_description($description) |
|
688 | + { |
|
689 | + $this->set('TKT_description', $description); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Gets start_date |
|
695 | + * |
|
696 | + * @param string $date_format |
|
697 | + * @param string $time_format |
|
698 | + * @return string |
|
699 | + * @throws EE_Error |
|
700 | + * @throws ReflectionException |
|
701 | + */ |
|
702 | + public function start_date($date_format = '', $time_format = '') |
|
703 | + { |
|
704 | + return $this->_get_datetime('TKT_start_date', $date_format, $time_format); |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * Sets start_date |
|
710 | + * |
|
711 | + * @param string $start_date |
|
712 | + * @return void |
|
713 | + * @throws EE_Error |
|
714 | + * @throws ReflectionException |
|
715 | + */ |
|
716 | + public function set_start_date($start_date) |
|
717 | + { |
|
718 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * Gets end_date |
|
724 | + * |
|
725 | + * @param string $date_format |
|
726 | + * @param string $time_format |
|
727 | + * @return string |
|
728 | + * @throws EE_Error |
|
729 | + * @throws ReflectionException |
|
730 | + */ |
|
731 | + public function end_date($date_format = '', $time_format = '') |
|
732 | + { |
|
733 | + return $this->_get_datetime('TKT_end_date', $date_format, $time_format); |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * Sets end_date |
|
739 | + * |
|
740 | + * @param string $end_date |
|
741 | + * @return void |
|
742 | + * @throws EE_Error |
|
743 | + * @throws ReflectionException |
|
744 | + */ |
|
745 | + public function set_end_date($end_date) |
|
746 | + { |
|
747 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
748 | + } |
|
749 | + |
|
750 | + |
|
751 | + /** |
|
752 | + * Sets sell until time |
|
753 | + * |
|
754 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
755 | + * @throws EE_Error |
|
756 | + * @throws ReflectionException |
|
757 | + * @since 4.5.0 |
|
758 | + */ |
|
759 | + public function set_end_time($time) |
|
760 | + { |
|
761 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + /** |
|
766 | + * Sets min |
|
767 | + * |
|
768 | + * @param int $min |
|
769 | + * @return void |
|
770 | + * @throws EE_Error |
|
771 | + * @throws ReflectionException |
|
772 | + */ |
|
773 | + public function set_min($min) |
|
774 | + { |
|
775 | + $this->set('TKT_min', $min); |
|
776 | + } |
|
777 | + |
|
778 | + |
|
779 | + /** |
|
780 | + * Gets max |
|
781 | + * |
|
782 | + * @return int |
|
783 | + * @throws EE_Error |
|
784 | + * @throws ReflectionException |
|
785 | + */ |
|
786 | + public function max() |
|
787 | + { |
|
788 | + return $this->get('TKT_max'); |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + /** |
|
793 | + * Sets max |
|
794 | + * |
|
795 | + * @param int $max |
|
796 | + * @return void |
|
797 | + * @throws EE_Error |
|
798 | + * @throws ReflectionException |
|
799 | + */ |
|
800 | + public function set_max($max) |
|
801 | + { |
|
802 | + $this->set('TKT_max', $max); |
|
803 | + } |
|
804 | + |
|
805 | + |
|
806 | + /** |
|
807 | + * Sets price |
|
808 | + * |
|
809 | + * @param float $price |
|
810 | + * @return void |
|
811 | + * @throws EE_Error |
|
812 | + * @throws ReflectionException |
|
813 | + */ |
|
814 | + public function set_price($price) |
|
815 | + { |
|
816 | + $this->set('TKT_price', $price); |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * Gets sold |
|
822 | + * |
|
823 | + * @return int |
|
824 | + * @throws EE_Error |
|
825 | + * @throws ReflectionException |
|
826 | + */ |
|
827 | + public function sold() |
|
828 | + { |
|
829 | + return $this->get_raw('TKT_sold'); |
|
830 | + } |
|
831 | + |
|
832 | + |
|
833 | + /** |
|
834 | + * Sets sold |
|
835 | + * |
|
836 | + * @param int $sold |
|
837 | + * @return void |
|
838 | + * @throws EE_Error |
|
839 | + * @throws ReflectionException |
|
840 | + */ |
|
841 | + public function set_sold($sold) |
|
842 | + { |
|
843 | + // sold can not go below zero |
|
844 | + $sold = max(0, $sold); |
|
845 | + $this->set('TKT_sold', $sold); |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + /** |
|
850 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
851 | + * associated datetimes. |
|
852 | + * |
|
853 | + * @param int $qty |
|
854 | + * @return boolean |
|
855 | + * @throws EE_Error |
|
856 | + * @throws InvalidArgumentException |
|
857 | + * @throws InvalidDataTypeException |
|
858 | + * @throws InvalidInterfaceException |
|
859 | + * @throws ReflectionException |
|
860 | + * @since 4.9.80.p |
|
861 | + */ |
|
862 | + public function increaseSold($qty = 1) |
|
863 | + { |
|
864 | + $qty = absint($qty); |
|
865 | + // increment sold and decrement reserved datetime quantities simultaneously |
|
866 | + // don't worry about failures, because they must have already had a spot reserved |
|
867 | + $this->increaseSoldForDatetimes($qty); |
|
868 | + // Increment and decrement ticket quantities simultaneously |
|
869 | + $success = $this->adjustNumericFieldsInDb( |
|
870 | + [ |
|
871 | + 'TKT_reserved' => $qty * -1, |
|
872 | + 'TKT_sold' => $qty, |
|
873 | + ] |
|
874 | + ); |
|
875 | + do_action( |
|
876 | + 'AHEE__EE_Ticket__increase_sold', |
|
877 | + $this, |
|
878 | + $qty, |
|
879 | + $this->sold(), |
|
880 | + $success |
|
881 | + ); |
|
882 | + return $success; |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + /** |
|
887 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
888 | + * |
|
889 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
|
890 | + * counts), Negative means to decreases old counts (and increase reserved counts). |
|
891 | + * @param EE_Datetime[] $datetimes |
|
892 | + * @throws EE_Error |
|
893 | + * @throws InvalidArgumentException |
|
894 | + * @throws InvalidDataTypeException |
|
895 | + * @throws InvalidInterfaceException |
|
896 | + * @throws ReflectionException |
|
897 | + * @since 4.9.80.p |
|
898 | + */ |
|
899 | + protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
900 | + { |
|
901 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
902 | + foreach ($datetimes as $datetime) { |
|
903 | + $datetime->increaseSold($qty); |
|
904 | + } |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + /** |
|
909 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
910 | + * DB and then updates the model objects. |
|
911 | + * Does not affect the reserved counts. |
|
912 | + * |
|
913 | + * @param int $qty |
|
914 | + * @return boolean |
|
915 | + * @throws EE_Error |
|
916 | + * @throws InvalidArgumentException |
|
917 | + * @throws InvalidDataTypeException |
|
918 | + * @throws InvalidInterfaceException |
|
919 | + * @throws ReflectionException |
|
920 | + * @since 4.9.80.p |
|
921 | + */ |
|
922 | + public function decreaseSold($qty = 1) |
|
923 | + { |
|
924 | + $qty = absint($qty); |
|
925 | + $this->decreaseSoldForDatetimes($qty); |
|
926 | + $success = $this->adjustNumericFieldsInDb( |
|
927 | + [ |
|
928 | + 'TKT_sold' => $qty * -1, |
|
929 | + ] |
|
930 | + ); |
|
931 | + do_action( |
|
932 | + 'AHEE__EE_Ticket__decrease_sold', |
|
933 | + $this, |
|
934 | + $qty, |
|
935 | + $this->sold(), |
|
936 | + $success |
|
937 | + ); |
|
938 | + return $success; |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * Decreases sold on related datetimes |
|
944 | + * |
|
945 | + * @param int $qty |
|
946 | + * @param EE_Datetime[] $datetimes |
|
947 | + * @return void |
|
948 | + * @throws EE_Error |
|
949 | + * @throws InvalidArgumentException |
|
950 | + * @throws InvalidDataTypeException |
|
951 | + * @throws InvalidInterfaceException |
|
952 | + * @throws ReflectionException |
|
953 | + * @since 4.9.80.p |
|
954 | + */ |
|
955 | + protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
956 | + { |
|
957 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
958 | + if (is_array($datetimes)) { |
|
959 | + foreach ($datetimes as $datetime) { |
|
960 | + if ($datetime instanceof EE_Datetime) { |
|
961 | + $datetime->decreaseSold($qty); |
|
962 | + } |
|
963 | + } |
|
964 | + } |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + /** |
|
969 | + * Gets qty of reserved tickets |
|
970 | + * |
|
971 | + * @return int |
|
972 | + * @throws EE_Error |
|
973 | + * @throws ReflectionException |
|
974 | + */ |
|
975 | + public function reserved() |
|
976 | + { |
|
977 | + return $this->get_raw('TKT_reserved'); |
|
978 | + } |
|
979 | + |
|
980 | + |
|
981 | + /** |
|
982 | + * Sets reserved |
|
983 | + * |
|
984 | + * @param int $reserved |
|
985 | + * @return void |
|
986 | + * @throws EE_Error |
|
987 | + * @throws ReflectionException |
|
988 | + */ |
|
989 | + public function set_reserved($reserved) |
|
990 | + { |
|
991 | + // reserved can not go below zero |
|
992 | + $reserved = max(0, (int) $reserved); |
|
993 | + $this->set('TKT_reserved', $reserved); |
|
994 | + } |
|
995 | + |
|
996 | + |
|
997 | + /** |
|
998 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
999 | + * |
|
1000 | + * @param int $qty |
|
1001 | + * @param string $source |
|
1002 | + * @return bool whether we successfully reserved the ticket or not. |
|
1003 | + * @throws EE_Error |
|
1004 | + * @throws InvalidArgumentException |
|
1005 | + * @throws ReflectionException |
|
1006 | + * @throws InvalidDataTypeException |
|
1007 | + * @throws InvalidInterfaceException |
|
1008 | + * @since 4.9.80.p |
|
1009 | + */ |
|
1010 | + public function increaseReserved($qty = 1, $source = 'unknown') |
|
1011 | + { |
|
1012 | + $qty = absint($qty); |
|
1013 | + do_action( |
|
1014 | + 'AHEE__EE_Ticket__increase_reserved__begin', |
|
1015 | + $this, |
|
1016 | + $qty, |
|
1017 | + $source |
|
1018 | + ); |
|
1019 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
1020 | + $success = false; |
|
1021 | + $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
1022 | + if ($datetimes_adjusted_successfully) { |
|
1023 | + $success = $this->incrementFieldConditionallyInDb( |
|
1024 | + 'TKT_reserved', |
|
1025 | + 'TKT_sold', |
|
1026 | + 'TKT_qty', |
|
1027 | + $qty |
|
1028 | + ); |
|
1029 | + if (! $success) { |
|
1030 | + // The datetimes were successfully bumped, but not the |
|
1031 | + // ticket. So we need to manually rollback the datetimes. |
|
1032 | + $this->decreaseReservedForDatetimes($qty); |
|
1033 | + } |
|
1034 | + } |
|
1035 | + do_action( |
|
1036 | + 'AHEE__EE_Ticket__increase_reserved', |
|
1037 | + $this, |
|
1038 | + $qty, |
|
1039 | + $this->reserved(), |
|
1040 | + $success |
|
1041 | + ); |
|
1042 | + return $success; |
|
1043 | + } |
|
1044 | + |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * Increases reserved counts on related datetimes |
|
1048 | + * |
|
1049 | + * @param int $qty |
|
1050 | + * @param EE_Datetime[] $datetimes |
|
1051 | + * @return boolean indicating success |
|
1052 | + * @throws EE_Error |
|
1053 | + * @throws InvalidArgumentException |
|
1054 | + * @throws InvalidDataTypeException |
|
1055 | + * @throws InvalidInterfaceException |
|
1056 | + * @throws ReflectionException |
|
1057 | + * @since 4.9.80.p |
|
1058 | + */ |
|
1059 | + protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
1060 | + { |
|
1061 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
1062 | + $datetimes_updated = []; |
|
1063 | + $limit_exceeded = false; |
|
1064 | + if (is_array($datetimes)) { |
|
1065 | + foreach ($datetimes as $datetime) { |
|
1066 | + if ($datetime instanceof EE_Datetime) { |
|
1067 | + if ($datetime->increaseReserved($qty)) { |
|
1068 | + $datetimes_updated[] = $datetime; |
|
1069 | + } else { |
|
1070 | + $limit_exceeded = true; |
|
1071 | + break; |
|
1072 | + } |
|
1073 | + } |
|
1074 | + } |
|
1075 | + // If somewhere along the way we detected a datetime whose |
|
1076 | + // limit was exceeded, do a manual rollback. |
|
1077 | + if ($limit_exceeded) { |
|
1078 | + $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
1079 | + return false; |
|
1080 | + } |
|
1081 | + } |
|
1082 | + return true; |
|
1083 | + } |
|
1084 | + |
|
1085 | + |
|
1086 | + /** |
|
1087 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
1088 | + * |
|
1089 | + * @param int $qty |
|
1090 | + * @param bool $adjust_datetimes |
|
1091 | + * @param string $source |
|
1092 | + * @return boolean |
|
1093 | + * @throws EE_Error |
|
1094 | + * @throws InvalidArgumentException |
|
1095 | + * @throws ReflectionException |
|
1096 | + * @throws InvalidDataTypeException |
|
1097 | + * @throws InvalidInterfaceException |
|
1098 | + * @since 4.9.80.p |
|
1099 | + */ |
|
1100 | + public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
1101 | + { |
|
1102 | + $qty = absint($qty); |
|
1103 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
1104 | + if ($adjust_datetimes) { |
|
1105 | + $this->decreaseReservedForDatetimes($qty); |
|
1106 | + } |
|
1107 | + $success = $this->adjustNumericFieldsInDb( |
|
1108 | + [ |
|
1109 | + 'TKT_reserved' => $qty * -1, |
|
1110 | + ] |
|
1111 | + ); |
|
1112 | + do_action( |
|
1113 | + 'AHEE__EE_Ticket__decrease_reserved', |
|
1114 | + $this, |
|
1115 | + $qty, |
|
1116 | + $this->reserved(), |
|
1117 | + $success |
|
1118 | + ); |
|
1119 | + return $success; |
|
1120 | + } |
|
1121 | + |
|
1122 | + |
|
1123 | + /** |
|
1124 | + * Decreases the reserved count on the specified datetimes. |
|
1125 | + * |
|
1126 | + * @param int $qty |
|
1127 | + * @param EE_Datetime[] $datetimes |
|
1128 | + * @throws EE_Error |
|
1129 | + * @throws InvalidArgumentException |
|
1130 | + * @throws ReflectionException |
|
1131 | + * @throws InvalidDataTypeException |
|
1132 | + * @throws InvalidInterfaceException |
|
1133 | + * @since 4.9.80.p |
|
1134 | + */ |
|
1135 | + protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
1136 | + { |
|
1137 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
1138 | + foreach ($datetimes as $datetime) { |
|
1139 | + if ($datetime instanceof EE_Datetime) { |
|
1140 | + $datetime->decreaseReserved($qty); |
|
1141 | + } |
|
1142 | + } |
|
1143 | + } |
|
1144 | + |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * Gets ticket quantity |
|
1148 | + * |
|
1149 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
1150 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
1151 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
1152 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
1153 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
1154 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
1155 | + * @return int |
|
1156 | + * @throws EE_Error |
|
1157 | + * @throws ReflectionException |
|
1158 | + */ |
|
1159 | + public function qty($context = '') |
|
1160 | + { |
|
1161 | + switch ($context) { |
|
1162 | + case 'reg_limit': |
|
1163 | + return $this->real_quantity_on_ticket(); |
|
1164 | + case 'saleable': |
|
1165 | + return $this->real_quantity_on_ticket('saleable'); |
|
1166 | + default: |
|
1167 | + return $this->get_raw('TKT_qty'); |
|
1168 | + } |
|
1169 | + } |
|
1170 | + |
|
1171 | + |
|
1172 | + /** |
|
1173 | + * Gets ticket quantity |
|
1174 | + * |
|
1175 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
1176 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
1177 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
1178 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
1179 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
1180 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
1181 | + * set to 0 for all related datetimes |
|
1182 | + * @return int |
|
1183 | + * @throws EE_Error |
|
1184 | + * @throws ReflectionException |
|
1185 | + */ |
|
1186 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
1187 | + { |
|
1188 | + $raw = $this->get_raw('TKT_qty'); |
|
1189 | + // return immediately if it's zero |
|
1190 | + if ($raw === 0) { |
|
1191 | + return $raw; |
|
1192 | + } |
|
1193 | + // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
1194 | + // ensure qty doesn't exceed raw value for THIS ticket |
|
1195 | + $qty = min(EE_INF, $raw); |
|
1196 | + // echo "\n . qty: " . $qty . '<br />'; |
|
1197 | + // calculate this ticket's total sales and reservations |
|
1198 | + $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
1199 | + // echo "\n . sold: " . $this->sold() . '<br />'; |
|
1200 | + // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
1201 | + // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
1202 | + // first we need to calculate the maximum number of tickets available for the datetime |
|
1203 | + // do we want data for one datetime or all of them ? |
|
1204 | + $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : []; |
|
1205 | + $datetimes = $this->datetimes($query_params); |
|
1206 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
1207 | + foreach ($datetimes as $datetime) { |
|
1208 | + if ($datetime instanceof EE_Datetime) { |
|
1209 | + $datetime->refresh_from_db(); |
|
1210 | + // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
1211 | + // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
1212 | + // initialize with no restrictions for each datetime |
|
1213 | + // but adjust datetime qty based on datetime reg limit |
|
1214 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
1215 | + // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
1216 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1217 | + // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
1218 | + // and reservations for this datetime, that do NOT include sales and reservations |
|
1219 | + // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
1220 | + if ($context === 'saleable') { |
|
1221 | + $datetime_qty = max( |
|
1222 | + $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
1223 | + 0 |
|
1224 | + ); |
|
1225 | + // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
1226 | + // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
1227 | + // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
1228 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1229 | + $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
1230 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
1231 | + } |
|
1232 | + $qty = min($datetime_qty, $qty); |
|
1233 | + // echo "\n . . qty: " . $qty . '<br />'; |
|
1234 | + } |
|
1235 | + } |
|
1236 | + } |
|
1237 | + // NOW that we know the maximum number of tickets available for the datetime |
|
1238 | + // we can finally factor in the details for this specific ticket |
|
1239 | + if ($qty > 0 && $context === 'saleable') { |
|
1240 | + // and subtract the sales for THIS ticket |
|
1241 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
1242 | + // echo "\n . qty: " . $qty . '<br />'; |
|
1243 | + } |
|
1244 | + // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
1245 | + return $qty; |
|
1246 | + } |
|
1247 | + |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
1251 | + * |
|
1252 | + * @param int $qty |
|
1253 | + * @return void |
|
1254 | + * @throws EE_Error |
|
1255 | + * @throws ReflectionException |
|
1256 | + */ |
|
1257 | + public function set_qty($qty) |
|
1258 | + { |
|
1259 | + $datetimes = $this->datetimes(); |
|
1260 | + foreach ($datetimes as $datetime) { |
|
1261 | + if ($datetime instanceof EE_Datetime) { |
|
1262 | + $qty = min($qty, $datetime->reg_limit()); |
|
1263 | + } |
|
1264 | + } |
|
1265 | + $this->set('TKT_qty', $qty); |
|
1266 | + } |
|
1267 | + |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Gets uses |
|
1271 | + * |
|
1272 | + * @return int |
|
1273 | + * @throws EE_Error |
|
1274 | + * @throws ReflectionException |
|
1275 | + */ |
|
1276 | + public function uses() |
|
1277 | + { |
|
1278 | + return $this->get('TKT_uses'); |
|
1279 | + } |
|
1280 | + |
|
1281 | + |
|
1282 | + /** |
|
1283 | + * Sets uses |
|
1284 | + * |
|
1285 | + * @param int $uses |
|
1286 | + * @return void |
|
1287 | + * @throws EE_Error |
|
1288 | + * @throws ReflectionException |
|
1289 | + */ |
|
1290 | + public function set_uses($uses) |
|
1291 | + { |
|
1292 | + $this->set('TKT_uses', $uses); |
|
1293 | + } |
|
1294 | + |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * returns whether ticket is required or not. |
|
1298 | + * |
|
1299 | + * @return boolean |
|
1300 | + * @throws EE_Error |
|
1301 | + * @throws ReflectionException |
|
1302 | + */ |
|
1303 | + public function required() |
|
1304 | + { |
|
1305 | + return $this->get('TKT_required'); |
|
1306 | + } |
|
1307 | + |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * sets the TKT_required property |
|
1311 | + * |
|
1312 | + * @param boolean $required |
|
1313 | + * @return void |
|
1314 | + * @throws EE_Error |
|
1315 | + * @throws ReflectionException |
|
1316 | + */ |
|
1317 | + public function set_required($required) |
|
1318 | + { |
|
1319 | + $this->set('TKT_required', $required); |
|
1320 | + } |
|
1321 | + |
|
1322 | + |
|
1323 | + /** |
|
1324 | + * Gets taxable |
|
1325 | + * |
|
1326 | + * @return boolean |
|
1327 | + * @throws EE_Error |
|
1328 | + * @throws ReflectionException |
|
1329 | + */ |
|
1330 | + public function taxable() |
|
1331 | + { |
|
1332 | + return $this->get('TKT_taxable'); |
|
1333 | + } |
|
1334 | + |
|
1335 | + |
|
1336 | + /** |
|
1337 | + * Sets taxable |
|
1338 | + * |
|
1339 | + * @param boolean $taxable |
|
1340 | + * @return void |
|
1341 | + * @throws EE_Error |
|
1342 | + * @throws ReflectionException |
|
1343 | + */ |
|
1344 | + public function set_taxable($taxable) |
|
1345 | + { |
|
1346 | + $this->set('TKT_taxable', $taxable); |
|
1347 | + } |
|
1348 | + |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * Gets is_default |
|
1352 | + * |
|
1353 | + * @return boolean |
|
1354 | + * @throws EE_Error |
|
1355 | + * @throws ReflectionException |
|
1356 | + */ |
|
1357 | + public function is_default() |
|
1358 | + { |
|
1359 | + return $this->get('TKT_is_default'); |
|
1360 | + } |
|
1361 | + |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * Sets is_default |
|
1365 | + * |
|
1366 | + * @param boolean $is_default |
|
1367 | + * @return void |
|
1368 | + * @throws EE_Error |
|
1369 | + * @throws ReflectionException |
|
1370 | + */ |
|
1371 | + public function set_is_default($is_default) |
|
1372 | + { |
|
1373 | + $this->set('TKT_is_default', $is_default); |
|
1374 | + } |
|
1375 | + |
|
1376 | + |
|
1377 | + /** |
|
1378 | + * Gets order |
|
1379 | + * |
|
1380 | + * @return int |
|
1381 | + * @throws EE_Error |
|
1382 | + * @throws ReflectionException |
|
1383 | + */ |
|
1384 | + public function order() |
|
1385 | + { |
|
1386 | + return $this->get('TKT_order'); |
|
1387 | + } |
|
1388 | + |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * Sets order |
|
1392 | + * |
|
1393 | + * @param int $order |
|
1394 | + * @return void |
|
1395 | + * @throws EE_Error |
|
1396 | + * @throws ReflectionException |
|
1397 | + */ |
|
1398 | + public function set_order($order) |
|
1399 | + { |
|
1400 | + $this->set('TKT_order', $order); |
|
1401 | + } |
|
1402 | + |
|
1403 | + |
|
1404 | + /** |
|
1405 | + * Gets row |
|
1406 | + * |
|
1407 | + * @return int |
|
1408 | + * @throws EE_Error |
|
1409 | + * @throws ReflectionException |
|
1410 | + */ |
|
1411 | + public function row() |
|
1412 | + { |
|
1413 | + return $this->get('TKT_row'); |
|
1414 | + } |
|
1415 | + |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * Sets row |
|
1419 | + * |
|
1420 | + * @param int $row |
|
1421 | + * @return void |
|
1422 | + * @throws EE_Error |
|
1423 | + * @throws ReflectionException |
|
1424 | + */ |
|
1425 | + public function set_row($row) |
|
1426 | + { |
|
1427 | + $this->set('TKT_row', $row); |
|
1428 | + } |
|
1429 | + |
|
1430 | + |
|
1431 | + /** |
|
1432 | + * Gets deleted |
|
1433 | + * |
|
1434 | + * @return boolean |
|
1435 | + * @throws EE_Error |
|
1436 | + * @throws ReflectionException |
|
1437 | + */ |
|
1438 | + public function deleted() |
|
1439 | + { |
|
1440 | + return $this->get('TKT_deleted'); |
|
1441 | + } |
|
1442 | + |
|
1443 | + |
|
1444 | + /** |
|
1445 | + * Sets deleted |
|
1446 | + * |
|
1447 | + * @param boolean $deleted |
|
1448 | + * @return void |
|
1449 | + * @throws EE_Error |
|
1450 | + * @throws ReflectionException |
|
1451 | + */ |
|
1452 | + public function set_deleted($deleted) |
|
1453 | + { |
|
1454 | + $this->set('TKT_deleted', $deleted); |
|
1455 | + } |
|
1456 | + |
|
1457 | + |
|
1458 | + /** |
|
1459 | + * Gets parent |
|
1460 | + * |
|
1461 | + * @return int |
|
1462 | + * @throws EE_Error |
|
1463 | + * @throws ReflectionException |
|
1464 | + */ |
|
1465 | + public function parent_ID() |
|
1466 | + { |
|
1467 | + return $this->get('TKT_parent'); |
|
1468 | + } |
|
1469 | + |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Sets parent |
|
1473 | + * |
|
1474 | + * @param int $parent |
|
1475 | + * @return void |
|
1476 | + * @throws EE_Error |
|
1477 | + * @throws ReflectionException |
|
1478 | + */ |
|
1479 | + public function set_parent_ID($parent) |
|
1480 | + { |
|
1481 | + $this->set('TKT_parent', $parent); |
|
1482 | + } |
|
1483 | + |
|
1484 | + |
|
1485 | + /** |
|
1486 | + * @return boolean |
|
1487 | + * @throws EE_Error |
|
1488 | + * @throws InvalidArgumentException |
|
1489 | + * @throws InvalidDataTypeException |
|
1490 | + * @throws InvalidInterfaceException |
|
1491 | + * @throws ReflectionException |
|
1492 | + */ |
|
1493 | + public function reverse_calculate() |
|
1494 | + { |
|
1495 | + return $this->get('TKT_reverse_calculate'); |
|
1496 | + } |
|
1497 | + |
|
1498 | + |
|
1499 | + /** |
|
1500 | + * @param boolean $reverse_calculate |
|
1501 | + * @throws EE_Error |
|
1502 | + * @throws InvalidArgumentException |
|
1503 | + * @throws InvalidDataTypeException |
|
1504 | + * @throws InvalidInterfaceException |
|
1505 | + * @throws ReflectionException |
|
1506 | + */ |
|
1507 | + public function set_reverse_calculate($reverse_calculate) |
|
1508 | + { |
|
1509 | + $this->set('TKT_reverse_calculate', $reverse_calculate); |
|
1510 | + } |
|
1511 | + |
|
1512 | + |
|
1513 | + /** |
|
1514 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
1515 | + * |
|
1516 | + * @return string |
|
1517 | + * @throws EE_Error |
|
1518 | + * @throws ReflectionException |
|
1519 | + */ |
|
1520 | + public function name_and_info() |
|
1521 | + { |
|
1522 | + $times = []; |
|
1523 | + foreach ($this->datetimes() as $datetime) { |
|
1524 | + $times[] = $datetime->start_date_and_time(); |
|
1525 | + } |
|
1526 | + return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
1527 | + } |
|
1528 | + |
|
1529 | + |
|
1530 | + /** |
|
1531 | + * Gets name |
|
1532 | + * |
|
1533 | + * @return string |
|
1534 | + * @throws EE_Error |
|
1535 | + * @throws ReflectionException |
|
1536 | + */ |
|
1537 | + public function name() |
|
1538 | + { |
|
1539 | + return $this->get('TKT_name'); |
|
1540 | + } |
|
1541 | + |
|
1542 | + |
|
1543 | + /** |
|
1544 | + * Gets price |
|
1545 | + * |
|
1546 | + * @return float |
|
1547 | + * @throws EE_Error |
|
1548 | + * @throws ReflectionException |
|
1549 | + */ |
|
1550 | + public function price() |
|
1551 | + { |
|
1552 | + return $this->get('TKT_price'); |
|
1553 | + } |
|
1554 | + |
|
1555 | + |
|
1556 | + /** |
|
1557 | + * Gets all the registrations for this ticket |
|
1558 | + * |
|
1559 | + * @param array $query_params @see |
|
1560 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1561 | + * @return EE_Registration[]|EE_Base_Class[] |
|
1562 | + * @throws EE_Error |
|
1563 | + * @throws ReflectionException |
|
1564 | + */ |
|
1565 | + public function registrations($query_params = []) |
|
1566 | + { |
|
1567 | + return $this->get_many_related('Registration', $query_params); |
|
1568 | + } |
|
1569 | + |
|
1570 | + |
|
1571 | + /** |
|
1572 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
1573 | + * |
|
1574 | + * @return int |
|
1575 | + * @throws EE_Error |
|
1576 | + * @throws ReflectionException |
|
1577 | + */ |
|
1578 | + public function update_tickets_sold() |
|
1579 | + { |
|
1580 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
1581 | + [ |
|
1582 | + [ |
|
1583 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
1584 | + 'REG_deleted' => 0, |
|
1585 | + ], |
|
1586 | + ] |
|
1587 | + ); |
|
1588 | + $this->set_sold($count_regs_for_this_ticket); |
|
1589 | + $this->save(); |
|
1590 | + return $count_regs_for_this_ticket; |
|
1591 | + } |
|
1592 | + |
|
1593 | + |
|
1594 | + /** |
|
1595 | + * Counts the registrations for this ticket |
|
1596 | + * |
|
1597 | + * @param array $query_params @see |
|
1598 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1599 | + * @return int |
|
1600 | + * @throws EE_Error |
|
1601 | + * @throws ReflectionException |
|
1602 | + */ |
|
1603 | + public function count_registrations($query_params = []) |
|
1604 | + { |
|
1605 | + return $this->count_related('Registration', $query_params); |
|
1606 | + } |
|
1607 | + |
|
1608 | + |
|
1609 | + /** |
|
1610 | + * Implementation for EEI_Has_Icon interface method. |
|
1611 | + * |
|
1612 | + * @return string |
|
1613 | + * @see EEI_Visual_Representation for comments |
|
1614 | + */ |
|
1615 | + public function get_icon() |
|
1616 | + { |
|
1617 | + return '<span class="dashicons dashicons-tickets-alt"/>'; |
|
1618 | + } |
|
1619 | + |
|
1620 | + |
|
1621 | + /** |
|
1622 | + * Implementation of the EEI_Event_Relation interface method |
|
1623 | + * |
|
1624 | + * @return EE_Event |
|
1625 | + * @throws EE_Error |
|
1626 | + * @throws UnexpectedEntityException |
|
1627 | + * @throws ReflectionException |
|
1628 | + * @see EEI_Event_Relation for comments |
|
1629 | + */ |
|
1630 | + public function get_related_event() |
|
1631 | + { |
|
1632 | + // get one datetime to use for getting the event |
|
1633 | + $datetime = $this->first_datetime(); |
|
1634 | + if (! $datetime instanceof EE_Datetime) { |
|
1635 | + throw new UnexpectedEntityException( |
|
1636 | + $datetime, |
|
1637 | + 'EE_Datetime', |
|
1638 | + sprintf( |
|
1639 | + __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
1640 | + $this->name() |
|
1641 | + ) |
|
1642 | + ); |
|
1643 | + } |
|
1644 | + $event = $datetime->event(); |
|
1645 | + if (! $event instanceof EE_Event) { |
|
1646 | + throw new UnexpectedEntityException( |
|
1647 | + $event, |
|
1648 | + 'EE_Event', |
|
1649 | + sprintf( |
|
1650 | + __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
1651 | + $this->name() |
|
1652 | + ) |
|
1653 | + ); |
|
1654 | + } |
|
1655 | + return $event; |
|
1656 | + } |
|
1657 | + |
|
1658 | + |
|
1659 | + /** |
|
1660 | + * Implementation of the EEI_Event_Relation interface method |
|
1661 | + * |
|
1662 | + * @return string |
|
1663 | + * @throws UnexpectedEntityException |
|
1664 | + * @throws EE_Error |
|
1665 | + * @throws ReflectionException |
|
1666 | + * @see EEI_Event_Relation for comments |
|
1667 | + */ |
|
1668 | + public function get_event_name() |
|
1669 | + { |
|
1670 | + $event = $this->get_related_event(); |
|
1671 | + return $event instanceof EE_Event ? $event->name() : ''; |
|
1672 | + } |
|
1673 | + |
|
1674 | + |
|
1675 | + /** |
|
1676 | + * Implementation of the EEI_Event_Relation interface method |
|
1677 | + * |
|
1678 | + * @return int |
|
1679 | + * @throws UnexpectedEntityException |
|
1680 | + * @throws EE_Error |
|
1681 | + * @throws ReflectionException |
|
1682 | + * @see EEI_Event_Relation for comments |
|
1683 | + */ |
|
1684 | + public function get_event_ID() |
|
1685 | + { |
|
1686 | + $event = $this->get_related_event(); |
|
1687 | + return $event instanceof EE_Event ? $event->ID() : 0; |
|
1688 | + } |
|
1689 | + |
|
1690 | + |
|
1691 | + /** |
|
1692 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
1693 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
1694 | + * If there are none then it can be permanently deleted. |
|
1695 | + * |
|
1696 | + * @return bool |
|
1697 | + * @throws EE_Error |
|
1698 | + * @throws ReflectionException |
|
1699 | + */ |
|
1700 | + public function is_permanently_deleteable() |
|
1701 | + { |
|
1702 | + return $this->count_registrations() === 0; |
|
1703 | + } |
|
1704 | + |
|
1705 | + |
|
1706 | + /** |
|
1707 | + * @return int |
|
1708 | + * @throws EE_Error |
|
1709 | + * @throws ReflectionException |
|
1710 | + * @since $VID:$ |
|
1711 | + */ |
|
1712 | + public function visibility(): int |
|
1713 | + { |
|
1714 | + return $this->get('TKT_visibility'); |
|
1715 | + } |
|
1716 | + |
|
1717 | + |
|
1718 | + /** |
|
1719 | + * @return int |
|
1720 | + * @throws EE_Error |
|
1721 | + * @throws ReflectionException |
|
1722 | + * @since $VID:$ |
|
1723 | + */ |
|
1724 | + public function isHidden(): int |
|
1725 | + { |
|
1726 | + return $this->visibility() === EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE; |
|
1727 | + } |
|
1728 | + |
|
1729 | + |
|
1730 | + /** |
|
1731 | + * @return int |
|
1732 | + * @throws EE_Error |
|
1733 | + * @throws ReflectionException |
|
1734 | + * @since $VID:$ |
|
1735 | + */ |
|
1736 | + public function isNotHidden(): int |
|
1737 | + { |
|
1738 | + return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE; |
|
1739 | + } |
|
1740 | + |
|
1741 | + |
|
1742 | + /** |
|
1743 | + * @return int |
|
1744 | + * @throws EE_Error |
|
1745 | + * @throws ReflectionException |
|
1746 | + * @since $VID:$ |
|
1747 | + */ |
|
1748 | + public function isPublicOnly(): int |
|
1749 | + { |
|
1750 | + return $this->isNotHidden() && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE; |
|
1751 | + } |
|
1752 | + |
|
1753 | + |
|
1754 | + /** |
|
1755 | + * @return int |
|
1756 | + * @throws EE_Error |
|
1757 | + * @throws ReflectionException |
|
1758 | + * @since $VID:$ |
|
1759 | + */ |
|
1760 | + public function isMembersOnly(): int |
|
1761 | + { |
|
1762 | + return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE |
|
1763 | + && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE; |
|
1764 | + } |
|
1765 | + |
|
1766 | + |
|
1767 | + /** |
|
1768 | + * @return int |
|
1769 | + * @throws EE_Error |
|
1770 | + * @throws ReflectionException |
|
1771 | + * @since $VID:$ |
|
1772 | + */ |
|
1773 | + public function isAdminsOnly(): int |
|
1774 | + { |
|
1775 | + return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE |
|
1776 | + && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE; |
|
1777 | + } |
|
1778 | + |
|
1779 | + |
|
1780 | + /** |
|
1781 | + * @return int |
|
1782 | + * @throws EE_Error |
|
1783 | + * @throws ReflectionException |
|
1784 | + * @since $VID:$ |
|
1785 | + */ |
|
1786 | + public function isAdminUiOnly(): int |
|
1787 | + { |
|
1788 | + return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE |
|
1789 | + && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE; |
|
1790 | + } |
|
1791 | + |
|
1792 | + |
|
1793 | + /** |
|
1794 | + * @param int $visibility |
|
1795 | + * @throws EE_Error |
|
1796 | + * @throws ReflectionException |
|
1797 | + * @since $VID:$ |
|
1798 | + */ |
|
1799 | + public function set_visibility(int $visibility) |
|
1800 | + { |
|
1801 | + |
|
1802 | + $ticket_visibility_options = $this->_model->ticketVisibilityOptions(); |
|
1803 | + $ticket_visibility = -1; |
|
1804 | + foreach ($ticket_visibility_options as $ticket_visibility_option) { |
|
1805 | + if ($visibility === $ticket_visibility_option) { |
|
1806 | + $ticket_visibility = $visibility; |
|
1807 | + } |
|
1808 | + } |
|
1809 | + if ($ticket_visibility === -1) { |
|
1810 | + throw new DomainException( |
|
1811 | + sprintf( |
|
1812 | + esc_html__( |
|
1813 | + 'The supplied ticket visibility setting of "%1$s" is not valid. It needs to match one of the keys in the following array:%2$s %3$s ', |
|
1814 | + 'event_espresso' |
|
1815 | + ), |
|
1816 | + $visibility, |
|
1817 | + '<br />', |
|
1818 | + var_export($ticket_visibility_options, true) |
|
1819 | + ) |
|
1820 | + ); |
|
1821 | + } |
|
1822 | + $this->set('TKT_visibility', $ticket_visibility); |
|
1823 | + } |
|
1824 | + |
|
1825 | + |
|
1826 | + /******************************************************************* |
|
1827 | 1827 | *********************** DEPRECATED METHODS ********************** |
1828 | 1828 | *******************************************************************/ |
1829 | 1829 | |
1830 | 1830 | |
1831 | - /** |
|
1832 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
1833 | - * associated datetimes. |
|
1834 | - * |
|
1835 | - * @param int $qty |
|
1836 | - * @return void |
|
1837 | - * @throws EE_Error |
|
1838 | - * @throws InvalidArgumentException |
|
1839 | - * @throws InvalidDataTypeException |
|
1840 | - * @throws InvalidInterfaceException |
|
1841 | - * @throws ReflectionException |
|
1842 | - * @deprecated 4.9.80.p |
|
1843 | - */ |
|
1844 | - public function increase_sold($qty = 1) |
|
1845 | - { |
|
1846 | - EE_Error::doing_it_wrong( |
|
1847 | - __FUNCTION__, |
|
1848 | - esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
1849 | - '4.9.80.p', |
|
1850 | - '5.0.0.p' |
|
1851 | - ); |
|
1852 | - $this->increaseSold($qty); |
|
1853 | - } |
|
1854 | - |
|
1855 | - |
|
1856 | - /** |
|
1857 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
1858 | - * |
|
1859 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
1860 | - * Negative means to decreases old counts (and increase reserved counts). |
|
1861 | - * @throws EE_Error |
|
1862 | - * @throws InvalidArgumentException |
|
1863 | - * @throws InvalidDataTypeException |
|
1864 | - * @throws InvalidInterfaceException |
|
1865 | - * @throws ReflectionException |
|
1866 | - * @deprecated 4.9.80.p |
|
1867 | - */ |
|
1868 | - protected function _increase_sold_for_datetimes($qty) |
|
1869 | - { |
|
1870 | - EE_Error::doing_it_wrong( |
|
1871 | - __FUNCTION__, |
|
1872 | - esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
1873 | - '4.9.80.p', |
|
1874 | - '5.0.0.p' |
|
1875 | - ); |
|
1876 | - $this->increaseSoldForDatetimes($qty); |
|
1877 | - } |
|
1878 | - |
|
1879 | - |
|
1880 | - /** |
|
1881 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
1882 | - * DB and then updates the model objects. |
|
1883 | - * Does not affect the reserved counts. |
|
1884 | - * |
|
1885 | - * @param int $qty |
|
1886 | - * @return void |
|
1887 | - * @throws EE_Error |
|
1888 | - * @throws InvalidArgumentException |
|
1889 | - * @throws InvalidDataTypeException |
|
1890 | - * @throws InvalidInterfaceException |
|
1891 | - * @throws ReflectionException |
|
1892 | - * @deprecated 4.9.80.p |
|
1893 | - */ |
|
1894 | - public function decrease_sold($qty = 1) |
|
1895 | - { |
|
1896 | - EE_Error::doing_it_wrong( |
|
1897 | - __FUNCTION__, |
|
1898 | - esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
1899 | - '4.9.80.p', |
|
1900 | - '5.0.0.p' |
|
1901 | - ); |
|
1902 | - $this->decreaseSold($qty); |
|
1903 | - } |
|
1904 | - |
|
1905 | - |
|
1906 | - /** |
|
1907 | - * Decreases sold on related datetimes |
|
1908 | - * |
|
1909 | - * @param int $qty |
|
1910 | - * @return void |
|
1911 | - * @throws EE_Error |
|
1912 | - * @throws InvalidArgumentException |
|
1913 | - * @throws InvalidDataTypeException |
|
1914 | - * @throws InvalidInterfaceException |
|
1915 | - * @throws ReflectionException |
|
1916 | - * @deprecated 4.9.80.p |
|
1917 | - */ |
|
1918 | - protected function _decrease_sold_for_datetimes($qty = 1) |
|
1919 | - { |
|
1920 | - EE_Error::doing_it_wrong( |
|
1921 | - __FUNCTION__, |
|
1922 | - esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
1923 | - '4.9.80.p', |
|
1924 | - '5.0.0.p' |
|
1925 | - ); |
|
1926 | - $this->decreaseSoldForDatetimes($qty); |
|
1927 | - } |
|
1928 | - |
|
1929 | - |
|
1930 | - /** |
|
1931 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
1932 | - * |
|
1933 | - * @param int $qty |
|
1934 | - * @param string $source |
|
1935 | - * @return bool whether we successfully reserved the ticket or not. |
|
1936 | - * @throws EE_Error |
|
1937 | - * @throws InvalidArgumentException |
|
1938 | - * @throws ReflectionException |
|
1939 | - * @throws InvalidDataTypeException |
|
1940 | - * @throws InvalidInterfaceException |
|
1941 | - * @deprecated 4.9.80.p |
|
1942 | - */ |
|
1943 | - public function increase_reserved($qty = 1, $source = 'unknown') |
|
1944 | - { |
|
1945 | - EE_Error::doing_it_wrong( |
|
1946 | - __FUNCTION__, |
|
1947 | - esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
1948 | - '4.9.80.p', |
|
1949 | - '5.0.0.p' |
|
1950 | - ); |
|
1951 | - return $this->increaseReserved($qty); |
|
1952 | - } |
|
1953 | - |
|
1954 | - |
|
1955 | - /** |
|
1956 | - * Increases sold on related datetimes |
|
1957 | - * |
|
1958 | - * @param int $qty |
|
1959 | - * @return boolean indicating success |
|
1960 | - * @throws EE_Error |
|
1961 | - * @throws InvalidArgumentException |
|
1962 | - * @throws InvalidDataTypeException |
|
1963 | - * @throws InvalidInterfaceException |
|
1964 | - * @throws ReflectionException |
|
1965 | - * @deprecated 4.9.80.p |
|
1966 | - */ |
|
1967 | - protected function _increase_reserved_for_datetimes($qty = 1) |
|
1968 | - { |
|
1969 | - EE_Error::doing_it_wrong( |
|
1970 | - __FUNCTION__, |
|
1971 | - esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
1972 | - '4.9.80.p', |
|
1973 | - '5.0.0.p' |
|
1974 | - ); |
|
1975 | - return $this->increaseReservedForDatetimes($qty); |
|
1976 | - } |
|
1977 | - |
|
1978 | - |
|
1979 | - /** |
|
1980 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
1981 | - * |
|
1982 | - * @param int $qty |
|
1983 | - * @param bool $adjust_datetimes |
|
1984 | - * @param string $source |
|
1985 | - * @return void |
|
1986 | - * @throws EE_Error |
|
1987 | - * @throws InvalidArgumentException |
|
1988 | - * @throws ReflectionException |
|
1989 | - * @throws InvalidDataTypeException |
|
1990 | - * @throws InvalidInterfaceException |
|
1991 | - * @deprecated 4.9.80.p |
|
1992 | - */ |
|
1993 | - public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
1994 | - { |
|
1995 | - EE_Error::doing_it_wrong( |
|
1996 | - __FUNCTION__, |
|
1997 | - esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
1998 | - '4.9.80.p', |
|
1999 | - '5.0.0.p' |
|
2000 | - ); |
|
2001 | - $this->decreaseReserved($qty); |
|
2002 | - } |
|
2003 | - |
|
2004 | - |
|
2005 | - /** |
|
2006 | - * Decreases reserved on related datetimes |
|
2007 | - * |
|
2008 | - * @param int $qty |
|
2009 | - * @return void |
|
2010 | - * @throws EE_Error |
|
2011 | - * @throws InvalidArgumentException |
|
2012 | - * @throws ReflectionException |
|
2013 | - * @throws InvalidDataTypeException |
|
2014 | - * @throws InvalidInterfaceException |
|
2015 | - * @deprecated 4.9.80.p |
|
2016 | - */ |
|
2017 | - protected function _decrease_reserved_for_datetimes($qty = 1) |
|
2018 | - { |
|
2019 | - EE_Error::doing_it_wrong( |
|
2020 | - __FUNCTION__, |
|
2021 | - esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
2022 | - '4.9.80.p', |
|
2023 | - '5.0.0.p' |
|
2024 | - ); |
|
2025 | - $this->decreaseReservedForDatetimes($qty); |
|
2026 | - } |
|
1831 | + /** |
|
1832 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
1833 | + * associated datetimes. |
|
1834 | + * |
|
1835 | + * @param int $qty |
|
1836 | + * @return void |
|
1837 | + * @throws EE_Error |
|
1838 | + * @throws InvalidArgumentException |
|
1839 | + * @throws InvalidDataTypeException |
|
1840 | + * @throws InvalidInterfaceException |
|
1841 | + * @throws ReflectionException |
|
1842 | + * @deprecated 4.9.80.p |
|
1843 | + */ |
|
1844 | + public function increase_sold($qty = 1) |
|
1845 | + { |
|
1846 | + EE_Error::doing_it_wrong( |
|
1847 | + __FUNCTION__, |
|
1848 | + esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
1849 | + '4.9.80.p', |
|
1850 | + '5.0.0.p' |
|
1851 | + ); |
|
1852 | + $this->increaseSold($qty); |
|
1853 | + } |
|
1854 | + |
|
1855 | + |
|
1856 | + /** |
|
1857 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
1858 | + * |
|
1859 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
1860 | + * Negative means to decreases old counts (and increase reserved counts). |
|
1861 | + * @throws EE_Error |
|
1862 | + * @throws InvalidArgumentException |
|
1863 | + * @throws InvalidDataTypeException |
|
1864 | + * @throws InvalidInterfaceException |
|
1865 | + * @throws ReflectionException |
|
1866 | + * @deprecated 4.9.80.p |
|
1867 | + */ |
|
1868 | + protected function _increase_sold_for_datetimes($qty) |
|
1869 | + { |
|
1870 | + EE_Error::doing_it_wrong( |
|
1871 | + __FUNCTION__, |
|
1872 | + esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
1873 | + '4.9.80.p', |
|
1874 | + '5.0.0.p' |
|
1875 | + ); |
|
1876 | + $this->increaseSoldForDatetimes($qty); |
|
1877 | + } |
|
1878 | + |
|
1879 | + |
|
1880 | + /** |
|
1881 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
1882 | + * DB and then updates the model objects. |
|
1883 | + * Does not affect the reserved counts. |
|
1884 | + * |
|
1885 | + * @param int $qty |
|
1886 | + * @return void |
|
1887 | + * @throws EE_Error |
|
1888 | + * @throws InvalidArgumentException |
|
1889 | + * @throws InvalidDataTypeException |
|
1890 | + * @throws InvalidInterfaceException |
|
1891 | + * @throws ReflectionException |
|
1892 | + * @deprecated 4.9.80.p |
|
1893 | + */ |
|
1894 | + public function decrease_sold($qty = 1) |
|
1895 | + { |
|
1896 | + EE_Error::doing_it_wrong( |
|
1897 | + __FUNCTION__, |
|
1898 | + esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
1899 | + '4.9.80.p', |
|
1900 | + '5.0.0.p' |
|
1901 | + ); |
|
1902 | + $this->decreaseSold($qty); |
|
1903 | + } |
|
1904 | + |
|
1905 | + |
|
1906 | + /** |
|
1907 | + * Decreases sold on related datetimes |
|
1908 | + * |
|
1909 | + * @param int $qty |
|
1910 | + * @return void |
|
1911 | + * @throws EE_Error |
|
1912 | + * @throws InvalidArgumentException |
|
1913 | + * @throws InvalidDataTypeException |
|
1914 | + * @throws InvalidInterfaceException |
|
1915 | + * @throws ReflectionException |
|
1916 | + * @deprecated 4.9.80.p |
|
1917 | + */ |
|
1918 | + protected function _decrease_sold_for_datetimes($qty = 1) |
|
1919 | + { |
|
1920 | + EE_Error::doing_it_wrong( |
|
1921 | + __FUNCTION__, |
|
1922 | + esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
1923 | + '4.9.80.p', |
|
1924 | + '5.0.0.p' |
|
1925 | + ); |
|
1926 | + $this->decreaseSoldForDatetimes($qty); |
|
1927 | + } |
|
1928 | + |
|
1929 | + |
|
1930 | + /** |
|
1931 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
1932 | + * |
|
1933 | + * @param int $qty |
|
1934 | + * @param string $source |
|
1935 | + * @return bool whether we successfully reserved the ticket or not. |
|
1936 | + * @throws EE_Error |
|
1937 | + * @throws InvalidArgumentException |
|
1938 | + * @throws ReflectionException |
|
1939 | + * @throws InvalidDataTypeException |
|
1940 | + * @throws InvalidInterfaceException |
|
1941 | + * @deprecated 4.9.80.p |
|
1942 | + */ |
|
1943 | + public function increase_reserved($qty = 1, $source = 'unknown') |
|
1944 | + { |
|
1945 | + EE_Error::doing_it_wrong( |
|
1946 | + __FUNCTION__, |
|
1947 | + esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
1948 | + '4.9.80.p', |
|
1949 | + '5.0.0.p' |
|
1950 | + ); |
|
1951 | + return $this->increaseReserved($qty); |
|
1952 | + } |
|
1953 | + |
|
1954 | + |
|
1955 | + /** |
|
1956 | + * Increases sold on related datetimes |
|
1957 | + * |
|
1958 | + * @param int $qty |
|
1959 | + * @return boolean indicating success |
|
1960 | + * @throws EE_Error |
|
1961 | + * @throws InvalidArgumentException |
|
1962 | + * @throws InvalidDataTypeException |
|
1963 | + * @throws InvalidInterfaceException |
|
1964 | + * @throws ReflectionException |
|
1965 | + * @deprecated 4.9.80.p |
|
1966 | + */ |
|
1967 | + protected function _increase_reserved_for_datetimes($qty = 1) |
|
1968 | + { |
|
1969 | + EE_Error::doing_it_wrong( |
|
1970 | + __FUNCTION__, |
|
1971 | + esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
1972 | + '4.9.80.p', |
|
1973 | + '5.0.0.p' |
|
1974 | + ); |
|
1975 | + return $this->increaseReservedForDatetimes($qty); |
|
1976 | + } |
|
1977 | + |
|
1978 | + |
|
1979 | + /** |
|
1980 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
1981 | + * |
|
1982 | + * @param int $qty |
|
1983 | + * @param bool $adjust_datetimes |
|
1984 | + * @param string $source |
|
1985 | + * @return void |
|
1986 | + * @throws EE_Error |
|
1987 | + * @throws InvalidArgumentException |
|
1988 | + * @throws ReflectionException |
|
1989 | + * @throws InvalidDataTypeException |
|
1990 | + * @throws InvalidInterfaceException |
|
1991 | + * @deprecated 4.9.80.p |
|
1992 | + */ |
|
1993 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
1994 | + { |
|
1995 | + EE_Error::doing_it_wrong( |
|
1996 | + __FUNCTION__, |
|
1997 | + esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
1998 | + '4.9.80.p', |
|
1999 | + '5.0.0.p' |
|
2000 | + ); |
|
2001 | + $this->decreaseReserved($qty); |
|
2002 | + } |
|
2003 | + |
|
2004 | + |
|
2005 | + /** |
|
2006 | + * Decreases reserved on related datetimes |
|
2007 | + * |
|
2008 | + * @param int $qty |
|
2009 | + * @return void |
|
2010 | + * @throws EE_Error |
|
2011 | + * @throws InvalidArgumentException |
|
2012 | + * @throws ReflectionException |
|
2013 | + * @throws InvalidDataTypeException |
|
2014 | + * @throws InvalidInterfaceException |
|
2015 | + * @deprecated 4.9.80.p |
|
2016 | + */ |
|
2017 | + protected function _decrease_reserved_for_datetimes($qty = 1) |
|
2018 | + { |
|
2019 | + EE_Error::doing_it_wrong( |
|
2020 | + __FUNCTION__, |
|
2021 | + esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
2022 | + '4.9.80.p', |
|
2023 | + '5.0.0.p' |
|
2024 | + ); |
|
2025 | + $this->decreaseReservedForDatetimes($qty); |
|
2026 | + } |
|
2027 | 2027 | } |
@@ -22,201 +22,201 @@ |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - protected function _init_props() |
|
26 | - { |
|
27 | - $this->label = __('Line Item List Shortcodes', 'event_espresso'); |
|
28 | - $this->description = __('All shortcodes specific to line item lists', 'event_espresso'); |
|
29 | - $this->_shortcodes = array( |
|
30 | - '[TICKET_LINE_ITEM_LIST]' => __('Outputs a list of ticket line items.', 'event_espresso'), |
|
31 | - '[TAX_LINE_ITEM_LIST]' => __('Outputs a list of tax line items.', 'event_espresso'), |
|
32 | - '[ADDITIONAL_LINE_ITEM_LIST]' => __( |
|
33 | - 'Outputs a list of additional line items (other charges or discounts)', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]' => __('Outputs a list of price modifier line items', 'event_espresso'), |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - protected function _parser($shortcode) |
|
42 | - { |
|
43 | - |
|
44 | - switch ($shortcode) { |
|
45 | - case '[TICKET_LINE_ITEM_LIST]': |
|
46 | - return $this->_get_ticket_line_item_list(); |
|
47 | - |
|
48 | - case '[TAX_LINE_ITEM_LIST]': |
|
49 | - return $this->_get_tax_line_item_list(); |
|
50 | - |
|
51 | - case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
52 | - return $this->_get_price_mod_line_item_list(); |
|
53 | - |
|
54 | - case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
55 | - return $this->_get_additional_line_item_list(); |
|
56 | - |
|
57 | - default: |
|
58 | - return ''; |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
65 | - * |
|
66 | - * @since 4.5.0 |
|
67 | - * |
|
68 | - * @return string parsed ticket line item list. |
|
69 | - */ |
|
70 | - private function _get_ticket_line_item_list() |
|
71 | - { |
|
72 | - $this->_validate_list_requirements(); |
|
73 | - |
|
74 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
75 | - return ''; |
|
76 | - } |
|
77 | - |
|
78 | - $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
79 | - |
|
80 | - $ticket = $this->_data['data']; |
|
81 | - $templates = $this->_extra_data['template']; |
|
82 | - $addressee_obj = $this->_extra_data['data']; |
|
83 | - |
|
84 | - // made it here so we have an EE_Ticket, so we should have what we need. |
|
85 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
87 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
88 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
89 | - |
|
90 | - $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
91 | - : $templates['ticket_line_item_pms']; |
|
92 | - |
|
93 | - if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
94 | - return ''; |
|
95 | - } |
|
96 | - |
|
97 | - // now we just return the appropriate template parsed for each ticket. |
|
98 | - return $this->_shortcode_helper->parse_line_item_list_template( |
|
99 | - $template, |
|
100 | - $ticket_line_item, |
|
101 | - $valid_shortcodes, |
|
102 | - $this->_extra_data |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
109 | - * |
|
110 | - * @return string parsed tax line item list. |
|
111 | - * @throws EE_Error |
|
112 | - * @since 4.5.0 |
|
113 | - */ |
|
114 | - private function _get_tax_line_item_list() |
|
115 | - { |
|
116 | - /** @var EE_Admin_Config $admin_config */ |
|
117 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
118 | - if ($admin_config->useAdvancedEditor()) { |
|
119 | - return ''; |
|
120 | - } |
|
121 | - $this->_validate_list_requirements(); |
|
122 | - |
|
123 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
124 | - return ''; |
|
125 | - } |
|
126 | - |
|
127 | - // made it here so we're good to go. |
|
128 | - $valid_shortcodes = array('line_item'); |
|
129 | - $templates = $this->_data['template']; |
|
130 | - |
|
131 | - $tax_line_items = $this->_data['data']->tax_line_items; |
|
132 | - $line_item_list = ''; |
|
133 | - foreach ($tax_line_items as $line_item) { |
|
134 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
135 | - $templates['tax_line_item_list'], |
|
136 | - $line_item, |
|
137 | - $valid_shortcodes, |
|
138 | - $this->_extra_data |
|
139 | - ); |
|
140 | - } |
|
141 | - |
|
142 | - return $line_item_list; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
147 | - * |
|
148 | - * @since 4.5.0 |
|
149 | - * |
|
150 | - * @return string parsed other line item list. |
|
151 | - */ |
|
152 | - private function _get_additional_line_item_list() |
|
153 | - { |
|
154 | - |
|
155 | - $this->_validate_list_requirements(); |
|
156 | - |
|
157 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
158 | - return ''; |
|
159 | - } |
|
160 | - |
|
161 | - // made it here so we're good to go. |
|
162 | - $valid_shortcodes = array('line_item'); |
|
163 | - $templates = $this->_data['template']; |
|
164 | - |
|
165 | - $additional_line_items = $this->_data['data']->additional_line_items; |
|
166 | - $line_item_list = ''; |
|
167 | - foreach ($additional_line_items as $line_item) { |
|
168 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
169 | - $templates['additional_line_item_list'], |
|
170 | - $line_item, |
|
171 | - $valid_shortcodes, |
|
172 | - $this->_extra_data |
|
173 | - ); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - return $line_item_list; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
183 | - * parent ticket line item. |
|
184 | - * |
|
185 | - * @since 4.5.0 |
|
186 | - * |
|
187 | - * @return string parsed price modifier line item list. |
|
188 | - */ |
|
189 | - private function _get_price_mod_line_item_list() |
|
190 | - { |
|
191 | - $this->_validate_list_requirements(); |
|
192 | - |
|
193 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
194 | - return ''; |
|
195 | - } |
|
196 | - |
|
197 | - // made it here so we're good to go. |
|
198 | - $main_line_item = $this->_data['data']; |
|
199 | - $templates = $this->_extra_data['template']; |
|
200 | - $addressee_obj = $this->_extra_data['data']; |
|
201 | - |
|
202 | - $valid_shortcodes = array('line_item'); |
|
203 | - |
|
204 | - $main_line_item_id = $main_line_item->ID(); |
|
205 | - |
|
206 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
207 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
208 | - |
|
209 | - $line_item_list = ''; |
|
210 | - |
|
211 | - foreach ($price_mod_line_items as $line_item) { |
|
212 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
213 | - $templates['price_modifier_line_item_list'], |
|
214 | - $line_item, |
|
215 | - $valid_shortcodes, |
|
216 | - $this->_extra_data |
|
217 | - ); |
|
218 | - } |
|
219 | - |
|
220 | - return $line_item_list; |
|
221 | - } |
|
25 | + protected function _init_props() |
|
26 | + { |
|
27 | + $this->label = __('Line Item List Shortcodes', 'event_espresso'); |
|
28 | + $this->description = __('All shortcodes specific to line item lists', 'event_espresso'); |
|
29 | + $this->_shortcodes = array( |
|
30 | + '[TICKET_LINE_ITEM_LIST]' => __('Outputs a list of ticket line items.', 'event_espresso'), |
|
31 | + '[TAX_LINE_ITEM_LIST]' => __('Outputs a list of tax line items.', 'event_espresso'), |
|
32 | + '[ADDITIONAL_LINE_ITEM_LIST]' => __( |
|
33 | + 'Outputs a list of additional line items (other charges or discounts)', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]' => __('Outputs a list of price modifier line items', 'event_espresso'), |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + protected function _parser($shortcode) |
|
42 | + { |
|
43 | + |
|
44 | + switch ($shortcode) { |
|
45 | + case '[TICKET_LINE_ITEM_LIST]': |
|
46 | + return $this->_get_ticket_line_item_list(); |
|
47 | + |
|
48 | + case '[TAX_LINE_ITEM_LIST]': |
|
49 | + return $this->_get_tax_line_item_list(); |
|
50 | + |
|
51 | + case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
52 | + return $this->_get_price_mod_line_item_list(); |
|
53 | + |
|
54 | + case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
55 | + return $this->_get_additional_line_item_list(); |
|
56 | + |
|
57 | + default: |
|
58 | + return ''; |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
65 | + * |
|
66 | + * @since 4.5.0 |
|
67 | + * |
|
68 | + * @return string parsed ticket line item list. |
|
69 | + */ |
|
70 | + private function _get_ticket_line_item_list() |
|
71 | + { |
|
72 | + $this->_validate_list_requirements(); |
|
73 | + |
|
74 | + if (! $this->_data['data'] instanceof EE_Ticket) { |
|
75 | + return ''; |
|
76 | + } |
|
77 | + |
|
78 | + $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
79 | + |
|
80 | + $ticket = $this->_data['data']; |
|
81 | + $templates = $this->_extra_data['template']; |
|
82 | + $addressee_obj = $this->_extra_data['data']; |
|
83 | + |
|
84 | + // made it here so we have an EE_Ticket, so we should have what we need. |
|
85 | + $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
86 | + ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
87 | + $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
88 | + ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
89 | + |
|
90 | + $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
91 | + : $templates['ticket_line_item_pms']; |
|
92 | + |
|
93 | + if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
94 | + return ''; |
|
95 | + } |
|
96 | + |
|
97 | + // now we just return the appropriate template parsed for each ticket. |
|
98 | + return $this->_shortcode_helper->parse_line_item_list_template( |
|
99 | + $template, |
|
100 | + $ticket_line_item, |
|
101 | + $valid_shortcodes, |
|
102 | + $this->_extra_data |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
109 | + * |
|
110 | + * @return string parsed tax line item list. |
|
111 | + * @throws EE_Error |
|
112 | + * @since 4.5.0 |
|
113 | + */ |
|
114 | + private function _get_tax_line_item_list() |
|
115 | + { |
|
116 | + /** @var EE_Admin_Config $admin_config */ |
|
117 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
118 | + if ($admin_config->useAdvancedEditor()) { |
|
119 | + return ''; |
|
120 | + } |
|
121 | + $this->_validate_list_requirements(); |
|
122 | + |
|
123 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
124 | + return ''; |
|
125 | + } |
|
126 | + |
|
127 | + // made it here so we're good to go. |
|
128 | + $valid_shortcodes = array('line_item'); |
|
129 | + $templates = $this->_data['template']; |
|
130 | + |
|
131 | + $tax_line_items = $this->_data['data']->tax_line_items; |
|
132 | + $line_item_list = ''; |
|
133 | + foreach ($tax_line_items as $line_item) { |
|
134 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
135 | + $templates['tax_line_item_list'], |
|
136 | + $line_item, |
|
137 | + $valid_shortcodes, |
|
138 | + $this->_extra_data |
|
139 | + ); |
|
140 | + } |
|
141 | + |
|
142 | + return $line_item_list; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
147 | + * |
|
148 | + * @since 4.5.0 |
|
149 | + * |
|
150 | + * @return string parsed other line item list. |
|
151 | + */ |
|
152 | + private function _get_additional_line_item_list() |
|
153 | + { |
|
154 | + |
|
155 | + $this->_validate_list_requirements(); |
|
156 | + |
|
157 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
158 | + return ''; |
|
159 | + } |
|
160 | + |
|
161 | + // made it here so we're good to go. |
|
162 | + $valid_shortcodes = array('line_item'); |
|
163 | + $templates = $this->_data['template']; |
|
164 | + |
|
165 | + $additional_line_items = $this->_data['data']->additional_line_items; |
|
166 | + $line_item_list = ''; |
|
167 | + foreach ($additional_line_items as $line_item) { |
|
168 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
169 | + $templates['additional_line_item_list'], |
|
170 | + $line_item, |
|
171 | + $valid_shortcodes, |
|
172 | + $this->_extra_data |
|
173 | + ); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + return $line_item_list; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
183 | + * parent ticket line item. |
|
184 | + * |
|
185 | + * @since 4.5.0 |
|
186 | + * |
|
187 | + * @return string parsed price modifier line item list. |
|
188 | + */ |
|
189 | + private function _get_price_mod_line_item_list() |
|
190 | + { |
|
191 | + $this->_validate_list_requirements(); |
|
192 | + |
|
193 | + if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
194 | + return ''; |
|
195 | + } |
|
196 | + |
|
197 | + // made it here so we're good to go. |
|
198 | + $main_line_item = $this->_data['data']; |
|
199 | + $templates = $this->_extra_data['template']; |
|
200 | + $addressee_obj = $this->_extra_data['data']; |
|
201 | + |
|
202 | + $valid_shortcodes = array('line_item'); |
|
203 | + |
|
204 | + $main_line_item_id = $main_line_item->ID(); |
|
205 | + |
|
206 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
207 | + ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
208 | + |
|
209 | + $line_item_list = ''; |
|
210 | + |
|
211 | + foreach ($price_mod_line_items as $line_item) { |
|
212 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
213 | + $templates['price_modifier_line_item_list'], |
|
214 | + $line_item, |
|
215 | + $valid_shortcodes, |
|
216 | + $this->_extra_data |
|
217 | + ); |
|
218 | + } |
|
219 | + |
|
220 | + return $line_item_list; |
|
221 | + } |
|
222 | 222 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->_validate_list_requirements(); |
73 | 73 | |
74 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
74 | + if ( ! $this->_data['data'] instanceof EE_Ticket) { |
|
75 | 75 | return ''; |
76 | 76 | } |
77 | 77 | |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | $addressee_obj = $this->_extra_data['data']; |
83 | 83 | |
84 | 84 | // made it here so we have an EE_Ticket, so we should have what we need. |
85 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
87 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
88 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
85 | + $ticket_line_item = isset($addressee_obj->tickets[$ticket->ID()]['line_item']) |
|
86 | + ? $addressee_obj->tickets[$ticket->ID()]['line_item'] : null; |
|
87 | + $sub_line_items = isset($addressee_obj->tickets[$ticket->ID()]['sub_line_items']) |
|
88 | + ? $addressee_obj->tickets[$ticket->ID()]['sub_line_items'] : array(); |
|
89 | 89 | |
90 | 90 | $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
91 | 91 | : $templates['ticket_line_item_pms']; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } |
121 | 121 | $this->_validate_list_requirements(); |
122 | 122 | |
123 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
123 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
124 | 124 | return ''; |
125 | 125 | } |
126 | 126 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | $this->_validate_list_requirements(); |
156 | 156 | |
157 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
157 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
158 | 158 | return ''; |
159 | 159 | } |
160 | 160 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | { |
191 | 191 | $this->_validate_list_requirements(); |
192 | 192 | |
193 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
193 | + if ( ! $this->_data['data'] instanceof EE_Line_Item) { |
|
194 | 194 | return ''; |
195 | 195 | } |
196 | 196 | |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | |
204 | 204 | $main_line_item_id = $main_line_item->ID(); |
205 | 205 | |
206 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
207 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
206 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[$main_line_item_id]['children']) |
|
207 | + ? $addressee_obj->line_items_with_children[$main_line_item_id]['children'] : array(); |
|
208 | 208 | |
209 | 209 | $line_item_list = ''; |
210 | 210 |
@@ -12,663 +12,663 @@ |
||
12 | 12 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * array of events |
|
17 | - * |
|
18 | - * @type EE_Line_Item[] $_events |
|
19 | - */ |
|
20 | - private $_events = array(); |
|
21 | - |
|
22 | - /** |
|
23 | - * whether to display the taxes row or not |
|
24 | - * |
|
25 | - * @type bool $_show_taxes |
|
26 | - */ |
|
27 | - private $_show_taxes = false; |
|
28 | - |
|
29 | - /** |
|
30 | - * html for any tax rows |
|
31 | - * |
|
32 | - * @type string $_show_taxes |
|
33 | - */ |
|
34 | - private $_taxes_html = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * total amount including tax we can bill for at this time |
|
38 | - * |
|
39 | - * @type float $_grand_total |
|
40 | - */ |
|
41 | - private $_grand_total = 0.00; |
|
42 | - |
|
43 | - /** |
|
44 | - * total number of items being billed for |
|
45 | - * |
|
46 | - * @type int $_total_items |
|
47 | - */ |
|
48 | - private $_total_items = 0; |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return float |
|
54 | - */ |
|
55 | - public function grand_total() |
|
56 | - { |
|
57 | - return $this->_grand_total; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public function total_items() |
|
66 | - { |
|
67 | - return $this->_total_items; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param EE_Line_Item $line_item |
|
74 | - * @param array $options |
|
75 | - * @param EE_Line_Item $parent_line_item |
|
76 | - * @return mixed |
|
77 | - * @throws EE_Error |
|
78 | - */ |
|
79 | - public function display_line_item( |
|
80 | - EE_Line_Item $line_item, |
|
81 | - $options = array(), |
|
82 | - EE_Line_Item $parent_line_item = null |
|
83 | - ) { |
|
84 | - $html = ''; |
|
85 | - // set some default options and merge with incoming |
|
86 | - $default_options = array( |
|
87 | - 'show_desc' => true, // true false |
|
88 | - 'odd' => false, |
|
89 | - ); |
|
90 | - $options = array_merge($default_options, (array) $options); |
|
91 | - switch ($line_item->type()) { |
|
92 | - case EEM_Line_Item::type_line_item: |
|
93 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
94 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
95 | - // item row |
|
96 | - $html .= $this->_ticket_row($line_item, $options); |
|
97 | - } else { |
|
98 | - // item row |
|
99 | - $html .= $this->_item_row($line_item, $options); |
|
100 | - } |
|
101 | - if ( |
|
102 | - apply_filters( |
|
103 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
104 | - true |
|
105 | - ) |
|
106 | - ) { |
|
107 | - // got any kids? |
|
108 | - foreach ($line_item->children() as $child_line_item) { |
|
109 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
110 | - } |
|
111 | - } |
|
112 | - break; |
|
113 | - case EEM_Line_Item::type_sub_line_item: |
|
114 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
115 | - break; |
|
116 | - case EEM_Line_Item::type_sub_total: |
|
117 | - static $sub_total = 0; |
|
118 | - $event_sub_total = 0; |
|
119 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
120 | - if ($line_item->OBJ_type() === 'Event') { |
|
121 | - $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
122 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
123 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
124 | - // if event has default reg status of Not Approved, then don't display info on it |
|
125 | - if ( |
|
126 | - $event instanceof EE_Event |
|
127 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
128 | - ) { |
|
129 | - $display_event = false; |
|
130 | - // unless there are registrations for it that are returning to pay |
|
131 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
132 | - foreach ($options['registrations'] as $registration) { |
|
133 | - if (! $registration instanceof EE_Registration) { |
|
134 | - continue; |
|
135 | - } |
|
136 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
137 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
138 | - ? true |
|
139 | - : $display_event; |
|
140 | - } |
|
141 | - } |
|
142 | - if (! $display_event) { |
|
143 | - return ''; |
|
144 | - } |
|
145 | - } |
|
146 | - $this->_events[ $options['event_id'] ] = 0; |
|
147 | - $html .= $this->_event_row($line_item); |
|
148 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
149 | - } |
|
150 | - } |
|
151 | - $child_line_items = $line_item->children(); |
|
152 | - // loop thru children |
|
153 | - foreach ($child_line_items as $child_line_item) { |
|
154 | - // recursively feed children back into this method |
|
155 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
156 | - } |
|
157 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
158 | - $sub_total += $event_sub_total; |
|
159 | - if ( |
|
160 | - ( |
|
161 | - // event subtotals |
|
162 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
163 | - ) |
|
164 | - || ( |
|
165 | - // pre-tax subtotals |
|
166 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
167 | - ) |
|
168 | - ) { |
|
169 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
170 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
171 | - } |
|
172 | - break; |
|
173 | - case EEM_Line_Item::type_tax: |
|
174 | - if ($this->_show_taxes) { |
|
175 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
176 | - } |
|
177 | - break; |
|
178 | - case EEM_Line_Item::type_tax_sub_total: |
|
179 | - if ($this->_show_taxes) { |
|
180 | - $child_line_items = $line_item->children(); |
|
181 | - // loop thru children |
|
182 | - foreach ($child_line_items as $child_line_item) { |
|
183 | - // recursively feed children back into this method |
|
184 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
185 | - } |
|
186 | - if (count($child_line_items) > 1) { |
|
187 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
188 | - } |
|
189 | - } |
|
190 | - break; |
|
191 | - case EEM_Line_Item::type_total: |
|
192 | - // get all child line items |
|
193 | - $children = $line_item->children(); |
|
194 | - // loop thru all non-tax child line items |
|
195 | - foreach ($children as $child_line_item) { |
|
196 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
197 | - // recursively feed children back into this method |
|
198 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
199 | - } |
|
200 | - } |
|
201 | - // now loop thru tax child line items |
|
202 | - foreach ($children as $child_line_item) { |
|
203 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
204 | - // recursively feed children back into this method |
|
205 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
206 | - } |
|
207 | - } |
|
208 | - $html .= $this->_taxes_html; |
|
209 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
210 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
211 | - break; |
|
212 | - } |
|
213 | - return $html; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
220 | - * |
|
221 | - * @param EE_Line_Item $line_item |
|
222 | - * @return mixed |
|
223 | - */ |
|
224 | - private function _event_row(EE_Line_Item $line_item) |
|
225 | - { |
|
226 | - // start of row |
|
227 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
228 | - // event name td |
|
229 | - $html .= EEH_HTML::td( |
|
230 | - EEH_HTML::strong($line_item->name()), |
|
231 | - '', |
|
232 | - 'event-header', |
|
233 | - '', |
|
234 | - ' colspan="4"' |
|
235 | - ); |
|
236 | - // end of row |
|
237 | - $html .= EEH_HTML::trx(); |
|
238 | - return $html; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * _ticket_row |
|
245 | - * |
|
246 | - * @param EE_Line_Item $line_item |
|
247 | - * @param array $options |
|
248 | - * @return mixed |
|
249 | - * @throws EE_Error |
|
250 | - */ |
|
251 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
252 | - { |
|
253 | - // start of row |
|
254 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
255 | - $html = EEH_HTML::tr('', '', $row_class); |
|
256 | - // name && desc |
|
257 | - $name_and_desc = apply_filters( |
|
258 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
259 | - $line_item->name(), |
|
260 | - $line_item |
|
261 | - ); |
|
262 | - $name_and_desc .= apply_filters( |
|
263 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
264 | - ( |
|
265 | - $options['show_desc'] |
|
266 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
267 | - : '' |
|
268 | - ), |
|
269 | - $line_item, |
|
270 | - $options |
|
271 | - ); |
|
272 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
273 | - $name_and_desc = apply_filters( |
|
274 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc', |
|
275 | - $name_and_desc, |
|
276 | - $line_item, |
|
277 | - $options |
|
278 | - ); |
|
279 | - |
|
280 | - // name td |
|
281 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
282 | - $name_and_desc, |
|
283 | - '', |
|
284 | - 'item_l' |
|
285 | - ); |
|
286 | - // price td |
|
287 | - $price = apply_filters( |
|
288 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
289 | - $line_item->unit_price_no_code(), |
|
290 | - $line_item |
|
291 | - ); |
|
292 | - $html .= EEH_HTML::td($price, '', 'spco-nowrap item_c jst-rght'); |
|
293 | - // quantity td |
|
294 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
295 | - $this->_total_items += $line_item->quantity(); |
|
296 | - // determine total for line item |
|
297 | - $total = apply_filters( |
|
298 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
299 | - $line_item->total(), |
|
300 | - $line_item |
|
301 | - ); |
|
302 | - $this->_events[ $options['event_id'] ] += $total; |
|
303 | - // total td |
|
304 | - $html .= EEH_HTML::td( |
|
305 | - EEH_Template::format_currency($total, false, false), |
|
306 | - '', |
|
307 | - 'spco-nowrap item_r jst-rght' |
|
308 | - ); |
|
309 | - // end of row |
|
310 | - $html .= EEH_HTML::trx(); |
|
311 | - return $html; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * _item_row |
|
318 | - * |
|
319 | - * @param EE_Line_Item $line_item |
|
320 | - * @param array $options |
|
321 | - * @return mixed |
|
322 | - * @throws EE_Error |
|
323 | - */ |
|
324 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
325 | - { |
|
326 | - // start of row |
|
327 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
328 | - $html = EEH_HTML::tr('', '', $row_class); |
|
329 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
330 | - // name && desc |
|
331 | - $name_and_desc = apply_filters( |
|
332 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
333 | - $obj_name . $line_item->name(), |
|
334 | - $line_item |
|
335 | - ); |
|
336 | - $name_and_desc .= apply_filters( |
|
337 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
338 | - ( |
|
339 | - $options['show_desc'] |
|
340 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
341 | - : '' |
|
342 | - ), |
|
343 | - $line_item, |
|
344 | - $options |
|
345 | - ); |
|
346 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
347 | - $name_and_desc = apply_filters( |
|
348 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc', |
|
349 | - $name_and_desc, |
|
350 | - $line_item, |
|
351 | - $options |
|
352 | - ); |
|
353 | - |
|
354 | - // name td |
|
355 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
356 | - // price td |
|
357 | - if ($line_item->is_percent()) { |
|
358 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
359 | - } else { |
|
360 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
361 | - } |
|
362 | - // quantity td |
|
363 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
364 | - // $total = $line_item->total() * $line_item->quantity(); |
|
365 | - $total = $line_item->total(); |
|
366 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
367 | - $this->_events[ $options['event_id'] ] += $total; |
|
368 | - } |
|
369 | - // total td |
|
370 | - $html .= EEH_HTML::td( |
|
371 | - EEH_Template::format_currency($total, false, false), |
|
372 | - '', |
|
373 | - 'spco-nowrap item_r jst-rght' |
|
374 | - ); |
|
375 | - // end of row |
|
376 | - $html .= EEH_HTML::trx(); |
|
377 | - return $html; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * _sub_item_row |
|
384 | - * |
|
385 | - * @param EE_Line_Item $line_item |
|
386 | - * @param array $options |
|
387 | - * @param EE_Line_Item $parent_line_item |
|
388 | - * @return mixed |
|
389 | - * @throws EE_Error |
|
390 | - */ |
|
391 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
392 | - { |
|
393 | - if ( |
|
394 | - $parent_line_item instanceof EE_Line_Item |
|
395 | - && $line_item->children() === array() |
|
396 | - && $line_item->name() === $parent_line_item->name() |
|
397 | - && apply_filters( |
|
398 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
399 | - true |
|
400 | - ) |
|
401 | - ) { |
|
402 | - return ''; |
|
403 | - } |
|
404 | - // start of row |
|
405 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
406 | - // name && desc |
|
407 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
408 | - . $line_item->name(); |
|
409 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
410 | - . $line_item->desc() |
|
411 | - . '</span>' : ''; |
|
412 | - // name td |
|
413 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
414 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
415 | - // discount/surcharge td |
|
416 | - if ($line_item->is_percent()) { |
|
417 | - $html .= EEH_HTML::td( |
|
418 | - EEH_Template::format_currency( |
|
419 | - $line_item->total() / $qty, |
|
420 | - false, |
|
421 | - false |
|
422 | - ), |
|
423 | - '', |
|
424 | - 'spco-nowrap item_c jst-rght' |
|
425 | - ); |
|
426 | - } else { |
|
427 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
428 | - } |
|
429 | - // no quantity td |
|
430 | - $html .= EEH_HTML::td(); |
|
431 | - // no total td |
|
432 | - $html .= EEH_HTML::td(); |
|
433 | - // end of row |
|
434 | - $html .= EEH_HTML::trx(); |
|
435 | - $html = apply_filters( |
|
436 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
437 | - $html, |
|
438 | - $line_item, |
|
439 | - $options, |
|
440 | - $parent_line_item |
|
441 | - ); |
|
442 | - return $html; |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * _tax_row |
|
449 | - * |
|
450 | - * @param EE_Line_Item $line_item |
|
451 | - * @param array $options |
|
452 | - * @return mixed |
|
453 | - * @throws EE_Error |
|
454 | - */ |
|
455 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
456 | - { |
|
457 | - // start of row |
|
458 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
459 | - // name && desc |
|
460 | - $name_and_desc = $line_item->name(); |
|
461 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
462 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
463 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
464 | - // name td |
|
465 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
466 | - $name_and_desc, |
|
467 | - '', |
|
468 | - 'item_l sub-item' |
|
469 | - ); |
|
470 | - // percent td |
|
471 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
472 | - // empty td (price) |
|
473 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
474 | - // total td |
|
475 | - $html .= EEH_HTML::td( |
|
476 | - EEH_Template::format_currency( |
|
477 | - $line_item->total(), |
|
478 | - false, |
|
479 | - false |
|
480 | - ), |
|
481 | - '', |
|
482 | - 'spco-nowrap item_r jst-rght' |
|
483 | - ); |
|
484 | - // end of row |
|
485 | - $html .= EEH_HTML::trx(); |
|
486 | - return $html; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * _total_row |
|
493 | - * |
|
494 | - * @param EE_Line_Item $line_item |
|
495 | - * @param string $text |
|
496 | - * @return mixed |
|
497 | - * @throws EE_Error |
|
498 | - */ |
|
499 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
500 | - { |
|
501 | - $html = ''; |
|
502 | - if ($line_item->total()) { |
|
503 | - // start of row |
|
504 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
505 | - // total td |
|
506 | - $html .= EEH_HTML::td( |
|
507 | - $text, |
|
508 | - '', |
|
509 | - 'total_currency total jst-rght', |
|
510 | - '', |
|
511 | - ' colspan="2"' |
|
512 | - ); |
|
513 | - // empty td (price) |
|
514 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
515 | - // total td |
|
516 | - $html .= EEH_HTML::td( |
|
517 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
518 | - '', |
|
519 | - 'spco-nowrap total jst-rght' |
|
520 | - ); |
|
521 | - // end of row |
|
522 | - $html .= EEH_HTML::trx(); |
|
523 | - } |
|
524 | - return $html; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * _total_row |
|
531 | - * |
|
532 | - * @param EE_Line_Item $line_item |
|
533 | - * @param string $text |
|
534 | - * @param array $options |
|
535 | - * @return mixed |
|
536 | - * @throws EE_Error |
|
537 | - */ |
|
538 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
539 | - { |
|
540 | - $html = ''; |
|
541 | - if ($line_item->total()) { |
|
542 | - // start of row |
|
543 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
544 | - // total td |
|
545 | - $html .= EEH_HTML::td( |
|
546 | - $text, |
|
547 | - '', |
|
548 | - 'total_currency total jst-rght', |
|
549 | - '', |
|
550 | - ' colspan="3"' |
|
551 | - ); |
|
552 | - // total td |
|
553 | - $html .= EEH_HTML::td( |
|
554 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
555 | - '', |
|
556 | - 'spco-nowrap total jst-rght' |
|
557 | - ); |
|
558 | - // end of row |
|
559 | - $html .= EEH_HTML::trx(); |
|
560 | - } |
|
561 | - return $html; |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * _total_row |
|
568 | - * |
|
569 | - * @param EE_Line_Item $line_item |
|
570 | - * @param string $text |
|
571 | - * @return mixed |
|
572 | - * @throws EE_Error |
|
573 | - */ |
|
574 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
575 | - { |
|
576 | - // start of row |
|
577 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
578 | - // total td |
|
579 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
580 | - // total td |
|
581 | - $html .= EEH_HTML::td( |
|
582 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
583 | - '', |
|
584 | - 'spco-nowrap total jst-rght' |
|
585 | - ); |
|
586 | - // end of row |
|
587 | - $html .= EEH_HTML::trx(); |
|
588 | - return $html; |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * _payments_and_amount_owing_rows |
|
595 | - * |
|
596 | - * @param EE_Line_Item $line_item |
|
597 | - * @param array $options |
|
598 | - * @return mixed |
|
599 | - * @throws EE_Error |
|
600 | - */ |
|
601 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
602 | - { |
|
603 | - $html = ''; |
|
604 | - $owing = $line_item->total(); |
|
605 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
606 | - if ($transaction instanceof EE_Transaction) { |
|
607 | - $registration_payments = array(); |
|
608 | - $registrations = ! empty($options['registrations']) |
|
609 | - ? $options['registrations'] |
|
610 | - : $transaction->registrations(); |
|
611 | - foreach ($registrations as $registration) { |
|
612 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
613 | - $registration_payments += $registration->registration_payments(); |
|
614 | - } |
|
615 | - } |
|
616 | - if (! empty($registration_payments)) { |
|
617 | - foreach ($registration_payments as $registration_payment) { |
|
618 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
619 | - $owing -= $registration_payment->amount(); |
|
620 | - $payment = $registration_payment->payment(); |
|
621 | - $payment_desc = ''; |
|
622 | - if ($payment instanceof EE_Payment) { |
|
623 | - $payment_desc = sprintf( |
|
624 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
625 | - $payment->txn_id_chq_nmbr() !== '' |
|
626 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
627 | - : '', |
|
628 | - $payment->timestamp() |
|
629 | - ); |
|
630 | - } |
|
631 | - // start of row |
|
632 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
633 | - // payment desc |
|
634 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
635 | - // total td |
|
636 | - $html .= EEH_HTML::td( |
|
637 | - EEH_Template::format_currency( |
|
638 | - $registration_payment->amount(), |
|
639 | - false, |
|
640 | - false |
|
641 | - ), |
|
642 | - '', |
|
643 | - 'spco-nowrap total jst-rght' |
|
644 | - ); |
|
645 | - // end of row |
|
646 | - $html .= EEH_HTML::trx(); |
|
647 | - } |
|
648 | - } |
|
649 | - if ($line_item->total()) { |
|
650 | - // start of row |
|
651 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
652 | - // total td |
|
653 | - $html .= EEH_HTML::td( |
|
654 | - esc_html__('Amount Owing', 'event_espresso'), |
|
655 | - '', |
|
656 | - 'total_currency total jst-rght', |
|
657 | - '', |
|
658 | - ' colspan="3"' |
|
659 | - ); |
|
660 | - // total td |
|
661 | - $html .= EEH_HTML::td( |
|
662 | - EEH_Template::format_currency($owing, false, false), |
|
663 | - '', |
|
664 | - 'spco-nowrap total jst-rght' |
|
665 | - ); |
|
666 | - // end of row |
|
667 | - $html .= EEH_HTML::trx(); |
|
668 | - } |
|
669 | - } |
|
670 | - } |
|
671 | - $this->_grand_total = $owing; |
|
672 | - return $html; |
|
673 | - } |
|
15 | + /** |
|
16 | + * array of events |
|
17 | + * |
|
18 | + * @type EE_Line_Item[] $_events |
|
19 | + */ |
|
20 | + private $_events = array(); |
|
21 | + |
|
22 | + /** |
|
23 | + * whether to display the taxes row or not |
|
24 | + * |
|
25 | + * @type bool $_show_taxes |
|
26 | + */ |
|
27 | + private $_show_taxes = false; |
|
28 | + |
|
29 | + /** |
|
30 | + * html for any tax rows |
|
31 | + * |
|
32 | + * @type string $_show_taxes |
|
33 | + */ |
|
34 | + private $_taxes_html = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * total amount including tax we can bill for at this time |
|
38 | + * |
|
39 | + * @type float $_grand_total |
|
40 | + */ |
|
41 | + private $_grand_total = 0.00; |
|
42 | + |
|
43 | + /** |
|
44 | + * total number of items being billed for |
|
45 | + * |
|
46 | + * @type int $_total_items |
|
47 | + */ |
|
48 | + private $_total_items = 0; |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return float |
|
54 | + */ |
|
55 | + public function grand_total() |
|
56 | + { |
|
57 | + return $this->_grand_total; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public function total_items() |
|
66 | + { |
|
67 | + return $this->_total_items; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param EE_Line_Item $line_item |
|
74 | + * @param array $options |
|
75 | + * @param EE_Line_Item $parent_line_item |
|
76 | + * @return mixed |
|
77 | + * @throws EE_Error |
|
78 | + */ |
|
79 | + public function display_line_item( |
|
80 | + EE_Line_Item $line_item, |
|
81 | + $options = array(), |
|
82 | + EE_Line_Item $parent_line_item = null |
|
83 | + ) { |
|
84 | + $html = ''; |
|
85 | + // set some default options and merge with incoming |
|
86 | + $default_options = array( |
|
87 | + 'show_desc' => true, // true false |
|
88 | + 'odd' => false, |
|
89 | + ); |
|
90 | + $options = array_merge($default_options, (array) $options); |
|
91 | + switch ($line_item->type()) { |
|
92 | + case EEM_Line_Item::type_line_item: |
|
93 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
94 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
95 | + // item row |
|
96 | + $html .= $this->_ticket_row($line_item, $options); |
|
97 | + } else { |
|
98 | + // item row |
|
99 | + $html .= $this->_item_row($line_item, $options); |
|
100 | + } |
|
101 | + if ( |
|
102 | + apply_filters( |
|
103 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
104 | + true |
|
105 | + ) |
|
106 | + ) { |
|
107 | + // got any kids? |
|
108 | + foreach ($line_item->children() as $child_line_item) { |
|
109 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
110 | + } |
|
111 | + } |
|
112 | + break; |
|
113 | + case EEM_Line_Item::type_sub_line_item: |
|
114 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
115 | + break; |
|
116 | + case EEM_Line_Item::type_sub_total: |
|
117 | + static $sub_total = 0; |
|
118 | + $event_sub_total = 0; |
|
119 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
120 | + if ($line_item->OBJ_type() === 'Event') { |
|
121 | + $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
122 | + if (! isset($this->_events[ $options['event_id'] ])) { |
|
123 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
124 | + // if event has default reg status of Not Approved, then don't display info on it |
|
125 | + if ( |
|
126 | + $event instanceof EE_Event |
|
127 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
128 | + ) { |
|
129 | + $display_event = false; |
|
130 | + // unless there are registrations for it that are returning to pay |
|
131 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
132 | + foreach ($options['registrations'] as $registration) { |
|
133 | + if (! $registration instanceof EE_Registration) { |
|
134 | + continue; |
|
135 | + } |
|
136 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
137 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
138 | + ? true |
|
139 | + : $display_event; |
|
140 | + } |
|
141 | + } |
|
142 | + if (! $display_event) { |
|
143 | + return ''; |
|
144 | + } |
|
145 | + } |
|
146 | + $this->_events[ $options['event_id'] ] = 0; |
|
147 | + $html .= $this->_event_row($line_item); |
|
148 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
149 | + } |
|
150 | + } |
|
151 | + $child_line_items = $line_item->children(); |
|
152 | + // loop thru children |
|
153 | + foreach ($child_line_items as $child_line_item) { |
|
154 | + // recursively feed children back into this method |
|
155 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
156 | + } |
|
157 | + $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
158 | + $sub_total += $event_sub_total; |
|
159 | + if ( |
|
160 | + ( |
|
161 | + // event subtotals |
|
162 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
163 | + ) |
|
164 | + || ( |
|
165 | + // pre-tax subtotals |
|
166 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
167 | + ) |
|
168 | + ) { |
|
169 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
170 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
171 | + } |
|
172 | + break; |
|
173 | + case EEM_Line_Item::type_tax: |
|
174 | + if ($this->_show_taxes) { |
|
175 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
176 | + } |
|
177 | + break; |
|
178 | + case EEM_Line_Item::type_tax_sub_total: |
|
179 | + if ($this->_show_taxes) { |
|
180 | + $child_line_items = $line_item->children(); |
|
181 | + // loop thru children |
|
182 | + foreach ($child_line_items as $child_line_item) { |
|
183 | + // recursively feed children back into this method |
|
184 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
185 | + } |
|
186 | + if (count($child_line_items) > 1) { |
|
187 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
188 | + } |
|
189 | + } |
|
190 | + break; |
|
191 | + case EEM_Line_Item::type_total: |
|
192 | + // get all child line items |
|
193 | + $children = $line_item->children(); |
|
194 | + // loop thru all non-tax child line items |
|
195 | + foreach ($children as $child_line_item) { |
|
196 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
197 | + // recursively feed children back into this method |
|
198 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
199 | + } |
|
200 | + } |
|
201 | + // now loop thru tax child line items |
|
202 | + foreach ($children as $child_line_item) { |
|
203 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
204 | + // recursively feed children back into this method |
|
205 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
206 | + } |
|
207 | + } |
|
208 | + $html .= $this->_taxes_html; |
|
209 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
210 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
211 | + break; |
|
212 | + } |
|
213 | + return $html; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
220 | + * |
|
221 | + * @param EE_Line_Item $line_item |
|
222 | + * @return mixed |
|
223 | + */ |
|
224 | + private function _event_row(EE_Line_Item $line_item) |
|
225 | + { |
|
226 | + // start of row |
|
227 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
228 | + // event name td |
|
229 | + $html .= EEH_HTML::td( |
|
230 | + EEH_HTML::strong($line_item->name()), |
|
231 | + '', |
|
232 | + 'event-header', |
|
233 | + '', |
|
234 | + ' colspan="4"' |
|
235 | + ); |
|
236 | + // end of row |
|
237 | + $html .= EEH_HTML::trx(); |
|
238 | + return $html; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * _ticket_row |
|
245 | + * |
|
246 | + * @param EE_Line_Item $line_item |
|
247 | + * @param array $options |
|
248 | + * @return mixed |
|
249 | + * @throws EE_Error |
|
250 | + */ |
|
251 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
252 | + { |
|
253 | + // start of row |
|
254 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
255 | + $html = EEH_HTML::tr('', '', $row_class); |
|
256 | + // name && desc |
|
257 | + $name_and_desc = apply_filters( |
|
258 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
259 | + $line_item->name(), |
|
260 | + $line_item |
|
261 | + ); |
|
262 | + $name_and_desc .= apply_filters( |
|
263 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
264 | + ( |
|
265 | + $options['show_desc'] |
|
266 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
267 | + : '' |
|
268 | + ), |
|
269 | + $line_item, |
|
270 | + $options |
|
271 | + ); |
|
272 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
273 | + $name_and_desc = apply_filters( |
|
274 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc', |
|
275 | + $name_and_desc, |
|
276 | + $line_item, |
|
277 | + $options |
|
278 | + ); |
|
279 | + |
|
280 | + // name td |
|
281 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
282 | + $name_and_desc, |
|
283 | + '', |
|
284 | + 'item_l' |
|
285 | + ); |
|
286 | + // price td |
|
287 | + $price = apply_filters( |
|
288 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
289 | + $line_item->unit_price_no_code(), |
|
290 | + $line_item |
|
291 | + ); |
|
292 | + $html .= EEH_HTML::td($price, '', 'spco-nowrap item_c jst-rght'); |
|
293 | + // quantity td |
|
294 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
295 | + $this->_total_items += $line_item->quantity(); |
|
296 | + // determine total for line item |
|
297 | + $total = apply_filters( |
|
298 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
299 | + $line_item->total(), |
|
300 | + $line_item |
|
301 | + ); |
|
302 | + $this->_events[ $options['event_id'] ] += $total; |
|
303 | + // total td |
|
304 | + $html .= EEH_HTML::td( |
|
305 | + EEH_Template::format_currency($total, false, false), |
|
306 | + '', |
|
307 | + 'spco-nowrap item_r jst-rght' |
|
308 | + ); |
|
309 | + // end of row |
|
310 | + $html .= EEH_HTML::trx(); |
|
311 | + return $html; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * _item_row |
|
318 | + * |
|
319 | + * @param EE_Line_Item $line_item |
|
320 | + * @param array $options |
|
321 | + * @return mixed |
|
322 | + * @throws EE_Error |
|
323 | + */ |
|
324 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
325 | + { |
|
326 | + // start of row |
|
327 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
328 | + $html = EEH_HTML::tr('', '', $row_class); |
|
329 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
330 | + // name && desc |
|
331 | + $name_and_desc = apply_filters( |
|
332 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
333 | + $obj_name . $line_item->name(), |
|
334 | + $line_item |
|
335 | + ); |
|
336 | + $name_and_desc .= apply_filters( |
|
337 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
338 | + ( |
|
339 | + $options['show_desc'] |
|
340 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
341 | + : '' |
|
342 | + ), |
|
343 | + $line_item, |
|
344 | + $options |
|
345 | + ); |
|
346 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
347 | + $name_and_desc = apply_filters( |
|
348 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc', |
|
349 | + $name_and_desc, |
|
350 | + $line_item, |
|
351 | + $options |
|
352 | + ); |
|
353 | + |
|
354 | + // name td |
|
355 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
356 | + // price td |
|
357 | + if ($line_item->is_percent()) { |
|
358 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
359 | + } else { |
|
360 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
361 | + } |
|
362 | + // quantity td |
|
363 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
364 | + // $total = $line_item->total() * $line_item->quantity(); |
|
365 | + $total = $line_item->total(); |
|
366 | + if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
367 | + $this->_events[ $options['event_id'] ] += $total; |
|
368 | + } |
|
369 | + // total td |
|
370 | + $html .= EEH_HTML::td( |
|
371 | + EEH_Template::format_currency($total, false, false), |
|
372 | + '', |
|
373 | + 'spco-nowrap item_r jst-rght' |
|
374 | + ); |
|
375 | + // end of row |
|
376 | + $html .= EEH_HTML::trx(); |
|
377 | + return $html; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * _sub_item_row |
|
384 | + * |
|
385 | + * @param EE_Line_Item $line_item |
|
386 | + * @param array $options |
|
387 | + * @param EE_Line_Item $parent_line_item |
|
388 | + * @return mixed |
|
389 | + * @throws EE_Error |
|
390 | + */ |
|
391 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
392 | + { |
|
393 | + if ( |
|
394 | + $parent_line_item instanceof EE_Line_Item |
|
395 | + && $line_item->children() === array() |
|
396 | + && $line_item->name() === $parent_line_item->name() |
|
397 | + && apply_filters( |
|
398 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
399 | + true |
|
400 | + ) |
|
401 | + ) { |
|
402 | + return ''; |
|
403 | + } |
|
404 | + // start of row |
|
405 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
406 | + // name && desc |
|
407 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
408 | + . $line_item->name(); |
|
409 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
410 | + . $line_item->desc() |
|
411 | + . '</span>' : ''; |
|
412 | + // name td |
|
413 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
414 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
415 | + // discount/surcharge td |
|
416 | + if ($line_item->is_percent()) { |
|
417 | + $html .= EEH_HTML::td( |
|
418 | + EEH_Template::format_currency( |
|
419 | + $line_item->total() / $qty, |
|
420 | + false, |
|
421 | + false |
|
422 | + ), |
|
423 | + '', |
|
424 | + 'spco-nowrap item_c jst-rght' |
|
425 | + ); |
|
426 | + } else { |
|
427 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
428 | + } |
|
429 | + // no quantity td |
|
430 | + $html .= EEH_HTML::td(); |
|
431 | + // no total td |
|
432 | + $html .= EEH_HTML::td(); |
|
433 | + // end of row |
|
434 | + $html .= EEH_HTML::trx(); |
|
435 | + $html = apply_filters( |
|
436 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
437 | + $html, |
|
438 | + $line_item, |
|
439 | + $options, |
|
440 | + $parent_line_item |
|
441 | + ); |
|
442 | + return $html; |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * _tax_row |
|
449 | + * |
|
450 | + * @param EE_Line_Item $line_item |
|
451 | + * @param array $options |
|
452 | + * @return mixed |
|
453 | + * @throws EE_Error |
|
454 | + */ |
|
455 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
456 | + { |
|
457 | + // start of row |
|
458 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
459 | + // name && desc |
|
460 | + $name_and_desc = $line_item->name(); |
|
461 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
462 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
463 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
464 | + // name td |
|
465 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
466 | + $name_and_desc, |
|
467 | + '', |
|
468 | + 'item_l sub-item' |
|
469 | + ); |
|
470 | + // percent td |
|
471 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
472 | + // empty td (price) |
|
473 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
474 | + // total td |
|
475 | + $html .= EEH_HTML::td( |
|
476 | + EEH_Template::format_currency( |
|
477 | + $line_item->total(), |
|
478 | + false, |
|
479 | + false |
|
480 | + ), |
|
481 | + '', |
|
482 | + 'spco-nowrap item_r jst-rght' |
|
483 | + ); |
|
484 | + // end of row |
|
485 | + $html .= EEH_HTML::trx(); |
|
486 | + return $html; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * _total_row |
|
493 | + * |
|
494 | + * @param EE_Line_Item $line_item |
|
495 | + * @param string $text |
|
496 | + * @return mixed |
|
497 | + * @throws EE_Error |
|
498 | + */ |
|
499 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
500 | + { |
|
501 | + $html = ''; |
|
502 | + if ($line_item->total()) { |
|
503 | + // start of row |
|
504 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
505 | + // total td |
|
506 | + $html .= EEH_HTML::td( |
|
507 | + $text, |
|
508 | + '', |
|
509 | + 'total_currency total jst-rght', |
|
510 | + '', |
|
511 | + ' colspan="2"' |
|
512 | + ); |
|
513 | + // empty td (price) |
|
514 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
515 | + // total td |
|
516 | + $html .= EEH_HTML::td( |
|
517 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
518 | + '', |
|
519 | + 'spco-nowrap total jst-rght' |
|
520 | + ); |
|
521 | + // end of row |
|
522 | + $html .= EEH_HTML::trx(); |
|
523 | + } |
|
524 | + return $html; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * _total_row |
|
531 | + * |
|
532 | + * @param EE_Line_Item $line_item |
|
533 | + * @param string $text |
|
534 | + * @param array $options |
|
535 | + * @return mixed |
|
536 | + * @throws EE_Error |
|
537 | + */ |
|
538 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
539 | + { |
|
540 | + $html = ''; |
|
541 | + if ($line_item->total()) { |
|
542 | + // start of row |
|
543 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
544 | + // total td |
|
545 | + $html .= EEH_HTML::td( |
|
546 | + $text, |
|
547 | + '', |
|
548 | + 'total_currency total jst-rght', |
|
549 | + '', |
|
550 | + ' colspan="3"' |
|
551 | + ); |
|
552 | + // total td |
|
553 | + $html .= EEH_HTML::td( |
|
554 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
555 | + '', |
|
556 | + 'spco-nowrap total jst-rght' |
|
557 | + ); |
|
558 | + // end of row |
|
559 | + $html .= EEH_HTML::trx(); |
|
560 | + } |
|
561 | + return $html; |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * _total_row |
|
568 | + * |
|
569 | + * @param EE_Line_Item $line_item |
|
570 | + * @param string $text |
|
571 | + * @return mixed |
|
572 | + * @throws EE_Error |
|
573 | + */ |
|
574 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
575 | + { |
|
576 | + // start of row |
|
577 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
578 | + // total td |
|
579 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
580 | + // total td |
|
581 | + $html .= EEH_HTML::td( |
|
582 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
583 | + '', |
|
584 | + 'spco-nowrap total jst-rght' |
|
585 | + ); |
|
586 | + // end of row |
|
587 | + $html .= EEH_HTML::trx(); |
|
588 | + return $html; |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * _payments_and_amount_owing_rows |
|
595 | + * |
|
596 | + * @param EE_Line_Item $line_item |
|
597 | + * @param array $options |
|
598 | + * @return mixed |
|
599 | + * @throws EE_Error |
|
600 | + */ |
|
601 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
602 | + { |
|
603 | + $html = ''; |
|
604 | + $owing = $line_item->total(); |
|
605 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
606 | + if ($transaction instanceof EE_Transaction) { |
|
607 | + $registration_payments = array(); |
|
608 | + $registrations = ! empty($options['registrations']) |
|
609 | + ? $options['registrations'] |
|
610 | + : $transaction->registrations(); |
|
611 | + foreach ($registrations as $registration) { |
|
612 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
613 | + $registration_payments += $registration->registration_payments(); |
|
614 | + } |
|
615 | + } |
|
616 | + if (! empty($registration_payments)) { |
|
617 | + foreach ($registration_payments as $registration_payment) { |
|
618 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
619 | + $owing -= $registration_payment->amount(); |
|
620 | + $payment = $registration_payment->payment(); |
|
621 | + $payment_desc = ''; |
|
622 | + if ($payment instanceof EE_Payment) { |
|
623 | + $payment_desc = sprintf( |
|
624 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
625 | + $payment->txn_id_chq_nmbr() !== '' |
|
626 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
627 | + : '', |
|
628 | + $payment->timestamp() |
|
629 | + ); |
|
630 | + } |
|
631 | + // start of row |
|
632 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
633 | + // payment desc |
|
634 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
635 | + // total td |
|
636 | + $html .= EEH_HTML::td( |
|
637 | + EEH_Template::format_currency( |
|
638 | + $registration_payment->amount(), |
|
639 | + false, |
|
640 | + false |
|
641 | + ), |
|
642 | + '', |
|
643 | + 'spco-nowrap total jst-rght' |
|
644 | + ); |
|
645 | + // end of row |
|
646 | + $html .= EEH_HTML::trx(); |
|
647 | + } |
|
648 | + } |
|
649 | + if ($line_item->total()) { |
|
650 | + // start of row |
|
651 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
652 | + // total td |
|
653 | + $html .= EEH_HTML::td( |
|
654 | + esc_html__('Amount Owing', 'event_espresso'), |
|
655 | + '', |
|
656 | + 'total_currency total jst-rght', |
|
657 | + '', |
|
658 | + ' colspan="3"' |
|
659 | + ); |
|
660 | + // total td |
|
661 | + $html .= EEH_HTML::td( |
|
662 | + EEH_Template::format_currency($owing, false, false), |
|
663 | + '', |
|
664 | + 'spco-nowrap total jst-rght' |
|
665 | + ); |
|
666 | + // end of row |
|
667 | + $html .= EEH_HTML::trx(); |
|
668 | + } |
|
669 | + } |
|
670 | + } |
|
671 | + $this->_grand_total = $owing; |
|
672 | + return $html; |
|
673 | + } |
|
674 | 674 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $html = ''; |
85 | 85 | // set some default options and merge with incoming |
86 | 86 | $default_options = array( |
87 | - 'show_desc' => true, // true false |
|
87 | + 'show_desc' => true, // true false |
|
88 | 88 | 'odd' => false, |
89 | 89 | ); |
90 | 90 | $options = array_merge($default_options, (array) $options); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $text = esc_html__('Sub-Total', 'event_espresso'); |
120 | 120 | if ($line_item->OBJ_type() === 'Event') { |
121 | 121 | $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
122 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
122 | + if ( ! isset($this->_events[$options['event_id']])) { |
|
123 | 123 | $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
124 | 124 | // if event has default reg status of Not Approved, then don't display info on it |
125 | 125 | if ( |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | // unless there are registrations for it that are returning to pay |
131 | 131 | if (isset($options['registrations']) && is_array($options['registrations'])) { |
132 | 132 | foreach ($options['registrations'] as $registration) { |
133 | - if (! $registration instanceof EE_Registration) { |
|
133 | + if ( ! $registration instanceof EE_Registration) { |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | $display_event = $registration->event_ID() === $options['event_id'] |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | : $display_event; |
140 | 140 | } |
141 | 141 | } |
142 | - if (! $display_event) { |
|
142 | + if ( ! $display_event) { |
|
143 | 143 | return ''; |
144 | 144 | } |
145 | 145 | } |
146 | - $this->_events[ $options['event_id'] ] = 0; |
|
146 | + $this->_events[$options['event_id']] = 0; |
|
147 | 147 | $html .= $this->_event_row($line_item); |
148 | 148 | $text = esc_html__('Event Sub-Total', 'event_espresso'); |
149 | 149 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | // recursively feed children back into this method |
155 | 155 | $html .= $this->display_line_item($child_line_item, $options, $line_item); |
156 | 156 | } |
157 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
157 | + $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
158 | 158 | $sub_total += $event_sub_total; |
159 | 159 | if ( |
160 | 160 | ( |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
264 | 264 | ( |
265 | 265 | $options['show_desc'] |
266 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
266 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
267 | 267 | : '' |
268 | 268 | ), |
269 | 269 | $line_item, |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $line_item->total(), |
300 | 300 | $line_item |
301 | 301 | ); |
302 | - $this->_events[ $options['event_id'] ] += $total; |
|
302 | + $this->_events[$options['event_id']] += $total; |
|
303 | 303 | // total td |
304 | 304 | $html .= EEH_HTML::td( |
305 | 305 | EEH_Template::format_currency($total, false, false), |
@@ -326,18 +326,18 @@ discard block |
||
326 | 326 | // start of row |
327 | 327 | $row_class = $options['odd'] ? 'item odd' : 'item'; |
328 | 328 | $html = EEH_HTML::tr('', '', $row_class); |
329 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
329 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : ''; |
|
330 | 330 | // name && desc |
331 | 331 | $name_and_desc = apply_filters( |
332 | 332 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
333 | - $obj_name . $line_item->name(), |
|
333 | + $obj_name.$line_item->name(), |
|
334 | 334 | $line_item |
335 | 335 | ); |
336 | 336 | $name_and_desc .= apply_filters( |
337 | 337 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
338 | 338 | ( |
339 | 339 | $options['show_desc'] |
340 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
340 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
341 | 341 | : '' |
342 | 342 | ), |
343 | 343 | $line_item, |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
356 | 356 | // price td |
357 | 357 | if ($line_item->is_percent()) { |
358 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
358 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'spco-nowrap item_c jst-rght'); |
|
359 | 359 | } else { |
360 | 360 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
361 | 361 | } |
@@ -363,8 +363,8 @@ discard block |
||
363 | 363 | $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
364 | 364 | // $total = $line_item->total() * $line_item->quantity(); |
365 | 365 | $total = $line_item->total(); |
366 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
367 | - $this->_events[ $options['event_id'] ] += $total; |
|
366 | + if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
367 | + $this->_events[$options['event_id']] += $total; |
|
368 | 368 | } |
369 | 369 | // total td |
370 | 370 | $html .= EEH_HTML::td( |
@@ -459,8 +459,8 @@ discard block |
||
459 | 459 | // name && desc |
460 | 460 | $name_and_desc = $line_item->name(); |
461 | 461 | $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
462 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
463 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
462 | + . esc_html__(' * taxable items', 'event_espresso').'</span>'; |
|
463 | + $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : ''; |
|
464 | 464 | // name td |
465 | 465 | $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
466 | 466 | $name_and_desc, |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | 'item_l sub-item' |
469 | 469 | ); |
470 | 470 | // percent td |
471 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
471 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'spco-nowrap jst-rght', ''); |
|
472 | 472 | // empty td (price) |
473 | 473 | $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
474 | 474 | // total td |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | $registration_payments += $registration->registration_payments(); |
614 | 614 | } |
615 | 615 | } |
616 | - if (! empty($registration_payments)) { |
|
616 | + if ( ! empty($registration_payments)) { |
|
617 | 617 | foreach ($registration_payments as $registration_payment) { |
618 | 618 | if ($registration_payment instanceof EE_Registration_Payment) { |
619 | 619 | $owing -= $registration_payment->amount(); |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | $payment_desc = sprintf( |
624 | 624 | esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
625 | 625 | $payment->txn_id_chq_nmbr() !== '' |
626 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
626 | + ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> ' |
|
627 | 627 | : '', |
628 | 628 | $payment->timestamp() |
629 | 629 | ); |
@@ -17,192 +17,192 @@ |
||
17 | 17 | class RegistrantForm extends EE_Form_Section_Proper |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var EEM_Event_Question_Group |
|
22 | - */ |
|
23 | - public $event_question_group_model; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - private $has_questions = false; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * RegistrantForm constructor. |
|
33 | - * |
|
34 | - * @param EE_Registration $registration |
|
35 | - * @param bool $admin_request |
|
36 | - * @param bool $copy_attendee_info |
|
37 | - * @param callable $enablePrintCopyInfo |
|
38 | - * @param EEM_Event_Question_Group $event_question_group_model |
|
39 | - * @throws EE_Error |
|
40 | - * @throws ReflectionException |
|
41 | - */ |
|
42 | - public function __construct( |
|
43 | - EE_Registration $registration, |
|
44 | - bool $admin_request, |
|
45 | - bool $copy_attendee_info, |
|
46 | - callable $enablePrintCopyInfo, |
|
47 | - EEM_Event_Question_Group $event_question_group_model |
|
48 | - ) { |
|
49 | - $this->event_question_group_model = $event_question_group_model; |
|
50 | - parent::__construct( |
|
51 | - $this->generateFormArgs($registration, $admin_request, $copy_attendee_info, $enablePrintCopyInfo) |
|
52 | - ); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function hasQuestions(): bool |
|
60 | - { |
|
61 | - return $this->has_questions; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param EE_Registration $registration |
|
67 | - * @param bool $admin_request |
|
68 | - * @param bool $copy_attendee_info |
|
69 | - * @param callable $enablePrintCopyInfo |
|
70 | - * @return array |
|
71 | - * @throws EE_Error |
|
72 | - * @throws ReflectionException |
|
73 | - */ |
|
74 | - private function generateFormArgs( |
|
75 | - EE_Registration $registration, |
|
76 | - bool $admin_request, |
|
77 | - bool $copy_attendee_info, |
|
78 | - callable $enablePrintCopyInfo |
|
79 | - ): array { |
|
80 | - static $attendee_nmbr = 1; |
|
81 | - $form_args = []; |
|
82 | - // verify that registration has valid event |
|
83 | - if ($registration->event() instanceof EE_Event) { |
|
84 | - $field_name = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext( |
|
85 | - $registration->is_primary_registrant() |
|
86 | - ); |
|
87 | - $question_groups = $registration->event()->question_groups( |
|
88 | - apply_filters( |
|
89 | - // @codingStandardsIgnoreStart |
|
90 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
91 | - // @codingStandardsIgnoreEnd |
|
92 | - [ |
|
93 | - [ |
|
94 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
95 | - $field_name => true, |
|
96 | - ], |
|
97 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
98 | - ], |
|
99 | - $registration, |
|
100 | - $this |
|
101 | - ) |
|
102 | - ); |
|
103 | - if ($question_groups) { |
|
104 | - // array of params to pass to parent constructor |
|
105 | - $form_args = [ |
|
106 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
107 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
108 | - 'html_style' => $admin_request |
|
109 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
110 | - : '', |
|
111 | - 'subsections' => [], |
|
112 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
113 | - [ |
|
114 | - 'legend_class' => 'spco-attendee-lgnd', |
|
115 | - 'legend_text' => sprintf( |
|
116 | - esc_html_x( |
|
117 | - 'Attendee %d', |
|
118 | - 'Attendee 123', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - $attendee_nmbr |
|
122 | - ), |
|
123 | - ] |
|
124 | - ), |
|
125 | - ]; |
|
126 | - foreach ($question_groups as $question_group) { |
|
127 | - if ($question_group instanceof EE_Question_Group) { |
|
128 | - $question_group_reg_form = LoaderFactory::getNew( |
|
129 | - RegFormQuestionGroup::class, |
|
130 | - [$registration, $question_group, $admin_request] |
|
131 | - ); |
|
132 | - $form_args['subsections'][ $question_group->identifier() ] = apply_filters( |
|
133 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
134 | - $question_group_reg_form, |
|
135 | - $registration, |
|
136 | - $question_group, |
|
137 | - $this |
|
138 | - ); |
|
139 | - } |
|
140 | - } |
|
141 | - // add hidden input |
|
142 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->additionalAttendeeRegInfoInput( |
|
143 | - $registration |
|
144 | - ); |
|
145 | - |
|
146 | - // If we have question groups for additional attendees, then display the copy options |
|
147 | - $printCopyInfo = apply_filters( |
|
148 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
149 | - $attendee_nmbr > 1 && $copy_attendee_info, |
|
150 | - $attendee_nmbr |
|
151 | - ); |
|
152 | - if ($printCopyInfo) { |
|
153 | - $enablePrintCopyInfo(); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - if ($registration->is_primary_registrant()) { |
|
158 | - // generate hidden input |
|
159 | - $form_args['subsections']['primary_registrant'] = $this->additionalPrimaryRegistrantInputs( |
|
160 | - $registration |
|
161 | - ); |
|
162 | - } |
|
163 | - } |
|
164 | - } |
|
165 | - $attendee_nmbr++; |
|
166 | - |
|
167 | - // Increment the reg forms number if form is valid. |
|
168 | - if (! empty($form_args)) { |
|
169 | - $this->has_questions = true; |
|
170 | - } |
|
171 | - |
|
172 | - return $form_args; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @param EE_Registration $registration |
|
178 | - * @return EE_Form_Input_Base |
|
179 | - * @throws EE_Error |
|
180 | - */ |
|
181 | - private function additionalAttendeeRegInfoInput(EE_Registration $registration) |
|
182 | - { |
|
183 | - // generate hidden input |
|
184 | - return new EE_Hidden_Input( |
|
185 | - [ |
|
186 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
187 | - 'default' => true, |
|
188 | - ] |
|
189 | - ); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @param EE_Registration $registration |
|
195 | - * @return EE_Form_Input_Base |
|
196 | - * @throws EE_Error |
|
197 | - */ |
|
198 | - private function additionalPrimaryRegistrantInputs(EE_Registration $registration) |
|
199 | - { |
|
200 | - // generate hidden input |
|
201 | - return new EE_Hidden_Input( |
|
202 | - [ |
|
203 | - 'html_id' => 'primary_registrant', |
|
204 | - 'default' => $registration->reg_url_link(), |
|
205 | - ] |
|
206 | - ); |
|
207 | - } |
|
20 | + /** |
|
21 | + * @var EEM_Event_Question_Group |
|
22 | + */ |
|
23 | + public $event_question_group_model; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + private $has_questions = false; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * RegistrantForm constructor. |
|
33 | + * |
|
34 | + * @param EE_Registration $registration |
|
35 | + * @param bool $admin_request |
|
36 | + * @param bool $copy_attendee_info |
|
37 | + * @param callable $enablePrintCopyInfo |
|
38 | + * @param EEM_Event_Question_Group $event_question_group_model |
|
39 | + * @throws EE_Error |
|
40 | + * @throws ReflectionException |
|
41 | + */ |
|
42 | + public function __construct( |
|
43 | + EE_Registration $registration, |
|
44 | + bool $admin_request, |
|
45 | + bool $copy_attendee_info, |
|
46 | + callable $enablePrintCopyInfo, |
|
47 | + EEM_Event_Question_Group $event_question_group_model |
|
48 | + ) { |
|
49 | + $this->event_question_group_model = $event_question_group_model; |
|
50 | + parent::__construct( |
|
51 | + $this->generateFormArgs($registration, $admin_request, $copy_attendee_info, $enablePrintCopyInfo) |
|
52 | + ); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function hasQuestions(): bool |
|
60 | + { |
|
61 | + return $this->has_questions; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param EE_Registration $registration |
|
67 | + * @param bool $admin_request |
|
68 | + * @param bool $copy_attendee_info |
|
69 | + * @param callable $enablePrintCopyInfo |
|
70 | + * @return array |
|
71 | + * @throws EE_Error |
|
72 | + * @throws ReflectionException |
|
73 | + */ |
|
74 | + private function generateFormArgs( |
|
75 | + EE_Registration $registration, |
|
76 | + bool $admin_request, |
|
77 | + bool $copy_attendee_info, |
|
78 | + callable $enablePrintCopyInfo |
|
79 | + ): array { |
|
80 | + static $attendee_nmbr = 1; |
|
81 | + $form_args = []; |
|
82 | + // verify that registration has valid event |
|
83 | + if ($registration->event() instanceof EE_Event) { |
|
84 | + $field_name = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext( |
|
85 | + $registration->is_primary_registrant() |
|
86 | + ); |
|
87 | + $question_groups = $registration->event()->question_groups( |
|
88 | + apply_filters( |
|
89 | + // @codingStandardsIgnoreStart |
|
90 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
91 | + // @codingStandardsIgnoreEnd |
|
92 | + [ |
|
93 | + [ |
|
94 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
95 | + $field_name => true, |
|
96 | + ], |
|
97 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
98 | + ], |
|
99 | + $registration, |
|
100 | + $this |
|
101 | + ) |
|
102 | + ); |
|
103 | + if ($question_groups) { |
|
104 | + // array of params to pass to parent constructor |
|
105 | + $form_args = [ |
|
106 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
107 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
108 | + 'html_style' => $admin_request |
|
109 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
110 | + : '', |
|
111 | + 'subsections' => [], |
|
112 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
113 | + [ |
|
114 | + 'legend_class' => 'spco-attendee-lgnd', |
|
115 | + 'legend_text' => sprintf( |
|
116 | + esc_html_x( |
|
117 | + 'Attendee %d', |
|
118 | + 'Attendee 123', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + $attendee_nmbr |
|
122 | + ), |
|
123 | + ] |
|
124 | + ), |
|
125 | + ]; |
|
126 | + foreach ($question_groups as $question_group) { |
|
127 | + if ($question_group instanceof EE_Question_Group) { |
|
128 | + $question_group_reg_form = LoaderFactory::getNew( |
|
129 | + RegFormQuestionGroup::class, |
|
130 | + [$registration, $question_group, $admin_request] |
|
131 | + ); |
|
132 | + $form_args['subsections'][ $question_group->identifier() ] = apply_filters( |
|
133 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
134 | + $question_group_reg_form, |
|
135 | + $registration, |
|
136 | + $question_group, |
|
137 | + $this |
|
138 | + ); |
|
139 | + } |
|
140 | + } |
|
141 | + // add hidden input |
|
142 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->additionalAttendeeRegInfoInput( |
|
143 | + $registration |
|
144 | + ); |
|
145 | + |
|
146 | + // If we have question groups for additional attendees, then display the copy options |
|
147 | + $printCopyInfo = apply_filters( |
|
148 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
149 | + $attendee_nmbr > 1 && $copy_attendee_info, |
|
150 | + $attendee_nmbr |
|
151 | + ); |
|
152 | + if ($printCopyInfo) { |
|
153 | + $enablePrintCopyInfo(); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + if ($registration->is_primary_registrant()) { |
|
158 | + // generate hidden input |
|
159 | + $form_args['subsections']['primary_registrant'] = $this->additionalPrimaryRegistrantInputs( |
|
160 | + $registration |
|
161 | + ); |
|
162 | + } |
|
163 | + } |
|
164 | + } |
|
165 | + $attendee_nmbr++; |
|
166 | + |
|
167 | + // Increment the reg forms number if form is valid. |
|
168 | + if (! empty($form_args)) { |
|
169 | + $this->has_questions = true; |
|
170 | + } |
|
171 | + |
|
172 | + return $form_args; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @param EE_Registration $registration |
|
178 | + * @return EE_Form_Input_Base |
|
179 | + * @throws EE_Error |
|
180 | + */ |
|
181 | + private function additionalAttendeeRegInfoInput(EE_Registration $registration) |
|
182 | + { |
|
183 | + // generate hidden input |
|
184 | + return new EE_Hidden_Input( |
|
185 | + [ |
|
186 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
187 | + 'default' => true, |
|
188 | + ] |
|
189 | + ); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @param EE_Registration $registration |
|
195 | + * @return EE_Form_Input_Base |
|
196 | + * @throws EE_Error |
|
197 | + */ |
|
198 | + private function additionalPrimaryRegistrantInputs(EE_Registration $registration) |
|
199 | + { |
|
200 | + // generate hidden input |
|
201 | + return new EE_Hidden_Input( |
|
202 | + [ |
|
203 | + 'html_id' => 'primary_registrant', |
|
204 | + 'default' => $registration->reg_url_link(), |
|
205 | + ] |
|
206 | + ); |
|
207 | + } |
|
208 | 208 | } |
@@ -22,2064 +22,2064 @@ |
||
22 | 22 | class EEH_Line_Item |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Adds a simple item (unrelated to any other model object) to the provided PARENT line item. |
|
27 | - * Does NOT automatically re-calculate the line item totals or update the related transaction. |
|
28 | - * You should call recalculate_total_including_taxes() on the grant total line item after this |
|
29 | - * to update the subtotals, and EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
30 | - * to keep the registration final prices in-sync with the transaction's total. |
|
31 | - * |
|
32 | - * @param EE_Line_Item $parent_line_item |
|
33 | - * @param string $name |
|
34 | - * @param float $unit_price |
|
35 | - * @param string $description |
|
36 | - * @param int $quantity |
|
37 | - * @param boolean $taxable |
|
38 | - * @param boolean $code if set to a value, ensures there is only one line item with that code |
|
39 | - * @return boolean success |
|
40 | - * @throws EE_Error |
|
41 | - * @throws InvalidArgumentException |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - * @throws InvalidInterfaceException |
|
44 | - * @throws ReflectionException |
|
45 | - */ |
|
46 | - public static function add_unrelated_item( |
|
47 | - EE_Line_Item $parent_line_item, |
|
48 | - $name, |
|
49 | - $unit_price, |
|
50 | - $description = '', |
|
51 | - $quantity = 1, |
|
52 | - $taxable = false, |
|
53 | - $code = null |
|
54 | - ) { |
|
55 | - $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
56 | - $line_item = EE_Line_Item::new_instance(array( |
|
57 | - 'LIN_name' => $name, |
|
58 | - 'LIN_desc' => $description, |
|
59 | - 'LIN_unit_price' => $unit_price, |
|
60 | - 'LIN_quantity' => $quantity, |
|
61 | - 'LIN_percent' => null, |
|
62 | - 'LIN_is_taxable' => $taxable, |
|
63 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
64 | - 'LIN_total' => (float) $unit_price * (int) $quantity, |
|
65 | - 'LIN_type' => EEM_Line_Item::type_line_item, |
|
66 | - 'LIN_code' => $code, |
|
67 | - )); |
|
68 | - $line_item = apply_filters( |
|
69 | - 'FHEE__EEH_Line_Item__add_unrelated_item__line_item', |
|
70 | - $line_item, |
|
71 | - $parent_line_item |
|
72 | - ); |
|
73 | - return self::add_item($parent_line_item, $line_item); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * Adds a simple item ( unrelated to any other model object) to the total line item, |
|
79 | - * in the correct spot in the line item tree. Does not automatically |
|
80 | - * re-calculate the line item totals, nor update the related transaction, nor upgrade the transaction's |
|
81 | - * registrations' final prices (which should probably change because of this). |
|
82 | - * You should call recalculate_total_including_taxes() on the grand total line item, then |
|
83 | - * update the transaction's total, and EE_Registration_Processor::update_registration_final_prices() |
|
84 | - * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
85 | - * |
|
86 | - * @param EE_Line_Item $parent_line_item |
|
87 | - * @param string $name |
|
88 | - * @param float $percentage_amount |
|
89 | - * @param string $description |
|
90 | - * @param boolean $taxable |
|
91 | - * @return boolean success |
|
92 | - * @throws EE_Error |
|
93 | - */ |
|
94 | - public static function add_percentage_based_item( |
|
95 | - EE_Line_Item $parent_line_item, |
|
96 | - $name, |
|
97 | - $percentage_amount, |
|
98 | - $description = '', |
|
99 | - $taxable = false |
|
100 | - ) { |
|
101 | - $line_item = EE_Line_Item::new_instance(array( |
|
102 | - 'LIN_name' => $name, |
|
103 | - 'LIN_desc' => $description, |
|
104 | - 'LIN_unit_price' => 0, |
|
105 | - 'LIN_percent' => $percentage_amount, |
|
106 | - 'LIN_quantity' => 1, |
|
107 | - 'LIN_is_taxable' => $taxable, |
|
108 | - 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
109 | - 'LIN_type' => EEM_Line_Item::type_line_item, |
|
110 | - 'LIN_parent' => $parent_line_item->ID(), |
|
111 | - )); |
|
112 | - $line_item = apply_filters( |
|
113 | - 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
|
114 | - $line_item |
|
115 | - ); |
|
116 | - return $parent_line_item->add_child_line_item($line_item, false); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Returns the new line item created by adding a purchase of the ticket |
|
122 | - * ensures that ticket line item is saved, and that cart total has been recalculated. |
|
123 | - * If this ticket has already been purchased, just increments its count. |
|
124 | - * Automatically re-calculates the line item totals and updates the related transaction. But |
|
125 | - * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
126 | - * should probably change because of this). |
|
127 | - * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
128 | - * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
129 | - * |
|
130 | - * @param EE_Line_Item $total_line_item grand total line item of type EEM_Line_Item::type_total |
|
131 | - * @param EE_Ticket $ticket |
|
132 | - * @param int $qty |
|
133 | - * @return EE_Line_Item |
|
134 | - * @throws EE_Error |
|
135 | - * @throws InvalidArgumentException |
|
136 | - * @throws InvalidDataTypeException |
|
137 | - * @throws InvalidInterfaceException |
|
138 | - * @throws ReflectionException |
|
139 | - */ |
|
140 | - public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) |
|
141 | - { |
|
142 | - if (! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
143 | - throw new EE_Error( |
|
144 | - sprintf( |
|
145 | - esc_html__( |
|
146 | - 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', |
|
147 | - 'event_espresso' |
|
148 | - ), |
|
149 | - $ticket->ID(), |
|
150 | - $total_line_item->ID() |
|
151 | - ) |
|
152 | - ); |
|
153 | - } |
|
154 | - // either increment the qty for an existing ticket |
|
155 | - $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
156 | - // or add a new one |
|
157 | - if (! $line_item instanceof EE_Line_Item) { |
|
158 | - $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
159 | - } |
|
160 | - $total_line_item->recalculate_total_including_taxes(); |
|
161 | - return $line_item; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns the new line item created by adding a purchase of the ticket |
|
167 | - * |
|
168 | - * @param EE_Line_Item $total_line_item |
|
169 | - * @param EE_Ticket $ticket |
|
170 | - * @param int $qty |
|
171 | - * @return EE_Line_Item |
|
172 | - * @throws EE_Error |
|
173 | - * @throws InvalidArgumentException |
|
174 | - * @throws InvalidDataTypeException |
|
175 | - * @throws InvalidInterfaceException |
|
176 | - * @throws ReflectionException |
|
177 | - */ |
|
178 | - public static function increment_ticket_qty_if_already_in_cart( |
|
179 | - EE_Line_Item $total_line_item, |
|
180 | - EE_Ticket $ticket, |
|
181 | - $qty = 1 |
|
182 | - ) { |
|
183 | - $line_item = null; |
|
184 | - if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
185 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
186 | - foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
187 | - if ( |
|
188 | - $ticket_line_item instanceof EE_Line_Item |
|
189 | - && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
|
190 | - ) { |
|
191 | - $line_item = $ticket_line_item; |
|
192 | - break; |
|
193 | - } |
|
194 | - } |
|
195 | - } |
|
196 | - if ($line_item instanceof EE_Line_Item) { |
|
197 | - EEH_Line_Item::increment_quantity($line_item, $qty); |
|
198 | - return $line_item; |
|
199 | - } |
|
200 | - return null; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Increments the line item and all its children's quantity by $qty (but percent line items are unaffected). |
|
206 | - * Does NOT save or recalculate other line items totals |
|
207 | - * |
|
208 | - * @param EE_Line_Item $line_item |
|
209 | - * @param int $qty |
|
210 | - * @return void |
|
211 | - * @throws EE_Error |
|
212 | - * @throws InvalidArgumentException |
|
213 | - * @throws InvalidDataTypeException |
|
214 | - * @throws InvalidInterfaceException |
|
215 | - * @throws ReflectionException |
|
216 | - */ |
|
217 | - public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) |
|
218 | - { |
|
219 | - if (! $line_item->is_percent()) { |
|
220 | - $qty += $line_item->quantity(); |
|
221 | - $line_item->set_quantity($qty); |
|
222 | - $line_item->set_total($line_item->unit_price() * $qty); |
|
223 | - $line_item->save(); |
|
224 | - } |
|
225 | - foreach ($line_item->children() as $child) { |
|
226 | - if ($child->is_sub_line_item()) { |
|
227 | - EEH_Line_Item::update_quantity($child, $qty); |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * Decrements the line item and all its children's quantity by $qty (but percent line items are unaffected). |
|
235 | - * Does NOT save or recalculate other line items totals |
|
236 | - * |
|
237 | - * @param EE_Line_Item $line_item |
|
238 | - * @param int $qty |
|
239 | - * @return void |
|
240 | - * @throws EE_Error |
|
241 | - * @throws InvalidArgumentException |
|
242 | - * @throws InvalidDataTypeException |
|
243 | - * @throws InvalidInterfaceException |
|
244 | - * @throws ReflectionException |
|
245 | - */ |
|
246 | - public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) |
|
247 | - { |
|
248 | - if (! $line_item->is_percent()) { |
|
249 | - $qty = $line_item->quantity() - $qty; |
|
250 | - $qty = max($qty, 0); |
|
251 | - $line_item->set_quantity($qty); |
|
252 | - $line_item->set_total($line_item->unit_price() * $qty); |
|
253 | - $line_item->save(); |
|
254 | - } |
|
255 | - foreach ($line_item->children() as $child) { |
|
256 | - if ($child->is_sub_line_item()) { |
|
257 | - EEH_Line_Item::update_quantity($child, $qty); |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * Updates the line item and its children's quantities to the specified number. |
|
265 | - * Does NOT save them or recalculate totals. |
|
266 | - * |
|
267 | - * @param EE_Line_Item $line_item |
|
268 | - * @param int $new_quantity |
|
269 | - * @throws EE_Error |
|
270 | - * @throws InvalidArgumentException |
|
271 | - * @throws InvalidDataTypeException |
|
272 | - * @throws InvalidInterfaceException |
|
273 | - * @throws ReflectionException |
|
274 | - */ |
|
275 | - public static function update_quantity(EE_Line_Item $line_item, $new_quantity) |
|
276 | - { |
|
277 | - if (! $line_item->is_percent()) { |
|
278 | - $line_item->set_quantity($new_quantity); |
|
279 | - $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
280 | - $line_item->save(); |
|
281 | - } |
|
282 | - foreach ($line_item->children() as $child) { |
|
283 | - if ($child->is_sub_line_item()) { |
|
284 | - EEH_Line_Item::update_quantity($child, $new_quantity); |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Returns the new line item created by adding a purchase of the ticket |
|
292 | - * |
|
293 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
294 | - * @param EE_Ticket $ticket |
|
295 | - * @param int $qty |
|
296 | - * @return EE_Line_Item |
|
297 | - * @throws EE_Error |
|
298 | - * @throws InvalidArgumentException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws InvalidInterfaceException |
|
301 | - * @throws ReflectionException |
|
302 | - */ |
|
303 | - public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) |
|
304 | - { |
|
305 | - $datetimes = $ticket->datetimes(); |
|
306 | - $first_datetime = reset($datetimes); |
|
307 | - $first_datetime_name = esc_html__('Event', 'event_espresso'); |
|
308 | - if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
309 | - $first_datetime_name = $first_datetime->event()->name(); |
|
310 | - } |
|
311 | - $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
312 | - // get event subtotal line |
|
313 | - $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
314 | - $taxes = $ticket->tax_price_modifiers(); |
|
315 | - $is_taxable = empty($taxes) ? $ticket->taxable() : false; |
|
316 | - // add $ticket to cart |
|
317 | - $line_item = EE_Line_Item::new_instance(array( |
|
318 | - 'LIN_name' => $ticket->name(), |
|
319 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
320 | - 'LIN_unit_price' => $ticket->price(), |
|
321 | - 'LIN_quantity' => $qty, |
|
322 | - 'LIN_is_taxable' => $is_taxable, |
|
323 | - 'LIN_order' => count($events_sub_total->children()), |
|
324 | - 'LIN_total' => $ticket->price() * $qty, |
|
325 | - 'LIN_type' => EEM_Line_Item::type_line_item, |
|
326 | - 'OBJ_ID' => $ticket->ID(), |
|
327 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
328 | - )); |
|
329 | - $line_item = apply_filters( |
|
330 | - 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
|
331 | - $line_item |
|
332 | - ); |
|
333 | - $events_sub_total->add_child_line_item($line_item); |
|
334 | - // now add the sub-line items |
|
335 | - $running_total_for_ticket = 0; |
|
336 | - foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
337 | - $sign = $price->is_discount() ? -1 : 1; |
|
338 | - $price_total = $price->is_percent() |
|
339 | - ? $running_total_for_ticket * $price->amount() / 100 |
|
340 | - : $price->amount() * $qty; |
|
341 | - $sub_line_item = EE_Line_Item::new_instance(array( |
|
342 | - 'LIN_name' => $price->name(), |
|
343 | - 'LIN_desc' => $price->desc(), |
|
344 | - 'LIN_quantity' => $price->is_percent() ? null : $qty, |
|
345 | - 'LIN_is_taxable' => false, |
|
346 | - 'LIN_order' => $price->order(), |
|
347 | - 'LIN_total' => $sign * $price_total, |
|
348 | - 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
|
349 | - 'OBJ_ID' => $price->ID(), |
|
350 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PRICE, |
|
351 | - )); |
|
352 | - $sub_line_item = apply_filters( |
|
353 | - 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
|
354 | - $sub_line_item |
|
355 | - ); |
|
356 | - if ($price->is_percent()) { |
|
357 | - $sub_line_item->set_percent($sign * $price->amount()); |
|
358 | - } else { |
|
359 | - $sub_line_item->set_unit_price($sign * $price->amount()); |
|
360 | - } |
|
361 | - $running_total_for_ticket += $price_total; |
|
362 | - $line_item->add_child_line_item($sub_line_item); |
|
363 | - } |
|
364 | - return $line_item; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Adds the specified item under the pre-tax-sub-total line item. Automatically |
|
370 | - * re-calculates the line item totals and updates the related transaction. But |
|
371 | - * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
372 | - * should probably change because of this). |
|
373 | - * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
374 | - * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
375 | - * |
|
376 | - * @param EE_Line_Item $total_line_item |
|
377 | - * @param EE_Line_Item $item to be added |
|
378 | - * @return boolean |
|
379 | - * @throws EE_Error |
|
380 | - * @throws InvalidArgumentException |
|
381 | - * @throws InvalidDataTypeException |
|
382 | - * @throws InvalidInterfaceException |
|
383 | - * @throws ReflectionException |
|
384 | - */ |
|
385 | - public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) |
|
386 | - { |
|
387 | - $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
388 | - if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
389 | - $success = $pre_tax_subtotal->add_child_line_item($item); |
|
390 | - } else { |
|
391 | - return false; |
|
392 | - } |
|
393 | - $total_line_item->recalculate_total_including_taxes(); |
|
394 | - return $success; |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * cancels an existing ticket line item, |
|
400 | - * by decrementing it's quantity by 1 and adding a new "type_cancellation" sub-line-item. |
|
401 | - * ALL totals and subtotals will NEED TO BE UPDATED after performing this action |
|
402 | - * |
|
403 | - * @param EE_Line_Item $ticket_line_item |
|
404 | - * @param int $qty |
|
405 | - * @return bool success |
|
406 | - * @throws EE_Error |
|
407 | - * @throws InvalidArgumentException |
|
408 | - * @throws InvalidDataTypeException |
|
409 | - * @throws InvalidInterfaceException |
|
410 | - * @throws ReflectionException |
|
411 | - */ |
|
412 | - public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) |
|
413 | - { |
|
414 | - // validate incoming line_item |
|
415 | - if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
416 | - throw new EE_Error( |
|
417 | - sprintf( |
|
418 | - esc_html__( |
|
419 | - 'The supplied line item must have an Object Type of "Ticket", not %1$s.', |
|
420 | - 'event_espresso' |
|
421 | - ), |
|
422 | - $ticket_line_item->type() |
|
423 | - ) |
|
424 | - ); |
|
425 | - } |
|
426 | - if ($ticket_line_item->quantity() < $qty) { |
|
427 | - throw new EE_Error( |
|
428 | - sprintf( |
|
429 | - esc_html__( |
|
430 | - 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', |
|
431 | - 'event_espresso' |
|
432 | - ), |
|
433 | - $qty, |
|
434 | - $ticket_line_item->quantity() |
|
435 | - ) |
|
436 | - ); |
|
437 | - } |
|
438 | - // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
|
439 | - $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
440 | - foreach ($ticket_line_item->children() as $child_line_item) { |
|
441 | - if ( |
|
442 | - $child_line_item->is_sub_line_item() |
|
443 | - && ! $child_line_item->is_percent() |
|
444 | - && ! $child_line_item->is_cancellation() |
|
445 | - ) { |
|
446 | - $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
447 | - } |
|
448 | - } |
|
449 | - // get cancellation sub line item |
|
450 | - $cancellation_line_item = EEH_Line_Item::get_descendants_of_type( |
|
451 | - $ticket_line_item, |
|
452 | - EEM_Line_Item::type_cancellation |
|
453 | - ); |
|
454 | - $cancellation_line_item = reset($cancellation_line_item); |
|
455 | - // verify that this ticket was indeed previously cancelled |
|
456 | - if ($cancellation_line_item instanceof EE_Line_Item) { |
|
457 | - // increment cancelled quantity |
|
458 | - $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
459 | - } else { |
|
460 | - // create cancellation sub line item |
|
461 | - $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
462 | - 'LIN_name' => esc_html__('Cancellation', 'event_espresso'), |
|
463 | - 'LIN_desc' => sprintf( |
|
464 | - esc_html_x( |
|
465 | - 'Cancelled %1$s : %2$s', |
|
466 | - 'Cancelled Ticket Name : 2015-01-01 11:11', |
|
467 | - 'event_espresso' |
|
468 | - ), |
|
469 | - $ticket_line_item->name(), |
|
470 | - current_time(get_option('date_format') . ' ' . get_option('time_format')) |
|
471 | - ), |
|
472 | - 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
|
473 | - 'LIN_quantity' => $qty, |
|
474 | - 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
|
475 | - 'LIN_order' => count($ticket_line_item->children()), |
|
476 | - 'LIN_total' => 0, // $ticket_line_item->unit_price() |
|
477 | - 'LIN_type' => EEM_Line_Item::type_cancellation, |
|
478 | - )); |
|
479 | - $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
480 | - } |
|
481 | - if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
482 | - // decrement parent line item quantity |
|
483 | - $event_line_item = $ticket_line_item->parent(); |
|
484 | - if ( |
|
485 | - $event_line_item instanceof EE_Line_Item |
|
486 | - && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
487 | - ) { |
|
488 | - $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
489 | - $event_line_item->save(); |
|
490 | - } |
|
491 | - EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
492 | - return true; |
|
493 | - } |
|
494 | - return false; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * reinstates (un-cancels?) a previously canceled ticket line item, |
|
500 | - * by incrementing it's quantity by 1, and decrementing it's "type_cancellation" sub-line-item. |
|
501 | - * ALL totals and subtotals will NEED TO BE UPDATED after performing this action |
|
502 | - * |
|
503 | - * @param EE_Line_Item $ticket_line_item |
|
504 | - * @param int $qty |
|
505 | - * @return bool success |
|
506 | - * @throws EE_Error |
|
507 | - * @throws InvalidArgumentException |
|
508 | - * @throws InvalidDataTypeException |
|
509 | - * @throws InvalidInterfaceException |
|
510 | - * @throws ReflectionException |
|
511 | - */ |
|
512 | - public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) |
|
513 | - { |
|
514 | - // validate incoming line_item |
|
515 | - if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
516 | - throw new EE_Error( |
|
517 | - sprintf( |
|
518 | - esc_html__( |
|
519 | - 'The supplied line item must have an Object Type of "Ticket", not %1$s.', |
|
520 | - 'event_espresso' |
|
521 | - ), |
|
522 | - $ticket_line_item->type() |
|
523 | - ) |
|
524 | - ); |
|
525 | - } |
|
526 | - // get cancellation sub line item |
|
527 | - $cancellation_line_item = EEH_Line_Item::get_descendants_of_type( |
|
528 | - $ticket_line_item, |
|
529 | - EEM_Line_Item::type_cancellation |
|
530 | - ); |
|
531 | - $cancellation_line_item = reset($cancellation_line_item); |
|
532 | - // verify that this ticket was indeed previously cancelled |
|
533 | - if (! $cancellation_line_item instanceof EE_Line_Item) { |
|
534 | - return false; |
|
535 | - } |
|
536 | - if ($cancellation_line_item->quantity() > $qty) { |
|
537 | - // decrement cancelled quantity |
|
538 | - $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
539 | - } elseif ($cancellation_line_item->quantity() === $qty) { |
|
540 | - // decrement cancelled quantity in case anyone still has the object kicking around |
|
541 | - $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
542 | - // delete because quantity will end up as 0 |
|
543 | - $cancellation_line_item->delete(); |
|
544 | - // and attempt to destroy the object, |
|
545 | - // even though PHP won't actually destroy it until it needs the memory |
|
546 | - unset($cancellation_line_item); |
|
547 | - } else { |
|
548 | - // what ?!?! negative quantity ?!?! |
|
549 | - throw new EE_Error( |
|
550 | - sprintf( |
|
551 | - esc_html__( |
|
552 | - 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
553 | - 'event_espresso' |
|
554 | - ), |
|
555 | - $qty, |
|
556 | - $cancellation_line_item->quantity() |
|
557 | - ) |
|
558 | - ); |
|
559 | - } |
|
560 | - // increment ticket quantity |
|
561 | - $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
562 | - if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
563 | - // increment parent line item quantity |
|
564 | - $event_line_item = $ticket_line_item->parent(); |
|
565 | - if ( |
|
566 | - $event_line_item instanceof EE_Line_Item |
|
567 | - && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
568 | - ) { |
|
569 | - $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
570 | - } |
|
571 | - EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
572 | - return true; |
|
573 | - } |
|
574 | - return false; |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * calls EEH_Line_Item::find_transaction_grand_total_for_line_item() |
|
580 | - * then EE_Line_Item::recalculate_total_including_taxes() on the result |
|
581 | - * |
|
582 | - * @param EE_Line_Item $line_item |
|
583 | - * @return float |
|
584 | - * @throws EE_Error |
|
585 | - * @throws InvalidArgumentException |
|
586 | - * @throws InvalidDataTypeException |
|
587 | - * @throws InvalidInterfaceException |
|
588 | - * @throws ReflectionException |
|
589 | - */ |
|
590 | - public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) |
|
591 | - { |
|
592 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
593 | - return $grand_total_line_item->recalculate_total_including_taxes(); |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Gets the line item which contains the subtotal of all the items |
|
599 | - * |
|
600 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
601 | - * @return EE_Line_Item |
|
602 | - * @throws EE_Error |
|
603 | - * @throws InvalidArgumentException |
|
604 | - * @throws InvalidDataTypeException |
|
605 | - * @throws InvalidInterfaceException |
|
606 | - * @throws ReflectionException |
|
607 | - */ |
|
608 | - public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) |
|
609 | - { |
|
610 | - $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
611 | - return $pre_tax_subtotal instanceof EE_Line_Item |
|
612 | - ? $pre_tax_subtotal |
|
613 | - : self::create_pre_tax_subtotal($total_line_item); |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - /** |
|
618 | - * Gets the line item for the taxes subtotal |
|
619 | - * |
|
620 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
621 | - * @return EE_Line_Item |
|
622 | - * @throws EE_Error |
|
623 | - * @throws InvalidArgumentException |
|
624 | - * @throws InvalidDataTypeException |
|
625 | - * @throws InvalidInterfaceException |
|
626 | - * @throws ReflectionException |
|
627 | - */ |
|
628 | - public static function get_taxes_subtotal(EE_Line_Item $total_line_item) |
|
629 | - { |
|
630 | - $taxes = $total_line_item->get_child_line_item('taxes'); |
|
631 | - return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * sets the TXN ID on an EE_Line_Item if passed a valid EE_Transaction object |
|
637 | - * |
|
638 | - * @param EE_Line_Item $line_item |
|
639 | - * @param EE_Transaction $transaction |
|
640 | - * @return void |
|
641 | - * @throws EE_Error |
|
642 | - * @throws InvalidArgumentException |
|
643 | - * @throws InvalidDataTypeException |
|
644 | - * @throws InvalidInterfaceException |
|
645 | - * @throws ReflectionException |
|
646 | - */ |
|
647 | - public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = null) |
|
648 | - { |
|
649 | - if ($transaction) { |
|
650 | - /** @type EEM_Transaction $EEM_Transaction */ |
|
651 | - $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
652 | - $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
653 | - $line_item->set_TXN_ID($TXN_ID); |
|
654 | - } |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * Creates a new default total line item for the transaction, |
|
660 | - * and its tickets subtotal and taxes subtotal line items (and adds the |
|
661 | - * existing taxes as children of the taxes subtotal line item) |
|
662 | - * |
|
663 | - * @param EE_Transaction $transaction |
|
664 | - * @return EE_Line_Item of type total |
|
665 | - * @throws EE_Error |
|
666 | - * @throws InvalidArgumentException |
|
667 | - * @throws InvalidDataTypeException |
|
668 | - * @throws InvalidInterfaceException |
|
669 | - * @throws ReflectionException |
|
670 | - */ |
|
671 | - public static function create_total_line_item($transaction = null) |
|
672 | - { |
|
673 | - $total_line_item = EE_Line_Item::new_instance(array( |
|
674 | - 'LIN_code' => 'total', |
|
675 | - 'LIN_name' => esc_html__('Grand Total', 'event_espresso'), |
|
676 | - 'LIN_type' => EEM_Line_Item::type_total, |
|
677 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TRANSACTION, |
|
678 | - )); |
|
679 | - $total_line_item = apply_filters( |
|
680 | - 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
|
681 | - $total_line_item |
|
682 | - ); |
|
683 | - self::set_TXN_ID($total_line_item, $transaction); |
|
684 | - self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
685 | - self::create_taxes_subtotal($total_line_item, $transaction); |
|
686 | - return $total_line_item; |
|
687 | - } |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * Creates a default items subtotal line item |
|
692 | - * |
|
693 | - * @param EE_Line_Item $total_line_item |
|
694 | - * @param EE_Transaction $transaction |
|
695 | - * @return EE_Line_Item |
|
696 | - * @throws EE_Error |
|
697 | - * @throws InvalidArgumentException |
|
698 | - * @throws InvalidDataTypeException |
|
699 | - * @throws InvalidInterfaceException |
|
700 | - * @throws ReflectionException |
|
701 | - */ |
|
702 | - protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
703 | - { |
|
704 | - $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
705 | - 'LIN_code' => 'pre-tax-subtotal', |
|
706 | - 'LIN_name' => esc_html__('Pre-Tax Subtotal', 'event_espresso'), |
|
707 | - 'LIN_type' => EEM_Line_Item::type_sub_total, |
|
708 | - )); |
|
709 | - $pre_tax_line_item = apply_filters( |
|
710 | - 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
|
711 | - $pre_tax_line_item |
|
712 | - ); |
|
713 | - self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
714 | - $total_line_item->add_child_line_item($pre_tax_line_item); |
|
715 | - self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
716 | - return $pre_tax_line_item; |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * Creates a line item for the taxes subtotal and finds all the tax prices |
|
722 | - * and applies taxes to it |
|
723 | - * |
|
724 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
725 | - * @param EE_Transaction $transaction |
|
726 | - * @return EE_Line_Item |
|
727 | - * @throws EE_Error |
|
728 | - * @throws InvalidArgumentException |
|
729 | - * @throws InvalidDataTypeException |
|
730 | - * @throws InvalidInterfaceException |
|
731 | - * @throws ReflectionException |
|
732 | - */ |
|
733 | - protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
734 | - { |
|
735 | - $tax_line_item = EE_Line_Item::new_instance(array( |
|
736 | - 'LIN_code' => 'taxes', |
|
737 | - 'LIN_name' => esc_html__('Taxes', 'event_espresso'), |
|
738 | - 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
|
739 | - 'LIN_order' => 1000,// this should always come last |
|
740 | - )); |
|
741 | - $tax_line_item = apply_filters( |
|
742 | - 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
|
743 | - $tax_line_item |
|
744 | - ); |
|
745 | - self::set_TXN_ID($tax_line_item, $transaction); |
|
746 | - $total_line_item->add_child_line_item($tax_line_item); |
|
747 | - // and lastly, add the actual taxes |
|
748 | - self::apply_taxes($total_line_item); |
|
749 | - return $tax_line_item; |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * Creates a default items subtotal line item |
|
755 | - * |
|
756 | - * @param EE_Line_Item $pre_tax_line_item |
|
757 | - * @param EE_Transaction $transaction |
|
758 | - * @param EE_Event $event |
|
759 | - * @return EE_Line_Item |
|
760 | - * @throws EE_Error |
|
761 | - * @throws InvalidArgumentException |
|
762 | - * @throws InvalidDataTypeException |
|
763 | - * @throws InvalidInterfaceException |
|
764 | - * @throws ReflectionException |
|
765 | - */ |
|
766 | - public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = null, $event = null) |
|
767 | - { |
|
768 | - $event_line_item = EE_Line_Item::new_instance(array( |
|
769 | - 'LIN_code' => self::get_event_code($event), |
|
770 | - 'LIN_name' => self::get_event_name($event), |
|
771 | - 'LIN_desc' => self::get_event_desc($event), |
|
772 | - 'LIN_type' => EEM_Line_Item::type_sub_total, |
|
773 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_EVENT, |
|
774 | - 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0, |
|
775 | - )); |
|
776 | - $event_line_item = apply_filters( |
|
777 | - 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
|
778 | - $event_line_item |
|
779 | - ); |
|
780 | - self::set_TXN_ID($event_line_item, $transaction); |
|
781 | - $pre_tax_line_item->add_child_line_item($event_line_item); |
|
782 | - return $event_line_item; |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * Gets what the event ticket's code SHOULD be |
|
788 | - * |
|
789 | - * @param EE_Event $event |
|
790 | - * @return string |
|
791 | - * @throws EE_Error |
|
792 | - */ |
|
793 | - public static function get_event_code($event) |
|
794 | - { |
|
795 | - return 'event-' . ($event instanceof EE_Event ? $event->ID() : '0'); |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * Gets the event name |
|
801 | - * |
|
802 | - * @param EE_Event $event |
|
803 | - * @return string |
|
804 | - * @throws EE_Error |
|
805 | - */ |
|
806 | - public static function get_event_name($event) |
|
807 | - { |
|
808 | - return $event instanceof EE_Event |
|
809 | - ? mb_substr($event->name(), 0, 245) |
|
810 | - : esc_html__('Event', 'event_espresso'); |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * Gets the event excerpt |
|
816 | - * |
|
817 | - * @param EE_Event $event |
|
818 | - * @return string |
|
819 | - * @throws EE_Error |
|
820 | - */ |
|
821 | - public static function get_event_desc($event) |
|
822 | - { |
|
823 | - return $event instanceof EE_Event ? $event->short_description() : ''; |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * Given the grand total line item and a ticket, finds the event sub-total |
|
829 | - * line item the ticket's purchase should be added onto |
|
830 | - * |
|
831 | - * @access public |
|
832 | - * @param EE_Line_Item $grand_total the grand total line item |
|
833 | - * @param EE_Ticket $ticket |
|
834 | - * @return EE_Line_Item |
|
835 | - * @throws EE_Error |
|
836 | - * @throws InvalidArgumentException |
|
837 | - * @throws InvalidDataTypeException |
|
838 | - * @throws InvalidInterfaceException |
|
839 | - * @throws ReflectionException |
|
840 | - */ |
|
841 | - public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) |
|
842 | - { |
|
843 | - $first_datetime = $ticket->first_datetime(); |
|
844 | - if (! $first_datetime instanceof EE_Datetime) { |
|
845 | - throw new EE_Error( |
|
846 | - sprintf( |
|
847 | - __('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), |
|
848 | - $ticket->ID() |
|
849 | - ) |
|
850 | - ); |
|
851 | - } |
|
852 | - $event = $first_datetime->event(); |
|
853 | - if (! $event instanceof EE_Event) { |
|
854 | - throw new EE_Error( |
|
855 | - sprintf( |
|
856 | - esc_html__( |
|
857 | - 'The supplied ticket (ID %d) has no event data associated with it.', |
|
858 | - 'event_espresso' |
|
859 | - ), |
|
860 | - $ticket->ID() |
|
861 | - ) |
|
862 | - ); |
|
863 | - } |
|
864 | - $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
865 | - if (! $events_sub_total instanceof EE_Line_Item) { |
|
866 | - throw new EE_Error( |
|
867 | - sprintf( |
|
868 | - esc_html__( |
|
869 | - 'There is no events sub-total for ticket %s on total line item %d', |
|
870 | - 'event_espresso' |
|
871 | - ), |
|
872 | - $ticket->ID(), |
|
873 | - $grand_total->ID() |
|
874 | - ) |
|
875 | - ); |
|
876 | - } |
|
877 | - return $events_sub_total; |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - /** |
|
882 | - * Gets the event line item |
|
883 | - * |
|
884 | - * @param EE_Line_Item $grand_total |
|
885 | - * @param EE_Event $event |
|
886 | - * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
|
887 | - * @throws EE_Error |
|
888 | - * @throws InvalidArgumentException |
|
889 | - * @throws InvalidDataTypeException |
|
890 | - * @throws InvalidInterfaceException |
|
891 | - * @throws ReflectionException |
|
892 | - */ |
|
893 | - public static function get_event_line_item(EE_Line_Item $grand_total, $event) |
|
894 | - { |
|
895 | - /** @type EE_Event $event */ |
|
896 | - $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
897 | - $event_line_item = null; |
|
898 | - $found = false; |
|
899 | - foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
900 | - // default event subtotal, we should only ever find this the first time this method is called |
|
901 | - if (! $event_line_item->OBJ_ID()) { |
|
902 | - // let's use this! but first... set the event details |
|
903 | - EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
904 | - $found = true; |
|
905 | - break; |
|
906 | - } |
|
907 | - if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
908 | - // found existing line item for this event in the cart, so break out of loop and use this one |
|
909 | - $found = true; |
|
910 | - break; |
|
911 | - } |
|
912 | - } |
|
913 | - if (! $found) { |
|
914 | - // there is no event sub-total yet, so add it |
|
915 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
916 | - // create a new "event" subtotal below that |
|
917 | - $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
918 | - // and set the event details |
|
919 | - EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
920 | - } |
|
921 | - return $event_line_item; |
|
922 | - } |
|
923 | - |
|
924 | - |
|
925 | - /** |
|
926 | - * Creates a default items subtotal line item |
|
927 | - * |
|
928 | - * @param EE_Line_Item $event_line_item |
|
929 | - * @param EE_Event $event |
|
930 | - * @param EE_Transaction $transaction |
|
931 | - * @return void |
|
932 | - * @throws EE_Error |
|
933 | - * @throws InvalidArgumentException |
|
934 | - * @throws InvalidDataTypeException |
|
935 | - * @throws InvalidInterfaceException |
|
936 | - * @throws ReflectionException |
|
937 | - */ |
|
938 | - public static function set_event_subtotal_details( |
|
939 | - EE_Line_Item $event_line_item, |
|
940 | - EE_Event $event, |
|
941 | - $transaction = null |
|
942 | - ) { |
|
943 | - if ($event instanceof EE_Event) { |
|
944 | - $event_line_item->set_code(self::get_event_code($event)); |
|
945 | - $event_line_item->set_name(self::get_event_name($event)); |
|
946 | - $event_line_item->set_desc(self::get_event_desc($event)); |
|
947 | - $event_line_item->set_OBJ_ID($event->ID()); |
|
948 | - } |
|
949 | - self::set_TXN_ID($event_line_item, $transaction); |
|
950 | - } |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * Finds what taxes should apply, adds them as tax line items under the taxes sub-total, |
|
955 | - * and recalculates the taxes sub-total and the grand total. Resets the taxes, so |
|
956 | - * any old taxes are removed |
|
957 | - * |
|
958 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
959 | - * @param bool $update_txn_status |
|
960 | - * @return bool |
|
961 | - * @throws EE_Error |
|
962 | - * @throws InvalidArgumentException |
|
963 | - * @throws InvalidDataTypeException |
|
964 | - * @throws InvalidInterfaceException |
|
965 | - * @throws ReflectionException |
|
966 | - * @throws RuntimeException |
|
967 | - */ |
|
968 | - public static function apply_taxes(EE_Line_Item $total_line_item, $update_txn_status = false) |
|
969 | - { |
|
970 | - /** @var EE_Admin_Config $admin_config */ |
|
971 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
972 | - if ($admin_config->useAdvancedEditor()) { |
|
973 | - return false; |
|
974 | - } |
|
975 | - /** @type EEM_Price $EEM_Price */ |
|
976 | - $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
977 | - // get array of taxes via Price Model |
|
978 | - $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
|
979 | - ksort($ordered_taxes); |
|
980 | - $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
981 | - // just to be safe, remove its old tax line items |
|
982 | - $deleted = $taxes_line_item->delete_children_line_items(); |
|
983 | - $updates = false; |
|
984 | - // loop thru taxes |
|
985 | - foreach ($ordered_taxes as $order => $taxes) { |
|
986 | - foreach ($taxes as $tax) { |
|
987 | - if ($tax instanceof EE_Price) { |
|
988 | - $tax_line_item = EE_Line_Item::new_instance( |
|
989 | - array( |
|
990 | - 'LIN_name' => $tax->name(), |
|
991 | - 'LIN_desc' => $tax->desc(), |
|
992 | - 'LIN_percent' => $tax->amount(), |
|
993 | - 'LIN_is_taxable' => false, |
|
994 | - 'LIN_order' => $order, |
|
995 | - 'LIN_total' => 0, |
|
996 | - 'LIN_type' => EEM_Line_Item::type_tax, |
|
997 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PRICE, |
|
998 | - 'OBJ_ID' => $tax->ID(), |
|
999 | - ) |
|
1000 | - ); |
|
1001 | - $tax_line_item = apply_filters( |
|
1002 | - 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
|
1003 | - $tax_line_item |
|
1004 | - ); |
|
1005 | - $updates = $taxes_line_item->add_child_line_item($tax_line_item) ? |
|
1006 | - true : |
|
1007 | - $updates; |
|
1008 | - } |
|
1009 | - } |
|
1010 | - } |
|
1011 | - // only recalculate totals if something changed |
|
1012 | - if ($deleted || $updates) { |
|
1013 | - $total_line_item->recalculate_total_including_taxes($update_txn_status); |
|
1014 | - return true; |
|
1015 | - } |
|
1016 | - return false; |
|
1017 | - } |
|
1018 | - |
|
1019 | - |
|
1020 | - /** |
|
1021 | - * Ensures that taxes have been applied to the order, if not applies them. |
|
1022 | - * Returns the total amount of tax |
|
1023 | - * |
|
1024 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
1025 | - * @return float |
|
1026 | - * @throws EE_Error |
|
1027 | - * @throws InvalidArgumentException |
|
1028 | - * @throws InvalidDataTypeException |
|
1029 | - * @throws InvalidInterfaceException |
|
1030 | - * @throws ReflectionException |
|
1031 | - */ |
|
1032 | - public static function ensure_taxes_applied($total_line_item) |
|
1033 | - { |
|
1034 | - $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
1035 | - if (! $taxes_subtotal->children()) { |
|
1036 | - self::apply_taxes($total_line_item); |
|
1037 | - } |
|
1038 | - return $taxes_subtotal->total(); |
|
1039 | - } |
|
1040 | - |
|
1041 | - |
|
1042 | - /** |
|
1043 | - * Deletes ALL children of the passed line item |
|
1044 | - * |
|
1045 | - * @param EE_Line_Item $parent_line_item |
|
1046 | - * @return bool |
|
1047 | - * @throws EE_Error |
|
1048 | - * @throws InvalidArgumentException |
|
1049 | - * @throws InvalidDataTypeException |
|
1050 | - * @throws InvalidInterfaceException |
|
1051 | - * @throws ReflectionException |
|
1052 | - */ |
|
1053 | - public static function delete_all_child_items(EE_Line_Item $parent_line_item) |
|
1054 | - { |
|
1055 | - $deleted = 0; |
|
1056 | - foreach ($parent_line_item->children() as $child_line_item) { |
|
1057 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1058 | - $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
1059 | - if ($child_line_item->ID()) { |
|
1060 | - $child_line_item->delete(); |
|
1061 | - unset($child_line_item); |
|
1062 | - } else { |
|
1063 | - $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
1064 | - } |
|
1065 | - $deleted++; |
|
1066 | - } |
|
1067 | - } |
|
1068 | - return $deleted; |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * Deletes the line items as indicated by the line item code(s) provided, |
|
1074 | - * regardless of where they're found in the line item tree. Automatically |
|
1075 | - * re-calculates the line item totals and updates the related transaction. But |
|
1076 | - * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
1077 | - * should probably change because of this). |
|
1078 | - * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
1079 | - * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
1080 | - * |
|
1081 | - * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
1082 | - * @param array|bool|string $line_item_codes |
|
1083 | - * @return int number of items successfully removed |
|
1084 | - * @throws EE_Error |
|
1085 | - */ |
|
1086 | - public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = false) |
|
1087 | - { |
|
1088 | - |
|
1089 | - if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
1090 | - EE_Error::doing_it_wrong( |
|
1091 | - 'EEH_Line_Item::delete_items', |
|
1092 | - esc_html__( |
|
1093 | - 'This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly', |
|
1094 | - 'event_espresso' |
|
1095 | - ), |
|
1096 | - '4.6.18' |
|
1097 | - ); |
|
1098 | - } |
|
1099 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1100 | - |
|
1101 | - // check if only a single line_item_id was passed |
|
1102 | - if (! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
1103 | - // place single line_item_id in an array to appear as multiple line_item_ids |
|
1104 | - $line_item_codes = array($line_item_codes); |
|
1105 | - } |
|
1106 | - $removals = 0; |
|
1107 | - // cycle thru line_item_ids |
|
1108 | - foreach ($line_item_codes as $line_item_id) { |
|
1109 | - $removals += $total_line_item->delete_child_line_item($line_item_id); |
|
1110 | - } |
|
1111 | - |
|
1112 | - if ($removals > 0) { |
|
1113 | - $total_line_item->recalculate_taxes_and_tax_total(); |
|
1114 | - return $removals; |
|
1115 | - } else { |
|
1116 | - return false; |
|
1117 | - } |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * Overwrites the previous tax by clearing out the old taxes, and creates a new |
|
1123 | - * tax and updates the total line item accordingly |
|
1124 | - * |
|
1125 | - * @param EE_Line_Item $total_line_item |
|
1126 | - * @param float $amount |
|
1127 | - * @param string $name |
|
1128 | - * @param string $description |
|
1129 | - * @param string $code |
|
1130 | - * @param boolean $add_to_existing_line_item |
|
1131 | - * if true, and a duplicate line item with the same code is found, |
|
1132 | - * $amount will be added onto it; otherwise will simply set the taxes to match $amount |
|
1133 | - * @return EE_Line_Item the new tax line item created |
|
1134 | - * @throws EE_Error |
|
1135 | - * @throws InvalidArgumentException |
|
1136 | - * @throws InvalidDataTypeException |
|
1137 | - * @throws InvalidInterfaceException |
|
1138 | - * @throws ReflectionException |
|
1139 | - */ |
|
1140 | - public static function set_total_tax_to( |
|
1141 | - EE_Line_Item $total_line_item, |
|
1142 | - $amount, |
|
1143 | - $name = null, |
|
1144 | - $description = null, |
|
1145 | - $code = null, |
|
1146 | - $add_to_existing_line_item = false |
|
1147 | - ) { |
|
1148 | - $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
1149 | - $taxable_total = $total_line_item->taxable_total(); |
|
1150 | - |
|
1151 | - if ($add_to_existing_line_item) { |
|
1152 | - $new_tax = $tax_subtotal->get_child_line_item($code); |
|
1153 | - EEM_Line_Item::instance()->delete( |
|
1154 | - array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
1155 | - ); |
|
1156 | - } else { |
|
1157 | - $new_tax = null; |
|
1158 | - $tax_subtotal->delete_children_line_items(); |
|
1159 | - } |
|
1160 | - if ($new_tax) { |
|
1161 | - $new_tax->set_total($new_tax->total() + $amount); |
|
1162 | - $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
1163 | - } else { |
|
1164 | - // no existing tax item. Create it |
|
1165 | - $new_tax = EE_Line_Item::new_instance(array( |
|
1166 | - 'TXN_ID' => $total_line_item->TXN_ID(), |
|
1167 | - 'LIN_name' => $name ? $name : esc_html__('Tax', 'event_espresso'), |
|
1168 | - 'LIN_desc' => $description ? $description : '', |
|
1169 | - 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
1170 | - 'LIN_total' => $amount, |
|
1171 | - 'LIN_parent' => $tax_subtotal->ID(), |
|
1172 | - 'LIN_type' => EEM_Line_Item::type_tax, |
|
1173 | - 'LIN_code' => $code, |
|
1174 | - )); |
|
1175 | - } |
|
1176 | - |
|
1177 | - $new_tax = apply_filters( |
|
1178 | - 'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal', |
|
1179 | - $new_tax, |
|
1180 | - $total_line_item |
|
1181 | - ); |
|
1182 | - $new_tax->save(); |
|
1183 | - $tax_subtotal->set_total($new_tax->total()); |
|
1184 | - $tax_subtotal->save(); |
|
1185 | - $total_line_item->recalculate_total_including_taxes(); |
|
1186 | - return $new_tax; |
|
1187 | - } |
|
1188 | - |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * Makes all the line items which are children of $line_item taxable (or not). |
|
1192 | - * Does NOT save the line items |
|
1193 | - * |
|
1194 | - * @param EE_Line_Item $line_item |
|
1195 | - * @param boolean $taxable |
|
1196 | - * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
1197 | - * it will be whitelisted (ie, except from becoming taxable) |
|
1198 | - * @throws EE_Error |
|
1199 | - */ |
|
1200 | - public static function set_line_items_taxable( |
|
1201 | - EE_Line_Item $line_item, |
|
1202 | - $taxable = true, |
|
1203 | - $code_substring_for_whitelist = null |
|
1204 | - ) { |
|
1205 | - $whitelisted = false; |
|
1206 | - if ($code_substring_for_whitelist !== null) { |
|
1207 | - $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false; |
|
1208 | - } |
|
1209 | - if (! $whitelisted && $line_item->is_line_item()) { |
|
1210 | - $line_item->set_is_taxable($taxable); |
|
1211 | - } |
|
1212 | - foreach ($line_item->children() as $child_line_item) { |
|
1213 | - EEH_Line_Item::set_line_items_taxable( |
|
1214 | - $child_line_item, |
|
1215 | - $taxable, |
|
1216 | - $code_substring_for_whitelist |
|
1217 | - ); |
|
1218 | - } |
|
1219 | - } |
|
1220 | - |
|
1221 | - |
|
1222 | - /** |
|
1223 | - * Gets all descendants that are event subtotals |
|
1224 | - * |
|
1225 | - * @uses EEH_Line_Item::get_subtotals_of_object_type() |
|
1226 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1227 | - * @return EE_Line_Item[] |
|
1228 | - * @throws EE_Error |
|
1229 | - */ |
|
1230 | - public static function get_event_subtotals(EE_Line_Item $parent_line_item) |
|
1231 | - { |
|
1232 | - return self::get_subtotals_of_object_type($parent_line_item, EEM_Line_Item::OBJ_TYPE_EVENT); |
|
1233 | - } |
|
1234 | - |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * Gets all descendants subtotals that match the supplied object type |
|
1238 | - * |
|
1239 | - * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
1240 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1241 | - * @param string $obj_type |
|
1242 | - * @return EE_Line_Item[] |
|
1243 | - * @throws EE_Error |
|
1244 | - */ |
|
1245 | - public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') |
|
1246 | - { |
|
1247 | - return self::_get_descendants_by_type_and_object_type( |
|
1248 | - $parent_line_item, |
|
1249 | - EEM_Line_Item::type_sub_total, |
|
1250 | - $obj_type |
|
1251 | - ); |
|
1252 | - } |
|
1253 | - |
|
1254 | - |
|
1255 | - /** |
|
1256 | - * Gets all descendants that are tickets |
|
1257 | - * |
|
1258 | - * @uses EEH_Line_Item::get_line_items_of_object_type() |
|
1259 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1260 | - * @return EE_Line_Item[] |
|
1261 | - * @throws EE_Error |
|
1262 | - */ |
|
1263 | - public static function get_ticket_line_items(EE_Line_Item $parent_line_item) |
|
1264 | - { |
|
1265 | - return self::get_line_items_of_object_type( |
|
1266 | - $parent_line_item, |
|
1267 | - EEM_Line_Item::OBJ_TYPE_TICKET |
|
1268 | - ); |
|
1269 | - } |
|
1270 | - |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * Gets all descendants subtotals that match the supplied object type |
|
1274 | - * |
|
1275 | - * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
1276 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1277 | - * @param string $obj_type |
|
1278 | - * @return EE_Line_Item[] |
|
1279 | - * @throws EE_Error |
|
1280 | - */ |
|
1281 | - public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') |
|
1282 | - { |
|
1283 | - return self::_get_descendants_by_type_and_object_type( |
|
1284 | - $parent_line_item, |
|
1285 | - EEM_Line_Item::type_line_item, |
|
1286 | - $obj_type |
|
1287 | - ); |
|
1288 | - } |
|
1289 | - |
|
1290 | - |
|
1291 | - /** |
|
1292 | - * Gets all the descendants (ie, children or children of children etc) that are of the type 'tax' |
|
1293 | - * |
|
1294 | - * @uses EEH_Line_Item::get_descendants_of_type() |
|
1295 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1296 | - * @return EE_Line_Item[] |
|
1297 | - * @throws EE_Error |
|
1298 | - */ |
|
1299 | - public static function get_tax_descendants(EE_Line_Item $parent_line_item) |
|
1300 | - { |
|
1301 | - return EEH_Line_Item::get_descendants_of_type( |
|
1302 | - $parent_line_item, |
|
1303 | - EEM_Line_Item::type_tax |
|
1304 | - ); |
|
1305 | - } |
|
1306 | - |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * Gets all the real items purchased which are children of this item |
|
1310 | - * |
|
1311 | - * @uses EEH_Line_Item::get_descendants_of_type() |
|
1312 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1313 | - * @return EE_Line_Item[] |
|
1314 | - * @throws EE_Error |
|
1315 | - */ |
|
1316 | - public static function get_line_item_descendants(EE_Line_Item $parent_line_item) |
|
1317 | - { |
|
1318 | - return EEH_Line_Item::get_descendants_of_type( |
|
1319 | - $parent_line_item, |
|
1320 | - EEM_Line_Item::type_line_item |
|
1321 | - ); |
|
1322 | - } |
|
1323 | - |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * Gets all descendants of supplied line item that match the supplied line item type |
|
1327 | - * |
|
1328 | - * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
1329 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1330 | - * @param string $line_item_type one of the EEM_Line_Item constants |
|
1331 | - * @return EE_Line_Item[] |
|
1332 | - * @throws EE_Error |
|
1333 | - */ |
|
1334 | - public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) |
|
1335 | - { |
|
1336 | - return self::_get_descendants_by_type_and_object_type( |
|
1337 | - $parent_line_item, |
|
1338 | - $line_item_type, |
|
1339 | - null |
|
1340 | - ); |
|
1341 | - } |
|
1342 | - |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type |
|
1346 | - * as well |
|
1347 | - * |
|
1348 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1349 | - * @param string $line_item_type one of the EEM_Line_Item constants |
|
1350 | - * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when |
|
1351 | - * searching |
|
1352 | - * @return EE_Line_Item[] |
|
1353 | - * @throws EE_Error |
|
1354 | - */ |
|
1355 | - protected static function _get_descendants_by_type_and_object_type( |
|
1356 | - EE_Line_Item $parent_line_item, |
|
1357 | - $line_item_type, |
|
1358 | - $obj_type = null |
|
1359 | - ) { |
|
1360 | - $objects = array(); |
|
1361 | - foreach ($parent_line_item->children() as $child_line_item) { |
|
1362 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1363 | - if ( |
|
1364 | - $child_line_item->type() === $line_item_type |
|
1365 | - && ( |
|
1366 | - $child_line_item->OBJ_type() === $obj_type || $obj_type === null |
|
1367 | - ) |
|
1368 | - ) { |
|
1369 | - $objects[] = $child_line_item; |
|
1370 | - } else { |
|
1371 | - // go-through-all-its children looking for more matches |
|
1372 | - $objects = array_merge( |
|
1373 | - $objects, |
|
1374 | - self::_get_descendants_by_type_and_object_type( |
|
1375 | - $child_line_item, |
|
1376 | - $line_item_type, |
|
1377 | - $obj_type |
|
1378 | - ) |
|
1379 | - ); |
|
1380 | - } |
|
1381 | - } |
|
1382 | - } |
|
1383 | - return $objects; |
|
1384 | - } |
|
1385 | - |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * Gets all descendants subtotals that match the supplied object type |
|
1389 | - * |
|
1390 | - * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
1391 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1392 | - * @param string $OBJ_type object type (like Event) |
|
1393 | - * @param array $OBJ_IDs array of OBJ_IDs |
|
1394 | - * @return EE_Line_Item[] |
|
1395 | - * @throws EE_Error |
|
1396 | - */ |
|
1397 | - public static function get_line_items_by_object_type_and_IDs( |
|
1398 | - EE_Line_Item $parent_line_item, |
|
1399 | - $OBJ_type = '', |
|
1400 | - $OBJ_IDs = array() |
|
1401 | - ) { |
|
1402 | - return self::_get_descendants_by_object_type_and_object_ID( |
|
1403 | - $parent_line_item, |
|
1404 | - $OBJ_type, |
|
1405 | - $OBJ_IDs |
|
1406 | - ); |
|
1407 | - } |
|
1408 | - |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type |
|
1412 | - * as well |
|
1413 | - * |
|
1414 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1415 | - * @param string $OBJ_type object type (like Event) |
|
1416 | - * @param array $OBJ_IDs array of OBJ_IDs |
|
1417 | - * @return EE_Line_Item[] |
|
1418 | - * @throws EE_Error |
|
1419 | - */ |
|
1420 | - protected static function _get_descendants_by_object_type_and_object_ID( |
|
1421 | - EE_Line_Item $parent_line_item, |
|
1422 | - $OBJ_type, |
|
1423 | - $OBJ_IDs |
|
1424 | - ) { |
|
1425 | - $objects = array(); |
|
1426 | - foreach ($parent_line_item->children() as $child_line_item) { |
|
1427 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1428 | - if ( |
|
1429 | - $child_line_item->OBJ_type() === $OBJ_type |
|
1430 | - && is_array($OBJ_IDs) |
|
1431 | - && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1432 | - ) { |
|
1433 | - $objects[] = $child_line_item; |
|
1434 | - } else { |
|
1435 | - // go-through-all-its children looking for more matches |
|
1436 | - $objects = array_merge( |
|
1437 | - $objects, |
|
1438 | - self::_get_descendants_by_object_type_and_object_ID( |
|
1439 | - $child_line_item, |
|
1440 | - $OBJ_type, |
|
1441 | - $OBJ_IDs |
|
1442 | - ) |
|
1443 | - ); |
|
1444 | - } |
|
1445 | - } |
|
1446 | - } |
|
1447 | - return $objects; |
|
1448 | - } |
|
1449 | - |
|
1450 | - |
|
1451 | - /** |
|
1452 | - * Uses a breadth-first-search in order to find the nearest descendant of |
|
1453 | - * the specified type and returns it, else NULL |
|
1454 | - * |
|
1455 | - * @uses EEH_Line_Item::_get_nearest_descendant() |
|
1456 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1457 | - * @param string $type like one of the EEM_Line_Item::type_* |
|
1458 | - * @return EE_Line_Item |
|
1459 | - * @throws EE_Error |
|
1460 | - * @throws InvalidArgumentException |
|
1461 | - * @throws InvalidDataTypeException |
|
1462 | - * @throws InvalidInterfaceException |
|
1463 | - * @throws ReflectionException |
|
1464 | - */ |
|
1465 | - public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) |
|
1466 | - { |
|
1467 | - return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1468 | - } |
|
1469 | - |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Uses a breadth-first-search in order to find the nearest descendant |
|
1473 | - * having the specified LIN_code and returns it, else NULL |
|
1474 | - * |
|
1475 | - * @uses EEH_Line_Item::_get_nearest_descendant() |
|
1476 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1477 | - * @param string $code any value used for LIN_code |
|
1478 | - * @return EE_Line_Item |
|
1479 | - * @throws EE_Error |
|
1480 | - * @throws InvalidArgumentException |
|
1481 | - * @throws InvalidDataTypeException |
|
1482 | - * @throws InvalidInterfaceException |
|
1483 | - * @throws ReflectionException |
|
1484 | - */ |
|
1485 | - public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) |
|
1486 | - { |
|
1487 | - return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1488 | - } |
|
1489 | - |
|
1490 | - |
|
1491 | - /** |
|
1492 | - * Uses a breadth-first-search in order to find the nearest descendant |
|
1493 | - * having the specified LIN_code and returns it, else NULL |
|
1494 | - * |
|
1495 | - * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1496 | - * @param string $search_field name of EE_Line_Item property |
|
1497 | - * @param string $value any value stored in $search_field |
|
1498 | - * @return EE_Line_Item |
|
1499 | - * @throws EE_Error |
|
1500 | - * @throws InvalidArgumentException |
|
1501 | - * @throws InvalidDataTypeException |
|
1502 | - * @throws InvalidInterfaceException |
|
1503 | - * @throws ReflectionException |
|
1504 | - */ |
|
1505 | - protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) |
|
1506 | - { |
|
1507 | - foreach ($parent_line_item->children() as $child) { |
|
1508 | - if ($child->get($search_field) == $value) { |
|
1509 | - return $child; |
|
1510 | - } |
|
1511 | - } |
|
1512 | - foreach ($parent_line_item->children() as $child) { |
|
1513 | - $descendant_found = self::_get_nearest_descendant( |
|
1514 | - $child, |
|
1515 | - $search_field, |
|
1516 | - $value |
|
1517 | - ); |
|
1518 | - if ($descendant_found) { |
|
1519 | - return $descendant_found; |
|
1520 | - } |
|
1521 | - } |
|
1522 | - return null; |
|
1523 | - } |
|
1524 | - |
|
1525 | - |
|
1526 | - /** |
|
1527 | - * if passed line item has a TXN ID, uses that to jump directly to the grand total line item for the transaction, |
|
1528 | - * else recursively walks up the line item tree until a parent of type total is found, |
|
1529 | - * |
|
1530 | - * @param EE_Line_Item $line_item |
|
1531 | - * @return EE_Line_Item |
|
1532 | - * @throws EE_Error |
|
1533 | - */ |
|
1534 | - public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) |
|
1535 | - { |
|
1536 | - if ($line_item->TXN_ID()) { |
|
1537 | - $total_line_item = $line_item->transaction()->total_line_item(false); |
|
1538 | - if ($total_line_item instanceof EE_Line_Item) { |
|
1539 | - return $total_line_item; |
|
1540 | - } |
|
1541 | - } else { |
|
1542 | - $line_item_parent = $line_item->parent(); |
|
1543 | - if ($line_item_parent instanceof EE_Line_Item) { |
|
1544 | - if ($line_item_parent->is_total()) { |
|
1545 | - return $line_item_parent; |
|
1546 | - } |
|
1547 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
1548 | - } |
|
1549 | - } |
|
1550 | - throw new EE_Error( |
|
1551 | - sprintf( |
|
1552 | - esc_html__( |
|
1553 | - 'A valid grand total for line item %1$d was not found.', |
|
1554 | - 'event_espresso' |
|
1555 | - ), |
|
1556 | - $line_item->ID() |
|
1557 | - ) |
|
1558 | - ); |
|
1559 | - } |
|
1560 | - |
|
1561 | - |
|
1562 | - /** |
|
1563 | - * Prints out a representation of the line item tree |
|
1564 | - * |
|
1565 | - * @param EE_Line_Item $line_item |
|
1566 | - * @param int $indentation |
|
1567 | - * @return void |
|
1568 | - * @throws EE_Error |
|
1569 | - */ |
|
1570 | - public static function visualize(EE_Line_Item $line_item, $indentation = 0) |
|
1571 | - { |
|
1572 | - echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1573 | - if (! $indentation) { |
|
1574 | - echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1575 | - } |
|
1576 | - for ($i = 0; $i < $indentation; $i++) { |
|
1577 | - echo '. '; |
|
1578 | - } |
|
1579 | - $breakdown = ''; |
|
1580 | - if ($line_item->is_line_item()) { |
|
1581 | - if ($line_item->is_percent()) { |
|
1582 | - $breakdown = "{$line_item->percent()}%"; |
|
1583 | - } else { |
|
1584 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1585 | - } |
|
1586 | - } |
|
1587 | - echo $line_item->name(); |
|
1588 | - echo " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : "; |
|
1589 | - echo '$' . (string) $line_item->total(); |
|
1590 | - if ($breakdown) { |
|
1591 | - echo " ( {$breakdown} )"; |
|
1592 | - } |
|
1593 | - if ($line_item->is_taxable()) { |
|
1594 | - echo ' * taxable'; |
|
1595 | - } |
|
1596 | - if ($line_item->children()) { |
|
1597 | - foreach ($line_item->children() as $child) { |
|
1598 | - self::visualize($child, $indentation + 1); |
|
1599 | - } |
|
1600 | - } |
|
1601 | - } |
|
1602 | - |
|
1603 | - |
|
1604 | - /** |
|
1605 | - * Calculates the registration's final price, taking into account that they |
|
1606 | - * need to not only help pay for their OWN ticket, but also any transaction-wide surcharges and taxes, |
|
1607 | - * and receive a portion of any transaction-wide discounts. |
|
1608 | - * eg1, if I buy a $1 ticket and brent buys a $9 ticket, and we receive a $5 discount |
|
1609 | - * then I'll get 1/10 of that $5 discount, which is $0.50, and brent will get |
|
1610 | - * 9/10ths of that $5 discount, which is $4.50. So my final price should be $0.50 |
|
1611 | - * and brent's final price should be $5.50. |
|
1612 | - * In order to do this, we basically need to traverse the line item tree calculating |
|
1613 | - * the running totals (just as if we were recalculating the total), but when we identify |
|
1614 | - * regular line items, we need to keep track of their share of the grand total. |
|
1615 | - * Also, we need to keep track of the TAXABLE total for each ticket purchase, so |
|
1616 | - * we can know how to apply taxes to it. (Note: "taxable total" does not equal the "pretax total" |
|
1617 | - * when there are non-taxable items; otherwise they would be the same) |
|
1618 | - * |
|
1619 | - * @param EE_Line_Item $line_item |
|
1620 | - * @param array $billable_ticket_quantities array of EE_Ticket IDs and their corresponding quantity that |
|
1621 | - * can be included in price calculations at this moment |
|
1622 | - * @return array keys are line items for tickets IDs and values are their share of the running total, |
|
1623 | - * plus the key 'total', and 'taxable' which also has keys of all |
|
1624 | - * the ticket IDs. |
|
1625 | - * Eg array( |
|
1626 | - * 12 => 4.3 |
|
1627 | - * 23 => 8.0 |
|
1628 | - * 'total' => 16.6, |
|
1629 | - * 'taxable' => array( |
|
1630 | - * 12 => 10, |
|
1631 | - * 23 => 4 |
|
1632 | - * ). |
|
1633 | - * So to find which registrations have which final price, we need |
|
1634 | - * to find which line item is theirs, which can be done with |
|
1635 | - * `EEM_Line_Item::instance()->get_line_item_for_registration( |
|
1636 | - * $registration );` |
|
1637 | - * @throws EE_Error |
|
1638 | - * @throws InvalidArgumentException |
|
1639 | - * @throws InvalidDataTypeException |
|
1640 | - * @throws InvalidInterfaceException |
|
1641 | - * @throws ReflectionException |
|
1642 | - */ |
|
1643 | - public static function calculate_reg_final_prices_per_line_item( |
|
1644 | - EE_Line_Item $line_item, |
|
1645 | - $billable_ticket_quantities = array() |
|
1646 | - ) { |
|
1647 | - $running_totals = [ |
|
1648 | - 'total' => 0, |
|
1649 | - 'taxable' => ['total' => 0] |
|
1650 | - ]; |
|
1651 | - foreach ($line_item->children() as $child_line_item) { |
|
1652 | - switch ($child_line_item->type()) { |
|
1653 | - case EEM_Line_Item::type_sub_total: |
|
1654 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
1655 | - $child_line_item, |
|
1656 | - $billable_ticket_quantities |
|
1657 | - ); |
|
1658 | - // combine arrays but preserve numeric keys |
|
1659 | - $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1660 | - $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1661 | - $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1662 | - break; |
|
1663 | - |
|
1664 | - case EEM_Line_Item::type_tax_sub_total: |
|
1665 | - // find how much the taxes percentage is |
|
1666 | - if ($child_line_item->percent() !== 0) { |
|
1667 | - $tax_percent_decimal = $child_line_item->percent() / 100; |
|
1668 | - } else { |
|
1669 | - $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
|
1670 | - } |
|
1671 | - // and apply to all the taxable totals, and add to the pretax totals |
|
1672 | - foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1673 | - // "total" and "taxable" array key is an exception |
|
1674 | - if ($line_item_id === 'taxable') { |
|
1675 | - continue; |
|
1676 | - } |
|
1677 | - $taxable_total = $running_totals['taxable'][ $line_item_id ]; |
|
1678 | - $running_totals[ $line_item_id ] += ($taxable_total * $tax_percent_decimal); |
|
1679 | - } |
|
1680 | - break; |
|
1681 | - |
|
1682 | - case EEM_Line_Item::type_line_item: |
|
1683 | - // ticket line items or ???? |
|
1684 | - if ($child_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
1685 | - // kk it's a ticket |
|
1686 | - if (isset($running_totals[ $child_line_item->ID() ])) { |
|
1687 | - // huh? that shouldn't happen. |
|
1688 | - $running_totals['total'] += $child_line_item->total(); |
|
1689 | - } else { |
|
1690 | - // its not in our running totals yet. great. |
|
1691 | - if ($child_line_item->is_taxable()) { |
|
1692 | - $taxable_amount = $child_line_item->unit_price(); |
|
1693 | - } else { |
|
1694 | - $taxable_amount = 0; |
|
1695 | - } |
|
1696 | - // are we only calculating totals for some tickets? |
|
1697 | - if (isset($billable_ticket_quantities[ $child_line_item->OBJ_ID() ])) { |
|
1698 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1699 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
1700 | - ? $child_line_item->unit_price() |
|
1701 | - : 0; |
|
1702 | - $running_totals['taxable'][ $child_line_item->ID() ] = $quantity |
|
1703 | - ? $taxable_amount |
|
1704 | - : 0; |
|
1705 | - } else { |
|
1706 | - $quantity = $child_line_item->quantity(); |
|
1707 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1708 | - $running_totals['taxable'][ $child_line_item->ID() ] = $taxable_amount; |
|
1709 | - } |
|
1710 | - $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1711 | - $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1712 | - } |
|
1713 | - } else { |
|
1714 | - // it's some other type of item added to the cart |
|
1715 | - // it should affect the running totals |
|
1716 | - // basically we want to convert it into a PERCENT modifier. Because |
|
1717 | - // more clearly affect all registration's final price equally |
|
1718 | - $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1719 | - ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1720 | - : 1; |
|
1721 | - foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1722 | - // the "taxable" array key is an exception |
|
1723 | - if ($line_item_id === 'taxable') { |
|
1724 | - continue; |
|
1725 | - } |
|
1726 | - // update the running totals |
|
1727 | - // yes this actually even works for the running grand total! |
|
1728 | - $running_totals[ $line_item_id ] = |
|
1729 | - $line_items_percent_of_running_total * $this_running_total; |
|
1730 | - |
|
1731 | - if ($child_line_item->is_taxable()) { |
|
1732 | - $running_totals['taxable'][ $line_item_id ] = |
|
1733 | - $line_items_percent_of_running_total * $running_totals['taxable'][ $line_item_id ]; |
|
1734 | - } |
|
1735 | - } |
|
1736 | - } |
|
1737 | - break; |
|
1738 | - } |
|
1739 | - } |
|
1740 | - return $running_totals; |
|
1741 | - } |
|
1742 | - |
|
1743 | - |
|
1744 | - /** |
|
1745 | - * @param EE_Line_Item $total_line_item |
|
1746 | - * @param EE_Line_Item $ticket_line_item |
|
1747 | - * @return float | null |
|
1748 | - * @throws EE_Error |
|
1749 | - * @throws InvalidArgumentException |
|
1750 | - * @throws InvalidDataTypeException |
|
1751 | - * @throws InvalidInterfaceException |
|
1752 | - * @throws OutOfRangeException |
|
1753 | - * @throws ReflectionException |
|
1754 | - */ |
|
1755 | - public static function calculate_final_price_for_ticket_line_item( |
|
1756 | - EE_Line_Item $total_line_item, |
|
1757 | - EE_Line_Item $ticket_line_item |
|
1758 | - ) { |
|
1759 | - static $final_prices_per_ticket_line_item = array(); |
|
1760 | - if (empty($final_prices_per_ticket_line_item) || empty($final_prices_per_ticket_line_item[ $total_line_item->ID() ])) { |
|
1761 | - $final_prices_per_ticket_line_item[ $total_line_item->ID() ] = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
1762 | - $total_line_item |
|
1763 | - ); |
|
1764 | - } |
|
1765 | - // ok now find this new registration's final price |
|
1766 | - if (isset($final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ])) { |
|
1767 | - return $final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ]; |
|
1768 | - } |
|
1769 | - $message = sprintf( |
|
1770 | - esc_html__( |
|
1771 | - 'The final price for the ticket line item (ID:%1$d) could not be calculated.', |
|
1772 | - 'event_espresso' |
|
1773 | - ), |
|
1774 | - $ticket_line_item->ID() |
|
1775 | - ); |
|
1776 | - if (WP_DEBUG) { |
|
1777 | - $message .= '<br>' . print_r($final_prices_per_ticket_line_item, true); |
|
1778 | - throw new OutOfRangeException($message); |
|
1779 | - } |
|
1780 | - EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1781 | - return null; |
|
1782 | - } |
|
1783 | - |
|
1784 | - |
|
1785 | - /** |
|
1786 | - * Creates a duplicate of the line item tree, except only includes billable items |
|
1787 | - * and the portion of line items attributed to billable things |
|
1788 | - * |
|
1789 | - * @param EE_Line_Item $line_item |
|
1790 | - * @param EE_Registration[] $registrations |
|
1791 | - * @return EE_Line_Item |
|
1792 | - * @throws EE_Error |
|
1793 | - * @throws InvalidArgumentException |
|
1794 | - * @throws InvalidDataTypeException |
|
1795 | - * @throws InvalidInterfaceException |
|
1796 | - * @throws ReflectionException |
|
1797 | - */ |
|
1798 | - public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) |
|
1799 | - { |
|
1800 | - $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1801 | - foreach ($line_item->children() as $child_li) { |
|
1802 | - $copy_li->add_child_line_item( |
|
1803 | - EEH_Line_Item::billable_line_item_tree($child_li, $registrations) |
|
1804 | - ); |
|
1805 | - } |
|
1806 | - // if this is the grand total line item, make sure the totals all add up |
|
1807 | - // (we could have duplicated this logic AS we copied the line items, but |
|
1808 | - // it seems DRYer this way) |
|
1809 | - if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1810 | - $copy_li->recalculate_total_including_taxes(); |
|
1811 | - } |
|
1812 | - return $copy_li; |
|
1813 | - } |
|
1814 | - |
|
1815 | - |
|
1816 | - /** |
|
1817 | - * Creates a new, unsaved line item from $line_item that factors in the |
|
1818 | - * number of billable registrations on $registrations. |
|
1819 | - * |
|
1820 | - * @param EE_Line_Item $line_item |
|
1821 | - * @param EE_Registration[] $registrations |
|
1822 | - * @return EE_Line_Item |
|
1823 | - * @throws EE_Error |
|
1824 | - * @throws InvalidArgumentException |
|
1825 | - * @throws InvalidDataTypeException |
|
1826 | - * @throws InvalidInterfaceException |
|
1827 | - * @throws ReflectionException |
|
1828 | - */ |
|
1829 | - public static function billable_line_item(EE_Line_Item $line_item, $registrations) |
|
1830 | - { |
|
1831 | - $new_li_fields = $line_item->model_field_array(); |
|
1832 | - if ( |
|
1833 | - $line_item->type() === EEM_Line_Item::type_line_item && |
|
1834 | - $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
1835 | - ) { |
|
1836 | - $count = 0; |
|
1837 | - foreach ($registrations as $registration) { |
|
1838 | - if ( |
|
1839 | - $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1840 | - in_array( |
|
1841 | - $registration->status_ID(), |
|
1842 | - EEM_Registration::reg_statuses_that_allow_payment(), |
|
1843 | - true |
|
1844 | - ) |
|
1845 | - ) { |
|
1846 | - $count++; |
|
1847 | - } |
|
1848 | - } |
|
1849 | - $new_li_fields['LIN_quantity'] = $count; |
|
1850 | - } |
|
1851 | - // don't set the total. We'll leave that up to the code that calculates it |
|
1852 | - unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1853 | - return EE_Line_Item::new_instance($new_li_fields); |
|
1854 | - } |
|
1855 | - |
|
1856 | - |
|
1857 | - /** |
|
1858 | - * Returns a modified line item tree where all the subtotals which have a total of 0 |
|
1859 | - * are removed, and line items with a quantity of 0 |
|
1860 | - * |
|
1861 | - * @param EE_Line_Item $line_item |null |
|
1862 | - * @return EE_Line_Item|null |
|
1863 | - * @throws EE_Error |
|
1864 | - * @throws InvalidArgumentException |
|
1865 | - * @throws InvalidDataTypeException |
|
1866 | - * @throws InvalidInterfaceException |
|
1867 | - * @throws ReflectionException |
|
1868 | - */ |
|
1869 | - public static function non_empty_line_items(EE_Line_Item $line_item) |
|
1870 | - { |
|
1871 | - $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1872 | - if ($copied_li === null) { |
|
1873 | - return null; |
|
1874 | - } |
|
1875 | - // if this is an event subtotal, we want to only include it if it |
|
1876 | - // has a non-zero total and at least one ticket line item child |
|
1877 | - $ticket_children = 0; |
|
1878 | - foreach ($line_item->children() as $child_li) { |
|
1879 | - $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1880 | - if ($child_li_copy !== null) { |
|
1881 | - $copied_li->add_child_line_item($child_li_copy); |
|
1882 | - if ( |
|
1883 | - $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1884 | - $child_li_copy->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
1885 | - ) { |
|
1886 | - $ticket_children++; |
|
1887 | - } |
|
1888 | - } |
|
1889 | - } |
|
1890 | - // if this is an event subtotal with NO ticket children |
|
1891 | - // we basically want to ignore it |
|
1892 | - if ( |
|
1893 | - $ticket_children === 0 |
|
1894 | - && $line_item->type() === EEM_Line_Item::type_sub_total |
|
1895 | - && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
1896 | - && $line_item->total() === 0 |
|
1897 | - ) { |
|
1898 | - return null; |
|
1899 | - } |
|
1900 | - return $copied_li; |
|
1901 | - } |
|
1902 | - |
|
1903 | - |
|
1904 | - /** |
|
1905 | - * Creates a new, unsaved line item, but if it's a ticket line item |
|
1906 | - * with a total of 0, or a subtotal of 0, returns null instead |
|
1907 | - * |
|
1908 | - * @param EE_Line_Item $line_item |
|
1909 | - * @return EE_Line_Item |
|
1910 | - * @throws EE_Error |
|
1911 | - * @throws InvalidArgumentException |
|
1912 | - * @throws InvalidDataTypeException |
|
1913 | - * @throws InvalidInterfaceException |
|
1914 | - * @throws ReflectionException |
|
1915 | - */ |
|
1916 | - public static function non_empty_line_item(EE_Line_Item $line_item) |
|
1917 | - { |
|
1918 | - if ( |
|
1919 | - $line_item->type() === EEM_Line_Item::type_line_item |
|
1920 | - && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
1921 | - && $line_item->quantity() === 0 |
|
1922 | - ) { |
|
1923 | - return null; |
|
1924 | - } |
|
1925 | - $new_li_fields = $line_item->model_field_array(); |
|
1926 | - // don't set the total. We'll leave that up to the code that calculates it |
|
1927 | - unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1928 | - return EE_Line_Item::new_instance($new_li_fields); |
|
1929 | - } |
|
1930 | - |
|
1931 | - |
|
1932 | - /** |
|
1933 | - * Cycles through all of the ticket line items for the supplied total line item |
|
1934 | - * and ensures that the line item's "is_taxable" field matches that of its corresponding ticket |
|
1935 | - * |
|
1936 | - * @param EE_Line_Item $total_line_item |
|
1937 | - * @since 4.9.79.p |
|
1938 | - * @throws EE_Error |
|
1939 | - * @throws InvalidArgumentException |
|
1940 | - * @throws InvalidDataTypeException |
|
1941 | - * @throws InvalidInterfaceException |
|
1942 | - * @throws ReflectionException |
|
1943 | - */ |
|
1944 | - public static function resetIsTaxableForTickets(EE_Line_Item $total_line_item) |
|
1945 | - { |
|
1946 | - $ticket_line_items = self::get_ticket_line_items($total_line_item); |
|
1947 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
1948 | - if ( |
|
1949 | - $ticket_line_item instanceof EE_Line_Item |
|
1950 | - && $ticket_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
1951 | - ) { |
|
1952 | - $ticket = $ticket_line_item->ticket(); |
|
1953 | - if ($ticket instanceof EE_Ticket && $ticket->taxable() !== $ticket_line_item->is_taxable()) { |
|
1954 | - $ticket_line_item->set_is_taxable($ticket->taxable()); |
|
1955 | - $ticket_line_item->save(); |
|
1956 | - } |
|
1957 | - } |
|
1958 | - } |
|
1959 | - } |
|
1960 | - |
|
1961 | - |
|
1962 | - |
|
1963 | - /**************************************** @DEPRECATED METHODS *************************************** */ |
|
1964 | - /** |
|
1965 | - * @deprecated |
|
1966 | - * @param EE_Line_Item $total_line_item |
|
1967 | - * @return EE_Line_Item |
|
1968 | - * @throws EE_Error |
|
1969 | - * @throws InvalidArgumentException |
|
1970 | - * @throws InvalidDataTypeException |
|
1971 | - * @throws InvalidInterfaceException |
|
1972 | - * @throws ReflectionException |
|
1973 | - */ |
|
1974 | - public static function get_items_subtotal(EE_Line_Item $total_line_item) |
|
1975 | - { |
|
1976 | - EE_Error::doing_it_wrong( |
|
1977 | - 'EEH_Line_Item::get_items_subtotal()', |
|
1978 | - sprintf( |
|
1979 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1980 | - 'EEH_Line_Item::get_pre_tax_subtotal()' |
|
1981 | - ), |
|
1982 | - '4.6.0' |
|
1983 | - ); |
|
1984 | - return self::get_pre_tax_subtotal($total_line_item); |
|
1985 | - } |
|
1986 | - |
|
1987 | - |
|
1988 | - /** |
|
1989 | - * @deprecated |
|
1990 | - * @param EE_Transaction $transaction |
|
1991 | - * @return EE_Line_Item |
|
1992 | - * @throws EE_Error |
|
1993 | - * @throws InvalidArgumentException |
|
1994 | - * @throws InvalidDataTypeException |
|
1995 | - * @throws InvalidInterfaceException |
|
1996 | - * @throws ReflectionException |
|
1997 | - */ |
|
1998 | - public static function create_default_total_line_item($transaction = null) |
|
1999 | - { |
|
2000 | - EE_Error::doing_it_wrong( |
|
2001 | - 'EEH_Line_Item::create_default_total_line_item()', |
|
2002 | - sprintf( |
|
2003 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
2004 | - 'EEH_Line_Item::create_total_line_item()' |
|
2005 | - ), |
|
2006 | - '4.6.0' |
|
2007 | - ); |
|
2008 | - return self::create_total_line_item($transaction); |
|
2009 | - } |
|
2010 | - |
|
2011 | - |
|
2012 | - /** |
|
2013 | - * @deprecated |
|
2014 | - * @param EE_Line_Item $total_line_item |
|
2015 | - * @param EE_Transaction $transaction |
|
2016 | - * @return EE_Line_Item |
|
2017 | - * @throws EE_Error |
|
2018 | - * @throws InvalidArgumentException |
|
2019 | - * @throws InvalidDataTypeException |
|
2020 | - * @throws InvalidInterfaceException |
|
2021 | - * @throws ReflectionException |
|
2022 | - */ |
|
2023 | - public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
2024 | - { |
|
2025 | - EE_Error::doing_it_wrong( |
|
2026 | - 'EEH_Line_Item::create_default_tickets_subtotal()', |
|
2027 | - sprintf( |
|
2028 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
2029 | - 'EEH_Line_Item::create_pre_tax_subtotal()' |
|
2030 | - ), |
|
2031 | - '4.6.0' |
|
2032 | - ); |
|
2033 | - return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
2034 | - } |
|
2035 | - |
|
2036 | - |
|
2037 | - /** |
|
2038 | - * @deprecated |
|
2039 | - * @param EE_Line_Item $total_line_item |
|
2040 | - * @param EE_Transaction $transaction |
|
2041 | - * @return EE_Line_Item |
|
2042 | - * @throws EE_Error |
|
2043 | - * @throws InvalidArgumentException |
|
2044 | - * @throws InvalidDataTypeException |
|
2045 | - * @throws InvalidInterfaceException |
|
2046 | - * @throws ReflectionException |
|
2047 | - */ |
|
2048 | - public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
2049 | - { |
|
2050 | - EE_Error::doing_it_wrong( |
|
2051 | - 'EEH_Line_Item::create_default_taxes_subtotal()', |
|
2052 | - sprintf( |
|
2053 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
2054 | - 'EEH_Line_Item::create_taxes_subtotal()' |
|
2055 | - ), |
|
2056 | - '4.6.0' |
|
2057 | - ); |
|
2058 | - return self::create_taxes_subtotal($total_line_item, $transaction); |
|
2059 | - } |
|
2060 | - |
|
2061 | - |
|
2062 | - /** |
|
2063 | - * @deprecated |
|
2064 | - * @param EE_Line_Item $total_line_item |
|
2065 | - * @param EE_Transaction $transaction |
|
2066 | - * @return EE_Line_Item |
|
2067 | - * @throws EE_Error |
|
2068 | - * @throws InvalidArgumentException |
|
2069 | - * @throws InvalidDataTypeException |
|
2070 | - * @throws InvalidInterfaceException |
|
2071 | - * @throws ReflectionException |
|
2072 | - */ |
|
2073 | - public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
2074 | - { |
|
2075 | - EE_Error::doing_it_wrong( |
|
2076 | - 'EEH_Line_Item::create_default_event_subtotal()', |
|
2077 | - sprintf( |
|
2078 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
2079 | - 'EEH_Line_Item::create_event_subtotal()' |
|
2080 | - ), |
|
2081 | - '4.6.0' |
|
2082 | - ); |
|
2083 | - return self::create_event_subtotal($total_line_item, $transaction); |
|
2084 | - } |
|
25 | + /** |
|
26 | + * Adds a simple item (unrelated to any other model object) to the provided PARENT line item. |
|
27 | + * Does NOT automatically re-calculate the line item totals or update the related transaction. |
|
28 | + * You should call recalculate_total_including_taxes() on the grant total line item after this |
|
29 | + * to update the subtotals, and EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
30 | + * to keep the registration final prices in-sync with the transaction's total. |
|
31 | + * |
|
32 | + * @param EE_Line_Item $parent_line_item |
|
33 | + * @param string $name |
|
34 | + * @param float $unit_price |
|
35 | + * @param string $description |
|
36 | + * @param int $quantity |
|
37 | + * @param boolean $taxable |
|
38 | + * @param boolean $code if set to a value, ensures there is only one line item with that code |
|
39 | + * @return boolean success |
|
40 | + * @throws EE_Error |
|
41 | + * @throws InvalidArgumentException |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + * @throws InvalidInterfaceException |
|
44 | + * @throws ReflectionException |
|
45 | + */ |
|
46 | + public static function add_unrelated_item( |
|
47 | + EE_Line_Item $parent_line_item, |
|
48 | + $name, |
|
49 | + $unit_price, |
|
50 | + $description = '', |
|
51 | + $quantity = 1, |
|
52 | + $taxable = false, |
|
53 | + $code = null |
|
54 | + ) { |
|
55 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
56 | + $line_item = EE_Line_Item::new_instance(array( |
|
57 | + 'LIN_name' => $name, |
|
58 | + 'LIN_desc' => $description, |
|
59 | + 'LIN_unit_price' => $unit_price, |
|
60 | + 'LIN_quantity' => $quantity, |
|
61 | + 'LIN_percent' => null, |
|
62 | + 'LIN_is_taxable' => $taxable, |
|
63 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
64 | + 'LIN_total' => (float) $unit_price * (int) $quantity, |
|
65 | + 'LIN_type' => EEM_Line_Item::type_line_item, |
|
66 | + 'LIN_code' => $code, |
|
67 | + )); |
|
68 | + $line_item = apply_filters( |
|
69 | + 'FHEE__EEH_Line_Item__add_unrelated_item__line_item', |
|
70 | + $line_item, |
|
71 | + $parent_line_item |
|
72 | + ); |
|
73 | + return self::add_item($parent_line_item, $line_item); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * Adds a simple item ( unrelated to any other model object) to the total line item, |
|
79 | + * in the correct spot in the line item tree. Does not automatically |
|
80 | + * re-calculate the line item totals, nor update the related transaction, nor upgrade the transaction's |
|
81 | + * registrations' final prices (which should probably change because of this). |
|
82 | + * You should call recalculate_total_including_taxes() on the grand total line item, then |
|
83 | + * update the transaction's total, and EE_Registration_Processor::update_registration_final_prices() |
|
84 | + * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
85 | + * |
|
86 | + * @param EE_Line_Item $parent_line_item |
|
87 | + * @param string $name |
|
88 | + * @param float $percentage_amount |
|
89 | + * @param string $description |
|
90 | + * @param boolean $taxable |
|
91 | + * @return boolean success |
|
92 | + * @throws EE_Error |
|
93 | + */ |
|
94 | + public static function add_percentage_based_item( |
|
95 | + EE_Line_Item $parent_line_item, |
|
96 | + $name, |
|
97 | + $percentage_amount, |
|
98 | + $description = '', |
|
99 | + $taxable = false |
|
100 | + ) { |
|
101 | + $line_item = EE_Line_Item::new_instance(array( |
|
102 | + 'LIN_name' => $name, |
|
103 | + 'LIN_desc' => $description, |
|
104 | + 'LIN_unit_price' => 0, |
|
105 | + 'LIN_percent' => $percentage_amount, |
|
106 | + 'LIN_quantity' => 1, |
|
107 | + 'LIN_is_taxable' => $taxable, |
|
108 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
109 | + 'LIN_type' => EEM_Line_Item::type_line_item, |
|
110 | + 'LIN_parent' => $parent_line_item->ID(), |
|
111 | + )); |
|
112 | + $line_item = apply_filters( |
|
113 | + 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
|
114 | + $line_item |
|
115 | + ); |
|
116 | + return $parent_line_item->add_child_line_item($line_item, false); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Returns the new line item created by adding a purchase of the ticket |
|
122 | + * ensures that ticket line item is saved, and that cart total has been recalculated. |
|
123 | + * If this ticket has already been purchased, just increments its count. |
|
124 | + * Automatically re-calculates the line item totals and updates the related transaction. But |
|
125 | + * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
126 | + * should probably change because of this). |
|
127 | + * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
128 | + * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
129 | + * |
|
130 | + * @param EE_Line_Item $total_line_item grand total line item of type EEM_Line_Item::type_total |
|
131 | + * @param EE_Ticket $ticket |
|
132 | + * @param int $qty |
|
133 | + * @return EE_Line_Item |
|
134 | + * @throws EE_Error |
|
135 | + * @throws InvalidArgumentException |
|
136 | + * @throws InvalidDataTypeException |
|
137 | + * @throws InvalidInterfaceException |
|
138 | + * @throws ReflectionException |
|
139 | + */ |
|
140 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) |
|
141 | + { |
|
142 | + if (! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
143 | + throw new EE_Error( |
|
144 | + sprintf( |
|
145 | + esc_html__( |
|
146 | + 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', |
|
147 | + 'event_espresso' |
|
148 | + ), |
|
149 | + $ticket->ID(), |
|
150 | + $total_line_item->ID() |
|
151 | + ) |
|
152 | + ); |
|
153 | + } |
|
154 | + // either increment the qty for an existing ticket |
|
155 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
156 | + // or add a new one |
|
157 | + if (! $line_item instanceof EE_Line_Item) { |
|
158 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
159 | + } |
|
160 | + $total_line_item->recalculate_total_including_taxes(); |
|
161 | + return $line_item; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns the new line item created by adding a purchase of the ticket |
|
167 | + * |
|
168 | + * @param EE_Line_Item $total_line_item |
|
169 | + * @param EE_Ticket $ticket |
|
170 | + * @param int $qty |
|
171 | + * @return EE_Line_Item |
|
172 | + * @throws EE_Error |
|
173 | + * @throws InvalidArgumentException |
|
174 | + * @throws InvalidDataTypeException |
|
175 | + * @throws InvalidInterfaceException |
|
176 | + * @throws ReflectionException |
|
177 | + */ |
|
178 | + public static function increment_ticket_qty_if_already_in_cart( |
|
179 | + EE_Line_Item $total_line_item, |
|
180 | + EE_Ticket $ticket, |
|
181 | + $qty = 1 |
|
182 | + ) { |
|
183 | + $line_item = null; |
|
184 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
185 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
186 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
187 | + if ( |
|
188 | + $ticket_line_item instanceof EE_Line_Item |
|
189 | + && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
|
190 | + ) { |
|
191 | + $line_item = $ticket_line_item; |
|
192 | + break; |
|
193 | + } |
|
194 | + } |
|
195 | + } |
|
196 | + if ($line_item instanceof EE_Line_Item) { |
|
197 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
198 | + return $line_item; |
|
199 | + } |
|
200 | + return null; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Increments the line item and all its children's quantity by $qty (but percent line items are unaffected). |
|
206 | + * Does NOT save or recalculate other line items totals |
|
207 | + * |
|
208 | + * @param EE_Line_Item $line_item |
|
209 | + * @param int $qty |
|
210 | + * @return void |
|
211 | + * @throws EE_Error |
|
212 | + * @throws InvalidArgumentException |
|
213 | + * @throws InvalidDataTypeException |
|
214 | + * @throws InvalidInterfaceException |
|
215 | + * @throws ReflectionException |
|
216 | + */ |
|
217 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) |
|
218 | + { |
|
219 | + if (! $line_item->is_percent()) { |
|
220 | + $qty += $line_item->quantity(); |
|
221 | + $line_item->set_quantity($qty); |
|
222 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
223 | + $line_item->save(); |
|
224 | + } |
|
225 | + foreach ($line_item->children() as $child) { |
|
226 | + if ($child->is_sub_line_item()) { |
|
227 | + EEH_Line_Item::update_quantity($child, $qty); |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * Decrements the line item and all its children's quantity by $qty (but percent line items are unaffected). |
|
235 | + * Does NOT save or recalculate other line items totals |
|
236 | + * |
|
237 | + * @param EE_Line_Item $line_item |
|
238 | + * @param int $qty |
|
239 | + * @return void |
|
240 | + * @throws EE_Error |
|
241 | + * @throws InvalidArgumentException |
|
242 | + * @throws InvalidDataTypeException |
|
243 | + * @throws InvalidInterfaceException |
|
244 | + * @throws ReflectionException |
|
245 | + */ |
|
246 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) |
|
247 | + { |
|
248 | + if (! $line_item->is_percent()) { |
|
249 | + $qty = $line_item->quantity() - $qty; |
|
250 | + $qty = max($qty, 0); |
|
251 | + $line_item->set_quantity($qty); |
|
252 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
253 | + $line_item->save(); |
|
254 | + } |
|
255 | + foreach ($line_item->children() as $child) { |
|
256 | + if ($child->is_sub_line_item()) { |
|
257 | + EEH_Line_Item::update_quantity($child, $qty); |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * Updates the line item and its children's quantities to the specified number. |
|
265 | + * Does NOT save them or recalculate totals. |
|
266 | + * |
|
267 | + * @param EE_Line_Item $line_item |
|
268 | + * @param int $new_quantity |
|
269 | + * @throws EE_Error |
|
270 | + * @throws InvalidArgumentException |
|
271 | + * @throws InvalidDataTypeException |
|
272 | + * @throws InvalidInterfaceException |
|
273 | + * @throws ReflectionException |
|
274 | + */ |
|
275 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) |
|
276 | + { |
|
277 | + if (! $line_item->is_percent()) { |
|
278 | + $line_item->set_quantity($new_quantity); |
|
279 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
280 | + $line_item->save(); |
|
281 | + } |
|
282 | + foreach ($line_item->children() as $child) { |
|
283 | + if ($child->is_sub_line_item()) { |
|
284 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Returns the new line item created by adding a purchase of the ticket |
|
292 | + * |
|
293 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
294 | + * @param EE_Ticket $ticket |
|
295 | + * @param int $qty |
|
296 | + * @return EE_Line_Item |
|
297 | + * @throws EE_Error |
|
298 | + * @throws InvalidArgumentException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws InvalidInterfaceException |
|
301 | + * @throws ReflectionException |
|
302 | + */ |
|
303 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) |
|
304 | + { |
|
305 | + $datetimes = $ticket->datetimes(); |
|
306 | + $first_datetime = reset($datetimes); |
|
307 | + $first_datetime_name = esc_html__('Event', 'event_espresso'); |
|
308 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
309 | + $first_datetime_name = $first_datetime->event()->name(); |
|
310 | + } |
|
311 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
312 | + // get event subtotal line |
|
313 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
314 | + $taxes = $ticket->tax_price_modifiers(); |
|
315 | + $is_taxable = empty($taxes) ? $ticket->taxable() : false; |
|
316 | + // add $ticket to cart |
|
317 | + $line_item = EE_Line_Item::new_instance(array( |
|
318 | + 'LIN_name' => $ticket->name(), |
|
319 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
320 | + 'LIN_unit_price' => $ticket->price(), |
|
321 | + 'LIN_quantity' => $qty, |
|
322 | + 'LIN_is_taxable' => $is_taxable, |
|
323 | + 'LIN_order' => count($events_sub_total->children()), |
|
324 | + 'LIN_total' => $ticket->price() * $qty, |
|
325 | + 'LIN_type' => EEM_Line_Item::type_line_item, |
|
326 | + 'OBJ_ID' => $ticket->ID(), |
|
327 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
328 | + )); |
|
329 | + $line_item = apply_filters( |
|
330 | + 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
|
331 | + $line_item |
|
332 | + ); |
|
333 | + $events_sub_total->add_child_line_item($line_item); |
|
334 | + // now add the sub-line items |
|
335 | + $running_total_for_ticket = 0; |
|
336 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
337 | + $sign = $price->is_discount() ? -1 : 1; |
|
338 | + $price_total = $price->is_percent() |
|
339 | + ? $running_total_for_ticket * $price->amount() / 100 |
|
340 | + : $price->amount() * $qty; |
|
341 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
342 | + 'LIN_name' => $price->name(), |
|
343 | + 'LIN_desc' => $price->desc(), |
|
344 | + 'LIN_quantity' => $price->is_percent() ? null : $qty, |
|
345 | + 'LIN_is_taxable' => false, |
|
346 | + 'LIN_order' => $price->order(), |
|
347 | + 'LIN_total' => $sign * $price_total, |
|
348 | + 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
|
349 | + 'OBJ_ID' => $price->ID(), |
|
350 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PRICE, |
|
351 | + )); |
|
352 | + $sub_line_item = apply_filters( |
|
353 | + 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
|
354 | + $sub_line_item |
|
355 | + ); |
|
356 | + if ($price->is_percent()) { |
|
357 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
358 | + } else { |
|
359 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
360 | + } |
|
361 | + $running_total_for_ticket += $price_total; |
|
362 | + $line_item->add_child_line_item($sub_line_item); |
|
363 | + } |
|
364 | + return $line_item; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Adds the specified item under the pre-tax-sub-total line item. Automatically |
|
370 | + * re-calculates the line item totals and updates the related transaction. But |
|
371 | + * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
372 | + * should probably change because of this). |
|
373 | + * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
374 | + * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
375 | + * |
|
376 | + * @param EE_Line_Item $total_line_item |
|
377 | + * @param EE_Line_Item $item to be added |
|
378 | + * @return boolean |
|
379 | + * @throws EE_Error |
|
380 | + * @throws InvalidArgumentException |
|
381 | + * @throws InvalidDataTypeException |
|
382 | + * @throws InvalidInterfaceException |
|
383 | + * @throws ReflectionException |
|
384 | + */ |
|
385 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) |
|
386 | + { |
|
387 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
388 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
389 | + $success = $pre_tax_subtotal->add_child_line_item($item); |
|
390 | + } else { |
|
391 | + return false; |
|
392 | + } |
|
393 | + $total_line_item->recalculate_total_including_taxes(); |
|
394 | + return $success; |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * cancels an existing ticket line item, |
|
400 | + * by decrementing it's quantity by 1 and adding a new "type_cancellation" sub-line-item. |
|
401 | + * ALL totals and subtotals will NEED TO BE UPDATED after performing this action |
|
402 | + * |
|
403 | + * @param EE_Line_Item $ticket_line_item |
|
404 | + * @param int $qty |
|
405 | + * @return bool success |
|
406 | + * @throws EE_Error |
|
407 | + * @throws InvalidArgumentException |
|
408 | + * @throws InvalidDataTypeException |
|
409 | + * @throws InvalidInterfaceException |
|
410 | + * @throws ReflectionException |
|
411 | + */ |
|
412 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) |
|
413 | + { |
|
414 | + // validate incoming line_item |
|
415 | + if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
416 | + throw new EE_Error( |
|
417 | + sprintf( |
|
418 | + esc_html__( |
|
419 | + 'The supplied line item must have an Object Type of "Ticket", not %1$s.', |
|
420 | + 'event_espresso' |
|
421 | + ), |
|
422 | + $ticket_line_item->type() |
|
423 | + ) |
|
424 | + ); |
|
425 | + } |
|
426 | + if ($ticket_line_item->quantity() < $qty) { |
|
427 | + throw new EE_Error( |
|
428 | + sprintf( |
|
429 | + esc_html__( |
|
430 | + 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', |
|
431 | + 'event_espresso' |
|
432 | + ), |
|
433 | + $qty, |
|
434 | + $ticket_line_item->quantity() |
|
435 | + ) |
|
436 | + ); |
|
437 | + } |
|
438 | + // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
|
439 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
440 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
441 | + if ( |
|
442 | + $child_line_item->is_sub_line_item() |
|
443 | + && ! $child_line_item->is_percent() |
|
444 | + && ! $child_line_item->is_cancellation() |
|
445 | + ) { |
|
446 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
447 | + } |
|
448 | + } |
|
449 | + // get cancellation sub line item |
|
450 | + $cancellation_line_item = EEH_Line_Item::get_descendants_of_type( |
|
451 | + $ticket_line_item, |
|
452 | + EEM_Line_Item::type_cancellation |
|
453 | + ); |
|
454 | + $cancellation_line_item = reset($cancellation_line_item); |
|
455 | + // verify that this ticket was indeed previously cancelled |
|
456 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
457 | + // increment cancelled quantity |
|
458 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
459 | + } else { |
|
460 | + // create cancellation sub line item |
|
461 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
462 | + 'LIN_name' => esc_html__('Cancellation', 'event_espresso'), |
|
463 | + 'LIN_desc' => sprintf( |
|
464 | + esc_html_x( |
|
465 | + 'Cancelled %1$s : %2$s', |
|
466 | + 'Cancelled Ticket Name : 2015-01-01 11:11', |
|
467 | + 'event_espresso' |
|
468 | + ), |
|
469 | + $ticket_line_item->name(), |
|
470 | + current_time(get_option('date_format') . ' ' . get_option('time_format')) |
|
471 | + ), |
|
472 | + 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
|
473 | + 'LIN_quantity' => $qty, |
|
474 | + 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
|
475 | + 'LIN_order' => count($ticket_line_item->children()), |
|
476 | + 'LIN_total' => 0, // $ticket_line_item->unit_price() |
|
477 | + 'LIN_type' => EEM_Line_Item::type_cancellation, |
|
478 | + )); |
|
479 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
480 | + } |
|
481 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
482 | + // decrement parent line item quantity |
|
483 | + $event_line_item = $ticket_line_item->parent(); |
|
484 | + if ( |
|
485 | + $event_line_item instanceof EE_Line_Item |
|
486 | + && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
487 | + ) { |
|
488 | + $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
489 | + $event_line_item->save(); |
|
490 | + } |
|
491 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
492 | + return true; |
|
493 | + } |
|
494 | + return false; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * reinstates (un-cancels?) a previously canceled ticket line item, |
|
500 | + * by incrementing it's quantity by 1, and decrementing it's "type_cancellation" sub-line-item. |
|
501 | + * ALL totals and subtotals will NEED TO BE UPDATED after performing this action |
|
502 | + * |
|
503 | + * @param EE_Line_Item $ticket_line_item |
|
504 | + * @param int $qty |
|
505 | + * @return bool success |
|
506 | + * @throws EE_Error |
|
507 | + * @throws InvalidArgumentException |
|
508 | + * @throws InvalidDataTypeException |
|
509 | + * @throws InvalidInterfaceException |
|
510 | + * @throws ReflectionException |
|
511 | + */ |
|
512 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) |
|
513 | + { |
|
514 | + // validate incoming line_item |
|
515 | + if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
516 | + throw new EE_Error( |
|
517 | + sprintf( |
|
518 | + esc_html__( |
|
519 | + 'The supplied line item must have an Object Type of "Ticket", not %1$s.', |
|
520 | + 'event_espresso' |
|
521 | + ), |
|
522 | + $ticket_line_item->type() |
|
523 | + ) |
|
524 | + ); |
|
525 | + } |
|
526 | + // get cancellation sub line item |
|
527 | + $cancellation_line_item = EEH_Line_Item::get_descendants_of_type( |
|
528 | + $ticket_line_item, |
|
529 | + EEM_Line_Item::type_cancellation |
|
530 | + ); |
|
531 | + $cancellation_line_item = reset($cancellation_line_item); |
|
532 | + // verify that this ticket was indeed previously cancelled |
|
533 | + if (! $cancellation_line_item instanceof EE_Line_Item) { |
|
534 | + return false; |
|
535 | + } |
|
536 | + if ($cancellation_line_item->quantity() > $qty) { |
|
537 | + // decrement cancelled quantity |
|
538 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
539 | + } elseif ($cancellation_line_item->quantity() === $qty) { |
|
540 | + // decrement cancelled quantity in case anyone still has the object kicking around |
|
541 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
542 | + // delete because quantity will end up as 0 |
|
543 | + $cancellation_line_item->delete(); |
|
544 | + // and attempt to destroy the object, |
|
545 | + // even though PHP won't actually destroy it until it needs the memory |
|
546 | + unset($cancellation_line_item); |
|
547 | + } else { |
|
548 | + // what ?!?! negative quantity ?!?! |
|
549 | + throw new EE_Error( |
|
550 | + sprintf( |
|
551 | + esc_html__( |
|
552 | + 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
553 | + 'event_espresso' |
|
554 | + ), |
|
555 | + $qty, |
|
556 | + $cancellation_line_item->quantity() |
|
557 | + ) |
|
558 | + ); |
|
559 | + } |
|
560 | + // increment ticket quantity |
|
561 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
562 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
563 | + // increment parent line item quantity |
|
564 | + $event_line_item = $ticket_line_item->parent(); |
|
565 | + if ( |
|
566 | + $event_line_item instanceof EE_Line_Item |
|
567 | + && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
568 | + ) { |
|
569 | + $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
570 | + } |
|
571 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
572 | + return true; |
|
573 | + } |
|
574 | + return false; |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * calls EEH_Line_Item::find_transaction_grand_total_for_line_item() |
|
580 | + * then EE_Line_Item::recalculate_total_including_taxes() on the result |
|
581 | + * |
|
582 | + * @param EE_Line_Item $line_item |
|
583 | + * @return float |
|
584 | + * @throws EE_Error |
|
585 | + * @throws InvalidArgumentException |
|
586 | + * @throws InvalidDataTypeException |
|
587 | + * @throws InvalidInterfaceException |
|
588 | + * @throws ReflectionException |
|
589 | + */ |
|
590 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) |
|
591 | + { |
|
592 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
593 | + return $grand_total_line_item->recalculate_total_including_taxes(); |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Gets the line item which contains the subtotal of all the items |
|
599 | + * |
|
600 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
601 | + * @return EE_Line_Item |
|
602 | + * @throws EE_Error |
|
603 | + * @throws InvalidArgumentException |
|
604 | + * @throws InvalidDataTypeException |
|
605 | + * @throws InvalidInterfaceException |
|
606 | + * @throws ReflectionException |
|
607 | + */ |
|
608 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) |
|
609 | + { |
|
610 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
611 | + return $pre_tax_subtotal instanceof EE_Line_Item |
|
612 | + ? $pre_tax_subtotal |
|
613 | + : self::create_pre_tax_subtotal($total_line_item); |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + /** |
|
618 | + * Gets the line item for the taxes subtotal |
|
619 | + * |
|
620 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
621 | + * @return EE_Line_Item |
|
622 | + * @throws EE_Error |
|
623 | + * @throws InvalidArgumentException |
|
624 | + * @throws InvalidDataTypeException |
|
625 | + * @throws InvalidInterfaceException |
|
626 | + * @throws ReflectionException |
|
627 | + */ |
|
628 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) |
|
629 | + { |
|
630 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
631 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * sets the TXN ID on an EE_Line_Item if passed a valid EE_Transaction object |
|
637 | + * |
|
638 | + * @param EE_Line_Item $line_item |
|
639 | + * @param EE_Transaction $transaction |
|
640 | + * @return void |
|
641 | + * @throws EE_Error |
|
642 | + * @throws InvalidArgumentException |
|
643 | + * @throws InvalidDataTypeException |
|
644 | + * @throws InvalidInterfaceException |
|
645 | + * @throws ReflectionException |
|
646 | + */ |
|
647 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = null) |
|
648 | + { |
|
649 | + if ($transaction) { |
|
650 | + /** @type EEM_Transaction $EEM_Transaction */ |
|
651 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
652 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
653 | + $line_item->set_TXN_ID($TXN_ID); |
|
654 | + } |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * Creates a new default total line item for the transaction, |
|
660 | + * and its tickets subtotal and taxes subtotal line items (and adds the |
|
661 | + * existing taxes as children of the taxes subtotal line item) |
|
662 | + * |
|
663 | + * @param EE_Transaction $transaction |
|
664 | + * @return EE_Line_Item of type total |
|
665 | + * @throws EE_Error |
|
666 | + * @throws InvalidArgumentException |
|
667 | + * @throws InvalidDataTypeException |
|
668 | + * @throws InvalidInterfaceException |
|
669 | + * @throws ReflectionException |
|
670 | + */ |
|
671 | + public static function create_total_line_item($transaction = null) |
|
672 | + { |
|
673 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
674 | + 'LIN_code' => 'total', |
|
675 | + 'LIN_name' => esc_html__('Grand Total', 'event_espresso'), |
|
676 | + 'LIN_type' => EEM_Line_Item::type_total, |
|
677 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TRANSACTION, |
|
678 | + )); |
|
679 | + $total_line_item = apply_filters( |
|
680 | + 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
|
681 | + $total_line_item |
|
682 | + ); |
|
683 | + self::set_TXN_ID($total_line_item, $transaction); |
|
684 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
685 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
686 | + return $total_line_item; |
|
687 | + } |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * Creates a default items subtotal line item |
|
692 | + * |
|
693 | + * @param EE_Line_Item $total_line_item |
|
694 | + * @param EE_Transaction $transaction |
|
695 | + * @return EE_Line_Item |
|
696 | + * @throws EE_Error |
|
697 | + * @throws InvalidArgumentException |
|
698 | + * @throws InvalidDataTypeException |
|
699 | + * @throws InvalidInterfaceException |
|
700 | + * @throws ReflectionException |
|
701 | + */ |
|
702 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
703 | + { |
|
704 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
705 | + 'LIN_code' => 'pre-tax-subtotal', |
|
706 | + 'LIN_name' => esc_html__('Pre-Tax Subtotal', 'event_espresso'), |
|
707 | + 'LIN_type' => EEM_Line_Item::type_sub_total, |
|
708 | + )); |
|
709 | + $pre_tax_line_item = apply_filters( |
|
710 | + 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
|
711 | + $pre_tax_line_item |
|
712 | + ); |
|
713 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
714 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
715 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
716 | + return $pre_tax_line_item; |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * Creates a line item for the taxes subtotal and finds all the tax prices |
|
722 | + * and applies taxes to it |
|
723 | + * |
|
724 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
725 | + * @param EE_Transaction $transaction |
|
726 | + * @return EE_Line_Item |
|
727 | + * @throws EE_Error |
|
728 | + * @throws InvalidArgumentException |
|
729 | + * @throws InvalidDataTypeException |
|
730 | + * @throws InvalidInterfaceException |
|
731 | + * @throws ReflectionException |
|
732 | + */ |
|
733 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
734 | + { |
|
735 | + $tax_line_item = EE_Line_Item::new_instance(array( |
|
736 | + 'LIN_code' => 'taxes', |
|
737 | + 'LIN_name' => esc_html__('Taxes', 'event_espresso'), |
|
738 | + 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
|
739 | + 'LIN_order' => 1000,// this should always come last |
|
740 | + )); |
|
741 | + $tax_line_item = apply_filters( |
|
742 | + 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
|
743 | + $tax_line_item |
|
744 | + ); |
|
745 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
746 | + $total_line_item->add_child_line_item($tax_line_item); |
|
747 | + // and lastly, add the actual taxes |
|
748 | + self::apply_taxes($total_line_item); |
|
749 | + return $tax_line_item; |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * Creates a default items subtotal line item |
|
755 | + * |
|
756 | + * @param EE_Line_Item $pre_tax_line_item |
|
757 | + * @param EE_Transaction $transaction |
|
758 | + * @param EE_Event $event |
|
759 | + * @return EE_Line_Item |
|
760 | + * @throws EE_Error |
|
761 | + * @throws InvalidArgumentException |
|
762 | + * @throws InvalidDataTypeException |
|
763 | + * @throws InvalidInterfaceException |
|
764 | + * @throws ReflectionException |
|
765 | + */ |
|
766 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = null, $event = null) |
|
767 | + { |
|
768 | + $event_line_item = EE_Line_Item::new_instance(array( |
|
769 | + 'LIN_code' => self::get_event_code($event), |
|
770 | + 'LIN_name' => self::get_event_name($event), |
|
771 | + 'LIN_desc' => self::get_event_desc($event), |
|
772 | + 'LIN_type' => EEM_Line_Item::type_sub_total, |
|
773 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_EVENT, |
|
774 | + 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0, |
|
775 | + )); |
|
776 | + $event_line_item = apply_filters( |
|
777 | + 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
|
778 | + $event_line_item |
|
779 | + ); |
|
780 | + self::set_TXN_ID($event_line_item, $transaction); |
|
781 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
782 | + return $event_line_item; |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * Gets what the event ticket's code SHOULD be |
|
788 | + * |
|
789 | + * @param EE_Event $event |
|
790 | + * @return string |
|
791 | + * @throws EE_Error |
|
792 | + */ |
|
793 | + public static function get_event_code($event) |
|
794 | + { |
|
795 | + return 'event-' . ($event instanceof EE_Event ? $event->ID() : '0'); |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * Gets the event name |
|
801 | + * |
|
802 | + * @param EE_Event $event |
|
803 | + * @return string |
|
804 | + * @throws EE_Error |
|
805 | + */ |
|
806 | + public static function get_event_name($event) |
|
807 | + { |
|
808 | + return $event instanceof EE_Event |
|
809 | + ? mb_substr($event->name(), 0, 245) |
|
810 | + : esc_html__('Event', 'event_espresso'); |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * Gets the event excerpt |
|
816 | + * |
|
817 | + * @param EE_Event $event |
|
818 | + * @return string |
|
819 | + * @throws EE_Error |
|
820 | + */ |
|
821 | + public static function get_event_desc($event) |
|
822 | + { |
|
823 | + return $event instanceof EE_Event ? $event->short_description() : ''; |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * Given the grand total line item and a ticket, finds the event sub-total |
|
829 | + * line item the ticket's purchase should be added onto |
|
830 | + * |
|
831 | + * @access public |
|
832 | + * @param EE_Line_Item $grand_total the grand total line item |
|
833 | + * @param EE_Ticket $ticket |
|
834 | + * @return EE_Line_Item |
|
835 | + * @throws EE_Error |
|
836 | + * @throws InvalidArgumentException |
|
837 | + * @throws InvalidDataTypeException |
|
838 | + * @throws InvalidInterfaceException |
|
839 | + * @throws ReflectionException |
|
840 | + */ |
|
841 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) |
|
842 | + { |
|
843 | + $first_datetime = $ticket->first_datetime(); |
|
844 | + if (! $first_datetime instanceof EE_Datetime) { |
|
845 | + throw new EE_Error( |
|
846 | + sprintf( |
|
847 | + __('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), |
|
848 | + $ticket->ID() |
|
849 | + ) |
|
850 | + ); |
|
851 | + } |
|
852 | + $event = $first_datetime->event(); |
|
853 | + if (! $event instanceof EE_Event) { |
|
854 | + throw new EE_Error( |
|
855 | + sprintf( |
|
856 | + esc_html__( |
|
857 | + 'The supplied ticket (ID %d) has no event data associated with it.', |
|
858 | + 'event_espresso' |
|
859 | + ), |
|
860 | + $ticket->ID() |
|
861 | + ) |
|
862 | + ); |
|
863 | + } |
|
864 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
865 | + if (! $events_sub_total instanceof EE_Line_Item) { |
|
866 | + throw new EE_Error( |
|
867 | + sprintf( |
|
868 | + esc_html__( |
|
869 | + 'There is no events sub-total for ticket %s on total line item %d', |
|
870 | + 'event_espresso' |
|
871 | + ), |
|
872 | + $ticket->ID(), |
|
873 | + $grand_total->ID() |
|
874 | + ) |
|
875 | + ); |
|
876 | + } |
|
877 | + return $events_sub_total; |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + /** |
|
882 | + * Gets the event line item |
|
883 | + * |
|
884 | + * @param EE_Line_Item $grand_total |
|
885 | + * @param EE_Event $event |
|
886 | + * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
|
887 | + * @throws EE_Error |
|
888 | + * @throws InvalidArgumentException |
|
889 | + * @throws InvalidDataTypeException |
|
890 | + * @throws InvalidInterfaceException |
|
891 | + * @throws ReflectionException |
|
892 | + */ |
|
893 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) |
|
894 | + { |
|
895 | + /** @type EE_Event $event */ |
|
896 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
897 | + $event_line_item = null; |
|
898 | + $found = false; |
|
899 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
900 | + // default event subtotal, we should only ever find this the first time this method is called |
|
901 | + if (! $event_line_item->OBJ_ID()) { |
|
902 | + // let's use this! but first... set the event details |
|
903 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
904 | + $found = true; |
|
905 | + break; |
|
906 | + } |
|
907 | + if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
908 | + // found existing line item for this event in the cart, so break out of loop and use this one |
|
909 | + $found = true; |
|
910 | + break; |
|
911 | + } |
|
912 | + } |
|
913 | + if (! $found) { |
|
914 | + // there is no event sub-total yet, so add it |
|
915 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
916 | + // create a new "event" subtotal below that |
|
917 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
918 | + // and set the event details |
|
919 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
920 | + } |
|
921 | + return $event_line_item; |
|
922 | + } |
|
923 | + |
|
924 | + |
|
925 | + /** |
|
926 | + * Creates a default items subtotal line item |
|
927 | + * |
|
928 | + * @param EE_Line_Item $event_line_item |
|
929 | + * @param EE_Event $event |
|
930 | + * @param EE_Transaction $transaction |
|
931 | + * @return void |
|
932 | + * @throws EE_Error |
|
933 | + * @throws InvalidArgumentException |
|
934 | + * @throws InvalidDataTypeException |
|
935 | + * @throws InvalidInterfaceException |
|
936 | + * @throws ReflectionException |
|
937 | + */ |
|
938 | + public static function set_event_subtotal_details( |
|
939 | + EE_Line_Item $event_line_item, |
|
940 | + EE_Event $event, |
|
941 | + $transaction = null |
|
942 | + ) { |
|
943 | + if ($event instanceof EE_Event) { |
|
944 | + $event_line_item->set_code(self::get_event_code($event)); |
|
945 | + $event_line_item->set_name(self::get_event_name($event)); |
|
946 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
947 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
948 | + } |
|
949 | + self::set_TXN_ID($event_line_item, $transaction); |
|
950 | + } |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * Finds what taxes should apply, adds them as tax line items under the taxes sub-total, |
|
955 | + * and recalculates the taxes sub-total and the grand total. Resets the taxes, so |
|
956 | + * any old taxes are removed |
|
957 | + * |
|
958 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
959 | + * @param bool $update_txn_status |
|
960 | + * @return bool |
|
961 | + * @throws EE_Error |
|
962 | + * @throws InvalidArgumentException |
|
963 | + * @throws InvalidDataTypeException |
|
964 | + * @throws InvalidInterfaceException |
|
965 | + * @throws ReflectionException |
|
966 | + * @throws RuntimeException |
|
967 | + */ |
|
968 | + public static function apply_taxes(EE_Line_Item $total_line_item, $update_txn_status = false) |
|
969 | + { |
|
970 | + /** @var EE_Admin_Config $admin_config */ |
|
971 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
972 | + if ($admin_config->useAdvancedEditor()) { |
|
973 | + return false; |
|
974 | + } |
|
975 | + /** @type EEM_Price $EEM_Price */ |
|
976 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
977 | + // get array of taxes via Price Model |
|
978 | + $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
|
979 | + ksort($ordered_taxes); |
|
980 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
981 | + // just to be safe, remove its old tax line items |
|
982 | + $deleted = $taxes_line_item->delete_children_line_items(); |
|
983 | + $updates = false; |
|
984 | + // loop thru taxes |
|
985 | + foreach ($ordered_taxes as $order => $taxes) { |
|
986 | + foreach ($taxes as $tax) { |
|
987 | + if ($tax instanceof EE_Price) { |
|
988 | + $tax_line_item = EE_Line_Item::new_instance( |
|
989 | + array( |
|
990 | + 'LIN_name' => $tax->name(), |
|
991 | + 'LIN_desc' => $tax->desc(), |
|
992 | + 'LIN_percent' => $tax->amount(), |
|
993 | + 'LIN_is_taxable' => false, |
|
994 | + 'LIN_order' => $order, |
|
995 | + 'LIN_total' => 0, |
|
996 | + 'LIN_type' => EEM_Line_Item::type_tax, |
|
997 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PRICE, |
|
998 | + 'OBJ_ID' => $tax->ID(), |
|
999 | + ) |
|
1000 | + ); |
|
1001 | + $tax_line_item = apply_filters( |
|
1002 | + 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
|
1003 | + $tax_line_item |
|
1004 | + ); |
|
1005 | + $updates = $taxes_line_item->add_child_line_item($tax_line_item) ? |
|
1006 | + true : |
|
1007 | + $updates; |
|
1008 | + } |
|
1009 | + } |
|
1010 | + } |
|
1011 | + // only recalculate totals if something changed |
|
1012 | + if ($deleted || $updates) { |
|
1013 | + $total_line_item->recalculate_total_including_taxes($update_txn_status); |
|
1014 | + return true; |
|
1015 | + } |
|
1016 | + return false; |
|
1017 | + } |
|
1018 | + |
|
1019 | + |
|
1020 | + /** |
|
1021 | + * Ensures that taxes have been applied to the order, if not applies them. |
|
1022 | + * Returns the total amount of tax |
|
1023 | + * |
|
1024 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
1025 | + * @return float |
|
1026 | + * @throws EE_Error |
|
1027 | + * @throws InvalidArgumentException |
|
1028 | + * @throws InvalidDataTypeException |
|
1029 | + * @throws InvalidInterfaceException |
|
1030 | + * @throws ReflectionException |
|
1031 | + */ |
|
1032 | + public static function ensure_taxes_applied($total_line_item) |
|
1033 | + { |
|
1034 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
1035 | + if (! $taxes_subtotal->children()) { |
|
1036 | + self::apply_taxes($total_line_item); |
|
1037 | + } |
|
1038 | + return $taxes_subtotal->total(); |
|
1039 | + } |
|
1040 | + |
|
1041 | + |
|
1042 | + /** |
|
1043 | + * Deletes ALL children of the passed line item |
|
1044 | + * |
|
1045 | + * @param EE_Line_Item $parent_line_item |
|
1046 | + * @return bool |
|
1047 | + * @throws EE_Error |
|
1048 | + * @throws InvalidArgumentException |
|
1049 | + * @throws InvalidDataTypeException |
|
1050 | + * @throws InvalidInterfaceException |
|
1051 | + * @throws ReflectionException |
|
1052 | + */ |
|
1053 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) |
|
1054 | + { |
|
1055 | + $deleted = 0; |
|
1056 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1057 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1058 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
1059 | + if ($child_line_item->ID()) { |
|
1060 | + $child_line_item->delete(); |
|
1061 | + unset($child_line_item); |
|
1062 | + } else { |
|
1063 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
1064 | + } |
|
1065 | + $deleted++; |
|
1066 | + } |
|
1067 | + } |
|
1068 | + return $deleted; |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * Deletes the line items as indicated by the line item code(s) provided, |
|
1074 | + * regardless of where they're found in the line item tree. Automatically |
|
1075 | + * re-calculates the line item totals and updates the related transaction. But |
|
1076 | + * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
|
1077 | + * should probably change because of this). |
|
1078 | + * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
|
1079 | + * after using this, to keep the registration final prices in-sync with the transaction's total. |
|
1080 | + * |
|
1081 | + * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
|
1082 | + * @param array|bool|string $line_item_codes |
|
1083 | + * @return int number of items successfully removed |
|
1084 | + * @throws EE_Error |
|
1085 | + */ |
|
1086 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = false) |
|
1087 | + { |
|
1088 | + |
|
1089 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
1090 | + EE_Error::doing_it_wrong( |
|
1091 | + 'EEH_Line_Item::delete_items', |
|
1092 | + esc_html__( |
|
1093 | + 'This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly', |
|
1094 | + 'event_espresso' |
|
1095 | + ), |
|
1096 | + '4.6.18' |
|
1097 | + ); |
|
1098 | + } |
|
1099 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1100 | + |
|
1101 | + // check if only a single line_item_id was passed |
|
1102 | + if (! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
1103 | + // place single line_item_id in an array to appear as multiple line_item_ids |
|
1104 | + $line_item_codes = array($line_item_codes); |
|
1105 | + } |
|
1106 | + $removals = 0; |
|
1107 | + // cycle thru line_item_ids |
|
1108 | + foreach ($line_item_codes as $line_item_id) { |
|
1109 | + $removals += $total_line_item->delete_child_line_item($line_item_id); |
|
1110 | + } |
|
1111 | + |
|
1112 | + if ($removals > 0) { |
|
1113 | + $total_line_item->recalculate_taxes_and_tax_total(); |
|
1114 | + return $removals; |
|
1115 | + } else { |
|
1116 | + return false; |
|
1117 | + } |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * Overwrites the previous tax by clearing out the old taxes, and creates a new |
|
1123 | + * tax and updates the total line item accordingly |
|
1124 | + * |
|
1125 | + * @param EE_Line_Item $total_line_item |
|
1126 | + * @param float $amount |
|
1127 | + * @param string $name |
|
1128 | + * @param string $description |
|
1129 | + * @param string $code |
|
1130 | + * @param boolean $add_to_existing_line_item |
|
1131 | + * if true, and a duplicate line item with the same code is found, |
|
1132 | + * $amount will be added onto it; otherwise will simply set the taxes to match $amount |
|
1133 | + * @return EE_Line_Item the new tax line item created |
|
1134 | + * @throws EE_Error |
|
1135 | + * @throws InvalidArgumentException |
|
1136 | + * @throws InvalidDataTypeException |
|
1137 | + * @throws InvalidInterfaceException |
|
1138 | + * @throws ReflectionException |
|
1139 | + */ |
|
1140 | + public static function set_total_tax_to( |
|
1141 | + EE_Line_Item $total_line_item, |
|
1142 | + $amount, |
|
1143 | + $name = null, |
|
1144 | + $description = null, |
|
1145 | + $code = null, |
|
1146 | + $add_to_existing_line_item = false |
|
1147 | + ) { |
|
1148 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
1149 | + $taxable_total = $total_line_item->taxable_total(); |
|
1150 | + |
|
1151 | + if ($add_to_existing_line_item) { |
|
1152 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
1153 | + EEM_Line_Item::instance()->delete( |
|
1154 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
1155 | + ); |
|
1156 | + } else { |
|
1157 | + $new_tax = null; |
|
1158 | + $tax_subtotal->delete_children_line_items(); |
|
1159 | + } |
|
1160 | + if ($new_tax) { |
|
1161 | + $new_tax->set_total($new_tax->total() + $amount); |
|
1162 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
1163 | + } else { |
|
1164 | + // no existing tax item. Create it |
|
1165 | + $new_tax = EE_Line_Item::new_instance(array( |
|
1166 | + 'TXN_ID' => $total_line_item->TXN_ID(), |
|
1167 | + 'LIN_name' => $name ? $name : esc_html__('Tax', 'event_espresso'), |
|
1168 | + 'LIN_desc' => $description ? $description : '', |
|
1169 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
1170 | + 'LIN_total' => $amount, |
|
1171 | + 'LIN_parent' => $tax_subtotal->ID(), |
|
1172 | + 'LIN_type' => EEM_Line_Item::type_tax, |
|
1173 | + 'LIN_code' => $code, |
|
1174 | + )); |
|
1175 | + } |
|
1176 | + |
|
1177 | + $new_tax = apply_filters( |
|
1178 | + 'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal', |
|
1179 | + $new_tax, |
|
1180 | + $total_line_item |
|
1181 | + ); |
|
1182 | + $new_tax->save(); |
|
1183 | + $tax_subtotal->set_total($new_tax->total()); |
|
1184 | + $tax_subtotal->save(); |
|
1185 | + $total_line_item->recalculate_total_including_taxes(); |
|
1186 | + return $new_tax; |
|
1187 | + } |
|
1188 | + |
|
1189 | + |
|
1190 | + /** |
|
1191 | + * Makes all the line items which are children of $line_item taxable (or not). |
|
1192 | + * Does NOT save the line items |
|
1193 | + * |
|
1194 | + * @param EE_Line_Item $line_item |
|
1195 | + * @param boolean $taxable |
|
1196 | + * @param string $code_substring_for_whitelist if this string is part of the line item's code |
|
1197 | + * it will be whitelisted (ie, except from becoming taxable) |
|
1198 | + * @throws EE_Error |
|
1199 | + */ |
|
1200 | + public static function set_line_items_taxable( |
|
1201 | + EE_Line_Item $line_item, |
|
1202 | + $taxable = true, |
|
1203 | + $code_substring_for_whitelist = null |
|
1204 | + ) { |
|
1205 | + $whitelisted = false; |
|
1206 | + if ($code_substring_for_whitelist !== null) { |
|
1207 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false; |
|
1208 | + } |
|
1209 | + if (! $whitelisted && $line_item->is_line_item()) { |
|
1210 | + $line_item->set_is_taxable($taxable); |
|
1211 | + } |
|
1212 | + foreach ($line_item->children() as $child_line_item) { |
|
1213 | + EEH_Line_Item::set_line_items_taxable( |
|
1214 | + $child_line_item, |
|
1215 | + $taxable, |
|
1216 | + $code_substring_for_whitelist |
|
1217 | + ); |
|
1218 | + } |
|
1219 | + } |
|
1220 | + |
|
1221 | + |
|
1222 | + /** |
|
1223 | + * Gets all descendants that are event subtotals |
|
1224 | + * |
|
1225 | + * @uses EEH_Line_Item::get_subtotals_of_object_type() |
|
1226 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1227 | + * @return EE_Line_Item[] |
|
1228 | + * @throws EE_Error |
|
1229 | + */ |
|
1230 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) |
|
1231 | + { |
|
1232 | + return self::get_subtotals_of_object_type($parent_line_item, EEM_Line_Item::OBJ_TYPE_EVENT); |
|
1233 | + } |
|
1234 | + |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * Gets all descendants subtotals that match the supplied object type |
|
1238 | + * |
|
1239 | + * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
1240 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1241 | + * @param string $obj_type |
|
1242 | + * @return EE_Line_Item[] |
|
1243 | + * @throws EE_Error |
|
1244 | + */ |
|
1245 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') |
|
1246 | + { |
|
1247 | + return self::_get_descendants_by_type_and_object_type( |
|
1248 | + $parent_line_item, |
|
1249 | + EEM_Line_Item::type_sub_total, |
|
1250 | + $obj_type |
|
1251 | + ); |
|
1252 | + } |
|
1253 | + |
|
1254 | + |
|
1255 | + /** |
|
1256 | + * Gets all descendants that are tickets |
|
1257 | + * |
|
1258 | + * @uses EEH_Line_Item::get_line_items_of_object_type() |
|
1259 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1260 | + * @return EE_Line_Item[] |
|
1261 | + * @throws EE_Error |
|
1262 | + */ |
|
1263 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) |
|
1264 | + { |
|
1265 | + return self::get_line_items_of_object_type( |
|
1266 | + $parent_line_item, |
|
1267 | + EEM_Line_Item::OBJ_TYPE_TICKET |
|
1268 | + ); |
|
1269 | + } |
|
1270 | + |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * Gets all descendants subtotals that match the supplied object type |
|
1274 | + * |
|
1275 | + * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
1276 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1277 | + * @param string $obj_type |
|
1278 | + * @return EE_Line_Item[] |
|
1279 | + * @throws EE_Error |
|
1280 | + */ |
|
1281 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') |
|
1282 | + { |
|
1283 | + return self::_get_descendants_by_type_and_object_type( |
|
1284 | + $parent_line_item, |
|
1285 | + EEM_Line_Item::type_line_item, |
|
1286 | + $obj_type |
|
1287 | + ); |
|
1288 | + } |
|
1289 | + |
|
1290 | + |
|
1291 | + /** |
|
1292 | + * Gets all the descendants (ie, children or children of children etc) that are of the type 'tax' |
|
1293 | + * |
|
1294 | + * @uses EEH_Line_Item::get_descendants_of_type() |
|
1295 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1296 | + * @return EE_Line_Item[] |
|
1297 | + * @throws EE_Error |
|
1298 | + */ |
|
1299 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) |
|
1300 | + { |
|
1301 | + return EEH_Line_Item::get_descendants_of_type( |
|
1302 | + $parent_line_item, |
|
1303 | + EEM_Line_Item::type_tax |
|
1304 | + ); |
|
1305 | + } |
|
1306 | + |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * Gets all the real items purchased which are children of this item |
|
1310 | + * |
|
1311 | + * @uses EEH_Line_Item::get_descendants_of_type() |
|
1312 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1313 | + * @return EE_Line_Item[] |
|
1314 | + * @throws EE_Error |
|
1315 | + */ |
|
1316 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) |
|
1317 | + { |
|
1318 | + return EEH_Line_Item::get_descendants_of_type( |
|
1319 | + $parent_line_item, |
|
1320 | + EEM_Line_Item::type_line_item |
|
1321 | + ); |
|
1322 | + } |
|
1323 | + |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * Gets all descendants of supplied line item that match the supplied line item type |
|
1327 | + * |
|
1328 | + * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
1329 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1330 | + * @param string $line_item_type one of the EEM_Line_Item constants |
|
1331 | + * @return EE_Line_Item[] |
|
1332 | + * @throws EE_Error |
|
1333 | + */ |
|
1334 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) |
|
1335 | + { |
|
1336 | + return self::_get_descendants_by_type_and_object_type( |
|
1337 | + $parent_line_item, |
|
1338 | + $line_item_type, |
|
1339 | + null |
|
1340 | + ); |
|
1341 | + } |
|
1342 | + |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type |
|
1346 | + * as well |
|
1347 | + * |
|
1348 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1349 | + * @param string $line_item_type one of the EEM_Line_Item constants |
|
1350 | + * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when |
|
1351 | + * searching |
|
1352 | + * @return EE_Line_Item[] |
|
1353 | + * @throws EE_Error |
|
1354 | + */ |
|
1355 | + protected static function _get_descendants_by_type_and_object_type( |
|
1356 | + EE_Line_Item $parent_line_item, |
|
1357 | + $line_item_type, |
|
1358 | + $obj_type = null |
|
1359 | + ) { |
|
1360 | + $objects = array(); |
|
1361 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1362 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1363 | + if ( |
|
1364 | + $child_line_item->type() === $line_item_type |
|
1365 | + && ( |
|
1366 | + $child_line_item->OBJ_type() === $obj_type || $obj_type === null |
|
1367 | + ) |
|
1368 | + ) { |
|
1369 | + $objects[] = $child_line_item; |
|
1370 | + } else { |
|
1371 | + // go-through-all-its children looking for more matches |
|
1372 | + $objects = array_merge( |
|
1373 | + $objects, |
|
1374 | + self::_get_descendants_by_type_and_object_type( |
|
1375 | + $child_line_item, |
|
1376 | + $line_item_type, |
|
1377 | + $obj_type |
|
1378 | + ) |
|
1379 | + ); |
|
1380 | + } |
|
1381 | + } |
|
1382 | + } |
|
1383 | + return $objects; |
|
1384 | + } |
|
1385 | + |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * Gets all descendants subtotals that match the supplied object type |
|
1389 | + * |
|
1390 | + * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
|
1391 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1392 | + * @param string $OBJ_type object type (like Event) |
|
1393 | + * @param array $OBJ_IDs array of OBJ_IDs |
|
1394 | + * @return EE_Line_Item[] |
|
1395 | + * @throws EE_Error |
|
1396 | + */ |
|
1397 | + public static function get_line_items_by_object_type_and_IDs( |
|
1398 | + EE_Line_Item $parent_line_item, |
|
1399 | + $OBJ_type = '', |
|
1400 | + $OBJ_IDs = array() |
|
1401 | + ) { |
|
1402 | + return self::_get_descendants_by_object_type_and_object_ID( |
|
1403 | + $parent_line_item, |
|
1404 | + $OBJ_type, |
|
1405 | + $OBJ_IDs |
|
1406 | + ); |
|
1407 | + } |
|
1408 | + |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type |
|
1412 | + * as well |
|
1413 | + * |
|
1414 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1415 | + * @param string $OBJ_type object type (like Event) |
|
1416 | + * @param array $OBJ_IDs array of OBJ_IDs |
|
1417 | + * @return EE_Line_Item[] |
|
1418 | + * @throws EE_Error |
|
1419 | + */ |
|
1420 | + protected static function _get_descendants_by_object_type_and_object_ID( |
|
1421 | + EE_Line_Item $parent_line_item, |
|
1422 | + $OBJ_type, |
|
1423 | + $OBJ_IDs |
|
1424 | + ) { |
|
1425 | + $objects = array(); |
|
1426 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1427 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1428 | + if ( |
|
1429 | + $child_line_item->OBJ_type() === $OBJ_type |
|
1430 | + && is_array($OBJ_IDs) |
|
1431 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1432 | + ) { |
|
1433 | + $objects[] = $child_line_item; |
|
1434 | + } else { |
|
1435 | + // go-through-all-its children looking for more matches |
|
1436 | + $objects = array_merge( |
|
1437 | + $objects, |
|
1438 | + self::_get_descendants_by_object_type_and_object_ID( |
|
1439 | + $child_line_item, |
|
1440 | + $OBJ_type, |
|
1441 | + $OBJ_IDs |
|
1442 | + ) |
|
1443 | + ); |
|
1444 | + } |
|
1445 | + } |
|
1446 | + } |
|
1447 | + return $objects; |
|
1448 | + } |
|
1449 | + |
|
1450 | + |
|
1451 | + /** |
|
1452 | + * Uses a breadth-first-search in order to find the nearest descendant of |
|
1453 | + * the specified type and returns it, else NULL |
|
1454 | + * |
|
1455 | + * @uses EEH_Line_Item::_get_nearest_descendant() |
|
1456 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1457 | + * @param string $type like one of the EEM_Line_Item::type_* |
|
1458 | + * @return EE_Line_Item |
|
1459 | + * @throws EE_Error |
|
1460 | + * @throws InvalidArgumentException |
|
1461 | + * @throws InvalidDataTypeException |
|
1462 | + * @throws InvalidInterfaceException |
|
1463 | + * @throws ReflectionException |
|
1464 | + */ |
|
1465 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) |
|
1466 | + { |
|
1467 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1468 | + } |
|
1469 | + |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Uses a breadth-first-search in order to find the nearest descendant |
|
1473 | + * having the specified LIN_code and returns it, else NULL |
|
1474 | + * |
|
1475 | + * @uses EEH_Line_Item::_get_nearest_descendant() |
|
1476 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1477 | + * @param string $code any value used for LIN_code |
|
1478 | + * @return EE_Line_Item |
|
1479 | + * @throws EE_Error |
|
1480 | + * @throws InvalidArgumentException |
|
1481 | + * @throws InvalidDataTypeException |
|
1482 | + * @throws InvalidInterfaceException |
|
1483 | + * @throws ReflectionException |
|
1484 | + */ |
|
1485 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) |
|
1486 | + { |
|
1487 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1488 | + } |
|
1489 | + |
|
1490 | + |
|
1491 | + /** |
|
1492 | + * Uses a breadth-first-search in order to find the nearest descendant |
|
1493 | + * having the specified LIN_code and returns it, else NULL |
|
1494 | + * |
|
1495 | + * @param EE_Line_Item $parent_line_item - the line item to find descendants of |
|
1496 | + * @param string $search_field name of EE_Line_Item property |
|
1497 | + * @param string $value any value stored in $search_field |
|
1498 | + * @return EE_Line_Item |
|
1499 | + * @throws EE_Error |
|
1500 | + * @throws InvalidArgumentException |
|
1501 | + * @throws InvalidDataTypeException |
|
1502 | + * @throws InvalidInterfaceException |
|
1503 | + * @throws ReflectionException |
|
1504 | + */ |
|
1505 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) |
|
1506 | + { |
|
1507 | + foreach ($parent_line_item->children() as $child) { |
|
1508 | + if ($child->get($search_field) == $value) { |
|
1509 | + return $child; |
|
1510 | + } |
|
1511 | + } |
|
1512 | + foreach ($parent_line_item->children() as $child) { |
|
1513 | + $descendant_found = self::_get_nearest_descendant( |
|
1514 | + $child, |
|
1515 | + $search_field, |
|
1516 | + $value |
|
1517 | + ); |
|
1518 | + if ($descendant_found) { |
|
1519 | + return $descendant_found; |
|
1520 | + } |
|
1521 | + } |
|
1522 | + return null; |
|
1523 | + } |
|
1524 | + |
|
1525 | + |
|
1526 | + /** |
|
1527 | + * if passed line item has a TXN ID, uses that to jump directly to the grand total line item for the transaction, |
|
1528 | + * else recursively walks up the line item tree until a parent of type total is found, |
|
1529 | + * |
|
1530 | + * @param EE_Line_Item $line_item |
|
1531 | + * @return EE_Line_Item |
|
1532 | + * @throws EE_Error |
|
1533 | + */ |
|
1534 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) |
|
1535 | + { |
|
1536 | + if ($line_item->TXN_ID()) { |
|
1537 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
1538 | + if ($total_line_item instanceof EE_Line_Item) { |
|
1539 | + return $total_line_item; |
|
1540 | + } |
|
1541 | + } else { |
|
1542 | + $line_item_parent = $line_item->parent(); |
|
1543 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
1544 | + if ($line_item_parent->is_total()) { |
|
1545 | + return $line_item_parent; |
|
1546 | + } |
|
1547 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
1548 | + } |
|
1549 | + } |
|
1550 | + throw new EE_Error( |
|
1551 | + sprintf( |
|
1552 | + esc_html__( |
|
1553 | + 'A valid grand total for line item %1$d was not found.', |
|
1554 | + 'event_espresso' |
|
1555 | + ), |
|
1556 | + $line_item->ID() |
|
1557 | + ) |
|
1558 | + ); |
|
1559 | + } |
|
1560 | + |
|
1561 | + |
|
1562 | + /** |
|
1563 | + * Prints out a representation of the line item tree |
|
1564 | + * |
|
1565 | + * @param EE_Line_Item $line_item |
|
1566 | + * @param int $indentation |
|
1567 | + * @return void |
|
1568 | + * @throws EE_Error |
|
1569 | + */ |
|
1570 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) |
|
1571 | + { |
|
1572 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1573 | + if (! $indentation) { |
|
1574 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1575 | + } |
|
1576 | + for ($i = 0; $i < $indentation; $i++) { |
|
1577 | + echo '. '; |
|
1578 | + } |
|
1579 | + $breakdown = ''; |
|
1580 | + if ($line_item->is_line_item()) { |
|
1581 | + if ($line_item->is_percent()) { |
|
1582 | + $breakdown = "{$line_item->percent()}%"; |
|
1583 | + } else { |
|
1584 | + $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1585 | + } |
|
1586 | + } |
|
1587 | + echo $line_item->name(); |
|
1588 | + echo " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : "; |
|
1589 | + echo '$' . (string) $line_item->total(); |
|
1590 | + if ($breakdown) { |
|
1591 | + echo " ( {$breakdown} )"; |
|
1592 | + } |
|
1593 | + if ($line_item->is_taxable()) { |
|
1594 | + echo ' * taxable'; |
|
1595 | + } |
|
1596 | + if ($line_item->children()) { |
|
1597 | + foreach ($line_item->children() as $child) { |
|
1598 | + self::visualize($child, $indentation + 1); |
|
1599 | + } |
|
1600 | + } |
|
1601 | + } |
|
1602 | + |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * Calculates the registration's final price, taking into account that they |
|
1606 | + * need to not only help pay for their OWN ticket, but also any transaction-wide surcharges and taxes, |
|
1607 | + * and receive a portion of any transaction-wide discounts. |
|
1608 | + * eg1, if I buy a $1 ticket and brent buys a $9 ticket, and we receive a $5 discount |
|
1609 | + * then I'll get 1/10 of that $5 discount, which is $0.50, and brent will get |
|
1610 | + * 9/10ths of that $5 discount, which is $4.50. So my final price should be $0.50 |
|
1611 | + * and brent's final price should be $5.50. |
|
1612 | + * In order to do this, we basically need to traverse the line item tree calculating |
|
1613 | + * the running totals (just as if we were recalculating the total), but when we identify |
|
1614 | + * regular line items, we need to keep track of their share of the grand total. |
|
1615 | + * Also, we need to keep track of the TAXABLE total for each ticket purchase, so |
|
1616 | + * we can know how to apply taxes to it. (Note: "taxable total" does not equal the "pretax total" |
|
1617 | + * when there are non-taxable items; otherwise they would be the same) |
|
1618 | + * |
|
1619 | + * @param EE_Line_Item $line_item |
|
1620 | + * @param array $billable_ticket_quantities array of EE_Ticket IDs and their corresponding quantity that |
|
1621 | + * can be included in price calculations at this moment |
|
1622 | + * @return array keys are line items for tickets IDs and values are their share of the running total, |
|
1623 | + * plus the key 'total', and 'taxable' which also has keys of all |
|
1624 | + * the ticket IDs. |
|
1625 | + * Eg array( |
|
1626 | + * 12 => 4.3 |
|
1627 | + * 23 => 8.0 |
|
1628 | + * 'total' => 16.6, |
|
1629 | + * 'taxable' => array( |
|
1630 | + * 12 => 10, |
|
1631 | + * 23 => 4 |
|
1632 | + * ). |
|
1633 | + * So to find which registrations have which final price, we need |
|
1634 | + * to find which line item is theirs, which can be done with |
|
1635 | + * `EEM_Line_Item::instance()->get_line_item_for_registration( |
|
1636 | + * $registration );` |
|
1637 | + * @throws EE_Error |
|
1638 | + * @throws InvalidArgumentException |
|
1639 | + * @throws InvalidDataTypeException |
|
1640 | + * @throws InvalidInterfaceException |
|
1641 | + * @throws ReflectionException |
|
1642 | + */ |
|
1643 | + public static function calculate_reg_final_prices_per_line_item( |
|
1644 | + EE_Line_Item $line_item, |
|
1645 | + $billable_ticket_quantities = array() |
|
1646 | + ) { |
|
1647 | + $running_totals = [ |
|
1648 | + 'total' => 0, |
|
1649 | + 'taxable' => ['total' => 0] |
|
1650 | + ]; |
|
1651 | + foreach ($line_item->children() as $child_line_item) { |
|
1652 | + switch ($child_line_item->type()) { |
|
1653 | + case EEM_Line_Item::type_sub_total: |
|
1654 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
1655 | + $child_line_item, |
|
1656 | + $billable_ticket_quantities |
|
1657 | + ); |
|
1658 | + // combine arrays but preserve numeric keys |
|
1659 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1660 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1661 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1662 | + break; |
|
1663 | + |
|
1664 | + case EEM_Line_Item::type_tax_sub_total: |
|
1665 | + // find how much the taxes percentage is |
|
1666 | + if ($child_line_item->percent() !== 0) { |
|
1667 | + $tax_percent_decimal = $child_line_item->percent() / 100; |
|
1668 | + } else { |
|
1669 | + $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
|
1670 | + } |
|
1671 | + // and apply to all the taxable totals, and add to the pretax totals |
|
1672 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1673 | + // "total" and "taxable" array key is an exception |
|
1674 | + if ($line_item_id === 'taxable') { |
|
1675 | + continue; |
|
1676 | + } |
|
1677 | + $taxable_total = $running_totals['taxable'][ $line_item_id ]; |
|
1678 | + $running_totals[ $line_item_id ] += ($taxable_total * $tax_percent_decimal); |
|
1679 | + } |
|
1680 | + break; |
|
1681 | + |
|
1682 | + case EEM_Line_Item::type_line_item: |
|
1683 | + // ticket line items or ???? |
|
1684 | + if ($child_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
1685 | + // kk it's a ticket |
|
1686 | + if (isset($running_totals[ $child_line_item->ID() ])) { |
|
1687 | + // huh? that shouldn't happen. |
|
1688 | + $running_totals['total'] += $child_line_item->total(); |
|
1689 | + } else { |
|
1690 | + // its not in our running totals yet. great. |
|
1691 | + if ($child_line_item->is_taxable()) { |
|
1692 | + $taxable_amount = $child_line_item->unit_price(); |
|
1693 | + } else { |
|
1694 | + $taxable_amount = 0; |
|
1695 | + } |
|
1696 | + // are we only calculating totals for some tickets? |
|
1697 | + if (isset($billable_ticket_quantities[ $child_line_item->OBJ_ID() ])) { |
|
1698 | + $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1699 | + $running_totals[ $child_line_item->ID() ] = $quantity |
|
1700 | + ? $child_line_item->unit_price() |
|
1701 | + : 0; |
|
1702 | + $running_totals['taxable'][ $child_line_item->ID() ] = $quantity |
|
1703 | + ? $taxable_amount |
|
1704 | + : 0; |
|
1705 | + } else { |
|
1706 | + $quantity = $child_line_item->quantity(); |
|
1707 | + $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1708 | + $running_totals['taxable'][ $child_line_item->ID() ] = $taxable_amount; |
|
1709 | + } |
|
1710 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1711 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1712 | + } |
|
1713 | + } else { |
|
1714 | + // it's some other type of item added to the cart |
|
1715 | + // it should affect the running totals |
|
1716 | + // basically we want to convert it into a PERCENT modifier. Because |
|
1717 | + // more clearly affect all registration's final price equally |
|
1718 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1719 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1720 | + : 1; |
|
1721 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1722 | + // the "taxable" array key is an exception |
|
1723 | + if ($line_item_id === 'taxable') { |
|
1724 | + continue; |
|
1725 | + } |
|
1726 | + // update the running totals |
|
1727 | + // yes this actually even works for the running grand total! |
|
1728 | + $running_totals[ $line_item_id ] = |
|
1729 | + $line_items_percent_of_running_total * $this_running_total; |
|
1730 | + |
|
1731 | + if ($child_line_item->is_taxable()) { |
|
1732 | + $running_totals['taxable'][ $line_item_id ] = |
|
1733 | + $line_items_percent_of_running_total * $running_totals['taxable'][ $line_item_id ]; |
|
1734 | + } |
|
1735 | + } |
|
1736 | + } |
|
1737 | + break; |
|
1738 | + } |
|
1739 | + } |
|
1740 | + return $running_totals; |
|
1741 | + } |
|
1742 | + |
|
1743 | + |
|
1744 | + /** |
|
1745 | + * @param EE_Line_Item $total_line_item |
|
1746 | + * @param EE_Line_Item $ticket_line_item |
|
1747 | + * @return float | null |
|
1748 | + * @throws EE_Error |
|
1749 | + * @throws InvalidArgumentException |
|
1750 | + * @throws InvalidDataTypeException |
|
1751 | + * @throws InvalidInterfaceException |
|
1752 | + * @throws OutOfRangeException |
|
1753 | + * @throws ReflectionException |
|
1754 | + */ |
|
1755 | + public static function calculate_final_price_for_ticket_line_item( |
|
1756 | + EE_Line_Item $total_line_item, |
|
1757 | + EE_Line_Item $ticket_line_item |
|
1758 | + ) { |
|
1759 | + static $final_prices_per_ticket_line_item = array(); |
|
1760 | + if (empty($final_prices_per_ticket_line_item) || empty($final_prices_per_ticket_line_item[ $total_line_item->ID() ])) { |
|
1761 | + $final_prices_per_ticket_line_item[ $total_line_item->ID() ] = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
1762 | + $total_line_item |
|
1763 | + ); |
|
1764 | + } |
|
1765 | + // ok now find this new registration's final price |
|
1766 | + if (isset($final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ])) { |
|
1767 | + return $final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ]; |
|
1768 | + } |
|
1769 | + $message = sprintf( |
|
1770 | + esc_html__( |
|
1771 | + 'The final price for the ticket line item (ID:%1$d) could not be calculated.', |
|
1772 | + 'event_espresso' |
|
1773 | + ), |
|
1774 | + $ticket_line_item->ID() |
|
1775 | + ); |
|
1776 | + if (WP_DEBUG) { |
|
1777 | + $message .= '<br>' . print_r($final_prices_per_ticket_line_item, true); |
|
1778 | + throw new OutOfRangeException($message); |
|
1779 | + } |
|
1780 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1781 | + return null; |
|
1782 | + } |
|
1783 | + |
|
1784 | + |
|
1785 | + /** |
|
1786 | + * Creates a duplicate of the line item tree, except only includes billable items |
|
1787 | + * and the portion of line items attributed to billable things |
|
1788 | + * |
|
1789 | + * @param EE_Line_Item $line_item |
|
1790 | + * @param EE_Registration[] $registrations |
|
1791 | + * @return EE_Line_Item |
|
1792 | + * @throws EE_Error |
|
1793 | + * @throws InvalidArgumentException |
|
1794 | + * @throws InvalidDataTypeException |
|
1795 | + * @throws InvalidInterfaceException |
|
1796 | + * @throws ReflectionException |
|
1797 | + */ |
|
1798 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) |
|
1799 | + { |
|
1800 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1801 | + foreach ($line_item->children() as $child_li) { |
|
1802 | + $copy_li->add_child_line_item( |
|
1803 | + EEH_Line_Item::billable_line_item_tree($child_li, $registrations) |
|
1804 | + ); |
|
1805 | + } |
|
1806 | + // if this is the grand total line item, make sure the totals all add up |
|
1807 | + // (we could have duplicated this logic AS we copied the line items, but |
|
1808 | + // it seems DRYer this way) |
|
1809 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1810 | + $copy_li->recalculate_total_including_taxes(); |
|
1811 | + } |
|
1812 | + return $copy_li; |
|
1813 | + } |
|
1814 | + |
|
1815 | + |
|
1816 | + /** |
|
1817 | + * Creates a new, unsaved line item from $line_item that factors in the |
|
1818 | + * number of billable registrations on $registrations. |
|
1819 | + * |
|
1820 | + * @param EE_Line_Item $line_item |
|
1821 | + * @param EE_Registration[] $registrations |
|
1822 | + * @return EE_Line_Item |
|
1823 | + * @throws EE_Error |
|
1824 | + * @throws InvalidArgumentException |
|
1825 | + * @throws InvalidDataTypeException |
|
1826 | + * @throws InvalidInterfaceException |
|
1827 | + * @throws ReflectionException |
|
1828 | + */ |
|
1829 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) |
|
1830 | + { |
|
1831 | + $new_li_fields = $line_item->model_field_array(); |
|
1832 | + if ( |
|
1833 | + $line_item->type() === EEM_Line_Item::type_line_item && |
|
1834 | + $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
1835 | + ) { |
|
1836 | + $count = 0; |
|
1837 | + foreach ($registrations as $registration) { |
|
1838 | + if ( |
|
1839 | + $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1840 | + in_array( |
|
1841 | + $registration->status_ID(), |
|
1842 | + EEM_Registration::reg_statuses_that_allow_payment(), |
|
1843 | + true |
|
1844 | + ) |
|
1845 | + ) { |
|
1846 | + $count++; |
|
1847 | + } |
|
1848 | + } |
|
1849 | + $new_li_fields['LIN_quantity'] = $count; |
|
1850 | + } |
|
1851 | + // don't set the total. We'll leave that up to the code that calculates it |
|
1852 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1853 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1854 | + } |
|
1855 | + |
|
1856 | + |
|
1857 | + /** |
|
1858 | + * Returns a modified line item tree where all the subtotals which have a total of 0 |
|
1859 | + * are removed, and line items with a quantity of 0 |
|
1860 | + * |
|
1861 | + * @param EE_Line_Item $line_item |null |
|
1862 | + * @return EE_Line_Item|null |
|
1863 | + * @throws EE_Error |
|
1864 | + * @throws InvalidArgumentException |
|
1865 | + * @throws InvalidDataTypeException |
|
1866 | + * @throws InvalidInterfaceException |
|
1867 | + * @throws ReflectionException |
|
1868 | + */ |
|
1869 | + public static function non_empty_line_items(EE_Line_Item $line_item) |
|
1870 | + { |
|
1871 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1872 | + if ($copied_li === null) { |
|
1873 | + return null; |
|
1874 | + } |
|
1875 | + // if this is an event subtotal, we want to only include it if it |
|
1876 | + // has a non-zero total and at least one ticket line item child |
|
1877 | + $ticket_children = 0; |
|
1878 | + foreach ($line_item->children() as $child_li) { |
|
1879 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1880 | + if ($child_li_copy !== null) { |
|
1881 | + $copied_li->add_child_line_item($child_li_copy); |
|
1882 | + if ( |
|
1883 | + $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1884 | + $child_li_copy->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
1885 | + ) { |
|
1886 | + $ticket_children++; |
|
1887 | + } |
|
1888 | + } |
|
1889 | + } |
|
1890 | + // if this is an event subtotal with NO ticket children |
|
1891 | + // we basically want to ignore it |
|
1892 | + if ( |
|
1893 | + $ticket_children === 0 |
|
1894 | + && $line_item->type() === EEM_Line_Item::type_sub_total |
|
1895 | + && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT |
|
1896 | + && $line_item->total() === 0 |
|
1897 | + ) { |
|
1898 | + return null; |
|
1899 | + } |
|
1900 | + return $copied_li; |
|
1901 | + } |
|
1902 | + |
|
1903 | + |
|
1904 | + /** |
|
1905 | + * Creates a new, unsaved line item, but if it's a ticket line item |
|
1906 | + * with a total of 0, or a subtotal of 0, returns null instead |
|
1907 | + * |
|
1908 | + * @param EE_Line_Item $line_item |
|
1909 | + * @return EE_Line_Item |
|
1910 | + * @throws EE_Error |
|
1911 | + * @throws InvalidArgumentException |
|
1912 | + * @throws InvalidDataTypeException |
|
1913 | + * @throws InvalidInterfaceException |
|
1914 | + * @throws ReflectionException |
|
1915 | + */ |
|
1916 | + public static function non_empty_line_item(EE_Line_Item $line_item) |
|
1917 | + { |
|
1918 | + if ( |
|
1919 | + $line_item->type() === EEM_Line_Item::type_line_item |
|
1920 | + && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
1921 | + && $line_item->quantity() === 0 |
|
1922 | + ) { |
|
1923 | + return null; |
|
1924 | + } |
|
1925 | + $new_li_fields = $line_item->model_field_array(); |
|
1926 | + // don't set the total. We'll leave that up to the code that calculates it |
|
1927 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1928 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1929 | + } |
|
1930 | + |
|
1931 | + |
|
1932 | + /** |
|
1933 | + * Cycles through all of the ticket line items for the supplied total line item |
|
1934 | + * and ensures that the line item's "is_taxable" field matches that of its corresponding ticket |
|
1935 | + * |
|
1936 | + * @param EE_Line_Item $total_line_item |
|
1937 | + * @since 4.9.79.p |
|
1938 | + * @throws EE_Error |
|
1939 | + * @throws InvalidArgumentException |
|
1940 | + * @throws InvalidDataTypeException |
|
1941 | + * @throws InvalidInterfaceException |
|
1942 | + * @throws ReflectionException |
|
1943 | + */ |
|
1944 | + public static function resetIsTaxableForTickets(EE_Line_Item $total_line_item) |
|
1945 | + { |
|
1946 | + $ticket_line_items = self::get_ticket_line_items($total_line_item); |
|
1947 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
1948 | + if ( |
|
1949 | + $ticket_line_item instanceof EE_Line_Item |
|
1950 | + && $ticket_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET |
|
1951 | + ) { |
|
1952 | + $ticket = $ticket_line_item->ticket(); |
|
1953 | + if ($ticket instanceof EE_Ticket && $ticket->taxable() !== $ticket_line_item->is_taxable()) { |
|
1954 | + $ticket_line_item->set_is_taxable($ticket->taxable()); |
|
1955 | + $ticket_line_item->save(); |
|
1956 | + } |
|
1957 | + } |
|
1958 | + } |
|
1959 | + } |
|
1960 | + |
|
1961 | + |
|
1962 | + |
|
1963 | + /**************************************** @DEPRECATED METHODS *************************************** */ |
|
1964 | + /** |
|
1965 | + * @deprecated |
|
1966 | + * @param EE_Line_Item $total_line_item |
|
1967 | + * @return EE_Line_Item |
|
1968 | + * @throws EE_Error |
|
1969 | + * @throws InvalidArgumentException |
|
1970 | + * @throws InvalidDataTypeException |
|
1971 | + * @throws InvalidInterfaceException |
|
1972 | + * @throws ReflectionException |
|
1973 | + */ |
|
1974 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) |
|
1975 | + { |
|
1976 | + EE_Error::doing_it_wrong( |
|
1977 | + 'EEH_Line_Item::get_items_subtotal()', |
|
1978 | + sprintf( |
|
1979 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1980 | + 'EEH_Line_Item::get_pre_tax_subtotal()' |
|
1981 | + ), |
|
1982 | + '4.6.0' |
|
1983 | + ); |
|
1984 | + return self::get_pre_tax_subtotal($total_line_item); |
|
1985 | + } |
|
1986 | + |
|
1987 | + |
|
1988 | + /** |
|
1989 | + * @deprecated |
|
1990 | + * @param EE_Transaction $transaction |
|
1991 | + * @return EE_Line_Item |
|
1992 | + * @throws EE_Error |
|
1993 | + * @throws InvalidArgumentException |
|
1994 | + * @throws InvalidDataTypeException |
|
1995 | + * @throws InvalidInterfaceException |
|
1996 | + * @throws ReflectionException |
|
1997 | + */ |
|
1998 | + public static function create_default_total_line_item($transaction = null) |
|
1999 | + { |
|
2000 | + EE_Error::doing_it_wrong( |
|
2001 | + 'EEH_Line_Item::create_default_total_line_item()', |
|
2002 | + sprintf( |
|
2003 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
2004 | + 'EEH_Line_Item::create_total_line_item()' |
|
2005 | + ), |
|
2006 | + '4.6.0' |
|
2007 | + ); |
|
2008 | + return self::create_total_line_item($transaction); |
|
2009 | + } |
|
2010 | + |
|
2011 | + |
|
2012 | + /** |
|
2013 | + * @deprecated |
|
2014 | + * @param EE_Line_Item $total_line_item |
|
2015 | + * @param EE_Transaction $transaction |
|
2016 | + * @return EE_Line_Item |
|
2017 | + * @throws EE_Error |
|
2018 | + * @throws InvalidArgumentException |
|
2019 | + * @throws InvalidDataTypeException |
|
2020 | + * @throws InvalidInterfaceException |
|
2021 | + * @throws ReflectionException |
|
2022 | + */ |
|
2023 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
2024 | + { |
|
2025 | + EE_Error::doing_it_wrong( |
|
2026 | + 'EEH_Line_Item::create_default_tickets_subtotal()', |
|
2027 | + sprintf( |
|
2028 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
2029 | + 'EEH_Line_Item::create_pre_tax_subtotal()' |
|
2030 | + ), |
|
2031 | + '4.6.0' |
|
2032 | + ); |
|
2033 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
2034 | + } |
|
2035 | + |
|
2036 | + |
|
2037 | + /** |
|
2038 | + * @deprecated |
|
2039 | + * @param EE_Line_Item $total_line_item |
|
2040 | + * @param EE_Transaction $transaction |
|
2041 | + * @return EE_Line_Item |
|
2042 | + * @throws EE_Error |
|
2043 | + * @throws InvalidArgumentException |
|
2044 | + * @throws InvalidDataTypeException |
|
2045 | + * @throws InvalidInterfaceException |
|
2046 | + * @throws ReflectionException |
|
2047 | + */ |
|
2048 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
2049 | + { |
|
2050 | + EE_Error::doing_it_wrong( |
|
2051 | + 'EEH_Line_Item::create_default_taxes_subtotal()', |
|
2052 | + sprintf( |
|
2053 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
2054 | + 'EEH_Line_Item::create_taxes_subtotal()' |
|
2055 | + ), |
|
2056 | + '4.6.0' |
|
2057 | + ); |
|
2058 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
2059 | + } |
|
2060 | + |
|
2061 | + |
|
2062 | + /** |
|
2063 | + * @deprecated |
|
2064 | + * @param EE_Line_Item $total_line_item |
|
2065 | + * @param EE_Transaction $transaction |
|
2066 | + * @return EE_Line_Item |
|
2067 | + * @throws EE_Error |
|
2068 | + * @throws InvalidArgumentException |
|
2069 | + * @throws InvalidDataTypeException |
|
2070 | + * @throws InvalidInterfaceException |
|
2071 | + * @throws ReflectionException |
|
2072 | + */ |
|
2073 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = null) |
|
2074 | + { |
|
2075 | + EE_Error::doing_it_wrong( |
|
2076 | + 'EEH_Line_Item::create_default_event_subtotal()', |
|
2077 | + sprintf( |
|
2078 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
2079 | + 'EEH_Line_Item::create_event_subtotal()' |
|
2080 | + ), |
|
2081 | + '4.6.0' |
|
2082 | + ); |
|
2083 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
2084 | + } |
|
2085 | 2085 | } |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | <?php if (!is_admin()) : ?> |
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | - 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | - sprintf( |
|
11 | - __( |
|
12 | - 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | - 'event_espresso' |
|
14 | - ), |
|
15 | - '<br />', |
|
16 | - '<span class="asterisk">*</span>' |
|
17 | - ) |
|
18 | - ); ?> |
|
9 | + 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | + sprintf( |
|
11 | + __( |
|
12 | + 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | + 'event_espresso' |
|
14 | + ), |
|
15 | + '<br />', |
|
16 | + '<span class="asterisk">*</span>' |
|
17 | + ) |
|
18 | + ); ?> |
|
19 | 19 | </p> |
20 | 20 | <?php endif; ?> |
21 | 21 | |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | $prev_ticket = 0; |
26 | 26 | |
27 | 27 | if (count($registrations) > 0) { |
28 | - foreach ($registrations as $registration) { |
|
29 | - if ($registration instanceof EE_Registration) { |
|
30 | - $att_nmbr++; |
|
31 | - ?> |
|
28 | + foreach ($registrations as $registration) { |
|
29 | + if ($registration instanceof EE_Registration) { |
|
30 | + $att_nmbr++; |
|
31 | + ?> |
|
32 | 32 | |
33 | 33 | <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>" |
34 | 34 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>"> |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | <th scope="col" width="" class="jst-left"></th> |
48 | 48 | <th scope="col" width="7.5%" class="jst-rght"> |
49 | 49 | <?php _e( |
50 | - 'Qty', |
|
51 | - 'event_espresso' |
|
52 | - ); ?></th> |
|
50 | + 'Qty', |
|
51 | + 'event_espresso' |
|
52 | + ); ?></th> |
|
53 | 53 | <th scope="col" width="17.5%" class="jst-rght"> |
54 | 54 | <?php _e( |
55 | - 'Price', |
|
56 | - 'event_espresso' |
|
57 | - ); ?></th> |
|
55 | + 'Price', |
|
56 | + 'event_espresso' |
|
57 | + ); ?></th> |
|
58 | 58 | <th scope="col" width="17.5%" class="jst-rght"> |
59 | 59 | <?php _e( |
60 | - 'Total', |
|
61 | - 'event_espresso' |
|
62 | - ); ?></th> |
|
60 | + 'Total', |
|
61 | + 'event_espresso' |
|
62 | + ); ?></th> |
|
63 | 63 | </tr> |
64 | 64 | </thead> |
65 | 65 | <tbody> |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | <?php } ?> |
72 | 72 | |
73 | 73 | <?php |
74 | - // ATTENDEE QUESTIONS |
|
75 | - $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
76 | - echo ${$reg_form}; |
|
77 | - ?> |
|
74 | + // ATTENDEE QUESTIONS |
|
75 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
76 | + echo ${$reg_form}; |
|
77 | + ?> |
|
78 | 78 | |
79 | 79 | </div> |
80 | 80 | <?php |
81 | - $prev_event = $registration->event()->ID(); |
|
82 | - $prev_ticket = $registration->ticket()->ID(); |
|
83 | - } // if ( $registration instanceof EE_Registration ) |
|
84 | - } // end foreach ( $registrations as $registration ) |
|
81 | + $prev_event = $registration->event()->ID(); |
|
82 | + $prev_ticket = $registration->ticket()->ID(); |
|
83 | + } // if ( $registration instanceof EE_Registration ) |
|
84 | + } // end foreach ( $registrations as $registration ) |
|
85 | 85 | |
86 | - echo $default_hidden_inputs; |
|
86 | + echo $default_hidden_inputs; |
|
87 | 87 | } // end if ( count( $registrations ) > 0 ) |
88 | 88 | |
89 | 89 | ?> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | /** @var array $ticket_line_item */ |
4 | 4 | /** @var string $default_hidden_inputs */ |
5 | 5 | ?> |
6 | -<?php if (!is_admin()) : ?> |
|
6 | +<?php if ( ! is_admin()) : ?> |
|
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | 9 | 'FHEE__registration_page_attendee_information__attendee_information_pg', |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>" |
34 | 34 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>"> |
35 | 35 | |
36 | - <?php if (!is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
|
36 | + <?php if ( ! is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
|
37 | 37 | <h4 id="event_title-<?php echo $registration->event()->ID() ?>" class="big-event-title-hdr"> |
38 | 38 | <?php echo $registration->event()->name(); ?> |
39 | 39 | </h4> |
40 | 40 | <?php } ?> |
41 | 41 | <?php if ($registration->ticket()->ID() !== $prev_ticket) { ?> |
42 | - <?php if (! $revisit) { ?> |
|
42 | + <?php if ( ! $revisit) { ?> |
|
43 | 43 | <div class="spco-ticket-info-dv"> |
44 | 44 | <table class="spco-ticket-details"> |
45 | 45 | <thead> |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | </tr> |
64 | 64 | </thead> |
65 | 65 | <tbody> |
66 | - <?php echo $ticket_line_item[ $registration->ticket()->ID() ]; ?> |
|
66 | + <?php echo $ticket_line_item[$registration->ticket()->ID()]; ?> |
|
67 | 67 | </tbody> |
68 | 68 | </table> |
69 | 69 | </div> |