MS_Helper_ListTable_Billing

Membership List Table.

Defined (1)

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

/app/helper/listtable/class-ms-helper-listtable-billing.php  
  1. class MS_Helper_ListTable_Billing extends MS_Helper_ListTable { 
  2.  
  3. protected $id = 'billing'; 
  4.  
  5. public function __construct() { 
  6. parent::__construct( 
  7. array( 
  8. 'singular' => 'billing',  
  9. 'plural' => 'billings',  
  10. 'ajax' => false,  
  11. ); 
  12.  
  13. public function get_columns() { 
  14. $currency = MS_Plugin::instance()->settings->currency; 
  15.  
  16. $columns = apply_filters( 
  17. 'ms_helper_listtable_billing_columns',  
  18. array( 
  19. 'cb' => '<input type="checkbox" />',  
  20. 'invoice' => __( 'Invoice #', 'membership2' ),  
  21. 'user' => __( 'User', 'membership2' ),  
  22. 'membership' => __( 'Membership', 'membership2' ),  
  23. 'status' => __( 'Status', 'membership2' ),  
  24. 'total' => __( 'Total', 'membership2' ),  
  25. 'due_date' => __( 'Due date', 'membership2' ),  
  26. 'gateway_id' => __( 'Gateway', 'membership2' ),  
  27. ); 
  28.  
  29. $columns = apply_filters( 
  30. 'ms_helper_listtable_billing_get_columns',  
  31. $columns,  
  32. $currency 
  33. ); 
  34.  
  35. return $columns; 
  36.  
  37. public function column_cb( $item ) { 
  38. return sprintf( 
  39. '<input type="checkbox" name="invoice_id[]" value="%1$s" />',  
  40. esc_attr( $item->id ) 
  41. ); 
  42.  
  43. public function get_hidden_columns() { 
  44. return apply_filters( 
  45. 'ms_helper_listtable_billing_hidden_columns',  
  46. array() 
  47. ); 
  48.  
  49. public function get_sortable_columns() { 
  50. return apply_filters( 
  51. 'ms_helper_listtable_billing_sortable_columns',  
  52. array( 
  53. 'invoice' => array( 'ID', false ),  
  54. 'user' => array( 'author', false ),  
  55. 'membership' => array( 'ms_membership_ids', false ),  
  56. 'status' => array( 'status', false ),  
  57. 'amount' => array( 'amount', false ),  
  58. 'total' => array( 'total', false ),  
  59. 'due_date' => array( 'due_date', false ),  
  60. 'gateway_id' => array( 'gateway_id', false ),  
  61. ); 
  62.  
  63. public function prepare_items() { 
  64. $this->_column_headers = array( 
  65. $this->get_columns(),  
  66. $this->get_hidden_columns(),  
  67. $this->get_sortable_columns(),  
  68. ); 
  69.  
  70. if ( ! isset( $_REQUEST['status'] ) ) { 
  71. $_GET['status'] = 'default'; 
  72. $_REQUEST['status'] = 'default'; 
  73.  
  74. $args = $this->get_query_args(); 
  75.  
  76. $total_items = MS_Model_Invoice::get_invoice_count( $args ); 
  77.  
  78. $this->items = apply_filters( 
  79. 'ms_helper_listtable_billing_items',  
  80. MS_Model_Invoice::get_invoices( $args ) 
  81. ); 
  82.  
  83. $per_page = $this->get_items_per_page( 
  84. 'invoice_per_page',  
  85. self::DEFAULT_PAGE_SIZE 
  86. ); 
  87. $this->set_pagination_args( 
  88. array( 
  89. 'total_items' => $total_items,  
  90. 'per_page' => $per_page,  
  91. ); 
  92.  
  93. private function get_query_args() { 
  94. $defaults = MS_Model_Invoice::get_query_args(); 
  95. lib3()->array->equip_request( 's' ); 
  96.  
  97. $per_page = $this->get_items_per_page( 
  98. 'invoice_per_page',  
  99. self::DEFAULT_PAGE_SIZE 
  100. ); 
  101. $current_page = $this->get_pagenum(); 
  102.  
  103. $args = array( 
  104. 'posts_per_page' => $per_page,  
  105. 'offset' => ( $current_page - 1 ) * $per_page,  
  106. ); 
  107.  
  108. // Filter by search-term 
  109. $search_filter = $_REQUEST['s']; 
  110. if ( ! empty( $search_filter ) ) { 
  111. $this->search_string = $search_filter; 
  112.  
  113. $args = wp_parse_args( $args, $defaults ); 
  114.  
  115. return $args; 
  116.  
  117. /** 
  118. * Returns the row-class to be used for the specified table item. 
  119. * @param object $item The current item. 
  120. * @return string Class to be added to the table row. 
  121. */ 
  122. protected function single_row_class( $item ) { 
  123. return 'invoice-' . $item->status; 
  124.  
  125. public function column_invoice( $item ) { 
  126. $actions = array(); 
  127.  
  128. // Prepare the item actions. 
  129. $actions['view'] = sprintf( 
  130. '<a href="%s">%s</a>',  
  131. get_permalink( $item->id ),  
  132. __( 'View', 'membership2' ) 
  133. ); 
  134.  
  135. if ( MS_Gateway_Manual::ID == $item->gateway_id && ! $item->is_paid() ) { 
  136. $action_url = MS_Controller_Plugin::get_admin_url( 
  137. 'billing',  
  138. array( 
  139. 'action' => MS_Controller_Billing::ACTION_PAY_IT,  
  140. '_wpnonce' => wp_create_nonce( MS_Controller_Billing::ACTION_PAY_IT ),  
  141. 'invoice_id' => $item->id,  
  142. ); 
  143.  
  144. $actions['pay_it'] = sprintf( 
  145. '<a href="%s">%s</a>',  
  146. $action_url,  
  147. __( 'Mark as paid', 'membership2' ) 
  148. ); 
  149.  
  150. $edit_url = MS_Controller_Plugin::get_admin_url( 
  151. 'billing',  
  152. array( 
  153. 'action' => MS_Controller_Billing::ACTION_EDIT,  
  154. 'invoice_id' => $item->id,  
  155. ); 
  156.  
  157. return sprintf( 
  158. '<a href="%3$s"><b>%1$s</b></a> %2$s',  
  159. $item->get_invoice_number(),  
  160. $this->row_actions( $actions ),  
  161. $edit_url 
  162. ); 
  163.  
  164. public function column_user( $item, $column_name ) { 
  165. $member = MS_Factory::load( 'MS_Model_Member', $item->user_id ); 
  166.  
  167. $html = sprintf( 
  168. '<a href="%s">%s</a>',  
  169. MS_Controller_Plugin::get_admin_url( 
  170. 'add-member',  
  171. array( 'user_id' => $item->user_id ) 
  172. ),  
  173. $member->username 
  174. ); 
  175.  
  176. return $html; 
  177.  
  178. public function column_membership( $item, $column_name ) { 
  179. $membership = MS_Factory::load( 'MS_Model_Membership', $item->membership_id ); 
  180.  
  181. return $membership->get_name_tag(); 
  182.  
  183. public function column_status( $item, $column_name ) { 
  184. $icon = ''; 
  185.  
  186. switch ( $item->status ) { 
  187. case MS_Model_Invoice::STATUS_NEW: 
  188. $icon = '<i class="wpmui-fa wpmui-fa-circle-o"></i>'; 
  189. break; 
  190.  
  191. case MS_Model_Invoice::STATUS_PAID: 
  192. $icon = '<i class="wpmui-fa wpmui-fa-check-circle"></i>'; 
  193. break; 
  194.  
  195. case MS_Model_Invoice::STATUS_PENDING: 
  196. case MS_Model_Invoice::STATUS_BILLED: 
  197. $icon = '<i class="wpmui-fa wpmui-fa-clock-o"></i>'; 
  198. break; 
  199.  
  200. case MS_Model_Invoice::STATUS_DENIED: 
  201. $icon = '<i class="wpmui-fa wpmui-fa-times-circle"></i>'; 
  202. break; 
  203.  
  204. case MS_Model_Invoice::STATUS_ARCHIVED: 
  205. $icon = '<i class="wpmui-fa wpmui-fa-times-circle-o"></i>'; 
  206. break; 
  207.  
  208. default: 
  209. $icon = $item->status_text(); 
  210. break; 
  211.  
  212. return sprintf( 
  213. '<span class="payment-status payment-status-%1$s" title="%3$s">%2$s</span>',  
  214. $item->status,  
  215. $icon,  
  216. $item->status_text() 
  217. ); 
  218.  
  219. public function column_amount( $item, $column_name ) { 
  220. $html = MS_Helper_Billing::format_price( $item->amount ); 
  221. return $html; 
  222.  
  223. public function column_total( $item, $column_name ) { 
  224. if ( $item->total ) { 
  225. $currency = $item->currency; 
  226. $value = MS_Helper_Billing::format_price( $item->total ); 
  227.  
  228. $html = sprintf( 
  229. '<b>%1$s</b> <small>%2$s</small>',  
  230. $value,  
  231. $currency 
  232. ); 
  233. } else { 
  234. $html = __( 'Free', 'membership2' ); 
  235.  
  236. return $html; 
  237.  
  238. public function column_due_date( $item, $column_name ) { 
  239. $due_now = false; 
  240. $is_paid = $item->is_paid(); 
  241.  
  242. if ( ! $is_paid ) { 
  243. $diff = MS_Helper_Period::subtract_dates( 
  244. $item->due_date,  
  245. MS_Helper_Period::current_date(),  
  246. null,  
  247. true 
  248. ); 
  249. $due_now = ($diff < 0); 
  250.  
  251. $due_date = MS_Helper_Period::format_date( $item->due_date ); 
  252.  
  253. if ( $due_now ) { 
  254. $html = sprintf( 
  255. '<span class="due-now" title="%2$s">%1$s</span>',  
  256. $due_date,  
  257. __( 'Payment is overdue', 'membership2' ) 
  258. ); 
  259. } elseif ( $item->pay_date ) { 
  260. $pay_date = MS_Helper_Period::format_date( $item->pay_date, 'M j, Y' ); 
  261. $html = sprintf( 
  262. '<span class="is-paid" title="%2$s">%1$s</span>',  
  263. $due_date,  
  264. sprintf( 
  265. __( 'Paid: %s', 'membership2' ),  
  266. $pay_date 
  267. ); 
  268. } else { 
  269. $html = sprintf( 
  270. '<span>%1$s</span>',  
  271. $due_date 
  272. ); 
  273.  
  274. return $html; 
  275.  
  276. public function column_gateway_id( $item, $column_name ) { 
  277. $html = MS_Model_Gateway::get_name( $item->gateway_id ); 
  278. return $html; 
  279.  
  280. public function column_default( $item, $column_name ) { 
  281. $html = ''; 
  282.  
  283. if ( property_exists( $item, $column_name ) ) { 
  284. $html = $item->column_name; 
  285.  
  286. return $html; 
  287.  
  288. public function get_bulk_actions() { 
  289. $bulk_actions = array( 
  290. 'archive' => __( 'Remove', 'membership2' ),  
  291. ); 
  292.  
  293. return apply_filters( 
  294. 'ms_helper_listtable_billing_bulk_actions',  
  295. $bulk_actions,  
  296. $this 
  297. ); 
  298.  
  299. public function get_views() { 
  300. $all_status = array( 
  301. MS_Model_Invoice::STATUS_PAID => __( 'Paid', 'membership2' ),  
  302. MS_Model_Invoice::STATUS_NEW => __( 'Draft', 'membership2' ),  
  303. MS_Model_Invoice::STATUS_DENIED => __( 'Denied', 'membership2' ),  
  304. ); 
  305.  
  306. $views = array(); 
  307. $orig_status = ''; 
  308.  
  309. if ( isset( $_REQUEST['status'] ) ) { 
  310. $orig_status = $_REQUEST['status']; 
  311. $_REQUEST['status'] = 'default'; 
  312. $args = $this->get_query_args(); 
  313. $_REQUEST['status'] = $orig_status; 
  314. $base_url = esc_url_raw( remove_query_arg( array( 'status', 'msg' ) ) ); 
  315. $count = MS_Model_Invoice::get_invoice_count( $args ); 
  316. $views['all'] = array( 
  317. 'url' => $base_url,  
  318. 'label' => __( 'Default', 'membership2' ),  
  319. 'count' => $count,  
  320. ); 
  321.  
  322. $url = esc_url_raw( add_query_arg( 'status', 'open', $base_url ) ); 
  323. $args = $this->get_query_args(); 
  324. $args['meta_query']['status']['value'] = array( 
  325. MS_Model_Invoice::STATUS_BILLED,  
  326. MS_Model_Invoice::STATUS_PENDING,  
  327. ); 
  328. $args['meta_query']['status']['compare'] = 'IN'; 
  329. $count = MS_Model_Invoice::get_invoice_count( $args ); 
  330. $views['open'] = array( 
  331. 'url' => $url,  
  332. 'label' => __( 'Billed or Pending', 'membership2' ),  
  333. 'count' => $count,  
  334. ); 
  335.  
  336. foreach ( $all_status as $status => $desc ) { 
  337. $args = $this->get_query_args(); 
  338. $args['meta_query']['status']['value'] = $status; 
  339. $count = MS_Model_Invoice::get_invoice_count( $args ); 
  340.  
  341. if ( $count ) { 
  342. $status_url = esc_url_raw( 
  343. add_query_arg( 
  344. array( 'status' => $status ),  
  345. remove_query_arg( array( 'msg' ) ) 
  346. ); 
  347. } else { 
  348. $status_url = false; 
  349. $desc .= ' (0)'; 
  350. if ( MS_Model_Invoice::STATUS_DENIED != $status ) { 
  351. $desc .= ' |'; 
  352. $count = false; 
  353.  
  354. $views[ $status ] = array( 
  355. 'url' => $status_url,  
  356. 'label' => $desc,  
  357. 'count' => $count,  
  358. ); 
  359.  
  360. return apply_filters( 'ms_helper_listtable_billing_views', $views ); 
  361.