Completed
Branch yet-another-batch-of-ui-fixes (371f49)
by
unknown
30:27 queued 22:46
created
core/libraries/shortcodes/EE_Line_Item_List_Shortcodes.lib.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -20,201 +20,201 @@
 block discarded – undo
20 20
  */
21 21
 class EE_Line_Item_List_Shortcodes extends EE_Shortcodes
22 22
 {
23
-    protected function _init_props()
24
-    {
25
-        $this->label = esc_html__('Line Item List Shortcodes', 'event_espresso');
26
-        $this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso');
27
-        $this->_shortcodes = array(
28
-            '[TICKET_LINE_ITEM_LIST]'         => esc_html__('Outputs a list of ticket line items.', 'event_espresso'),
29
-            '[TAX_LINE_ITEM_LIST]'            => esc_html__('Outputs a list of tax line items.', 'event_espresso'),
30
-            '[ADDITIONAL_LINE_ITEM_LIST]'     => esc_html__(
31
-                'Outputs a list of additional line items (other charges or discounts)',
32
-                'event_espresso'
33
-            ),
34
-            '[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'),
35
-        );
36
-    }
37
-
38
-
39
-    protected function _parser($shortcode)
40
-    {
41
-
42
-        switch ($shortcode) {
43
-            case '[TICKET_LINE_ITEM_LIST]':
44
-                return $this->_get_ticket_line_item_list();
45
-
46
-            case '[TAX_LINE_ITEM_LIST]':
47
-                return $this->_get_tax_line_item_list();
48
-
49
-            case '[PRICE_MODIFIER_LINE_ITEM_LIST]':
50
-                return $this->_get_price_mod_line_item_list();
51
-
52
-            case '[ADDITIONAL_LINE_ITEM_LIST]':
53
-                return $this->_get_additional_line_item_list();
54
-
55
-            default:
56
-                return '';
57
-        }
58
-    }
59
-
60
-
61
-    /**
62
-     * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event.
63
-     *
64
-     * @since 4.5.0
65
-     *
66
-     * @return string parsed ticket line item list.
67
-     */
68
-    private function _get_ticket_line_item_list()
69
-    {
70
-        $this->_validate_list_requirements();
71
-
72
-        if (! $this->_data['data'] instanceof EE_Ticket) {
73
-            return '';
74
-        }
75
-
76
-        $valid_shortcodes = array('line_item', 'line_item_list', 'ticket');
77
-
78
-        $ticket = $this->_data['data'];
79
-        $templates = $this->_extra_data['template'];
80
-        $addressee_obj = $this->_extra_data['data'];
81
-
82
-        // made it here so we have an EE_Ticket, so we should have what we need.
83
-        $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item'])
84
-            ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null;
85
-        $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'])
86
-            ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array();
87
-
88
-        $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms']
89
-            : $templates['ticket_line_item_pms'];
90
-
91
-        if (empty($ticket_line_item) || empty($sub_line_items)) {
92
-            return '';
93
-        }
94
-
95
-        // now we just return the appropriate template parsed for each ticket.
96
-        return $this->_shortcode_helper->parse_line_item_list_template(
97
-            $template,
98
-            $ticket_line_item,
99
-            $valid_shortcodes,
100
-            $this->_extra_data
101
-        );
102
-    }
103
-
104
-
105
-    /**
106
-     * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction.
107
-     *
108
-     * @return string  parsed tax line item list.
109
-     * @throws EE_Error
110
-     * @since 4.5.0
111
-     */
112
-    private function _get_tax_line_item_list()
113
-    {
114
-        /** @var EE_Admin_Config $admin_config */
115
-        $admin_config = LoaderFactory::getShared(EE_Admin_Config::class);
116
-        if ($admin_config->useAdvancedEditor()) {
117
-            return '';
118
-        }
119
-        $this->_validate_list_requirements();
120
-
121
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
122
-            return '';
123
-        }
124
-
125
-        // made it here so we're good to go.
126
-        $valid_shortcodes = array('line_item');
127
-        $templates = $this->_data['template'];
128
-
129
-        $tax_line_items = $this->_data['data']->tax_line_items;
130
-        $line_item_list = '';
131
-        foreach ($tax_line_items as $line_item) {
132
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
133
-                $templates['tax_line_item_list'],
134
-                $line_item,
135
-                $valid_shortcodes,
136
-                $this->_extra_data
137
-            );
138
-        }
139
-
140
-        return $line_item_list;
141
-    }
142
-
143
-    /**
144
-     * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction.
145
-     *
146
-     * @since 4.5.0
147
-     *
148
-     * @return string  parsed other line item list.
149
-     */
150
-    private function _get_additional_line_item_list()
151
-    {
152
-
153
-        $this->_validate_list_requirements();
154
-
155
-        if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
156
-            return '';
157
-        }
158
-
159
-        // made it here so we're good to go.
160
-        $valid_shortcodes = array('line_item');
161
-        $templates = $this->_data['template'];
162
-
163
-        $additional_line_items = $this->_data['data']->additional_line_items;
164
-        $line_item_list = '';
165
-        foreach ($additional_line_items as $line_item) {
166
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
167
-                $templates['additional_line_item_list'],
168
-                $line_item,
169
-                $valid_shortcodes,
170
-                $this->_extra_data
171
-            );
172
-        }
173
-
174
-
175
-        return $line_item_list;
176
-    }
177
-
178
-
179
-    /**
180
-     * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a
181
-     * parent ticket line item.
182
-     *
183
-     * @since 4.5.0
184
-     *
185
-     * @return string parsed price modifier line item list.
186
-     */
187
-    private function _get_price_mod_line_item_list()
188
-    {
189
-        $this->_validate_list_requirements();
190
-
191
-        if (! $this->_data['data'] instanceof EE_Line_Item) {
192
-            return '';
193
-        }
194
-
195
-        // made it here so we're good to go.
196
-        $main_line_item = $this->_data['data'];
197
-        $templates = $this->_extra_data['template'];
198
-        $addressee_obj = $this->_extra_data['data'];
199
-
200
-        $valid_shortcodes = array('line_item');
201
-
202
-        $main_line_item_id = $main_line_item->ID();
203
-
204
-        $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children'])
205
-            ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array();
206
-
207
-        $line_item_list = '';
208
-
209
-        foreach ($price_mod_line_items as $line_item) {
210
-            $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
211
-                $templates['price_modifier_line_item_list'],
212
-                $line_item,
213
-                $valid_shortcodes,
214
-                $this->_extra_data
215
-            );
216
-        }
217
-
218
-        return $line_item_list;
219
-    }
23
+	protected function _init_props()
24
+	{
25
+		$this->label = esc_html__('Line Item List Shortcodes', 'event_espresso');
26
+		$this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso');
27
+		$this->_shortcodes = array(
28
+			'[TICKET_LINE_ITEM_LIST]'         => esc_html__('Outputs a list of ticket line items.', 'event_espresso'),
29
+			'[TAX_LINE_ITEM_LIST]'            => esc_html__('Outputs a list of tax line items.', 'event_espresso'),
30
+			'[ADDITIONAL_LINE_ITEM_LIST]'     => esc_html__(
31
+				'Outputs a list of additional line items (other charges or discounts)',
32
+				'event_espresso'
33
+			),
34
+			'[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'),
35
+		);
36
+	}
37
+
38
+
39
+	protected function _parser($shortcode)
40
+	{
41
+
42
+		switch ($shortcode) {
43
+			case '[TICKET_LINE_ITEM_LIST]':
44
+				return $this->_get_ticket_line_item_list();
45
+
46
+			case '[TAX_LINE_ITEM_LIST]':
47
+				return $this->_get_tax_line_item_list();
48
+
49
+			case '[PRICE_MODIFIER_LINE_ITEM_LIST]':
50
+				return $this->_get_price_mod_line_item_list();
51
+
52
+			case '[ADDITIONAL_LINE_ITEM_LIST]':
53
+				return $this->_get_additional_line_item_list();
54
+
55
+			default:
56
+				return '';
57
+		}
58
+	}
59
+
60
+
61
+	/**
62
+	 * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event.
63
+	 *
64
+	 * @since 4.5.0
65
+	 *
66
+	 * @return string parsed ticket line item list.
67
+	 */
68
+	private function _get_ticket_line_item_list()
69
+	{
70
+		$this->_validate_list_requirements();
71
+
72
+		if (! $this->_data['data'] instanceof EE_Ticket) {
73
+			return '';
74
+		}
75
+
76
+		$valid_shortcodes = array('line_item', 'line_item_list', 'ticket');
77
+
78
+		$ticket = $this->_data['data'];
79
+		$templates = $this->_extra_data['template'];
80
+		$addressee_obj = $this->_extra_data['data'];
81
+
82
+		// made it here so we have an EE_Ticket, so we should have what we need.
83
+		$ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item'])
84
+			? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null;
85
+		$sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'])
86
+			? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array();
87
+
88
+		$template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms']
89
+			: $templates['ticket_line_item_pms'];
90
+
91
+		if (empty($ticket_line_item) || empty($sub_line_items)) {
92
+			return '';
93
+		}
94
+
95
+		// now we just return the appropriate template parsed for each ticket.
96
+		return $this->_shortcode_helper->parse_line_item_list_template(
97
+			$template,
98
+			$ticket_line_item,
99
+			$valid_shortcodes,
100
+			$this->_extra_data
101
+		);
102
+	}
103
+
104
+
105
+	/**
106
+	 * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction.
107
+	 *
108
+	 * @return string  parsed tax line item list.
109
+	 * @throws EE_Error
110
+	 * @since 4.5.0
111
+	 */
112
+	private function _get_tax_line_item_list()
113
+	{
114
+		/** @var EE_Admin_Config $admin_config */
115
+		$admin_config = LoaderFactory::getShared(EE_Admin_Config::class);
116
+		if ($admin_config->useAdvancedEditor()) {
117
+			return '';
118
+		}
119
+		$this->_validate_list_requirements();
120
+
121
+		if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
122
+			return '';
123
+		}
124
+
125
+		// made it here so we're good to go.
126
+		$valid_shortcodes = array('line_item');
127
+		$templates = $this->_data['template'];
128
+
129
+		$tax_line_items = $this->_data['data']->tax_line_items;
130
+		$line_item_list = '';
131
+		foreach ($tax_line_items as $line_item) {
132
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
133
+				$templates['tax_line_item_list'],
134
+				$line_item,
135
+				$valid_shortcodes,
136
+				$this->_extra_data
137
+			);
138
+		}
139
+
140
+		return $line_item_list;
141
+	}
142
+
143
+	/**
144
+	 * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction.
145
+	 *
146
+	 * @since 4.5.0
147
+	 *
148
+	 * @return string  parsed other line item list.
149
+	 */
150
+	private function _get_additional_line_item_list()
151
+	{
152
+
153
+		$this->_validate_list_requirements();
154
+
155
+		if (! $this->_data['data'] instanceof EE_Messages_Addressee) {
156
+			return '';
157
+		}
158
+
159
+		// made it here so we're good to go.
160
+		$valid_shortcodes = array('line_item');
161
+		$templates = $this->_data['template'];
162
+
163
+		$additional_line_items = $this->_data['data']->additional_line_items;
164
+		$line_item_list = '';
165
+		foreach ($additional_line_items as $line_item) {
166
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
167
+				$templates['additional_line_item_list'],
168
+				$line_item,
169
+				$valid_shortcodes,
170
+				$this->_extra_data
171
+			);
172
+		}
173
+
174
+
175
+		return $line_item_list;
176
+	}
177
+
178
+
179
+	/**
180
+	 * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a
181
+	 * parent ticket line item.
182
+	 *
183
+	 * @since 4.5.0
184
+	 *
185
+	 * @return string parsed price modifier line item list.
186
+	 */
187
+	private function _get_price_mod_line_item_list()
188
+	{
189
+		$this->_validate_list_requirements();
190
+
191
+		if (! $this->_data['data'] instanceof EE_Line_Item) {
192
+			return '';
193
+		}
194
+
195
+		// made it here so we're good to go.
196
+		$main_line_item = $this->_data['data'];
197
+		$templates = $this->_extra_data['template'];
198
+		$addressee_obj = $this->_extra_data['data'];
199
+
200
+		$valid_shortcodes = array('line_item');
201
+
202
+		$main_line_item_id = $main_line_item->ID();
203
+
204
+		$price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children'])
205
+			? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array();
206
+
207
+		$line_item_list = '';
208
+
209
+		foreach ($price_mod_line_items as $line_item) {
210
+			$line_item_list .= $this->_shortcode_helper->parse_line_item_list_template(
211
+				$templates['price_modifier_line_item_list'],
212
+				$line_item,
213
+				$valid_shortcodes,
214
+				$this->_extra_data
215
+			);
216
+		}
217
+
218
+		return $line_item_list;
219
+	}
220 220
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Taxes.class.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $tax = 0;
43 43
         $total_tax = 0;
44 44
         // This first checks to see if the given ticket is taxable.
45
-        if (! $ticket->taxable()) {
45
+        if ( ! $ticket->taxable()) {
46 46
             return $tax;
47 47
         }
48 48
         // get subtotal (notice we're only retrieving a subtotal if there isn't one given)
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     public static function get_subtotal_for_admin(EE_Ticket $ticket)
86 86
     {
87 87
         $TKT_ID = $ticket->ID();
88
-        return EE_Taxes::$_subtotal[ $TKT_ID ] ?? EE_Taxes::_get_subtotal_for_admin($ticket);
88
+        return EE_Taxes::$_subtotal[$TKT_ID] ?? EE_Taxes::_get_subtotal_for_admin($ticket);
89 89
     }
90 90
 
91 91
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             }
134 134
         }
135 135
         $TKT_ID = $ticket->ID();
136
-        EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal;
136
+        EE_Taxes::$_subtotal[$TKT_ID] = $subtotal;
137 137
         return $subtotal;
138 138
     }
139 139
 
