MS_View_Billing_Edit

Render Invoice add/edit view.

Defined (1)

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

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