PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/usage/usage.php

https://bitbucket.org/petris/openvbx
PHP | 203 lines | 187 code | 14 blank | 2 comment | 5 complexity | 7dfd7861fae1ecad498648a1aa1904c7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. <?php
  2. // get usage
  3. $account = OpenVBX::getAccount();
  4. $account_sid = $account->sid;
  5. $usage_data = $account->usage_records->this_month;
  6. $shortcodeTotal = 0;
  7. foreach ($usage_data as $record) {
  8. if (!isset($usage_start)) {
  9. $usage_start = $record->start_date;
  10. $usage_end = $record->end_date;
  11. }
  12. $category = $record->category;
  13. $price = $record->price;
  14. if (strpos('shortcode', $category) !== false) {
  15. $shortcodeTotal += $price;
  16. }
  17. $usage[$category] = array(
  18. 'price' => !empty($price) ? $price : 0,
  19. 'description' => $record->description,
  20. 'price_unit' => $record->price_unit,
  21. 'count' => $record->count,
  22. 'count_unit' => $record->count_unit,
  23. );
  24. }
  25. // usage is always in USD as of the time of writing this
  26. $usage_denominator = '$';
  27. ?>
  28. <div class="vbx-plugin usage-vbx-plugin">
  29. <div id="usage">
  30. <h2>Usage</h2>
  31. <br />
  32. <p>Usage data for account <?php echo $account_sid; ?>, <?php echo $usage_start; ?> through <?php echo $usage_end; ?></p>
  33. <br />
  34. <h3>SMS Messages</h3>
  35. <table class="vbx-items-grid">
  36. <thead>
  37. <tr class="items-head">
  38. <th colspan="2">Item</th>
  39. <th>Count</th>
  40. <th>Cost</th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. <tr class="items-row">
  45. <td>SMS Inbound</td>
  46. <td>&nbsp;</td>
  47. <td><?php echo $usage['sms-inbound']['count'] . ' ' .$usage['sms']['count_unit']; ?></td>
  48. <td><?php echo $usage_denominator . $usage['sms-inbound']['price']; ?></td>
  49. </tr>
  50. <tr class="items-row">
  51. <td>SMS Outbound</td>
  52. <td>&nbsp;</td>
  53. <td><?php echo $usage['sms-outbound']['count'] . ' ' .$usage['sms']['count_unit']; ?></td>
  54. <td><?php echo $usage_denominator . $usage['sms-outbound']['price']; ?></td>
  55. </tr>
  56. <?php if ($shortcodeTotal > 0) { ?>
  57. <tr class="items-row">
  58. <td>SMS Inbound Shortcode</td>
  59. <td>&nbsp;</td>
  60. <td><?php echo $usage['sms-inbound-shortcode']['count'] . ' ' .$usage['sms']['count_unit']; ?></td>
  61. <td><?php echo $usage_denominator . $usage['sms-inbound-shortcode']['price']; ?></td>
  62. </tr>
  63. <tr class="items-row">
  64. <td>SMS Outbound Shortcode</td>
  65. <td>&nbsp;</td>
  66. <td><?php echo $usage['sms-outbound-shortcode']['count'] . ' ' .$usage['sms']['count_unit']; ?></td>
  67. <td><?php echo $usage_denominator . $usage['sms-outbound-shortcode']['price']; ?></td>
  68. </tr>
  69. <?php } /* close shortcodes */ ?>
  70. <tr class="items-row">
  71. <td>&nbsp;</td>
  72. <td class="usage-group-total">SMS Total</td>
  73. <td><?php echo $usage['sms']['count'] . ' ' .$usage['sms']['count_unit']; ?></td>
  74. <td><?php echo $usage_denominator . $usage['sms']['price']; ?></td>
  75. </tr>
  76. </tbody>
  77. </table>
  78. <h3>Phone Calls</h3>
  79. <table class="vbx-items-grid">
  80. <thead>
  81. <tr class="items-head">
  82. <th colspan="2">Item</th>
  83. <th>Count</th>
  84. <th>Cost</th>
  85. </tr>
  86. </thead>
  87. <tbody>
  88. <tr class="items-row">
  89. <td>Calls Inbound</td>
  90. <td>&nbsp;</td>
  91. <td><?php echo $usage['calls-inbound']['count'] . ' ' .$usage['calls']['count_unit']; ?></td>
  92. <td><?php echo $usage_denominator . $usage['calls-inbound']['price']; ?></td>
  93. </tr>
  94. <tr class="items-row">
  95. <td>Calls Outbound</td>
  96. <td>&nbsp;</td>
  97. <td><?php echo $usage['calls-outbound']['count'] . ' ' .$usage['calls']['count_unit']; ?></td>
  98. <td><?php echo $usage_denominator . $usage['calls-outbound']['price']; ?></td>
  99. </tr>
  100. <tr class="items-row">
  101. <td>Calls Inbound Toll Free</td>
  102. <td>&nbsp;</td>
  103. <td><?php echo $usage['calls-inbound-tollfree']['count'] . ' ' .$usage['calls']['count_unit']; ?></td>
  104. <td><?php echo $usage_denominator . $usage['calls-inbound-tollfree']['price']; ?></td>
  105. </tr>
  106. <tr class="items-row">
  107. <td>Client</td>
  108. <td>&nbsp;</td>
  109. <td><?php echo $usage['calls-client']['count'] . ' ' .$usage['calls']['count_unit']; ?></td>
  110. <td><?php echo $usage_denominator . $usage['calls-client']['price']; ?></td>
  111. </tr>
  112. <tr class="items-row">
  113. <td>&nbsp;</td>
  114. <td class="usage-group-total">Calls Total</td>
  115. <td><?php echo $usage['calls']['count'] . ' ' .$usage['calls']['count_unit']; ?></td>
  116. <td><?php echo $usage_denominator . $usage['calls']['price']; ?></td>
  117. </tr>
  118. </tbody>
  119. </table>
  120. <?php if ($shortcodeTotal > 0) { ?>
  121. <h3>Shortcodes</h3>
  122. <table class="vbx-items-grid">
  123. <thead>
  124. <tr class="items-head">
  125. <th colspan="2">Item</th>
  126. <th>Count</th>
  127. <th>Cost</th>
  128. </tr>
  129. </thead>
  130. <tbody>
  131. <tr class="items-row">
  132. <td>Vanity Shortcodes</td>
  133. <td>&nbsp;</td>
  134. <td><?php echo $usage['shortcodes-vanity']['count'] . ' ' .$usage['shortcodes']['count_unit']; ?></td>
  135. <td><?php echo $usage_denominator . $usage['shortcodes-vanity']['price']; ?></td>
  136. </tr>
  137. <tr class="items-row">
  138. <td>Random Shortcodes</td>
  139. <td>&nbsp;</td>
  140. <td><?php echo $usage['shortcodes-random']['count'] . ' ' .$usage['shortcodes']['count_unit']; ?></td>
  141. <td><?php echo $usage_denominator . $usage['shortcodes-random']['price']; ?></td>
  142. </tr>
  143. <tr class="items-row">
  144. <td>Customer Owned Shortcodes</td>
  145. <td>&nbsp;</td>
  146. <td><?php echo $usage['shortcodes-customerowned']['count'] . ' ' .$usage['shortcodes']['count_unit']; ?></td>
  147. <td><?php echo $usage_denominator . $usage['shortcodes-customerowned']['price']; ?></td>
  148. </tr>
  149. <tr class="items-row">
  150. <td>&nbsp;</td>
  151. <td class="usage-group-total">Shortcodes Total</td>
  152. <td><?php echo $usage['shortcodes']['count'] . ' ' .$usage['shortcodes']['count_unit']; ?></td>
  153. <td><?php echo $usage_denominator . $usage['shortcodes']['price']; ?></td>
  154. </tr>
  155. </tbody>
  156. </table>
  157. <?php } /* close shortcodes */ ?>
  158. <h3>Misc.</h3>
  159. <table class="vbx-items-grid">
  160. <thead>
  161. <tr class="items-head">
  162. <th colspan="2">Item</th>
  163. <th>Count</th>
  164. <th>Cost</th>
  165. </tr>
  166. </thead>
  167. <tbody>
  168. <tr class="items-row">
  169. <td>Recordings</td>
  170. <td>&nbsp;</td>
  171. <td><?php echo $usage['recordings']['count'] . ' ' .$usage['recordings']['count_unit']; ?></td>
  172. <td><?php echo $usage_denominator . $usage['recordings']['price']; ?></td>
  173. </tr>
  174. <tr class="items-row">
  175. <td>Recording Storage</td>
  176. <td>&nbsp;</td>
  177. <td><?php echo $usage['recordingstorage']['count'] . ' ' .$usage['recordingstorage']['count_unit']; ?></td>
  178. <td><?php echo $usage_denominator . $usage['recordingstorage']['price']; ?></td>
  179. </tr>
  180. <tr class="items-row">
  181. <td>Transcriptions</td>
  182. <td>&nbsp;</td>
  183. <td><?php echo $usage['transcriptions']['count'] . ' ' .$usage['transcriptions']['count_unit']; ?></td>
  184. <td><?php echo $usage_denominator . $usage['transcriptions']['price']; ?></td>
  185. </tr>
  186. </tbody>
  187. </table>
  188. </div>
  189. </div>