WalletOverview.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!--
  2. Copyright 2019 Hackware SpA <human@hackware.cl>
  3. This file is part of "Hackware Userland" and licensed under the terms
  4. of the GNU Affero General Public License version 3, or (at your option)
  5. a later version. You should have received a copy of this license along
  6. with the software. If not, see <https://www.gnu.org/licenses/>.
  7. -->
  8. <template>
  9. <div class="wallet-overview">
  10. <div class="d-flex justify-content-between">
  11. <h3>
  12. <small>Saldo total</small> {{ wallet.balance | currency }}
  13. </h3>
  14. <router-link
  15. class="btn btn-primary"
  16. to="/transactions"
  17. >
  18. Ver detalle
  19. <i class="fas fa-history" />
  20. </router-link>
  21. </div>
  22. <template v-if="dueTransactions.length">
  23. <hr>
  24. <h5>Pagos pendientes</h5>
  25. <table class="table table-sm">
  26. <thead>
  27. <tr>
  28. <th>emisión</th>
  29. <th>vencimiento</th>
  30. <th>monto</th>
  31. </tr>
  32. </thead>
  33. <tbody
  34. v-for="dueTransaction in dueTransactions"
  35. :key="dueTransaction.id"
  36. >
  37. <tr>
  38. <td>{{ dueTransaction.created_at | date }}</td>
  39. <td>{{ dueTransaction.due_at | datetime }}</td>
  40. <td>{{ dueTransaction.amount | currency }}</td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </template>
  45. </div>
  46. </template>
  47. <script>
  48. export default {
  49. name: 'WalletOverview',
  50. data() {
  51. return {
  52. dueTransactions: [],
  53. wallet: { balance: 0 },
  54. };
  55. },
  56. created() {
  57. this.refreshWallet();
  58. this.$eventHub.$on('payment-updated', this.refreshWallet);
  59. },
  60. beforeDestroy() {
  61. this.$eventHub.$off('payment-updated', this.refreshWallet);
  62. },
  63. methods: {
  64. fetchWallet() {
  65. this.$fetcher.haweseGet(`/wallets/${this.$auth.uid}`)
  66. .then((body) => { if (!('error' in body)) { this.wallet = body; } });
  67. },
  68. fetchDueTransactions() {
  69. this.$fetcher.haweseGet('/transactions', { user_uid: this.$auth.uid, due: true })
  70. .then((body) => { this.dueTransactions = body.data; });
  71. },
  72. refreshWallet() {
  73. this.fetchWallet();
  74. this.fetchDueTransactions();
  75. },
  76. },
  77. };
  78. </script>