UNPKG

wholesale-vuex

Version:
978 lines (906 loc) 37.7 kB
import { snakeCase } from "lodash"; import humps from "lodash-humps"; import createHumps from "lodash-humps/lib/createHumps"; const { v4 } = require('uuid') import { getField, updateField } from "vuex-map-fields"; import wholesaleOrderSnapshotService from "./wholesale_order_snapshot.service"; import wholesaleOrderService from "./wholesale_order.service"; import wholesalePackingListService from './wholesale_packing_list.service' const { doPostOne, doFetchPackingListOne } = wholesalePackingListService const { doPostSalesOrderChanges } = wholesaleOrderService; const { doWholesaleOrderGetSnapshot } = wholesaleOrderSnapshotService; import { createVariantsListFromItemsList, checkExistOrNot, returnOriginalSkuQtyBySku, getPaymentTypesInArray, getPaymentTypesInObj, updateTermsList, otherPaymentTermsList } from "./common.service"; const snakes = createHumps(snakeCase); export default { namespaced: true, state: { masterOne: null, one: null, otherPaymentTypes: [], details: null, shipments: null, orderSnapshotObj: null, orderItemList: [], inProgress: false, filteredItemsVariantList: [], originalItems: null, snapShotResponseItems: [], currentOriginalVariants:[], itemOne: null, currentItemVariantList: [], oneVariantsObj: null, masterItemOne: null, originalVariants: [], variantsListInProgress:false, allChangesObject: [], originalOrderItemList:[], totalWholesalePrice: 0 // for store variant items total amount }, getters: { getField, }, mutations: { updateField, inProgress(state, yesOrNo) { state.inProgress = yesOrNo; }, setTotalWholesalePrice(state, price) { state.totalWholesalePrice = price; }, variantsListInProgress(state, yesOrNo) { state.variantsListInProgress = yesOrNo; }, setOrderItemList(state, list){ state.originalOrderItemList=JSON.parse(JSON.stringify(list)); }, setMasterOne(state, one) { if (one) state.masterOne = JSON.parse(JSON.stringify(one)); }, setNewVariantsList(state) { state.variantsList = []; state.originalVariants = [] }, setOne(state, one) { try{ if (!one.shippingAddress) { one.shippingAddress = { line: null, postcode: null, city: null, country: null, countryIso3: null } } if (!one.billingAddress) { one.billingAddress = { line: null, postcode: null, city: null, country: null, countryIso3: null } } if (one.paymentTermsObject) { state.otherPaymentTypes = getPaymentTypesInArray(one.paymentTermsObject) state.otherPaymentTypes=updateTermsList(state.otherPaymentTypes) } if (one.category) { one.category = one.category.split(',') } // if (one.state) { // state.wholesaleOrderNextState = state.wholesaleOrderStateList.filter((item) => { // return item.state == one.state // }) // } // else { // state.wholesaleOrderNextState = state.wholesaleOrderStateList.filter((item) => { // return item.state == 'submitted_processing' // }) // } if (one) state.one = JSON.parse(JSON.stringify(one)); }catch(err){ console.log(err) } }, setSnapshotObj(state, one) { state.orderSnapshotObj = one; }, setDetails(state, details) { state.details = details; }, setOrderItems(state, { items, shipmentDates }) { // to save only sipment dates items if (shipmentDates) { let newItems = []; items.filter((item) => { if ( item.shipmentStartDate === shipmentDates[0] && item.shipmentCancelDate === shipmentDates[1] ) newItems.push(item); }); state.orderItemList = newItems; state.originalItems = JSON.parse(JSON.stringify(newItems)); } // state.orderItemList = items; // state.originalItems = JSON.parse(JSON.stringify(items)); }, setSnapShotResponseItems(state, { items }) { state.snapShotResponseItems = items; }, setShipments(state, shipments) { state.shipments = shipments; }, async deleteOne(state, itemId){ let newList = state.orderItemList.filter(item => item.id !== itemId) state.orderItemList = [] state.orderItemList = newList const list = await createVariantsListFromItemsList( state.orderItemList ); state.filteredItemsVariantList = list; }, async setSnapShotItems(state) { if ( state.orderSnapshotObj && state.orderSnapshotObj.items && state.orderSnapshotObj.items.length ) { state.filteredItemsVariantList = []; if ( state.orderSnapshotObj && state.orderSnapshotObj.details && state.orderSnapshotObj.details.itemsFormat === "variant_size_color" && state.orderSnapshotObj.items ) { const list = await createVariantsListFromItemsList( state.orderItemList ); state.filteredItemsVariantList = list; // state.originalSnapShotItemsVariantsList = list; } else if ( state.orderSnapshotObj && state.orderSnapshotObj.details && state.orderSnapshotObj.details.itemsFormat === "sku" && state.orderSnapshotObj.items ) { state.filteredItemsVariantList = state.orderItemList; // state.originalSnapShotItemsVariantsList = state.orderItemList; } } }, async searchSnapShotItems(state, data) { if(state.orderItemList && state.orderItemList.length) state.filteredItemsVariantList = await createVariantsListFromItemsList( state.orderItemList ); let searchString = data.searchString; let shipmentDates = data.shipmentDates; if (searchString) { let items = []; state.filteredItemsVariantList.filter((variant) => { if ( variant.name && variant.name.toLowerCase().search(searchString.toLowerCase()) !== -1 ) { items.push(variant); } else if ( variant.sku && variant.sku.toLowerCase().search(searchString.toLowerCase()) !== -1 ) { items.push(variant); } else if ( variant.eanCode && variant.eanCode.toLowerCase().search(searchString.toLowerCase()) !== -1 ) { items.push(variant); } else if ( variant.color && variant.color.toLowerCase().search(searchString.toLowerCase()) !== -1 ) { items.push(variant); } }); state.filteredItemsVariantList = items; state.filteredItemsVariantList = [ ...new Set(state.filteredItemsVariantList), ]; } // filtered onlly current shipment window else if (shipmentDates) { let items = []; state.filteredItemsVariantList.filter((variant) => { if ( variant.shipmentStartDate === shipmentDates[0] && variant.shipmentCancelDate === shipmentDates[1] ) items.push(variant); }); state.filteredItemsVariantList = items; } // send all items if no filter else { state.filteredItemsVariantList = []; state.filteredItemsVariantList = state.orderItemList; } }, // for order details setOtherPaymentTypes(state, paymentTypes) { state.otherPaymentTypes = getPaymentTypesInArray(paymentTypes) state.otherPaymentTypes=updateTermsList(state.otherPaymentTypes) }, getOtherPaymentTypesInObj(state, paymentTypes) { state.otherPaymentTypes = getPaymentTypesInObj(paymentTypes) state.otherPaymentTypes=updateTermsList(state.otherPaymentTypes) }, addDefaultPaymentType(state, val) { try{ if (state.otherPaymentTypes === undefined || state.otherPaymentTypes == null) { state.otherPaymentTypes = [{ type: 'Payment on order confirmation', paid: 30 },{ type: 'Payment after last delivery', paid: 70,days: 0 }] } if (val.type == 'new') { state.otherPaymentTypes = [] state.otherPaymentTypes.splice(0, 0, { type: '', paid: 0, days: 0 }) } else if (val.type == 'default') { state.otherPaymentTypes = [{ type: 'Payment on order confirmation', paid: 30},{ type: 'Payment after last delivery', paid: 70,days: 0 }] state.otherPaymentTypes=updateTermsList(state.otherPaymentTypes) }else if(val.type == 'splitPaymentIn30%Deposit/70%BFDelivery'){ state.otherPaymentTypes = [ { "type": "Payment on order confirmation", "paid": "30", "days": 0 }, { "type": "Payment before first delivery", "paid": "70", "days": 0 } ] }else if(val.type == 'splitPaymentIn30%Deposit/70%ALDelivery'){ state.otherPaymentTypes = [ { "type": "Payment on order confirmation", "paid": "30", "days": 0 }, { "type": "Payment after last delivery", "paid": "70", "days": 0 } ] }else if(val.type === 'reset'){ state.otherPaymentTypes = [] } else { let termsList= state.otherPaymentTypes.map((item)=> item.type) let difference = otherPaymentTermsList.filter(x => !termsList.includes(x)); state.otherPaymentTypes.splice(val.index, 0, { type:difference[0], paid: 0, days: 0 }) state.otherPaymentTypes=updateTermsList(state.otherPaymentTypes) } }catch(err){ console.log(err) } }, updatePaymentTerms(state){ state.otherPaymentTypes=updateTermsList(state.otherPaymentTypes) }, deletePaymentTypeRow(state, index) { state.otherPaymentTypes.splice(index, 1); state.otherPaymentTypes=updateTermsList(state.otherPaymentTypes) }, async setUpdateVariantsToList(state, data){ try{ state.itemOne = null state.itemOne = data.item let newList = state.orderItemList state.orderItemList.filter((item)=> { if(item.id === state.itemOne.id) { item.variants = data.variants } }) state.orderItemList = [] state.filteredItemsVariantList = [] state.orderItemList = newList state.filteredItemsVariantList = await createVariantsListFromItemsList( state.orderItemList ); }catch(err){ console.log(err) } }, async addNewVariantsToList(state, data){ try{ state.itemOne = null state.itemOne = data.item // let newList = state.orderItemList state.orderItemList.push(data.item) state.filteredItemsVariantList = [] //state.orderItemList = newList state.filteredItemsVariantList = await createVariantsListFromItemsList( state.orderItemList ); }catch(err){ console.log(err) } }, // for items setOneVariantsObj(state, oneItem) { state.oneVariantsObj = oneItem; }, setItemOne(state, data) { try{ state.currentItemVariantList = [] state.currentOriginalVariants = [] state.itemOne = null // setting master item one state.masterItemOne = null let itemId = data.itemId state.itemOne = data if(itemId) state.masterItemOne = state.originalItems.filter((item)=> item.id === itemId)[0] if(state.masterItemOne && state.masterItemOne.shipmentCancelDateOld){ state.masterItemOne.shipmentCancelDate=state.masterItemOne.shipmentCancelDateOld delete state.masterItemOne.shipmentCancelDateOld } if(state.masterItemOne && state.masterItemOne.shipmentStartDateOld){ state.masterItemOne.shipmentStartDate=state.masterItemOne.shipmentStartDateOld delete state.masterItemOne.shipmentStartDateOld } state.masterItemOne = JSON.stringify(state.masterItemOne); // setting current one item if(itemId){ state.itemOne = state.orderItemList.filter((item)=> item.id === itemId)[0] } if (state.itemOne.variants.length > 0 && state.itemOne.format === 'sku') { state.oneVariantsObj = Object.assign({}, state.itemOne.variants[0]) let resultColor = state.oneVariantsObj.color let newColor = resultColor && resultColor.length && typeof resultColor == "object" ? resultColor[0] : resultColor && typeof resultColor == "string" ? resultColor : null; state.oneVariantsObj.color = newColor let resultSize = state.oneVariantsObj.size let newSize = resultSize && resultSize.length && typeof resultSize == "object" ? resultSize[0] : resultSize && typeof resultSize == "string" ? resultSize : null; state.oneVariantsObj.size = newSize let resultCategory = state.oneVariantsObj.category let newCategory = resultCategory && resultCategory.length && Array.isArray(resultCategory) ? resultCategory : typeof resultCategory == "object" ? resultCategory[0] : resultCategory && typeof resultCategory == "string" ? resultCategory : null; state.oneVariantsObj.category = newCategory } if (state.itemOne.variants.length > 0 && state.itemOne.format === "variant_size_color") { state.oneVariantsObj = Object.assign({}, state.itemOne.variants[0]) state.oneVariantsObj.boxNumber = '' state.itemOne.variants.map((a) => { if (!a.qtyPacked){ a.qtyPacked=a.qty } }); let resultSize = [] let resultColor = [] state.itemOne.variants.filter((a) => { resultSize.push(a.size+'') resultColor.push(a.color) }); let newListSize = resultSize state.oneVariantsObj.size = newListSize && newListSize.length ? [...new Set(newListSize)] : null; // state.itemOne.variants.filter((a) => { // resultColor.push(a.color) // }); let newListColor = resultColor && resultColor.length ? (resultColor.toString()).split(",") : null; state.oneVariantsObj.color = newListColor && newListColor.length ? [...new Set(newListColor)] : null; let resultCategory = state.itemOne.variants.map(a => a.category ); let newListCategory = (resultCategory.toString()).split(","); state.oneVariantsObj.category = [...new Set(newListCategory)]; state.currentItemVariantList = state.itemOne.variants; state.currentOriginalVariants = state.itemOne.variants; } }catch(err){ console.log(err) } }, setEmptyItemVariantsList(state){ state.currentItemVariantList = [] state.currentOriginalVariants = [] }, setItemVariantsList(state) { try{ // state.currentItemVariantList = [] if(state.oneVariantsObj && state.oneVariantsObj.category && state.currentItemVariantList.length <= 0){ state.oneVariantsObj.category.filter((categoryItem) => { if (state.oneVariantsObj.color && state.oneVariantsObj.color.length > 0) { // if variants has color and size state.oneVariantsObj.color.filter((colorItem) => { if (state.oneVariantsObj.size && state.oneVariantsObj.size.length > 0) { state.oneVariantsObj.size.filter((sizeItem) => { state.currentItemVariantList.push( { variantId:v4(), sku: state.itemOne.variantsRefCode + '-' + categoryItem + '-' + sizeItem + '-' + colorItem, category: categoryItem ? categoryItem : null, size: sizeItem ? sizeItem : null, color: colorItem ? colorItem : null, qty: 0, //qty: state.oneVariantsObj.qty, retailPrice: state.oneVariantsObj.retailPrice, wholesalePrice: state.oneVariantsObj.wholesalePrice, eanCode: null,// state.oneVariantsObj.eanCode, qtyPacked:0, boxNumber: '' } ) }) } else { // if variants has color and no size state.currentItemVariantList.push( { variantId:v4(), sku: state.itemOne.variantsRefCode + '-' + categoryItem + '-' + colorItem, category: categoryItem, size: null, color: colorItem ? colorItem : null, qty: 0, //qty: state.oneVariantsObj.qty, retailPrice: state.oneVariantsObj.retailPrice, wholesalePrice: state.oneVariantsObj.wholesalePrice, eanCode: null, //state.oneVariantsObj.eanCode qtyPacked:0, boxNumber: '' } ) } }) } else if (state.oneVariantsObj.size && state.oneVariantsObj.size.length > 0) { // if variants has size and no color state.oneVariantsObj.size.filter((sizeItem) => { state.currentItemVariantList.push( { variantId:v4(), sku: state.one.variantsRefCode + '-' + categoryItem + '-' + sizeItem, category: categoryItem, size: sizeItem, color: null, qty: 0, //qty: state.oneVariantsObj.qty, retailPrice: state.oneVariantsObj.retailPrice, wholesalePrice: state.oneVariantsObj.wholesalePrice, eanCode: null, //state.oneVariantsObj.eanCode qtyPacked:0, boxNumber: '' } ) }) } else { // if variants has no size and no color , only has category state.currentItemVariantList.push( { variantId:v4(), sku: state.itemOne.variantsRefCode + '-' + categoryItem, category: categoryItem, size: null, color: null, qty: 0, //qty: state.oneVariantsObj.qty, retailPrice: state.oneVariantsObj.retailPrice, wholesalePrice: state.oneVariantsObj.wholesalePrice, eanCode: null,//state.oneVariantsObj.eanCode qtyPacked:0, boxNumber: '' } ) } }) } else { let variantList = state.currentItemVariantList.length > 0 ? state.currentItemVariantList : state.currentOriginalVariants let newColors = checkExistOrNot({oneVariantsObj: state.oneVariantsObj.color,variantsList: variantList, type: 'color'}) let newCategory = checkExistOrNot({oneVariantsObj: state.oneVariantsObj.category,variantsList: variantList, type: 'category'}) let newSize = checkExistOrNot({oneVariantsObj: state.oneVariantsObj.size,variantsList: variantList, type: 'size'}) let newVariantItems = [] if(state.currentOriginalVariants && state.currentOriginalVariants.length){ state.currentOriginalVariants.filter((item)=>{ let flag = false if(state.oneVariantsObj && state.oneVariantsObj.category && state.oneVariantsObj.category.includes(item.category)){ if(!state.oneVariantsObj.size.includes(item.size)){ flag = true } if(!state.oneVariantsObj.color.includes(item.color)){ flag = true } if(!flag) { newVariantItems.push(item) } } }) } let totalMixedCategories = [] if(newCategory && newCategory.length) totalMixedCategories = [...new Set([...newCategory])] if(state.oneVariantsObj.category) totalMixedCategories = [...new Set([...totalMixedCategories, ...state.oneVariantsObj.category])] let totalMixedColors = [] if(newColors && newColors.length) totalMixedColors = [...new Set([...newColors])] if(state.oneVariantsObj.color) totalMixedColors = [...new Set([...totalMixedColors, ...state.oneVariantsObj.color])] let totalMixedSizes = [] if(newSize && newSize.length) totalMixedSizes = [...new Set([...newSize])] if(state.oneVariantsObj.size) totalMixedSizes = [...new Set([...totalMixedSizes, ...state.oneVariantsObj.size])] // let totalMixedColors = [...new Set([...newColors, ...state.oneVariantsObj.color])] // let totalMixedSizes = [...new Set([...newSize, ...state.oneVariantsObj.size])] // if(newCategory.length){ for(let i=0; i< totalMixedCategories.length; i++){ let category = totalMixedCategories[i]; // if(newColors.length){ for(let j=0; j< totalMixedColors.length; j++){ let color = totalMixedColors[j]; // if(newSize.length){ for(let k=0; k< totalMixedSizes.length; k++){ let size = totalMixedSizes[k]; let obj = { variantId:v4(), sku: state.itemOne.variantsRefCode + '-' + category + '-' + size + '-' + color, category: category ? category : null, size: size ? size : null, color: color ? color : null, qty: returnOriginalSkuQtyBySku(state.currentItemVariantList, 'qty', category , size ,color), retailPrice: state.oneVariantsObj.retailPrice, // returnOriginalSkuQtyBySku(state.currentItemVariantList, 'retailPrice', category , size ,color),// wholesalePrice: state.oneVariantsObj.wholesalePrice, // returnOriginalSkuQtyBySku(state.currentItemVariantList, 'wholesalePrice', category , size ,color), eanCode: returnOriginalSkuQtyBySku(state.currentItemVariantList, 'eanCode', category , size ,color), qtyPacked: returnOriginalSkuQtyBySku(state.currentItemVariantList, 'qtyPacked', category , size ,color), boxNumber: '' } // avoid duplication if(!newVariantItems.filter((item => (item.category == obj.category && item.size == obj.size && item.color == obj.color))).length) newVariantItems.push(obj) else { newVariantItems.filter((item,index) => { if(item.category == obj.category && item.size == obj.size && item.color == obj.color){ let {sku, ...othersProp } = obj newVariantItems[index] = { sku: item.sku, ...othersProp } } }) } } // totalMixedSizes //} } //totalMixedColors //} } // totalMixedCategories //} //newCategory.length if(newVariantItems && newVariantItems.length) state.currentItemVariantList = [...new Set([...newVariantItems])] state.orderItemList.filter((item)=> { if(item.id === state.itemOne.id) { item.variants = state.currentItemVariantList } }) } }catch(err){ console.log(err) } }, saveChangeObjectInStore(state, data){ try{ let isFound = false if(state.allChangesObject && state.allChangesObject.length){ for(let i=0; i<state.allChangesObject.length; i++){ let currentChange = state.allChangesObject[i] if(currentChange.change.change === data.change.change){ isFound = true state.allChangesObject[i] = data if(!(data.change.changeValues.new == null && data.change.changeValues.old == null)){ state.allChangesObject.splice(i, 1) } break; } } } // if(!isFound){ if(!(data.change.changeValues.new == null && data.change.changeValues.old == null)){ state.allChangesObject.push({...data}) state.allChangesObject = [...new Set(state.allChangesObject)] } // } } catch(err){ console.log(err) } } }, actions: { new({ commit }, { appId, wholesaleOrderId, purchaserBusinessEntityId, providerBusinessEntityId, brandId,startDate,endDate,itemsFormat }) { commit('inProgress', false) commit('setItemOne', { 'appId': appId, 'wholesaleOrderId': wholesaleOrderId, 'brandId': brandId, 'format': itemsFormat, 'lineNumber': 0, 'quantity': 0, 'unitPrice': 0, 'name': null, 'description': null, 'variantsRefCode': null, 'variants': [], 'purchaserBusinessEntityId': purchaserBusinessEntityId, 'providerBusinessEntityId': providerBusinessEntityId, 'shipmentStartDate':startDate, 'shipmentCancelDate':endDate, 'hsCode':null }) }, savePackingList : async({ commit, state, dispatch }) => { commit('inProgress', true) try { if (state.one.id) { let packingList = { app_id: state.one.appId, provider_business_entity_id: state.one.providerBusinessEntityId, purchaser_business_entity_id: state.one.purchaserBusinessEntityId, reference_id: state.one.id, reference_type: 'wholesale', packing_date: state.one.date, shipping_address: state.one.shippingAddress, billing_address: state.one.billingAddress, salesteam_service_id: null } let data = await doPostOne(packingList) if(data) { commit('inProgress', false) let packingListBoxDetails = await dispatch("salesPackingListBoxOne/savePackingBoxAndPallet", { packingList: humps(data) }, {root: true}); // Save packing list items let packingListItemsDetails = await dispatch("salesPackingListItemList/savePackingListItems", { packingList: humps(data), dataList: humps(state.filteredItemsVariantList), itemsFormat: 'variant_size_color' }, {root: true}); if (packingListBoxDetails && packingListItemsDetails) { return ({ new: true, packingList: humps(data), packingListBoxDetails: humps(packingListBoxDetails), packingListItemsDetails: humps(packingListItemsDetails) }) } } return ({ new: true, packingList: humps(data) }) } else { // let packingList = await doPatchOne(snakes(state.one)) // commit('inProgress', false) // return ({ update: true, packingList: packingList }) } } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, fetchProcessingSnapshot: async ( { commit }, { wholesaleOrderId, shipmentDates, specs } ) => { commit("inProgress", true); try { let snapshot = await doWholesaleOrderGetSnapshot({ wholesaleOrderId, specs, }); if (snapshot) { commit("setSnapshotObj", humps(snapshot)); commit("setOrderItems", { items: humps(snapshot.items), shipmentDates }); commit("setOrderItemList", (snapshot.items)); commit("setDetails", humps(snapshot.details)); commit("setMasterOne", humps(snapshot.details)); commit("setOne", humps(snapshot.details)); commit("setShipments", humps(snapshot.shipments)); commit("setSnapShotResponseItems", { items: humps(snapshot.items) }); commit("searchSnapShotItems", { searchString : '', shipmentDates }); return humps(snapshot); } } catch (err) { throw "error"+ err; } finally { commit("inProgress", false); } }, snapShotOrderItemsForFilter: ({ commit }, {}) => { commit("setSnapShotItems"); }, searchSnapShotItems: ({ commit }, { searchString, shipmentDates }) => { commit("searchSnapShotItems", { searchString, shipmentDates}); }, addDefaultPaymentType: async ({ commit }, val) => { commit('addDefaultPaymentType', val); }, deletePaymentTypeRow: async ({ commit }, index) => { commit('deletePaymentTypeRow', index); }, deleteOrderItem: async ({ commit}, itemId ) => { try { commit('deleteOne', itemId); return ({ changeResp: true }) } catch (err) { throw 'error' } }, updateOtherPaymentTypes: async ({ commit }) => { commit('inProgress', true); try { commit('updatePaymentTerms'); } catch (err) { throw 'error' } finally { commit('inProgress', false); } }, // for items setCurrentItemOne: ({ commit }, { itemId }) => { commit("setItemOne", { itemId }); }, setUpdateVariantsToList: ({ commit }, { variants, item }) => { commit("setUpdateVariantsToList", { variants, item }); }, addNewVariantsToList: ({ commit }, { variants, item }) => { commit("addNewVariantsToList", { variants, item }); }, // for item edit form newItemVariantsList: async ({ commit }) => { try { commit('setItemVariantsList'); } catch (err) { console.log(err) } }, newItemVariant({ commit }) { commit('setOneVariantsObj', { sku: null, category: null, size: null, color: null, qty: null, retailPrice: null, wholesalePrice: null, eanCode: null, qtyPacked:null }) }, newVariantsList: async ({ commit }) => { commit('variantsListInProgress', true); try { commit('setNewVariantsList'); commit('variantsListInProgress', false); } catch (err) { commit('variantsListInProgress', false); } }, saveChangeObjectInStore({ commit }, { wholesaleOrderChangesetId, change } ) { commit("saveChangeObjectInStore", { wholesaleOrderChangesetId, change }); }, // to save order details changes saveOrderChangeObject: async ( { commit }, { wholesaleOrderChangesetId, change,itemIcpData } ) => { commit("inProgress", true); try { let data = await doPostSalesOrderChanges({ wholesaleOrderChangesetId, change: snakes(change), itemIcpData }); return { data: humps(data) }; } catch (err) { throw err; } finally { commit("inProgress", false); } }, setTotalWholesalePriceOne: ({ commit }, { price }) => { commit("setTotalWholesalePrice", price) }, fetchOne: async ({ commit}, { salesOrderId }) => { // used to fetch commercial invoice items based on latest packing list id commit('inProgress', true); try { let packingListOne = await doFetchPackingListOne({ salesOrderId }); if (packingListOne) { if(packingListOne.length > 0){ // commit('setOne', humps(packingListOne[packingListOne.length - 1])) return { packingListOne : humps(packingListOne[packingListOne.length - 1]) } } return { packingListOne : null } } } // eslint-disable-next-line no-useless-catch catch (err) { throw err } finally { commit('inProgress', false) } }, }, // actions } // Old Packing list code backup // import { snakeCase } from 'lodash' // import humps from 'lodash-humps' // import createHumps from 'lodash-humps/lib/createHumps' // import { getField, updateField } from 'vuex-map-fields' // import wholesalePackingListService from './wholesale_packing_list.service' // const { doPostOne, doFetchPackingListOne, doDeleteSelectedPackingList } = wholesalePackingListService // const snakes = createHumps(snakeCase) // export default { // namespaced: true, // state: { // one: null, // inProgress: true, // itemsPackedTypeList: [], // selectedItemId : null, // }, // getters: { // getField, // }, // mutations: { // updateField, // setOne(state, one) { // if(!one.shippingAddress ){ // one.shippingAddress={line:'',postcode:'',city:'',country:'',countryIso3:''} // } // if(!one.billingAddress){ // one.billingAddress={line:'',postcode:'',city:'',country:'',countryIso3:''} // } // state.one = one; // }, // inProgress(state, yesOrNo) { // state.inProgress = yesOrNo // }, // removeBusinessEntity(state) { // if (state.one.businessEntity) // delete state.one.businessEntity // }, // }, // actions: { // new({ commit }, { salesOrderOne }) { // commit('inProgress', false); // commit('setOne', { // appId: salesOrderOne.appId, // soNumber: salesOrderOne.soNumber, // packingDate: salesOrderOne.date, // shippingAddress: salesOrderOne.shippingAddress, // billingAddress: salesOrderOne.billingAddress, // salesteamServiceId : salesOrderOne.brandOwnerSalesteamId ? // salesOrderOne.brandOwnerSalesteamId : salesOrderOne.distributorSalesteamId // ? salesOrderOne.distributorSalesteamId : salesOrderOne.salesagentSalesteamId, // providerBusinessEntityId : typeof salesOrderOne.providerBusinessEntityId == 'object' ? salesOrderOne.providerBusinessEntityId.id : salesOrderOne.providerBusinessEntityId, // purchaserBusinessEntityId: typeof salesOrderOne.purchaserBusinessEntityId == 'object' ? salesOrderOne.purchaserBusinessEntityId.id : salesOrderOne.purchaserBusinessEntityId, // referenceId : salesOrderOne.id, // referenceType : 'sales_order', // }); // }, // fetchOne: async ({ commit}, { salesOrderId }) => { // // used to fetch commercial invoice items based on latest packing list id // commit('inProgress', true); // try { // let packingListOne = await doFetchPackingListOne({ salesOrderId }); // if (packingListOne) { // if(packingListOne.length > 0){ // commit('setOne', humps(packingListOne[packingListOne.length - 1])) // return { packingListOne : humps(packingListOne[packingListOne.length - 1]) } // } // else // commit('setOne', []) // return { packingListOne : null } // } // } // // eslint-disable-next-line no-useless-catch // catch (err) { // throw err // } // finally { // commit('inProgress', false) // } // }, // savePackingList : async({ commit, state, dispatch }) => { // commit('inProgress', true) // try { // if (undefined === state.one.id) { // let packingList = await doPostOne(snakes(Object.assign({}, state.one))) // packingList = humps(packingList) // if(packingList) { // await dispatch("salesPackingListBoxOne/savePackingBoxes", { packingList }, {root: true}); // commit('setOne', { ...packingList }) // } // commit('inProgress', false) // return ({ new: true, packingList }) // } else { // // let packingList = await doPatchOne(snakes(state.one)) // // commit('inProgress', false) // // return ({ update: true, packingList: packingList }) // } // } // // eslint-disable-next-line no-useless-catch // catch (err) { // throw err // } // finally { // commit('inProgress', false) // } // }, // deletePackingList: async ({ commit }, { packingListId }) => { // commit('inProgress', true); // try { // await doDeleteSelectedPackingList({ packingListId }); // return ({ deleteSelected: true }) // } catch (err) { // return ({ deleteSelected: false }) // } // finally { // commit('inProgress', false); // } // }, // } // }