fix status action in view estimate

This commit is contained in:
satyaprakash10
2019-11-15 19:43:42 +05:30
parent e018d71443
commit d529c1d68f
5 changed files with 71 additions and 19 deletions

View File

@ -56,6 +56,7 @@ export const fetchViewEstimate = ({ 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/estimates/send`, data).then((response) => { window.axios.post(`/api/estimates/send`, data).then((response) => {
commit(types.UPDATE_ESTIMATE_STATUS, {id: data.id, status: 'SENT'})
resolve(response) resolve(response)
}).catch((err) => { }).catch((err) => {
reject(err) reject(err)
@ -100,7 +101,7 @@ export const deleteMultipleEstimates = ({ commit, dispatch, state }, id) => {
export const updateEstimate = ({ commit, dispatch, state }, data) => { export const updateEstimate = ({ commit, dispatch, state }, data) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
window.axios.put(`/api/estimates/${data.id}`, data).then((response) => { window.axios.put(`/api/estimates/${data.id}`, data).then((response) => {
commit(types.UPDATE_ESTIMATE, response.data) commit(types.UPDATE_ESTIMATE_STATUS, response.data)
resolve(response) resolve(response)
}).catch((err) => { }).catch((err) => {
reject(err) reject(err)

View File

@ -4,3 +4,7 @@ export const getTemplateId = (state) => state.estimateTemplateId
export const selectedEstimates = (state) => state.selectedEstimates export const selectedEstimates = (state) => state.selectedEstimates
export const totalEstimates = (state) => state.totalEstimates export const totalEstimates = (state) => state.totalEstimates
export const selectedCustomer = (state) => state.selectedCustomer export const selectedCustomer = (state) => state.selectedCustomer
export const getEstimate = (state) => (id) => {
let invId = parseInt(id)
return state.estimates.find(estimate => estimate.id === invId)
}

View File

@ -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_ESTIMATES = 'RESET_SELECTED_ESTIMATES' export const RESET_SELECTED_ESTIMATES = 'RESET_SELECTED_ESTIMATES'
export const UPDATE_ESTIMATE_STATUS = 'UPDATE_ESTIMATE_STATUS'

View File

@ -37,6 +37,12 @@ export default {
state.estimates[pos] = data.estimate state.estimates[pos] = data.estimate
}, },
[types.UPDATE_ESTIMATE_STATUS] (state, data) {
let pos = state.estimates.findIndex(estimate => estimate.id === data.id)
state.estimates[pos].status = data.status
},
[types.RESET_SELECTED_ESTIMATES] (state, data) { [types.RESET_SELECTED_ESTIMATES] (state, data) {
state.selectedEstimates = [] state.selectedEstimates = []
state.selectAllField = false state.selectAllField = false

View File

@ -3,11 +3,11 @@
<div class="page-header"> <div class="page-header">
<h3 class="page-title"> {{ estimate.estimate_number }}</h3> <h3 class="page-title"> {{ estimate.estimate_number }}</h3>
<div class="page-actions row"> <div class="page-actions row">
<div class="col-xs-2"> <div class="col-xs-2 mr-3">
<base-button <base-button
v-if="estimate.status !== 'SENT'" v-if="estimate.status === 'DRAFT'"
:loading="isRequestOnGoing" :loading="isMarkAsSent"
:disabled="isRequestOnGoing" :disabled="isMarkAsSent"
:outline="true" :outline="true"
color="theme" color="theme"
@click="onMarkAsSent" @click="onMarkAsSent"
@ -15,6 +15,18 @@
{{ $t('estimates.mark_as_sent') }} {{ $t('estimates.mark_as_sent') }}
</base-button> </base-button>
</div> </div>
<div class="col-xs-2">
<base-button
v-if="estimate.status === 'DRAFT'"
:loading="isSendingEmail"
:disabled="isSendingEmail"
:outline="true"
color="theme"
@click="onSendEstimate"
>
{{ $t('estimates.send_estimate') }}
</base-button>
</div>
<v-dropdown :close-on-select="false" align="left" class="filter-container"> <v-dropdown :close-on-select="false" align="left" class="filter-container">
<a slot="activator" href="#"> <a slot="activator" href="#">
<base-button color="theme"> <base-button color="theme">
@ -111,7 +123,7 @@
<div class="left"> <div class="left">
<div class="inv-name">{{ estimate.user.name }}</div> <div class="inv-name">{{ estimate.user.name }}</div>
<div class="inv-number">{{ estimate.estimate_number }}</div> <div class="inv-number">{{ estimate.estimate_number }}</div>
<div :class="'est-status-'+estimate.status.toLowerCase()" class="inv-status">{{ estimate.status }}</div> <div :class="'est-status-'+estimate.status.toLowerCase()"class="inv-status">{{ estimate.status }}</div>
</div> </div>
<div class="right"> <div class="right">
<div class="inv-amount" v-html="$utils.formatMoney(estimate.total, estimate.user.currency)" /> <div class="inv-amount" v-html="$utils.formatMoney(estimate.total, estimate.user.currency)" />
@ -129,7 +141,9 @@
</div> </div>
</template> </template>
<script> <script>
import { mapActions } from 'vuex' // import { mapActions } from 'vuex'
import { mapActions, mapGetters } from 'vuex'
const _ = require('lodash') const _ = require('lodash')
export default { export default {
data () { data () {
@ -137,9 +151,9 @@ export default {
id: null, id: null,
count: null, count: null,
estimates: [], estimates: [],
estimate: null, // estimate: null,
currency: null, currency: null,
shareableLink: null, // shareableLink: null,
searchData: { searchData: {
orderBy: null, orderBy: null,
orderByField: null, orderByField: null,
@ -147,11 +161,16 @@ export default {
}, },
status: ['DRAFT', 'SENT', 'VIEWED', 'EXPIRED', 'ACCEPTED', 'REJECTED'], status: ['DRAFT', 'SENT', 'VIEWED', 'EXPIRED', 'ACCEPTED', 'REJECTED'],
isMarkAsSent: false, isMarkAsSent: false,
isSendingEmail: false,
isRequestOnGoing: false, isRequestOnGoing: false,
isSearching: false isSearching: false
} }
}, },
computed: { computed: {
estimate () {
return this.$store.getters['estimate/getEstimate'](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
@ -159,22 +178,25 @@ export default {
return false return false
} }
}, },
shareableLink () {
return `/estimates/pdf/${this.estimate.unique_hash}`
},
watch: { watch: {
'$route.params.id' (val) { '$route.params.id' (val) {
this.fetchEstimate() this.fetchEstimate()
} }
}, },
mounted () { created () {
this.loadEstimates() this.loadEstimates()
this.onSearched = _.debounce(this.onSearched, 500) this.onSearched = _.debounce(this.onSearched, 500)
}, },
methods: { methods: {
...mapActions('estimate', [ ...mapActions('estimate', [
'fetchEstimates', 'fetchEstimates',
'fetchViewEstimate',
'getRecord', 'getRecord',
'searchEstimate', 'searchEstimate',
'markAsSent', 'markAsSent',
'sendEmail',
'deleteEstimate', 'deleteEstimate',
'selectEstimate' 'selectEstimate'
]), ]),
@ -205,15 +227,15 @@ export default {
this.estimates = response.data.estimates.data this.estimates = response.data.estimates.data
} }
}, },
async fetchEstimate () { // async fetchEstimate () {
let estimate = await this.fetchViewEstimate(this.$route.params.id) // let estimate = await this.fetchViewEstimate(this.$route.params.id)
if (estimate.data) { // if (estimate.data) {
this.estimate = estimate.data.estimate // this.estimate = estimate.data.estimate
this.shareableLink = estimate.data.shareable_link // this.shareableLink = estimate.data.shareable_link
this.currency = estimate.data.estimate.user.currency // this.currency = estimate.data.estimate.user.currency
} // }
}, // },
sortData () { sortData () {
if (this.searchData.orderBy === 'asc') { if (this.searchData.orderBy === 'asc') {
this.searchData.orderBy = 'desc' this.searchData.orderBy = 'desc'
@ -242,6 +264,24 @@ export default {
} }
}) })
}, },
async onSendEstimate (id) {
swal({
title: this.$t('general.are_you_sure'),
text: this.$t('estimates.confirm_send_estimate'),
icon: '/assets/icon/paper-plane-solid.svg',
buttons: true,
dangerMode: true
}).then(async (willSendEstimate) => {
if (willSendEstimate) {
this.isSendingEmail = true
let response = await this.sendEmail({id: this.estimate.id})
this.isSendingEmail = false
if (response.data) {
window.toastr['success'](this.$tc('estimates.send_estimate_successfully'))
}
}
})
},
async removeEstimate (id) { async removeEstimate (id) {
this.selectEstimate([parseInt(id)]) this.selectEstimate([parseInt(id)])
this.id = id this.id = id