/app/view/billing/class-ms-view-billing-edit.php

  1. <?php 
  2.  
  3. /** 
  4. * Render Invoice add/edit view. 
  5. * 
  6. * Extends MS_View for rendering methods and magic methods. 
  7. * 
  8. * @since 1.0.0 
  9. * 
  10. * @package Membership2 
  11. * @subpackage View 
  12. */ 
  13. class MS_View_Billing_Edit extends MS_View { 
  14.  
  15. /** 
  16. * Create view output. 
  17. * 
  18. * @since 1.0.0 
  19. * 
  20. * @return string 
  21. */ 
  22. public function to_html() { 
  23. $this->check_simulation(); 
  24.  
  25. $fields = $this->prepare_fields(); 
  26. $form_url = esc_url_raw( 
  27. remove_query_arg( array( 'action', 'invoice_id' ) ) 
  28. ); 
  29.  
  30. if ( $this->data['invoice']->is_valid() ) { 
  31. $title = __( 'Edit Billing', 'membership2' ); 
  32. } else { 
  33. $title = __( 'Add Billing', 'membership2' ); 
  34.  
  35. ob_start(); 
  36. // Render tabbed interface. 
  37. ?> 
  38. <div class="ms-wrap ms-billing"> 
  39. <?php 
  40. MS_Helper_Html::settings_header( 
  41. array( 
  42. 'title' => $title,  
  43. 'title_icon_class' => 'wpmui-fa wpmui-fa-pencil-square',  
  44. ); 
  45. ?> 
  46. <form action="<?php echo $form_url; ?>" method="post" class="ms-form"> 
  47. <?php MS_Helper_Html::settings_box( $fields, '', '', 'static', 'ms-small-form' ); ?> 
  48. </form> 
  49. <div class="clear"></div> 
  50. </div> 
  51. <?php 
  52. $html = ob_get_clean(); 
  53.  
  54. return apply_filters( 'ms_view_billing_edit_to_html', $html, $this ); 
  55.  
  56. /** 
  57. * Prepare html fields. 
  58. * 
  59. * @since 1.0.0 
  60. * 
  61. * @return array 
  62. */ 
  63. function prepare_fields() { 
  64. $invoice = $this->data['invoice']; 
  65. $currency = MS_Plugin::instance()->settings->currency; 
  66. $user_name = ''; 
  67. $transaction_link = ''; 
  68. $user_id = 0; 
  69. $user_list = array(); 
  70.  
  71. if ( $invoice->id ) { 
  72. $member = $invoice->get_member(); 
  73. $user_id = $member->id; 
  74. $user_name = $member->name; 
  75.  
  76. $transaction_link = sprintf( 
  77. '<a href="%s" target="_blank">%s</a>',  
  78. MS_Controller_Plugin::get_admin_url( 
  79. 'billing',  
  80. array( 'show' => 'logs', 'invoice' => $invoice->id ) 
  81. ),  
  82. __( 'Show Transactions', 'membership2' ) 
  83. ); 
  84. } else { 
  85. $user_list = MS_Model_Member::get_usernames( null, MS_Model_Member::SEARCH_ALL_USERS ); 
  86.  
  87. $fields = array( 
  88. 'link_transactions' => array( 
  89. 'id' => 'link_transactions',  
  90. 'title' => $transaction_link,  
  91. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  92. 'wrapper_class' => 'ms-transactions-link',  
  93. ),  
  94. 'txt_user' => array( 
  95. 'id' => 'txt_user',  
  96. 'title' => __( 'Invoice for member', 'membership2' ),  
  97. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  98. 'value' => sprintf( 
  99. '<a href="%s">%s</a>',  
  100. MS_Controller_Plugin::get_admin_url( 
  101. 'add-member',  
  102. array( 'user_id' => $user_id ) 
  103. ),  
  104. $user_name 
  105. ),  
  106. ),  
  107. 'txt_membership' => array( 
  108. 'id' => 'txt_membership',  
  109. 'title' => __( 'Payment for membership', 'membership2' ),  
  110. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  111. ),  
  112. 'txt_created' => array( 
  113. 'id' => 'txt_created',  
  114. 'title' => __( 'Invoice created on', 'membership2' ),  
  115. 'type' => MS_Helper_Html::TYPE_HTML_TEXT,  
  116. ),  
  117. 'txt_separator' => array( 
  118. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  119. ),  
  120. 'status' => array( 
  121. 'id' => 'status',  
  122. 'title' => __( 'Invoice status', 'membership2' ),  
  123. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  124. 'field_options' => MS_Model_Invoice::get_status_types( true ),  
  125. 'value' => $invoice->status,  
  126. ),  
  127. 'user_id' => array( 
  128. 'id' => 'user_id',  
  129. 'title' => __( 'Invoice for member', 'membership2' ),  
  130. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  131. 'value' => $invoice->user_id,  
  132. 'field_options' => $user_list,  
  133. ),  
  134. 'membership_id' => array( 
  135. 'id' => 'membership_id',  
  136. 'title' => __( 'Payment for membership', 'membership2' ),  
  137. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  138. 'value' => $invoice->membership_id,  
  139. 'field_options' => $this->data['memberships'],  
  140. ),  
  141. 'amount' => array( 
  142. 'id' => 'amount',  
  143. 'title' => sprintf( __( 'Amount (%s)', 'membership2' ), $currency ),  
  144. 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER,  
  145. 'value' => MS_Helper_Billing::format_price( $invoice->amount ),  
  146. 'config' => array( 
  147. 'step' => 'any',  
  148. 'min' => 0,  
  149. ),  
  150. ),  
  151. 'discount' => array( 
  152. 'id' => 'discount',  
  153. 'title' => sprintf( __( 'Discount (%s)', 'membership2' ), $currency ),  
  154. 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER,  
  155. 'value' => MS_Helper_Billing::format_price( $invoice->discount ),  
  156. 'config' => array( 
  157. 'step' => 'any',  
  158. 'min' => 0,  
  159. ),  
  160. ),  
  161. 'due_date' => array( 
  162. 'id' => 'due_date',  
  163. 'title' => __( 'Due date', 'membership2' ),  
  164. 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER,  
  165. 'value' => $invoice->due_date,  
  166. ),  
  167. 'description' => array( 
  168. 'id' => 'description',  
  169. 'title' => __( 'Description', 'membership2' ),  
  170. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  171. 'class' => 'widefat',  
  172. 'value' => $invoice->description,  
  173. ),  
  174. 'notes' => array( 
  175. 'id' => 'notes',  
  176. 'title' => __( 'Notes', 'membership2' ),  
  177. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT_AREA,  
  178. 'class' => 'widefat',  
  179. 'value' => $invoice->get_notes_desc(),  
  180. ),  
  181. 'invoice_id' => array( 
  182. 'id' => 'invoice_id',  
  183. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  184. 'value' => $invoice->id,  
  185. ),  
  186. '_wpnonce' => array( 
  187. 'id' => '_wpnonce',  
  188. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  189. 'value' => wp_create_nonce( $this->data['action'] ),  
  190. ),  
  191. 'action' => array( 
  192. 'id' => 'action',  
  193. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  194. 'value' => $this->data['action'],  
  195. ),  
  196. 'separator' => array( 
  197. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  198. ),  
  199. 'execute' => array( 
  200. 'id' => 'execute',  
  201. 'title' => __( 'Execute status change actions on Save (add/remove membership)', 'membership2' ),  
  202. 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX,  
  203. 'value' => true,  
  204. ),  
  205. 'cancel' => array( 
  206. 'id' => 'cancel',  
  207. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  208. 'title' => __( 'Cancel', 'membership2' ),  
  209. 'value' => __( 'Cancel', 'membership2' ),  
  210. 'url' => esc_url_raw( remove_query_arg( array( 'action', 'invoice_id' ) ) ),  
  211. 'class' => 'wpmui-field-button button',  
  212. ),  
  213. 'submit' => array( 
  214. 'id' => 'submit',  
  215. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  216. 'value' => __( 'Save Changes', 'membership2' ),  
  217. ),  
  218. ); 
  219.  
  220. if ( $invoice->id > 0 ) { 
  221. $fields['user_id']['type'] = MS_Helper_Html::INPUT_TYPE_HIDDEN; 
  222. $fields['membership_id']['type'] = MS_Helper_Html::INPUT_TYPE_HIDDEN; 
  223. $fields['txt_membership']['value'] = $this->data['memberships'][ $invoice->membership_id ]; 
  224. $fields['txt_created']['value'] = MS_Helper_Period::format_date( $invoice->invoice_date ); 
  225. } else { 
  226. unset( $fields['txt_user'] ); 
  227. unset( $fields['txt_membership'] ); 
  228. unset( $fields['txt_created'] ); 
  229. unset( $fields['txt_separator'] ); 
  230.  
  231. return apply_filters( 
  232. 'ms_view_billing_edit_prepare_fields',  
  233. $fields,  
  234. $this 
  235. ); 
.