Passed
Push — master ( 9b80b5...fde38c )
by Brian
06:01
created

GetPaid_Meta_Box_Invoice_Details   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 248
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 166
c 1
b 0
f 0
dl 0
loc 248
rs 10
wmc 18

1 Method

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