1
|
|
|
<?php |
2
|
|
|
// MUST have WordPress. |
3
|
|
|
if ( !defined( 'WPINC' ) ) { |
4
|
|
|
exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
class WPInv_Meta_Box_Items { |
8
|
|
|
public static function output( $post ) { |
9
|
|
|
global $wpinv_euvat, $ajax_cart_details; |
10
|
|
|
|
11
|
|
|
$post_id = !empty( $post->ID ) ? $post->ID : 0; |
12
|
|
|
$invoice = new WPInv_Invoice( $post_id ); |
13
|
|
|
$ajax_cart_details = $invoice->get_cart_details(); |
14
|
|
|
$subtotal = $invoice->get_subtotal( true ); |
15
|
|
|
$discount_raw = $invoice->get_discount(); |
16
|
|
|
$discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
|
|
|
|
17
|
|
|
$discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
|
|
|
|
18
|
|
|
$tax = $invoice->get_tax( true ); |
19
|
|
|
$total = $invoice->get_total( true ); |
20
|
|
|
$item_quantities = wpinv_item_quantities_enabled(); |
21
|
|
|
$use_taxes = wpinv_use_taxes(); |
22
|
|
|
$item_types = wpinv_get_item_types(); |
23
|
|
|
$is_recurring = $invoice->is_recurring(); |
24
|
|
|
$post_type_object = get_post_type_object($invoice->post_type); |
25
|
|
|
$type_title = $post_type_object->labels->singular_name; |
26
|
|
|
|
27
|
|
|
if (isset($item_types['package'])) { |
28
|
|
|
unset($item_types['package']); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$cols = 5; |
32
|
|
|
if ( $item_quantities ) { |
33
|
|
|
$cols++; |
34
|
|
|
} |
35
|
|
|
if ( $use_taxes ) { |
36
|
|
|
$cols++; |
37
|
|
|
} |
38
|
|
|
$class = ''; |
39
|
|
|
if ( $invoice->is_paid() ) { |
40
|
|
|
$class .= ' wpinv-paid'; |
41
|
|
|
} |
42
|
|
|
if ( $is_recurring ) { |
43
|
|
|
$class .= ' wpi-recurring'; |
44
|
|
|
} |
45
|
|
|
?> |
46
|
|
|
<div class="wpinv-items-wrap<?php echo $class; ?>" id="wpinv_items_wrap" data-status="<?php echo $invoice->status; ?>"> |
47
|
|
|
<table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
48
|
|
|
<thead> |
49
|
|
|
<tr> |
50
|
|
|
<th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
51
|
|
|
<th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
52
|
|
|
<th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
53
|
|
|
<?php if ( $item_quantities ) { ?> |
54
|
|
|
<th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
55
|
|
|
<?php } ?> |
56
|
|
|
<th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
57
|
|
|
<?php if ( $use_taxes ) { ?> |
58
|
|
|
<th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
59
|
|
|
<?php } ?> |
60
|
|
|
<th class="action"></th> |
61
|
|
|
</tr> |
62
|
|
|
</thead> |
63
|
|
|
<tbody class="wpinv-line-items"> |
64
|
|
|
<?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
|
|
|
65
|
|
|
</tbody> |
66
|
|
|
<tfoot class="wpinv-totals"> |
67
|
|
|
<tr> |
68
|
|
|
<td colspan="<?php echo $cols; ?>" style="padding:0;border:0"> |
69
|
|
|
<div id="wpinv-quick-add"> |
70
|
|
|
<table cellspacing="0" cellpadding="0"> |
71
|
|
|
<tr> |
72
|
|
|
<td class="id"> |
73
|
|
|
</td> |
74
|
|
|
<td class="title"> |
75
|
|
|
<input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]"> |
76
|
|
|
<?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
77
|
|
|
<div class="wp-clearfix"> |
78
|
|
|
<label class="wpi-vat-rule"> |
79
|
|
|
<span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
80
|
|
|
<span class="input-text-wrap"> |
81
|
|
|
<?php echo wpinv_html_select( array( |
82
|
|
|
'options' => $wpinv_euvat->get_rules(), |
83
|
|
|
'name' => '_wpinv_quick[vat_rule]', |
84
|
|
|
'id' => '_wpinv_quick_vat_rule', |
85
|
|
|
'show_option_all' => false, |
86
|
|
|
'show_option_none' => false, |
87
|
|
|
'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
88
|
|
|
) ); ?> |
89
|
|
|
</span> |
90
|
|
|
</label> |
91
|
|
|
</div> |
92
|
|
|
<?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
93
|
|
|
<div class="wp-clearfix"> |
94
|
|
|
<label class="wpi-vat-class"> |
95
|
|
|
<span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
96
|
|
|
<span class="input-text-wrap"> |
97
|
|
|
<?php echo wpinv_html_select( array( |
98
|
|
|
'options' => $wpinv_euvat->get_all_classes(), |
99
|
|
|
'name' => '_wpinv_quick[vat_class]', |
100
|
|
|
'id' => '_wpinv_quick_vat_class', |
101
|
|
|
'show_option_all' => false, |
102
|
|
|
'show_option_none' => false, |
103
|
|
|
'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
104
|
|
|
) ); ?> |
105
|
|
|
</span> |
106
|
|
|
</label> |
107
|
|
|
</div> |
108
|
|
|
<?php } ?> |
109
|
|
|
<div class="wp-clearfix"> |
110
|
|
|
<label class="wpi-item-type"> |
111
|
|
|
<span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
112
|
|
|
<span class="input-text-wrap"> |
113
|
|
|
<?php echo wpinv_html_select( array( |
114
|
|
|
'options' => $item_types, |
115
|
|
|
'name' => '_wpinv_quick[type]', |
116
|
|
|
'id' => '_wpinv_quick_type', |
117
|
|
|
'selected' => 'custom', |
118
|
|
|
'show_option_all' => false, |
119
|
|
|
'show_option_none' => false, |
120
|
|
|
'class' => 'gdmbx2-text-medium wpinv-quick-type', |
121
|
|
|
) ); ?> |
122
|
|
|
</span> |
123
|
|
|
</label> |
124
|
|
|
</div> |
125
|
|
|
<div class="wp-clearfix"> |
126
|
|
|
<label class="wpi-item-actions"> |
127
|
|
|
<span class="input-text-wrap"> |
128
|
|
|
<input type="button" value="Save" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
129
|
|
|
</span> |
130
|
|
|
</label> |
131
|
|
|
</div> |
132
|
|
|
</td> |
133
|
|
|
<td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
134
|
|
|
<?php if ( $item_quantities ) { ?> |
135
|
|
|
<td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
136
|
|
|
<?php } ?> |
137
|
|
|
<td class="total"></td> |
138
|
|
|
<?php if ( $use_taxes ) { ?> |
139
|
|
|
<td class="tax"></td> |
140
|
|
|
<?php } ?> |
141
|
|
|
<td class="action"></td> |
142
|
|
|
</tr> |
143
|
|
|
</table> |
144
|
|
|
</div> |
145
|
|
|
</td> |
146
|
|
|
</tr> |
147
|
|
|
<tr class="clear"> |
148
|
|
|
<td colspan="<?php echo $cols; ?>"></td> |
149
|
|
|
</tr> |
150
|
|
|
<tr class="totals"> |
151
|
|
|
<td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
152
|
|
|
<td colspan="4"> |
153
|
|
|
<table cellspacing="0" cellpadding="0"> |
154
|
|
|
<tr class="subtotal"> |
155
|
|
|
<td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
156
|
|
|
<td class="total"><?php echo $subtotal;?></td> |
157
|
|
|
<td class="action"></td> |
158
|
|
|
</tr> |
159
|
|
|
<tr class="discount"> |
160
|
|
|
<td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
161
|
|
|
<td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
162
|
|
|
<td class="action"></td> |
163
|
|
|
</tr> |
164
|
|
|
<?php if ( $use_taxes ) { ?> |
165
|
|
|
<tr class="tax"> |
166
|
|
|
<td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
167
|
|
|
<td class="total"><?php echo $tax;?></td> |
168
|
|
|
<td class="action"></td> |
169
|
|
|
</tr> |
170
|
|
|
<?php } ?> |
171
|
|
|
<tr class="total"> |
172
|
|
|
<td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td> |
173
|
|
|
<td class="total"><?php echo $total;?></td> |
174
|
|
|
<td class="action"></td> |
175
|
|
|
</tr> |
176
|
|
|
</table> |
177
|
|
|
</td> |
178
|
|
|
</tr> |
179
|
|
|
</tfoot> |
180
|
|
|
</table> |
181
|
|
|
<div class="wpinv-actions"> |
182
|
|
|
<?php |
183
|
|
|
if ( !$invoice->is_paid() ) { |
184
|
|
|
if ( !$invoice->is_recurring() ) { |
185
|
|
|
echo wpinv_item_dropdown( array( |
186
|
|
|
'name' => 'wpinv_invoice_item', |
187
|
|
|
'id' => 'wpinv_invoice_item', |
188
|
|
|
'with_packages' => false, |
189
|
|
|
'show_recurring' => true, |
190
|
|
|
) ); |
191
|
|
|
?> |
192
|
|
|
<input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
193
|
|
|
<?php } ?> |
194
|
|
|
<?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
195
|
|
|
</div> |
196
|
|
|
</div> |
197
|
|
|
<?php |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public static function prices( $post ) { |
201
|
|
|
$symbol = wpinv_currency_symbol(); |
202
|
|
|
$position = wpinv_currency_position(); |
203
|
|
|
$item = new WPInv_Item( $post->ID ); |
204
|
|
|
|
205
|
|
|
$price = $item->get_price(); |
206
|
|
|
$is_recurring = $item->is_recurring(); |
207
|
|
|
$period = $item->get_recurring_period(); |
208
|
|
|
$interval = absint( $item->get_recurring_interval() ); |
209
|
|
|
$times = absint( $item->get_recurring_limit() ); |
210
|
|
|
$free_trial = $item->has_free_trial(); |
211
|
|
|
$trial_interval = $item->get_trial_interval(); |
212
|
|
|
$trial_period = $item->get_trial_period(); |
213
|
|
|
|
214
|
|
|
$intervals = array(); |
215
|
|
|
for ( $i = 1; $i <= 90; $i++ ) { |
216
|
|
|
$intervals[$i] = $i; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
$interval = $interval > 0 ? $interval : 1; |
220
|
|
|
|
221
|
|
|
$class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
222
|
|
|
?> |
223
|
|
|
<p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" /> |
224
|
|
|
<?php if ( $item->is_package() ) { ?> |
225
|
|
|
<span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span> |
226
|
|
|
<?php } ?> |
227
|
|
|
</p> |
228
|
|
|
<p class="wpinv-row-is-recurring"> |
229
|
|
|
<label for="wpinv_is_recurring"> |
230
|
|
|
<input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
231
|
|
|
<?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
232
|
|
|
</label> |
233
|
|
|
</p> |
234
|
|
|
<p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
235
|
|
|
<label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label> |
236
|
|
|
<label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
237
|
|
|
'options' => $intervals, |
238
|
|
|
'name' => 'wpinv_recurring_interval', |
239
|
|
|
'id' => 'wpinv_recurring_interval', |
240
|
|
|
'selected' => $interval, |
241
|
|
|
'show_option_all' => false, |
242
|
|
|
'show_option_none' => false |
243
|
|
|
) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
244
|
|
|
<label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label> |
245
|
|
|
<span class="clear wpi-trial-clr"></span> |
246
|
|
|
<label class="wpinv-free-trial" for="wpinv_free_trial"> |
247
|
|
|
<input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
248
|
|
|
<?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
249
|
|
|
</label> |
250
|
|
|
<label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
251
|
|
|
<input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select> |
252
|
|
|
</label> |
253
|
|
|
</p> |
254
|
|
|
<input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
255
|
|
|
<?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
256
|
|
|
<?php |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public static function vat_rules( $post ) { |
260
|
|
|
global $wpinv_euvat; |
261
|
|
|
|
262
|
|
|
$rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
263
|
|
|
?> |
264
|
|
|
<p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
265
|
|
|
<?php echo wpinv_html_select( array( |
266
|
|
|
'options' => $wpinv_euvat->get_rules(), |
267
|
|
|
'name' => 'wpinv_vat_rules', |
268
|
|
|
'id' => 'wpinv_vat_rules', |
269
|
|
|
'selected' => $rule_type, |
270
|
|
|
'show_option_all' => false, |
271
|
|
|
'show_option_none' => false, |
272
|
|
|
'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
273
|
|
|
) ); ?> |
274
|
|
|
</p> |
275
|
|
|
<p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p> |
276
|
|
|
<p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p> |
277
|
|
|
<?php |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public static function vat_classes( $post ) { |
281
|
|
|
global $wpinv_euvat; |
282
|
|
|
|
283
|
|
|
$vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
284
|
|
|
?> |
285
|
|
|
<p><?php echo wpinv_html_select( array( |
286
|
|
|
'options' => $wpinv_euvat->get_all_classes(), |
287
|
|
|
'name' => 'wpinv_vat_class', |
288
|
|
|
'id' => 'wpinv_vat_class', |
289
|
|
|
'selected' => $vat_class, |
290
|
|
|
'show_option_all' => false, |
291
|
|
|
'show_option_none' => false, |
292
|
|
|
'class' => 'gdmbx2-text-medium wpinv-vat-class', |
293
|
|
|
) ); ?> |
294
|
|
|
</p> |
295
|
|
|
<p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
296
|
|
|
<?php |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public static function item_info( $post ) { |
300
|
|
|
$item_type = wpinv_get_item_type( $post->ID ); |
301
|
|
|
do_action( 'wpinv_item_info_metabox_before', $post ); |
302
|
|
|
?> |
303
|
|
|
<p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
304
|
|
|
<?php echo wpinv_html_select( array( |
305
|
|
|
'options' => wpinv_get_item_types(), |
306
|
|
|
'name' => 'wpinv_item_type', |
307
|
|
|
'id' => 'wpinv_item_type', |
308
|
|
|
'selected' => $item_type, |
309
|
|
|
'show_option_all' => false, |
310
|
|
|
'show_option_none' => false, |
311
|
|
|
'class' => 'gdmbx2-text-medium wpinv-item-type', |
312
|
|
|
//'disabled' => $item_type == 'package' ? true : false, |
|
|
|
|
313
|
|
|
) ); ?> |
314
|
|
|
</p> |
315
|
|
|
<p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p> |
316
|
|
|
<?php |
317
|
|
|
do_action( 'wpinv_item_info_metabox_after', $post ); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
public static function meta_values( $post ) { |
321
|
|
|
$meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array( |
322
|
|
|
'type', |
323
|
|
|
'custom_id' |
324
|
|
|
) ); |
325
|
|
|
|
326
|
|
|
if ( empty( $meta_keys ) ) { |
327
|
|
|
return; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
do_action( 'wpinv_meta_values_metabox_before', $post ); |
331
|
|
|
|
332
|
|
|
foreach ( $meta_keys as $meta_key ) { |
333
|
|
|
?> |
334
|
|
|
<p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p> |
335
|
|
|
<?php |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
do_action( 'wpinv_meta_values_metabox_after', $post ); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
public static function save( $post_id, $data, $post ) { |
|
|
|
|
342
|
|
|
$invoice = new WPInv_Invoice( $post_id ); |
343
|
|
|
|
344
|
|
|
// Billing |
345
|
|
|
$first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
346
|
|
|
$last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
347
|
|
|
$company = sanitize_text_field( $data['wpinv_company'] ); |
348
|
|
|
$vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
349
|
|
|
$phone = sanitize_text_field( $data['wpinv_phone'] ); |
350
|
|
|
$address = sanitize_text_field( $data['wpinv_address'] ); |
351
|
|
|
$city = sanitize_text_field( $data['wpinv_city'] ); |
352
|
|
|
$zip = sanitize_text_field( $data['wpinv_zip'] ); |
353
|
|
|
$country = sanitize_text_field( $data['wpinv_country'] ); |
354
|
|
|
$state = sanitize_text_field( $data['wpinv_state'] ); |
355
|
|
|
|
356
|
|
|
// Details |
357
|
|
|
$status = sanitize_text_field( $data['wpinv_status'] ); |
358
|
|
|
$old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
|
|
|
359
|
|
|
$number = sanitize_text_field( $data['wpinv_number'] ); |
360
|
|
|
$due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
361
|
|
|
//$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
|
|
|
|
362
|
|
|
//$discount = sanitize_text_field( $data['wpinv_discount'] ); |
|
|
|
|
363
|
|
|
|
364
|
|
|
$ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
365
|
|
|
|
366
|
|
|
$invoice->set( 'due_date', $due_date ); |
367
|
|
|
$invoice->set( 'first_name', $first_name ); |
368
|
|
|
$invoice->set( 'last_name', $last_name ); |
369
|
|
|
$invoice->set( 'company', $company ); |
370
|
|
|
$invoice->set( 'vat_number', $vat_number ); |
371
|
|
|
$invoice->set( 'phone', $phone ); |
372
|
|
|
$invoice->set( 'address', $address ); |
373
|
|
|
$invoice->set( 'city', $city ); |
374
|
|
|
$invoice->set( 'zip', $zip ); |
375
|
|
|
$invoice->set( 'country', $country ); |
376
|
|
|
$invoice->set( 'state', $state ); |
377
|
|
|
$invoice->set( 'status', $status ); |
378
|
|
|
$invoice->set( 'number', $number ); |
379
|
|
|
//$invoice->set( 'discounts', $discounts ); |
|
|
|
|
380
|
|
|
//$invoice->set( 'discount', $discount ); |
|
|
|
|
381
|
|
|
$invoice->set( 'ip', $ip ); |
382
|
|
|
$invoice->old_status = $_POST['original_post_status']; |
383
|
|
|
$invoice->currency = wpinv_get_currency(); |
384
|
|
|
if ( !empty( $data['wpinv_gateway'] ) ) { |
385
|
|
|
$invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
386
|
|
|
} |
387
|
|
|
$saved = $invoice->save(); |
388
|
|
|
|
389
|
|
|
// Check for payment notes |
390
|
|
|
if ( !empty( $data['invoice_note'] ) ) { |
391
|
|
|
$note = wp_kses( $data['invoice_note'], array() ); |
392
|
|
|
$note_type = sanitize_text_field( $data['invoice_note_type'] ); |
393
|
|
|
$is_customer_note = $note_type == 'customer' ? 1 : 0; |
394
|
|
|
|
395
|
|
|
wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
|
|
|
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
// Update user address if empty. |
399
|
|
|
if ( $saved && !empty( $invoice ) ) { |
400
|
|
|
if ( $user_id = $invoice->get_user_id() ) { |
401
|
|
|
$user_address = wpinv_get_user_address( $user_id, false ); |
402
|
|
|
|
403
|
|
|
if (empty($user_address['first_name'])) { |
404
|
|
|
update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
405
|
|
|
update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
406
|
|
|
} else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
407
|
|
|
update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
411
|
|
|
update_user_meta( $user_id, '_wpinv_address', $address ); |
412
|
|
|
update_user_meta( $user_id, '_wpinv_city', $city ); |
413
|
|
|
update_user_meta( $user_id, '_wpinv_state', $state ); |
414
|
|
|
update_user_meta( $user_id, '_wpinv_country', $country ); |
415
|
|
|
update_user_meta( $user_id, '_wpinv_zip', $zip ); |
416
|
|
|
update_user_meta( $user_id, '_wpinv_phone', $phone ); |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
return $saved; |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.