Browse Source

fixed #100

ali 3 years ago
parent
commit
33c6d252a5

+ 16 - 1
src/api/models/Invoice.js

@@ -8,7 +8,8 @@ export default class InvoiceAPI extends APIRepository {
     this.APIAdresses = {
       base: '/accounting/invoices',
       byId: (id) => '/accounting/invoices/' + id,
-      pay: (id) => '/accounting/invoices/' + id + '/pay'
+      pay: (id) => '/accounting/invoices/' + id + '/pay',
+      cancel: (id) => '/accounting/invoices/' + id + '/cancel'
     }
     this.CacheList = {
       base: this.name + this.APIAdresses.base
@@ -68,6 +69,20 @@ export default class InvoiceAPI extends APIRepository {
     })
   }
 
+  cancel(invoiceId) {
+    return this.sendRequest({
+      apiMethod: 'put',
+      api: this.api,
+      request: this.APIAdresses.cancel(invoiceId),
+      resolveCallback: (response) => {
+        return response.data.detail // String : message
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+
   createService (products = []) {
     return this.sendRequest({
       apiMethod: 'post',

+ 14 - 2
src/components/Widgets/Invoice/AdminInvoiceShow/AdminInvoiceShow.vue

@@ -137,7 +137,7 @@ import { Wallet } from 'src/models/Wallet.js'
 import { Invoice } from 'src/models/Invoice.js'
 import { mixinWidget } from 'src/mixin/Mixins.js'
 import { APIGateway } from 'src/api/APIGateway.js'
-import InvoicePaymentCard from 'src/components/InvoicePaymentCard.vue'
+import InvoicePaymentCard from 'src/components/InvoicePaymentCard/InvoicePaymentCard.vue'
 
 export default {
   name: 'AdminInvoiceShow',
@@ -172,7 +172,19 @@ export default {
       return Assist.miladiToShamsi(dateTime)
     },
     onCancel () {
-      this.$router.push({ name: 'UserPanel.Invoice.List' })
+      this.invoice.loading = true
+      APIGateway.invoice.cancel(this.invoice.id)
+        .then((message) => {
+          this.invoice.loading = false
+          this.getInvoice()
+          this.$q.notify({
+            message,
+            type: 'positive'
+          })
+        })
+        .catch(() => {
+          this.invoice.loading = false
+        })
     },
     onAccept () {
       this.payInvoice()

+ 13 - 1
src/components/Widgets/Invoice/InvoiceShow/InvoiceShow.vue

@@ -150,7 +150,19 @@ export default {
       return Assist.miladiToShamsi(dateTime)
     },
     onCancel () {
-      this.$router.push({ name: 'UserPanel.Invoice.List' })
+      this.invoice.loading = true
+      APIGateway.invoice.cancel(this.invoice.id)
+        .then((message) => {
+          this.invoice.loading = false
+          this.getInvoice()
+          this.$q.notify({
+            message,
+            type: 'positive'
+          })
+        })
+        .catch(() => {
+          this.invoice.loading = false
+        })
     },
     onAccept () {
       this.payInvoice()

+ 1 - 1
src/components/Widgets/Other/Shop/ShopPaymentFromWallet/ShopPaymentFromWallet.vue

@@ -255,7 +255,7 @@ import ShamsiDate from 'src/assets/ShamsiDate.js'
 import { APIGateway } from 'src/api/APIGateway.js'
 import { Classroom } from 'src/models/Classroom.js'
 import InvoiceInfo from './components/InvoiceInfo.vue'
-import InvoicePaymentCard from 'src/components/InvoicePaymentCard.vue'
+import InvoicePaymentCard from 'src/components/InvoicePaymentCard/InvoicePaymentCard.vue'
 
 export default {
   name: 'PaymentFromWallet',