Passed
Push — master ( 5cb736...359125 )
by Brian
04:57
created

GetPaid_Meta_Box_Invoice_Details::output()   D

Complexity

Conditions 16
Paths 72

Size

Total Lines 254
Code Lines 177

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 177
nc 72
nop 1
dl 0
loc 254
rs 4.4532
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
/**
4
 * Invoice Details
5
 *
6
 * Display the invoice data meta box.
7
 *
8
 */
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit; // Exit if accessed directly
12
}
13
14
/**
15
 * GetPaid_Meta_Box_Invoice_Details Class.
16
 */
17
class GetPaid_Meta_Box_Invoice_Details {
18
19
    /**
20
	 * Output the metabox.
21
	 *
22
	 * @param WP_Post $post
23
	 */
24
    public static function output( $post ) {
25
26
        // Prepare the invoice.
27
        $invoice = new WPInv_Invoice( $post );
28
29
        // Nonce field.
30
        wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' );
31
32
        ?>
33
34
        <style>
35
            #poststuff .input-group-text,
36
            #poststuff .form-control {
37
                border-color: #7e8993;
38
            }
39
40
            #wpinv-details label {
41
                margin-bottom: 3px;
42
                font-weight: 600;
43
            }
44
        </style>
45
46
                <div class="bsui" style="margin-top: 1.5rem">
47
48
                    <?php do_action( 'getpaid_invoice_edit_before_viewed_by_customer', $invoice ); ?>
49
                    <?php if ( ! $invoice->is_draft() ) : ?>
50
                        <div class="form-group">
51
                            <strong><?php esc_html_e( 'Viewed by Customer:', 'invoicing' ); ?></strong>
52
                            <?php ( $invoice->get_is_viewed() ) ? esc_html_e( 'Yes', 'invoicing' ) : esc_html_e( 'No', 'invoicing' ); ?>
53
                        </div>
54
                    <?php endif; ?>
55
56
                    <?php
57
58
                        // Date created.
59
                        $label = sprintf(
60
                            // translators: %s is the invoice type.
61
                            __( '%s Date:', 'invoicing' ),
62
                            ucfirst( $invoice->get_invoice_quote_type() )
63
                        );
64
65
                        $info  = sprintf(
66
                            // translators: %s is the invoice type.
67
                            __( 'The date this %s was created.', 'invoicing' ),
68
                            strtolower( $invoice->get_invoice_quote_type() )
69
                        );
70
71
                        aui()->input(
72
                            array(
73
                                'type'             => 'datepicker',
74
                                'id'               => 'wpinv_date_created',
75
                                'name'             => 'date_created',
76
                                'label'            => $label . getpaid_get_help_tip( $info ),
77
                                'label_type'       => 'vertical',
78
                                'placeholder'      => 'YYYY-MM-DD 00:00',
79
                                'class'            => 'form-control-sm',
80
                                'value'            => $invoice->get_date_created( 'edit' ),
81
                                'extra_attributes' => array(
82
                                    'data-enable-time' => 'true',
83
                                    'data-time_24hr'   => 'true',
84
                                    'data-allow-input' => 'true',
85
                                    'data-max-date'    => 'today',
86
                                ),
87
                            ),
88
                            true
89
                        );
90
91
                        // Date paid.
92
                        aui()->input(
93
                            array(
94
                                'type'        => 'text',
95
                                'id'          => 'wpinv_date_completed',
96
                                'name'        => 'wpinv_date_completed',
97
                                'label'       => __( 'Date Completed:', 'invoicing' ),
98
                                'label_type'  => 'vertical',
99
                                'class'       => 'form-control-sm',
100
                                'value'       => $invoice->get_date_completed( 'edit' ),
101
                                'placeholder' => 'YYYY-MM-DD 00:00',
102
                            ),
103
                            true
104
                        );
105
106
                        // Due date.
107
                        if ( $invoice->is_type( 'invoice' ) && wpinv_get_option( 'overdue_active' ) && ( ! $invoice->is_paid() || $invoice->is_draft() ) ) {
108
109
                            aui()->input(
110
                                array(
111
                                    'type'             => 'datepicker',
112
                                    'id'               => 'wpinv_due_date',
113
                                    'name'             => 'wpinv_due_date',
114
                                    'label'            => __( 'Due Date:', 'invoicing' ) . getpaid_get_help_tip( __( 'Leave blank to disable automated reminder emails for this invoice.', 'invoicing' ) ),
115
                                    'label_type'       => 'vertical',
116
                                    'placeholder'      => __( 'No due date', 'invoicing' ),
117
                                    'class'            => 'form-control-sm',
118
                                    'value'            => $invoice->get_due_date( 'edit' ),
119
                                    'extra_attributes' => array(
120
                                        'data-enable-time' => 'true',
121
                                        'data-time_24hr'   => 'true',
122
                                        'data-allow-input' => 'true',
123
                                        'data-min-date'    => 'today',
124
                                    ),
125
                                ),
126
                                true
127
                            );
128
129
                        }
130
131
                        do_action( 'wpinv_meta_box_details_after_due_date', $invoice->get_id() );
132
                        do_action( 'getpaid_metabox_after_due_date', $invoice );
133
134
                        // Status.
135
                        $label = sprintf(
136
                            // translators: %s: Invoice type.
137
                            __( '%s Status:', 'invoicing' ),
138
                            ucfirst( $invoice->get_invoice_quote_type() )
139
                        );
