diff --git a/resources/assets/js/plugins/en.js b/resources/assets/js/plugins/en.js index 76e4f6eb..ea2900d4 100644 --- a/resources/assets/js/plugins/en.js +++ b/resources/assets/js/plugins/en.js @@ -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', diff --git a/resources/assets/js/store/modules/invoice/actions.js b/resources/assets/js/store/modules/invoice/actions.js index 64d167a0..4910fe63 100644 --- a/resources/assets/js/store/modules/invoice/actions.js +++ b/resources/assets/js/store/modules/invoice/actions.js @@ -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) diff --git a/resources/assets/js/store/modules/invoice/mutation-types.js b/resources/assets/js/store/modules/invoice/mutation-types.js index 9c7553dd..c92a4755 100644 --- a/resources/assets/js/store/modules/invoice/mutation-types.js +++ b/resources/assets/js/store/modules/invoice/mutation-types.js @@ -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' diff --git a/resources/assets/js/store/modules/invoice/mutations.js b/resources/assets/js/store/modules/invoice/mutations.js index b765f045..f8a5cad2 100644 --- a/resources/assets/js/store/modules/invoice/mutations.js +++ b/resources/assets/js/store/modules/invoice/mutations.js @@ -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 diff --git a/resources/assets/js/views/invoices/View.vue b/resources/assets/js/views/invoices/View.vue index fd1ce809..4a7359fd 100644 --- a/resources/assets/js/views/invoices/View.vue +++ b/resources/assets/js/views/invoices/View.vue @@ -5,16 +5,28 @@
{{ $t('invoices.mark_as_sent') }} +
- + + {{ $t('invoices.send_invoice') }} + + @@ -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)])