-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved: Migrated open orders page to use Moqui APIs(#905)
- Loading branch information
Showing
12 changed files
with
399 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { api, client, hasError } from '@/adapter'; | ||
import store from '@/store'; | ||
import { showToast } from '@/utils'; | ||
import { translate } from '@hotwax/dxp-components'; | ||
import logger from '@/logger' | ||
import { cogOutline } from 'ionicons/icons'; | ||
|
||
const findOpenOrders = async (query: any): Promise<any> => { | ||
return api({ | ||
// TODO: We can replace this with any API | ||
url: "solr-query", | ||
method: "post", | ||
data: query | ||
}); | ||
} | ||
|
||
const createPicklist = async (payload: any): Promise <any> => { | ||
const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo']; | ||
const baseURL = store.getters['user/getMaargBaseUrl']; | ||
|
||
return client({ | ||
url: `/createOrderFulfillmentWave`, | ||
method: "POST", | ||
baseURL, | ||
headers: { | ||
"api_key": omsRedirectionInfo.token, | ||
"Content-Type": "application/json" | ||
}, | ||
data: payload, | ||
}); | ||
} | ||
|
||
const printPicklist = async (picklistId: string): Promise <any> => { | ||
const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo']; | ||
const baseURL = store.getters['user/getMaargBaseUrl']; | ||
|
||
try { | ||
const resp = await client({ | ||
url: "/printPicklist.pdf", | ||
method: "GET", | ||
baseURL, | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
responseType: "blob" | ||
}); | ||
|
||
if (!resp || resp.status !== 200 || hasError(resp)) { | ||
throw resp.data; | ||
} | ||
|
||
// Generate local file URL for the blob received | ||
const pdfUrl = window.URL.createObjectURL(resp.data); | ||
// Open the file in new tab | ||
try { | ||
(window as any).open(pdfUrl, "_blank").focus(); | ||
} | ||
catch { | ||
showToast(translate('Unable to open as browser is blocking pop-ups.', {documentName: 'picklist'}), { icon: cogOutline }); | ||
} | ||
} catch (err) { | ||
showToast(translate('Failed to print picklist')) | ||
logger.error("Failed to print picklist", err) | ||
} | ||
} | ||
|
||
const recycleOutstandingOrders = async(payload: any): Promise<any> => { | ||
|
||
const omsRedirectionInfo = store.getters['user/getOmsRedirectionInfo']; | ||
const baseURL = store.getters['user/getMaargBaseUrl']; | ||
|
||
return client({ | ||
url: `/bulkRejectStoreOutstandingOrders`, | ||
method: "POST", | ||
baseURL, | ||
headers: { | ||
"api_key": omsRedirectionInfo.token, | ||
"Content-Type": "application/json" | ||
}, | ||
data: payload, | ||
}); | ||
} | ||
|
||
export const MaargOrderService = { | ||
createPicklist, | ||
findOpenOrders, | ||
printPicklist, | ||
recycleOutstandingOrders | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export default interface OrderState { | ||
open: { | ||
list: any, | ||
total: number, | ||
query: { | ||
viewIndex: number, | ||
viewSize: any, | ||
queryString: string, | ||
selectedShipmentMethods: Array<string> | ||
} | ||
}, | ||
completed: { | ||
list: any, | ||
total: number, | ||
query: { | ||
viewIndex: number, | ||
viewSize: any, | ||
queryString: string, | ||
selectedCarrierPartyIds: Array<string>, | ||
selectedShipmentMethods: Array<string> | ||
} | ||
}, | ||
inProgress: { | ||
list: any, | ||
total: number, | ||
query: { | ||
viewIndex: number, | ||
viewSize: any, | ||
selectedPicklist: string, | ||
queryString: string | ||
} | ||
}, | ||
current: any, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { ActionTree } from 'vuex' | ||
import RootState from '@/store/RootState' | ||
import OrderState from './MaargOrderState' | ||
import emitter from '@/event-bus' | ||
import { MaargOrderService } from '@/services/MaargOrderService' | ||
import { hasError } from '@/adapter' | ||
import * as types from './mutation-types' | ||
import { escapeSolrSpecialChars, prepareOrderQuery } from '@/utils/solrHelper' | ||
import logger from '@/logger' | ||
import { removeKitComponents } from '@/utils/order' | ||
import { getCurrentFacilityId, getProductStoreId } from '@/utils' | ||
|
||
const actions: ActionTree<OrderState, RootState> = { | ||
|
||
// get open orders | ||
async findOpenOrders ({ commit, state }, payload = {}) { | ||
emitter.emit('presentLoader'); | ||
let resp; | ||
|
||
const openOrderQuery = JSON.parse(JSON.stringify(state.open.query)) | ||
|
||
const params = { | ||
...payload, | ||
docType: 'ORDER', | ||
queryString: openOrderQuery.queryString, | ||
queryFields: 'productId productName parentProductName orderId orderName customerEmailId customerPartyId customerPartyName search_orderIdentifications goodIdentifications', | ||
viewSize: openOrderQuery.viewSize, | ||
sort: payload.sort ? payload.sort : "orderDate asc", | ||
filters: { | ||
'-shipmentMethodTypeId': { value: 'STOREPICKUP' }, | ||
'-fulfillmentStatus': { value: '[* TO *]' }, | ||
orderStatusId: { value: 'ORDER_APPROVED' }, | ||
orderTypeId: { value: 'SALES_ORDER' }, | ||
facilityId: { value: escapeSolrSpecialChars(getCurrentFacilityId()) }, | ||
productStoreId: { value: getProductStoreId() } | ||
} | ||
} | ||
|
||
// only adding shipmentMethods when a method is selected | ||
if(openOrderQuery.selectedShipmentMethods.length) { | ||
params.filters['shipmentMethodTypeId'] = { value: openOrderQuery.selectedShipmentMethods, op: 'OR' } | ||
} | ||
|
||
const orderQueryPayload = prepareOrderQuery(params) | ||
let orders = []; | ||
let total = 0; | ||
|
||
try { | ||
resp = await MaargOrderService.findOpenOrders(orderQueryPayload); | ||
if (!hasError(resp) && resp.data.grouped?.orderId.matches > 0) { | ||
total = resp.data.grouped.orderId.ngroups | ||
orders = resp.data.grouped.orderId.groups | ||
await this.dispatch('product/getProductInformation', { orders }) | ||
|
||
orders = orders.map((order: any) => { | ||
const orderItem = order.doclist.docs[0]; | ||
|
||
return { | ||
category: 'open', | ||
customerId: orderItem.customerPartyId, | ||
customerName: orderItem.customerPartyName, | ||
orderId: orderItem.orderId, | ||
orderDate: orderItem.orderDate, | ||
orderName: orderItem.orderName, | ||
groupValue: order.groupValue, | ||
items: removeKitComponents({items: order.doclist.docs}), | ||
shipGroupSeqId: orderItem.shipGroupSeqId, | ||
shipmentMethodTypeId: orderItem.shipmentMethodTypeId, | ||
reservedDatetime: orderItem.reservedDatetime | ||
} | ||
}) | ||
} else { | ||
throw resp.data | ||
} | ||
} catch (err) { | ||
logger.error('No outstanding orders found', err) | ||
} | ||
|
||
openOrderQuery.viewSize = orders.length | ||
|
||
commit(types.ORDER_OPEN_QUERY_UPDATED, { ...openOrderQuery }) | ||
commit(types.ORDER_OPEN_UPDATED, {list: orders, total}) | ||
|
||
emitter.emit('dismissLoader'); | ||
return resp; | ||
}, | ||
async updateOpenQuery({ commit, dispatch }, payload) { | ||
commit(types.ORDER_OPEN_QUERY_UPDATED, payload) | ||
await dispatch('findOpenOrders'); | ||
}, | ||
} | ||
|
||
export default actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { GetterTree } from "vuex"; | ||
import OrderState from "./MaargOrderState"; | ||
import RootState from "../../RootState"; | ||
|
||
const getters: GetterTree<OrderState, RootState> = { | ||
getOpenOrders (state) { | ||
return state.open; | ||
}, | ||
getInProgressOrders (state) { | ||
return state.inProgress; | ||
}, | ||
getCompletedOrders (state) { | ||
return state.completed; | ||
}, | ||
getCurrent (state) { | ||
return state.current | ||
} | ||
}; | ||
export default getters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import actions from './actions' | ||
import getters from './getters' | ||
import mutations from './mutations' | ||
import { Module } from 'vuex' | ||
import OrderState from './MaargOrderState' | ||
import RootState from '../../RootState' | ||
|
||
const orderModule: Module<OrderState, RootState> = { | ||
namespaced: true, | ||
state: { | ||
open: { | ||
list: [], | ||
total: 0, | ||
query: { | ||
viewIndex: 0, | ||
viewSize: process.env.VUE_APP_VIEW_SIZE, | ||
queryString: '', | ||
selectedShipmentMethods: [] | ||
} | ||
}, | ||
completed: { | ||
list: [], | ||
total: 0, | ||
query: { | ||
viewIndex: 0, | ||
viewSize: process.env.VUE_APP_VIEW_SIZE, | ||
queryString: '', | ||
selectedCarrierPartyIds: [], | ||
selectedShipmentMethods: [] | ||
} | ||
}, | ||
inProgress: { | ||
list: [], | ||
total: 0, | ||
query: { | ||
viewIndex: 0, | ||
viewSize: process.env.VUE_APP_VIEW_SIZE, | ||
selectedPicklist: '', | ||
queryString: '' | ||
} | ||
}, | ||
current: {} | ||
}, | ||
getters, | ||
actions, | ||
mutations | ||
} | ||
|
||
export default orderModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const SN_ORDER = 'order' | ||
export const ORDER_OPEN_UPDATED = SN_ORDER + '/OPEN_UPDATED' | ||
export const ORDER_OPEN_QUERY_UPDATED = SN_ORDER + '/OPEN_QUERY_UPDATED' | ||
export const ORDER_OPEN_CLEARED = SN_ORDER + '/OPEN_CLEARED' | ||
export const ORDER_INPROGRESS_UPDATED = SN_ORDER + '/INPROGRESS_UPDATED' | ||
export const ORDER_INPROGRESS_QUERY_UPDATED = SN_ORDER + '/INPROGRESS_QUERY_UPDATED' | ||
export const ORDER_INPROGRESS_CLEARED = SN_ORDER + '/INPROGRESS_CLEARED' | ||
export const ORDER_COMPLETED_UPDATED = SN_ORDER + '/COMPLETED_UPDATED' | ||
export const ORDER_COMPLETED_QUERY_UPDATED = SN_ORDER + '/COMPLETED_QUERY_UPDATED' | ||
export const ORDER_COMPLETED_CLEARED = SN_ORDER + '/COMPLETED_CLEARED' | ||
export const ORDER_CURRENT_UPDATED = SN_ORDER + '/CURRENT_UPDATED' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { MutationTree } from 'vuex' | ||
import OrderState from './MaargOrderState' | ||
import * as types from './mutation-types' | ||
|
||
const mutations: MutationTree <OrderState> = { | ||
[types.ORDER_OPEN_UPDATED] (state, payload) { | ||
state.open.list = payload.list; | ||
state.open.total = payload.total; | ||
}, | ||
[types.ORDER_OPEN_QUERY_UPDATED](state, payload) { | ||
state.open.query = payload | ||
}, | ||
[types.ORDER_OPEN_CLEARED](state) { | ||
state.open = { | ||
list: [], | ||
total: 0, | ||
query: { | ||
viewIndex: 0, | ||
viewSize: process.env.VUE_APP_VIEW_SIZE, | ||
queryString: '', | ||
selectedShipmentMethods: [] | ||
} | ||
} | ||
}, | ||
[types.ORDER_COMPLETED_UPDATED] (state, payload) { | ||
state.completed.list = payload.list; | ||
state.completed.total = payload.total; | ||
}, | ||
[types.ORDER_COMPLETED_QUERY_UPDATED](state, payload) { | ||
state.completed.query = payload | ||
}, | ||
[types.ORDER_COMPLETED_CLEARED](state) { | ||
state.completed = { | ||
list: [], | ||
total: 0, | ||
query: { | ||
viewIndex: 0, | ||
viewSize: process.env.VUE_APP_VIEW_SIZE, | ||
selectedCarrierPartyIds: [], | ||
selectedShipmentMethods: [], | ||
queryString: '' | ||
} | ||
} | ||
}, | ||
[types.ORDER_INPROGRESS_UPDATED] (state, payload) { | ||
state.inProgress.list = payload.orders; | ||
state.inProgress.total = payload.total; | ||
}, | ||
[types.ORDER_INPROGRESS_QUERY_UPDATED] (state, payload) { | ||
state.inProgress.query = payload; | ||
}, | ||
[types.ORDER_INPROGRESS_CLEARED](state) { | ||
state.inProgress = { | ||
list: [], | ||
total: 0, | ||
query: { | ||
viewIndex: 0, | ||
viewSize: process.env.VUE_APP_VIEW_SIZE, | ||
selectedPicklist: '', | ||
queryString: '' | ||
} | ||
} | ||
}, | ||
[types.ORDER_CURRENT_UPDATED] (state, payload) { | ||
state.current = payload | ||
}, | ||
} | ||
export default mutations; |
Oops, something went wrong.