MS_Addon_Taxamo_Userprofile

The members tax settings editor.

Defined (1)

The class is defined in the following location(s).

/app/addon/taxamo/class-ms-addon-taxamo-userprofile.php  
  1. class MS_Addon_Taxamo_Userprofile extends MS_View { 
  2.  
  3. public function to_html() { 
  4. $fields = $this->prepare_fields(); 
  5.  
  6. $classes = array(); 
  7. $classes[] = 'ms-tax-' . $fields['country_choice']['value']; 
  8.  
  9. ob_start(); 
  10. ?> 
  11. <div class="ms-wrap <?php echo esc_attr( implode( ' ', $classes ) ); ?>"> 
  12. <div class="modal-header"> 
  13. <button type="button" class="close">×</button> 
  14. <h4 class="modal-title"><?php _e( 'Tax Settings', 'membership2' ); ?></h4> 
  15. </div> 
  16. <div class="modal-body"> 
  17.  
  18. <?php 
  19. foreach ( $fields as $field ) { 
  20. MS_Helper_Html::html_element( $field ); 
  21. ?> 
  22.  
  23. </div> 
  24. <div class="modal-footer"> 
  25. <button type="button" class="btn btn-default close"><?php _e( 'Close', 'membership2' ); ?></button> 
  26. <button type="button" class="btn btn-primary save"><?php _e( 'Save', 'membership2' ); ?></button> 
  27. </div> 
  28. <div class="loading-message"> 
  29. <?php _e( 'Saving data, please wait...', 'membership2' ); ?> 
  30. </div> 
  31. </div> 
  32. <div class="body-messages"> 
  33. <div class="ms-tax-loading-overlay"></div> 
  34. <div class="ms-tax-loading-message"><?php _e( 'Refreshing page, please wait...', 'membership2' ); ?></div> 
  35. </div> 
  36. <?php 
  37. $html = ob_get_clean(); 
  38.  
  39. return apply_filters( 
  40. 'ms_addon_taxamo_userprofile',  
  41. $html 
  42. ); 
  43.  
  44. public function prepare_fields() { 
  45. $fields = array(); 
  46. $invoice_id = false; 
  47.  
  48. if ( isset( $this->data['invoice'] ) ) { 
  49. $invoice = $this->data['invoice']; 
  50. $invoice_id = $invoice->id; 
  51.  
  52. $profile = MS_Addon_Taxamo_Api::get_tax_profile(); 
  53. $countries = MS_Addon_Taxamo_Api::get_country_codes(); 
  54. $action = MS_Addon_Taxamo::AJAX_SAVE_USERPROFILE; 
  55. $nonce = wp_create_nonce( $action ); 
  56.  
  57. $country_options = array( 
  58. 'auto' => sprintf( 
  59. __( 'The detected country %s is correct.', 'membership2' ),  
  60. '<strong>' . $profile->detected_country->name . '</strong>' 
  61. ),  
  62. 'vat' => __( 'I have an EU VAT number and want to use it for tax declaration.', 'membership2' ),  
  63. 'declared' => __( 'Manually declare my country of residence.', 'membership2' ),  
  64. ); 
  65.  
  66. $vat_details = ''; 
  67. if ( ! empty( $profile->vat_number ) && $profile->vat_valid ) { 
  68. $vat_details = sprintf( 
  69. __( 'This is a valid VAT number of %s. By using this you are are now exempt of VAT.', 'membership2' ),  
  70. '<strong>' . $profile->vat_country->name . '</strong>' 
  71. ); 
  72. } else { 
  73. $vat_details = __( 'VAT Number is invalid.', 'membership2' ); 
  74. if ( $profile->use_vat_number ) { 
  75. $tax_message = __( 'Valid EU VAT Number provided: You are exempt of VAT', 'membership2' ); 
  76. } else { 
  77. $tax_message = __( 'The country used for tax calculation is %s', 'membership2' ); 
  78.  
  79. $fields['tax_country_label'] = array( 
  80. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  81. 'title' => sprintf( 
  82. $tax_message,  
  83. '<strong>' . $profile->tax_country->name . '</strong>' 
  84. ),  
  85. 'wrapper_class' => 'effective_tax_country',  
  86. ); 
  87. $fields['detected_country_label'] = array( 
  88. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  89. 'title' => sprintf( 
  90. __( 'We have detected that your computer is located in %s', 'membership2' ),  
  91. '<strong>' . $profile->detected_country->name . '</strong>' 
  92. ),  
  93. ); 
  94. $fields['detected_country'] = array( 
  95. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  96. 'id' => 'detected_country',  
  97. 'value' => $profile->detected_country->code,  
  98. ); 
  99. $fields['country_choice'] = array( 
  100. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO,  
  101. 'id' => 'country_choice',  
  102. 'class' => 'country_choice',  
  103. 'value' => $profile->country_choice,  
  104. 'field_options' => $country_options,  
  105. ); 
  106. $fields['declared_country_code'] = array( 
  107. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  108. 'id' => 'declared_country',  
  109. 'title' => __( 'My country of residence', 'membership2' ),  
  110. 'desc' => __( 'I confirm that I am established, have my permanent address, or usually reside in the following country', 'membership2' ),  
  111. 'value' => $profile->declared_country->code,  
  112. 'field_options' => $countries,  
  113. 'wrapper_class' => 'manual_country_field',  
  114. ); 
  115. $fields['vat_number'] = array( 
  116. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  117. 'id' => 'vat_number',  
  118. 'title' => __( 'EU VAT Number', 'membership2' ),  
  119. 'desc' => __( 'Fill this field if you are representing EU VAT payer', 'membership2' ),  
  120. 'wrapper_class' => 'vat_number_field',  
  121. 'value' => $profile->vat_number,  
  122. 'valid_country' => $profile->vat_country->vat_valid,  
  123. 'after' => $vat_details,  
  124. ); 
  125. $fields['invoice_id'] = array( 
  126. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  127. 'id' => 'invoice_id',  
  128. 'value' => $invoice_id,  
  129. ); 
  130. $fields['action'] = array( 
  131. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  132. 'id' => 'action',  
  133. 'value' => $action,  
  134. ); 
  135. $fields['_wpnonce'] = array( 
  136. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  137. 'id' => '_wpnonce',  
  138. 'value' => $nonce,  
  139. ); 
  140.  
  141. /** 
  142. * 1. Checkbox "I confirm that the country of my main residence is in <country>" (in the payment table!) 
  143. * 4. When VAT is entered the checkbox is disabled and VAT country is used. Checkbox 1 is hidden. 
  144. */ 
  145.  
  146. return apply_filters( 
  147. 'ms_addon_taxamo_userprofile_fields',  
  148. $fields 
  149. );