mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-29 12:41:10 -04:00
Merge branch 'fix-view-status-action' into 'master'
fix status action in view invoice See merge request mohit.panjvani/crater-web!27
This commit is contained in:
@ -310,6 +310,7 @@ export default {
|
|||||||
invoice_template: 'Invoice Template',
|
invoice_template: 'Invoice Template',
|
||||||
template: 'Template',
|
template: 'Template',
|
||||||
mark_as_sent: 'Mark as sent',
|
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',
|
invoice_mark_as_sent: 'This invoice will be marked as sent',
|
||||||
confirm_send: 'This invoice will be sent via email to the customer',
|
confirm_send: 'This invoice will be sent via email to the customer',
|
||||||
invoice_date: 'Invoice Date',
|
invoice_date: 'Invoice Date',
|
||||||
|
|||||||
@ -47,6 +47,7 @@ export const fetchViewInvoice = ({ commit, dispatch, state }, id) => {
|
|||||||
export const sendEmail = ({ commit, dispatch, state }, data) => {
|
export const sendEmail = ({ commit, dispatch, state }, data) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
window.axios.post(`/api/invoices/send`, data).then((response) => {
|
window.axios.post(`/api/invoices/send`, data).then((response) => {
|
||||||
|
commit(types.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'})
|
||||||
resolve(response)
|
resolve(response)
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
reject(err)
|
reject(err)
|
||||||
@ -121,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)
|
||||||
|
|||||||
@ -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)
|
||||||
|
}
|
||||||
|
|||||||
@ -14,3 +14,4 @@ export const SELECT_CUSTOMER = 'SELECT_CUSTOMER'
|
|||||||
export const RESET_SELECTED_CUSTOMER = 'RESET_SELECTED_CUSTOMER'
|
export const RESET_SELECTED_CUSTOMER = 'RESET_SELECTED_CUSTOMER'
|
||||||
export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE'
|
export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE'
|
||||||
export const RESET_SELECTED_INVOICES = 'RESET_SELECTED_INVOICES'
|
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
|
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) {
|
[types.RESET_SELECTED_INVOICES] (state, data) {
|
||||||
state.selectedInvoices = []
|
state.selectedInvoices = []
|
||||||
state.selectAllField = false
|
state.selectAllField = false
|
||||||
|
|||||||
@ -5,8 +5,9 @@
|
|||||||
<div class="page-actions row">
|
<div class="page-actions row">
|
||||||
<div class="col-xs-2 mr-3">
|
<div class="col-xs-2 mr-3">
|
||||||
<base-button
|
<base-button
|
||||||
:loading="isRequestOnGoing"
|
v-if="invoice.status === 'DRAFT'"
|
||||||
:disabled="isRequestOnGoing"
|
:loading="isMarkingAsSent"
|
||||||
|
:disabled="isMarkingAsSent"
|
||||||
:outline="true"
|
:outline="true"
|
||||||
color="theme"
|
color="theme"
|
||||||
@click="onMarkAsSent"
|
@click="onMarkAsSent"
|
||||||
@ -14,7 +15,17 @@
|
|||||||
{{ $t('invoices.mark_as_sent') }}
|
{{ $t('invoices.mark_as_sent') }}
|
||||||
</base-button>
|
</base-button>
|
||||||
</div>
|
</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
|
<base-button
|
||||||
color="theme"
|
color="theme"
|
||||||
>
|
>
|
||||||
@ -135,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 () {
|
||||||
@ -143,42 +154,43 @@ 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,
|
||||||
searchText: null
|
searchText: null
|
||||||
},
|
},
|
||||||
isRequestOnGoing: false,
|
isRequestOnGoing: false,
|
||||||
isSearching: false
|
isSearching: false,
|
||||||
|
isSendingEmail: false,
|
||||||
|
isMarkingAsSent: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
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: {
|
created () {
|
||||||
'$route.params.id' (val) {
|
|
||||||
this.fetchInvoice()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted () {
|
|
||||||
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',
|
||||||
|
'sendEmail',
|
||||||
'deleteInvoice',
|
'deleteInvoice',
|
||||||
'selectInvoice'
|
'selectInvoice'
|
||||||
]),
|
]),
|
||||||
@ -187,7 +199,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 = ''
|
||||||
@ -209,15 +220,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'
|
||||||
@ -235,17 +237,35 @@ export default {
|
|||||||
icon: '/assets/icon/check-circle-solid.svg',
|
icon: '/assets/icon/check-circle-solid.svg',
|
||||||
buttons: true,
|
buttons: true,
|
||||||
dangerMode: true
|
dangerMode: true
|
||||||
}).then(async (MarkAsSend_Invoice) => {
|
}).then(async (willMarkAsSent) => {
|
||||||
if (MarkAsSend_Invoice) {
|
if (willMarkAsSent) {
|
||||||
this.isRequestOnGoing = true
|
this.isMarkingAsSent = true
|
||||||
let response = await this.markAsSent({id: this.invoice.id})
|
let response = await this.markAsSent({id: this.invoice.id})
|
||||||
this.isRequestOnGoing = false
|
this.isMarkingAsSent = false
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
window.toastr['success'](this.$tc('invoices.marked_as_sent_message'))
|
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.isSendingEmail = false
|
||||||
|
if (response.data) {
|
||||||
|
window.toastr['success'](this.$tc('invoices.confirm_send_invoice'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
async removeInvoice (id) {
|
async removeInvoice (id) {
|
||||||
this.selectInvoice([parseInt(id)])
|
this.selectInvoice([parseInt(id)])
|
||||||
this.id = id
|
this.id = id
|
||||||
|
|||||||
Reference in New Issue
Block a user