|
@@ -1,6 +1,7 @@
|
|
|
const state = {
|
|
|
loadingPricelists: false,
|
|
|
pricelists: [],
|
|
|
+ customerPricelist: null,
|
|
|
showPricelists: false
|
|
|
}
|
|
|
|
|
@@ -11,6 +12,9 @@ const getters = {
|
|
|
pricelists(state) {
|
|
|
return state.pricelists
|
|
|
},
|
|
|
+ customerPricelist(state) {
|
|
|
+ return state.customerPricelist
|
|
|
+ },
|
|
|
pricelistsForProduct(state, getters) {
|
|
|
let product = getters.itemToDiscount
|
|
|
|
|
@@ -49,6 +53,29 @@ const getters = {
|
|
|
|
|
|
return pricelists
|
|
|
},
|
|
|
+ pricelistsForCustomer(state, getters) {
|
|
|
+ let customer = getters.selectedCustomer
|
|
|
+
|
|
|
+ if (!customer) {
|
|
|
+ return []
|
|
|
+ }
|
|
|
+
|
|
|
+ let pricelists = []
|
|
|
+
|
|
|
+ for (let p of state.pricelists) {
|
|
|
+ if (p.type !== 'sale') {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if (p.id !== customer.pricelistId) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ pricelists.push(p)
|
|
|
+ }
|
|
|
+
|
|
|
+ return pricelists
|
|
|
+ },
|
|
|
showPricelists(state) {
|
|
|
return state.showPricelists
|
|
|
}
|
|
@@ -61,6 +88,25 @@ const mutations = {
|
|
|
setPricelists(state, pricelists) {
|
|
|
state.pricelists = pricelists
|
|
|
},
|
|
|
+ setCustomerPricelist(state, pricelistId) {
|
|
|
+ let pricelist = null
|
|
|
+
|
|
|
+ for (let p of state.pricelists) {
|
|
|
+ if (p.id === pricelistId) {
|
|
|
+ pricelist = p
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ state.customerPricelist = pricelist
|
|
|
+ },
|
|
|
+ autoselectPricelist(state) {
|
|
|
+ if (state.pricelists.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ state.customerPricelist = state.pricelists[0]
|
|
|
+ },
|
|
|
togglePricelists(state) {
|
|
|
state.showPricelists = !state.showPricelists
|
|
|
}
|
|
@@ -69,11 +115,16 @@ const mutations = {
|
|
|
const actions = {
|
|
|
initPricelists({ commit }, pricelists) {
|
|
|
commit('setPricelists', pricelists)
|
|
|
+ commit('autoselectPricelist')
|
|
|
commit('setLoadingPricelists')
|
|
|
},
|
|
|
togglePricelists({ commit }) {
|
|
|
commit('togglePricelists')
|
|
|
},
|
|
|
+ selectCustomerPricelist({ commit }, pricelistId) {
|
|
|
+ console.log(pricelistId)
|
|
|
+ commit('setCustomerPricelist', pricelistId)
|
|
|
+ },
|
|
|
resetPricelist({ commit }) {
|
|
|
commit('setLoadingPricelists', true)
|
|
|
commit('setPricelists', [])
|