From 090c33f63cc1dd0769d7f8b8f0b362af8826c994 Mon Sep 17 00:00:00 2001 From: satyaprakash10 Date: Thu, 14 Nov 2019 19:54:23 +0530 Subject: [PATCH 1/3] fix status action in view invoice --- resources/assets/js/plugins/en.js | 1 + .../js/store/modules/invoice/actions.js | 1 + .../store/modules/invoice/mutation-types.js | 1 + .../js/store/modules/invoice/mutations.js | 6 +++ resources/assets/js/views/invoices/View.vue | 50 ++++++++++++++++--- 5 files changed, 51 insertions(+), 8 deletions(-) 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)]) From adbc04846c49a8ccf2e2500fdb4dd4b7c231b427 Mon Sep 17 00:00:00 2001 From: yogesh_gohil Date: Fri, 15 Nov 2019 12:55:35 +0530 Subject: [PATCH 2/3] fix invoice getter --- .../js/store/modules/invoice/actions.js | 2 +- .../js/store/modules/invoice/getters.js | 4 ++ resources/assets/js/views/invoices/View.vue | 37 +++++++------------ 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/resources/assets/js/store/modules/invoice/actions.js b/resources/assets/js/store/modules/invoice/actions.js index 4910fe63..47d4dd77 100644 --- a/resources/assets/js/store/modules/invoice/actions.js +++ b/resources/assets/js/store/modules/invoice/actions.js @@ -122,7 +122,7 @@ export const updateInvoice = ({ commit, dispatch, state }, data) => { export const markAsSent = ({ commit, dispatch, state }, data) => { return new Promise((resolve, reject) => { 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) }).catch((err) => { reject(err) diff --git a/resources/assets/js/store/modules/invoice/getters.js b/resources/assets/js/store/modules/invoice/getters.js index 2e57c1de..fa2b598e 100644 --- a/resources/assets/js/store/modules/invoice/getters.js +++ b/resources/assets/js/store/modules/invoice/getters.js @@ -4,3 +4,7 @@ export const getTemplateId = (state) => state.invoiceTemplateId export const selectedInvoices = (state) => state.selectedInvoices export const totalInvoices = (state) => state.totalInvoices export const selectedCustomer = (state) => state.selectedCustomer +export const getInvoice = (state) => (id) => { + let invId = parseInt(id) + return state.invoices.find(invoice => invoice.id === invId) +} diff --git a/resources/assets/js/views/invoices/View.vue b/resources/assets/js/views/invoices/View.vue index 4a7359fd..ee4db7b1 100644 --- a/resources/assets/js/views/invoices/View.vue +++ b/resources/assets/js/views/invoices/View.vue @@ -14,7 +14,6 @@ > {{ $t('invoices.mark_as_sent') }} -
- {{ $t('invoices.send_invoice') }} - + {{ $t('invoices.send_invoice') }} +