Conditions | 21 |
Paths | > 20000 |
Total Lines | 173 |
Code Lines | 126 |
Lines | 6 |
Ratio | 3.47 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
35 | public function send_invoice( $download = FALSE ) { |
||
36 | $template_args = array(); |
||
37 | $EE = EE_Registry::instance(); |
||
38 | |||
39 | //allow the request to override the default theme defined in the invoice settings |
||
40 | $theme_requested = ( isset( $_REQUEST['theme'] ) && $_REQUEST['theme'] > 0 && $_REQUEST['theme'] < 8 ) ? absint( $_REQUEST['theme'] ) : null; |
||
41 | $themes = array( |
||
42 | 1 => "simple.css", |
||
43 | 2 => "bauhaus.css", |
||
44 | 3 => "ejs.css", |
||
45 | 4 => "horizon.css", |
||
46 | 5 => "lola.css", |
||
47 | 6 => "tranquility.css", |
||
48 | 7 => "union.css" |
||
49 | ); |
||
50 | //Get the CSS file |
||
51 | if( isset( $themes[ $theme_requested ] ) ) { |
||
52 | $template_args['invoice_css'] = $themes[ $theme_requested ]; |
||
53 | }else{ |
||
54 | $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta( 'legacy_invoice_css', TRUE, 'simple.css' ); |
||
55 | } |
||
56 | |||
57 | if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) { |
||
58 | $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'; |
||
59 | } else { |
||
60 | $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/'; |
||
61 | } |
||
62 | $primary_attendee = $this->transaction->primary_registration()->attendee(); |
||
63 | |||
64 | $template_args['organization'] = $EE->CFG->organization->get_pretty( 'name' ); |
||
65 | $template_args['street'] = empty( $EE->CFG->organization->address_2 ) ? $EE->CFG->organization->get_pretty( 'address_1' ) : $EE->CFG->organization->get_pretty( 'address_1' ) . '<br>' . $EE->CFG->organization->get_pretty( 'address_2' ); |
||
66 | $template_args['city'] = $EE->CFG->organization->get_pretty( 'city' ); |
||
67 | $template_args['state'] = EE_Registry::instance()->load_model( 'State' )->get_one_by_ID( $EE->CFG->organization->STA_ID ); |
||
68 | $template_args['country'] = EE_Registry::instance()->load_model( 'Country' )->get_one_by_ID( $EE->CFG->organization->CNT_ISO ); |
||
69 | $template_args['zip'] = $EE->CFG->organization->get_pretty( 'zip' ); |
||
70 | $template_args['email'] = $EE->CFG->organization->get_pretty( 'email' ); |
||
71 | |||
72 | $template_args['registration_code'] = $this->registration->reg_code(); |
||
73 | $template_args['registration_date'] = $this->registration->date(); |
||
74 | $template_args['name'] = $primary_attendee->full_name(); |
||
75 | $template_args['attendee_address'] = $primary_attendee->address(); |
||
76 | $template_args['attendee_address2'] = $primary_attendee->address2(); |
||
77 | $template_args['attendee_city'] = $primary_attendee->city(); |
||
78 | $attendee_state = $primary_attendee->state_obj(); |
||
79 | if($attendee_state){ |
||
80 | $attendee_state_name = $attendee_state->name(); |
||
81 | }else{ |
||
82 | $attendee_state_name = ''; |
||
83 | } |
||
84 | $template_args['attendee_state'] = $attendee_state_name; |
||
85 | $template_args['attendee_zip'] = $primary_attendee->zip(); |
||
86 | |||
87 | $template_args['ship_name'] = $template_args['name']; |
||
88 | $template_args['ship_address'] = $template_args['attendee_address']; |
||
89 | $template_args['ship_city'] = $template_args['attendee_city']; |
||
90 | $template_args['ship_state'] = $template_args['attendee_state']; |
||
91 | $template_args['ship_zip'] = $template_args['attendee_zip']; |
||
92 | |||
93 | $template_args['total_cost'] = number_format($this->transaction->total(), 2, '.', ''); |
||
94 | $template_args['transaction'] = $this->transaction; |
||
95 | $template_args['amount_pd'] = $this->transaction->paid(); |
||
96 | $template_args['amount_owed'] = $this->transaction->total() - $this->transaction->paid(); |
||
97 | $template_args['payments'] = $this->transaction->approved_payments(); |
||
98 | $template_args['net_total'] = ''; |
||
99 | $template_args['edit_reg_info_url'] = $this->registration->edit_attendee_information_url(); |
||
100 | $template_args['retry_payment_url'] = $this->registration->payment_overview_url(); |
||
101 | $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description($this->transaction->total_line_item()); |
||
102 | if ($template_args['amount_pd'] != $template_args['total_cost']) { |
||
103 | //$template_args['net_total'] = $this->espressoInvoiceTotals( __('SubTotal', 'event_espresso'), $this->transaction->total());//$this->session_data['cart']['REG']['sub_total']); |
||
104 | $tax_items = $this->transaction->tax_items(); |
||
105 | if(!empty($tax_items) ){ |
||
106 | foreach ($tax_items as $tax) { |
||
107 | $template_args['net_total'] .= $this->espressoInvoiceTotals( $tax->name(), $tax->total()); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | $difference = $template_args['amount_pd'] - $template_args['total_cost']; |
||
112 | if ($difference < 0) { |
||
113 | $text = __('Discount', 'event_espresso'); |
||
114 | } else { |
||
115 | $text = __('Extra', 'event_espresso'); |
||
116 | } |
||
117 | $template_args['discount'] = $this->espressoInvoiceTotals( $text, $difference ); |
||
118 | } |
||
119 | |||
120 | $template_args['currency_symbol'] = $EE->CFG->currency->sign; |
||
121 | $template_args['template_payment_instructions'] = wpautop(stripslashes_deep(html_entity_decode($this->invoice_payment_method->get_extra_meta( 'pdf_instructions', TRUE ), ENT_QUOTES))); |
||
122 | $template_args['shameless_plug'] = apply_filters( 'FHEE_Invoice__send_invoice__shameless_plug',true ); |
||
123 | if(isset($_GET['receipt'])){ |
||
124 | //receipt-specific stuff |
||
125 | $events_for_txn = EEM_Event::instance()->get_all(array(array('Registration.TXN_ID'=>$this->transaction->ID()))); |
||
126 | $ticket_line_items_per_event = array(); |
||
127 | $registrations_per_line_item = array(); |
||
128 | $venues_for_events = array(); |
||
129 | foreach($events_for_txn as $event_id => $event){ |
||
130 | $line_items_for_this_event = EEM_Line_Item::instance()->get_all(array(array('Ticket.Datetime.EVT_ID'=>$event_id,'TXN_ID'=>$this->transaction->ID()))); |
||
131 | $ticket_line_items_per_event[$event_id] = $line_items_for_this_event; |
||
132 | foreach($line_items_for_this_event as $line_item_id => $line_item){ |
||
133 | $ticket = $line_item->ticket(); |
||
134 | $registrations_for_this_ticket = EEM_Registration::instance()->get_all(array(array('TKT_ID'=>$ticket->ID(),'TXN_ID'=>$this->transaction->ID()))); |
||
135 | $registrations_per_line_item[$line_item_id] = $registrations_for_this_ticket; |
||
136 | } |
||
137 | $venues_for_events = array_merge($venues_for_events, $event->venues()); |
||
138 | } |
||
139 | $tax_total_line_item = EEM_Line_Item::instance()->get_one(array(array('TXN_ID'=>$this->transaction->ID(),'LIN_type'=> EEM_Line_Item::type_tax_sub_total))); |
||
140 | $questions_to_skip = array(EEM_Attendee::system_question_fname,EEM_Attendee::system_question_lname, EEM_Attendee::system_question_email); |
||
141 | |||
142 | |||
143 | $template_args['events_for_txn'] = $events_for_txn; |
||
144 | $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event; |
||
145 | $template_args['registrations_per_line_item'] = $registrations_per_line_item; |
||
146 | $template_args['venues_for_events'] = $venues_for_events; |
||
147 | $template_args['tax_total_line_item'] = $tax_total_line_item; |
||
148 | $template_args['questions_to_skip'] = $questions_to_skip; |
||
149 | $EE->load_helper( 'Venue_View' ); |
||
150 | // d($template_args); |
||
151 | $template_args['download_link'] = $this->registration->receipt_url('download'); |
||
152 | }else{ |
||
153 | //it's just an invoice we're accessing |
||
154 | $template_args['download_link'] = $this->registration->invoice_url('download'); |
||
155 | } |
||
156 | |||
157 | |||
158 | |||
159 | //require helpers |
||
160 | $EE->load_helper( 'Formatter' ); |
||
161 | |||
162 | //Get the HTML as an object |
||
163 | EE_Registry::instance()->load_helper('Template'); |
||
164 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
||
165 | $template_header = EEH_Template::locate_template( $templates_relative_path . 'invoice_header.template.php', $template_args, TRUE, TRUE ); |
||
166 | if(isset($_GET['receipt'])){ |
||
167 | $template_body = EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', $template_args, TRUE, TRUE ); |
||
168 | }else{ |
||
169 | $template_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', $template_args, TRUE, TRUE ); |
||
170 | } |
||
171 | |||
172 | |||
173 | $template_footer = EEH_Template::locate_template( $templates_relative_path . 'invoice_footer.template.php', $template_args, TRUE, TRUE ); |
||
174 | |||
175 | $copies = ! empty( $_REQUEST['copies'] ) ? $_REQUEST['copies'] : 1; |
||
176 | |||
177 | $content = $this->espresso_replace_invoice_shortcodes($template_header); |
||
178 | for( $x = 1; $x <= $copies; $x++ ) { |
||
179 | $content .= $this->espresso_replace_invoice_shortcodes($template_body); |
||
180 | } |
||
181 | $content .= $this->espresso_replace_invoice_shortcodes($template_footer); |
||
182 | |||
183 | //Check if debugging or mobile is set |
||
184 | if (!empty($_REQUEST['html'])) { |
||
185 | echo $content; |
||
186 | exit(0); |
||
187 | } |
||
188 | $invoice_name = $template_args['organization'] . ' ' . __('Invoice #', 'event_espresso') . $template_args['registration_code'] . __(' for ', 'event_espresso') . $template_args['name']; |
||
189 | $invoice_name = str_replace( ' ', '_', $invoice_name ); |
||
190 | //Create the PDF |
||
191 | if(array_key_exists('html',$_GET)){ |
||
192 | echo $content; |
||
193 | }else{ |
||
194 | //only load dompdf if nobody else has yet... |
||
195 | View Code Duplication | if( ! defined('DOMPDF_DIR')){ |
|
196 | define('DOMPDF_ENABLE_REMOTE', TRUE); |
||
197 | define('DOMPDF_ENABLE_JAVASCRIPT', FALSE); |
||
198 | define('DOMPDF_ENABLE_CSS_FLOAT', TRUE); |
||
199 | require_once(EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php'); |
||
200 | } |
||
201 | $dompdf = new DOMPDF(); |
||
202 | $dompdf->load_html($content); |
||
203 | $dompdf->render(); |
||
204 | $dompdf->stream($invoice_name . ".pdf", array( 'Attachment' => $download )); |
||
205 | } |
||
206 | exit(0); |
||
207 | } |
||
208 | /** |
||
313 |
This check marks private properties in classes that are never used. Those properties can be removed.