MS_View_Billing_List

Renders Billing/Transaction History.

Defined (1)

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

/app/view/billing/class-ms-view-billing-list.php  
  1. class MS_View_Billing_List 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. $buttons = array(); 
  12.  
  13. $module = 'billing'; 
  14. if ( isset( $_GET['show'] ) ) { 
  15. $module = $_GET['show']; 
  16.  
  17. if ( ! $module ) { 
  18. // Show a message if there are error-state transactions. 
  19. $args = array( 'state' => 'err' ); 
  20. $error_count = MS_Model_Transactionlog::get_item_count( $args ); 
  21.  
  22. if ( $error_count ) { 
  23. if ( 1 == $error_count ) { 
  24. $message = __( 'One transaction failed. Please %2$sreview the logs%3$s and decide if you want to ignore the transaction or manually assign it to an invoice.', 'membership2' ); 
  25. } else { 
  26. $message = __( '%1$s transactions failed. Please %2$sreview the logs%3$s and decide if you want to ignore the transaction or manually assign it to an invoice.', 'membership2' ); 
  27. $review_url = MS_Controller_Plugin::get_admin_url( 
  28. 'billing',  
  29. array( 
  30. 'show' => 'logs',  
  31. 'state' => 'err',  
  32. ); 
  33.  
  34. lib3()->ui->admin_message( 
  35. sprintf( 
  36. $message,  
  37. $error_count,  
  38. '<a href="' . $review_url . '">',  
  39. '</a>' 
  40. ),  
  41. 'err' 
  42. ); 
  43.  
  44. // Decide which list to display in the Billings page. 
  45. switch ( $module ) { 
  46. // Transaction logs. 
  47. case 'logs': 
  48. $title = __( 'Transaction Logs', 'membership2' ); 
  49.  
  50. $listview = MS_Factory::create( 'MS_Helper_ListTable_TransactionLog' ); 
  51. $listview->prepare_items(); 
  52.  
  53. $buttons[] = array( 
  54. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  55. 'url' => MS_Controller_Plugin::get_admin_url( 
  56. 'billing' 
  57. ),  
  58. 'value' => __( 'Show Invoices', 'membership2' ),  
  59. 'class' => 'button',  
  60. ); 
  61. break; 
  62.  
  63. // M1 Migration matching. 
  64. case 'matching': 
  65. $title = __( 'Automatic Transaction Matching', 'membership2' ); 
  66.  
  67. $listview = MS_Factory::create( 'MS_Helper_ListTable_TransactionMatching' ); 
  68. $listview->prepare_items(); 
  69.  
  70. $buttons[] = array( 
  71. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  72. 'url' => MS_Controller_Plugin::get_admin_url( 
  73. 'billing' 
  74. ),  
  75. 'value' => __( 'Show Invoices', 'membership2' ),  
  76. 'class' => 'button',  
  77. ); 
  78. $buttons[] = array( 
  79. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  80. 'url' => MS_Controller_Plugin::get_admin_url( 
  81. 'billing',  
  82. array( 'show' => 'logs' ) 
  83. ),  
  84. 'value' => __( 'Show Transaction Logs', 'membership2' ),  
  85. 'class' => 'button',  
  86. ); 
  87.  
  88. break; 
  89.  
  90. // Default billings list. 
  91. case 'billing': 
  92. default: 
  93. $title = __( 'Billing', 'membership2' ); 
  94.  
  95. $listview = MS_Factory::create( 'MS_Helper_ListTable_Billing' ); 
  96. $listview->prepare_items(); 
  97.  
  98. $buttons[] = array( 
  99. 'id' => 'add_new',  
  100. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  101. 'url' => MS_Controller_Plugin::get_admin_url( 
  102. 'billing',  
  103. array( 
  104. 'action' => MS_Controller_Billing::ACTION_EDIT,  
  105. 'invoice_id' => 0,  
  106. ),  
  107. 'value' => __( 'Create new Invoice', 'membership2' ),  
  108. 'class' => 'button',  
  109. ); 
  110. $buttons[] = array( 
  111. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  112. 'url' => MS_Controller_Plugin::get_admin_url( 
  113. 'billing',  
  114. array( 'show' => 'logs' ) 
  115. ),  
  116. 'value' => __( 'Show Transaction Logs', 'membership2' ),  
  117. 'class' => 'button',  
  118. ); 
  119.  
  120. if ( ! empty( $_GET['gateway_id'] ) ) { 
  121. $gateway = MS_Model_Gateway::factory( $_GET['gateway_id'] ); 
  122. if ( $gateway->name ) { 
  123. $title .= ' - ' . $gateway->name; 
  124. break; 
  125.  
  126. if ( 'matching' != $module ) { 
  127. if ( MS_Model_Import::can_match() ) { 
  128. $btn_label = __( 'Setup automatic matching', 'membership2' ); 
  129. $btn_class = 'button'; 
  130. } else { 
  131. $btn_label = '(' . __( 'Setup automatic matching', 'membership2' ) . ')'; 
  132. $btn_class = 'button button-link'; 
  133.  
  134. $buttons[] = array( 
  135. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  136. 'url' => MS_Controller_Plugin::get_admin_url( 
  137. 'billing',  
  138. array( 'show' => 'matching' ) 
  139. ),  
  140. 'value' => $btn_label,  
  141. 'class' => $btn_class,  
  142. ); 
  143.  
  144. // Default list view part - dislay prepared values from above. 
  145. ob_start(); 
  146. ?> 
  147.  
  148. <div class="wrap ms-wrap ms-billing"> 
  149. <?php 
  150. MS_Helper_Html::settings_header( 
  151. array( 
  152. 'title' => $title,  
  153. 'title_icon_class' => 'wpmui-fa wpmui-fa-credit-card',  
  154. ); 
  155. ?> 
  156. <div> 
  157. <?php 
  158. foreach ( $buttons as $button ) { 
  159. MS_Helper_Html::html_element( $button ); 
  160. ?> 
  161. </div> 
  162. <?php 
  163. $listview->views(); 
  164. $listview->search_box( 
  165. __( 'User', 'membership2' ),  
  166. 'search' 
  167. ); 
  168. ?> 
  169. <form action="" method="post"> 
  170. <?php $listview->display(); ?> 
  171. </form> 
  172. </div> 
  173.  
  174. <?php 
  175. $html = ob_get_clean(); 
  176.  
  177. return apply_filters( 
  178. 'ms_view_billing_list',  
  179. $html,  
  180. $this 
  181. );