140
141
                        $status = $invoice->get_status( 'edit' );
142
                        aui()->select(
143
                            array(
144
                                'id'               => 'wpinv_status',
145
                                'name'             => 'wpinv_status',
146
                                'label'            => $label,
147
                                'label_type'       => 'vertical',
148
                                'placeholder'      => __( 'Select Status', 'invoicing' ),
149
                                'value'            => array_key_exists( $status, $invoice->get_all_statuses() ) ? $status : $invoice->get_default_status(),
150
                                'select2'          => true,
151
                                'data-allow-clear' => 'false',
152
                                'options'          => wpinv_get_invoice_statuses( true, false, $invoice ),
153
                            ),
154
                            true
155
                        );
156
157
                        // Invoice number.
158
                        $label = sprintf(
159
                            // translators: %s: Invoice type.
160
                            __( '%s Number:', 'invoicing' ),
161
                            ucfirst( $invoice->get_invoice_quote_type() )
162
                        );
163
164
                        $info  = sprintf(
165
                            // translators: %s: Invoice type.
166
                            __( 'Each %s number must be unique.', 'invoicing' ),
167
                            strtolower( $invoice->get_invoice_quote_type() )
168
                        );
169
170
                        aui()->input(
171
                            array(
172
                                'type'        => 'text',
173
                                'id'          => 'wpinv_number',
174
                                'name'        => 'wpinv_number',
175
                                'label'       => $label . getpaid_get_help_tip( $info ),
176
                                'label_type'  => 'vertical',
177
                                'placeholder' => __( 'Autogenerate', 'invoicing' ),
178
                                'class'       => 'form-control-sm',
179
                                'value'       => $invoice->get_number( 'edit' ),
180
                            ),
181
                            true
182
                        );
183
184
                        // Invoice cc.
185
                        aui()->input(
186
                            array(
187
                                'type'        => 'text',
188
                                'id'          => 'wpinv_cc',
189
                                'name'        => 'wpinv_cc',
190
                                'label'       => __( 'Email CC:', 'invoicing' ) . getpaid_get_help_tip( __( 'Enter a comma separated list of other emails that should be notified about the invoice.', 'invoicing' ) ),
191
                                'label_type'  => 'vertical',
192
                                'placeholder' => __( '[email protected], [email protected]', 'invoicing' ),
193
                                'class'       => 'form-control-sm',
194
                                'value'       => $invoice->get_email_cc( 'edit' ),
195
                            ),
196
                            true
197
                        );
198
199
                        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
200
201
                            // Apply a discount.
202
                            aui()->input(
203
                                array(
204
                                    'type'        => 'text',
205
                                    'id'          => 'wpinv_discount_code',
206
                                    'name'        => 'wpinv_discount_code',
207
                                    'label'       => __( 'Discount Code:', 'invoicing' ),
208
                                    'placeholder' => __( 'Apply Discount', 'invoicing' ),
209
                                    'label_type'  => 'vertical',
210
                                    'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
211
                                    'value'       => $invoice->get_discount_code( 'edit' ),
212
                                ),
213
                                true
214
                            );
215
216
                        } elseif ( $invoice->get_discount_code( 'edit' ) ) {
217
218
                            aui()->input(
219
                                array(
220
                                    'type'             => 'text',
221
                                    'id'               => 'wpinv_discount_code',
222
                                    'name'             => 'wpinv_discount_code',
223
                                    'label'            => __( 'Discount Code:', 'invoicing' ),
224
                                    'label_type'       => 'vertical',
225
                                    'class'            => 'form-control-sm',
226
                                    'value'            => $invoice->get_discount_code( 'edit' ),
227
                                    'extra_attributes' => array(
228
                                        'onclick'  => 'this.select();',
229
                                        'readonly' => 'true',
230
                                    ),
231
                                ),
232
                                true
233
                            );
234
235
                        }
236
237
                        do_action( 'wpinv_meta_box_details_inner', $invoice->get_id() );
238
239
                        // Disable taxes.
240
                        if ( wpinv_use_taxes() && ! ( $invoice->is_paid() || $invoice->is_refunded() ) ) {
241
242
                            aui()->input(
243
                                array(
244
                                    'id'      => 'wpinv_taxable',
245
                                    'name'    => 'disable_taxes',
246
                                    'type'    => 'checkbox',
247
                                    'label'   => __( 'Disable taxes', 'invoicing' ),
248
                                    'value'   => '1',
249
                                    'checked' => (bool) $invoice->get_disable_taxes(),
250
                                    'class'   => 'getpaid-recalculate-prices-on-change',
251
                                ),
252
                                true
253
                            );
254
255
                        }
256
257
                        if ( $invoice->is_type( 'invoice' ) ) {
258
259
                            // Send to customer.
260
                            aui()->input(
261
                                array(
262
                                    'id'      => 'wpinv_send_to_customer',
263
                                    'name'    => 'send_to_customer',
264
                                    'type'    => 'checkbox',
265
                                    'label'   => __( 'Send invoice to customer after saving', 'invoicing' ),
266
                                    'value'   => '1',
267
                                    'checked' => $invoice->is_draft() && (bool) wpinv_get_option( 'email_user_invoice_active', true ),
268
                                ),
269
                                true
270
                            );
271
272
                        }
273
274
                        do_action( 'getpaid_metabox_after_invoice_details', $invoice );
275
276
                    ?>
277
278
                </div>
279
280
        <?php
281
    }
282
}
283