fix invoice getter

This commit is contained in:
yogesh_gohil
2019-11-15 12:55:35 +05:30
parent 090c33f63c
commit adbc04846c
3 changed files with 19 additions and 24 deletions

View File

@ -122,7 +122,7 @@ export const updateInvoice = ({ commit, dispatch, state }, data) => {
export const markAsSent = ({ commit, dispatch, state }, data) => { export const markAsSent = ({ commit, dispatch, state }, data) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
window.axios.post(`/api/invoices/mark-as-sent`, data).then((response) => { window.axios.post(`/api/invoices/mark-as-sent`, data).then((response) => {
// commit(types.UPDATE_INVOICE, response.data) commit(types.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'})
resolve(response) resolve(response)
}).catch((err) => { }).catch((err) => {
reject(err) reject(err)

View File

@ -4,3 +4,7 @@ export const getTemplateId = (state) => state.invoiceTemplateId
export const selectedInvoices = (state) => state.selectedInvoices export const selectedInvoices = (state) => state.selectedInvoices
export const totalInvoices = (state) => state.totalInvoices export const totalInvoices = (state) => state.totalInvoices
export const selectedCustomer = (state) => state.selectedCustomer export const selectedCustomer = (state) => state.selectedCustomer
export const getInvoice = (state) => (id) => {
let invId = parseInt(id)
return state.invoices.find(invoice => invoice.id === invId)
}

View File

@ -14,7 +14,6 @@
> >
{{ $t('invoices.mark_as_sent') }} {{ $t('invoices.mark_as_sent') }}
</base-button> </base-button>
</div> </div>
<base-button <base-button
v-if="invoice.status === 'DRAFT'" v-if="invoice.status === 'DRAFT'"
@ -24,8 +23,8 @@
color="theme" color="theme"
@click="onSendInvoice" @click="onSendInvoice"
> >
{{ $t('invoices.send_invoice') }} {{ $t('invoices.send_invoice') }}
</base-button> </base-button>
<router-link v-if="invoice.status === 'SENT'" :to="`/admin/payments/${$route.params.id}/create`"> <router-link v-if="invoice.status === 'SENT'" :to="`/admin/payments/${$route.params.id}/create`">
<base-button <base-button
color="theme" color="theme"
@ -147,7 +146,7 @@
</div> </div>
</template> </template>
<script> <script>
import { mapActions } from 'vuex' import { mapActions, mapGetters } from 'vuex'
const _ = require('lodash') const _ = require('lodash')
export default { export default {
data () { data () {
@ -155,9 +154,7 @@ export default {
id: null, id: null,
count: null, count: null,
invoices: [], invoices: [],
invoice: null,
currency: null, currency: null,
shareableLink: null,
searchData: { searchData: {
orderBy: null, orderBy: null,
orderByField: null, orderByField: null,
@ -170,26 +167,31 @@ export default {
} }
}, },
computed: { computed: {
invoice () {
return this.$store.getters['invoice/getInvoice'](this.$route.params.id)
},
getOrderBy () { getOrderBy () {
if (this.searchData.orderBy === 'asc' || this.searchData.orderBy == null) { if (this.searchData.orderBy === 'asc' || this.searchData.orderBy == null) {
return true return true
} }
return false return false
},
shareableLink () {
return `/invoices/pdf/${this.invoice.unique_hash}`
} }
}, },
watch: { watch: {
'$route.params.id' (val) { '$route.params.id' (val) {
this.fetchInvoice() this.invoice()
} }
}, },
mounted () { created () {
this.loadInvoices() this.loadInvoices()
this.onSearched = _.debounce(this.onSearched, 500) this.onSearched = _.debounce(this.onSearched, 500)
}, },
methods: { methods: {
...mapActions('invoice', [ ...mapActions('invoice', [
'fetchInvoices', 'fetchInvoices',
'fetchViewInvoice',
'getRecord', 'getRecord',
'searchInvoice', 'searchInvoice',
'markAsSent', 'markAsSent',
@ -202,7 +204,6 @@ export default {
if (response.data) { if (response.data) {
this.invoices = response.data.invoices.data this.invoices = response.data.invoices.data
} }
this.fetchInvoice()
}, },
async onSearched () { async onSearched () {
let data = '' let data = ''
@ -224,15 +225,6 @@ export default {
this.invoices = response.data.invoices.data this.invoices = response.data.invoices.data
} }
}, },
async fetchInvoice () {
let invoice = await this.fetchViewInvoice(this.$route.params.id)
if (invoice.data) {
this.invoice = invoice.data.invoice
this.shareableLink = invoice.data.shareable_link
this.currency = invoice.data.invoice.user.currency
}
},
sortData () { sortData () {
if (this.searchData.orderBy === 'asc') { if (this.searchData.orderBy === 'asc') {
this.searchData.orderBy = 'desc' this.searchData.orderBy = 'desc'
@ -244,7 +236,7 @@ export default {
return true return true
}, },
async onMarkAsSent () { async onMarkAsSent () {
swal({ swal({
title: this.$t('general.are_you_sure'), title: this.$t('general.are_you_sure'),
text: this.$t('invoices.invoice_mark_as_sent'), text: this.$t('invoices.invoice_mark_as_sent'),
icon: '/assets/icon/check-circle-solid.svg', icon: '/assets/icon/check-circle-solid.svg',
@ -261,8 +253,8 @@ export default {
} }
}) })
}, },
async onSendInvoice () { async onSendInvoice () {
swal({ swal({
title: this.$tc('general.are_you_sure'), title: this.$tc('general.are_you_sure'),
text: this.$tc('invoices.confirm_send_invoice'), text: this.$tc('invoices.confirm_send_invoice'),
icon: '/assets/icon/paper-plane-solid.svg', icon: '/assets/icon/paper-plane-solid.svg',
@ -272,7 +264,6 @@ export default {
if (willSendInvoice) { if (willSendInvoice) {
this.isSendingEmail = true this.isSendingEmail = true
let response = await this.sendEmail({id: this.invoice.id}) let response = await this.sendEmail({id: this.invoice.id})
this.fetchInvoice()
this.isSendingEmail = false this.isSendingEmail = false
if (response.data) { if (response.data) {
window.toastr['success'](this.$tc('invoices.confirm_send_invoice')) window.toastr['success'](this.$tc('invoices.confirm_send_invoice'))