Passed
Push — master ( a2648f...42db48 )
by Brian
195:36 queued 107:03
created

GetPaid_Meta_Box_Item_VAT::output_vat_classes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 26
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 27
rs 9.504
1
<?php
2
3
/**
4
 * Item VAT
5
 *
6
 * Display the item data meta box.
7
 *
8
 */
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit; // Exit if accessed directly
12
}
13
14
/**
15
 * GetPaid_Meta_Box_Item_VAT Class.
16
 */
17
class GetPaid_Meta_Box_Item_VAT {
18
19
    /**
20
	 * Output the metabox.
21
	 *
22
	 * @param WP_Post $post
23
	 */
24
    public static function output( $post ) {
25
        global $wpinv_euvat;
26
27
        // Prepare the item.
28
        $item = new WPInv_Item( $post );
29
30
        echo "<div class='bsui' style='max-width: 600px;padding-top: 10px;'>";
31
32
        do_action( 'wpinv_item_before_vat_metabox', $item );
33
34
        // Output the vat rules settings.
35
        if ( $wpinv_euvat->allow_vat_rules() ) {
36
            do_action( 'wpinv_item_vat_metabox_before_vat_rules', $item );
37
            self::output_vat_rules( $item, $wpinv_euvat );
38
            do_action( 'wpinv_item_vat_metabox_vat_rules', $item );
39
        }
40
41
        // Output vat class settings.
42
        if ( $wpinv_euvat->allow_vat_classes() ) {
43
            do_action( 'wpinv_item_vat_metabox_before_vat_rules', $item );
44
            self::output_vat_classes( $item, $wpinv_euvat );
45
            do_action( 'wpinv_item_vat_metabox_vat_class', $item );
46
        }
47
48
        do_action( 'wpinv_item_vat_metabox', $item );
49
50
        echo '</div>';
51
    }
52
53
    /**
54
	 * Output the VAT rules settings.
55
	 *
56
	 * @param WPInv_Item $item
57
     * @param WPInv_EUVat $wpinv_euvat
58
	 */
59
    public static function output_vat_rules( $item, $wpinv_euvat ) {
60
        ?>
61
62
            <div class="wpinv_vat_rules">
63
64
                <div class="form-group row">
65
                    <label for="wpinv_vat_rules" class="col-sm-3 col-form-label">
66
                        <?php _e( 'VAT Rule', 'invoicing' );?>
67
                    </label>
68
                    <div class="col-sm-8">
69
                        <?php
70
                            echo aui()->select(
71
                                array(
72
                                    'id'               => 'wpinv_vat_rules',
73
                                    'name'             => 'wpinv_vat_rules',
74
                                    'placeholder'      => __( 'Select VAT rule', 'invoicing' ),
75
                                    'value'            => $item->get_vat_rule( 'edit' ),
76
                                    'select2'          => true,
77
                                    'data-allow-clear' => 'false',
78
                                    'no_wrap'          => true,
79
                                    'options'          => $wpinv_euvat->get_rules()
80
                                )
81
                            );
82
                        ?>
83
                    </div>
84
                    <div class="col-sm-1 pt-2 pl-0">
85
                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_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. <br><br>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' ); ?>"></span>
86
                    </div>
87
                </div>
88
89
            </div>
90
91
        <?php
92
93
    }
94
95
    /**
96
	 * Output the VAT class settings.
97
	 *
98
	 * @param WPInv_Item $item
99
     * @param WPInv_EUVat $wpinv_euvat
100
	 */
101
    public static function output_vat_classes( $item, $wpinv_euvat ) {
102
        ?>
103
104
            <div class="wpinv_vat_classes">
105
106
                <div class="form-group row">
107
                    <label for="wpinv_vat_class" class="col-sm-3 col-form-label">
108
                        <?php _e( 'VAT Class', 'invoicing' );?>
109
                    </label>
110
                    <div class="col-sm-8">
111
                        <?php
112
                            echo aui()->select(
113
                                array(
114
                                    'id'               => 'wpinv_vat_class',
115
                                    'name'             => 'wpinv_vat_class',
116
                                    'placeholder'      => __( 'Select VAT class', 'invoicing' ),
117
                                    'value'            => $item->get_vat_class( 'edit' ),
118
                                    'select2'          => true,
119
                                    'data-allow-clear' => 'false',
120
                                    'no_wrap'          => true,
121
                                    'options'          => $wpinv_euvat->get_all_classes()
122
                                )
123
                            );
124
                        ?>
125
                    </div>
126
                    <div class="col-sm-1 pt-2 pl-0">
127
                        <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the VAT rate class to use for this invoice item', 'invoicing' ); ?>"></span>
128
                    </div>
129
                </div>
130
131
            </div>
132
133
        <?php
134
135
    }
136
137
}
138