/app/view/shortcode/class-ms-view-shortcode-invoice.php

  1. <?php 
  2.  
  3. class MS_View_Shortcode_Invoice extends MS_View { 
  4.  
  5. public function to_html() { 
  6. /** 
  7. * Provide a customized invoice. 
  8. * 
  9. * @since 1.0.0 
  10. */ 
  11. $html = apply_filters( 
  12. 'ms_shortcode_custom_invoice',  
  13. '',  
  14. $this->data 
  15. ); 
  16.  
  17. if ( ! empty( $html ) ) { 
  18. return $html; 
  19. } else { 
  20. $html = ''; 
  21.  
  22. $invoice = $this->data['invoice']; 
  23. $member = $this->data['member']; 
  24. $subscription = $this->data['ms_relationship']; 
  25. $membership = $this->data['membership']; 
  26. $gateway = $this->data['gateway']; 
  27. $is_free = false; 
  28.  
  29. $invoice_number = $invoice->get_invoice_number(); 
  30.  
  31. $inv_title = sprintf( 
  32. '<a href="%s">%s</a>',  
  33. get_permalink( $invoice->id ),  
  34. esc_html( __( 'Invoice ', 'membership2' ) . $invoice_number ) 
  35. ); 
  36.  
  37. if ( $invoice->amount > 0 ) { 
  38. $inv_amount = sprintf( 
  39. '%1$s %2$s',  
  40. $invoice->currency,  
  41. MS_Helper_Billing::format_price( $invoice->amount ) 
  42. ); 
  43. } else { 
  44. $inv_amount = __( 'Free', 'membership2' ); 
  45. $is_free = true; 
  46.  
  47. if ( $invoice->tax ) { 
  48. $inv_taxes = sprintf( 
  49. '%s %s',  
  50. $invoice->currency,  
  51. MS_Helper_Billing::format_price( $invoice->tax ) 
  52. ); 
  53. } else { 
  54. $inv_taxes = ''; 
  55.  
  56. if ( $invoice->discount ) { 
  57. $inv_discount = sprintf( 
  58. '%s -%s',  
  59. $invoice->currency,  
  60. MS_Helper_Billing::format_price( $invoice->discount ) 
  61. ); 
  62. } else { 
  63. $inv_discount = ''; 
  64.  
  65. if ( $invoice->pro_rate ) { 
  66. $inv_pro_rate = sprintf( 
  67. '%s -%s',  
  68. $invoice->currency,  
  69. MS_Helper_Billing::format_price( $invoice->pro_rate ) 
  70. ); 
  71. } else { 
  72. $inv_pro_rate = ''; 
  73.  
  74. $inv_total = sprintf( 
  75. '%s %s',  
  76. $invoice->currency,  
  77. MS_Helper_Billing::format_price( $invoice->total ) 
  78. ); 
  79.  
  80. $inv_title = apply_filters( 'ms_invoice_title', $inv_title, $invoice ); 
  81. $inv_from = apply_filters( 'ms_invoice_sender', MS_Plugin::instance()->settings->invoice_sender_name, $invoice ); 
  82. $inv_to = apply_filters( 'ms_invoice_recipient', $member->username, $invoice, $member ); 
  83. $inv_status = apply_filters( 'ms_invoice_status', $invoice->status_text(), $invoice ); 
  84. $inv_item_name = apply_filters( 'ms_invoice_item_name', $membership->name, $invoice, $membership ); 
  85. $inv_amount = apply_filters( 'ms_invoice_amount', $inv_amount, $invoice ); 
  86. $inv_taxes = apply_filters( 'ms_invoice_taxes', $inv_taxes, $invoice ); 
  87. $inv_discount = apply_filters( 'ms_invoice_discount', $inv_discount, $invoice ); 
  88. $inv_pro_rate = apply_filters( 'ms_invoice_pro_rate', $inv_pro_rate, $invoice ); 
  89. $inv_total = apply_filters( 'ms_invoice_total', $inv_total, $invoice ); 
  90.  
  91. $inv_details = apply_filters( 'ms_invoice_description', $invoice->description, $invoice, null ); 
  92. $inv_date = apply_filters( 
  93. 'ms_invoice_date',  
  94. MS_Helper_Period::format_date( $invoice->invoice_date ),  
  95. $invoice,  
  96. null 
  97. ); 
  98. $inv_due_date = apply_filters( 
  99. 'ms_invoice_due_date',  
  100. MS_Helper_Period::format_date( $invoice->due_date ),  
  101. $invoice,  
  102. null 
  103. ); 
  104.  
  105. if ( $invoice->uses_trial ) { 
  106. $trial_date = apply_filters( 
  107. 'ms_invoice_trial_date',  
  108. MS_Helper_Period::get_period_desc( $membership->trial_period, true ),  
  109. $trial_invoice,  
  110. $invoice 
  111. ); 
  112. $trial_date .= sprintf( 
  113. ' <small>(%s %s)</small>',  
  114. __( 'ends on', 'membership2' ),  
  115. MS_Helper_Period::format_date( $invoice->trial_ends ) 
  116. ); 
  117. } else { 
  118. $trial_date = ''; 
  119.  
  120. ob_start(); 
  121. ?> 
  122. <div class="entry-content ms-invoice" id="invoice"> 
  123. <?php 
  124. /** 
  125. * We hardcode the CSS styles into this file, because the shortcode 
  126. * is also used in Emails, which usually do not load remote CSS 
  127. * files by default... 
  128. */ 
  129. ?> 
  130. <style> 
  131. #invoice table, th, td { margin: 0; font-size: 14px; } 
  132. #invoice table { padding: 0; width: 520px; border: 1px solid #DDD; background-color: #FFF; box-shadow: 0 1px 8px #F0F0F0; } 
  133. #invoice th, td { border: 0; padding: 8px; } 
  134. #invoice th { font-weight: bold; text-align: left; text-transform: none; font-size: 13px; } 
  135. #invoice tr.alt { background-color: #F9F9F9; } 
  136. #invoice tr.sep th,  
  137. #invoice tr.sep td { border-top: 1px solid #DDD; padding-top: 16px; } 
  138. #invoice tr.space th,  
  139. #invoice tr.space td { padding-bottom: 16px; } 
  140. #invoice tr.ms-inv-sep th,  
  141. #invoice tr.ms-inv-sep td { line-height: 1px; height: 1px; padding: 0; border-bottom: 1px solid #DDD; background-color: #F9F9F9; } 
  142. #invoice .ms-inv-total .ms-inv-price { font-weight: bold; font-size: 18px; text-align: right; } 
  143. #invoice h2 { text-align: right; padding: 10px 10px 0 0; } 
  144. #invoice h2 a { color: #000; } 
  145. <?php do_action( 'ms_invoice_css' ) ?> 
  146. </style> 
  147.  
  148. <div class="ms-invoice-details ms-status-<?php echo esc_attr( $invoice->status ); ?>"> 
  149. <table class="ms-purchase-table"> 
  150. <tr class="ms-inv-title"> 
  151. <td colspan="2"><h2><?php echo $inv_title; ?></h2></td> 
  152. </tr> 
  153.  
  154. <?php if ( ! empty( $inv_from ) ) : ?> 
  155. <tr class="ms-inv-from"> 
  156. <th><?php _e( 'Sender', 'membership2' ); ?></th> 
  157. <td class="ms-inv-text"><?php echo $inv_from; ?></td> 
  158. </tr> 
  159. <?php endif; ?> 
  160.  
  161. <tr class="ms-inv-to"> 
  162. <th><?php _e( 'Invoice to', 'membership2' ); ?></th> 
  163. <td class="ms-inv-text"><?php echo $inv_to; ?></td> 
  164. </tr> 
  165. <tr class="ms-inv-invoice-date"> 
  166. <th><?php _e( 'Invoice date', 'membership2' ); ?></th> 
  167. <td class="ms-inv-date"><?php echo $inv_date; ?></td> 
  168. </tr> 
  169. <?php if ( ! empty( $trial_date ) ) : ?> 
  170. <tr class="ms-inv-trial-end-date"> 
  171. <th><?php _e( 'Trial period', 'membership2' ); ?></th> 
  172. <td class="ms-inv-date"><?php echo $trial_date; ?></td> 
  173. </tr> 
  174. <?php endif; ?> 
  175. <tr class="ms-inv-status space"> 
  176. <th><?php _e( 'Status', 'membership2' ); ?></th> 
  177. <td class="ms-inv-text"><?php echo $inv_status; ?></td> 
  178. </tr> 
  179. <tr class="ms-inv-item-name alt sep"> 
  180. <th><?php _e( 'Name', 'membership2' ); ?></th> 
  181. <td class="ms-inv-text"><?php echo $inv_item_name; ?></td> 
  182. </tr> 
  183.  
  184. <?php if ( ! empty( $inv_details ) ) : ?> 
  185. <tr class="ms-inv-description alt"> 
  186. <th><?php _e( 'Description', 'membership2' ); ?></th> 
  187. <td class="ms-inv-text"><?php echo $inv_details; ?></td> 
  188. </tr> 
  189. <?php endif; ?> 
  190.  
  191. <tr class="ms-inv-amount alt space"> 
  192. <th><?php _e( 'Amount', 'membership2' ); ?></th> 
  193. <td class="ms-inv-price"><?php echo $inv_amount; ?></td> 
  194. </tr> 
  195.  
  196. <?php $sep = 'sep'; ?> 
  197.  
  198. <?php if ( ! empty( $inv_discount ) ) : ?> 
  199. <tr class="ms-inv-discount <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  200. <th><?php _e( 'Coupon discount', 'membership2' ); ?></th> 
  201. <td class="ms-inv-price"><?php echo $inv_discount; ?></td> 
  202. </tr> 
  203. <?php endif; ?> 
  204.  
  205. <?php if ( ! empty( $inv_pro_rate ) ) : ?> 
  206. <tr class="ms-inv-pro-rate <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  207. <th><?php _e( 'Pro rate discount', 'membership2' ); ?></th> 
  208. <td class="ms-inv-price"><?php echo $inv_pro_rate; ?></td> 
  209. </tr> 
  210. <?php endif; ?> 
  211.  
  212. <?php if ( ! empty( $inv_taxes ) ) : ?> 
  213. <tr class="ms-inv-tax <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  214. <th><?php 
  215. printf( 
  216. __( 'Taxes %s', 'membership2' ),  
  217. '<small>(' . $invoice->tax_name . ')</small>' 
  218. ); 
  219. ?></th> 
  220. <td class="ms-inv-price"><?php echo $inv_taxes; ?></td> 
  221. </tr> 
  222. <?php endif; ?> 
  223.  
  224. <?php if ( ! $is_free ) : ?> 
  225. <tr class="ms-inv-due-date <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  226. <th><?php _e( 'Payment due', 'membership2' ); ?></th> 
  227. <td class="ms-inv-date"><?php echo $inv_due_date; ?></td> 
  228. </tr> 
  229. <?php endif; ?> 
  230. <tr class="ms-inv-total <?php echo esc_attr( $sep ); $sep = ''; ?>"> 
  231. <th><?php _e( 'Total', 'membership2' ); ?></th> 
  232. <td class="ms-inv-price"><?php echo $inv_total; ?></td> 
  233. </tr> 
  234.  
  235. <?php 
  236. $show_button = lib3()->is_true( $this->data['pay_button'] ); 
  237.  
  238. if ( $invoice->is_paid() ) { 
  239. // Invoice is already paid. We don't need a payment 
  240. // button... 
  241. $show_button = false; 
  242.  
  243. if ( $show_button ) { 
  244. ?> 
  245. <tr class="ms-inv-sep sep"><td colspan="2"></td></tr> 
  246. <?php 
  247. do_action( 
  248. 'ms_view_shortcode_invoice_purchase_button',  
  249. $subscription,  
  250. $invoice 
  251. ); 
  252. ?> 
  253. </table> 
  254. </div> 
  255. </div> 
  256. <?php 
  257. $html = ob_get_clean(); 
  258. $html = apply_filters( 'ms_compact_code', $html ); 
  259.  
  260. return apply_filters( 
  261. 'ms_shortcode_invoice',  
  262. $html,  
  263. $this->data 
  264. ); 
.