Please login to merge, or discard this patch.
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -11,147 +11,147 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Taxes extends EE_Base
13 13
 {
14
-    /**
15
-     * This is used for when EE_Taxes is used statically by the admin
16
-     *
17
-     * @var array
18
-     */
19
-    private static $_subtotal = [];
14
+	/**
15
+	 * This is used for when EE_Taxes is used statically by the admin
16
+	 *
17
+	 * @var array
18
+	 */
19
+	private static $_subtotal = [];
20 20
 
21
-    /**
22
-     * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types)
23
-     *
24
-     * @var EE_Price[]
25
-     */
26
-    private static $_default_taxes = [];
21
+	/**
22
+	 * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types)
23
+	 *
24
+	 * @var EE_Price[]
25
+	 */
26
+	private static $_default_taxes = [];
27 27
 
28 28
 
29
-    /**
30
-     * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket
31
-     * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick
32
-     * calc of taxes for tickets listed in the event editor.
33
-     *
34
-     * @param EE_Ticket $ticket incoming EE_Ticket
35
-     * @return float             total taxes to apply to ticket.
36
-     * @throws EE_Error
37
-     * @throws ReflectionException
38
-     */
39
-    public static function get_total_taxes_for_admin(EE_Ticket $ticket)
40
-    {
41
-        $tax = 0;
42
-        $total_tax = 0;
43
-        // This first checks to see if the given ticket is taxable.
44
-        if (! $ticket->taxable()) {
45
-            return $tax;
46
-        }
47
-        // get subtotal (notice we're only retrieving a subtotal if there isn't one given)
48
-        $subtotal = EE_Taxes::get_subtotal_for_admin($ticket);
49
-        // get taxes
50
-        $taxes = EE_Taxes::get_taxes_for_admin();
51
-        // apply taxes to subtotal
52
-        foreach ($taxes as $tax) {
53
-            // assuming taxes are not cumulative
54
-            $total_tax += $subtotal * $tax->amount() / 100;
55
-        }
56
-        return $total_tax;
57
-    }
29
+	/**
30
+	 * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket
31
+	 * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick
32
+	 * calc of taxes for tickets listed in the event editor.
33
+	 *
34
+	 * @param EE_Ticket $ticket incoming EE_Ticket
35
+	 * @return float             total taxes to apply to ticket.
36
+	 * @throws EE_Error
37
+	 * @throws ReflectionException
38
+	 */
39
+	public static function get_total_taxes_for_admin(EE_Ticket $ticket)
40
+	{
41
+		$tax = 0;
42
+		$total_tax = 0;
43
+		// This first checks to see if the given ticket is taxable.
44
+		if (! $ticket->taxable()) {
45
+			return $tax;
46
+		}
47
+		// get subtotal (notice we're only retrieving a subtotal if there isn't one given)
48
+		$subtotal = EE_Taxes::get_subtotal_for_admin($ticket);
49
+		// get taxes
50
+		$taxes = EE_Taxes::get_taxes_for_admin();
51
+		// apply taxes to subtotal
52
+		foreach ($taxes as $tax) {
53
+			// assuming taxes are not cumulative
54
+			$total_tax += $subtotal * $tax->amount() / 100;
55
+		}
56
+		return $total_tax;
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * Gets the total percentage of tax that should be applied to taxable line items
62
-     *
63
-     * @return float the percentage of tax that should be added to taxable items
64
-     * @throws EE_Error
65
-     * @throws ReflectionException
66
-     * eg 20 for %20 tax (NOT 0.20, which
67
-     */
68
-    public static function get_total_taxes_percentage()
69
-    {
70
-        $total_tax_percent = 0;
71
-        foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) {
72
-            $total_tax_percent += $tax_price->get('PRC_amount');
73
-        }
74
-        return $total_tax_percent;
75
-    }
60
+	/**
61
+	 * Gets the total percentage of tax that should be applied to taxable line items
62
+	 *
63
+	 * @return float the percentage of tax that should be added to taxable items
64
+	 * @throws EE_Error
65
+	 * @throws ReflectionException
66
+	 * eg 20 for %20 tax (NOT 0.20, which
67
+	 */
68
+	public static function get_total_taxes_percentage()
69
+	{
70
+		$total_tax_percent = 0;
71
+		foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) {
72
+			$total_tax_percent += $tax_price->get('PRC_amount');
73
+		}
74
+		return $total_tax_percent;
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * @param EE_Ticket $ticket
80
-     * @return float
81
-     * @throws EE_Error
82
-     * @throws ReflectionException
83
-     */
84
-    public static function get_subtotal_for_admin(EE_Ticket $ticket)
85
-    {
86
-        $TKT_ID = $ticket->ID();
87
-        return EE_Taxes::$_subtotal[ $TKT_ID ] ?? EE_Taxes::_get_subtotal_for_admin($ticket);
88
-    }
78
+	/**
79
+	 * @param EE_Ticket $ticket
80
+	 * @return float
81
+	 * @throws EE_Error
82
+	 * @throws ReflectionException
83
+	 */
84
+	public static function get_subtotal_for_admin(EE_Ticket $ticket)
85
+	{
86
+		$TKT_ID = $ticket->ID();
87
+		return EE_Taxes::$_subtotal[ $TKT_ID ] ?? EE_Taxes::_get_subtotal_for_admin($ticket);
88
+	}
89 89
 
90 90
 
91
-    /**
92
-     * simply take an incoming ticket and calculate the subtotal for the ticket
93
-     *
94
-     * @param EE_Ticket $ticket
95
-     * @return float     subtotal calculated from all EE_Price[] on Ticket.
96
-     * @throws EE_Error
97
-     * @throws ReflectionException
98
-     */
99
-    private static function _get_subtotal_for_admin(EE_Ticket $ticket)
100
-    {
101
-        $subtotal = 0;
102
-        // get all prices
103
-        $prices = $ticket->get_many_related(
104
-            'Price',
105
-            [
106
-                0 => [
107
-                    'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax],
108
-                ],
109
-                'default_where_conditions' => 'none',
110
-                'order_by'                 => ['PRC_order' => 'ASC'],
111
-            ]
112
-        );
113
-        // let's loop through them (base price is always the first item)
114
-        foreach ($prices as $price) {
115
-            if ($price instanceof EE_Price) {
116
-                $price_type = $price->type_obj();
117
-                if ($price_type instanceof EE_Price_Type) {
118
-                    switch ($price->type_obj()->base_type()) {
119
-                        case 1: // base price
120
-                        case 3: // surcharges
121
-                            $subtotal += $price->is_percent()
122
-                                ? $subtotal * $price->get('PRC_amount') / 100
123
-                                : $price->get('PRC_amount');
124
-                            break;
125
-                        case 2: // discounts
126
-                            $subtotal -= $price->is_percent()
127
-                                ? $subtotal * $price->get('PRC_amount') / 100
128
-                                : $price->get('PRC_amount');
129
-                            break;
130
-                    }
131
-                }
132
-            }
133
-        }
134
-        $TKT_ID = $ticket->ID();
135
-        EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal;
136
-        return $subtotal;
137
-    }
91
+	/**
92
+	 * simply take an incoming ticket and calculate the subtotal for the ticket
93
+	 *
94
+	 * @param EE_Ticket $ticket
95
+	 * @return float     subtotal calculated from all EE_Price[] on Ticket.
96
+	 * @throws EE_Error
97
+	 * @throws ReflectionException
98
+	 */
99
+	private static function _get_subtotal_for_admin(EE_Ticket $ticket)
100
+	{
101
+		$subtotal = 0;
102
+		// get all prices
103
+		$prices = $ticket->get_many_related(
104
+			'Price',
105
+			[
106
+				0 => [
107
+					'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax],
108
+				],
109
+				'default_where_conditions' => 'none',
110
+				'order_by'                 => ['PRC_order' => 'ASC'],
111
+			]
112
+		);
113
+		// let's loop through them (base price is always the first item)
114
+		foreach ($prices as $price) {
115
+			if ($price instanceof EE_Price) {
116
+				$price_type = $price->type_obj();
117
+				if ($price_type instanceof EE_Price_Type) {
118
+					switch ($price->type_obj()->base_type()) {
119
+						case 1: // base price
120
+						case 3: // surcharges
121
+							$subtotal += $price->is_percent()
122
+								? $subtotal * $price->get('PRC_amount') / 100
123
+								: $price->get('PRC_amount');
124
+							break;
125
+						case 2: // discounts
126
+							$subtotal -= $price->is_percent()
127
+								? $subtotal * $price->get('PRC_amount') / 100
128
+								: $price->get('PRC_amount');
129
+							break;
130
+					}
131
+				}
132
+			}
133
+		}
134
+		$TKT_ID = $ticket->ID();
135
+		EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal;
136
+		return $subtotal;
137
+	}
138 138
 
139 139
 
140
-    /**
141
-     * get all default prices that are a Tax price type (PRT_ID = 4) and return
142
-     *
143
-     * @return EE_Price[] EE_Price objects that have PRT_ID == 4
144
-     * @throws EE_Error
145
-     */
146
-    public static function get_taxes_for_admin(): array
147
-    {
148
-        if (empty(EE_Taxes::$_default_taxes)) {
149
-            /** @var EEM_Price $price_model */
150
-            $price_model = LoaderFactory::getLoader()->getShared('EEM_Price');
151
-            EE_Taxes::$_default_taxes = $price_model->get_all(
152
-                [['PRC_is_default' => 1, 'Price_Type.PBT_ID' => 4]]
153
-            );
154
-        }
155
-        return EE_Taxes::$_default_taxes;
156
-    }
140
+	/**
141
+	 * get all default prices that are a Tax price type (PRT_ID = 4) and return
142
+	 *
143
+	 * @return EE_Price[] EE_Price objects that have PRT_ID == 4
144
+	 * @throws EE_Error
145
+	 */
146
+	public static function get_taxes_for_admin(): array
147
+	{
148
+		if (empty(EE_Taxes::$_default_taxes)) {
149
+			/** @var EEM_Price $price_model */
150
+			$price_model = LoaderFactory::getLoader()->getShared('EEM_Price');
151
+			EE_Taxes::$_default_taxes = $price_model->get_all(
152
+				[['PRC_is_default' => 1, 'Price_Type.PBT_ID' => 4]]
153
+			);
154
+		}
155
+		return EE_Taxes::$_default_taxes;
156
+	}
157 157
 }
Please login to merge, or discard this patch.
core/interfaces/line_items/EE_Line_Item_Filter.interface.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@
 block discarded – undo
15 15
  */
16 16
 interface EE_Line_Item_Filter
17 17
 {
18
-    /**
19
-     * process
20
-     *
21
-     * @param EE_Line_Item $line_item
22
-     * @return EE_Line_Item
23
-     */
24
-    public function process(EE_Line_Item $line_item): ?EE_Line_Item;
18
+	/**
19
+	 * process
20
+	 *
21
+	 * @param EE_Line_Item $line_item
22
+	 * @return EE_Line_Item
23
+	 */
24
+	public function process(EE_Line_Item $line_item): ?EE_Line_Item;
25 25
 }
Please login to merge, or discard this patch.
core/domain/entities/tickets/TicketPriceModifiers.php 1 patch
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -20,234 +20,234 @@
 block discarded – undo
20 20
  */
21 21
 class TicketPriceModifiers
22 22
 {
23
-    /**
24
-     * @var EE_Ticket
25
-     */
26
-    private $ticket;
27
-
28
-
29
-    /**
30
-     * @var EE_Price[]
31
-     */
32
-    private $ticket_prices;
33
-
34
-
35
-    /**
36
-     * @param EE_Ticket $ticket
37
-     * @throws EE_Error
38
-     * @throws ReflectionException
39
-     */
40
-    public function __construct(EE_Ticket $ticket)
41
-    {
42
-        $this->ticket = $ticket;
43
-        // run a query to retrieve ALL of this ticket's related prices before doing anything else
44
-        $this->ticket_prices = $this->ticket->prices();
45
-    }
46
-
47
-
48
-    /**
49
-     * @param callable  $filter
50
-     * @return array
51
-     * @throws EE_Error
52
-     * @throws ReflectionException
53
-     */
54
-    private function filterModifiersForTicket(callable $filter): array
55
-    {
56
-        $ticket_modifiers = $this->ticket->get_all_from_cache('Price');
57
-        if (empty($ticket_modifiers)) {
58
-            $ticket_modifiers = $this->ticket_prices;
59
-        }
60
-        return array_filter($ticket_modifiers, $filter);
61
-    }
62
-
63
-
64
-    /**
65
-     * retrieve all price modifiers for the this ticket
66
-     *
67
-     * @return array
68
-     * @throws EE_Error
69
-     * @throws ReflectionException
70
-     */
71
-    public function getAllModifiersForTicket(): array
72
-    {
73
-        return $this->filterModifiersForTicket([$this, 'allModifiersFilter']);
74
-    }
75
-
76
-
77
-    /**
78
-     * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket
79
-     *
80
-     * @param EE_Price $price_modifier
81
-     * @return bool
82
-     * @throws EE_Error
83
-     * @throws ReflectionException
84
-     */
85
-    public function allModifiersFilter(EE_Price $price_modifier): bool
86
-    {
87
-        return ! $price_modifier->is_base_price();
88
-    }
89
-
90
-
91
-    /**
92
-     * retrieve all discounts for the this ticket
93
-     *
94
-     * @return array
95
-     * @throws EE_Error
96
-     * @throws ReflectionException
97
-     */
98
-    public function getAllDiscountModifiersForTicket(): array
99
-    {
100
-        return $this->filterModifiersForTicket([$this, 'discountModifierFilter']);
101
-    }
102
-
103
-
104
-    /**
105
-     * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket
106
-     *
107
-     * @param EE_Price $price_modifier
108
-     * @return bool
109
-     * @throws EE_Error
110
-     * @throws ReflectionException
111
-     */
112
-    public function discountModifierFilter(EE_Price $price_modifier): bool
113
-    {
114
-        return $price_modifier->is_discount();
115
-    }
116
-
117
-
118
-    /**
119
-     * retrieve all surcharges for the this ticket
120
-     *
121
-     * @return array
122
-     * @throws EE_Error
123
-     * @throws ReflectionException
124
-     */
125
-    public function getAllSurchargeModifiersForTicket(): array
126
-    {
127
-        return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']);
128
-    }
129
-
130
-
131
-    /**
132
-     * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket
133
-     *
134
-     * @param EE_Price $price_modifier
135
-     * @return bool
136
-     * @throws EE_Error
137
-     * @throws ReflectionException
138
-     */
139
-    public function surchargeModifierFilter(EE_Price $price_modifier): bool
140
-    {
141
-        return $price_modifier->is_surcharge();
142
-    }
143
-
144
-
145
-    /**
146
-     * retrieve all discounts AND surcharges for the this ticket
147
-     *
148
-     * @return array
149
-     * @throws EE_Error
150
-     * @throws ReflectionException
151
-     */
152
-    public function getAllDiscountAndSurchargeModifiersForTicket(): array
153
-    {
154
-        return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']);
155
-    }
156
-
157
-
158
-    /**
159
-     * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket
160
-     *
161
-     * @param EE_Price $price_modifier
162
-     * @return bool
163
-     * @throws EE_Error
164
-     * @throws ReflectionException
165
-     */
166
-    public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool
167
-    {
168
-        return $price_modifier->is_discount() || $price_modifier->is_surcharge();
169
-    }
170
-
171
-
172
-    /**
173
-     * retrieve all taxes for the this ticket
174
-     *
175
-     * @return array
176
-     * @throws EE_Error
177
-     * @throws ReflectionException
178
-     */
179
-    public function getAllTaxesForTicket(): array
180
-    {
181
-        return $this->filterModifiersForTicket([$this, 'taxModifierFilter']);
182
-    }
183
-
184
-
185
-    /**
186
-     * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket
187
-     *
188
-     * @param EE_Price $price_modifier
189
-     * @return bool
190
-     * @throws EE_Error
191
-     * @throws ReflectionException
192
-     */
193
-    public function taxModifierFilter(EE_Price $price_modifier): bool
194
-    {
195
-        return $price_modifier->is_tax();
196
-    }
197
-
198
-
199
-    /**
200
-     * retrieve ALL PRICES that are NOT taxes for the this ticket
201
-     *
202
-     * @return array
203
-     * @throws EE_Error
204
-     * @throws ReflectionException
205
-     */
206
-    public function getAllNonTaxPricesForTicket(): array
207
-    {
208
-        return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']);
209
-    }
210
-
211
-
212
-    /**
213
-     * pass to filterModifiersForTicket() with a ticket
214
-     * to retrieve ALL PRICES that are NOT taxes for the this ticket
215
-     *
216
-     * @param EE_Price $price_modifier
217
-     * @return bool
218
-     * @throws EE_Error
219
-     * @throws ReflectionException
220
-     */
221
-    public function nonTaxPriceFilter(EE_Price $price_modifier): bool
222
-    {
223
-        return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax();
224
-    }
225
-
226
-
227
-    /**
228
-     * retrieve the base price for the this ticket
229
-     *
230
-     * @return array
231
-     * @throws EE_Error
232
-     * @throws ReflectionException
233
-     */
234
-    public function getBasePrice(): array
235
-    {
236
-        return $this->filterModifiersForTicket([$this, 'basePriceFilter']);
237
-    }
238
-
239
-
240
-    /**
241
-     * pass to filterModifiersForTicket()
242
-     * to retrieve the base price for the this ticket
243
-     *
244
-     * @param EE_Price $price_modifier
245
-     * @return bool
246
-     * @throws EE_Error
247
-     * @throws ReflectionException
248
-     */
249
-    public function basePriceFilter(EE_Price $price_modifier): bool
250
-    {
251
-        return $price_modifier->is_base_price();
252
-    }
23
+	/**
24
+	 * @var EE_Ticket
25
+	 */
26
+	private $ticket;
27
+
28
+
29
+	/**
30
+	 * @var EE_Price[]
31
+	 */
32
+	private $ticket_prices;
33
+
34
+
35
+	/**
36
+	 * @param EE_Ticket $ticket
37
+	 * @throws EE_Error
38
+	 * @throws ReflectionException
39
+	 */
40
+	public function __construct(EE_Ticket $ticket)
41
+	{
42
+		$this->ticket = $ticket;
43
+		// run a query to retrieve ALL of this ticket's related prices before doing anything else
44
+		$this->ticket_prices = $this->ticket->prices();
45
+	}
46
+
47
+
48
+	/**
49
+	 * @param callable  $filter
50
+	 * @return array
51
+	 * @throws EE_Error
52
+	 * @throws ReflectionException
53
+	 */
54
+	private function filterModifiersForTicket(callable $filter): array
55
+	{
56
+		$ticket_modifiers = $this->ticket->get_all_from_cache('Price');
57
+		if (empty($ticket_modifiers)) {
58
+			$ticket_modifiers = $this->ticket_prices;
59
+		}
60
+		return array_filter($ticket_modifiers, $filter);
61
+	}
62
+
63
+
64
+	/**
65
+	 * retrieve all price modifiers for the this ticket
66
+	 *
67
+	 * @return array
68
+	 * @throws EE_Error
69
+	 * @throws ReflectionException
70
+	 */
71
+	public function getAllModifiersForTicket(): array
72
+	{
73
+		return $this->filterModifiersForTicket([$this, 'allModifiersFilter']);
74
+	}
75
+
76
+
77
+	/**
78
+	 * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket
79
+	 *
80
+	 * @param EE_Price $price_modifier
81
+	 * @return bool
82
+	 * @throws EE_Error
83
+	 * @throws ReflectionException
84
+	 */
85
+	public function allModifiersFilter(EE_Price $price_modifier): bool
86
+	{
87
+		return ! $price_modifier->is_base_price();
88
+	}
89
+
90
+
91
+	/**
92
+	 * retrieve all discounts for the this ticket
93
+	 *
94
+	 * @return array
95
+	 * @throws EE_Error
96
+	 * @throws ReflectionException
97
+	 */
98
+	public function getAllDiscountModifiersForTicket(): array
99
+	{
100
+		return $this->filterModifiersForTicket([$this, 'discountModifierFilter']);
101
+	}
102
+
103
+
104
+	/**
105
+	 * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket
106
+	 *
107
+	 * @param EE_Price $price_modifier
108
+	 * @return bool
109
+	 * @throws EE_Error
110
+	 * @throws ReflectionException
111
+	 */
112
+	public function discountModifierFilter(EE_Price $price_modifier): bool
113
+	{
114
+		return $price_modifier->is_discount();
115
+	}
116
+
117
+
118
+	/**
119
+	 * retrieve all surcharges for the this ticket
120
+	 *
121
+	 * @return array
122
+	 * @throws EE_Error
123
+	 * @throws ReflectionException
124
+	 */
125
+	public function getAllSurchargeModifiersForTicket(): array
126
+	{
127
+		return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']);
128
+	}
129
+
130
+
131
+	/**
132
+	 * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket
133
+	 *
134
+	 * @param EE_Price $price_modifier
135
+	 * @return bool
136
+	 * @throws EE_Error
137
+	 * @throws ReflectionException
138
+	 */
139
+	public function surchargeModifierFilter(EE_Price $price_modifier): bool
140
+	{
141
+		return $price_modifier->is_surcharge();
142
+	}
143
+
144
+
145
+	/**
146
+	 * retrieve all discounts AND surcharges for the this ticket
147
+	 *
148
+	 * @return array
149
+	 * @throws EE_Error
150
+	 * @throws ReflectionException
151
+	 */
152
+	public function getAllDiscountAndSurchargeModifiersForTicket(): array
153
+	{
154
+		return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']);
155
+	}
156
+
157
+
158
+	/**
159
+	 * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket
160
+	 *
161
+	 * @param EE_Price $price_modifier
162
+	 * @return bool
163
+	 * @throws EE_Error
164
+	 * @throws ReflectionException
165
+	 */
166
+	public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool
167
+	{
168
+		return $price_modifier->is_discount() || $price_modifier->is_surcharge();
169
+	}
170
+
171
+
172
+	/**
173
+	 * retrieve all taxes for the this ticket
174
+	 *
175
+	 * @return array
176
+	 * @throws EE_Error
177
+	 * @throws ReflectionException
178
+	 */
179
+	public function getAllTaxesForTicket(): array
180
+	{
181
+		return $this->filterModifiersForTicket([$this, 'taxModifierFilter']);
182
+	}
183
+
184
+
185
+	/**
186
+	 * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket
187
+	 *
188
+	 * @param EE_Price $price_modifier
189
+	 * @return bool
190
+	 * @throws EE_Error
191
+	 * @throws ReflectionException
192
+	 */
193
+	public function taxModifierFilter(EE_Price $price_modifier): bool
194
+	{
195
+		return $price_modifier->is_tax();
196
+	}
197
+
198
+
199
+	/**
200
+	 * retrieve ALL PRICES that are NOT taxes for the this ticket
201
+	 *
202
+	 * @return array
203
+	 * @throws EE_Error
204
+	 * @throws ReflectionException
205
+	 */
206
+	public function getAllNonTaxPricesForTicket(): array
207
+	{
208
+		return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']);
209
+	}
210
+
211
+
212
+	/**
213
+	 * pass to filterModifiersForTicket() with a ticket
214
+	 * to retrieve ALL PRICES that are NOT taxes for the this ticket
215
+	 *
216
+	 * @param EE_Price $price_modifier
217
+	 * @return bool
218
+	 * @throws EE_Error
219
+	 * @throws ReflectionException
220
+	 */
221
+	public function nonTaxPriceFilter(EE_Price $price_modifier): bool
222
+	{
223
+		return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax();
224
+	}
225
+
226
+
227
+	/**
228
+	 * retrieve the base price for the this ticket
229
+	 *
230
+	 * @return array
231
+	 * @throws EE_Error
232
+	 * @throws ReflectionException
233
+	 */
234
+	public function getBasePrice(): array
235
+	{
236
+		return $this->filterModifiersForTicket([$this, 'basePriceFilter']);
237
+	}
238
+
239
+
240
+	/**
241
+	 * pass to filterModifiersForTicket()
242
+	 * to retrieve the base price for the this ticket
243
+	 *
244
+	 * @param EE_Price $price_modifier
245
+	 * @return bool
246
+	 * @throws EE_Error
247
+	 * @throws ReflectionException
248
+	 */
249
+	public function basePriceFilter(EE_Price $price_modifier): bool
250
+	{
251
+		return $price_modifier->is_base_price();
252
+	}
253 253
 }
Please login to merge, or discard this patch.
line_item_filters/EE_Specific_Registrations_Line_Item_Filter.class.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
                 'LIN_code'
76 76
             );
