/app/addon/taxamo/class-ms-addon-taxamo-userprofile.php

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