mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 12:11:08 -04:00
fix status action in view invoice
This commit is contained in:
@ -308,6 +308,7 @@ export default {
|
||||
invoice_template: 'Invoice Template',
|
||||
template: 'Template',
|
||||
mark_as_sent: 'Mark as sent',
|
||||
confirm_send_invoice: 'This invoice will be sent via email to the customer',
|
||||
invoice_mark_as_sent: 'This invoice will be marked as sent',
|
||||
confirm_send: 'This invoice will be sent via email to the customer',
|
||||
invoice_date: 'Invoice Date',
|
||||
|
||||
@ -47,6 +47,7 @@ export const fetchViewInvoice = ({ commit, dispatch, state }, id) => {
|
||||
export const sendEmail = ({ commit, dispatch, state }, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.post(`/api/invoices/send`, data).then((response) => {
|
||||
commit(types.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'})
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
|
||||
@ -14,3 +14,4 @@ export const SELECT_CUSTOMER = 'SELECT_CUSTOMER'
|
||||
export const RESET_SELECTED_CUSTOMER = 'RESET_SELECTED_CUSTOMER'
|
||||
export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE'
|
||||
export const RESET_SELECTED_INVOICES = 'RESET_SELECTED_INVOICES'
|
||||
export const UPDATE_INVOICE_STATUS = 'UPDATE_INVOICE_STATUS'
|
||||
|
||||
@ -28,6 +28,12 @@ export default {
|
||||
state.invoices[pos] = data.invoice
|
||||
},
|
||||
|
||||
[types.UPDATE_INVOICE_STATUS] (state, data) {
|
||||
let pos = state.invoices.findIndex(invoice => invoice.id === data.id)
|
||||
|
||||
state.invoices[pos].status = data.status
|
||||
},
|
||||
|
||||
[types.RESET_SELECTED_INVOICES] (state, data) {
|
||||
state.selectedInvoices = []
|
||||
state.selectAllField = false
|
||||
|
||||
@ -5,16 +5,28 @@
|
||||
<div class="page-actions row">
|
||||
<div class="col-xs-2 mr-3">
|
||||
<base-button
|
||||
:loading="isRequestOnGoing"
|
||||
:disabled="isRequestOnGoing"
|
||||
v-if="invoice.status === 'DRAFT'"
|
||||
:loading="isMarkingAsSent"
|
||||
:disabled="isMarkingAsSent"
|
||||
:outline="true"
|
||||
color="theme"
|
||||
@click="onMarkAsSent"
|
||||
>
|
||||
{{ $t('invoices.mark_as_sent') }}
|
||||
</base-button>
|
||||
|
||||
</div>
|
||||
<router-link :to="`/admin/payments/${$route.params.id}/create`">
|
||||
<base-button
|
||||
v-if="invoice.status === 'DRAFT'"
|
||||
:loading="isSendingEmail"
|
||||
:disabled="isSendingEmail"
|
||||
:outline="true"
|
||||
color="theme"
|
||||
@click="onSendInvoice"
|
||||
>
|
||||
{{ $t('invoices.send_invoice') }}
|
||||
</base-button>
|
||||
<router-link v-if="invoice.status === 'SENT'" :to="`/admin/payments/${$route.params.id}/create`">
|
||||
<base-button
|
||||
color="theme"
|
||||
>
|
||||
@ -152,7 +164,9 @@ export default {
|
||||
searchText: null
|
||||
},
|
||||
isRequestOnGoing: false,
|
||||
isSearching: false
|
||||
isSearching: false,
|
||||
isSendingEmail: false,
|
||||
isMarkingAsSent: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -179,6 +193,7 @@ export default {
|
||||
'getRecord',
|
||||
'searchInvoice',
|
||||
'markAsSent',
|
||||
'sendEmail',
|
||||
'deleteInvoice',
|
||||
'selectInvoice'
|
||||
]),
|
||||
@ -235,16 +250,35 @@ export default {
|
||||
icon: '/assets/icon/check-circle-solid.svg',
|
||||
buttons: true,
|
||||
dangerMode: true
|
||||
}).then(async (MarkAsSend_Invoice) => {
|
||||
if (MarkAsSend_Invoice) {
|
||||
this.isRequestOnGoing = true
|
||||
}).then(async (willMarkAsSent) => {
|
||||
if (willMarkAsSent) {
|
||||
this.isMarkingAsSent = true
|
||||
let response = await this.markAsSent({id: this.invoice.id})
|
||||
this.isRequestOnGoing = false
|
||||
this.isMarkingAsSent = false
|
||||
if (response.data) {
|
||||
window.toastr['success'](this.$tc('invoices.marked_as_sent_message'))
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
async onSendInvoice () {
|
||||
swal({
|
||||
title: this.$tc('general.are_you_sure'),
|
||||
text: this.$tc('invoices.confirm_send_invoice'),
|
||||
icon: '/assets/icon/paper-plane-solid.svg',
|
||||
buttons: true,
|
||||
dangerMode: true
|
||||
}).then(async (willSendInvoice) => {
|
||||
if (willSendInvoice) {
|
||||
this.isSendingEmail = true
|
||||
let response = await this.sendEmail({id: this.invoice.id})
|
||||
this.fetchInvoice()
|
||||
this.isSendingEmail = false
|
||||
if (response.data) {
|
||||
window.toastr['success'](this.$tc('invoices.confirm_send_invoice'))
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
async removeInvoice (id) {
|
||||
this.selectInvoice([parseInt(id)])
|
||||
|
||||
Reference in New Issue
Block a user