77 77
             if ($line_item_code) {
78
-                if (! isset($this->_line_item_registrations[ $line_item_code ])) {
79
-                    $this->_line_item_registrations[ $line_item_code ] = array();
78
+                if ( ! isset($this->_line_item_registrations[$line_item_code])) {
79
+                    $this->_line_item_registrations[$line_item_code] = array();
80 80
                 }
81
-                $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
81
+                $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
82 82
             }
83 83
         }
84 84
     }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     public function process(EE_Line_Item $line_item): ?EE_Line_Item
97 97
     {
98 98
         $this->_adjust_line_item_quantity($line_item);
99
-        if (! $line_item->children()) {
99
+        if ( ! $line_item->children()) {
100 100
             return $line_item;
101 101
         }
102 102
         // the original running total (taking ALL tickets into account)
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 $child_line_item->set_total(
124 124
                     $running_total_of_children_under_consideration * $percent_of_running_total
125 125
                 );
126
-                if (! $child_line_item->is_percent()) {
126
+                if ( ! $child_line_item->is_percent()) {
127 127
                     $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
128 128
                 }
129 129
             } elseif (
@@ -186,11 +186,11 @@  discard block
 block discarded – undo
186 186
             $quantity = 0;
187 187
             // if this ticket is billable at this moment, then we should have a positive quantity
188 188
             if (
189
-                isset($this->_line_item_registrations[ $line_item->code() ])
190
-                && is_array($this->_line_item_registrations[ $line_item->code() ])
189
+                isset($this->_line_item_registrations[$line_item->code()])
190
+                && is_array($this->_line_item_registrations[$line_item->code()])
191 191
             ) {
192 192
                 // set quantity based on number of open registrations for this ticket
193
-                foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
193
+                foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194 194
                     if (
195 195
                         $registration instanceof EE_Registration
196 196
                     ) {
Please login to merge, or discard this patch.
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -12,195 +12,195 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base
14 14
 {
15
-    /**
16
-     * array of line item codes and their corresponding quantities for registrations
17
-     *
18
-     * @type array $_line_item_registrations
19
-     */
20
-    protected $_line_item_registrations = array();
15
+	/**
16
+	 * array of line item codes and their corresponding quantities for registrations
17
+	 *
18
+	 * @type array $_line_item_registrations
19
+	 */
20
+	protected $_line_item_registrations = array();
21 21
 
22
-    /**
23
-     * Just kept in case we want it someday. Currently unused
24
-     *
25
-     * @var EE_Registration[]
26
-     */
27
-    protected $_registrations = array();
22
+	/**
23
+	 * Just kept in case we want it someday. Currently unused
24
+	 *
25
+	 * @var EE_Registration[]
26
+	 */
27
+	protected $_registrations = array();
28 28
 
29
-    /**
30
-     * @var EE_Registration
31
-     */
32
-    protected $_current_registration;
29
+	/**
30
+	 * @var EE_Registration
31
+	 */
32
+	protected $_current_registration;
33 33
 
34
-    /**
35
-     * these reg statuses should NOT increment the line item quantity
36
-     *
37
-     * @var array
38
-     */
39
-    protected $_closed_reg_statuses = array();
34
+	/**
35
+	 * these reg statuses should NOT increment the line item quantity
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $_closed_reg_statuses = array();
40 40
 
41 41
 
42
-    /**
43
-     * EE_Billable_Line_Item_Filter constructor.
44
-     *
45
-     * @param EE_Registration[] $registrations
46
-     * @throws EE_Error
47
-     * @throws ReflectionException
48
-     */
49
-    public function __construct(array $registrations)
50
-    {
51
-        $this->_registrations = $registrations;
52
-        $this->_calculate_registrations_per_line_item_code($registrations);
53
-        // these reg statuses should NOT increment the line item quantity
54
-        $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
55
-    }
42
+	/**
43
+	 * EE_Billable_Line_Item_Filter constructor.
44
+	 *
45
+	 * @param EE_Registration[] $registrations
46
+	 * @throws EE_Error
47
+	 * @throws ReflectionException
48
+	 */
49
+	public function __construct(array $registrations)
50
+	{
51
+		$this->_registrations = $registrations;
52
+		$this->_calculate_registrations_per_line_item_code($registrations);
53
+		// these reg statuses should NOT increment the line item quantity
54
+		$this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * sets the _line_item_registrations from the provided registrations
60
-     *
61
-     * @param EE_Registration[] $registrations
62
-     * @return void
63
-     * @throws EE_Error
64
-     * @throws ReflectionException
65
-     */
66
-    protected function _calculate_registrations_per_line_item_code(array $registrations)
67
-    {
68
-        foreach ($registrations as $registration) {
69
-            $line_item_code = EEM_Line_Item::instance()->get_var(
70
-                EEM_Line_Item::instance()->line_item_for_registration_query_params(
71
-                    $registration,
72
-                    array('limit' => 1)
73
-                ),
74
-                'LIN_code'
75
-            );
76
-            if ($line_item_code) {
77
-                if (! isset($this->_line_item_registrations[ $line_item_code ])) {
78
-                    $this->_line_item_registrations[ $line_item_code ] = array();
79
-                }
80
-                $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
81
-            }
82
-        }
83
-    }
58
+	/**
59
+	 * sets the _line_item_registrations from the provided registrations
60
+	 *
61
+	 * @param EE_Registration[] $registrations
62
+	 * @return void
63
+	 * @throws EE_Error
64
+	 * @throws ReflectionException
65
+	 */
66
+	protected function _calculate_registrations_per_line_item_code(array $registrations)
67
+	{
68
+		foreach ($registrations as $registration) {
69
+			$line_item_code = EEM_Line_Item::instance()->get_var(
70
+				EEM_Line_Item::instance()->line_item_for_registration_query_params(
71
+					$registration,
72
+					array('limit' => 1)
73
+				),
74
+				'LIN_code'
75
+			);
76
+			if ($line_item_code) {
77
+				if (! isset($this->_line_item_registrations[ $line_item_code ])) {
78
+					$this->_line_item_registrations[ $line_item_code ] = array();
79
+				}
80
+				$this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration;
81
+			}
82
+		}
83
+	}
84 84
 
85 85
 
86
-    /**
87
-     * Creates a duplicate of the line item tree, except only includes billable items
88
-     * and the portion of line items attributed to billable things
89
-     *
90
-     * @param EE_Line_Item $line_item
91
-     * @return EE_Line_Item
92
-     * @throws EE_Error
93
-     * @throws ReflectionException
94
-     */
95
-    public function process(EE_Line_Item $line_item): ?EE_Line_Item
96
-    {
97
-        $this->_adjust_line_item_quantity($line_item);
98
-        if (! $line_item->children()) {
99
-            return $line_item;
100
-        }
101
-        // the original running total (taking ALL tickets into account)
102
-        $running_total_of_children = 0;
103
-        // the new running total (only taking the specified ticket quantities into account)
104
-        $running_total_of_children_under_consideration = 0;
105
-        // let's also track the quantity of tickets that pertain to the registrations
106
-        $total_child_ticket_quantity = 0;
107
-        foreach ($line_item->children() as $child_line_item) {
108
-            $original_li_total = $child_line_item->is_percent()
109
-                ? $running_total_of_children * $child_line_item->percent() / 100
110
-                : $child_line_item->unit_price() * $child_line_item->quantity();
111
-            $this->process($child_line_item);
112
-            // If this line item is a normal line item that isn't for a ticket,
113
-            // we want to modify its total (and unit price if not a percentage line item)
114
-            // so it reflects only that portion of the surcharge/discount shared by these registrations
115
-            if (
116
-                $child_line_item->type() === EEM_Line_Item::type_line_item
117
-                && $child_line_item->OBJ_type() !== 'Ticket'
118
-            ) {
119
-                $percent_of_running_total = $running_total_of_children
120
-                    ? $original_li_total / $running_total_of_children
121
-                    : 0;
122
-                $child_line_item->set_total(
123
-                    $running_total_of_children_under_consideration * $percent_of_running_total
124
-                );
125
-                if (! $child_line_item->is_percent()) {
126
-                    $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
127
-                }
128
-            } elseif (
129
-                // make sure this item's quantity and total matches its parent
130
-                $line_item->type() === EEM_Line_Item::type_line_item
131
-                && $line_item->OBJ_type() === 'Ticket'
132
-                // but not if it's a percentage modifier
133
-                && ! $child_line_item->is_percent()
134
-                && ! (
135
-                    // or a cancellation
136
-                    $child_line_item->is_cancelled()
137
-                    && ! (
138
-                        // unless it IS a cancellation and the current registration is cancelled
139
-                        $child_line_item->is_cancelled()
140
-                        && $this->_current_registration instanceof EE_Registration
141
-                        && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
142
-                    )
143
-                )
144
-            ) {
145
-                $child_line_item->set_quantity($line_item->quantity());
146
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
147
-            } elseif ($child_line_item->type() === EEM_Line_Item::type_sub_tax) {
148
-                // add this line item's portion of any directly applied taxes
149
-                $child_line_item->set_quantity($line_item->quantity());
150
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
151
-            }
152
-            $running_total_of_children += $original_li_total;
153
-            $running_total_of_children_under_consideration += $child_line_item->total();
154
-            if ($child_line_item->OBJ_type() === 'Ticket') {
155
-                $total_child_ticket_quantity += $child_line_item->quantity();
156
-            }
157
-        }
158
-        $line_item->set_total($running_total_of_children_under_consideration);
159
-        if ($line_item->quantity()) {
160
-            $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
161
-        } else {
162
-            $line_item->set_unit_price(0);
163
-        }
164
-        if ($line_item->OBJ_type() === 'Event') {
165
-            $line_item->set_quantity($total_child_ticket_quantity);
166
-        }
167
-        return $line_item;
168
-    }
86
+	/**
87
+	 * Creates a duplicate of the line item tree, except only includes billable items
88
+	 * and the portion of line items attributed to billable things
89
+	 *
90
+	 * @param EE_Line_Item $line_item
91
+	 * @return EE_Line_Item
92
+	 * @throws EE_Error
93
+	 * @throws ReflectionException
94
+	 */
95
+	public function process(EE_Line_Item $line_item): ?EE_Line_Item
96
+	{
97
+		$this->_adjust_line_item_quantity($line_item);
98
+		if (! $line_item->children()) {
99
+			return $line_item;
100
+		}
101
+		// the original running total (taking ALL tickets into account)
102
+		$running_total_of_children = 0;
103
+		// the new running total (only taking the specified ticket quantities into account)
104
+		$running_total_of_children_under_consideration = 0;
105
+		// let's also track the quantity of tickets that pertain to the registrations
106
+		$total_child_ticket_quantity = 0;
107
+		foreach ($line_item->children() as $child_line_item) {
108
+			$original_li_total = $child_line_item->is_percent()
109
+				? $running_total_of_children * $child_line_item->percent() / 100
110
+				: $child_line_item->unit_price() * $child_line_item->quantity();
111
+			$this->process($child_line_item);
112
+			// If this line item is a normal line item that isn't for a ticket,
113
+			// we want to modify its total (and unit price if not a percentage line item)
114
+			// so it reflects only that portion of the surcharge/discount shared by these registrations
115
+			if (
116
+				$child_line_item->type() === EEM_Line_Item::type_line_item
117
+				&& $child_line_item->OBJ_type() !== 'Ticket'
118
+			) {
119
+				$percent_of_running_total = $running_total_of_children
120
+					? $original_li_total / $running_total_of_children
121
+					: 0;
122
+				$child_line_item->set_total(
123
+					$running_total_of_children_under_consideration * $percent_of_running_total
124
+				);
125
+				if (! $child_line_item->is_percent()) {
126
+					$child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
127
+				}
128
+			} elseif (
129
+				// make sure this item's quantity and total matches its parent
130
+				$line_item->type() === EEM_Line_Item::type_line_item
131
+				&& $line_item->OBJ_type() === 'Ticket'
132
+				// but not if it's a percentage modifier
133
+				&& ! $child_line_item->is_percent()
134
+				&& ! (
135
+					// or a cancellation
136
+					$child_line_item->is_cancelled()
137
+					&& ! (
138
+						// unless it IS a cancellation and the current registration is cancelled
139
+						$child_line_item->is_cancelled()
140
+						&& $this->_current_registration instanceof EE_Registration
141
+						&& in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
142
+					)
143
+				)
144
+			) {
145
+				$child_line_item->set_quantity($line_item->quantity());
146
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
147
+			} elseif ($child_line_item->type() === EEM_Line_Item::type_sub_tax) {
148
+				// add this line item's portion of any directly applied taxes
149
+				$child_line_item->set_quantity($line_item->quantity());
150
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
151
+			}
152
+			$running_total_of_children += $original_li_total;
153
+			$running_total_of_children_under_consideration += $child_line_item->total();
154
+			if ($child_line_item->OBJ_type() === 'Ticket') {
155
+				$total_child_ticket_quantity += $child_line_item->quantity();
156
+			}
157
+		}
158
+		$line_item->set_total($running_total_of_children_under_consideration);
159
+		if ($line_item->quantity()) {
160
+			$line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
161
+		} else {
162
+			$line_item->set_unit_price(0);
163
+		}
164
+		if ($line_item->OBJ_type() === 'Event') {
165
+			$line_item->set_quantity($total_child_ticket_quantity);
166
+		}
167
+		return $line_item;
168
+	}
169 169
 
170 170
 
171
-    /**
172
-     * Adjusts quantities for line items for tickets according to the registrations provided
173
-     * in the constructor
174
-     *
175
-     * @param EE_Line_Item $line_item
176
-     * @return EE_Line_Item
177
-     * @throws EE_Error
178
-     * @throws ReflectionException
179
-     */
180
-    protected function _adjust_line_item_quantity(EE_Line_Item $line_item): EE_Line_Item
181
-    {
182
-        // is this a ticket ?
183
-        if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
184
-            $this->_current_registration = null;
185
-            $quantity = 0;
186
-            // if this ticket is billable at this moment, then we should have a positive quantity
187
-            if (
188
-                isset($this->_line_item_registrations[ $line_item->code() ])
189
-                && is_array($this->_line_item_registrations[ $line_item->code() ])
190
-            ) {
191
-                // set quantity based on number of open registrations for this ticket
192
-                foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
193
-                    if (
194
-                        $registration instanceof EE_Registration
195
-                    ) {
196
-                        $quantity++;
197
-                        $this->_current_registration = $registration;
198
-                    }
199
-                }
200
-            }
201
-            $line_item->set_quantity($quantity);
202
-            $line_item->set_total($line_item->unit_price() * $line_item->quantity());
203
-        }
204
-        return $line_item;
205
-    }
171
+	/**
172
+	 * Adjusts quantities for line items for tickets according to the registrations provided
173
+	 * in the constructor
174
+	 *
175
+	 * @param EE_Line_Item $line_item
176
+	 * @return EE_Line_Item
177
+	 * @throws EE_Error
178
+	 * @throws ReflectionException
179
+	 */
180
+	protected function _adjust_line_item_quantity(EE_Line_Item $line_item): EE_Line_Item
181
+	{
182
+		// is this a ticket ?
183
+		if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
184
+			$this->_current_registration = null;
185
+			$quantity = 0;
186
+			// if this ticket is billable at this moment, then we should have a positive quantity
187
+			if (
188
+				isset($this->_line_item_registrations[ $line_item->code() ])
189
+				&& is_array($this->_line_item_registrations[ $line_item->code() ])
190
+			) {
191
+				// set quantity based on number of open registrations for this ticket
192
+				foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) {
193
+					if (
194
+						$registration instanceof EE_Registration
195
+					) {
196
+						$quantity++;
197
+						$this->_current_registration = $registration;
198
+					}
199
+				}
200
+			}
201
+			$line_item->set_quantity($quantity);
202
+			$line_item->set_total($line_item->unit_price() * $line_item->quantity());
203
+		}
204
+		return $line_item;
205
+	}
206 206
 }
Please login to merge, or discard this patch.
core/libraries/line_item_filters/EE_Billable_Line_Item_Filter.class.php 2 patches
Spacing   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -43,17 +43,16 @@  discard block
 block discarded – undo
43 43
      */
44 44
     protected function _remove_unbillable_registrations(array $registrations = array()): array
45 45
     {
46
-        if (! empty($registrations)) {
46
+        if ( ! empty($registrations)) {
47 47
             // these reg statuses require payment (if event is not free)
48 48
             $requires_payment = EEM_Registration::reg_statuses_that_allow_payment();
49 49
             foreach ($registrations as $key => $registration) {
50
-                if (! $registration instanceof EE_Registration) {
50
+                if ( ! $registration instanceof EE_Registration) {
51 51
                     continue;
52 52
                 }
53 53
                 // are we billing for this registration at this moment ?
54 54
                 if (
55
-                    !
56
-                    $registration->owes_monies_and_can_pay($requires_payment) &&
55
+                    ! $registration->owes_monies_and_can_pay($requires_payment) &&
57 56
                     ! (
58 57
                         // free registration with valid reg status
59 58
                         $registration->final_price() == 0 &&
@@ -61,7 +60,7 @@  discard block
 block discarded – undo
61 60
                     )
62 61
                 ) {
63 62
                     // not billable. remove it
64
-                    unset($registrations[ $key ]);
63
+                    unset($registrations[$key]);
65 64
                 }
66 65
             }
67 66
         }
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -16,53 +16,53 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Billable_Line_Item_Filter extends EE_Specific_Registrations_Line_Item_Filter
18 18
 {
19
-    /**
20
-     * EE_Billable_Line_Item_Filter constructor.
21
-     *
22
-     * @param EE_Registration[] $registrations
23
-     * @throws EE_Error
24
-     * @throws EE_Error
25
-     */
26
-    public function __construct($registrations)
27
-    {
28
-        parent::__construct($this->_remove_unbillable_registrations($registrations));
29
-    }
19
+	/**
20
+	 * EE_Billable_Line_Item_Filter constructor.
21
+	 *
22
+	 * @param EE_Registration[] $registrations
23
+	 * @throws EE_Error
24
+	 * @throws EE_Error
25
+	 */
26
+	public function __construct($registrations)
27
+	{
28
+		parent::__construct($this->_remove_unbillable_registrations($registrations));
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     *    _calculate_billable_ticket_quantities_from_registrations
34
-     * compiles a list of EE_Tickets for each event in the passed array
35
-     *
36
-     * @access protected
37
-     * @param EE_Registration[] $registrations
38
-     * @return EE_Registration[]
39
-     * @throws EE_Error
40
-     * @throws EE_Error
41
-     */
42
-    protected function _remove_unbillable_registrations(array $registrations = array()): array
43
-    {
44
-        if (! empty($registrations)) {
45
-            // these reg statuses require payment (if event is not free)
46
-            $requires_payment = EEM_Registration::reg_statuses_that_allow_payment();
47
-            foreach ($registrations as $key => $registration) {
48
-                if (! $registration instanceof EE_Registration) {
49
-                    continue;
50
-                }
51
-                // are we billing for this registration at this moment ?
52
-                if (
53
-                    !
54
-                    $registration->owes_monies_and_can_pay($requires_payment) &&
55
-                    ! (
56
-                        // free registration with valid reg status
57
-                        $registration->final_price() == 0 &&
58
-                        in_array($registration->status_ID(), $requires_payment)
59
-                    )
60
-                ) {
61
-                    // not billable. remove it
62
-                    unset($registrations[ $key ]);
63
-                }
64
-            }
65
-        }
66
-        return $registrations;
67
-    }
32
+	/**
33
+	 *    _calculate_billable_ticket_quantities_from_registrations
34
+	 * compiles a list of EE_Tickets for each event in the passed array
35
+	 *
36
+	 * @access protected
37
+	 * @param EE_Registration[] $registrations
38
+	 * @return EE_Registration[]
39
+	 * @throws EE_Error
40
+	 * @throws EE_Error
41
+	 */
42
+	protected function _remove_unbillable_registrations(array $registrations = array()): array
43
+	{
44
+		if (! empty($registrations)) {
45
+			// these reg statuses require payment (if event is not free)
46
+			$requires_payment = EEM_Registration::reg_statuses_that_allow_payment();
47
+			foreach ($registrations as $key => $registration) {
48
+				if (! $registration instanceof EE_Registration) {
49
+					continue;
50
+				}
51
+				// are we billing for this registration at this moment ?
52
+				if (
53
+					!
54
+					$registration->owes_monies_and_can_pay($requires_payment) &&
55
+					! (
56
+						// free registration with valid reg status
57
+						$registration->final_price() == 0 &&
58
+						in_array($registration->status_ID(), $requires_payment)
59
+					)
60
+				) {
61
+					// not billable. remove it
62
+					unset($registrations[ $key ]);
63
+				}
64
+			}
65
+		}
66
+		return $registrations;
67
+	}
68 68
 }
Please login to merge, or discard this patch.
core/libraries/line_item_filters/EE_Non_Zero_Line_Item_Filter.class.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     public function process(EE_Line_Item $line_item): ?EE_Line_Item
35 35
     {
36 36
         $non_zero_line_item = $this->_filter_zero_line_item($line_item);
37
-        if (! $non_zero_line_item instanceof EE_Line_Item) {
37
+        if ( ! $non_zero_line_item instanceof EE_Line_Item) {
38 38
             return null;
39 39
         }
40 40
         // if this is an event subtotal, we want to only include it if it
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             foreach ($line_item->children() as $child_line_item) {
45 45
                 $code = $child_line_item->code();
46 46
                 $child_line_item = $this->process($child_line_item);
47
-                if (! $child_line_item instanceof EE_Line_Item) {
47
+                if ( ! $child_line_item instanceof EE_Line_Item) {
48 48
                     $line_item->delete_child_line_item($code);
49 49
                     continue;
50 50
                 }
Please login to merge, or discard this patch.
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -13,104 +13,104 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Non_Zero_Line_Item_Filter extends EE_Line_Item_Filter_Base
15 15
 {
16
-    /**
17
-     * EE_Non_Zero_Line_Item_Filter constructor.
18
-     */
19
-    public function __construct()
20
-    {
21
-    }
16
+	/**
17
+	 * EE_Non_Zero_Line_Item_Filter constructor.
18
+	 */
19
+	public function __construct()
20
+	{
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * Creates a duplicate of the line item tree, except only includes billable items
26
-     * and the portion of line items attributed to billable things
27
-     *
28
-     * @param EE_Line_Item $line_item
29
-     * @return EE_Line_Item
30
-     * @throws EE_Error
31
-     * @throws ReflectionException
32
-     */
33
-    public function process(EE_Line_Item $line_item): ?EE_Line_Item
34
-    {
35
-        $non_zero_line_item = $this->_filter_zero_line_item($line_item);
36
-        if (! $non_zero_line_item instanceof EE_Line_Item) {
37
-            return null;
38
-        }
39
-        // if this is an event subtotal, we want to only include it if it
40
-        // has a non-zero total and at least one ticket line item child
41
-        if ($line_item->children()) {
42
-            $ticket_or_subtotals_with_tkt_children_count = 0;
43
-            foreach ($line_item->children() as $child_line_item) {
44
-                $code = $child_line_item->code();
45
-                $child_line_item = $this->process($child_line_item);
46
-                if (! $child_line_item instanceof EE_Line_Item) {
47
-                    $line_item->delete_child_line_item($code);
48
-                    continue;
49
-                }
50
-                if (
51
-                    (
52
-                        $child_line_item instanceof EEI_Line_Item
53
-                        && $child_line_item->type() === EEM_Line_Item::type_sub_total
54
-                    )
55
-                    || (
56
-                        $child_line_item->type() === EEM_Line_Item::type_line_item
57
-                        && $child_line_item->OBJ_type() === 'Ticket'
58
-                    )
59
-                ) {
60
-                    $ticket_or_subtotals_with_tkt_children_count++;
61
-                }
62
-            }
63
-            // if this is an event subtotal with NO ticket children
64
-            // we basically want to ignore it
65
-            return $this->_filter_zero_subtotal_line_item(
66
-                $non_zero_line_item,
67
-                $ticket_or_subtotals_with_tkt_children_count
68
-            );
69
-        }
70
-        return $non_zero_line_item;
71
-    }
24
+	/**
25
+	 * Creates a duplicate of the line item tree, except only includes billable items
26
+	 * and the portion of line items attributed to billable things
27
+	 *
28
+	 * @param EE_Line_Item $line_item
29
+	 * @return EE_Line_Item
30
+	 * @throws EE_Error
31
+	 * @throws ReflectionException
32
+	 */
33
+	public function process(EE_Line_Item $line_item): ?EE_Line_Item
34
+	{
35
+		$non_zero_line_item = $this->_filter_zero_line_item($line_item);
36
+		if (! $non_zero_line_item instanceof EE_Line_Item) {
37
+			return null;
38
+		}
39
+		// if this is an event subtotal, we want to only include it if it
40
+		// has a non-zero total and at least one ticket line item child
41
+		if ($line_item->children()) {
42
+			$ticket_or_subtotals_with_tkt_children_count = 0;
43
+			foreach ($line_item->children() as $child_line_item) {
44
+				$code = $child_line_item->code();
45
+				$child_line_item = $this->process($child_line_item);
46
+				if (! $child_line_item instanceof EE_Line_Item) {
47
+					$line_item->delete_child_line_item($code);
48
+					continue;
49
+				}
50
+				if (
51
+					(
52
+						$child_line_item instanceof EEI_Line_Item
53
+						&& $child_line_item->type() === EEM_Line_Item::type_sub_total
54
+					)
55
+					|| (
56
+						$child_line_item->type() === EEM_Line_Item::type_line_item
57
+						&& $child_line_item->OBJ_type() === 'Ticket'
58
+					)
59
+				) {
60
+					$ticket_or_subtotals_with_tkt_children_count++;
61
+				}
62
+			}
63
+			// if this is an event subtotal with NO ticket children
64
+			// we basically want to ignore it
65
+			return $this->_filter_zero_subtotal_line_item(
66
+				$non_zero_line_item,
67
+				$ticket_or_subtotals_with_tkt_children_count
68
+			);
69
+		}
70
+		return $non_zero_line_item;
71
+	}
72 72
 
73 73
 
74
-    /**
75
-     * Creates a new, unsaved line item, but if it's a ticket line item
76
-     * with a total of 0, or a subtotal of 0, returns null instead
77
-     *
78
-     * @param EE_Line_Item $line_item
79
-     * @return EE_Line_Item
80
-     * @throws EE_Error
81
-     * @throws ReflectionException
82
-     */
83
-    protected function _filter_zero_line_item(EE_Line_Item $line_item): ?EE_Line_Item
84
-    {
85
-        if (
86
-            $line_item->type() === EEM_Line_Item::type_line_item
87
-            && $line_item->OBJ_type() === 'Ticket'
88
-            && $line_item->quantity() === 0
89
-        ) {
90
-            return null;
91
-        }
92
-        return $line_item;
93
-    }
74
+	/**
75
+	 * Creates a new, unsaved line item, but if it's a ticket line item
76
+	 * with a total of 0, or a subtotal of 0, returns null instead
77
+	 *
78
+	 * @param EE_Line_Item $line_item
79
+	 * @return EE_Line_Item
80
+	 * @throws EE_Error
81
+	 * @throws ReflectionException
82
+	 */
83
+	protected function _filter_zero_line_item(EE_Line_Item $line_item): ?EE_Line_Item
84
+	{
85
+		if (
86
+			$line_item->type() === EEM_Line_Item::type_line_item
87
+			&& $line_item->OBJ_type() === 'Ticket'
88
+			&& $line_item->quantity() === 0
89
+		) {
90
+			return null;
91
+		}
92
+		return $line_item;
93
+	}
94 94
 
95 95
 
96
-    /**
97
-     * Creates a new, unsaved line item, but if it's a ticket line item
98
-     * with a total of 0, or a subtotal of 0, returns null instead
99
-     *
100
-     * @param EE_Line_Item $line_item
101
-     * @param int          $ticket_children
102
-     * @return EE_Line_Item
103
-     * @throws EE_Error
104
-     * @throws ReflectionException
105
-     */
106
-    protected function _filter_zero_subtotal_line_item(EE_Line_Item $line_item, int $ticket_children = 0): ?EE_Line_Item
107
-    {
108
-        if (
109
-            (int) $ticket_children === 0
110
-            && $line_item->type() === EEM_Line_Item::type_sub_total
111
-        ) {
112
-            return null;
113
-        }
114
-        return $line_item;
115
-    }
96
+	/**
97
+	 * Creates a new, unsaved line item, but if it's a ticket line item
98
+	 * with a total of 0, or a subtotal of 0, returns null instead
99
+	 *
100
+	 * @param EE_Line_Item $line_item
101
+	 * @param int          $ticket_children
102
+	 * @return EE_Line_Item
103
+	 * @throws EE_Error
104
+	 * @throws ReflectionException
105
+	 */
106
+	protected function _filter_zero_subtotal_line_item(EE_Line_Item $line_item, int $ticket_children = 0): ?EE_Line_Item
107
+	{
108
+		if (
109
+			(int) $ticket_children === 0
110
+			&& $line_item->type() === EEM_Line_Item::type_sub_total
111
+		) {
112
+			return null;
113
+		}
114
+		return $line_item;
115
+	}
116 116
 }
Please login to merge, or discard this patch.
line_item_display/EE_Default_Line_Item_Display_Strategy.strategy.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         $html = '';
77 77
         // set some default options and merge with incoming
78 78
         $default_options = array(
79
-            'show_desc' => true,  //    TRUE        FALSE
79
+            'show_desc' => true, //    TRUE        FALSE
80 80
             'odd' => false
81 81
         );
82 82
         $options = array_merge($default_options, (array) $options);
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         );
164 164
         $name_and_desc .= apply_filters(
165 165
             'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
166
-            ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
166
+            ($options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''),
167 167
             $line_item,
168 168
             $options
169 169
         );
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
             $includes_taxes = $this->prices_include_taxes
172 172
                 ? esc_html__('* price includes taxes', 'event_espresso')
173 173
                 : esc_html__('* price does not include taxes', 'event_espresso');
174
-            $name_and_desc .= '<br /><span class="smaller-text grey-text">' . $includes_taxes . '</span>';
174
+            $name_and_desc .= '<br /><span class="smaller-text grey-text">'.$includes_taxes.'</span>';
175 175
         }
176 176
 
177 177
         // name td
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
         $html = EEH_HTML::tr('', 'item sub-item-row');
229 229
         // name && desc
230 230
         $name_and_desc = $line_item->name();
231
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
231
+        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : '';
232 232
         // name td
233 233
         $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
234 234
         // discount/surcharge td
235 235
         if ($line_item->is_percent()) {
236
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
236
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c');
237 237
         } else {
238 238
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
239 239
         }
Please login to merge, or discard this patch.
Indentation   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -1,248 +1,248 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
  /**
4
- *
5
- * Class EE_Default_Line_Item_Display_Strategy
6
- *
7
- * Description
8
- *
9
- * @package         Event Espresso
10
- * @subpackage    core
11
- * @author              Brent Christensen
12
- *
13
- *
14
- */
4
+  *
5
+  * Class EE_Default_Line_Item_Display_Strategy
6
+  *
7
+  * Description
8
+  *
9
+  * @package         Event Espresso
10
+  * @subpackage    core
11
+  * @author              Brent Christensen
12
+  *
13
+  *
14
+  */
15 15
 
16 16
 class EE_Default_Line_Item_Display_Strategy implements EEI_Line_Item_Display
17 17
 {
18
-    /**
19
-     * @var bool
20
-     */
21
-    protected $prices_include_taxes = false;
22
-
23
-    /**
24
-     * total amount of tax to apply
25
-     * @type float $_tax_rate
26
-     */
27
-    private $_tax_rate = 0;
28
-
29
-    /**
30
-     * total amount including tax we can bill for at this time
31
-     * @type float $_grand_total
32
-     */
33
-    private $_grand_total = 0.00;
34
-
35
-    /**
36
-     * total number of items being billed for
37
-     * @type int $_total_items
38
-     */
39
-    private $_total_items = 0;
40
-
41
-
42
-    public function __construct()
43
-    {
44
-        $this->prices_include_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes;
45
-    }
46
-
47
-
48
-    /**
49
-     * @return float
50
-     */
51
-    public function grand_total()
52
-    {
53
-        return $this->_grand_total;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * @return int
60
-     */
61
-    public function total_items()
62
-    {
63
-        return $this->_total_items;
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     * @param EE_Line_Item $line_item
70
-     * @param array        $options
71
-     * @return mixed
72
-     */
73
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
74
-    {
75
-
76
-        $html = '';
77
-        // set some default options and merge with incoming
78
-        $default_options = array(
79
-            'show_desc' => true,  //    TRUE        FALSE
80
-            'odd' => false
81
-        );
82
-        $options = array_merge($default_options, (array) $options);
83
-
84
-        switch ($line_item->type()) {
85
-            case EEM_Line_Item::type_line_item:
86
-                // item row
87
-                $html .= $this->_item_row($line_item, $options);
88
-                // got any kids?
89
-                foreach ($line_item->children() as $child_line_item) {
90
-                    $this->display_line_item($child_line_item, $options);
91
-                }
92
-                break;
93
-
94
-            case EEM_Line_Item::type_sub_line_item:
95
-                $html .= $this->_sub_item_row($line_item, $options);
96
-                break;
97
-
98
-            case EEM_Line_Item::type_sub_total:
99
-                break;
100
-
101
-            case EEM_Line_Item::type_tax:
102
-                $this->_tax_rate += $line_item->percent();
103
-                break;
104
-
105
-            case EEM_Line_Item::type_tax_sub_total:
106
-                foreach ($line_item->children() as $child_line_item) {
107
-                    if ($child_line_item->type() == EEM_Line_Item::type_tax) {
108
-                        // recursively feed children back into this method
109
-                        $this->display_line_item($child_line_item, $options);
110
-                    }
111
-                }
112
-                break;
113
-
114
-            case EEM_Line_Item::type_total:
115
-                // get all child line items
116
-                $children = $line_item->children();
117
-                if ($options['set_tax_rate'] === true) {
118
-                    // loop thru tax child line items just to determine tax rate
119
-                    foreach ($children as $child_line_item) {
120
-                        if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) {
121
-                            // recursively feed children back into this method
122
-                            $this->display_line_item($child_line_item, $options);
123
-                        }
124
-                    }
125
-                } else {
126
-                    // now loop thru all non-tax child line items
127
-                    foreach ($children as $child_line_item) {
128
-                        if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) {
129
-                            // recursively feed children back into this method
130
-                            $html .= $this->display_line_item($child_line_item, $options);
131
-                        }
132
-                    }
133
-                }
134
-                break;
135
-        }
136
-
137
-        return $html;
138
-    }
139
-
140
-
141
-    /**
142
-     *  _total_row
143
-     *
144
-     * @param EE_Line_Item $line_item
145
-     * @param array        $options
146
-     * @return string
147
-     * @throws EE_Error
148
-     * @throws ReflectionException
149
-     */
150
-    private function _item_row(EE_Line_Item $line_item, array $options = array()): string
151
-    {
152
-        $sub_taxes = $line_item->getSubTaxes();
153
-        $has_sub_taxes = ! empty($sub_taxes);
154
-        $is_taxable = $line_item->is_taxable();
155
-
156
-        $row_class = $options['odd'] ? 'item odd' : 'item';
157
-        $html = EEH_HTML::tr('', '', $row_class);
158
-        // name && desc
159
-        $name_and_desc = apply_filters(
160
-            'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name',
161
-            $line_item->name(),
162
-            $line_item
163
-        );
164
-        $name_and_desc .= apply_filters(
165
-            'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
166
-            ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
167
-            $line_item,
168
-            $options
169
-        );
170
-        if ($is_taxable || $has_sub_taxes) {
171
-            $includes_taxes = $this->prices_include_taxes
172
-                ? esc_html__('* price includes taxes', 'event_espresso')
173
-                : esc_html__('* price does not include taxes', 'event_espresso');
174
-            $name_and_desc .= '<br /><span class="smaller-text grey-text">' . $includes_taxes . '</span>';
175
-        }
176
-
177
-        // name td
178
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
179
-        // quantity td
180
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
181
-        $tax_rate = 1;
182
-        if ($this->prices_include_taxes) {
183
-            if ($has_sub_taxes) {
184
-                $tax_rate = 0;
185
-                foreach ($sub_taxes as $sub_tax) {
186
-                    if ($sub_tax instanceof EE_Line_Item && $sub_tax->isSubTax()) {
187
-                        $tax_rate += $sub_tax->percent();
188
-                    }
189
-                }
190
-                $tax_rate = 1 + $tax_rate / 100;
191
-            } elseif ($is_taxable && $this->prices_include_taxes) {
192
-                $tax_rate = 1 + ($this->_tax_rate / 100);
193
-            }
194
-        }
195
-
196
-        // price td
197
-        $unit_price = apply_filters(
198
-            'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__unit_price',
199
-            EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false),
200
-            $line_item,
201
-            $tax_rate
202
-        );
203
-        $html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght');
204
-        // total td
205
-        $total = apply_filters(
206
-            'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__total',
207
-            EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false),
208
-            $line_item,
209
-            $tax_rate
210
-        );
211
-        $html .= EEH_HTML::td($total, '', 'item_r jst-rght');
212
-        // end of row
213
-        $html .= EEH_HTML::trx();
214
-
215
-        return $html;
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     *  _sub_item_row
222
-     *
223
-     * @param EE_Line_Item $line_item
224
-     * @param array        $options
225
-     * @return mixed
226
-     */
227
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array())
228
-    {
229
-        // start of row
230
-        $html = EEH_HTML::tr('', 'item sub-item-row');
231
-        // name && desc
232
-        $name_and_desc = $line_item->name();
233
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
234
-        // name td
235
-        $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
236
-        // discount/surcharge td
237
-        if ($line_item->is_percent()) {
238
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
239
-        } else {
240
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
241
-        }
242
-        // total td
243
-        $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
244
-        // end of row
245
-        $html .= EEH_HTML::trx();
246
-        return $html;
247
-    }
18
+	/**
19
+	 * @var bool
20
+	 */
21
+	protected $prices_include_taxes = false;
22
+
23
+	/**
24
+	 * total amount of tax to apply
25
+	 * @type float $_tax_rate
26
+	 */
27
+	private $_tax_rate = 0;
28
+
29
+	/**
30
+	 * total amount including tax we can bill for at this time
31
+	 * @type float $_grand_total
32
+	 */
33
+	private $_grand_total = 0.00;
34
+
35
+	/**
36
+	 * total number of items being billed for
37
+	 * @type int $_total_items
38
+	 */
39
+	private $_total_items = 0;
40
+
41
+
42
+	public function __construct()
43
+	{
44
+		$this->prices_include_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes;
45
+	}
46
+
47
+
48
+	/**
49
+	 * @return float
50
+	 */
51
+	public function grand_total()
52
+	{
53
+		return $this->_grand_total;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * @return int
60
+	 */
61
+	public function total_items()
62
+	{
63
+		return $this->_total_items;
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 * @param EE_Line_Item $line_item
70
+	 * @param array        $options
71
+	 * @return mixed
72
+	 */
73
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
74
+	{
75
+
76
+		$html = '';
77
+		// set some default options and merge with incoming
78
+		$default_options = array(
79
+			'show_desc' => true,  //    TRUE        FALSE
80
+			'odd' => false
81
+		);
82
+		$options = array_merge($default_options, (array) $options);
83
+
84
+		switch ($line_item->type()) {
85
+			case EEM_Line_Item::type_line_item:
86
+				// item row
87
+				$html .= $this->_item_row($line_item, $options);
88
+				// got any kids?
89
+				foreach ($line_item->children() as $child_line_item) {
90
+					$this->display_line_item($child_line_item, $options);
91
+				}
92
+				break;
93
+
94
+			case EEM_Line_Item::type_sub_line_item:
95
+				$html .= $this->_sub_item_row($line_item, $options);
96
+				break;
97
+
98
+			case EEM_Line_Item::type_sub_total:
99
+				break;
100
+
101
+			case EEM_Line_Item::type_tax:
102
+				$this->_tax_rate += $line_item->percent();
103
+				break;
104
+
105
+			case EEM_Line_Item::type_tax_sub_total:
106
+				foreach ($line_item->children() as $child_line_item) {
107
+					if ($child_line_item->type() == EEM_Line_Item::type_tax) {
108
+						// recursively feed children back into this method
109
+						$this->display_line_item($child_line_item, $options);
110
+					}
111
+				}
112
+				break;
113
+
114
+			case EEM_Line_Item::type_total:
115
+				// get all child line items
116
+				$children = $line_item->children();
117
+				if ($options['set_tax_rate'] === true) {
118
+					// loop thru tax child line items just to determine tax rate
119
+					foreach ($children as $child_line_item) {
120
+						if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) {
121
+							// recursively feed children back into this method
122
+							$this->display_line_item($child_line_item, $options);
123
+						}
124
+					}
125
+				} else {
126
+					// now loop thru all non-tax child line items
127
+					foreach ($children as $child_line_item) {
128
+						if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) {
129
+							// recursively feed children back into this method
130
+							$html .= $this->display_line_item($child_line_item, $options);
131
+						}
132
+					}
133
+				}
134
+				break;
135
+		}
136
+
137
+		return $html;
138
+	}
139
+
140
+
141
+	/**
142
+	 *  _total_row
143
+	 *
144
+	 * @param EE_Line_Item $line_item
145
+	 * @param array        $options
146
+	 * @return string
147
+	 * @throws EE_Error
148
+	 * @throws ReflectionException
149
+	 */
150
+	private function _item_row(EE_Line_Item $line_item, array $options = array()): string
151
+	{
152
+		$sub_taxes = $line_item->getSubTaxes();
153
+		$has_sub_taxes = ! empty($sub_taxes);
154
+		$is_taxable = $line_item->is_taxable();
155
+
156
+		$row_class = $options['odd'] ? 'item odd' : 'item';
157
+		$html = EEH_HTML::tr('', '', $row_class);
158
+		// name && desc
159
+		$name_and_desc = apply_filters(
160
+			'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name',
161
+			$line_item->name(),
162
+			$line_item
163
+		);
164
+		$name_and_desc .= apply_filters(
165
+			'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
166
+			( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
167
+			$line_item,
168
+			$options
169
+		);
170
+		if ($is_taxable || $has_sub_taxes) {
171
+			$includes_taxes = $this->prices_include_taxes
172
+				? esc_html__('* price includes taxes', 'event_espresso')
173
+				: esc_html__('* price does not include taxes', 'event_espresso');
174
+			$name_and_desc .= '<br /><span class="smaller-text grey-text">' . $includes_taxes . '</span>';
175
+		}
176
+
177
+		// name td
178
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
179
+		// quantity td
180
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
181
+		$tax_rate = 1;
182
+		if ($this->prices_include_taxes) {
183
+			if ($has_sub_taxes) {
184
+				$tax_rate = 0;
185
+				foreach ($sub_taxes as $sub_tax) {
186
+					if ($sub_tax instanceof EE_Line_Item && $sub_tax->isSubTax()) {
187
+						$tax_rate += $sub_tax->percent();
188
+					}
189
+				}
190
+				$tax_rate = 1 + $tax_rate / 100;
191
+			} elseif ($is_taxable && $this->prices_include_taxes) {
192
+				$tax_rate = 1 + ($this->_tax_rate / 100);
193
+			}
194
+		}
195
+
196
+		// price td
197
+		$unit_price = apply_filters(
198
+			'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__unit_price',
199
+			EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false),
200
+			$line_item,
201
+			$tax_rate
202
+		);
203
+		$html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght');
204
+		// total td
205
+		$total = apply_filters(
206
+			'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__total',
207
+			EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false),
208
+			$line_item,
209
+			$tax_rate
210
+		);
211
+		$html .= EEH_HTML::td($total, '', 'item_r jst-rght');
212
+		// end of row
213
+		$html .= EEH_HTML::trx();
214
+
215
+		return $html;
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 *  _sub_item_row
222
+	 *
223
+	 * @param EE_Line_Item $line_item
224
+	 * @param array        $options
225
+	 * @return mixed
226
+	 */
227
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array())
228
+	{
229
+		// start of row
230
+		$html = EEH_HTML::tr('', 'item sub-item-row');
231
+		// name && desc
232
+		$name_and_desc = $line_item->name();
233
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
234
+		// name td
235
+		$html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
236
+		// discount/surcharge td
237
+		if ($line_item->is_percent()) {
238
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
239
+		} else {
240
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
241
+		}
242
+		// total td
243
+		$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
244
+		// end of row
245
+		$html .= EEH_HTML::trx();
246
+		return $html;
247
+	}
248 248
 }
Please login to merge, or discard this patch.
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 2 patches
Indentation   +680 added lines, -680 removed lines patch added patch discarded remove patch
@@ -11,684 +11,684 @@
 block discarded – undo
11 11
  */
12 12
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
13 13
 {
14
-    /**
15
-     * @var bool
16
-     */
17
-    protected $prices_include_taxes = false;
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
-    public function __construct()
56
-    {
57
-        $this->prices_include_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes;
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @return float
64
-     */
65
-    public function grand_total()
66
-    {
67
-        return $this->_grand_total;
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * @return int
74
-     */
75
-    public function total_items()
76
-    {
77
-        return $this->_total_items;
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * @param EE_Line_Item $line_item
84
-     * @param array        $options
85
-     * @param EE_Line_Item $parent_line_item
86
-     * @return mixed
87
-     * @throws EE_Error
88
-     */
89
-    public function display_line_item(
90
-        EE_Line_Item $line_item,
91
-        $options = array(),
92
-        EE_Line_Item $parent_line_item = null
93
-    ) {
94
-        $html = '';
95
-        // set some default options and merge with incoming
96
-        $default_options = array(
97
-            'show_desc' => true,  //    true        false
98
-            'odd'       => false,
99
-        );
100
-        $options = array_merge($default_options, (array) $options);
101
-
102
-        switch ($line_item->type()) {
103
-            case EEM_Line_Item::type_line_item:
104
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
105
-                if ($line_item->OBJ_type() === 'Ticket') {
106
-                    // item row
107
-                    $html .= $this->_ticket_row($line_item, $options);
108
-                } else {
109
-                    // item row
110
-                    $html .= $this->_item_row($line_item, $options);
111
-                }
112
-                if (
113
-                    apply_filters(
114
-                        'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
115
-                        true
116
-                    )
117
-                ) {
118
-                    // got any kids?
119
-                    foreach ($line_item->children() as $child_line_item) {
120
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
121
-                    }
122
-                }
123
-                break;
124
-
125
-            case EEM_Line_Item::type_sub_line_item:
126
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
127
-                break;
128
-
129
-            case EEM_Line_Item::type_sub_tax:
130
-                $this->_show_taxes = true;
131
-                break;
132
-
133
-            case EEM_Line_Item::type_sub_total:
134
-                static $sub_total = 0;
135
-                $event_sub_total = 0;
136
-                $text = esc_html__('Sub-Total', 'event_espresso');
137
-                if ($line_item->OBJ_type() === 'Event') {
138
-                    $options['event_id'] = $line_item->OBJ_ID();
139
-                    if (! isset($this->_events[ $options['event_id'] ])) {
140
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
141
-                        // if event has default reg status of Not Approved, then don't display info on it
142
-                        if (
143
-                            $event instanceof EE_Event
144
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
145
-                        ) {
146
-                            $display_event = false;
147
-                            // unless there are registrations for it that are returning to pay
148
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
149
-                                foreach ($options['registrations'] as $registration) {
150
-                                    if (! $registration instanceof EE_Registration) {
151
-                                        continue;
152
-                                    }
153
-                                    $display_event = $registration->event_ID() === $options['event_id']
154
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
155
-                                        ? true
156
-                                        : $display_event;
157
-                                }
158
-                            }
159
-                            if (! $display_event) {
160
-                                return '';
161
-                            }
162
-                        }
163
-                        $this->_events[ $options['event_id'] ] = 0;
164
-                        $html .= $this->_event_row($line_item);
165
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
166
-                    }
167
-                }
168
-                $child_line_items = $line_item->children();
169
-                // loop thru children
170
-                foreach ($child_line_items as $child_line_item) {
171
-                    // recursively feed children back into this method
172
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
173
-                }
174
-                $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
175
-                $sub_total += $event_sub_total;
176
-                if (
177
-                    (
178
-                        // event subtotals
179
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
180
-                    )
181
-                    || (
182
-                        // pre-tax subtotals
183
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
184
-                    )
185
-                ) {
186
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
187
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
188
-                }
189
-                break;
190
-
191
-            case EEM_Line_Item::type_tax:
192
-                if ($this->_show_taxes) {
193
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
194
-                }
195
-                break;
196
-
197
-            case EEM_Line_Item::type_tax_sub_total:
198
-                if ($this->_show_taxes) {
199
-                    $child_line_items = $line_item->children();
200
-                    // loop thru children
201
-                    foreach ($child_line_items as $child_line_item) {
202
-                        // recursively feed children back into this method
203
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
204
-                    }
205
-                    if (count($child_line_items) > 1) {
206
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
207
-                    }
208
-                }
209
-                break;
210
-
211
-            case EEM_Line_Item::type_total:
212
-                // get all child line items
213
-                $children = $line_item->children();
214
-                // loop thru all non-tax child line items
215
-                foreach ($children as $child_line_item) {
216
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
217
-                        // recursively feed children back into this method
218
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
219
-                    }
220
-                }
221
-                // now loop thru  tax child line items
222
-                foreach ($children as $child_line_item) {
223
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
224
-                        // recursively feed children back into this method
225
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
226
-                    }
227
-                }
228
-                $html .= $this->_taxes_html;
229
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
230
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
231
-                break;
232
-        }
233
-        return $html;
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
240
-     *
241
-     * @param EE_Line_Item $line_item
242
-     * @return mixed
243
-     */
244
-    private function _event_row(EE_Line_Item $line_item)
245
-    {
246
-        // start of row
247
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
248
-        // event name td
249
-        $html .= EEH_HTML::td(
250
-            EEH_HTML::strong($line_item->name()),
251
-            '',
252
-            'event-header',
253
-            '',
254
-            ' colspan="4"'
255
-        );
256
-        // end of row
257
-        $html .= EEH_HTML::trx();
258
-        return $html;
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * _ticket_row
265
-     *
266
-     * @param EE_Line_Item $line_item
267
-     * @param array        $options
268
-     * @return mixed
269
-     * @throws EE_Error
270
-     */
271
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
272
-    {
273
-        // start of row
274
-        $row_class = $options['odd'] ? 'item odd' : 'item';
275
-        $html = EEH_HTML::tr('', '', $row_class);
276
-        // name && desc
277
-        $name_and_desc = apply_filters(
278
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
279
-            $line_item->name(),
280
-            $line_item
281
-        );
282
-        $name_and_desc .= apply_filters(
283
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
284
-            (
285
-                $options['show_desc']
286
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
287
-                    : ''
288
-            ),
289
-            $line_item,
290
-            $options
291
-        );
292
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
293
-        $name_and_desc = apply_filters(
294
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc',
295
-            $name_and_desc,
296
-            $line_item,
297
-            $options
298
-        );
299
-
300
-        // name td
301
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
302
-            $name_and_desc,
303
-            '',
304
-            'item_l'
305
-        );
306
-        // price td
307
-        $price = apply_filters(
308
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price',
309
-            $line_item->unit_price_no_code(),
310
-            $line_item
311
-        );
312
-        $html .= EEH_HTML::td($price, '', 'spco-nowrap item_c jst-rght');
313
-        // quantity td
314
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght');
315
-        $this->_total_items += $line_item->quantity();
316
-        // determine total for line item
317
-        $total = apply_filters(
318
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total',
319
-            $line_item->pretaxTotal(),
320
-            $line_item
321
-        );
322
-        $this->_events[ $options['event_id'] ] += $total;
323
-        // total td
324
-        $html .= EEH_HTML::td(
325
-            EEH_Template::format_currency($total, false, false),
326
-            '',
327
-            'spco-nowrap item_r jst-rght'
328
-        );
329
-        // end of row
330
-        $html .= EEH_HTML::trx();
331
-        return $html;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * _item_row
338
-     *
339
-     * @param EE_Line_Item $line_item
340
-     * @param array        $options
341
-     * @return mixed
342
-     * @throws EE_Error
343
-     */
344
-    private function _item_row(EE_Line_Item $line_item, $options = array())
345
-    {
346
-        // start of row
347
-        $row_class = $options['odd'] ? 'item odd' : 'item';
348
-        $html = EEH_HTML::tr('', '', $row_class);
349
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
350
-        // name && desc
351
-        $name_and_desc = apply_filters(
352
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
353
-            $obj_name . $line_item->name(),
354
-            $line_item
355
-        );
356
-        $name_and_desc .= apply_filters(
357
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
358
-            (
359
-                $options['show_desc']
360
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
361
-                : ''
362
-            ),
363
-            $line_item,
364
-            $options
365
-        );
366
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
367
-        $name_and_desc = apply_filters(
368
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc',
369
-            $name_and_desc,
370
-            $line_item,
371
-            $options
372
-        );
373
-
374
-        // name td
375
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
376
-        // price td
377
-        if ($line_item->is_percent()) {
378
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght');
379
-        } else {
380
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght');
381
-        }
382
-        // quantity td
383
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght');
384
-        // $total = $line_item->total() * $line_item->quantity();
385
-        $total = $line_item->total();
386
-        if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
387
-            $this->_events[ $options['event_id'] ] += $total;
388
-        }
389
-        // total td
390
-        $html .= EEH_HTML::td(
391
-            EEH_Template::format_currency($total, false, false),
392
-            '',
393
-            'spco-nowrap item_r jst-rght'
394
-        );
395
-        // end of row
396
-        $html .= EEH_HTML::trx();
397
-        return $html;
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     * _sub_item_row
404
-     *
405
-     * @param EE_Line_Item $line_item
406
-     * @param array        $options
407
-     * @param EE_Line_Item $parent_line_item
408
-     * @return mixed
409
-     * @throws EE_Error
410
-     */
411
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
412
-    {
413
-        if (
414
-            $parent_line_item instanceof  EE_Line_Item
415
-            && $line_item->children() === array()
416
-            && $line_item->name() === $parent_line_item->name()
417
-            && apply_filters(
418
-                'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item',
419
-                true
420
-            )
421
-        ) {
422
-            return '';
423
-        }
424
-        // start of row
425
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
426
-        // name && desc
427
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
428
-                         . $line_item->name();
429
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
430
-                                                  . $line_item->desc()
431
-                                                  . '</span>' : '';
432
-        // name td
433
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
434
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
435
-        // discount/surcharge td
436
-        if ($line_item->is_percent()) {
437
-            $html .= EEH_HTML::td(
438
-                EEH_Template::format_currency(
439
-                    $line_item->total() / $qty,
440
-                    false,
441
-                    false
442
-                ),
443
-                '',
444
-                'spco-nowrap item_c jst-rght'
445
-            );
446
-        } else {
447
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght');
448
-        }
449
-        // no quantity td
450
-        $html .= EEH_HTML::td();
451
-        // no total td
452
-        $html .= EEH_HTML::td();
453
-        // end of row
454
-        $html .= EEH_HTML::trx();
455
-        $html = apply_filters(
456
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html',
457
-            $html,
458
-            $line_item,
459
-            $options,
460
-            $parent_line_item
461
-        );
462
-        return $html;
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * _tax_row
469
-     *
470
-     * @param EE_Line_Item $line_item
471
-     * @param array        $options
472
-     * @return mixed
473
-     * @throws EE_Error
474
-     */
475
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
476
-    {
477
-        // start of row
478
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
479
-        // name && desc
480
-        $name_and_desc = $line_item->name();
481
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
482
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
483
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
484
-        // name td
485
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
486
-            $name_and_desc,
487
-            '',
488
-            'item_l sub-item'
489
-        );
490
-        // percent td
491
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', '');
492
-        // empty td (price)
493
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
494
-        // total td
495
-        $html .= EEH_HTML::td(
496
-            EEH_Template::format_currency(
497
-                $line_item->total(),
498
-                false,
499
-                false
500
-            ),
501
-            '',
502
-            'spco-nowrap item_r jst-rght'
503
-        );
504
-        // end of row
505
-        $html .= EEH_HTML::trx();
506
-        return $html;
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     * _total_row
513
-     *
514
-     * @param EE_Line_Item $line_item
515
-     * @param string       $text
516
-     * @return mixed
517
-     * @throws EE_Error
518
-     */
519
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
520
-    {
521
-        $html = '';
522
-        if ($line_item->total()) {
523
-            // start of row
524
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
525
-            // total td
526
-            $html .= EEH_HTML::td(
527
-                $text,
528
-                '',
529
-                'total_currency total jst-rght',
530
-                '',
531
-                ' colspan="2"'
532
-            );
533
-            // empty td (price)
534
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
535
-            // total td
536
-            $html .= EEH_HTML::td(
537
-                EEH_Template::format_currency($line_item->total(), false, false),
538
-                '',
539
-                'spco-nowrap total jst-rght'
540
-            );
541
-            // end of row
542
-            $html .= EEH_HTML::trx();
543
-        }
544
-        return $html;
545
-    }
546
-
547
-
548
-
549
-    /**
550
-     * _total_row
551
-     *
552
-     * @param EE_Line_Item $line_item
553
-     * @param string       $text
554
-     * @param array        $options
555
-     * @return mixed
556
-     * @throws EE_Error
557
-     */
558
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
559
-    {
560
-        $html = '';
561
-        if ($line_item->total()) {
562
-            // start of row
563
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
564
-            // total td
565
-            $html .= EEH_HTML::td(
566
-                $text,
567
-                '',
568
-                'total_currency total jst-rght',
569
-                '',
570
-                ' colspan="3"'
571
-            );
572
-            // total td
573
-            $html .= EEH_HTML::td(
574
-                EEH_Template::format_currency($options['sub_total'], false, false),
575
-                '',
576
-                'spco-nowrap total jst-rght'
577
-            );
578
-            // end of row
579
-            $html .= EEH_HTML::trx();
580
-        }
581
-        return $html;
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * _total_row
588
-     *
589
-     * @param EE_Line_Item $line_item
590
-     * @param string       $text
591
-     * @return mixed
592
-     * @throws EE_Error
593
-     */
594
-    private function _total_row(EE_Line_Item $line_item, $text = '')
595
-    {
596
-        // start of row
597
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
598
-        // total td
599
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
600
-        // total td
601
-        $html .= EEH_HTML::td(
602
-            EEH_Template::format_currency($line_item->total(), false, false),
603
-            '',
604
-            'spco-nowrap total jst-rght'
605
-        );
606
-        // end of row
607
-        $html .= EEH_HTML::trx();
608
-        return $html;
609
-    }
610
-
611
-
612
-
613
-    /**
614
-     * _payments_and_amount_owing_rows
615
-     *
616
-     * @param EE_Line_Item $line_item
617
-     * @param array        $options
618
-     * @return mixed
619
-     * @throws EE_Error
620
-     */
621
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
622
-    {
623
-        $html = '';
624
-        $owing = $line_item->total();
625
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
626
-        if ($transaction instanceof EE_Transaction) {
627
-            $registration_payments = array();
628
-            $registrations = ! empty($options['registrations'])
629
-                ? $options['registrations']
630
-                : $transaction->registrations();
631
-            foreach ($registrations as $registration) {
632
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
633
-                    $registration_payments += $registration->registration_payments();
634
-                }
635
-            }
636
-            if (! empty($registration_payments)) {
637
-                foreach ($registration_payments as $registration_payment) {
638
-                    if ($registration_payment instanceof EE_Registration_Payment) {
639
-                        $owing -= $registration_payment->amount();
640
-                        $payment = $registration_payment->payment();
641
-                        $payment_desc = '';
642
-                        if ($payment instanceof EE_Payment) {
643
-                            $payment_desc = sprintf(
644
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
645
-                                $payment->txn_id_chq_nmbr() !== ''
646
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
647
-                                    : '',
648
-                                $payment->timestamp()
649
-                            );
650
-                        }
651
-                        // start of row
652
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
653
-                        // payment desc
654
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
655
-                        // total td
656
-                        $html .= EEH_HTML::td(
657
-                            EEH_Template::format_currency(
658
-                                $registration_payment->amount(),
659
-                                false,
660
-                                false
661
-                            ),
662
-                            '',
663
-                            'spco-nowrap total jst-rght'
664
-                        );
665
-                        // end of row
666
-                        $html .= EEH_HTML::trx();
667
-                    }
668
-                }
669
-                if ($line_item->total()) {
670
-                    // start of row
671
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
672
-                    // total td
673
-                    $html .= EEH_HTML::td(
674
-                        esc_html__('Amount Owing', 'event_espresso'),
675
-                        '',
676
-                        'total_currency total jst-rght',
677
-                        '',
678
-                        ' colspan="3"'
679
-                    );
680
-                    // total td
681
-                    $html .= EEH_HTML::td(
682
-                        EEH_Template::format_currency($owing, false, false),
683
-                        '',
684
-                        'spco-nowrap total jst-rght'
685
-                    );
686
-                    // end of row
687
-                    $html .= EEH_HTML::trx();
688
-                }
689
-            }
690
-        }
691
-        $this->_grand_total = $owing;
692
-        return $html;
693
-    }
14
+	/**
15
+	 * @var bool
16
+	 */
17
+	protected $prices_include_taxes = false;
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
+	public function __construct()
56
+	{
57
+		$this->prices_include_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes;
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @return float
64
+	 */
65
+	public function grand_total()
66
+	{
67
+		return $this->_grand_total;
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * @return int
74
+	 */
75
+	public function total_items()
76
+	{
77
+		return $this->_total_items;
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * @param EE_Line_Item $line_item
84
+	 * @param array        $options
85
+	 * @param EE_Line_Item $parent_line_item
86
+	 * @return mixed
87
+	 * @throws EE_Error
88
+	 */
89
+	public function display_line_item(
90
+		EE_Line_Item $line_item,
91
+		$options = array(),
92
+		EE_Line_Item $parent_line_item = null
93
+	) {
94
+		$html = '';
95
+		// set some default options and merge with incoming
96
+		$default_options = array(
97
+			'show_desc' => true,  //    true        false
98
+			'odd'       => false,
99
+		);
100
+		$options = array_merge($default_options, (array) $options);
101
+
102
+		switch ($line_item->type()) {
103
+			case EEM_Line_Item::type_line_item:
104
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
105
+				if ($line_item->OBJ_type() === 'Ticket') {
106
+					// item row
107
+					$html .= $this->_ticket_row($line_item, $options);
108
+				} else {
109
+					// item row
110
+					$html .= $this->_item_row($line_item, $options);
111
+				}
112
+				if (
113
+					apply_filters(
114
+						'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
115
+						true
116
+					)
117
+				) {
118
+					// got any kids?
119
+					foreach ($line_item->children() as $child_line_item) {
120
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
121
+					}
122
+				}
123
+				break;
124
+
125
+			case EEM_Line_Item::type_sub_line_item:
126
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
127
+				break;
128
+
129
+			case EEM_Line_Item::type_sub_tax:
130
+				$this->_show_taxes = true;
131
+				break;
132
+
133
+			case EEM_Line_Item::type_sub_total:
134
+				static $sub_total = 0;
135
+				$event_sub_total = 0;
136
+				$text = esc_html__('Sub-Total', 'event_espresso');
137
+				if ($line_item->OBJ_type() === 'Event') {
138
+					$options['event_id'] = $line_item->OBJ_ID();
139
+					if (! isset($this->_events[ $options['event_id'] ])) {
140
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
141
+						// if event has default reg status of Not Approved, then don't display info on it
142
+						if (
143
+							$event instanceof EE_Event
144
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
145
+						) {
146
+							$display_event = false;
147
+							// unless there are registrations for it that are returning to pay
148
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
149
+								foreach ($options['registrations'] as $registration) {
150
+									if (! $registration instanceof EE_Registration) {
151
+										continue;
152
+									}
153
+									$display_event = $registration->event_ID() === $options['event_id']
154
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
155
+										? true
156
+										: $display_event;
157
+								}
158
+							}
159
+							if (! $display_event) {
160
+								return '';
161
+							}
162
+						}
163
+						$this->_events[ $options['event_id'] ] = 0;
164
+						$html .= $this->_event_row($line_item);
165
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
166
+					}
167
+				}
168
+				$child_line_items = $line_item->children();
169
+				// loop thru children
170
+				foreach ($child_line_items as $child_line_item) {
171
+					// recursively feed children back into this method
172
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
173
+				}
174
+				$event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
175
+				$sub_total += $event_sub_total;
176
+				if (
177
+					(
178
+						// event subtotals
179
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
180
+					)
181
+					|| (
182
+						// pre-tax subtotals
183
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
184
+					)
185
+				) {
186
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
187
+					$html .= $this->_sub_total_row($line_item, $text, $options);
188
+				}
189
+				break;
190
+
191
+			case EEM_Line_Item::type_tax:
192
+				if ($this->_show_taxes) {
193
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
194
+				}
195
+				break;
196
+
197
+			case EEM_Line_Item::type_tax_sub_total:
198
+				if ($this->_show_taxes) {
199
+					$child_line_items = $line_item->children();
200
+					// loop thru children
201
+					foreach ($child_line_items as $child_line_item) {
202
+						// recursively feed children back into this method
203
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
204
+					}
205
+					if (count($child_line_items) > 1) {
206
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
207
+					}
208
+				}
209
+				break;
210
+
211
+			case EEM_Line_Item::type_total:
212
+				// get all child line items
213
+				$children = $line_item->children();
214
+				// loop thru all non-tax child line items
215
+				foreach ($children as $child_line_item) {
216
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
217
+						// recursively feed children back into this method
218
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
219
+					}
220
+				}
221
+				// now loop thru  tax child line items
222
+				foreach ($children as $child_line_item) {
223
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
224
+						// recursively feed children back into this method
225
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
226
+					}
227
+				}
228
+				$html .= $this->_taxes_html;
229
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
230
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
231
+				break;
232
+		}
233
+		return $html;
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
240
+	 *
241
+	 * @param EE_Line_Item $line_item
242
+	 * @return mixed
243
+	 */
244
+	private function _event_row(EE_Line_Item $line_item)
245
+	{
246
+		// start of row
247
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
248
+		// event name td
249
+		$html .= EEH_HTML::td(
250
+			EEH_HTML::strong($line_item->name()),
251
+			'',
252
+			'event-header',
253
+			'',
254
+			' colspan="4"'
255
+		);
256
+		// end of row
257
+		$html .= EEH_HTML::trx();
258
+		return $html;
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * _ticket_row
265
+	 *
266
+	 * @param EE_Line_Item $line_item
267
+	 * @param array        $options
268
+	 * @return mixed
269
+	 * @throws EE_Error
270
+	 */
271
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
272
+	{
273
+		// start of row
274
+		$row_class = $options['odd'] ? 'item odd' : 'item';
275
+		$html = EEH_HTML::tr('', '', $row_class);
276
+		// name && desc
277
+		$name_and_desc = apply_filters(
278
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
279
+			$line_item->name(),
280
+			$line_item
281
+		);
282
+		$name_and_desc .= apply_filters(
283
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
284
+			(
285
+				$options['show_desc']
286
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
287
+					: ''
288
+			),
289
+			$line_item,
290
+			$options
291
+		);
292
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
293
+		$name_and_desc = apply_filters(
294
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc',
295
+			$name_and_desc,
296
+			$line_item,
297
+			$options
298
+		);
299
+
300
+		// name td
301
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
302
+			$name_and_desc,
303
+			'',
304
+			'item_l'
305
+		);
306
+		// price td
307
+		$price = apply_filters(
308
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price',
309
+			$line_item->unit_price_no_code(),
310
+			$line_item
311
+		);
312
+		$html .= EEH_HTML::td($price, '', 'spco-nowrap item_c jst-rght');
313
+		// quantity td
314
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght');
315
+		$this->_total_items += $line_item->quantity();
316
+		// determine total for line item
317
+		$total = apply_filters(
318
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total',
319
+			$line_item->pretaxTotal(),
320
+			$line_item
321
+		);
322
+		$this->_events[ $options['event_id'] ] += $total;
323
+		// total td
324
+		$html .= EEH_HTML::td(
325
+			EEH_Template::format_currency($total, false, false),
326
+			'',
327
+			'spco-nowrap item_r jst-rght'
328
+		);
329
+		// end of row
330
+		$html .= EEH_HTML::trx();
331
+		return $html;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * _item_row
338
+	 *
339
+	 * @param EE_Line_Item $line_item
340
+	 * @param array        $options
341
+	 * @return mixed
342
+	 * @throws EE_Error
343
+	 */
344
+	private function _item_row(EE_Line_Item $line_item, $options = array())
345
+	{
346
+		// start of row
347
+		$row_class = $options['odd'] ? 'item odd' : 'item';
348
+		$html = EEH_HTML::tr('', '', $row_class);
349
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
350
+		// name && desc
351
+		$name_and_desc = apply_filters(
352
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
353
+			$obj_name . $line_item->name(),
354
+			$line_item
355
+		);
356
+		$name_and_desc .= apply_filters(
357
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
358
+			(
359
+				$options['show_desc']
360
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
361
+				: ''
362
+			),
363
+			$line_item,
364
+			$options
365
+		);
366
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
367
+		$name_and_desc = apply_filters(
368
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc',
369
+			$name_and_desc,
370
+			$line_item,
371
+			$options
372
+		);
373
+
374
+		// name td
375
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
376
+		// price td
377
+		if ($line_item->is_percent()) {
378
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght');
379
+		} else {
380
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght');
381
+		}
382
+		// quantity td
383
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght');
384
+		// $total = $line_item->total() * $line_item->quantity();
385
+		$total = $line_item->total();
386
+		if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
387
+			$this->_events[ $options['event_id'] ] += $total;
388
+		}
389
+		// total td
390
+		$html .= EEH_HTML::td(
391
+			EEH_Template::format_currency($total, false, false),
392
+			'',
393
+			'spco-nowrap item_r jst-rght'
394
+		);
395
+		// end of row
396
+		$html .= EEH_HTML::trx();
397
+		return $html;
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 * _sub_item_row
404
+	 *
405
+	 * @param EE_Line_Item $line_item
406
+	 * @param array        $options
407
+	 * @param EE_Line_Item $parent_line_item
408
+	 * @return mixed
409
+	 * @throws EE_Error
410
+	 */
411
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
412
+	{
413
+		if (
414
+			$parent_line_item instanceof  EE_Line_Item
415
+			&& $line_item->children() === array()
416
+			&& $line_item->name() === $parent_line_item->name()
417
+			&& apply_filters(
418
+				'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item',
419
+				true
420
+			)
421
+		) {
422
+			return '';
423
+		}
424
+		// start of row
425
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
426
+		// name && desc
427
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
428
+						 . $line_item->name();
429
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
430
+												  . $line_item->desc()
431
+												  . '</span>' : '';
432
+		// name td
433
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
434
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
435
+		// discount/surcharge td
436
+		if ($line_item->is_percent()) {
437
+			$html .= EEH_HTML::td(
438
+				EEH_Template::format_currency(
439
+					$line_item->total() / $qty,
440
+					false,
441
+					false
442
+				),
443
+				'',
444
+				'spco-nowrap item_c jst-rght'
445
+			);
446
+		} else {
447
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght');
448
+		}
449
+		// no quantity td
450
+		$html .= EEH_HTML::td();
451
+		// no total td
452
+		$html .= EEH_HTML::td();
453
+		// end of row
454
+		$html .= EEH_HTML::trx();
455
+		$html = apply_filters(
456
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html',
457
+			$html,
458
+			$line_item,
459
+			$options,
460
+			$parent_line_item
461
+		);
462
+		return $html;
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * _tax_row
469
+	 *
470
+	 * @param EE_Line_Item $line_item
471
+	 * @param array        $options
472
+	 * @return mixed
473
+	 * @throws EE_Error
474
+	 */
475
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
476
+	{
477
+		// start of row
478
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
479
+		// name && desc
480
+		$name_and_desc = $line_item->name();
481
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
482
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
483
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
484
+		// name td
485
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
486
+			$name_and_desc,
487
+			'',
488
+			'item_l sub-item'
489
+		);
490
+		// percent td
491
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', '');
492
+		// empty td (price)
493
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
494
+		// total td
495
+		$html .= EEH_HTML::td(
496
+			EEH_Template::format_currency(
497
+				$line_item->total(),
498
+				false,
499
+				false
500
+			),
501
+			'',
502
+			'spco-nowrap item_r jst-rght'
503
+		);
504
+		// end of row
505
+		$html .= EEH_HTML::trx();
506
+		return $html;
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 * _total_row
513
+	 *
514
+	 * @param EE_Line_Item $line_item
515
+	 * @param string       $text
516
+	 * @return mixed
517
+	 * @throws EE_Error
518
+	 */
519
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
520
+	{
521
+		$html = '';
522
+		if ($line_item->total()) {
523
+			// start of row
524
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
525
+			// total td
526
+			$html .= EEH_HTML::td(
527
+				$text,
528
+				'',
529
+				'total_currency total jst-rght',
530
+				'',
531
+				' colspan="2"'
532
+			);
533
+			// empty td (price)
534
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
535
+			// total td
536
+			$html .= EEH_HTML::td(
537
+				EEH_Template::format_currency($line_item->total(), false, false),
538
+				'',
539
+				'spco-nowrap total jst-rght'
540
+			);
541
+			// end of row
542
+			$html .= EEH_HTML::trx();
543
+		}
544
+		return $html;
545
+	}
546
+
547
+
548
+
549
+	/**
550
+	 * _total_row
551
+	 *
552
+	 * @param EE_Line_Item $line_item
553
+	 * @param string       $text
554
+	 * @param array        $options
555
+	 * @return mixed
556
+	 * @throws EE_Error
557
+	 */
558
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
559
+	{
560
+		$html = '';
561
+		if ($line_item->total()) {
562
+			// start of row
563
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
564
+			// total td
565
+			$html .= EEH_HTML::td(
566
+				$text,
567
+				'',
568
+				'total_currency total jst-rght',
569
+				'',
570
+				' colspan="3"'
571
+			);
572
+			// total td
573
+			$html .= EEH_HTML::td(
574
+				EEH_Template::format_currency($options['sub_total'], false, false),
575
+				'',
576
+				'spco-nowrap total jst-rght'
577
+			);
578
+			// end of row
579
+			$html .= EEH_HTML::trx();
580
+		}
581
+		return $html;
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * _total_row
588
+	 *
589
+	 * @param EE_Line_Item $line_item
590
+	 * @param string       $text
591
+	 * @return mixed
592
+	 * @throws EE_Error
593
+	 */
594
+	private function _total_row(EE_Line_Item $line_item, $text = '')
595
+	{
596
+		// start of row
597
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
598
+		// total td
599
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
600
+		// total td
601
+		$html .= EEH_HTML::td(
602
+			EEH_Template::format_currency($line_item->total(), false, false),
603
+			'',
604
+			'spco-nowrap total jst-rght'
605
+		);
606
+		// end of row
607
+		$html .= EEH_HTML::trx();
608
+		return $html;
609
+	}
610
+
611
+
612
+
613
+	/**
614
+	 * _payments_and_amount_owing_rows
615
+	 *
616
+	 * @param EE_Line_Item $line_item
617
+	 * @param array        $options
618
+	 * @return mixed
619
+	 * @throws EE_Error
620
+	 */
621
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
622
+	{
623
+		$html = '';
624
+		$owing = $line_item->total();
625
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
626
+		if ($transaction instanceof EE_Transaction) {
627
+			$registration_payments = array();
628
+			$registrations = ! empty($options['registrations'])
629
+				? $options['registrations']
630
+				: $transaction->registrations();
631
+			foreach ($registrations as $registration) {
632
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
633
+					$registration_payments += $registration->registration_payments();
634
+				}
635
+			}
636
+			if (! empty($registration_payments)) {
637
+				foreach ($registration_payments as $registration_payment) {
638
+					if ($registration_payment instanceof EE_Registration_Payment) {
639
+						$owing -= $registration_payment->amount();
640
+						$payment = $registration_payment->payment();
641
+						$payment_desc = '';
642
+						if ($payment instanceof EE_Payment) {
643
+							$payment_desc = sprintf(
644
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
645
+								$payment->txn_id_chq_nmbr() !== ''
646
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
647
+									: '',
648
+								$payment->timestamp()
649
+							);
650
+						}
651
+						// start of row
652
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
653
+						// payment desc
654
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
655
+						// total td
656
+						$html .= EEH_HTML::td(
657
+							EEH_Template::format_currency(
658
+								$registration_payment->amount(),
659
+								false,
660
+								false
661
+							),
662
+							'',
663
+							'spco-nowrap total jst-rght'
664
+						);
665
+						// end of row
666
+						$html .= EEH_HTML::trx();
667
+					}
668
+				}
669
+				if ($line_item->total()) {
670
+					// start of row
671
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
672
+					// total td
673
+					$html .= EEH_HTML::td(
674
+						esc_html__('Amount Owing', 'event_espresso'),
675
+						'',
676
+						'total_currency total jst-rght',
677
+						'',
678
+						' colspan="3"'
679
+					);
680
+					// total td
681
+					$html .= EEH_HTML::td(
682
+						EEH_Template::format_currency($owing, false, false),
683
+						'',
684
+						'spco-nowrap total jst-rght'
685
+					);
686
+					// end of row
687
+					$html .= EEH_HTML::trx();
688
+				}
689
+			}
690
+		}
691
+		$this->_grand_total = $owing;
692
+		return $html;
693
+	}
694 694
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
         $html = '';
95 95
         // set some default options and merge with incoming
96 96
         $default_options = array(
97
-            'show_desc' => true,  //    true        false
97
+            'show_desc' => true, //    true        false
98 98
             'odd'       => false,
99 99
         );
100 100
         $options = array_merge($default_options, (array) $options);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
                 $text = esc_html__('Sub-Total', 'event_espresso');
137 137
                 if ($line_item->OBJ_type() === 'Event') {
138 138
                     $options['event_id'] = $line_item->OBJ_ID();
139
-                    if (! isset($this->_events[ $options['event_id'] ])) {
139
+                    if ( ! isset($this->_events[$options['event_id']])) {
140 140
                         $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
141 141
                         // if event has default reg status of Not Approved, then don't display info on it
142 142
                         if (
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                             // unless there are registrations for it that are returning to pay
148 148
                             if (isset($options['registrations']) && is_array($options['registrations'])) {
149 149
                                 foreach ($options['registrations'] as $registration) {
150
-                                    if (! $registration instanceof EE_Registration) {
150
+                                    if ( ! $registration instanceof EE_Registration) {
151 151
                                         continue;
152 152
                                     }
153 153
                                     $display_event = $registration->event_ID() === $options['event_id']
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
                                         : $display_event;
157 157
                                 }
158 158
                             }
159
-                            if (! $display_event) {
159
+                            if ( ! $display_event) {
160 160
                                 return '';
161 161
                             }
162 162
                         }
163
-                        $this->_events[ $options['event_id'] ] = 0;
163
+                        $this->_events[$options['event_id']] = 0;
164 164
                         $html .= $this->_event_row($line_item);
165 165
                         $text = esc_html__('Event Sub-Total', 'event_espresso');
166 166
                     }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
                     // recursively feed children back into this method
172 172
                     $html .= $this->display_line_item($child_line_item, $options, $line_item);
173 173
                 }
174
-                $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
174
+                $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
175 175
                 $sub_total += $event_sub_total;
176 176
                 if (
177 177
                     (
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
284 284
             (
285 285
                 $options['show_desc']
286
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
286
+                    ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
287 287
                     : ''
288 288
             ),
289 289
             $line_item,
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
             $line_item->pretaxTotal(),
320 320
             $line_item
321 321
         );
322
-        $this->_events[ $options['event_id'] ] += $total;
322
+        $this->_events[$options['event_id']] += $total;
323 323
         // total td
324 324
         $html .= EEH_HTML::td(
325 325
             EEH_Template::format_currency($total, false, false),
@@ -346,18 +346,18 @@  discard block
 block discarded – undo
346 346
         // start of row
347 347
         $row_class = $options['odd'] ? 'item odd' : 'item';
348 348
         $html = EEH_HTML::tr('', '', $row_class);
349
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
349
+        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : '';
350 350
         // name && desc
351 351
         $name_and_desc = apply_filters(
352 352
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
353
-            $obj_name . $line_item->name(),
353
+            $obj_name.$line_item->name(),
354 354
             $line_item
355 355
         );
356 356
         $name_and_desc .= apply_filters(
357 357
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
358 358
             (
359 359
                 $options['show_desc']
360
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
360
+                ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
361 361
                 : ''
362 362
             ),
363 363
             $line_item,
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
         $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
376 376
         // price td
377 377
         if ($line_item->is_percent()) {
378
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght');
378
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'spco-nowrap item_c jst-rght');
379 379
         } else {
380 380
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght');
381 381
         }
@@ -383,8 +383,8 @@  discard block
 block discarded – undo
383 383
         $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght');
384 384
         // $total = $line_item->total() * $line_item->quantity();
385 385
         $total = $line_item->total();
386
-        if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
387
-            $this->_events[ $options['event_id'] ] += $total;
386
+        if (isset($options['event_id'], $this->_events[$options['event_id']])) {
387
+            $this->_events[$options['event_id']] += $total;
388 388
         }
389 389
         // total td
390 390
         $html .= EEH_HTML::td(
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
         // name && desc
480 480
         $name_and_desc = $line_item->name();
481 481
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
482
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
483
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
482
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
483
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
484 484
         // name td
485 485
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
486 486
             $name_and_desc,
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
             'item_l sub-item'
489 489
         );
490 490
         // percent td
491
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', '');
491
+        $html .= EEH_HTML::td($line_item->percent().'%', '', 'spco-nowrap jst-rght', '');
492 492
         // empty td (price)
493 493
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
494 494
         // total td
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
                     $registration_payments += $registration->registration_payments();
634 634
                 }
635 635
             }
636
-            if (! empty($registration_payments)) {
636
+            if ( ! empty($registration_payments)) {
637 637
                 foreach ($registration_payments as $registration_payment) {
638 638
                     if ($registration_payment instanceof EE_Registration_Payment) {
639 639
                         $owing -= $registration_payment->amount();
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
                             $payment_desc = sprintf(
644 644
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
645 645
                                 $payment->txn_id_chq_nmbr() !== ''
646
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
646
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
647 647
                                     : '',
648 648
                                 $payment->timestamp()
649 649
                             );
Please login to merge, or discard this patch.