@@ -16,612 +16,612 @@ |
||
16 | 16 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * array of events |
|
21 | - * |
|
22 | - * @type EE_Line_Item[] $_events |
|
23 | - */ |
|
24 | - private $_events = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * whether to display the taxes row or not |
|
28 | - * |
|
29 | - * @type bool $_show_taxes |
|
30 | - */ |
|
31 | - private $_show_taxes = false; |
|
32 | - |
|
33 | - /** |
|
34 | - * html for any tax rows |
|
35 | - * |
|
36 | - * @type string $_show_taxes |
|
37 | - */ |
|
38 | - private $_taxes_html = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * total amount including tax we can bill for at this time |
|
42 | - * |
|
43 | - * @type float $_grand_total |
|
44 | - */ |
|
45 | - private $_grand_total = 0.00; |
|
46 | - |
|
47 | - /** |
|
48 | - * total number of items being billed for |
|
49 | - * |
|
50 | - * @type int $_total_items |
|
51 | - */ |
|
52 | - private $_total_items = 0; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return float |
|
58 | - */ |
|
59 | - public function grand_total() |
|
60 | - { |
|
61 | - return $this->_grand_total; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public function total_items() |
|
70 | - { |
|
71 | - return $this->_total_items; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param EE_Line_Item $line_item |
|
78 | - * @param array $options |
|
79 | - * @param EE_Line_Item $parent_line_item |
|
80 | - * @return mixed |
|
81 | - * @throws EE_Error |
|
82 | - */ |
|
83 | - public function display_line_item( |
|
84 | - EE_Line_Item $line_item, |
|
85 | - $options = array(), |
|
86 | - EE_Line_Item $parent_line_item = null |
|
87 | - ) { |
|
88 | - $html = ''; |
|
89 | - // set some default options and merge with incoming |
|
90 | - $default_options = array( |
|
91 | - 'show_desc' => true, // true false |
|
92 | - 'odd' => false, |
|
93 | - ); |
|
94 | - $options = array_merge($default_options, (array)$options); |
|
95 | - switch ($line_item->type()) { |
|
96 | - case EEM_Line_Item::type_line_item: |
|
97 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
98 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
99 | - // item row |
|
100 | - $html .= $this->_ticket_row($line_item, $options); |
|
101 | - } else { |
|
102 | - // item row |
|
103 | - $html .= $this->_item_row($line_item, $options); |
|
104 | - } |
|
105 | - if ( |
|
106 | - apply_filters( |
|
107 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
108 | - true |
|
109 | - ) |
|
110 | - ) { |
|
111 | - // got any kids? |
|
112 | - foreach ($line_item->children() as $child_line_item) { |
|
113 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
114 | - } |
|
115 | - } |
|
116 | - break; |
|
117 | - case EEM_Line_Item::type_sub_line_item: |
|
118 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
119 | - break; |
|
120 | - case EEM_Line_Item::type_sub_total: |
|
121 | - static $sub_total = 0; |
|
122 | - $event_sub_total = 0; |
|
123 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
124 | - if ($line_item->OBJ_type() === 'Event') { |
|
125 | - $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
126 | - if (! isset($this->_events[$options['event_id']])) { |
|
127 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
128 | - // if event has default reg status of Not Approved, then don't display info on it |
|
129 | - if ( |
|
130 | - $event instanceof EE_Event |
|
131 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
132 | - ) { |
|
133 | - $display_event = false; |
|
134 | - // unless there are registrations for it that are returning to pay |
|
135 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
136 | - foreach ($options['registrations'] as $registration) { |
|
137 | - if (! $registration instanceof EE_Registration) { |
|
138 | - continue; |
|
139 | - } |
|
140 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
141 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
142 | - ? true |
|
143 | - : $display_event; |
|
144 | - } |
|
145 | - } |
|
146 | - if (! $display_event) { |
|
147 | - return ''; |
|
148 | - } |
|
149 | - } |
|
150 | - $this->_events[$options['event_id']] = 0; |
|
151 | - $html .= $this->_event_row($line_item); |
|
152 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
153 | - } |
|
154 | - } |
|
155 | - $child_line_items = $line_item->children(); |
|
156 | - // loop thru children |
|
157 | - foreach ($child_line_items as $child_line_item) { |
|
158 | - // recursively feed children back into this method |
|
159 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
160 | - } |
|
161 | - $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
162 | - $sub_total += $event_sub_total; |
|
163 | - if ( |
|
164 | - ( |
|
165 | - // event subtotals |
|
166 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
167 | - ) |
|
168 | - || ( |
|
169 | - // pre-tax subtotals |
|
170 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
171 | - ) |
|
172 | - ) { |
|
173 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
174 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
175 | - } |
|
176 | - break; |
|
177 | - case EEM_Line_Item::type_tax: |
|
178 | - if ($this->_show_taxes) { |
|
179 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
180 | - } |
|
181 | - break; |
|
182 | - case EEM_Line_Item::type_tax_sub_total: |
|
183 | - if ($this->_show_taxes) { |
|
184 | - $child_line_items = $line_item->children(); |
|
185 | - // loop thru children |
|
186 | - foreach ($child_line_items as $child_line_item) { |
|
187 | - // recursively feed children back into this method |
|
188 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
189 | - } |
|
190 | - if (count($child_line_items) > 1) { |
|
191 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
192 | - } |
|
193 | - } |
|
194 | - break; |
|
195 | - case EEM_Line_Item::type_total: |
|
196 | - // get all child line items |
|
197 | - $children = $line_item->children(); |
|
198 | - // loop thru all non-tax child line items |
|
199 | - foreach ($children as $child_line_item) { |
|
200 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
201 | - // recursively feed children back into this method |
|
202 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
203 | - } |
|
204 | - } |
|
205 | - // now loop thru tax child line items |
|
206 | - foreach ($children as $child_line_item) { |
|
207 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
208 | - // recursively feed children back into this method |
|
209 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
210 | - } |
|
211 | - } |
|
212 | - $html .= $this->_taxes_html; |
|
213 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
214 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
215 | - break; |
|
216 | - } |
|
217 | - return $html; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
224 | - * |
|
225 | - * @param EE_Line_Item $line_item |
|
226 | - * @return mixed |
|
227 | - */ |
|
228 | - private function _event_row(EE_Line_Item $line_item) |
|
229 | - { |
|
230 | - // start of row |
|
231 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
232 | - // event name td |
|
233 | - $html .= EEH_HTML::td( |
|
234 | - EEH_HTML::strong($line_item->name()), |
|
235 | - '', |
|
236 | - 'event-header', |
|
237 | - '', |
|
238 | - ' colspan="4"' |
|
239 | - ); |
|
240 | - // end of row |
|
241 | - $html .= EEH_HTML::trx(); |
|
242 | - return $html; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * _ticket_row |
|
249 | - * |
|
250 | - * @param EE_Line_Item $line_item |
|
251 | - * @param array $options |
|
252 | - * @return mixed |
|
253 | - * @throws EE_Error |
|
254 | - */ |
|
255 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
256 | - { |
|
257 | - // start of row |
|
258 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
259 | - $html = EEH_HTML::tr('', '', $row_class); |
|
260 | - // name && desc |
|
261 | - $name_and_desc = apply_filters( |
|
262 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
263 | - $line_item->name(), |
|
264 | - $line_item |
|
265 | - ); |
|
266 | - $name_and_desc .= apply_filters( |
|
267 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
268 | - ( |
|
269 | - $options['show_desc'] |
|
270 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
271 | - : '' |
|
272 | - ), |
|
273 | - $line_item, |
|
274 | - $options |
|
275 | - ); |
|
276 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
277 | - // name td |
|
278 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
279 | - $name_and_desc, '', 'item_l'); |
|
280 | - // price td |
|
281 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
282 | - // quantity td |
|
283 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
284 | - $this->_total_items += $line_item->quantity(); |
|
285 | - // determine total for line item |
|
286 | - $total = $line_item->total(); |
|
287 | - $this->_events[$options['event_id']] += $total; |
|
288 | - // total td |
|
289 | - $html .= EEH_HTML::td( |
|
290 | - EEH_Template::format_currency($total, false, false), |
|
291 | - '', |
|
292 | - 'item_r jst-rght' |
|
293 | - ); |
|
294 | - // end of row |
|
295 | - $html .= EEH_HTML::trx(); |
|
296 | - return $html; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * _item_row |
|
303 | - * |
|
304 | - * @param EE_Line_Item $line_item |
|
305 | - * @param array $options |
|
306 | - * @return mixed |
|
307 | - * @throws EE_Error |
|
308 | - */ |
|
309 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
310 | - { |
|
311 | - // start of row |
|
312 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
313 | - $html = EEH_HTML::tr('', '', $row_class); |
|
314 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
315 | - // name && desc |
|
316 | - $name_and_desc = apply_filters( |
|
317 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
318 | - $obj_name . $line_item->name(), |
|
319 | - $line_item |
|
320 | - ); |
|
321 | - $name_and_desc .= apply_filters( |
|
322 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
323 | - ( |
|
324 | - $options['show_desc'] |
|
325 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
326 | - : '' |
|
327 | - ), |
|
328 | - $line_item, |
|
329 | - $options |
|
330 | - ); |
|
331 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
332 | - // name td |
|
333 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
334 | - // price td |
|
335 | - if ($line_item->is_percent()) { |
|
336 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
337 | - } else { |
|
338 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
339 | - } |
|
340 | - // quantity td |
|
341 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
342 | - //$total = $line_item->total() * $line_item->quantity(); |
|
343 | - $total = $line_item->total(); |
|
344 | - if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
345 | - $this->_events[$options['event_id']] += $total; |
|
346 | - } |
|
347 | - // total td |
|
348 | - $html .= EEH_HTML::td( |
|
349 | - EEH_Template::format_currency($total, false, false), |
|
350 | - '', |
|
351 | - 'item_r jst-rght' |
|
352 | - ); |
|
353 | - // end of row |
|
354 | - $html .= EEH_HTML::trx(); |
|
355 | - return $html; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * _sub_item_row |
|
362 | - * |
|
363 | - * @param EE_Line_Item $line_item |
|
364 | - * @param array $options |
|
365 | - * @param EE_Line_Item $parent_line_item |
|
366 | - * @return mixed |
|
367 | - * @throws EE_Error |
|
368 | - */ |
|
369 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
370 | - { |
|
371 | - if($parent_line_item instanceof EE_Line_Item && $line_item->name() === $parent_line_item->name()) { |
|
372 | - return ''; |
|
373 | - } |
|
374 | - // start of row |
|
375 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
376 | - // name && desc |
|
377 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
378 | - . $line_item->name(); |
|
379 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
380 | - . $line_item->desc() |
|
381 | - . '</span>' : ''; |
|
382 | - // name td |
|
383 | - $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
384 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
385 | - // discount/surcharge td |
|
386 | - if ($line_item->is_percent()) { |
|
387 | - $html .= EEH_HTML::td( |
|
388 | - EEH_Template::format_currency( |
|
389 | - $line_item->total() / $qty, |
|
390 | - false, false |
|
391 | - ), |
|
392 | - '', 'item_c jst-rght' |
|
393 | - ); |
|
394 | - } else { |
|
395 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
396 | - } |
|
397 | - // no quantity td |
|
398 | - $html .= EEH_HTML::td(); |
|
399 | - // no total td |
|
400 | - $html .= EEH_HTML::td(); |
|
401 | - // end of row |
|
402 | - $html .= EEH_HTML::trx(); |
|
403 | - return $html; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * _tax_row |
|
410 | - * |
|
411 | - * @param EE_Line_Item $line_item |
|
412 | - * @param array $options |
|
413 | - * @return mixed |
|
414 | - * @throws EE_Error |
|
415 | - */ |
|
416 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
417 | - { |
|
418 | - // start of row |
|
419 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
420 | - // name && desc |
|
421 | - $name_and_desc = $line_item->name(); |
|
422 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
423 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
424 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
425 | - // name td |
|
426 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
427 | - $name_and_desc, '', 'item_l sub-item'); |
|
428 | - // percent td |
|
429 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
430 | - // empty td (price) |
|
431 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
432 | - // total td |
|
433 | - $html .= EEH_HTML::td(EEH_Template::format_currency( |
|
434 | - $line_item->total(), false, false), |
|
435 | - '', |
|
436 | - 'item_r jst-rght' |
|
437 | - ); |
|
438 | - // end of row |
|
439 | - $html .= EEH_HTML::trx(); |
|
440 | - return $html; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * _total_row |
|
447 | - * |
|
448 | - * @param EE_Line_Item $line_item |
|
449 | - * @param string $text |
|
450 | - * @return mixed |
|
451 | - * @throws EE_Error |
|
452 | - */ |
|
453 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
454 | - { |
|
455 | - $html = ''; |
|
456 | - if ($line_item->total()) { |
|
457 | - // start of row |
|
458 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
459 | - // total td |
|
460 | - $html .= EEH_HTML::td( |
|
461 | - $text, |
|
462 | - '', |
|
463 | - 'total_currency total jst-rght', |
|
464 | - '', |
|
465 | - ' colspan="2"' |
|
466 | - ); |
|
467 | - // empty td (price) |
|
468 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
469 | - // total td |
|
470 | - $html .= EEH_HTML::td( |
|
471 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
472 | - '', |
|
473 | - 'total jst-rght' |
|
474 | - ); |
|
475 | - // end of row |
|
476 | - $html .= EEH_HTML::trx(); |
|
477 | - } |
|
478 | - return $html; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * _total_row |
|
485 | - * |
|
486 | - * @param EE_Line_Item $line_item |
|
487 | - * @param string $text |
|
488 | - * @param array $options |
|
489 | - * @return mixed |
|
490 | - * @throws EE_Error |
|
491 | - */ |
|
492 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
493 | - { |
|
494 | - $html = ''; |
|
495 | - if ($line_item->total()) { |
|
496 | - // start of row |
|
497 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
498 | - // total td |
|
499 | - $html .= EEH_HTML::td( |
|
500 | - $text, |
|
501 | - '', |
|
502 | - 'total_currency total jst-rght', |
|
503 | - '', |
|
504 | - ' colspan="3"' |
|
505 | - ); |
|
506 | - // total td |
|
507 | - $html .= EEH_HTML::td( |
|
508 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
509 | - '', |
|
510 | - 'total jst-rght' |
|
511 | - ); |
|
512 | - // end of row |
|
513 | - $html .= EEH_HTML::trx(); |
|
514 | - } |
|
515 | - return $html; |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * _total_row |
|
522 | - * |
|
523 | - * @param EE_Line_Item $line_item |
|
524 | - * @param string $text |
|
525 | - * @return mixed |
|
526 | - * @throws EE_Error |
|
527 | - */ |
|
528 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
529 | - { |
|
530 | - // start of row |
|
531 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
532 | - // total td |
|
533 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
534 | - // total td |
|
535 | - $html .= EEH_HTML::td( |
|
536 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
537 | - '', |
|
538 | - 'total jst-rght' |
|
539 | - ); |
|
540 | - // end of row |
|
541 | - $html .= EEH_HTML::trx(); |
|
542 | - return $html; |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * _payments_and_amount_owing_rows |
|
549 | - * |
|
550 | - * @param EE_Line_Item $line_item |
|
551 | - * @param array $options |
|
552 | - * @return mixed |
|
553 | - * @throws EE_Error |
|
554 | - */ |
|
555 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
556 | - { |
|
557 | - $html = ''; |
|
558 | - $owing = $line_item->total(); |
|
559 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
560 | - if ($transaction instanceof EE_Transaction) { |
|
561 | - $registration_payments = array(); |
|
562 | - $registrations = ! empty($options['registrations']) |
|
563 | - ? $options['registrations'] |
|
564 | - : $transaction->registrations(); |
|
565 | - foreach ($registrations as $registration) { |
|
566 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
567 | - $registration_payments += $registration->registration_payments(); |
|
568 | - } |
|
569 | - } |
|
570 | - if (! empty($registration_payments)) { |
|
571 | - foreach ($registration_payments as $registration_payment) { |
|
572 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
573 | - $owing -= $registration_payment->amount(); |
|
574 | - $payment = $registration_payment->payment(); |
|
575 | - $payment_desc = ''; |
|
576 | - if ($payment instanceof EE_Payment) { |
|
577 | - $payment_desc = sprintf( |
|
578 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
579 | - $payment->txn_id_chq_nmbr() !== '' |
|
580 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
581 | - : '', |
|
582 | - $payment->timestamp() |
|
583 | - ); |
|
584 | - } |
|
585 | - // start of row |
|
586 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
587 | - // payment desc |
|
588 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
589 | - // total td |
|
590 | - $html .= EEH_HTML::td( |
|
591 | - EEH_Template::format_currency( |
|
592 | - $registration_payment->amount(), |
|
593 | - false, |
|
594 | - false |
|
595 | - ), |
|
596 | - '', |
|
597 | - 'total jst-rght' |
|
598 | - ); |
|
599 | - // end of row |
|
600 | - $html .= EEH_HTML::trx(); |
|
601 | - } |
|
602 | - } |
|
603 | - if ($line_item->total()) { |
|
604 | - // start of row |
|
605 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
606 | - // total td |
|
607 | - $html .= EEH_HTML::td( |
|
608 | - esc_html__('Amount Owing', 'event_espresso'), |
|
609 | - '', 'total_currency total jst-rght', '', ' colspan="3"' |
|
610 | - ); |
|
611 | - // total td |
|
612 | - $html .= EEH_HTML::td( |
|
613 | - EEH_Template::format_currency($owing, false, false), |
|
614 | - '', |
|
615 | - 'total jst-rght' |
|
616 | - ); |
|
617 | - // end of row |
|
618 | - $html .= EEH_HTML::trx(); |
|
619 | - } |
|
620 | - } |
|
621 | - } |
|
622 | - $this->_grand_total = $owing; |
|
623 | - return $html; |
|
624 | - } |
|
19 | + /** |
|
20 | + * array of events |
|
21 | + * |
|
22 | + * @type EE_Line_Item[] $_events |
|
23 | + */ |
|
24 | + private $_events = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * whether to display the taxes row or not |
|
28 | + * |
|
29 | + * @type bool $_show_taxes |
|
30 | + */ |
|
31 | + private $_show_taxes = false; |
|
32 | + |
|
33 | + /** |
|
34 | + * html for any tax rows |
|
35 | + * |
|
36 | + * @type string $_show_taxes |
|
37 | + */ |
|
38 | + private $_taxes_html = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * total amount including tax we can bill for at this time |
|
42 | + * |
|
43 | + * @type float $_grand_total |
|
44 | + */ |
|
45 | + private $_grand_total = 0.00; |
|
46 | + |
|
47 | + /** |
|
48 | + * total number of items being billed for |
|
49 | + * |
|
50 | + * @type int $_total_items |
|
51 | + */ |
|
52 | + private $_total_items = 0; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return float |
|
58 | + */ |
|
59 | + public function grand_total() |
|
60 | + { |
|
61 | + return $this->_grand_total; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public function total_items() |
|
70 | + { |
|
71 | + return $this->_total_items; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param EE_Line_Item $line_item |
|
78 | + * @param array $options |
|
79 | + * @param EE_Line_Item $parent_line_item |
|
80 | + * @return mixed |
|
81 | + * @throws EE_Error |
|
82 | + */ |
|
83 | + public function display_line_item( |
|
84 | + EE_Line_Item $line_item, |
|
85 | + $options = array(), |
|
86 | + EE_Line_Item $parent_line_item = null |
|
87 | + ) { |
|
88 | + $html = ''; |
|
89 | + // set some default options and merge with incoming |
|
90 | + $default_options = array( |
|
91 | + 'show_desc' => true, // true false |
|
92 | + 'odd' => false, |
|
93 | + ); |
|
94 | + $options = array_merge($default_options, (array)$options); |
|
95 | + switch ($line_item->type()) { |
|
96 | + case EEM_Line_Item::type_line_item: |
|
97 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
98 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
99 | + // item row |
|
100 | + $html .= $this->_ticket_row($line_item, $options); |
|
101 | + } else { |
|
102 | + // item row |
|
103 | + $html .= $this->_item_row($line_item, $options); |
|
104 | + } |
|
105 | + if ( |
|
106 | + apply_filters( |
|
107 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
108 | + true |
|
109 | + ) |
|
110 | + ) { |
|
111 | + // got any kids? |
|
112 | + foreach ($line_item->children() as $child_line_item) { |
|
113 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
114 | + } |
|
115 | + } |
|
116 | + break; |
|
117 | + case EEM_Line_Item::type_sub_line_item: |
|
118 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
119 | + break; |
|
120 | + case EEM_Line_Item::type_sub_total: |
|
121 | + static $sub_total = 0; |
|
122 | + $event_sub_total = 0; |
|
123 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
124 | + if ($line_item->OBJ_type() === 'Event') { |
|
125 | + $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
126 | + if (! isset($this->_events[$options['event_id']])) { |
|
127 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
128 | + // if event has default reg status of Not Approved, then don't display info on it |
|
129 | + if ( |
|
130 | + $event instanceof EE_Event |
|
131 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
132 | + ) { |
|
133 | + $display_event = false; |
|
134 | + // unless there are registrations for it that are returning to pay |
|
135 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
136 | + foreach ($options['registrations'] as $registration) { |
|
137 | + if (! $registration instanceof EE_Registration) { |
|
138 | + continue; |
|
139 | + } |
|
140 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
141 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
142 | + ? true |
|
143 | + : $display_event; |
|
144 | + } |
|
145 | + } |
|
146 | + if (! $display_event) { |
|
147 | + return ''; |
|
148 | + } |
|
149 | + } |
|
150 | + $this->_events[$options['event_id']] = 0; |
|
151 | + $html .= $this->_event_row($line_item); |
|
152 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
153 | + } |
|
154 | + } |
|
155 | + $child_line_items = $line_item->children(); |
|
156 | + // loop thru children |
|
157 | + foreach ($child_line_items as $child_line_item) { |
|
158 | + // recursively feed children back into this method |
|
159 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
160 | + } |
|
161 | + $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
162 | + $sub_total += $event_sub_total; |
|
163 | + if ( |
|
164 | + ( |
|
165 | + // event subtotals |
|
166 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
167 | + ) |
|
168 | + || ( |
|
169 | + // pre-tax subtotals |
|
170 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
171 | + ) |
|
172 | + ) { |
|
173 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
174 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
175 | + } |
|
176 | + break; |
|
177 | + case EEM_Line_Item::type_tax: |
|
178 | + if ($this->_show_taxes) { |
|
179 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
180 | + } |
|
181 | + break; |
|
182 | + case EEM_Line_Item::type_tax_sub_total: |
|
183 | + if ($this->_show_taxes) { |
|
184 | + $child_line_items = $line_item->children(); |
|
185 | + // loop thru children |
|
186 | + foreach ($child_line_items as $child_line_item) { |
|
187 | + // recursively feed children back into this method |
|
188 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
189 | + } |
|
190 | + if (count($child_line_items) > 1) { |
|
191 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
192 | + } |
|
193 | + } |
|
194 | + break; |
|
195 | + case EEM_Line_Item::type_total: |
|
196 | + // get all child line items |
|
197 | + $children = $line_item->children(); |
|
198 | + // loop thru all non-tax child line items |
|
199 | + foreach ($children as $child_line_item) { |
|
200 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
201 | + // recursively feed children back into this method |
|
202 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
203 | + } |
|
204 | + } |
|
205 | + // now loop thru tax child line items |
|
206 | + foreach ($children as $child_line_item) { |
|
207 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
208 | + // recursively feed children back into this method |
|
209 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
210 | + } |
|
211 | + } |
|
212 | + $html .= $this->_taxes_html; |
|
213 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
214 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
215 | + break; |
|
216 | + } |
|
217 | + return $html; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
224 | + * |
|
225 | + * @param EE_Line_Item $line_item |
|
226 | + * @return mixed |
|
227 | + */ |
|
228 | + private function _event_row(EE_Line_Item $line_item) |
|
229 | + { |
|
230 | + // start of row |
|
231 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
232 | + // event name td |
|
233 | + $html .= EEH_HTML::td( |
|
234 | + EEH_HTML::strong($line_item->name()), |
|
235 | + '', |
|
236 | + 'event-header', |
|
237 | + '', |
|
238 | + ' colspan="4"' |
|
239 | + ); |
|
240 | + // end of row |
|
241 | + $html .= EEH_HTML::trx(); |
|
242 | + return $html; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * _ticket_row |
|
249 | + * |
|
250 | + * @param EE_Line_Item $line_item |
|
251 | + * @param array $options |
|
252 | + * @return mixed |
|
253 | + * @throws EE_Error |
|
254 | + */ |
|
255 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
256 | + { |
|
257 | + // start of row |
|
258 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
259 | + $html = EEH_HTML::tr('', '', $row_class); |
|
260 | + // name && desc |
|
261 | + $name_and_desc = apply_filters( |
|
262 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
263 | + $line_item->name(), |
|
264 | + $line_item |
|
265 | + ); |
|
266 | + $name_and_desc .= apply_filters( |
|
267 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
268 | + ( |
|
269 | + $options['show_desc'] |
|
270 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
271 | + : '' |
|
272 | + ), |
|
273 | + $line_item, |
|
274 | + $options |
|
275 | + ); |
|
276 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
277 | + // name td |
|
278 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
279 | + $name_and_desc, '', 'item_l'); |
|
280 | + // price td |
|
281 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
282 | + // quantity td |
|
283 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
284 | + $this->_total_items += $line_item->quantity(); |
|
285 | + // determine total for line item |
|
286 | + $total = $line_item->total(); |
|
287 | + $this->_events[$options['event_id']] += $total; |
|
288 | + // total td |
|
289 | + $html .= EEH_HTML::td( |
|
290 | + EEH_Template::format_currency($total, false, false), |
|
291 | + '', |
|
292 | + 'item_r jst-rght' |
|
293 | + ); |
|
294 | + // end of row |
|
295 | + $html .= EEH_HTML::trx(); |
|
296 | + return $html; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * _item_row |
|
303 | + * |
|
304 | + * @param EE_Line_Item $line_item |
|
305 | + * @param array $options |
|
306 | + * @return mixed |
|
307 | + * @throws EE_Error |
|
308 | + */ |
|
309 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
310 | + { |
|
311 | + // start of row |
|
312 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
313 | + $html = EEH_HTML::tr('', '', $row_class); |
|
314 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
315 | + // name && desc |
|
316 | + $name_and_desc = apply_filters( |
|
317 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
318 | + $obj_name . $line_item->name(), |
|
319 | + $line_item |
|
320 | + ); |
|
321 | + $name_and_desc .= apply_filters( |
|
322 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
323 | + ( |
|
324 | + $options['show_desc'] |
|
325 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
326 | + : '' |
|
327 | + ), |
|
328 | + $line_item, |
|
329 | + $options |
|
330 | + ); |
|
331 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
332 | + // name td |
|
333 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
334 | + // price td |
|
335 | + if ($line_item->is_percent()) { |
|
336 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
337 | + } else { |
|
338 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
339 | + } |
|
340 | + // quantity td |
|
341 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
342 | + //$total = $line_item->total() * $line_item->quantity(); |
|
343 | + $total = $line_item->total(); |
|
344 | + if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
345 | + $this->_events[$options['event_id']] += $total; |
|
346 | + } |
|
347 | + // total td |
|
348 | + $html .= EEH_HTML::td( |
|
349 | + EEH_Template::format_currency($total, false, false), |
|
350 | + '', |
|
351 | + 'item_r jst-rght' |
|
352 | + ); |
|
353 | + // end of row |
|
354 | + $html .= EEH_HTML::trx(); |
|
355 | + return $html; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * _sub_item_row |
|
362 | + * |
|
363 | + * @param EE_Line_Item $line_item |
|
364 | + * @param array $options |
|
365 | + * @param EE_Line_Item $parent_line_item |
|
366 | + * @return mixed |
|
367 | + * @throws EE_Error |
|
368 | + */ |
|
369 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
370 | + { |
|
371 | + if($parent_line_item instanceof EE_Line_Item && $line_item->name() === $parent_line_item->name()) { |
|
372 | + return ''; |
|
373 | + } |
|
374 | + // start of row |
|
375 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
376 | + // name && desc |
|
377 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
378 | + . $line_item->name(); |
|
379 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
380 | + . $line_item->desc() |
|
381 | + . '</span>' : ''; |
|
382 | + // name td |
|
383 | + $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
384 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
385 | + // discount/surcharge td |
|
386 | + if ($line_item->is_percent()) { |
|
387 | + $html .= EEH_HTML::td( |
|
388 | + EEH_Template::format_currency( |
|
389 | + $line_item->total() / $qty, |
|
390 | + false, false |
|
391 | + ), |
|
392 | + '', 'item_c jst-rght' |
|
393 | + ); |
|
394 | + } else { |
|
395 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
396 | + } |
|
397 | + // no quantity td |
|
398 | + $html .= EEH_HTML::td(); |
|
399 | + // no total td |
|
400 | + $html .= EEH_HTML::td(); |
|
401 | + // end of row |
|
402 | + $html .= EEH_HTML::trx(); |
|
403 | + return $html; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * _tax_row |
|
410 | + * |
|
411 | + * @param EE_Line_Item $line_item |
|
412 | + * @param array $options |
|
413 | + * @return mixed |
|
414 | + * @throws EE_Error |
|
415 | + */ |
|
416 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
417 | + { |
|
418 | + // start of row |
|
419 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
420 | + // name && desc |
|
421 | + $name_and_desc = $line_item->name(); |
|
422 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
423 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
424 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
425 | + // name td |
|
426 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
427 | + $name_and_desc, '', 'item_l sub-item'); |
|
428 | + // percent td |
|
429 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
430 | + // empty td (price) |
|
431 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
432 | + // total td |
|
433 | + $html .= EEH_HTML::td(EEH_Template::format_currency( |
|
434 | + $line_item->total(), false, false), |
|
435 | + '', |
|
436 | + 'item_r jst-rght' |
|
437 | + ); |
|
438 | + // end of row |
|
439 | + $html .= EEH_HTML::trx(); |
|
440 | + return $html; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * _total_row |
|
447 | + * |
|
448 | + * @param EE_Line_Item $line_item |
|
449 | + * @param string $text |
|
450 | + * @return mixed |
|
451 | + * @throws EE_Error |
|
452 | + */ |
|
453 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
454 | + { |
|
455 | + $html = ''; |
|
456 | + if ($line_item->total()) { |
|
457 | + // start of row |
|
458 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
459 | + // total td |
|
460 | + $html .= EEH_HTML::td( |
|
461 | + $text, |
|
462 | + '', |
|
463 | + 'total_currency total jst-rght', |
|
464 | + '', |
|
465 | + ' colspan="2"' |
|
466 | + ); |
|
467 | + // empty td (price) |
|
468 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
469 | + // total td |
|
470 | + $html .= EEH_HTML::td( |
|
471 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
472 | + '', |
|
473 | + 'total jst-rght' |
|
474 | + ); |
|
475 | + // end of row |
|
476 | + $html .= EEH_HTML::trx(); |
|
477 | + } |
|
478 | + return $html; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * _total_row |
|
485 | + * |
|
486 | + * @param EE_Line_Item $line_item |
|
487 | + * @param string $text |
|
488 | + * @param array $options |
|
489 | + * @return mixed |
|
490 | + * @throws EE_Error |
|
491 | + */ |
|
492 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
493 | + { |
|
494 | + $html = ''; |
|
495 | + if ($line_item->total()) { |
|
496 | + // start of row |
|
497 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
498 | + // total td |
|
499 | + $html .= EEH_HTML::td( |
|
500 | + $text, |
|
501 | + '', |
|
502 | + 'total_currency total jst-rght', |
|
503 | + '', |
|
504 | + ' colspan="3"' |
|
505 | + ); |
|
506 | + // total td |
|
507 | + $html .= EEH_HTML::td( |
|
508 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
509 | + '', |
|
510 | + 'total jst-rght' |
|
511 | + ); |
|
512 | + // end of row |
|
513 | + $html .= EEH_HTML::trx(); |
|
514 | + } |
|
515 | + return $html; |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * _total_row |
|
522 | + * |
|
523 | + * @param EE_Line_Item $line_item |
|
524 | + * @param string $text |
|
525 | + * @return mixed |
|
526 | + * @throws EE_Error |
|
527 | + */ |
|
528 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
529 | + { |
|
530 | + // start of row |
|
531 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
532 | + // total td |
|
533 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
534 | + // total td |
|
535 | + $html .= EEH_HTML::td( |
|
536 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
537 | + '', |
|
538 | + 'total jst-rght' |
|
539 | + ); |
|
540 | + // end of row |
|
541 | + $html .= EEH_HTML::trx(); |
|
542 | + return $html; |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * _payments_and_amount_owing_rows |
|
549 | + * |
|
550 | + * @param EE_Line_Item $line_item |
|
551 | + * @param array $options |
|
552 | + * @return mixed |
|
553 | + * @throws EE_Error |
|
554 | + */ |
|
555 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
556 | + { |
|
557 | + $html = ''; |
|
558 | + $owing = $line_item->total(); |
|
559 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
560 | + if ($transaction instanceof EE_Transaction) { |
|
561 | + $registration_payments = array(); |
|
562 | + $registrations = ! empty($options['registrations']) |
|
563 | + ? $options['registrations'] |
|
564 | + : $transaction->registrations(); |
|
565 | + foreach ($registrations as $registration) { |
|
566 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
567 | + $registration_payments += $registration->registration_payments(); |
|
568 | + } |
|
569 | + } |
|
570 | + if (! empty($registration_payments)) { |
|
571 | + foreach ($registration_payments as $registration_payment) { |
|
572 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
573 | + $owing -= $registration_payment->amount(); |
|
574 | + $payment = $registration_payment->payment(); |
|
575 | + $payment_desc = ''; |
|
576 | + if ($payment instanceof EE_Payment) { |
|
577 | + $payment_desc = sprintf( |
|
578 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
579 | + $payment->txn_id_chq_nmbr() !== '' |
|
580 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
581 | + : '', |
|
582 | + $payment->timestamp() |
|
583 | + ); |
|
584 | + } |
|
585 | + // start of row |
|
586 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
587 | + // payment desc |
|
588 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
589 | + // total td |
|
590 | + $html .= EEH_HTML::td( |
|
591 | + EEH_Template::format_currency( |
|
592 | + $registration_payment->amount(), |
|
593 | + false, |
|
594 | + false |
|
595 | + ), |
|
596 | + '', |
|
597 | + 'total jst-rght' |
|
598 | + ); |
|
599 | + // end of row |
|
600 | + $html .= EEH_HTML::trx(); |
|
601 | + } |
|
602 | + } |
|
603 | + if ($line_item->total()) { |
|
604 | + // start of row |
|
605 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
606 | + // total td |
|
607 | + $html .= EEH_HTML::td( |
|
608 | + esc_html__('Amount Owing', 'event_espresso'), |
|
609 | + '', 'total_currency total jst-rght', '', ' colspan="3"' |
|
610 | + ); |
|
611 | + // total td |
|
612 | + $html .= EEH_HTML::td( |
|
613 | + EEH_Template::format_currency($owing, false, false), |
|
614 | + '', |
|
615 | + 'total jst-rght' |
|
616 | + ); |
|
617 | + // end of row |
|
618 | + $html .= EEH_HTML::trx(); |
|
619 | + } |
|
620 | + } |
|
621 | + } |
|
622 | + $this->_grand_total = $owing; |
|
623 | + return $html; |
|
624 | + } |
|
625 | 625 | |
626 | 626 | |
627 | 627 | } |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | $html = ''; |
89 | 89 | // set some default options and merge with incoming |
90 | 90 | $default_options = array( |
91 | - 'show_desc' => true, // true false |
|
91 | + 'show_desc' => true, // true false |
|
92 | 92 | 'odd' => false, |
93 | 93 | ); |
94 | - $options = array_merge($default_options, (array)$options); |
|
94 | + $options = array_merge($default_options, (array) $options); |
|
95 | 95 | switch ($line_item->type()) { |
96 | 96 | case EEM_Line_Item::type_line_item: |
97 | 97 | $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $text = esc_html__('Sub-Total', 'event_espresso'); |
124 | 124 | if ($line_item->OBJ_type() === 'Event') { |
125 | 125 | $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
126 | - if (! isset($this->_events[$options['event_id']])) { |
|
126 | + if ( ! isset($this->_events[$options['event_id']])) { |
|
127 | 127 | $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
128 | 128 | // if event has default reg status of Not Approved, then don't display info on it |
129 | 129 | if ( |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | // unless there are registrations for it that are returning to pay |
135 | 135 | if (isset($options['registrations']) && is_array($options['registrations'])) { |
136 | 136 | foreach ($options['registrations'] as $registration) { |
137 | - if (! $registration instanceof EE_Registration) { |
|
137 | + if ( ! $registration instanceof EE_Registration) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | 140 | $display_event = $registration->event_ID() === $options['event_id'] |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | : $display_event; |
144 | 144 | } |
145 | 145 | } |
146 | - if (! $display_event) { |
|
146 | + if ( ! $display_event) { |
|
147 | 147 | return ''; |
148 | 148 | } |
149 | 149 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
268 | 268 | ( |
269 | 269 | $options['show_desc'] |
270 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
270 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
271 | 271 | : '' |
272 | 272 | ), |
273 | 273 | $line_item, |
@@ -311,18 +311,18 @@ discard block |
||
311 | 311 | // start of row |
312 | 312 | $row_class = $options['odd'] ? 'item odd' : 'item'; |
313 | 313 | $html = EEH_HTML::tr('', '', $row_class); |
314 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
314 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : ''; |
|
315 | 315 | // name && desc |
316 | 316 | $name_and_desc = apply_filters( |
317 | 317 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
318 | - $obj_name . $line_item->name(), |
|
318 | + $obj_name.$line_item->name(), |
|
319 | 319 | $line_item |
320 | 320 | ); |
321 | 321 | $name_and_desc .= apply_filters( |
322 | 322 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
323 | 323 | ( |
324 | 324 | $options['show_desc'] |
325 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
325 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
326 | 326 | : '' |
327 | 327 | ), |
328 | 328 | $line_item, |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
334 | 334 | // price td |
335 | 335 | if ($line_item->is_percent()) { |
336 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
336 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght'); |
|
337 | 337 | } else { |
338 | 338 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
339 | 339 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | */ |
369 | 369 | private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
370 | 370 | { |
371 | - if($parent_line_item instanceof EE_Line_Item && $line_item->name() === $parent_line_item->name()) { |
|
371 | + if ($parent_line_item instanceof EE_Line_Item && $line_item->name() === $parent_line_item->name()) { |
|
372 | 372 | return ''; |
373 | 373 | } |
374 | 374 | // start of row |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | . $line_item->desc() |
381 | 381 | . '</span>' : ''; |
382 | 382 | // name td |
383 | - $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
383 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
384 | 384 | $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
385 | 385 | // discount/surcharge td |
386 | 386 | if ($line_item->is_percent()) { |
@@ -420,13 +420,13 @@ discard block |
||
420 | 420 | // name && desc |
421 | 421 | $name_and_desc = $line_item->name(); |
422 | 422 | $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
423 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
424 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
423 | + . esc_html__(' * taxable items', 'event_espresso').'</span>'; |
|
424 | + $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : ''; |
|
425 | 425 | // name td |
426 | 426 | $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
427 | 427 | $name_and_desc, '', 'item_l sub-item'); |
428 | 428 | // percent td |
429 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
429 | + $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', ''); |
|
430 | 430 | // empty td (price) |
431 | 431 | $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
432 | 432 | // total td |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | $registration_payments += $registration->registration_payments(); |
568 | 568 | } |
569 | 569 | } |
570 | - if (! empty($registration_payments)) { |
|
570 | + if ( ! empty($registration_payments)) { |
|
571 | 571 | foreach ($registration_payments as $registration_payment) { |
572 | 572 | if ($registration_payment instanceof EE_Registration_Payment) { |
573 | 573 | $owing -= $registration_payment->amount(); |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | $payment_desc = sprintf( |
578 | 578 | esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
579 | 579 | $payment->txn_id_chq_nmbr() !== '' |
580 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
580 | + ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> ' |
|
581 | 581 | : '', |
582 | 582 | $payment->timestamp() |
583 | 583 | ); |